Skip to content

Commit 0b45270

Browse files
committed
Pull down to update subscription
1 parent 303b642 commit 0b45270

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

V2rayNG/app/src/main/java/com/v2ray/ang/ui/GroupServerFragment.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import androidx.fragment.app.activityViewModels
1111
import androidx.lifecycle.lifecycleScope
1212
import androidx.recyclerview.widget.GridLayoutManager
1313
import androidx.recyclerview.widget.ItemTouchHelper
14+
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
1415
import com.v2ray.ang.AppConfig
1516
import com.v2ray.ang.R
1617
import com.v2ray.ang.contracts.MainAdapterListener
@@ -28,7 +29,8 @@ import com.v2ray.ang.viewmodel.MainViewModel
2829
import kotlinx.coroutines.Dispatchers
2930
import 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
}

V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
433433
/**
434434
* import config from sub
435435
*/
436-
private fun importConfigViaSub(): Boolean {
436+
fun importConfigViaSub(): Boolean {
437437
showLoading()
438438

439439
lifecycleScope.launch(Dispatchers.IO) {

V2rayNG/app/src/main/res/layout/activity_logcat.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
tools:context=".ui.LogcatActivity">
99

1010
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
11-
android:id="@+id/refreshLayout"
11+
android:id="@+id/refresh_layout"
1212
android:layout_width="match_parent"
1313
android:layout_height="match_parent">
1414

V2rayNG/app/src/main/res/layout/fragment_group_server.xml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@
33
android:layout_width="match_parent"
44
android:layout_height="match_parent">
55

6-
<androidx.recyclerview.widget.RecyclerView
7-
android:id="@+id/recycler_view"
6+
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
7+
android:id="@+id/refresh_layout"
88
android:layout_width="match_parent"
9-
android:layout_height="match_parent"
10-
android:scrollbars="vertical" />
9+
android:layout_height="match_parent">
10+
11+
<androidx.recyclerview.widget.RecyclerView
12+
android:id="@+id/recycler_view"
13+
android:layout_width="match_parent"
14+
android:layout_height="match_parent"
15+
android:scrollbars="vertical" />
16+
17+
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
1118

1219
</FrameLayout>

0 commit comments

Comments
 (0)