Skip to content

Commit

Permalink
Applies requests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicbn committed Jan 26, 2022
1 parent 8fba01e commit 3e7ffe2
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ import com.readystatesoftware.systembartint.SystemBarTintManager
import java.io.File

class PreferencesActivity : ThemedActivity(), FolderChooserDialog.FolderCallback {
val layout: View
get() = _layout!!
private var _layout: View? = null
lateinit var layout: View

override fun onCreate(savedInstanceState: Bundle?) {
var savedInstanceState = savedInstanceState
Expand All @@ -58,7 +56,7 @@ class PreferencesActivity : ThemedActivity(), FolderChooserDialog.FolderCallback
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_preferences)

_layout = findViewById(R.id.activity_preferences)
layout = findViewById(R.id.activity_preferences)

val toolbar = findViewById<Toolbar>(R.id.toolbar)
setSupportActionBar(toolbar)
Expand All @@ -81,11 +79,11 @@ class PreferencesActivity : ThemedActivity(), FolderChooserDialog.FolderCallback
return
}

val x = Intent(this, MainActivity::class.java)
x.action = Intent.ACTION_MAIN
x.action = Intent.CATEGORY_LAUNCHER
val intent = Intent(this, MainActivity::class.java)
intent.action = Intent.ACTION_MAIN
intent.action = Intent.CATEGORY_LAUNCHER
finish()
startActivity(x)
startActivity(intent)
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out)
}

Expand Down Expand Up @@ -129,10 +127,10 @@ class PreferencesActivity : ThemedActivity(), FolderChooserDialog.FolderCallback
val tintManager = SystemBarTintManager(this)
tintManager.isStatusBarTintEnabled = true
tintManager.setStatusBarTintColor(primaryColor)
val p = findViewById<View>(R.id.activity_preferences).layoutParams
val layoutParams = findViewById<View>(R.id.activity_preferences).layoutParams
as ViewGroup.MarginLayoutParams
val config = tintManager.config
p.setMargins(0, config.statusBarHeight, 0, 0)
layoutParams.setMargins(0, config.statusBarHeight, 0, 0)
} else if (Build.VERSION.SDK_INT >= 21) {
val colouredNavigation = getBoolean(PreferencesConstants.PREFERENCE_COLORED_NAVIGATION)
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.core.util.Pair;
import androidx.preference.Preference.BaseSavedState;
import androidx.preference.PreferenceDialogFragmentCompat;
Expand Down Expand Up @@ -284,13 +285,13 @@ public void onDialogClosed(boolean positiveResult) {
}
}

public static int getTitle(int i) {
if (i == RANDOM_INDEX) {
public static @StringRes int getTitle(int index) {
if (index == RANDOM_INDEX) {
return R.string.random;
} else if (i == CUSTOM_INDEX) {
} else if (index == CUSTOM_INDEX) {
return R.string.custom;
} else if (i >= 0 && i < COLORS.length) {
return COLORS[i].first;
} else if (index >= 0 && index < COLORS.length) {
return COLORS[index].first;
} else {
return COLORS[0].first;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

package com.amaze.filemanager.ui.fragments.preference_fragments

import android.os.Build
import android.os.Bundle
import androidx.preference.Preference
import com.afollestad.materialdialogs.MaterialDialog
Expand Down Expand Up @@ -64,17 +63,15 @@ class AppearancePrefsFragment : BasePrefsFragment() {
true
}

val navPref = findPreference<Preference>(
PreferencesConstants.PREFERENCE_COLORED_NAVIGATION
)!!
if (Build.VERSION.SDK_INT >= 21) {
navPref.isEnabled = true
navPref.onPreferenceClickListener = Preference.OnPreferenceClickListener {
activity.invalidateNavBar()
findPreference<Preference>(PreferencesConstants.PREFERENCE_COLORED_NAVIGATION)
?.let {
it.isEnabled = true
it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
activity.invalidateNavBar()

true
true
}
}
}

val colorPrefs = findPreference<Preference>(
PreferencesConstants.PREFERENCE_SELECT_COLOR_CONFIG
Expand All @@ -88,7 +85,7 @@ class AppearancePrefsFragment : BasePrefsFragment() {
val gridColumnItems = resources.getStringArray(R.array.columns)
gridColumnPref = findPreference(PreferencesConstants.PREFERENCE_GRID_COLUMNS)
updateGridColumnSummary()
gridColumnPref!!.onPreferenceClickListener = Preference.OnPreferenceClickListener {
gridColumnPref?.onPreferenceClickListener = Preference.OnPreferenceClickListener {
val builder = MaterialDialog.Builder(activity)
builder.theme(activity.utilsProvider.appTheme.getMaterialDialogTheme(activity))
builder.title(R.string.gridcolumnno)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ class BehaviorPrefsFragment : BasePrefsFragment(), FolderChooserDialog.FolderCal
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.behavior_prefs, rootKey)

findPreference<Preference>("clear_open_file")!!.onPreferenceClickListener =
findPreference<Preference>("clear_open_file")?.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
clearPreferences(activity.prefs)
AppConfig.toast(getActivity(), activity.getString(R.string.done))
true
}

findPreference<Preference>(PreferencesConstants.PREFERENCE_ZIP_EXTRACT_PATH)!!
.onPreferenceClickListener = Preference.OnPreferenceClickListener {
findPreference<Preference>(PreferencesConstants.PREFERENCE_ZIP_EXTRACT_PATH)
?.onPreferenceClickListener = Preference.OnPreferenceClickListener {
FolderChooserDialog.Builder(activity)
.tag(PreferencesConstants.PREFERENCE_ZIP_EXTRACT_PATH)
.goUpLabel(getString(R.string.folder_go_up_one_level))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,16 @@ class BookmarksPrefsFragment : BasePrefsFragment() {

private fun reload() {
for (p in position) {
bookmarksList!!.removePreference(p.key)
bookmarksList?.removePreference(p.key)
}

position.clear()
for (i in dataUtils.books.indices) {
val p = PathSwitchPreference(activity)
val p = PathSwitchPreference(activity, itemOnEditListener, itemOnDeleteListener)
p.title = dataUtils.books[i][0]
p.summary = dataUtils.books[i][1]
p.onDelete = itemOnDeleteListener
p.onEdit = itemOnEditListener
position[p] = i
bookmarksList!!.addPreference(p)
bookmarksList?.addPreference(p)
}
}

Expand Down Expand Up @@ -113,11 +111,9 @@ class BookmarksPrefsFragment : BasePrefsFragment() {
disableButtonIfNotPath(txtShortcutPath, dialog)
dialog.getActionButton(DialogAction.POSITIVE)
.setOnClickListener {
val p = PathSwitchPreference(getActivity())
val p = PathSwitchPreference(activity, itemOnEditListener, itemOnDeleteListener)
p.title = txtShortcutName.text
p.summary = txtShortcutPath.text
p.onDelete = itemOnDeleteListener
p.onEdit = itemOnEditListener
position[p] = dataUtils.books.size
bookmarksList!!.addPreference(p)
val values = arrayOf(
Expand Down Expand Up @@ -169,11 +165,11 @@ class BookmarksPrefsFragment : BasePrefsFragment() {
val oldPath = p.summary.toString()
dataUtils.removeBook(position[p]!!)
position.remove(p)
bookmarksList!!.removePreference(p)
bookmarksList?.removePreference(p)
p.title = editText1.text
p.summary = editText2.text
position[p] = position.size
bookmarksList!!.addPreference(p)
bookmarksList?.addPreference(p)
val values = arrayOf(editText1.text.toString(), editText2.text.toString())
dataUtils.addBook(values)
AppConfig.getInstance()
Expand Down Expand Up @@ -212,7 +208,7 @@ class BookmarksPrefsFragment : BasePrefsFragment() {
p.summary.toString()
)
)
bookmarksList!!.removePreference(p)
bookmarksList?.removePreference(p)
position.remove(p)
dialog.dismiss()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ class ColorPrefsFragment : BasePrefsFragment() {
}

private fun showPreselectedColorsConfigDialog() {
val dialog = ColorPickerDialog.newInstance(
val newDialog = ColorPickerDialog.newInstance(
PreferencesConstants.PRESELECTED_CONFIGS,
activity.currentColorPreference,
activity.appTheme
)
dialog.setListener {
newDialog.setListener {
val colorPickerPref = activity.prefs.getInt(
PreferencesConstants.PREFERENCE_COLOR_CONFIG,
ColorPickerDialog.NO_DATA
Expand All @@ -95,8 +95,8 @@ class ColorPrefsFragment : BasePrefsFragment() {

activity.recreate()
}
dialog.setTargetFragment(this, 0)
dialog.show(parentFragmentManager, PreferencesConstants.PREFERENCE_SELECT_COLOR_CONFIG)
newDialog.setTargetFragment(this, 0)
newDialog.show(parentFragmentManager, PreferencesConstants.PREFERENCE_SELECT_COLOR_CONFIG)
}

private fun showColorChangeDialog(colorPrefKey: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,38 @@ class PrefsFragment : BasePrefsFragment() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.preferences, rootKey)

findPreference<Preference>("appearance")!!.onPreferenceClickListener =
findPreference<Preference>("appearance")?.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
activity.pushFragment(AppearancePrefsFragment())
true
}

findPreference<Preference>("ui")!!.onPreferenceClickListener =
findPreference<Preference>("ui")?.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
activity.pushFragment(UiPrefsFragment())
true
}

findPreference<Preference>("behavior")!!.onPreferenceClickListener =
findPreference<Preference>("behavior")?.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
activity.pushFragment(BehaviorPrefsFragment())
true
}

findPreference<Preference>("security")!!.onPreferenceClickListener =
findPreference<Preference>("security")?.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
activity.pushFragment(SecurityPrefsFragment())
true
}

findPreference<Preference>("about")!!.onPreferenceClickListener =
findPreference<Preference>("about")?.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
startActivity(Intent(activity, AboutActivity::class.java))
false
}

findPreference<Preference>("feedback")!!
.onPreferenceClickListener = Preference.OnPreferenceClickListener {
findPreference<Preference>("feedback")
?.onPreferenceClickListener = Preference.OnPreferenceClickListener {
val emailIntent = Utils.buildEmailIntent(null, Utils.EMAIL_SUPPORT)

val activities = activity.packageManager.queryIntentActivities(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ class QuickAccessesPrefsFragment : BasePrefsFragment() {

val currentValue = TinyDB.getBooleanArray(activity.prefs, KEY, DEFAULT)!!

val onChange = Preference.OnPreferenceClickListener {
currentValue[prefPos[it.key]!!] = (it as SwitchPreference).isChecked
TinyDB.putBooleanArray(activity.prefs, KEY, currentValue!!)
val onChange = Preference.OnPreferenceClickListener { preference ->
prefPos[preference.key]?.let {
currentValue[it] = (preference as SwitchPreference).isChecked
TinyDB.putBooleanArray(activity.prefs, KEY, currentValue)
}

true
}

for (k in KEYS) {
findPreference<Preference>(k)!!.onPreferenceClickListener = onChange
for (key in KEYS) {
findPreference<Preference>(key)?.onPreferenceClickListener = onChange
}
}
}
Loading

0 comments on commit 3e7ffe2

Please sign in to comment.