adding a Change View Type menu item for enabling grid view
This commit is contained in:
parent
bb5d918cf5
commit
e1c0554990
|
@ -58,7 +58,7 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.simplemobiletools:commons:5.31.13'
|
implementation 'com.simplemobiletools:commons:5.31.15'
|
||||||
implementation 'com.github.Stericson:RootTools:df729dcb13'
|
implementation 'com.github.Stericson:RootTools:df729dcb13'
|
||||||
implementation 'com.github.Stericson:RootShell:1.6'
|
implementation 'com.github.Stericson:RootShell:1.6'
|
||||||
implementation 'com.alexvasilkov:gesture-views:2.5.2'
|
implementation 'com.alexvasilkov:gesture-views:2.5.2'
|
||||||
|
|
|
@ -21,6 +21,7 @@ import com.simplemobiletools.commons.models.Release
|
||||||
import com.simplemobiletools.filemanager.pro.BuildConfig
|
import com.simplemobiletools.filemanager.pro.BuildConfig
|
||||||
import com.simplemobiletools.filemanager.pro.R
|
import com.simplemobiletools.filemanager.pro.R
|
||||||
import com.simplemobiletools.filemanager.pro.dialogs.ChangeSortingDialog
|
import com.simplemobiletools.filemanager.pro.dialogs.ChangeSortingDialog
|
||||||
|
import com.simplemobiletools.filemanager.pro.dialogs.ChangeViewTypeDialog
|
||||||
import com.simplemobiletools.filemanager.pro.extensions.config
|
import com.simplemobiletools.filemanager.pro.extensions.config
|
||||||
import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
|
import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
|
||||||
import com.simplemobiletools.filemanager.pro.fragments.ItemsFragment
|
import com.simplemobiletools.filemanager.pro.fragments.ItemsFragment
|
||||||
|
@ -107,6 +108,7 @@ class MainActivity : SimpleActivity() {
|
||||||
R.id.add_favorite -> addFavorite()
|
R.id.add_favorite -> addFavorite()
|
||||||
R.id.remove_favorite -> removeFavorite()
|
R.id.remove_favorite -> removeFavorite()
|
||||||
R.id.set_as_home -> setAsHome()
|
R.id.set_as_home -> setAsHome()
|
||||||
|
R.id.change_view_type -> changeViewType()
|
||||||
R.id.temporarily_show_hidden -> tryToggleTemporarilyShowHidden()
|
R.id.temporarily_show_hidden -> tryToggleTemporarilyShowHidden()
|
||||||
R.id.stop_showing_hidden -> tryToggleTemporarilyShowHidden()
|
R.id.stop_showing_hidden -> tryToggleTemporarilyShowHidden()
|
||||||
R.id.settings -> startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
R.id.settings -> startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
||||||
|
@ -281,6 +283,12 @@ class MainActivity : SimpleActivity() {
|
||||||
toast(R.string.home_folder_updated)
|
toast(R.string.home_folder_updated)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun changeViewType() {
|
||||||
|
ChangeViewTypeDialog(this, fragment.currentPath) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun tryToggleTemporarilyShowHidden() {
|
private fun tryToggleTemporarilyShowHidden() {
|
||||||
if (config.temporarilyShowHidden) {
|
if (config.temporarilyShowHidden) {
|
||||||
toggleTemporarilyShowHidden(false)
|
toggleTemporarilyShowHidden(false)
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package com.simplemobiletools.filemanager.pro.dialogs
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
|
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||||
|
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||||
|
import com.simplemobiletools.commons.helpers.VIEW_TYPE_GRID
|
||||||
|
import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST
|
||||||
|
import com.simplemobiletools.filemanager.pro.R
|
||||||
|
import com.simplemobiletools.filemanager.pro.extensions.config
|
||||||
|
import kotlinx.android.synthetic.main.dialog_change_view_type.view.*
|
||||||
|
|
||||||
|
class ChangeViewTypeDialog(val activity: BaseSimpleActivity, val path: String = "", val callback: () -> Unit) {
|
||||||
|
private var view: View
|
||||||
|
private var config = activity.config
|
||||||
|
|
||||||
|
init {
|
||||||
|
view = activity.layoutInflater.inflate(R.layout.dialog_change_view_type, null).apply {
|
||||||
|
val currViewType = config.getFolderViewType(this@ChangeViewTypeDialog.path)
|
||||||
|
val viewToCheck = if (currViewType == VIEW_TYPE_GRID) {
|
||||||
|
change_view_type_dialog_radio_grid.id
|
||||||
|
} else {
|
||||||
|
change_view_type_dialog_radio_list.id
|
||||||
|
}
|
||||||
|
|
||||||
|
change_view_type_dialog_radio.check(viewToCheck)
|
||||||
|
change_view_type_dialog_use_for_this_folder.apply {
|
||||||
|
isChecked = config.hasCustomViewType(this@ChangeViewTypeDialog.path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AlertDialog.Builder(activity)
|
||||||
|
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
|
||||||
|
.setNegativeButton(R.string.cancel, null)
|
||||||
|
.create().apply {
|
||||||
|
activity.setupDialogStuff(view, this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun dialogConfirmed() {
|
||||||
|
val viewType = if (view.change_view_type_dialog_radio.checkedRadioButtonId == view.change_view_type_dialog_radio_grid.id) VIEW_TYPE_GRID else VIEW_TYPE_LIST
|
||||||
|
if (view.change_view_type_dialog_use_for_this_folder.isChecked) {
|
||||||
|
config.saveFolderViewType(this.path, viewType)
|
||||||
|
} else {
|
||||||
|
config.removeFolderViewType(this.path)
|
||||||
|
config.viewType = viewType
|
||||||
|
}
|
||||||
|
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package com.simplemobiletools.filemanager.pro.helpers
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.simplemobiletools.commons.extensions.getInternalStoragePath
|
import com.simplemobiletools.commons.extensions.getInternalStoragePath
|
||||||
import com.simplemobiletools.commons.helpers.BaseConfig
|
import com.simplemobiletools.commons.helpers.BaseConfig
|
||||||
|
import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class Config(context: Context) : BaseConfig(context) {
|
class Config(context: Context) : BaseConfig(context) {
|
||||||
|
@ -69,4 +70,24 @@ class Config(context: Context) : BaseConfig(context) {
|
||||||
var editorTextZoom: Float
|
var editorTextZoom: Float
|
||||||
get() = prefs.getFloat(EDITOR_TEXT_ZOOM, 1.2f)
|
get() = prefs.getFloat(EDITOR_TEXT_ZOOM, 1.2f)
|
||||||
set(editorTextZoom) = prefs.edit().putFloat(EDITOR_TEXT_ZOOM, editorTextZoom).apply()
|
set(editorTextZoom) = prefs.edit().putFloat(EDITOR_TEXT_ZOOM, editorTextZoom).apply()
|
||||||
|
|
||||||
|
var viewType: Int
|
||||||
|
get() = prefs.getInt(VIEW_TYPE, VIEW_TYPE_LIST)
|
||||||
|
set(viewTypeFiles) = prefs.edit().putInt(VIEW_TYPE, viewTypeFiles).apply()
|
||||||
|
|
||||||
|
fun saveFolderViewType(path: String, value: Int) {
|
||||||
|
if (path.isEmpty()) {
|
||||||
|
viewType = value
|
||||||
|
} else {
|
||||||
|
prefs.edit().putInt(VIEW_TYPE_PREFIX + path.toLowerCase(), value).apply()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getFolderViewType(path: String) = prefs.getInt(VIEW_TYPE_PREFIX + path.toLowerCase(), viewType)
|
||||||
|
|
||||||
|
fun removeFolderViewType(path: String) {
|
||||||
|
prefs.edit().remove(VIEW_TYPE_PREFIX + path.toLowerCase()).apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun hasCustomViewType(path: String) = prefs.contains(VIEW_TYPE_PREFIX + path.toLowerCase())
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@ const val TEMPORARILY_SHOW_HIDDEN = "temporarily_show_hidden"
|
||||||
const val IS_ROOT_AVAILABLE = "is_root_available"
|
const val IS_ROOT_AVAILABLE = "is_root_available"
|
||||||
const val ENABLE_ROOT_ACCESS = "enable_root_access"
|
const val ENABLE_ROOT_ACCESS = "enable_root_access"
|
||||||
const val EDITOR_TEXT_ZOOM = "editor_text_zoom"
|
const val EDITOR_TEXT_ZOOM = "editor_text_zoom"
|
||||||
|
const val VIEW_TYPE = "view_type"
|
||||||
|
const val VIEW_TYPE_PREFIX = "view_type_folder_"
|
||||||
|
|
||||||
// open as
|
// open as
|
||||||
const val OPEN_AS_DEFAULT = 0
|
const val OPEN_AS_DEFAULT = 0
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/change_view_type_dialog_scrollview"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/change_view_type_dialog_holder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingStart="@dimen/activity_margin"
|
||||||
|
android:paddingTop="@dimen/activity_margin"
|
||||||
|
android:paddingEnd="@dimen/activity_margin">
|
||||||
|
|
||||||
|
<RadioGroup
|
||||||
|
android:id="@+id/change_view_type_dialog_radio"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="@dimen/medium_margin">
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||||
|
android:id="@+id/change_view_type_dialog_radio_grid"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingTop="@dimen/medium_margin"
|
||||||
|
android:paddingBottom="@dimen/medium_margin"
|
||||||
|
android:text="@string/grid" />
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||||
|
android:id="@+id/change_view_type_dialog_radio_list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingTop="@dimen/medium_margin"
|
||||||
|
android:paddingBottom="@dimen/medium_margin"
|
||||||
|
android:text="@string/list" />
|
||||||
|
|
||||||
|
</RadioGroup>
|
||||||
|
|
||||||
|
<include
|
||||||
|
android:id="@+id/use_for_this_folder_divider"
|
||||||
|
layout="@layout/divider" />
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
||||||
|
android:id="@+id/change_view_type_dialog_use_for_this_folder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/medium_margin"
|
||||||
|
android:paddingTop="@dimen/medium_margin"
|
||||||
|
android:paddingBottom="@dimen/medium_margin"
|
||||||
|
android:text="@string/use_for_this_folder" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</ScrollView>
|
|
@ -36,6 +36,10 @@
|
||||||
android:id="@+id/set_as_home"
|
android:id="@+id/set_as_home"
|
||||||
android:title="@string/set_as_home_folder"
|
android:title="@string/set_as_home_folder"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/change_view_type"
|
||||||
|
android:title="@string/change_view_type"
|
||||||
|
app:showAsAction="never"/>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/temporarily_show_hidden"
|
android:id="@+id/temporarily_show_hidden"
|
||||||
android:title="@string/temporarily_show_hidden"
|
android:title="@string/temporarily_show_hidden"
|
||||||
|
|
Loading…
Reference in New Issue