add dev settings gui
enable dev settings by clicking the app icon in the about screen 5 times
This commit is contained in:
		@ -11,6 +11,8 @@ object Preferences {
 | 
			
		||||
        internal set
 | 
			
		||||
    var autoplay = true
 | 
			
		||||
        internal set
 | 
			
		||||
    var devSettings = false
 | 
			
		||||
        internal set
 | 
			
		||||
    var theme = DataTypes.Theme.DARK
 | 
			
		||||
        internal set
 | 
			
		||||
 | 
			
		||||
@ -39,6 +41,15 @@ object Preferences {
 | 
			
		||||
        this.autoplay = autoplay
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun saveDevSettings(context: Context, devSettings: Boolean) {
 | 
			
		||||
        with(getSharedPref(context).edit()) {
 | 
			
		||||
            putBoolean(context.getString(R.string.save_key_dev_settings), devSettings)
 | 
			
		||||
            apply()
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        this.devSettings = devSettings
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun saveTheme(context: Context, theme: DataTypes.Theme) {
 | 
			
		||||
        with(getSharedPref(context).edit()) {
 | 
			
		||||
            putString(context.getString(R.string.save_key_theme), theme.toString())
 | 
			
		||||
@ -60,6 +71,9 @@ object Preferences {
 | 
			
		||||
        autoplay = sharedPref.getBoolean(
 | 
			
		||||
            context.getString(R.string.save_key_autoplay), true
 | 
			
		||||
        )
 | 
			
		||||
        devSettings = sharedPref.getBoolean(
 | 
			
		||||
            context.getString(R.string.save_key_dev_settings), false
 | 
			
		||||
        )
 | 
			
		||||
        theme = DataTypes.Theme.valueOf(
 | 
			
		||||
            sharedPref.getString(
 | 
			
		||||
                context.getString(R.string.save_key_theme), DataTypes.Theme.DARK.toString()
 | 
			
		||||
 | 
			
		||||
@ -6,6 +6,7 @@ import android.os.Bundle
 | 
			
		||||
import android.view.LayoutInflater
 | 
			
		||||
import android.view.View
 | 
			
		||||
import android.view.ViewGroup
 | 
			
		||||
import android.widget.Toast
 | 
			
		||||
import androidx.annotation.RawRes
 | 
			
		||||
import androidx.fragment.app.Fragment
 | 
			
		||||
import com.afollestad.materialdialogs.MaterialDialog
 | 
			
		||||
@ -13,15 +14,21 @@ import org.mosad.teapod.BuildConfig
 | 
			
		||||
import org.mosad.teapod.R
 | 
			
		||||
import org.mosad.teapod.databinding.FragmentAboutBinding
 | 
			
		||||
import org.mosad.teapod.databinding.ItemComponentBinding
 | 
			
		||||
import org.mosad.teapod.preferences.Preferences
 | 
			
		||||
import org.mosad.teapod.util.DataTypes.License
 | 
			
		||||
import org.mosad.teapod.util.ThirdPartyComponent
 | 
			
		||||
import java.lang.StringBuilder
 | 
			
		||||
import java.util.Timer
 | 
			
		||||
import kotlin.concurrent.schedule
 | 
			
		||||
 | 
			
		||||
class AboutFragment : Fragment() {
 | 
			
		||||
 | 
			
		||||
    private val teapodRepoUrl = "https://git.mosad.xyz/Seil0/teapod"
 | 
			
		||||
    private lateinit var binding: FragmentAboutBinding
 | 
			
		||||
 | 
			
		||||
    private val teapodRepoUrl = "https://git.mosad.xyz/Seil0/teapod"
 | 
			
		||||
    private val devClickMax = 5
 | 
			
		||||
    private var devClickCount = 0
 | 
			
		||||
 | 
			
		||||
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
 | 
			
		||||
        binding = FragmentAboutBinding.inflate(inflater, container, false)
 | 
			
		||||
        return binding.root
 | 
			
		||||
@ -52,6 +59,10 @@ class AboutFragment : Fragment() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun initActions() {
 | 
			
		||||
        binding.imageAppIcon.setOnClickListener {
 | 
			
		||||
            checkDevSettings()
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        binding.linearSource.setOnClickListener {
 | 
			
		||||
            startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(teapodRepoUrl)))
 | 
			
		||||
        }
 | 
			
		||||
@ -64,6 +75,30 @@ class AboutFragment : Fragment() {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * check if dev settings shall be enabled
 | 
			
		||||
     */
 | 
			
		||||
    private fun checkDevSettings() {
 | 
			
		||||
        // if the dev settings are already enabled show a toast
 | 
			
		||||
        if (Preferences.devSettings) {
 | 
			
		||||
            Toast.makeText(context, getString(R.string.dev_settings_already), Toast.LENGTH_SHORT).show()
 | 
			
		||||
            return
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // reset dev settings count after 5 seconds
 | 
			
		||||
        if (devClickCount == 0) {
 | 
			
		||||
            Timer("", false).schedule(5000) {
 | 
			
		||||
                devClickCount = 0
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        devClickCount++
 | 
			
		||||
 | 
			
		||||
        if (devClickCount == devClickMax) {
 | 
			
		||||
            Preferences.saveDevSettings(requireContext(), true)
 | 
			
		||||
            Toast.makeText(context, getString(R.string.dev_settings_enabled), Toast.LENGTH_SHORT).show()
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun getThirdPartyComponents(): List<ThirdPartyComponent> {
 | 
			
		||||
        return listOf(
 | 
			
		||||
            ThirdPartyComponent("AndroidX", "", "The Android Open Source Project",
 | 
			
		||||
 | 
			
		||||
@ -7,6 +7,7 @@ import android.util.Log
 | 
			
		||||
import android.view.LayoutInflater
 | 
			
		||||
import android.view.View
 | 
			
		||||
import android.view.ViewGroup
 | 
			
		||||
import androidx.core.view.isVisible
 | 
			
		||||
import androidx.fragment.app.Fragment
 | 
			
		||||
import com.afollestad.materialdialogs.MaterialDialog
 | 
			
		||||
import com.afollestad.materialdialogs.list.listItemsSingleChoice
 | 
			
		||||
@ -54,6 +55,8 @@ class AccountFragment : Fragment() {
 | 
			
		||||
        binding.switchSecondary.isChecked = Preferences.preferSecondary
 | 
			
		||||
        binding.switchAutoplay.isChecked = Preferences.autoplay
 | 
			
		||||
 | 
			
		||||
        binding.linearDevSettings.isVisible = Preferences.devSettings
 | 
			
		||||
 | 
			
		||||
        initActions()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -81,6 +84,14 @@ class AccountFragment : Fragment() {
 | 
			
		||||
        binding.switchAutoplay.setOnClickListener {
 | 
			
		||||
            Preferences.saveAutoplay(requireContext(), binding.switchAutoplay.isChecked)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        binding.linearExportData.setOnClickListener {
 | 
			
		||||
            println("TODO")
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        binding.linearImportData.setOnClickListener {
 | 
			
		||||
            println("TODO")
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun showLoginDialog(firstTry: Boolean) {
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user