Skip to content

Commit 448b24d

Browse files
committed
adding some grid view related UI improvements
1 parent 6c96ac1 commit 448b24d

File tree

12 files changed

+111
-27
lines changed

12 files changed

+111
-27
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ android {
6363
}
6464

6565
dependencies {
66-
implementation 'com.github.SimpleMobileTools:Simple-Commons:ee9863c9c5'
66+
implementation 'com.github.SimpleMobileTools:Simple-Commons:ed36316a16'
6767
implementation 'com.github.Stericson:RootTools:df729dcb13'
6868
implementation 'com.github.Stericson:RootShell:1.6'
6969
implementation 'com.alexvasilkov:gesture-views:2.5.2'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class DecompressActivity : SimpleActivity() {
170170

171171
val lastModified = if (isOreoPlus()) zipEntry.lastModifiedTime.toMillis() else 0
172172
val filename = zipEntry.name.removeSuffix("/")
173-
val listItem = ListItem(filename, filename.getFilenameFromPath(), zipEntry.isDirectory, 0, 0L, lastModified, false)
173+
val listItem = ListItem(filename, filename.getFilenameFromPath(), zipEntry.isDirectory, 0, 0L, lastModified, false, false)
174174
allFiles.add(listItem)
175175
}
176176
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
333333
private fun getListItemsFromFileDirItems(fileDirItems: ArrayList<FileDirItem>): ArrayList<ListItem> {
334334
val listItems = ArrayList<ListItem>()
335335
fileDirItems.forEach {
336-
val listItem = ListItem(it.path, it.name, false, 0, it.size, it.modified, false)
336+
val listItem = ListItem(it.path, it.name, false, 0, it.size, it.modified, false, false)
337337
listItems.add(listItem)
338338
}
339339
return listItems

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ItemsAdapter.kt

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ import com.simplemobiletools.filemanager.pro.helpers.*
4141
import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener
4242
import com.simplemobiletools.filemanager.pro.models.ListItem
4343
import com.stericson.RootTools.RootTools
44-
import kotlinx.android.synthetic.main.item_file_dir_grid.view.*
4544
import kotlinx.android.synthetic.main.item_file_dir_list.view.*
4645
import kotlinx.android.synthetic.main.item_file_dir_list.view.item_frame
4746
import kotlinx.android.synthetic.main.item_file_dir_list.view.item_icon
4847
import kotlinx.android.synthetic.main.item_file_dir_list.view.item_name
48+
import kotlinx.android.synthetic.main.item_file_grid.view.*
4949
import kotlinx.android.synthetic.main.item_section.view.*
5050
import java.io.BufferedInputStream
5151
import java.io.Closeable
@@ -61,8 +61,10 @@ class ItemsAdapter(
6161
) :
6262
MyRecyclerViewAdapter(activity, recyclerView, itemClick), RecyclerViewFastScroller.OnPopupTextUpdate {
6363

64-
private val TYPE_FILE_DIR = 1
65-
private val TYPE_SECTION = 2
64+
private val TYPE_FILE = 1
65+
private val TYPE_DIR = 2
66+
private val TYPE_SECTION = 3
67+
private val TYPE_GRID_TYPE_DIVIDER = 4
6668
private lateinit var fileDrawable: Drawable
6769
private lateinit var folderDrawable: Drawable
6870
private var fileDrawables = HashMap<String, Drawable>()
@@ -129,9 +131,9 @@ class ItemsAdapter(
129131
}
130132
}
131133

132-
override fun getSelectableItemCount() = listItems.filter { !it.isSectionTitle }.size
134+
override fun getSelectableItemCount() = listItems.filter { !it.isSectionTitle && !it.isGridTypeDivider }.size
133135

134-
override fun getIsItemSelectable(position: Int) = !listItems[position].isSectionTitle
136+
override fun getIsItemSelectable(position: Int) = !listItems[position].isSectionTitle && !listItems[position].isGridTypeDivider
135137

136138
override fun getItemSelectionKey(position: Int) = listItems.getOrNull(position)?.path?.hashCode()
137139

@@ -147,21 +149,28 @@ class ItemsAdapter(
147149
}
148150

149151
override fun getItemViewType(position: Int): Int {
150-
return if (listItems[position].isSectionTitle) {
151-
TYPE_SECTION
152-
} else {
153-
TYPE_FILE_DIR
152+
return when {
153+
listItems[position].isGridTypeDivider -> TYPE_GRID_TYPE_DIVIDER
154+
listItems[position].isSectionTitle -> TYPE_SECTION
155+
listItems[position].mIsDirectory -> TYPE_DIR
156+
else -> TYPE_FILE
154157
}
155158
}
156159

157160
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
158161
val layout = if (viewType == TYPE_SECTION) {
159162
R.layout.item_section
163+
} else if (viewType == TYPE_GRID_TYPE_DIVIDER) {
164+
R.layout.item_empty
160165
} else {
161166
if (isListViewType) {
162167
R.layout.item_file_dir_list
163168
} else {
164-
R.layout.item_file_dir_grid
169+
if (viewType == TYPE_DIR) {
170+
R.layout.item_dir_grid
171+
} else {
172+
R.layout.item_file_grid
173+
}
165174
}
166175
}
167176
return createViewHolder(layout, parent)
@@ -789,6 +798,8 @@ class ItemsAdapter(
789798

790799
fun isASectionTitle(position: Int) = listItems.getOrNull(position)?.isSectionTitle ?: false
791800

801+
fun isGridTypeDivider(position: Int) = listItems.getOrNull(position)?.isGridTypeDivider ?: false
802+
792803
override fun onViewRecycled(holder: ViewHolder) {
793804
super.onViewRecycled(holder)
794805
if (!activity.isDestroyed && !activity.isFinishing) {
@@ -804,11 +815,10 @@ class ItemsAdapter(
804815
view.apply {
805816
if (listItem.isSectionTitle) {
806817
item_icon.setImageDrawable(folderDrawable)
807-
808818
item_section.text = if (textToHighlight.isEmpty()) listItem.mName else listItem.mName.highlightTextPart(textToHighlight, adjustedPrimaryColor)
809819
item_section.setTextColor(textColor)
810820
item_section.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
811-
} else {
821+
} else if (!listItem.isGridTypeDivider) {
812822
item_frame.isSelected = isSelected
813823
val fileName = listItem.name
814824
item_name.text = if (textToHighlight.isEmpty()) fileName else fileName.highlightTextPart(textToHighlight, adjustedPrimaryColor)

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
102102

103103
FileDirItem.sorting = context!!.config.getFolderSorting(currentPath)
104104
listItems.sort()
105+
106+
if (context!!.config.getFolderViewType(currentPath) == VIEW_TYPE_GRID && listItems.none { it.isSectionTitle }) {
107+
if (listItems.any { it.mIsDirectory } && listItems.any { !it.mIsDirectory }) {
108+
val firstFileIndex = listItems.indexOfFirst { !it.mIsDirectory }
109+
if (firstFileIndex != -1) {
110+
val sectionTitle = ListItem("", "", false, 0, 0, 0, false, true)
111+
listItems.add(firstFileIndex, sectionTitle)
112+
}
113+
}
114+
}
115+
105116
activity?.runOnUiThread {
106117
activity?.invalidateOptionsMenu()
107118
addItems(listItems, forceRefresh)
@@ -241,13 +252,13 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
241252
lastModified = file.lastModified()
242253
}
243254

244-
return ListItem(curPath, curName, isDirectory, children, size, lastModified, false)
255+
return ListItem(curPath, curName, isDirectory, children, size, lastModified, false, false)
245256
}
246257

247258
private fun getListItemsFromFileDirItems(fileDirItems: ArrayList<FileDirItem>): ArrayList<ListItem> {
248259
val listItems = ArrayList<ListItem>()
249260
fileDirItems.forEach {
250-
val listItem = ListItem(it.path, it.name, it.isDirectory, it.children, it.size, it.modified, false)
261+
val listItem = ListItem(it.path, it.name, it.isDirectory, it.children, it.size, it.modified, false, false)
251262
listItems.add(listItem)
252263
}
253264
return listItems
@@ -303,13 +314,13 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
303314
files.forEach {
304315
val parent = it.mPath.getParentPath()
305316
if (!it.isDirectory && parent != previousParent && context != null) {
306-
val sectionTitle = ListItem(parent, context!!.humanizePath(parent), false, 0, 0, 0, true)
317+
val sectionTitle = ListItem(parent, context!!.humanizePath(parent), false, 0, 0, 0, true, false)
307318
listItems.add(sectionTitle)
308319
previousParent = parent
309320
}
310321

311322
if (it.isDirectory) {
312-
val sectionTitle = ListItem(it.path, context!!.humanizePath(it.path), true, 0, 0, 0, true)
323+
val sectionTitle = ListItem(it.path, context!!.humanizePath(it.path), true, 0, 0, 0, true, false)
313324
listItems.add(sectionTitle)
314325
previousParent = parent
315326
}
@@ -418,7 +429,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
418429

419430
layoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
420431
override fun getSpanSize(position: Int): Int {
421-
return if (getRecyclerAdapter()?.isASectionTitle(position) == true) {
432+
return if (getRecyclerAdapter()?.isASectionTitle(position) == true || getRecyclerAdapter()?.isGridTypeDivider(position) == true) {
422433
layoutManager.spanCount
423434
} else {
424435
1

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
142142
val name = cursor.getStringValue(FileColumns.DISPLAY_NAME) ?: path.getFilenameFromPath()
143143
val size = cursor.getLongValue(FileColumns.SIZE)
144144
val modified = cursor.getLongValue(FileColumns.DATE_MODIFIED) * 1000
145-
val fileDirItem = ListItem(path, name, false, 0, size, modified, false)
145+
val fileDirItem = ListItem(path, name, false, 0, size, modified, false, false)
146146
if ((showHidden || !name.startsWith(".")) && activity?.getDoesFilePathExist(path) == true) {
147147
listItems.add(fileDirItem)
148148
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class RootHelpers(val activity: Activity) {
4444
val file = File(path, line)
4545
val fullLine = fullLines.firstOrNull { it.endsWith(" $line") }
4646
val isDirectory = fullLine?.startsWith('d') ?: file.isDirectory
47-
val fileDirItem = ListItem(file.absolutePath, line, isDirectory, 0, 0, 0, false)
47+
val fileDirItem = ListItem(file.absolutePath, line, isDirectory, 0, 0, 0, false, false)
4848
files.add(fileDirItem)
4949
super.commandOutput(id, line)
5050
}

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/models/ListItem.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ package com.simplemobiletools.filemanager.pro.models
33
import com.simplemobiletools.commons.models.FileDirItem
44

55
// isSectionTitle is used only at search results for showing the current folders path
6-
data class ListItem(val mPath: String, val mName: String = "", var mIsDirectory: Boolean = false, var mChildren: Int = 0, var mSize: Long = 0L, var mModified: Long = 0L,
7-
var isSectionTitle: Boolean) : FileDirItem(mPath, mName, mIsDirectory, mChildren, mSize, mModified)
6+
data class ListItem(
7+
val mPath: String, val mName: String = "", var mIsDirectory: Boolean = false, var mChildren: Int = 0, var mSize: Long = 0L, var mModified: Long = 0L,
8+
var isSectionTitle: Boolean, val isGridTypeDivider: Boolean
9+
) : FileDirItem(mPath, mName, mIsDirectory, mChildren, mSize, mModified)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:id="@+id/item_frame"
5+
android:layout_width="match_parent"
6+
android:layout_height="wrap_content"
7+
android:background="?attr/selectableItemBackground"
8+
android:clickable="true"
9+
android:focusable="true"
10+
android:foreground="@drawable/selector"
11+
android:paddingStart="@dimen/small_margin"
12+
android:paddingTop="@dimen/tiny_margin"
13+
android:paddingEnd="@dimen/small_margin"
14+
android:paddingBottom="@dimen/tiny_margin">
15+
16+
<RelativeLayout
17+
android:id="@+id/item_holder"
18+
android:layout_width="match_parent"
19+
android:layout_height="wrap_content"
20+
android:layout_marginBottom="@dimen/medium_margin">
21+
22+
<ImageView
23+
android:id="@+id/item_icon"
24+
android:layout_width="@dimen/grid_view_icon_size"
25+
android:layout_height="@dimen/grid_view_icon_size"
26+
android:layout_centerHorizontal="true"
27+
android:adjustViewBounds="true"
28+
android:src="@drawable/ic_folder_vector" />
29+
30+
<TextView
31+
android:id="@+id/item_name"
32+
android:layout_width="match_parent"
33+
android:layout_height="wrap_content"
34+
android:layout_below="@+id/item_icon"
35+
android:ellipsize="middle"
36+
android:gravity="center_horizontal"
37+
android:paddingStart="@dimen/small_margin"
38+
android:paddingEnd="@dimen/small_margin"
39+
android:singleLine="true"
40+
tools:text="Directory" />
41+
42+
<ImageView
43+
android:id="@+id/item_check"
44+
android:layout_width="@dimen/selection_check_size"
45+
android:layout_height="@dimen/selection_check_size"
46+
android:layout_alignEnd="@+id/item_icon"
47+
android:layout_alignParentTop="true"
48+
android:layout_margin="@dimen/small_margin"
49+
android:background="@drawable/circle_background"
50+
android:contentDescription="@null"
51+
android:padding="@dimen/tiny_margin"
52+
android:src="@drawable/ic_check_vector"
53+
android:visibility="gone" />
54+
55+
</RelativeLayout>
56+
</FrameLayout>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:id="@+id/item_frame"
4+
android:layout_width="wrap_content"
5+
android:layout_height="wrap_content" />

0 commit comments

Comments
 (0)