Skip to content

Commit

Permalink
Codacy
Browse files Browse the repository at this point in the history
  • Loading branch information
nicbn committed Jan 28, 2022
1 parent 9c5a27b commit 71f1270
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ import com.readystatesoftware.systembartint.SystemBarTintManager
import java.io.File

class PreferencesActivity : ThemedActivity(), FolderChooserDialog.FolderCallback {
private companion object {
const val SAVED_INSTANCE_STATE_KEY = "savedInstanceState"
}

lateinit var layout: View

override fun onCreate(savedInstanceState: Bundle?) {
var savedInstanceState = savedInstanceState
if (savedInstanceState == null && intent.hasExtra("savedInstanceState")) {
savedInstanceState = intent.getBundleExtra("savedInstanceState")
if (savedInstanceState == null && intent.hasExtra(SAVED_INSTANCE_STATE_KEY)) {
savedInstanceState = intent.getBundleExtra(SAVED_INSTANCE_STATE_KEY)
}

super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -99,13 +103,16 @@ class PreferencesActivity : ThemedActivity(), FolderChooserDialog.FolderCallback
val bundle = Bundle()
onSaveInstanceState(bundle)
val intent = Intent(this, javaClass)
intent.putExtra("savedInstanceState", bundle)
intent.putExtra(SAVED_INSTANCE_STATE_KEY, bundle)

finish()
startActivity(intent)
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out)
}

/**
* Push a new fragment into the stack
*/
fun pushFragment(fragment: BasePrefsFragment) {
supportFragmentManager.commit {
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
Expand All @@ -116,6 +123,11 @@ class PreferencesActivity : ThemedActivity(), FolderChooserDialog.FolderCallback
}
}

/**
* Rebuild the nav bar
*
* Used to update color
*/
fun invalidateNavBar() {
val primaryColor = ColorPreferenceHelper
.getPrimary(currentColorPreference, MainActivity.currentTab)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,70 @@ import com.amaze.filemanager.ui.theme.AppTheme
class AppearancePrefsFragment : BasePrefsFragment() {
override val title = R.string.appearance

private lateinit var gridColumnItems: Array<String>
private var currentTheme = 0
private var gridColumnPref: Preference? = null

private val onClickTheme = Preference.OnPreferenceClickListener {
val builder = MaterialDialog.Builder(activity)
builder.items(R.array.theme)
.itemsCallbackSingleChoice(currentTheme) { dialog, _, which, _ ->
val editor = activity.prefs.edit()
editor.putString(PreferencesConstants.FRAGMENT_THEME, which.toString())
editor.apply()

activity.utilsProvider.themeManager.appTheme =
AppTheme.getTheme(activity, which)
activity.recreate()

dialog.dismiss()
true
}
.title(R.string.theme)
.build()
.show()

true
}

private val onClickGridColumn = Preference.OnPreferenceClickListener {
val builder = MaterialDialog.Builder(activity)
builder.theme(activity.utilsProvider.appTheme.getMaterialDialogTheme(activity))
builder.title(R.string.gridcolumnno)
var current = activity
.prefs
.getString(PreferencesConstants.PREFERENCE_GRID_COLUMNS, "-1")!!
.toInt() - 1
if (current < 0) current = 0
builder
.items(R.array.columns)
.itemsCallbackSingleChoice(current) { dialog, _, which, _ ->
val editor = activity.prefs.edit()
editor.putString(
PreferencesConstants.PREFERENCE_GRID_COLUMNS,
if (which != 0) gridColumnItems[which] else "-1"
)
editor.apply()
dialog.dismiss()
updateGridColumnSummary()
true
}
builder.build().show()

true
}

override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.appearance_prefs, rootKey)

val themePref = findPreference<Preference>(PreferencesConstants.FRAGMENT_THEME)
val themes = resources.getStringArray(R.array.theme)
val currentTheme = activity
currentTheme = activity
.prefs
.getString(PreferencesConstants.FRAGMENT_THEME, "4")!!
.toInt()
themePref?.summary = themes[currentTheme]
themePref?.onPreferenceClickListener = Preference.OnPreferenceClickListener {
val builder = MaterialDialog.Builder(activity)
builder.items(*themes)
.itemsCallbackSingleChoice(currentTheme) { dialog, _, which, _ ->
val editor = activity.prefs.edit()
editor.putString(PreferencesConstants.FRAGMENT_THEME, which.toString())
editor.apply()

activity.utilsProvider.themeManager.appTheme =
AppTheme.getTheme(activity, which)
activity.recreate()

dialog.dismiss()
true
}
.title(R.string.theme)
.build()
.show()

true
}
themePref?.onPreferenceClickListener = onClickTheme

findPreference<Preference>(PreferencesConstants.PREFERENCE_COLORED_NAVIGATION)
?.let {
Expand All @@ -81,35 +112,10 @@ class AppearancePrefsFragment : BasePrefsFragment() {
true
}

val gridColumnItems = resources.getStringArray(R.array.columns)
gridColumnItems = resources.getStringArray(R.array.columns)
gridColumnPref = findPreference(PreferencesConstants.PREFERENCE_GRID_COLUMNS)
updateGridColumnSummary()
gridColumnPref?.onPreferenceClickListener = Preference.OnPreferenceClickListener {
val builder = MaterialDialog.Builder(activity)
builder.theme(activity.utilsProvider.appTheme.getMaterialDialogTheme(activity))
builder.title(R.string.gridcolumnno)
var current = activity
.prefs
.getString(PreferencesConstants.PREFERENCE_GRID_COLUMNS, "-1")!!
.toInt() - 1
if (current < 0) current = 0
builder
.items(*gridColumnItems)
.itemsCallbackSingleChoice(current) { dialog, _, which, _ ->
val editor = activity.prefs.edit()
editor.putString(
PreferencesConstants.PREFERENCE_GRID_COLUMNS,
if (which != 0) gridColumnItems[which] else "-1"
)
editor.apply()
dialog.dismiss()
updateGridColumnSummary()
true
}
builder.build().show()

true
}
gridColumnPref?.onPreferenceClickListener = onClickGridColumn
}

private fun updateGridColumnSummary() {
Expand Down
Loading

0 comments on commit 71f1270

Please sign in to comment.