diff --git a/app/src/main/java/com/github/kr328/clash/MetaFeatureSettingsActivity.kt b/app/src/main/java/com/github/kr328/clash/MetaFeatureSettingsActivity.kt index 0bc7684a7..381123470 100644 --- a/app/src/main/java/com/github/kr328/clash/MetaFeatureSettingsActivity.kt +++ b/app/src/main/java/com/github/kr328/clash/MetaFeatureSettingsActivity.kt @@ -105,7 +105,7 @@ class MetaFeatureSettingsActivity : BaseActivity() { val ext = "." + displayName.substringAfterLast(".") if(!validDatabaseExtensions.contains(ext)) { - val dialog = MaterialAlertDialogBuilder(this) + MaterialAlertDialogBuilder(this) .setTitle("Unknown Database Format") .setMessage("Only ${validDatabaseExtensions.joinToString("/")} are supported") .setPositiveButton("OK"){ _, _ -> } diff --git a/app/src/main/java/com/github/kr328/clash/ProfilesActivity.kt b/app/src/main/java/com/github/kr328/clash/ProfilesActivity.kt index 751dcb110..aa6b677a0 100644 --- a/app/src/main/java/com/github/kr328/clash/ProfilesActivity.kt +++ b/app/src/main/java/com/github/kr328/clash/ProfilesActivity.kt @@ -6,8 +6,10 @@ import com.github.kr328.clash.common.util.ticker import com.github.kr328.clash.design.ProfilesDesign import com.github.kr328.clash.service.model.Profile import com.github.kr328.clash.util.withProfile +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.isActive import kotlinx.coroutines.selects.select +import kotlinx.coroutines.withContext import java.util.concurrent.TimeUnit class ProfilesActivity : BaseActivity() { @@ -34,9 +36,16 @@ class ProfilesActivity : BaseActivity() { startActivity(NewProfileActivity::class.intent) ProfilesDesign.Request.UpdateAll -> withProfile { - queryAll().forEach { p -> - if (p.imported && p.type != Profile.Type.File) - update(p.uuid) + try { + queryAll().forEach { p -> + if (p.imported && p.type != Profile.Type.File) + update(p.uuid) + } + } + finally { + withContext(Dispatchers.Main) { + design.finishUpdateAll(); + } } } is ProfilesDesign.Request.Update -> diff --git a/design/src/main/java/com/github/kr328/clash/design/ProfilesDesign.kt b/design/src/main/java/com/github/kr328/clash/design/ProfilesDesign.kt index 33c146771..24bfa40c5 100644 --- a/design/src/main/java/com/github/kr328/clash/design/ProfilesDesign.kt +++ b/design/src/main/java/com/github/kr328/clash/design/ProfilesDesign.kt @@ -4,6 +4,8 @@ import android.app.Dialog import android.content.Context import android.view.View import android.view.ViewGroup +import android.view.animation.Animation +import android.view.animation.AnimationUtils import com.github.kr328.clash.design.adapter.ProfileAdapter import com.github.kr328.clash.design.databinding.DesignProfilesBinding import com.github.kr328.clash.design.databinding.DialogProfilesMenuBinding @@ -29,6 +31,13 @@ class ProfilesDesign(context: Context) : Design(context) .inflate(context.layoutInflater, context.root, false) private val adapter = ProfileAdapter(context, this::requestActive, this::showMenu) + private var allUpdating: Boolean + get() = adapter.states.allUpdating; + set(value) { + adapter.states.allUpdating = value + } + private val rotateAnimation : Animation = AnimationUtils.loadAnimation(context, R.anim.rotate_infinite) + override val root: View get() = binding.root @@ -84,7 +93,14 @@ class ProfilesDesign(context: Context) : Design(context) } fun requestUpdateAll() { + allUpdating = true; requests.trySend(Request.UpdateAll) + changeUpdateAllButtonStatus() + } + + fun finishUpdateAll() { + allUpdating = false; + changeUpdateAllButtonStatus() } fun requestCreate() { @@ -118,4 +134,12 @@ class ProfilesDesign(context: Context) : Design(context) dialog.dismiss() } + + private fun changeUpdateAllButtonStatus() { + if (allUpdating) { + binding.updateView.startAnimation(rotateAnimation) + } else { + binding.updateView.clearAnimation() + } + } } \ No newline at end of file diff --git a/design/src/main/java/com/github/kr328/clash/design/adapter/ProfileAdapter.kt b/design/src/main/java/com/github/kr328/clash/design/adapter/ProfileAdapter.kt index e12cfbd94..fdb4cdf52 100644 --- a/design/src/main/java/com/github/kr328/clash/design/adapter/ProfileAdapter.kt +++ b/design/src/main/java/com/github/kr328/clash/design/adapter/ProfileAdapter.kt @@ -4,6 +4,8 @@ import android.content.Context import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import com.github.kr328.clash.design.databinding.AdapterProfileBinding +import com.github.kr328.clash.design.model.ProfilePageState +import com.github.kr328.clash.design.model.ProxyPageState import com.github.kr328.clash.design.ui.ObservableCurrentTime import com.github.kr328.clash.design.util.layoutInflater import com.github.kr328.clash.service.model.Profile @@ -18,6 +20,7 @@ class ProfileAdapter( private val currentTime = ObservableCurrentTime() var profiles: List = emptyList() + val states = ProfilePageState() fun updateElapsed() { currentTime.update() diff --git a/design/src/main/java/com/github/kr328/clash/design/model/ProfilePageState.kt b/design/src/main/java/com/github/kr328/clash/design/model/ProfilePageState.kt new file mode 100644 index 000000000..c61b13178 --- /dev/null +++ b/design/src/main/java/com/github/kr328/clash/design/model/ProfilePageState.kt @@ -0,0 +1,5 @@ +package com.github.kr328.clash.design.model + +class ProfilePageState { + var allUpdating = false +} \ No newline at end of file diff --git a/design/src/main/res/anim/rotate_infinite.xml b/design/src/main/res/anim/rotate_infinite.xml new file mode 100644 index 000000000..10ef573a4 --- /dev/null +++ b/design/src/main/res/anim/rotate_infinite.xml @@ -0,0 +1,11 @@ + + + + \ No newline at end of file