Skip to content

Commit e1c0554

Browse files
committed
adding a Change View Type menu item for enabling grid view
1 parent bb5d918 commit e1c0554

File tree

7 files changed

+141
-1
lines changed

7 files changed

+141
-1
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ android {
5858
}
5959

6060
dependencies {
61-
implementation 'com.simplemobiletools:commons:5.31.13'
61+
implementation 'com.simplemobiletools:commons:5.31.15'
6262
implementation 'com.github.Stericson:RootTools:df729dcb13'
6363
implementation 'com.github.Stericson:RootShell:1.6'
6464
implementation 'com.alexvasilkov:gesture-views:2.5.2'

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.simplemobiletools.commons.models.Release
2121
import com.simplemobiletools.filemanager.pro.BuildConfig
2222
import com.simplemobiletools.filemanager.pro.R
2323
import com.simplemobiletools.filemanager.pro.dialogs.ChangeSortingDialog
24+
import com.simplemobiletools.filemanager.pro.dialogs.ChangeViewTypeDialog
2425
import com.simplemobiletools.filemanager.pro.extensions.config
2526
import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
2627
import com.simplemobiletools.filemanager.pro.fragments.ItemsFragment
@@ -107,6 +108,7 @@ class MainActivity : SimpleActivity() {
107108
R.id.add_favorite -> addFavorite()
108109
R.id.remove_favorite -> removeFavorite()
109110
R.id.set_as_home -> setAsHome()
111+
R.id.change_view_type -> changeViewType()
110112
R.id.temporarily_show_hidden -> tryToggleTemporarilyShowHidden()
111113
R.id.stop_showing_hidden -> tryToggleTemporarilyShowHidden()
112114
R.id.settings -> startActivity(Intent(applicationContext, SettingsActivity::class.java))
@@ -281,6 +283,12 @@ class MainActivity : SimpleActivity() {
281283
toast(R.string.home_folder_updated)
282284
}
283285

286+
private fun changeViewType() {
287+
ChangeViewTypeDialog(this, fragment.currentPath) {
288+
289+
}
290+
}
291+
284292
private fun tryToggleTemporarilyShowHidden() {
285293
if (config.temporarilyShowHidden) {
286294
toggleTemporarilyShowHidden(false)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.simplemobiletools.filemanager.pro.dialogs
2+
3+
import android.view.View
4+
import androidx.appcompat.app.AlertDialog
5+
import com.simplemobiletools.commons.activities.BaseSimpleActivity
6+
import com.simplemobiletools.commons.extensions.setupDialogStuff
7+
import com.simplemobiletools.commons.helpers.VIEW_TYPE_GRID
8+
import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST
9+
import com.simplemobiletools.filemanager.pro.R
10+
import com.simplemobiletools.filemanager.pro.extensions.config
11+
import kotlinx.android.synthetic.main.dialog_change_view_type.view.*
12+
13+
class ChangeViewTypeDialog(val activity: BaseSimpleActivity, val path: String = "", val callback: () -> Unit) {
14+
private var view: View
15+
private var config = activity.config
16+
17+
init {
18+
view = activity.layoutInflater.inflate(R.layout.dialog_change_view_type, null).apply {
19+
val currViewType = config.getFolderViewType(this@ChangeViewTypeDialog.path)
20+
val viewToCheck = if (currViewType == VIEW_TYPE_GRID) {
21+
change_view_type_dialog_radio_grid.id
22+
} else {
23+
change_view_type_dialog_radio_list.id
24+
}
25+
26+
change_view_type_dialog_radio.check(viewToCheck)
27+
change_view_type_dialog_use_for_this_folder.apply {
28+
isChecked = config.hasCustomViewType(this@ChangeViewTypeDialog.path)
29+
}
30+
}
31+
32+
AlertDialog.Builder(activity)
33+
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
34+
.setNegativeButton(R.string.cancel, null)
35+
.create().apply {
36+
activity.setupDialogStuff(view, this)
37+
}
38+
}
39+
40+
private fun dialogConfirmed() {
41+
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
42+
if (view.change_view_type_dialog_use_for_this_folder.isChecked) {
43+
config.saveFolderViewType(this.path, viewType)
44+
} else {
45+
config.removeFolderViewType(this.path)
46+
config.viewType = viewType
47+
}
48+
49+
callback()
50+
}
51+
}

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Config.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.simplemobiletools.filemanager.pro.helpers
33
import android.content.Context
44
import com.simplemobiletools.commons.extensions.getInternalStoragePath
55
import com.simplemobiletools.commons.helpers.BaseConfig
6+
import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST
67
import java.io.File
78

89
class Config(context: Context) : BaseConfig(context) {
@@ -69,4 +70,24 @@ class Config(context: Context) : BaseConfig(context) {
6970
var editorTextZoom: Float
7071
get() = prefs.getFloat(EDITOR_TEXT_ZOOM, 1.2f)
7172
set(editorTextZoom) = prefs.edit().putFloat(EDITOR_TEXT_ZOOM, editorTextZoom).apply()
73+
74+
var viewType: Int
75+
get() = prefs.getInt(VIEW_TYPE, VIEW_TYPE_LIST)
76+
set(viewTypeFiles) = prefs.edit().putInt(VIEW_TYPE, viewTypeFiles).apply()
77+
78+
fun saveFolderViewType(path: String, value: Int) {
79+
if (path.isEmpty()) {
80+
viewType = value
81+
} else {
82+
prefs.edit().putInt(VIEW_TYPE_PREFIX + path.toLowerCase(), value).apply()
83+
}
84+
}
85+
86+
fun getFolderViewType(path: String) = prefs.getInt(VIEW_TYPE_PREFIX + path.toLowerCase(), viewType)
87+
88+
fun removeFolderViewType(path: String) {
89+
prefs.edit().remove(VIEW_TYPE_PREFIX + path.toLowerCase()).apply()
90+
}
91+
92+
fun hasCustomViewType(path: String) = prefs.contains(VIEW_TYPE_PREFIX + path.toLowerCase())
7293
}

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Constants.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const val TEMPORARILY_SHOW_HIDDEN = "temporarily_show_hidden"
99
const val IS_ROOT_AVAILABLE = "is_root_available"
1010
const val ENABLE_ROOT_ACCESS = "enable_root_access"
1111
const val EDITOR_TEXT_ZOOM = "editor_text_zoom"
12+
const val VIEW_TYPE = "view_type"
13+
const val VIEW_TYPE_PREFIX = "view_type_folder_"
1214

1315
// open as
1416
const val OPEN_AS_DEFAULT = 0
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:id="@+id/change_view_type_dialog_scrollview"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent">
6+
7+
<LinearLayout
8+
android:id="@+id/change_view_type_dialog_holder"
9+
android:layout_width="match_parent"
10+
android:layout_height="wrap_content"
11+
android:orientation="vertical"
12+
android:paddingStart="@dimen/activity_margin"
13+
android:paddingTop="@dimen/activity_margin"
14+
android:paddingEnd="@dimen/activity_margin">
15+
16+
<RadioGroup
17+
android:id="@+id/change_view_type_dialog_radio"
18+
android:layout_width="match_parent"
19+
android:layout_height="wrap_content"
20+
android:layout_marginBottom="@dimen/medium_margin">
21+
22+
<com.simplemobiletools.commons.views.MyCompatRadioButton
23+
android:id="@+id/change_view_type_dialog_radio_grid"
24+
android:layout_width="match_parent"
25+
android:layout_height="wrap_content"
26+
android:paddingTop="@dimen/medium_margin"
27+
android:paddingBottom="@dimen/medium_margin"
28+
android:text="@string/grid" />
29+
30+
<com.simplemobiletools.commons.views.MyCompatRadioButton
31+
android:id="@+id/change_view_type_dialog_radio_list"
32+
android:layout_width="match_parent"
33+
android:layout_height="wrap_content"
34+
android:paddingTop="@dimen/medium_margin"
35+
android:paddingBottom="@dimen/medium_margin"
36+
android:text="@string/list" />
37+
38+
</RadioGroup>
39+
40+
<include
41+
android:id="@+id/use_for_this_folder_divider"
42+
layout="@layout/divider" />
43+
44+
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
45+
android:id="@+id/change_view_type_dialog_use_for_this_folder"
46+
android:layout_width="match_parent"
47+
android:layout_height="wrap_content"
48+
android:layout_marginTop="@dimen/medium_margin"
49+
android:paddingTop="@dimen/medium_margin"
50+
android:paddingBottom="@dimen/medium_margin"
51+
android:text="@string/use_for_this_folder" />
52+
53+
</LinearLayout>
54+
</ScrollView>

app/src/main/res/menu/menu.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
android:id="@+id/set_as_home"
3737
android:title="@string/set_as_home_folder"
3838
app:showAsAction="never"/>
39+
<item
40+
android:id="@+id/change_view_type"
41+
android:title="@string/change_view_type"
42+
app:showAsAction="never"/>
3943
<item
4044
android:id="@+id/temporarily_show_hidden"
4145
android:title="@string/temporarily_show_hidden"

0 commit comments

Comments
 (0)