-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(image processing): use fab with shared element transition
- Loading branch information
1 parent
73f1547
commit 4c62d30
Showing
64 changed files
with
953 additions
and
1,086 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
app/src/main/kotlin/com/none/tom/exiferaser/core/extension/ContextExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2024, Tom Geiselmann (tomgapplicationsdevelopment@gmail.com) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software | ||
* and associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or | ||
* substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY,WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.none.tom.exiferaser.core.extension | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import android.os.Build | ||
import android.util.TypedValue | ||
import androidx.annotation.AttrRes | ||
import androidx.appcompat.app.AppCompatDelegate | ||
import com.none.tom.exiferaser.R | ||
|
||
fun Activity.resolveThemeAttribute(@AttrRes attrRes: Int): Int { | ||
val tv = TypedValue() | ||
theme.resolveAttribute(attrRes, tv, true) | ||
return tv.data | ||
} | ||
|
||
fun Context.defaultNightModes() = mutableMapOf( | ||
AppCompatDelegate.MODE_NIGHT_YES to getString(R.string.always), | ||
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM to getString(R.string.automatically), | ||
AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY to getString(R.string.low_batt_only), | ||
AppCompatDelegate.MODE_NIGHT_NO to getString(R.string.never) | ||
).apply { | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { | ||
remove(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) | ||
} | ||
}.toMap() | ||
|
||
fun Context.defaultNightModeDisplayValue() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { | ||
getString(R.string.automatically) | ||
} else { | ||
getString(R.string.never) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
app/src/main/kotlin/com/none/tom/exiferaser/core/extension/ViewExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright (c) 2024, Tom Geiselmann (tomgapplicationsdevelopment@gmail.com) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software | ||
* and associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or | ||
* substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY,WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.none.tom.exiferaser.core.extension | ||
|
||
import android.graphics.drawable.Animatable | ||
import android.graphics.drawable.Drawable | ||
import androidx.annotation.DrawableRes | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.LifecycleEventObserver | ||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.lifecycle.findViewTreeLifecycleOwner | ||
import androidx.recyclerview.widget.ItemTouchHelper | ||
import androidx.recyclerview.widget.RecyclerView | ||
import androidx.vectordrawable.graphics.drawable.Animatable2Compat | ||
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat | ||
import com.google.android.material.floatingactionbutton.FloatingActionButton | ||
|
||
inline fun FloatingActionButton.addIconAnimation( | ||
@DrawableRes animatedVectorDrawable: Int, | ||
@DrawableRes animatedVectorDrawableInverse: Int, | ||
crossinline showAnimatedVectorDrawableCondition: () -> Boolean | ||
) { | ||
setImageResource(animatedVectorDrawable) | ||
val callback = object : Animatable2Compat.AnimationCallback() { | ||
|
||
override fun onAnimationEnd(drawableEnd: Drawable?) { | ||
AnimatedVectorDrawableCompat.unregisterAnimationCallback(drawableEnd, this) | ||
setImageResource( | ||
if (showAnimatedVectorDrawableCondition()) { | ||
animatedVectorDrawable | ||
} else { | ||
animatedVectorDrawableInverse | ||
} | ||
) | ||
AnimatedVectorDrawableCompat.registerAnimationCallback(drawable, this) | ||
} | ||
} | ||
val lifecycle = findViewTreeLifecycleOwner()?.lifecycle | ||
lifecycle?.addObserver( | ||
object : LifecycleEventObserver { | ||
|
||
override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) { | ||
when (event) { | ||
Lifecycle.Event.ON_START -> { | ||
AnimatedVectorDrawableCompat.registerAnimationCallback( | ||
drawable, | ||
callback | ||
) | ||
} | ||
Lifecycle.Event.ON_STOP -> { | ||
if (drawable is Animatable) { | ||
(drawable as Animatable).stop() | ||
} | ||
AnimatedVectorDrawableCompat.unregisterAnimationCallback( | ||
drawable, | ||
callback | ||
) | ||
} | ||
Lifecycle.Event.ON_DESTROY -> { | ||
lifecycle.removeObserver(this) | ||
} | ||
else -> { | ||
} | ||
} | ||
} | ||
} | ||
) | ||
} | ||
|
||
fun ItemTouchHelper.attachTo(recyclerView: RecyclerView) { | ||
val lifecycle = recyclerView.findViewTreeLifecycleOwner()?.lifecycle | ||
lifecycle?.addObserver( | ||
object : LifecycleEventObserver { | ||
|
||
override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) { | ||
when (event) { | ||
Lifecycle.Event.ON_START -> { | ||
attachToRecyclerView(recyclerView) | ||
} | ||
Lifecycle.Event.ON_STOP -> { | ||
attachToRecyclerView(null) | ||
} | ||
Lifecycle.Event.ON_DESTROY -> { | ||
lifecycle.removeObserver(this) | ||
} | ||
else -> { | ||
} | ||
} | ||
} | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.