Add a progress bar
This commit is contained in:
1 parent
a0223a3eee
commit
828a39331b
3 files changed
+57
-48
No files matched your search
@@ -128,7 +128,6 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
|
|||||||
|
|
||||||
initGroupTab()
|
initGroupTab()
|
||||||
setupViewModel()
|
setupViewModel()
|
||||||
mainViewModel.copyAssets(assets)
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
RxPermissions(this)
|
RxPermissions(this)
|
||||||
@@ -175,6 +174,7 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
mainViewModel.startListenBroadcast()
|
mainViewModel.startListenBroadcast()
|
||||||
|
mainViewModel.copyAssets(assets)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initGroupTab() {
|
private fun initGroupTab() {
|
||||||
@@ -310,7 +310,18 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
|
|||||||
}
|
}
|
||||||
|
|
||||||
R.id.export_all -> {
|
R.id.export_all -> {
|
||||||
mainViewModel.exportAllServer()
|
binding.pbWaiting.show()
|
||||||
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
|
val ret = mainViewModel.exportAllServer()
|
||||||
|
launch(Dispatchers.Main) {
|
||||||
|
if (ret == 0)
|
||||||
|
toast(R.string.toast_success)
|
||||||
|
else
|
||||||
|
toast(R.string.toast_failure)
|
||||||
|
binding.pbWaiting.hide()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,7 +343,14 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
|
|||||||
R.id.del_all_config -> {
|
R.id.del_all_config -> {
|
||||||
AlertDialog.Builder(this).setMessage(R.string.del_config_comfirm)
|
AlertDialog.Builder(this).setMessage(R.string.del_config_comfirm)
|
||||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||||
|
binding.pbWaiting.show()
|
||||||
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
mainViewModel.removeAllServer()
|
mainViewModel.removeAllServer()
|
||||||
|
launch(Dispatchers.Main) {
|
||||||
|
mainViewModel.reloadServerList()
|
||||||
|
binding.pbWaiting.hide()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.setNegativeButton(android.R.string.no) {_, _ ->
|
.setNegativeButton(android.R.string.no) {_, _ ->
|
||||||
//do noting
|
//do noting
|
||||||
@@ -343,18 +361,34 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
|
|||||||
R.id.del_duplicate_config-> {
|
R.id.del_duplicate_config-> {
|
||||||
AlertDialog.Builder(this).setMessage(R.string.del_config_comfirm)
|
AlertDialog.Builder(this).setMessage(R.string.del_config_comfirm)
|
||||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||||
mainViewModel.removeDuplicateServer()
|
binding.pbWaiting.show()
|
||||||
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
|
val ret = mainViewModel.removeDuplicateServer()
|
||||||
|
launch(Dispatchers.Main) {
|
||||||
|
mainViewModel.reloadServerList()
|
||||||
|
toast(getString(R.string.title_del_duplicate_config_count, ret))
|
||||||
|
binding.pbWaiting.hide()
|
||||||
}
|
}
|
||||||
.setNegativeButton(android.R.string.no) {_, _ ->
|
}
|
||||||
|
}
|
||||||
|
.setNegativeButton(android.R.string.no) { _, _ ->
|
||||||
//do noting
|
//do noting
|
||||||
}
|
}
|
||||||
.show()
|
.show()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.del_invalid_config -> {
|
R.id.del_invalid_config -> {
|
||||||
AlertDialog.Builder(this).setMessage(R.string.del_config_comfirm)
|
AlertDialog.Builder(this).setMessage(R.string.del_config_comfirm)
|
||||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||||
|
binding.pbWaiting.show()
|
||||||
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
mainViewModel.removeInvalidServer()
|
mainViewModel.removeInvalidServer()
|
||||||
|
launch(Dispatchers.Main) {
|
||||||
|
mainViewModel.reloadServerList()
|
||||||
|
binding.pbWaiting.hide()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.setNegativeButton(android.R.string.no) {_, _ ->
|
.setNegativeButton(android.R.string.no) {_, _ ->
|
||||||
//do noting
|
//do noting
|
||||||
@@ -363,7 +397,14 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
R.id.sort_by_test_results -> {
|
R.id.sort_by_test_results -> {
|
||||||
|
binding.pbWaiting.show()
|
||||||
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
mainViewModel.sortByTestResults()
|
mainViewModel.sortByTestResults()
|
||||||
|
launch(Dispatchers.Main) {
|
||||||
|
mainViewModel.reloadServerList()
|
||||||
|
binding.pbWaiting.hide()
|
||||||
|
}
|
||||||
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
else -> super.onOptionsItemSelected(item)
|
else -> super.onOptionsItemSelected(item)
|
||||||
|
|||||||
@@ -5,22 +5,17 @@ import android.text.TextUtils
|
|||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.work.Constraints
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.work.ExistingPeriodicWorkPolicy
|
|
||||||
import androidx.work.NetworkType
|
|
||||||
import androidx.work.PeriodicWorkRequest
|
|
||||||
import androidx.work.multiprocess.RemoteWorkManager
|
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.tencent.mmkv.MMKV
|
import com.tencent.mmkv.MMKV
|
||||||
import com.v2ray.ang.AngApplication
|
|
||||||
import com.v2ray.ang.R
|
import com.v2ray.ang.R
|
||||||
import com.v2ray.ang.databinding.ActivitySubEditBinding
|
import com.v2ray.ang.databinding.ActivitySubEditBinding
|
||||||
import com.v2ray.ang.dto.SubscriptionItem
|
import com.v2ray.ang.dto.SubscriptionItem
|
||||||
import com.v2ray.ang.extension.toast
|
import com.v2ray.ang.extension.toast
|
||||||
import com.v2ray.ang.service.SubscriptionUpdater
|
|
||||||
import com.v2ray.ang.util.MmkvManager
|
import com.v2ray.ang.util.MmkvManager
|
||||||
import com.v2ray.ang.util.Utils
|
import com.v2ray.ang.util.Utils
|
||||||
import java.util.concurrent.TimeUnit
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class SubEditActivity : BaseActivity() {
|
class SubEditActivity : BaseActivity() {
|
||||||
private val binding by lazy {ActivitySubEditBinding.inflate(layoutInflater)}
|
private val binding by lazy {ActivitySubEditBinding.inflate(layoutInflater)}
|
||||||
@@ -106,9 +101,13 @@ class SubEditActivity : BaseActivity() {
|
|||||||
if (editSubId.isNotEmpty()) {
|
if (editSubId.isNotEmpty()) {
|
||||||
AlertDialog.Builder(this).setMessage(R.string.del_config_comfirm)
|
AlertDialog.Builder(this).setMessage(R.string.del_config_comfirm)
|
||||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||||
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
MmkvManager.removeSubscription(editSubId)
|
MmkvManager.removeSubscription(editSubId)
|
||||||
|
launch(Dispatchers.Main) {
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
.setNegativeButton(android.R.string.no) {_, _ ->
|
.setNegativeButton(android.R.string.no) {_, _ ->
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,8 +173,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun exportAllServer() {
|
fun exportAllServer() : Int {
|
||||||
viewModelScope.launch(Dispatchers.Default) {
|
|
||||||
val serverListCopy =
|
val serverListCopy =
|
||||||
if (subscriptionId.isNullOrEmpty()) {
|
if (subscriptionId.isNullOrEmpty()) {
|
||||||
serverList
|
serverList
|
||||||
@@ -186,15 +185,10 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
getApplication<AngApplication>(),
|
getApplication<AngApplication>(),
|
||||||
serverListCopy
|
serverListCopy
|
||||||
)
|
)
|
||||||
launch(Dispatchers.Main) {
|
return ret
|
||||||
if (ret == 0)
|
|
||||||
getApplication<AngApplication>().toast(R.string.toast_success)
|
|
||||||
else
|
|
||||||
getApplication<AngApplication>().toast(R.string.toast_failure)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun testAllTcping() {
|
fun testAllTcping() {
|
||||||
tcpingTestScope.coroutineContext[Job]?.cancelChildren()
|
tcpingTestScope.coroutineContext[Job]?.cancelChildren()
|
||||||
SpeedtestUtil.closeAllTcpSockets()
|
SpeedtestUtil.closeAllTcpSockets()
|
||||||
@@ -279,8 +273,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeDuplicateServer() {
|
fun removeDuplicateServer() : Int {
|
||||||
viewModelScope.launch(Dispatchers.Default) {
|
|
||||||
val serversCacheCopy = mutableListOf<Pair<String, ServerConfig>>()
|
val serversCacheCopy = mutableListOf<Pair<String, ServerConfig>>()
|
||||||
for (it in serversCache) {
|
for (it in serversCache) {
|
||||||
val config = MmkvManager.decodeServerConfig(it.guid) ?: continue
|
val config = MmkvManager.decodeServerConfig(it.guid) ?: continue
|
||||||
@@ -302,21 +295,11 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
for (it in deleteServer) {
|
for (it in deleteServer) {
|
||||||
MmkvManager.removeServer(it)
|
MmkvManager.removeServer(it)
|
||||||
}
|
}
|
||||||
launch(Dispatchers.Main) {
|
|
||||||
reloadServerList()
|
|
||||||
getApplication<AngApplication>().toast(
|
|
||||||
getApplication<AngApplication>().getString(
|
|
||||||
R.string.title_del_duplicate_config_count,
|
|
||||||
deleteServer.count()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
return deleteServer.count()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeAllServer() {
|
fun removeAllServer() {
|
||||||
viewModelScope.launch(Dispatchers.Default) {
|
|
||||||
if (subscriptionId.isNullOrEmpty()) {
|
if (subscriptionId.isNullOrEmpty()) {
|
||||||
MmkvManager.removeAllServer()
|
MmkvManager.removeAllServer()
|
||||||
} else {
|
} else {
|
||||||
@@ -325,14 +308,9 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
MmkvManager.removeServer(item.guid)
|
MmkvManager.removeServer(item.guid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
launch(Dispatchers.Main) {
|
|
||||||
reloadServerList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeInvalidServer() {
|
fun removeInvalidServer() {
|
||||||
viewModelScope.launch(Dispatchers.Default) {
|
|
||||||
if (subscriptionId.isNullOrEmpty()) {
|
if (subscriptionId.isNullOrEmpty()) {
|
||||||
MmkvManager.removeInvalidServer("")
|
MmkvManager.removeInvalidServer("")
|
||||||
} else {
|
} else {
|
||||||
@@ -341,19 +319,10 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
MmkvManager.removeInvalidServer(item.guid)
|
MmkvManager.removeInvalidServer(item.guid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
launch(Dispatchers.Main) {
|
|
||||||
reloadServerList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sortByTestResults() {
|
fun sortByTestResults() {
|
||||||
viewModelScope.launch(Dispatchers.Default) {
|
|
||||||
MmkvManager.sortByTestResults()
|
MmkvManager.sortByTestResults()
|
||||||
launch(Dispatchers.Main) {
|
|
||||||
reloadServerList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user