This commit is contained in:
machiav3lli
2022-09-18 16:28:27 +02:00
parent db17185d37
commit 8e295b1593
15 changed files with 52 additions and 222 deletions

View File

@ -1,14 +0,0 @@
package com.machiav3lli.fdroid.utility
sealed interface PreferenceType {
data class Switch(val title: String, val description: String, val key: String) : PreferenceType
data class Slider(
val title: String,
val value: Float,
val range: ClosedFloatingPointRange<Float>,
val key: String
) : PreferenceType
data class Data(val title: String, val description: String, val key: String) : PreferenceType
}

View File

@ -16,7 +16,6 @@ import android.content.pm.PermissionInfo
import android.content.pm.Signature
import android.content.res.Configuration
import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.net.Uri
import android.provider.Settings
import android.text.SpannableStringBuilder
@ -61,7 +60,6 @@ import com.machiav3lli.fdroid.ui.navigation.NavItem
import com.machiav3lli.fdroid.utility.extension.android.Android
import com.machiav3lli.fdroid.utility.extension.android.singleSignature
import com.machiav3lli.fdroid.utility.extension.android.versionCodeCompat
import com.machiav3lli.fdroid.utility.extension.resources.getDrawableCompat
import com.machiav3lli.fdroid.utility.extension.text.hex
import com.machiav3lli.fdroid.utility.extension.text.nullIfEmpty
import com.topjohnwu.superuser.Shell
@ -85,13 +83,6 @@ object Utils {
)
}
fun getDefaultApplicationIcon(context: Context): Drawable =
context.getDrawableCompat(R.drawable.ic_placeholder)
fun getToolbarIcon(context: Context, resId: Int): Drawable {
return context.getDrawableCompat(resId).mutate()
}
fun calculateHash(signature: Signature): String {
return MessageDigest.getInstance("MD5").digest(signature.toCharsString().toByteArray())
.hex()
@ -234,14 +225,14 @@ val isDarkTheme: Boolean
get() = when (Preferences[Preferences.Key.Theme]) {
is Preferences.Theme.Light -> false
is Preferences.Theme.Dark -> true
is Preferences.Theme.Amoled -> true
is Preferences.Theme.Black -> true
else -> false
}
val isBlackTheme: Boolean
get() = when (Preferences[Preferences.Key.Theme]) {
is Preferences.Theme.Amoled -> true
is Preferences.Theme.AmoledSystem -> true
is Preferences.Theme.Black -> true
is Preferences.Theme.SystemBlack -> true
else -> false
}

View File

@ -59,16 +59,4 @@ object Android {
get() = (if (sdk(28)) android.content.pm.PackageManager.GET_SIGNING_CERTIFICATES else 0) or
@Suppress("DEPRECATION") android.content.pm.PackageManager.GET_SIGNATURES
}
object Device {
val isHuaweiEmui: Boolean
get() {
return try {
Class.forName("com.huawei.android.os.BuildEx")
true
} catch (e: Exception) {
false
}
}
}
}

View File

@ -5,12 +5,8 @@ package com.machiav3lli.fdroid.utility.extension.resources
import android.content.Context
import android.content.res.ColorStateList
import android.content.res.Resources
import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.AttrRes
import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat
@ -18,11 +14,6 @@ import androidx.core.content.res.ResourcesCompat
import com.google.android.material.textview.MaterialTextView
import kotlin.math.roundToInt
object TypefaceExtra {
val medium = Typeface.create("sans-serif-medium", Typeface.NORMAL)!!
val light = Typeface.create("sans-serif-light", Typeface.NORMAL)!!
}
fun Context.getColorFromAttr(@AttrRes attrResId: Int): ColorStateList {
val typedArray = obtainStyledAttributes(intArrayOf(attrResId))
val (colorStateList, resId) = try {
@ -33,16 +24,6 @@ fun Context.getColorFromAttr(@AttrRes attrResId: Int): ColorStateList {
return colorStateList ?: ContextCompat.getColorStateList(this, resId)!!
}
fun Context.getDrawableFromAttr(attrResId: Int): Drawable {
val typedArray = obtainStyledAttributes(intArrayOf(attrResId))
val resId = try {
typedArray.getResourceId(0, 0)
} finally {
typedArray.recycle()
}
return getDrawableCompat(resId)
}
fun Context.getDrawableCompat(@DrawableRes resId: Int): Drawable =
ResourcesCompat.getDrawable(resources, resId, theme) ?: ContextCompat.getDrawable(this, resId)!!
@ -55,7 +36,3 @@ fun MaterialTextView.setTextSizeScaled(size: Int) {
val realSize = (size * resources.displayMetrics.scaledDensity).roundToInt()
setTextSize(TypedValue.COMPLEX_UNIT_PX, realSize.toFloat())
}
fun ViewGroup.inflate(layoutResId: Int): View {
return LayoutInflater.from(context).inflate(layoutResId, this, false)
}