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

@ -272,19 +272,9 @@ object Preferences {
override val values: List<DefaultTab> override val values: List<DefaultTab>
get() = listOf(Explore, Latest, Installed) get() = listOf(Explore, Latest, Installed)
abstract fun getResId(configuration: Configuration): Int object Explore : DefaultTab(NavItem.Explore.destination)
object Latest : DefaultTab(NavItem.Latest.destination)
object Explore : DefaultTab(NavItem.Explore.destination) { object Installed : DefaultTab(NavItem.Installed.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
}
} }
operator fun <T> get(key: Key<T>): T { operator fun <T> get(key: Key<T>): T {

View File

@ -51,9 +51,9 @@ import com.machiav3lli.fdroid.database.entity.Product
import com.machiav3lli.fdroid.database.entity.ProductTemp import com.machiav3lli.fdroid.database.entity.ProductTemp
import com.machiav3lli.fdroid.database.entity.asProductTemp import com.machiav3lli.fdroid.database.entity.asProductTemp
import com.machiav3lli.fdroid.entity.Order import com.machiav3lli.fdroid.entity.Order
import com.machiav3lli.fdroid.entity.Request
import com.machiav3lli.fdroid.entity.Section import com.machiav3lli.fdroid.entity.Section
import com.machiav3lli.fdroid.entity.UpdateCategory import com.machiav3lli.fdroid.entity.UpdateCategory
import com.machiav3lli.fdroid.ui.fragments.Request
@Dao @Dao
interface ProductDao : BaseDao<Product> { interface ProductDao : BaseDao<Product> {

View File

@ -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
}

View File

@ -2,12 +2,17 @@ package com.machiav3lli.fdroid.entity
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.annotation.StringRes 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 import com.machiav3lli.fdroid.R
enum class Order(@StringRes val titleResId: Int, @DrawableRes val iconResId: Int) { enum class Order(@StringRes val titleResId: Int, @DrawableRes val iconResId: Int) {
NAME(R.string.name,R.drawable.ic_placeholder), NAME(R.string.name, R.drawable.ic_placeholder),
DATE_ADDED(R.string.whats_new,R.drawable.ic_placeholder), DATE_ADDED(R.string.whats_new, R.drawable.ic_placeholder),
LAST_UPDATE(R.string.recently_updated,R.drawable.ic_placeholder) LAST_UPDATE(R.string.recently_updated, R.drawable.ic_placeholder)
} }
enum class UpdateCategory(val id: Int) { enum class UpdateCategory(val id: Int) {
@ -22,3 +27,37 @@ enum class InstallState {
INSTALLED, INSTALLED,
PENDING PENDING
} }
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
),
}

View File

@ -18,11 +18,6 @@ import androidx.compose.material.icons.rounded.Launch
import androidx.compose.material.icons.rounded.Share import androidx.compose.material.icons.rounded.Share
import androidx.compose.material.icons.rounded.Tune import androidx.compose.material.icons.rounded.Tune
import androidx.compose.ui.graphics.vector.ImageVector 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 com.machiav3lli.fdroid.R
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString 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) 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 { sealed interface ComponentState {
val icon: ImageVector val icon: ImageVector
val textId: Int 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 { sealed class Request {
internal abstract val id: Int internal abstract val id: Int
internal abstract val installed: Boolean internal abstract val installed: Boolean

View File

@ -76,13 +76,11 @@ class MainActivityX : AppCompatActivity() {
get() = (application as MainApplication).db get() = (application as MainApplication).db
private var currentTheme by Delegates.notNull<Int>() private var currentTheme by Delegates.notNull<Int>()
private var currentTab by Delegates.notNull<Int>()
@OptIn(ExperimentalAnimationApi::class, ExperimentalMaterial3Api::class) @OptIn(ExperimentalAnimationApi::class, ExperimentalMaterial3Api::class)
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
(application as MainApplication).mActivity = this (application as MainApplication).mActivity = this
currentTheme = Preferences[Preferences.Key.Theme].getResId(resources.configuration) currentTheme = Preferences[Preferences.Key.Theme].getResId(resources.configuration)
currentTab = Preferences[Preferences.Key.DefaultTab].getResId(resources.configuration)
setCustomTheme() setCustomTheme()
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)

View File

@ -25,7 +25,6 @@ import com.machiav3lli.fdroid.BuildConfig
import com.machiav3lli.fdroid.ContextWrapperX import com.machiav3lli.fdroid.ContextWrapperX
import com.machiav3lli.fdroid.MainApplication import com.machiav3lli.fdroid.MainApplication
import com.machiav3lli.fdroid.NAV_PREFS import com.machiav3lli.fdroid.NAV_PREFS
import com.machiav3lli.fdroid.R
import com.machiav3lli.fdroid.content.Preferences import com.machiav3lli.fdroid.content.Preferences
import com.machiav3lli.fdroid.installer.AppInstaller import com.machiav3lli.fdroid.installer.AppInstaller
import com.machiav3lli.fdroid.service.Connection import com.machiav3lli.fdroid.service.Connection
@ -147,7 +146,7 @@ class PrefsActivityX : AppCompatActivity() {
private fun handleSpecialIntent(specialIntent: SpecialIntent) { private fun handleSpecialIntent(specialIntent: SpecialIntent) {
when (specialIntent) { when (specialIntent) {
is SpecialIntent.Updates -> navController.navigate(R.id.installedTab) is SpecialIntent.Updates -> navController.navigate(NavItem.Installed.destination)
is SpecialIntent.Install -> { is SpecialIntent.Install -> {
val packageName = specialIntent.packageName val packageName = specialIntent.packageName
if (!packageName.isNullOrEmpty()) { if (!packageName.isNullOrEmpty()) {

View File

@ -247,7 +247,6 @@ fun EnumPreference(
) )
} }
@Composable @Composable
fun IntPreference( fun IntPreference(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,

View File

@ -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()
}

View File

@ -8,7 +8,7 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.bottomsheet.BottomSheetDialogFragment
abstract class FullscreenBottomSheetDialogFragment() : BottomSheetDialogFragment() { abstract class FullscreenBottomSheetDialogFragment : BottomSheetDialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val sheet = super.onCreateDialog(savedInstanceState) as BottomSheetDialog val sheet = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
sheet.setOnShowListener { sheet.setOnShowListener {

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.pm.Signature
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Typeface import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.net.Uri import android.net.Uri
import android.provider.Settings import android.provider.Settings
import android.text.SpannableStringBuilder 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.Android
import com.machiav3lli.fdroid.utility.extension.android.singleSignature import com.machiav3lli.fdroid.utility.extension.android.singleSignature
import com.machiav3lli.fdroid.utility.extension.android.versionCodeCompat 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.hex
import com.machiav3lli.fdroid.utility.extension.text.nullIfEmpty import com.machiav3lli.fdroid.utility.extension.text.nullIfEmpty
import com.topjohnwu.superuser.Shell 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 { fun calculateHash(signature: Signature): String {
return MessageDigest.getInstance("MD5").digest(signature.toCharsString().toByteArray()) return MessageDigest.getInstance("MD5").digest(signature.toCharsString().toByteArray())
.hex() .hex()
@ -234,14 +225,14 @@ val isDarkTheme: Boolean
get() = when (Preferences[Preferences.Key.Theme]) { get() = when (Preferences[Preferences.Key.Theme]) {
is Preferences.Theme.Light -> false is Preferences.Theme.Light -> false
is Preferences.Theme.Dark -> true is Preferences.Theme.Dark -> true
is Preferences.Theme.Amoled -> true is Preferences.Theme.Black -> true
else -> false else -> false
} }
val isBlackTheme: Boolean val isBlackTheme: Boolean
get() = when (Preferences[Preferences.Key.Theme]) { get() = when (Preferences[Preferences.Key.Theme]) {
is Preferences.Theme.Amoled -> true is Preferences.Theme.Black -> true
is Preferences.Theme.AmoledSystem -> true is Preferences.Theme.SystemBlack -> true
else -> false else -> false
} }

View File

@ -59,16 +59,4 @@ object Android {
get() = (if (sdk(28)) android.content.pm.PackageManager.GET_SIGNING_CERTIFICATES else 0) or get() = (if (sdk(28)) android.content.pm.PackageManager.GET_SIGNING_CERTIFICATES else 0) or
@Suppress("DEPRECATION") android.content.pm.PackageManager.GET_SIGNATURES @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.Context
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.content.res.Resources import android.content.res.Resources
import android.graphics.Typeface
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.util.TypedValue import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.AttrRes import androidx.annotation.AttrRes
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
@ -18,11 +14,6 @@ import androidx.core.content.res.ResourcesCompat
import com.google.android.material.textview.MaterialTextView import com.google.android.material.textview.MaterialTextView
import kotlin.math.roundToInt 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 { fun Context.getColorFromAttr(@AttrRes attrResId: Int): ColorStateList {
val typedArray = obtainStyledAttributes(intArrayOf(attrResId)) val typedArray = obtainStyledAttributes(intArrayOf(attrResId))
val (colorStateList, resId) = try { val (colorStateList, resId) = try {
@ -33,16 +24,6 @@ fun Context.getColorFromAttr(@AttrRes attrResId: Int): ColorStateList {
return colorStateList ?: ContextCompat.getColorStateList(this, resId)!! 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 = fun Context.getDrawableCompat(@DrawableRes resId: Int): Drawable =
ResourcesCompat.getDrawable(resources, resId, theme) ?: ContextCompat.getDrawable(this, resId)!! 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() val realSize = (size * resources.displayMetrics.scaledDensity).roundToInt()
setTextSize(TypedValue.COMPLEX_UNIT_PX, realSize.toFloat()) setTextSize(TypedValue.COMPLEX_UNIT_PX, realSize.toFloat())
} }
fun ViewGroup.inflate(layoutResId: Int): View {
return LayoutInflater.from(context).inflate(layoutResId, this, false)
}

View File

@ -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()
}
}
}