Skip to content

Commit

Permalink
Add reset card database button to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
joshfriend committed Jan 6, 2022
1 parent a5cd4dc commit f511e50
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class App : DaggerApplication() {
override fun onCreate() {
super.onCreate()

if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
}

val previousVersion = defaultSharedPreferences.getInt(KEY_APP_VERSION, 0)
if (BuildConfig.DEBUG || previousVersion < BuildConfig.VERSION_CODE) {
defaultSharedPreferences.edit()
Expand All @@ -30,10 +34,6 @@ class App : DaggerApplication() {
getDatabasePath(AppDatabase.DATABASE_NAME).delete()
}

if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
}

this.configureStrictMode()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import javax.inject.Singleton
@Module
class DatabaseModule {
@Provides
@Singleton
fun provideDatabase(context: Context): AppDatabase {
return Room.databaseBuilder(
context,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
package com.fueledbycaffeine.bunnypedia.ui.settings

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.animation.Animation
import android.widget.Button
import androidx.core.content.IntentCompat
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import com.fueledbycaffeine.bunnypedia.R
import com.fueledbycaffeine.bunnypedia.database.AppDatabase
import com.fueledbycaffeine.bunnypedia.ui.MainActivity
import timber.log.Timber

class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.preferences)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val resetCardDb = preferenceManager.findPreference<Preference>(
getString(R.string.pref_key_reset_card_db)
)
resetCardDb?.setOnPreferenceClickListener {
requireContext().getDatabasePath(AppDatabase.DATABASE_NAME).delete()
activity?.also {
it.finish()
startActivity(Intent.makeRestartActivityTask(it.componentName))
}
true
}
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = super.onCreateView(inflater, container, savedInstanceState)
view?.setBackgroundColor(requireContext().getColor(R.color.black))
Expand Down
2 changes: 2 additions & 0 deletions bunnies/src/main/res/values/donottranslate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
<string name="pref_key_booster_decks">available_booster_decks</string>
<string name="pref_key_view_type">view_type</string>
<string name="pref_default_view_type">LIST</string>
<string name="pref_key_reset_data">pref_key_reset_data</string>
<string name="pref_key_reset_card_db">pref_key_reset_card_db</string>
</resources>
4 changes: 4 additions & 0 deletions bunnies/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@
<string name="grid_view">Grid View</string>
<string name="pref_view_settings">View Settings</string>
<string name="pref_title_view_type">Cards View</string>
<string name="pref_view_reset_data">Reset Data</string>
<string name="pref_title_reset_database">Card Database</string>
<string name="pref_summary_reset_database">If you experience issues with the database, like no cards showing up, use this option.</string>
<string name="reset">Reset</string>
<string name="pref_summary_view_type">How would you like to view the list of cards.</string>
<string name="card_type_senator">Senator</string>
<string name="card_type_metal">Metal</string>
Expand Down
14 changes: 14 additions & 0 deletions bunnies/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,18 @@

</PreferenceCategory>

<PreferenceCategory
android:title="@string/pref_view_reset_data"
android:key="@null"
>

<Preference
android:key="@string/pref_key_reset_card_db"
android:persistent="false"
android:title="@string/pref_title_reset_database"
android:summary="@string/pref_summary_reset_database"
/>

</PreferenceCategory>

</PreferenceScreen>

0 comments on commit f511e50

Please sign in to comment.