@@ -11,6 +11,7 @@ import androidx.fragment.app.activityViewModels
1111import androidx.lifecycle.lifecycleScope
1212import androidx.recyclerview.widget.GridLayoutManager
1313import androidx.recyclerview.widget.ItemTouchHelper
14+ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
1415import com.v2ray.ang.AppConfig
1516import com.v2ray.ang.R
1617import com.v2ray.ang.contracts.MainAdapterListener
@@ -28,7 +29,8 @@ import com.v2ray.ang.viewmodel.MainViewModel
2829import kotlinx.coroutines.Dispatchers
2930import kotlinx.coroutines.launch
3031
31- class GroupServerFragment : BaseFragment <FragmentGroupServerBinding >() {
32+ class GroupServerFragment : BaseFragment <FragmentGroupServerBinding >(),
33+ SwipeRefreshLayout .OnRefreshListener {
3234 private val ownerActivity: MainActivity
3335 get() = requireActivity() as MainActivity
3436 private val mainViewModel: MainViewModel by activityViewModels()
@@ -68,6 +70,8 @@ class GroupServerFragment : BaseFragment<FragmentGroupServerBinding>() {
6870 itemTouchHelper = ItemTouchHelper (SimpleItemTouchHelperCallback (adapter, allowSwipe = false ))
6971 itemTouchHelper?.attachToRecyclerView(binding.recyclerView)
7072
73+ binding.refreshLayout.setOnRefreshListener(this )
74+
7175 mainViewModel.updateListAction.observe(viewLifecycleOwner) { index ->
7276 if (mainViewModel.subscriptionId != subId) {
7377 return @observe
@@ -142,7 +146,7 @@ class GroupServerFragment : BaseFragment<FragmentGroupServerBinding>() {
142146 * @param guid The server unique identifier
143147 */
144148 private fun shareFullContent (guid : String ) {
145- ownerActivity. lifecycleScope.launch(Dispatchers .IO ) {
149+ lifecycleScope.launch(Dispatchers .IO ) {
146150 val result = AngConfigManager .shareFullContent2Clipboard(ownerActivity, guid)
147151 launch(Dispatchers .Main ) {
148152 if (result == 0 ) {
@@ -212,7 +216,7 @@ class GroupServerFragment : BaseFragment<FragmentGroupServerBinding>() {
212216 * @param position The position in the list
213217 */
214218 private fun removeServerSub (guid : String , position : Int ) {
215- ownerActivity. mainViewModel.removeServer(guid)
219+ mainViewModel.removeServer(guid)
216220 adapter.removeServerSub(guid, position)
217221 }
218222
@@ -271,4 +275,9 @@ class GroupServerFragment : BaseFragment<FragmentGroupServerBinding>() {
271275 shareServer(guid, profile, position, shareOptions, skip)
272276 }
273277 }
278+
279+ override fun onRefresh () {
280+ ownerActivity.importConfigViaSub()
281+ binding.refreshLayout.isRefreshing = false
282+ }
274283}
0 commit comments