Skip to content

Commit

Permalink
Remove lottie clock
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmud0808 committed May 9, 2024
1 parent b0aa5dc commit b5c9317
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 12,732 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.drdisagree.iconify.config.RPrefs
import com.drdisagree.iconify.ui.models.ClockModel
import com.drdisagree.iconify.ui.utils.ViewBindingHelpers.setBitmapWithAnimation
import com.drdisagree.iconify.utils.WallpaperUtil
import com.drdisagree.iconify.xposed.modules.utils.ViewHelper
import com.google.android.material.button.MaterialButton
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -116,12 +115,6 @@ class ClockPreviewAdapter(
if (wallpaperBitmap != null) {
setBitmapWithAnimation(wallpaperView, wallpaperBitmap)
}

ViewHelper.loadLottieAnimationView(
appContext = context,
parent = container,
styleIndex = adapterPosition
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import com.google.android.material.slider.Slider
class XposedHeaderClock : BaseFragment() {

private lateinit var binding: FragmentXposedHeaderClockBinding
private var totalClocks: Int = 1

private var startActivityIntent = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
Expand Down Expand Up @@ -109,17 +110,25 @@ class XposedHeaderClock : BaseFragment() {

// Header clock style
val snapHelper: SnapHelper = LinearSnapHelper()
binding.rvHeaderClockPreview.setLayoutManager(
CarouselLayoutManager(
requireContext(),
RecyclerView.HORIZONTAL,
false
)
val carouselLayoutManager = CarouselLayoutManager(
requireContext(),
RecyclerView.HORIZONTAL,
false
)
carouselLayoutManager.setMinifyDistance(0.8f)

binding.rvHeaderClockPreview.setLayoutManager(carouselLayoutManager)
binding.rvHeaderClockPreview.setAdapter(initHeaderClockStyles())
binding.rvHeaderClockPreview.setHasFixedSize(true)
snapHelper.attachToRecyclerView(binding.rvHeaderClockPreview)
binding.rvHeaderClockPreview.scrollToPosition(getInt(HEADER_CLOCK_STYLE, 0))

// if index exceeds limit, set to highest available
var headerClockStyle = getInt(HEADER_CLOCK_STYLE, 0)
if (headerClockStyle >= totalClocks) {
headerClockStyle = totalClocks - 1
putInt(HEADER_CLOCK_STYLE, headerClockStyle)
}
binding.rvHeaderClockPreview.scrollToPosition(headerClockStyle)

// Lockscreen clock font picker
binding.headerClockFont.setActivityResultLauncher(startActivityIntent)
Expand Down Expand Up @@ -355,6 +364,8 @@ class XposedHeaderClock : BaseFragment() {
maxIndex++
}

totalClocks = maxIndex

for (i in 0 until maxIndex) {
headerClock.add(
ClockModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import com.google.android.material.slider.Slider
class XposedLockscreenClock : BaseFragment() {

private lateinit var binding: FragmentXposedLockscreenClockBinding
private var totalClocks: Int = 1

private var startActivityIntent = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
Expand Down Expand Up @@ -110,17 +111,25 @@ class XposedLockscreenClock : BaseFragment() {

// Lockscreen clock style
val snapHelper: SnapHelper = LinearSnapHelper()
binding.rvLockscreenClockPreview.setLayoutManager(
CarouselLayoutManager(
requireContext(),
RecyclerView.HORIZONTAL,
false
)
val carouselLayoutManager = CarouselLayoutManager(
requireContext(),
RecyclerView.HORIZONTAL,
false
)
carouselLayoutManager.setMinifyDistance(0.8f)

binding.rvLockscreenClockPreview.setLayoutManager(carouselLayoutManager)
binding.rvLockscreenClockPreview.setAdapter(initLockscreenClockStyles())
binding.rvLockscreenClockPreview.setHasFixedSize(true)
snapHelper.attachToRecyclerView(binding.rvLockscreenClockPreview)
binding.rvLockscreenClockPreview.scrollToPosition(getInt(LSCLOCK_STYLE, 0))

// if index exceeds limit, set to highest available
var lsClockStyle = getInt(LSCLOCK_STYLE, 0)
if (lsClockStyle >= totalClocks) {
lsClockStyle = totalClocks - 1
putInt(LSCLOCK_STYLE, lsClockStyle)
}
binding.rvLockscreenClockPreview.scrollToPosition(lsClockStyle)

// Lockscreen clock font picker
binding.lockscreenClockFont.setActivityResultLauncher(startActivityIntent)
Expand Down Expand Up @@ -345,6 +354,8 @@ class XposedLockscreenClock : BaseFragment() {
maxIndex++
}

totalClocks = maxIndex

for (i in 0 until maxIndex) {
lsClock.add(
ClockModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ import com.drdisagree.iconify.xposed.modules.utils.ViewHelper.applyTextMarginRec
import com.drdisagree.iconify.xposed.modules.utils.ViewHelper.applyTextScalingRecursively
import com.drdisagree.iconify.xposed.modules.utils.ViewHelper.findViewContainsTag
import com.drdisagree.iconify.xposed.modules.utils.ViewHelper.findViewWithTagAndChangeColor
import com.drdisagree.iconify.xposed.modules.utils.ViewHelper.loadLottieAnimationView
import com.drdisagree.iconify.xposed.modules.utils.ViewHelper.setMargins
import de.robv.android.xposed.XC_MethodHook
import de.robv.android.xposed.XposedBridge.hookAllMethods
import de.robv.android.xposed.XposedBridge.log
import de.robv.android.xposed.XposedHelpers.findClass
import de.robv.android.xposed.XposedHelpers.findClassIfExists
import de.robv.android.xposed.XposedHelpers.getObjectField
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam
import java.io.File
Expand All @@ -95,7 +93,6 @@ class LockscreenClock(context: Context?) : ModPack(context!!) {
private var mBatteryPercentage = 1
private var mVolumeLevelArcProgress: ImageView? = null
private var mRamUsageArcProgress: ImageView? = null
private var lottieAnimationViewClass: Class<*>? = null
private val mBatteryReceiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action != null && intent.action == Intent.ACTION_BATTERY_CHANGED) {
Expand Down Expand Up @@ -145,11 +142,6 @@ class LockscreenClock(context: Context?) : ModPack(context!!) {
override fun handleLoadPackage(loadPackageParam: LoadPackageParam) {
initResources(mContext)

lottieAnimationViewClass = findClassIfExists(
"com.airbnb.lottie.LottieAnimationView",
loadPackageParam.classLoader
)

val keyguardStatusViewClass = findClass(
"com.android.keyguard.KeyguardStatusView",
loadPackageParam.classLoader
Expand Down Expand Up @@ -396,14 +388,6 @@ class LockscreenClock(context: Context?) : ModPack(context!!) {
null
)

lottieAnimationViewClass?.let {
loadLottieAnimationView(
appContext = appContext!!,
lottieAnimationViewClass = it,
parent = view
)
}

return view
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.drdisagree.iconify.xposed.modules.utils

import android.annotation.SuppressLint
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.util.Log
import android.util.TypedValue
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.MarginLayoutParams
Expand All @@ -19,16 +16,7 @@ import android.widget.LinearLayout
import android.widget.ProgressBar
import android.widget.RelativeLayout
import android.widget.TextView
import com.airbnb.lottie.LottieAnimationView
import com.airbnb.lottie.LottieDrawable
import com.airbnb.lottie.RenderMode
import com.drdisagree.iconify.BuildConfig
import com.drdisagree.iconify.common.Preferences
import com.drdisagree.iconify.common.Resources.LOCKSCREEN_CLOCK_LOTTIE
import com.drdisagree.iconify.config.XPrefs.Xprefs
import de.robv.android.xposed.XposedBridge
import de.robv.android.xposed.XposedHelpers.callMethod
import java.io.InputStream


object ViewHelper {
Expand Down Expand Up @@ -262,101 +250,6 @@ object ViewHelper {
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, newSize)
}

fun loadLottieAnimationView(
appContext: Context,
lottieAnimationViewClass: Class<*>? = null,
parent: View,
styleIndex: Int? = null
) {
if (parent !is ViewGroup ||
parent.findViewContainsTag("lottie") == null ||
(lottieAnimationViewClass == null && styleIndex == null)
) return

var isXposedMode = true
val currentStyleIndex: Int? = try {
Xprefs!!.getInt(Preferences.LSCLOCK_STYLE, 0)
} catch (ignored: Throwable) {
if (styleIndex == null) {
throw IllegalStateException("Parameter \"styleIndex\" cannot be null")
}

isXposedMode = false
styleIndex
}
val rawResName = LOCKSCREEN_CLOCK_LOTTIE + currentStyleIndex

val lottieAnimView: Any = if (isXposedMode) {
if (lottieAnimationViewClass == null) {
throw IllegalStateException("Parameter \"lottieAnimationViewClass\" cannot be null")
}

lottieAnimationViewClass
.getConstructor(Context::class.java)
.newInstance(appContext)
} else {
LottieAnimationView(appContext)
}

val animationParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT
).apply {
gravity = Gravity.CENTER
}

@SuppressLint("DiscouragedApi")
val anim: Int = appContext.resources.getIdentifier(
rawResName,
"raw",
BuildConfig.APPLICATION_ID
)

if (anim == 0x0) {
if (isXposedMode) {
XposedBridge.log("Iconify - ${ViewHelper::class.simpleName}: $rawResName not found")
} else {
Log.w(ViewHelper::class.simpleName, "$rawResName not found")
}
return
}

val rawRes: InputStream = appContext.resources.openRawResource(anim)

if (isXposedMode) {
lottieAnimView.let {
callMethod(it, "setLayoutParams", animationParams)
callMethod(it, "setAnimation", rawRes, "cacheKey_$styleIndex");
callMethod(it, "setRepeatCount", LottieDrawable.INFINITE)
callMethod(it, "setScaleType", ImageView.ScaleType.FIT_CENTER)
callMethod(it, "setAdjustViewBounds", true)
callMethod(it, "enableMergePathsForKitKatAndAbove", true)
callMethod(it, "playAnimation")
}
} else {
(lottieAnimView as LottieAnimationView).apply {
layoutParams = animationParams
setAnimation(rawRes, "cacheKey_$styleIndex")
repeatCount = LottieDrawable.INFINITE
renderMode = RenderMode.HARDWARE
scaleType = ImageView.ScaleType.FIT_CENTER
adjustViewBounds = true
enableMergePathsForKitKatAndAbove(true)
playAnimation()
}
}

(parent.findViewContainsTag("lottie") as LinearLayout).let {
it.gravity = Gravity.CENTER

if (isXposedMode) {
callMethod(it, "addView", lottieAnimView);
} else {
it.addView(lottieAnimView as LottieAnimationView)
}
}
}

fun View.findViewContainsTag(tag: String): View? {
if (this is ViewGroup) {
for (i in 0 until childCount) {
Expand Down
Loading

0 comments on commit b5c9317

Please sign in to comment.