Skip to content

Commit

Permalink
feat: add rotate anim to profile update btn
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejohnson7 committed Oct 30, 2023
1 parent b091a87 commit 9773ea7
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class MetaFeatureSettingsActivity : BaseActivity<MetaFeatureSettingsDesign>() {
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"){ _, _ -> }
Expand Down
15 changes: 12 additions & 3 deletions app/src/main/java/com/github/kr328/clash/ProfilesActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProfilesDesign>() {
Expand All @@ -34,9 +36,16 @@ class ProfilesActivity : BaseActivity<ProfilesDesign>() {
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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,6 +31,13 @@ class ProfilesDesign(context: Context) : Design<ProfilesDesign.Request>(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

Expand Down Expand Up @@ -84,7 +93,14 @@ class ProfilesDesign(context: Context) : Design<ProfilesDesign.Request>(context)
}

fun requestUpdateAll() {
allUpdating = true;
requests.trySend(Request.UpdateAll)
changeUpdateAllButtonStatus()
}

fun finishUpdateAll() {
allUpdating = false;
changeUpdateAllButtonStatus()
}

fun requestCreate() {
Expand Down Expand Up @@ -118,4 +134,12 @@ class ProfilesDesign(context: Context) : Design<ProfilesDesign.Request>(context)

dialog.dismiss()
}

private fun changeUpdateAllButtonStatus() {
if (allUpdating) {
binding.updateView.startAnimation(rotateAnimation)
} else {
binding.updateView.clearAnimation()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,6 +20,7 @@ class ProfileAdapter(
private val currentTime = ObservableCurrentTime()

var profiles: List<Profile> = emptyList()
val states = ProfilePageState()

fun updateElapsed() {
currentTime.update()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.github.kr328.clash.design.model

class ProfilePageState {
var allUpdating = false
}
11 changes: 11 additions & 0 deletions design/src/main/res/anim/rotate_infinite.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="0"
android:repeatCount="infinite"
android:interpolator="@android:anim/cycle_interpolator" />
</set>

0 comments on commit 9773ea7

Please sign in to comment.