From 8e295b1593724ce268a9dfaa03de4b1d573efdca Mon Sep 17 00:00:00 2001 From: machiav3lli Date: Sun, 18 Sep 2022 16:28:27 +0200 Subject: [PATCH] Clean up --- .../machiav3lli/fdroid/content/Preferences.kt | 16 ++----- .../fdroid/database/dao/ProductDao.kt | 2 +- .../machiav3lli/fdroid/entity/AntiFeatures.kt | 39 --------------- .../com/machiav3lli/fdroid/entity/Enums.kt | 47 +++++++++++++++++-- .../machiav3lli/fdroid/entity/SubEntities.kt | 39 --------------- .../fdroid/ui/activities/MainActivityX.kt | 2 - .../fdroid/ui/activities/PrefsActivityX.kt | 3 +- .../ui/compose/components/prefs/BasicPrefs.kt | 1 - .../fdroid/ui/fragments/BaseNavFragment.kt | 14 ------ .../FullscreenBottomSheetDialogFragment.kt | 2 +- .../fdroid/utility/PreferenceType.kt | 14 ------ .../com/machiav3lli/fdroid/utility/Utils.kt | 15 ++---- .../fdroid/utility/extension/Android.kt | 12 ----- .../fdroid/utility/extension/Resources.kt | 23 --------- .../fdroid/widget/FocusSearchView.kt | 45 ------------------ 15 files changed, 52 insertions(+), 222 deletions(-) delete mode 100644 src/main/kotlin/com/machiav3lli/fdroid/entity/AntiFeatures.kt delete mode 100644 src/main/kotlin/com/machiav3lli/fdroid/ui/fragments/BaseNavFragment.kt delete mode 100644 src/main/kotlin/com/machiav3lli/fdroid/utility/PreferenceType.kt delete mode 100644 src/main/kotlin/com/machiav3lli/fdroid/widget/FocusSearchView.kt diff --git a/src/main/kotlin/com/machiav3lli/fdroid/content/Preferences.kt b/src/main/kotlin/com/machiav3lli/fdroid/content/Preferences.kt index 716899fb..261ffd1f 100644 --- a/src/main/kotlin/com/machiav3lli/fdroid/content/Preferences.kt +++ b/src/main/kotlin/com/machiav3lli/fdroid/content/Preferences.kt @@ -272,19 +272,9 @@ object Preferences { override val values: List get() = listOf(Explore, Latest, Installed) - abstract fun getResId(configuration: Configuration): Int - - object Explore : DefaultTab(NavItem.Explore.destination) { - override fun getResId(configuration: Configuration): Int = R.id.exploreTab - } - - object Latest : DefaultTab(NavItem.Latest.destination) { - override fun getResId(configuration: Configuration): Int = R.id.latestTab - } - - object Installed : DefaultTab(NavItem.Installed.destination) { - override fun getResId(configuration: Configuration): Int = R.id.installedTab - } + object Explore : DefaultTab(NavItem.Explore.destination) + object Latest : DefaultTab(NavItem.Latest.destination) + object Installed : DefaultTab(NavItem.Installed.destination) } operator fun get(key: Key): T { diff --git a/src/main/kotlin/com/machiav3lli/fdroid/database/dao/ProductDao.kt b/src/main/kotlin/com/machiav3lli/fdroid/database/dao/ProductDao.kt index 1a3638fd..4368b7e2 100644 --- a/src/main/kotlin/com/machiav3lli/fdroid/database/dao/ProductDao.kt +++ b/src/main/kotlin/com/machiav3lli/fdroid/database/dao/ProductDao.kt @@ -51,9 +51,9 @@ import com.machiav3lli.fdroid.database.entity.Product import com.machiav3lli.fdroid.database.entity.ProductTemp import com.machiav3lli.fdroid.database.entity.asProductTemp import com.machiav3lli.fdroid.entity.Order +import com.machiav3lli.fdroid.entity.Request import com.machiav3lli.fdroid.entity.Section import com.machiav3lli.fdroid.entity.UpdateCategory -import com.machiav3lli.fdroid.ui.fragments.Request @Dao interface ProductDao : BaseDao { diff --git a/src/main/kotlin/com/machiav3lli/fdroid/entity/AntiFeatures.kt b/src/main/kotlin/com/machiav3lli/fdroid/entity/AntiFeatures.kt deleted file mode 100644 index f5386c1f..00000000 --- a/src/main/kotlin/com/machiav3lli/fdroid/entity/AntiFeatures.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.machiav3lli.fdroid.entity - -import com.machiav3lli.fdroid.R - -sealed class AntiFeatures(val name: String, val string: Int) { - object Ads : AntiFeatures("Ads", R.string.has_advertising) - object ApplicationDebuggable : - AntiFeatures("ApplicationDebuggable", R.string.compiled_for_debugging) - - object DisabledAlgorithm : - AntiFeatures("DisabledAlgorithm", R.string.signed_using_unsafe_algorithm) - - object KnownVuln : AntiFeatures("KnownVuln", R.string.has_security_vulnerabilities) - object NoSourceSince : AntiFeatures("NoSourceSince", R.string.source_code_no_longer_available) - object NonFreeAdd : AntiFeatures("NonFreeAdd", R.string.promotes_non_free_software) - object NonFreeAssets : AntiFeatures("NonFreeAssets", R.string.contains_non_free_media) - object NonFreeDep : AntiFeatures("NonFreeDep", R.string.has_non_free_dependencies) - object NonFreeNet : AntiFeatures("NonFreeNet", R.string.promotes_non_free_network_services) - object Tracking : AntiFeatures("Tracking", R.string.tracks_or_reports_your_activity) - object UpstreamNonFree : - AntiFeatures("UpstreamNonFree", R.string.upstream_source_code_is_not_free) - - object Others : AntiFeatures("Others", R.string.unknown_FORMAT) -} - -fun String.toAntiFeatures() = when (this) { - AntiFeatures.Ads.name -> AntiFeatures.Ads - AntiFeatures.ApplicationDebuggable.name -> AntiFeatures.ApplicationDebuggable - AntiFeatures.DisabledAlgorithm.name -> AntiFeatures.Ads - AntiFeatures.KnownVuln.name -> AntiFeatures.Ads - AntiFeatures.NoSourceSince.name -> AntiFeatures.Ads - AntiFeatures.NonFreeAdd.name -> AntiFeatures.Ads - AntiFeatures.NonFreeAssets.name -> AntiFeatures.Ads - AntiFeatures.NonFreeDep.name -> AntiFeatures.Ads - AntiFeatures.NonFreeNet.name -> AntiFeatures.Ads - AntiFeatures.Tracking.name -> AntiFeatures.Ads - AntiFeatures.UpstreamNonFree.name -> AntiFeatures.Ads - else -> AntiFeatures.Others -} \ No newline at end of file diff --git a/src/main/kotlin/com/machiav3lli/fdroid/entity/Enums.kt b/src/main/kotlin/com/machiav3lli/fdroid/entity/Enums.kt index 1f55dc2c..e025515a 100644 --- a/src/main/kotlin/com/machiav3lli/fdroid/entity/Enums.kt +++ b/src/main/kotlin/com/machiav3lli/fdroid/entity/Enums.kt @@ -2,12 +2,17 @@ package com.machiav3lli.fdroid.entity import androidx.annotation.DrawableRes import androidx.annotation.StringRes +import com.machiav3lli.fdroid.HELP_CHANGELOG +import com.machiav3lli.fdroid.HELP_LICENSE +import com.machiav3lli.fdroid.HELP_MATRIX +import com.machiav3lli.fdroid.HELP_SOURCECODE +import com.machiav3lli.fdroid.HELP_TELEGRAM import com.machiav3lli.fdroid.R enum class Order(@StringRes val titleResId: Int, @DrawableRes val iconResId: Int) { - NAME(R.string.name,R.drawable.ic_placeholder), - DATE_ADDED(R.string.whats_new,R.drawable.ic_placeholder), - LAST_UPDATE(R.string.recently_updated,R.drawable.ic_placeholder) + NAME(R.string.name, R.drawable.ic_placeholder), + DATE_ADDED(R.string.whats_new, R.drawable.ic_placeholder), + LAST_UPDATE(R.string.recently_updated, R.drawable.ic_placeholder) } enum class UpdateCategory(val id: Int) { @@ -21,4 +26,38 @@ enum class InstallState { INSTALLING, INSTALLED, PENDING -} \ No newline at end of file +} + +enum class Source(val sections: Boolean, val order: Boolean) { + AVAILABLE(true, true), + INSTALLED(false, true), + UPDATES(false, false), + UPDATED(false, true), + NEW(false, true) +} + +enum class LinkRef( + @StringRes val titleId: Int, + val url: String? = null +) { + Sourcecode( + titleId = R.string.source_code, + url = HELP_SOURCECODE + ), + Changelog( + titleId = R.string.changelog, + url = HELP_CHANGELOG + ), + Telegram( + titleId = R.string.group_telegram, + url = HELP_TELEGRAM + ), + Matrix( + titleId = R.string.group_matrix, + url = HELP_MATRIX + ), + License( + titleId = R.string.license, + url = HELP_LICENSE + ), +} diff --git a/src/main/kotlin/com/machiav3lli/fdroid/entity/SubEntities.kt b/src/main/kotlin/com/machiav3lli/fdroid/entity/SubEntities.kt index 5f2c75fb..61205c19 100644 --- a/src/main/kotlin/com/machiav3lli/fdroid/entity/SubEntities.kt +++ b/src/main/kotlin/com/machiav3lli/fdroid/entity/SubEntities.kt @@ -18,11 +18,6 @@ import androidx.compose.material.icons.rounded.Launch import androidx.compose.material.icons.rounded.Share import androidx.compose.material.icons.rounded.Tune import androidx.compose.ui.graphics.vector.ImageVector -import com.machiav3lli.fdroid.HELP_CHANGELOG -import com.machiav3lli.fdroid.HELP_LICENSE -import com.machiav3lli.fdroid.HELP_MATRIX -import com.machiav3lli.fdroid.HELP_SOURCECODE -import com.machiav3lli.fdroid.HELP_TELEGRAM import com.machiav3lli.fdroid.R import kotlinx.serialization.Serializable import kotlinx.serialization.decodeFromString @@ -98,32 +93,6 @@ enum class AntiFeature(val key: String, @StringRes val titleResId: Int) { NSFW("NSFW", R.string.not_safe_for_work) } -enum class LinkRef( - @StringRes val titleId: Int, - val url: String? = null -) { - Sourcecode( - titleId = R.string.source_code, - url = HELP_SOURCECODE - ), - Changelog( - titleId = R.string.changelog, - url = HELP_CHANGELOG - ), - Telegram( - titleId = R.string.group_telegram, - url = HELP_TELEGRAM - ), - Matrix( - titleId = R.string.group_matrix, - url = HELP_MATRIX - ), - License( - titleId = R.string.license, - url = HELP_LICENSE - ), -} - sealed interface ComponentState { val icon: ImageVector val textId: Int @@ -194,14 +163,6 @@ class DonateType(donate: Donate, context: Context) : LinkType( } ) -enum class Source(val sections: Boolean, val order: Boolean) { - AVAILABLE(true, true), - INSTALLED(false, true), - UPDATES(false, false), - UPDATED(false, true), - NEW(false, true) -} - sealed class Request { internal abstract val id: Int internal abstract val installed: Boolean diff --git a/src/main/kotlin/com/machiav3lli/fdroid/ui/activities/MainActivityX.kt b/src/main/kotlin/com/machiav3lli/fdroid/ui/activities/MainActivityX.kt index 20b5137b..b4feb678 100644 --- a/src/main/kotlin/com/machiav3lli/fdroid/ui/activities/MainActivityX.kt +++ b/src/main/kotlin/com/machiav3lli/fdroid/ui/activities/MainActivityX.kt @@ -76,13 +76,11 @@ class MainActivityX : AppCompatActivity() { get() = (application as MainApplication).db private var currentTheme by Delegates.notNull() - private var currentTab by Delegates.notNull() @OptIn(ExperimentalAnimationApi::class, ExperimentalMaterial3Api::class) override fun onCreate(savedInstanceState: Bundle?) { (application as MainApplication).mActivity = this currentTheme = Preferences[Preferences.Key.Theme].getResId(resources.configuration) - currentTab = Preferences[Preferences.Key.DefaultTab].getResId(resources.configuration) setCustomTheme() super.onCreate(savedInstanceState) diff --git a/src/main/kotlin/com/machiav3lli/fdroid/ui/activities/PrefsActivityX.kt b/src/main/kotlin/com/machiav3lli/fdroid/ui/activities/PrefsActivityX.kt index 6cb78985..4487b738 100644 --- a/src/main/kotlin/com/machiav3lli/fdroid/ui/activities/PrefsActivityX.kt +++ b/src/main/kotlin/com/machiav3lli/fdroid/ui/activities/PrefsActivityX.kt @@ -25,7 +25,6 @@ import com.machiav3lli.fdroid.BuildConfig import com.machiav3lli.fdroid.ContextWrapperX import com.machiav3lli.fdroid.MainApplication import com.machiav3lli.fdroid.NAV_PREFS -import com.machiav3lli.fdroid.R import com.machiav3lli.fdroid.content.Preferences import com.machiav3lli.fdroid.installer.AppInstaller import com.machiav3lli.fdroid.service.Connection @@ -147,7 +146,7 @@ class PrefsActivityX : AppCompatActivity() { private fun handleSpecialIntent(specialIntent: SpecialIntent) { when (specialIntent) { - is SpecialIntent.Updates -> navController.navigate(R.id.installedTab) + is SpecialIntent.Updates -> navController.navigate(NavItem.Installed.destination) is SpecialIntent.Install -> { val packageName = specialIntent.packageName if (!packageName.isNullOrEmpty()) { diff --git a/src/main/kotlin/com/machiav3lli/fdroid/ui/compose/components/prefs/BasicPrefs.kt b/src/main/kotlin/com/machiav3lli/fdroid/ui/compose/components/prefs/BasicPrefs.kt index 54503cad..89cc75b9 100644 --- a/src/main/kotlin/com/machiav3lli/fdroid/ui/compose/components/prefs/BasicPrefs.kt +++ b/src/main/kotlin/com/machiav3lli/fdroid/ui/compose/components/prefs/BasicPrefs.kt @@ -247,7 +247,6 @@ fun EnumPreference( ) } - @Composable fun IntPreference( modifier: Modifier = Modifier, diff --git a/src/main/kotlin/com/machiav3lli/fdroid/ui/fragments/BaseNavFragment.kt b/src/main/kotlin/com/machiav3lli/fdroid/ui/fragments/BaseNavFragment.kt deleted file mode 100644 index df40f207..00000000 --- a/src/main/kotlin/com/machiav3lli/fdroid/ui/fragments/BaseNavFragment.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.machiav3lli.fdroid.ui.fragments - -import android.os.Bundle -import android.view.View -import androidx.fragment.app.Fragment - -abstract class BaseNavFragment : Fragment() { - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - setupLayout() - } - - abstract fun setupLayout() -} \ No newline at end of file diff --git a/src/main/kotlin/com/machiav3lli/fdroid/ui/fragments/FullscreenBottomSheetDialogFragment.kt b/src/main/kotlin/com/machiav3lli/fdroid/ui/fragments/FullscreenBottomSheetDialogFragment.kt index d1304af0..381c902b 100644 --- a/src/main/kotlin/com/machiav3lli/fdroid/ui/fragments/FullscreenBottomSheetDialogFragment.kt +++ b/src/main/kotlin/com/machiav3lli/fdroid/ui/fragments/FullscreenBottomSheetDialogFragment.kt @@ -8,7 +8,7 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialogFragment -abstract class FullscreenBottomSheetDialogFragment() : BottomSheetDialogFragment() { +abstract class FullscreenBottomSheetDialogFragment : BottomSheetDialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val sheet = super.onCreateDialog(savedInstanceState) as BottomSheetDialog sheet.setOnShowListener { diff --git a/src/main/kotlin/com/machiav3lli/fdroid/utility/PreferenceType.kt b/src/main/kotlin/com/machiav3lli/fdroid/utility/PreferenceType.kt deleted file mode 100644 index e00b3505..00000000 --- a/src/main/kotlin/com/machiav3lli/fdroid/utility/PreferenceType.kt +++ /dev/null @@ -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, - val key: String - ) : PreferenceType - - data class Data(val title: String, val description: String, val key: String) : PreferenceType -} \ No newline at end of file diff --git a/src/main/kotlin/com/machiav3lli/fdroid/utility/Utils.kt b/src/main/kotlin/com/machiav3lli/fdroid/utility/Utils.kt index 146b9f88..8dccbcb7 100644 --- a/src/main/kotlin/com/machiav3lli/fdroid/utility/Utils.kt +++ b/src/main/kotlin/com/machiav3lli/fdroid/utility/Utils.kt @@ -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 } diff --git a/src/main/kotlin/com/machiav3lli/fdroid/utility/extension/Android.kt b/src/main/kotlin/com/machiav3lli/fdroid/utility/extension/Android.kt index 4539b7b4..beeb927b 100644 --- a/src/main/kotlin/com/machiav3lli/fdroid/utility/extension/Android.kt +++ b/src/main/kotlin/com/machiav3lli/fdroid/utility/extension/Android.kt @@ -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 - } - } - } } diff --git a/src/main/kotlin/com/machiav3lli/fdroid/utility/extension/Resources.kt b/src/main/kotlin/com/machiav3lli/fdroid/utility/extension/Resources.kt index 0e23fa5b..4d6690be 100644 --- a/src/main/kotlin/com/machiav3lli/fdroid/utility/extension/Resources.kt +++ b/src/main/kotlin/com/machiav3lli/fdroid/utility/extension/Resources.kt @@ -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) -} \ No newline at end of file diff --git a/src/main/kotlin/com/machiav3lli/fdroid/widget/FocusSearchView.kt b/src/main/kotlin/com/machiav3lli/fdroid/widget/FocusSearchView.kt deleted file mode 100644 index a56d0b8c..00000000 --- a/src/main/kotlin/com/machiav3lli/fdroid/widget/FocusSearchView.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.machiav3lli.fdroid.widget - -import android.content.Context -import android.util.AttributeSet -import android.view.KeyEvent -import androidx.appcompat.widget.SearchView -import com.machiav3lli.fdroid.R - -class FocusSearchView : SearchView { - constructor(context: Context) : super(context) - constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) - constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super( - context, - attrs, - defStyleAttr - ) - - var allowFocus = true - - init { - maxWidth = Int.MAX_VALUE - queryHint = context.getString(R.string.search) - } - - override fun dispatchKeyEventPreIme(event: KeyEvent): Boolean { - // Always clear focus on back press - return if (hasFocus() && event.keyCode == KeyEvent.KEYCODE_BACK) { - if (event.action == KeyEvent.ACTION_UP) { - clearFocus() - } - true - } else { - super.dispatchKeyEventPreIme(event) - } - } - - override fun setIconified(iconify: Boolean) { - super.setIconified(iconify) - - // Don't focus view and raise keyboard unless allowed - if (!iconify && !allowFocus) { - clearFocus() - } - } -}