Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c3ba1566 authored by Fynn Godau's avatar Fynn Godau Committed by Jonathan Klee
Browse files

Add preference for auto-purchase

parent edb9d3b1
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -190,10 +190,12 @@ object SettingsContract {
        fun getContentType(context: Context) = "vnd.android.cursor.item/vnd.${getAuthority(context)}.$id"

        const val LICENSING = "vending_licensing"
        const val LICENSING_PURCHASE_FREE_APPS = "vending_licensing_purchase_free_apps"
        const val BILLING = "vending_billing"

        val PROJECTION = arrayOf(
            LICENSING,
            LICENSING_PURCHASE_FREE_APPS,
            BILLING,
        )
    }
+2 −0
Original line number Diff line number Diff line
@@ -348,6 +348,7 @@ class SettingsProvider : ContentProvider() {
    private fun queryVending(p: Array<out String>): Cursor = MatrixCursor(p).addRow(p) { key ->
        when (key) {
            Vending.LICENSING -> getSettingsBoolean(key, false)
            Vending.LICENSING_PURCHASE_FREE_APPS -> getSettingsBoolean(key, false)
            Vending.BILLING -> getSettingsBoolean(key, false)
            else -> throw IllegalArgumentException("Unknown key: $key")
        }
@@ -359,6 +360,7 @@ class SettingsProvider : ContentProvider() {
        values.valueSet().forEach { (key, value) ->
            when (key) {
                Vending.LICENSING -> editor.putBoolean(key, value as Boolean)
                Vending.LICENSING_PURCHASE_FREE_APPS -> editor.putBoolean(key, value as Boolean)
                Vending.BILLING -> editor.putBoolean(key, value as Boolean)
                else -> throw IllegalArgumentException("Unknown key: $key")
            }
+15 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ import org.microg.gms.vending.VendingPreferences

class VendingFragment : PreferenceFragmentCompat() {
    private lateinit var licensingEnabled: TwoStatePreference
    private lateinit var licensingPurchaseFreeAppsEnabled: TwoStatePreference
    private lateinit var iapEnable: TwoStatePreference

    override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
@@ -36,6 +37,18 @@ class VendingFragment : PreferenceFragmentCompat() {
            true
        }

        licensingPurchaseFreeAppsEnabled = preferenceScreen.findPreference(PREF_LICENSING_PURCHASE_FREE_APPS_ENABLED) ?: licensingPurchaseFreeAppsEnabled
        licensingPurchaseFreeAppsEnabled.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
            val appContext = requireContext().applicationContext
            lifecycleScope.launchWhenResumed {
                if (newValue is Boolean) {
                    VendingPreferences.setLicensingPurchaseFreeAppsEnabled(appContext, newValue)
                }
                updateContent()
            }
            true
        }

        iapEnable = preferenceScreen.findPreference(PREF_IAP_ENABLED) ?: iapEnable
        iapEnable.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
            val appContext = requireContext().applicationContext
@@ -58,12 +71,14 @@ class VendingFragment : PreferenceFragmentCompat() {
        val appContext = requireContext().applicationContext
        lifecycleScope.launchWhenResumed {
            licensingEnabled.isChecked = VendingPreferences.isLicensingEnabled(appContext)
            licensingPurchaseFreeAppsEnabled.isChecked = VendingPreferences.isLicensingPurchaseFreeAppsEnabled(appContext)
            iapEnable.isChecked = VendingPreferences.isBillingEnabled(appContext)
        }
    }

    companion object {
        const val PREF_LICENSING_ENABLED = "vending_licensing"
        const val PREF_LICENSING_PURCHASE_FREE_APPS_ENABLED = "vending_licensing_purchase_free_apps"
        const val PREF_IAP_ENABLED = "vending_iap"
    }
}
 No newline at end of file
+15 −0
Original line number Diff line number Diff line
@@ -24,6 +24,21 @@ object VendingPreferences {
        }
    }

    @JvmStatic
    fun isLicensingPurchaseFreeAppsEnabled(context: Context): Boolean {
        val projection = arrayOf(SettingsContract.Vending.LICENSING_PURCHASE_FREE_APPS)
        return SettingsContract.getSettings(context, SettingsContract.Vending.getContentUri(context), projection) { c ->
            c.getInt(0) != 0
        }
    }

    @JvmStatic
    fun setLicensingPurchaseFreeAppsEnabled(context: Context, enabled: Boolean) {
        SettingsContract.setSettings(context, SettingsContract.Vending.getContentUri(context)) {
            put(SettingsContract.Vending.LICENSING_PURCHASE_FREE_APPS, enabled)
        }
    }

    @JvmStatic
    fun isBillingEnabled(context: Context): Boolean {
        val projection = arrayOf(SettingsContract.Vending.BILLING)
+2 −0
Original line number Diff line number Diff line
@@ -207,6 +207,8 @@ Versuche es später noch einmal."</string>
    <string name="signin_picker_subtitle">weiter zu <xliff:g example="F-Droid">%1$s</xliff:g></string>
    <string name="signin_subtext_sharing">Um fortzufahren, wird microG Name, E-Mail-Adresse und Profilbild deines Google-Kontos mit <xliff:g example="F-Droid">%1$s</xliff:g> teilen.</string>
    <string name="pref_vending_license_enable_summary">Einige Apps erfordern einen Nachweis, dass du sie auf Google Play gekauft hast. Wenn dies von einer App verlangt wird, kann microG einen Kaufnachweis von Google herunterladen. Wenn deaktiviert oder kein Google-Konto hinzugefügt wurde, werden Anfragen zur Lizenzverifizierung ignoriert.</string>
    <string name="pref_vending_licensing_purchase_free_apps_switch">Kostenfreie Apps automatisch zur Mediathek hinzufügen</string>
    <string name="pref_vending_licensing_purchase_free_apps_summary">Kostenfreie Apps können prüfen, ob sie aus dem Google Play-Store bezogen wurden. Wenn du kostenfreie Apps automatisch zur Konto-Mediathek hinzufügst, wird dieser Test für alle Apps bestanden, die kostenlos und für dich derzeit verfügbar sind.</string>
    <string name="pref_recaptcha_test_title">ReCAPTCHA testen</string>
    <string name="signin_picker_title">Ein Konto auswählen</string>
    <string name="signin_subtext_policy_privacy">Datenschutzerklärung</string>
Loading