Pull down to update subscription

This commit is contained in:
2dust committed 2026-03-12 19:23:52 +08:00
1 parent 303b642ade
commit 0b452707c3
4 files changed
+25 -9

No files matched your search

@@ -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<FragmentGroupServerBinding>() {
class GroupServerFragment : BaseFragment<FragmentGroupServerBinding>(),
SwipeRefreshLayout.OnRefreshListener {
private val ownerActivity: MainActivity
get() = requireActivity() as MainActivity
private val mainViewModel: MainViewModel by activityViewModels()
@@ -68,6 +70,8 @@ class GroupServerFragment : BaseFragment<FragmentGroupServerBinding>() {
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<FragmentGroupServerBinding>() {
* @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<FragmentGroupServerBinding>() {
* @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<FragmentGroupServerBinding>() {
shareServer(guid, profile, position, shareOptions, skip)
}
}
override fun onRefresh() {
ownerActivity.importConfigViaSub()
binding.refreshLayout.isRefreshing = false
}
}
@@ -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) {
@@ -8,7 +8,7 @@
tools:context=".ui.LogcatActivity">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/refreshLayout"
android:id="@+id/refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
@@ -3,10 +3,17 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</FrameLayout>