diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/GroupServerFragment.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/GroupServerFragment.kt index e7023721..03822c6a 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/GroupServerFragment.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/GroupServerFragment.kt @@ -11,6 +11,7 @@ import androidx.fragment.app.activityViewModels import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.ItemTouchHelper +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import com.v2ray.ang.AppConfig import com.v2ray.ang.R import com.v2ray.ang.contracts.MainAdapterListener @@ -28,7 +29,8 @@ import com.v2ray.ang.viewmodel.MainViewModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -class GroupServerFragment : BaseFragment() { +class GroupServerFragment : BaseFragment(), + SwipeRefreshLayout.OnRefreshListener { private val ownerActivity: MainActivity get() = requireActivity() as MainActivity private val mainViewModel: MainViewModel by activityViewModels() @@ -68,6 +70,8 @@ class GroupServerFragment : BaseFragment() { itemTouchHelper = ItemTouchHelper(SimpleItemTouchHelperCallback(adapter, allowSwipe = false)) itemTouchHelper?.attachToRecyclerView(binding.recyclerView) + binding.refreshLayout.setOnRefreshListener(this) + mainViewModel.updateListAction.observe(viewLifecycleOwner) { index -> if (mainViewModel.subscriptionId != subId) { return@observe @@ -142,7 +146,7 @@ class GroupServerFragment : BaseFragment() { * @param guid The server unique identifier */ private fun shareFullContent(guid: String) { - ownerActivity.lifecycleScope.launch(Dispatchers.IO) { + lifecycleScope.launch(Dispatchers.IO) { val result = AngConfigManager.shareFullContent2Clipboard(ownerActivity, guid) launch(Dispatchers.Main) { if (result == 0) { @@ -212,7 +216,7 @@ class GroupServerFragment : BaseFragment() { * @param position The position in the list */ private fun removeServerSub(guid: String, position: Int) { - ownerActivity.mainViewModel.removeServer(guid) + mainViewModel.removeServer(guid) adapter.removeServerSub(guid, position) } @@ -271,4 +275,9 @@ class GroupServerFragment : BaseFragment() { shareServer(guid, profile, position, shareOptions, skip) } } + + override fun onRefresh() { + ownerActivity.importConfigViaSub() + binding.refreshLayout.isRefreshing = false + } } \ No newline at end of file diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainActivity.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainActivity.kt index 3f463961..7b42d865 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainActivity.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainActivity.kt @@ -433,7 +433,7 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect /** * import config from sub */ - private fun importConfigViaSub(): Boolean { + fun importConfigViaSub(): Boolean { showLoading() lifecycleScope.launch(Dispatchers.IO) { diff --git a/V2rayNG/app/src/main/res/layout/activity_logcat.xml b/V2rayNG/app/src/main/res/layout/activity_logcat.xml index 05db70a7..f0cbffd5 100644 --- a/V2rayNG/app/src/main/res/layout/activity_logcat.xml +++ b/V2rayNG/app/src/main/res/layout/activity_logcat.xml @@ -8,7 +8,7 @@ tools:context=".ui.LogcatActivity"> diff --git a/V2rayNG/app/src/main/res/layout/fragment_group_server.xml b/V2rayNG/app/src/main/res/layout/fragment_group_server.xml index ab9436d7..121e995c 100644 --- a/V2rayNG/app/src/main/res/layout/fragment_group_server.xml +++ b/V2rayNG/app/src/main/res/layout/fragment_group_server.xml @@ -3,10 +3,17 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + android:layout_height="match_parent"> + + + +