This is so cute
This commit is contained in:
parent
fafe7e2cd5
commit
64efa8c15e
2 changed files with 28 additions and 5 deletions
|
@ -1,16 +1,22 @@
|
|||
package partisan.weforge.xyz.pulse
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.os.SystemClock
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import nl.dionsegijn.konfetti.core.Party
|
||||
import nl.dionsegijn.konfetti.core.Position
|
||||
import nl.dionsegijn.konfetti.core.emitter.Emitter
|
||||
import nl.dionsegijn.konfetti.xml.KonfettiView
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class MainFragment : Fragment() {
|
||||
|
||||
private lateinit var prefs: Preferences
|
||||
private var lastConfettiTime = 0L
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
|
@ -21,6 +27,8 @@ class MainFragment : Fragment() {
|
|||
prefs = Preferences(requireContext())
|
||||
|
||||
val toggle = view.findViewById<MaterialButton>(R.id.toggle)
|
||||
val konfetti = view.findViewById<KonfettiView>(R.id.confettiView)
|
||||
|
||||
toggle.isCheckable = true
|
||||
toggle.isChecked = prefs.isServiceEnabledByUser
|
||||
|
||||
|
@ -29,10 +37,19 @@ class MainFragment : Fragment() {
|
|||
val isNowChecked = toggle.isChecked
|
||||
prefs.isServiceEnabledByUser = isNowChecked
|
||||
|
||||
// Log.d("ButtonState", """
|
||||
// User toggle: $isNowChecked
|
||||
// Prefs effective state (hasPerms): ${prefs.isEnabled}
|
||||
// """.trimIndent())
|
||||
if (isNowChecked && SystemClock.elapsedRealtime() - lastConfettiTime > 500) {
|
||||
konfetti.start(
|
||||
Party(
|
||||
emitter = Emitter(duration = 100, TimeUnit.MILLISECONDS).perSecond(100),
|
||||
speed = 30f,
|
||||
maxSpeed = 40f,
|
||||
damping = 0.85f,
|
||||
spread = 360,
|
||||
position = Position.Relative(0.5, 0.5)
|
||||
)
|
||||
)
|
||||
lastConfettiTime = SystemClock.elapsedRealtime()
|
||||
}
|
||||
|
||||
toggle.post {
|
||||
toggle.jumpDrawablesToCurrentState()
|
||||
|
|
|
@ -4,6 +4,12 @@
|
|||
android:layout_height="match_parent"
|
||||
android:gravity="center">
|
||||
|
||||
<nl.dionsegijn.konfetti.xml.KonfettiView
|
||||
android:id="@+id/confettiView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center" />
|
||||
|
||||
<View
|
||||
android:layout_width="104dp"
|
||||
android:layout_height="104dp"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue