adding some grid view related UI improvements

This commit is contained in:
tibbi 2022-03-01 12:13:05 +01:00
parent 6c96ac12de
commit 448b24da60
12 changed files with 111 additions and 27 deletions

View File

@ -63,7 +63,7 @@ android {
}
dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:ee9863c9c5'
implementation 'com.github.SimpleMobileTools:Simple-Commons:ed36316a16'
implementation 'com.github.Stericson:RootTools:df729dcb13'
implementation 'com.github.Stericson:RootShell:1.6'
implementation 'com.alexvasilkov:gesture-views:2.5.2'

View File

@ -170,7 +170,7 @@ class DecompressActivity : SimpleActivity() {
val lastModified = if (isOreoPlus()) zipEntry.lastModifiedTime.toMillis() else 0
val filename = zipEntry.name.removeSuffix("/")
val listItem = ListItem(filename, filename.getFilenameFromPath(), zipEntry.isDirectory, 0, 0L, lastModified, false)
val listItem = ListItem(filename, filename.getFilenameFromPath(), zipEntry.isDirectory, 0, 0L, lastModified, false, false)
allFiles.add(listItem)
}
}

View File

@ -333,7 +333,7 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
private fun getListItemsFromFileDirItems(fileDirItems: ArrayList<FileDirItem>): ArrayList<ListItem> {
val listItems = ArrayList<ListItem>()
fileDirItems.forEach {
val listItem = ListItem(it.path, it.name, false, 0, it.size, it.modified, false)
val listItem = ListItem(it.path, it.name, false, 0, it.size, it.modified, false, false)
listItems.add(listItem)
}
return listItems

View File

@ -41,11 +41,11 @@ import com.simplemobiletools.filemanager.pro.helpers.*
import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener
import com.simplemobiletools.filemanager.pro.models.ListItem
import com.stericson.RootTools.RootTools
import kotlinx.android.synthetic.main.item_file_dir_grid.view.*
import kotlinx.android.synthetic.main.item_file_dir_list.view.*
import kotlinx.android.synthetic.main.item_file_dir_list.view.item_frame
import kotlinx.android.synthetic.main.item_file_dir_list.view.item_icon
import kotlinx.android.synthetic.main.item_file_dir_list.view.item_name
import kotlinx.android.synthetic.main.item_file_grid.view.*
import kotlinx.android.synthetic.main.item_section.view.*
import java.io.BufferedInputStream
import java.io.Closeable
@ -61,8 +61,10 @@ class ItemsAdapter(
) :
MyRecyclerViewAdapter(activity, recyclerView, itemClick), RecyclerViewFastScroller.OnPopupTextUpdate {
private val TYPE_FILE_DIR = 1
private val TYPE_SECTION = 2
private val TYPE_FILE = 1
private val TYPE_DIR = 2
private val TYPE_SECTION = 3
private val TYPE_GRID_TYPE_DIVIDER = 4
private lateinit var fileDrawable: Drawable
private lateinit var folderDrawable: Drawable
private var fileDrawables = HashMap<String, Drawable>()
@ -129,9 +131,9 @@ class ItemsAdapter(
}
}
override fun getSelectableItemCount() = listItems.filter { !it.isSectionTitle }.size
override fun getSelectableItemCount() = listItems.filter { !it.isSectionTitle && !it.isGridTypeDivider }.size
override fun getIsItemSelectable(position: Int) = !listItems[position].isSectionTitle
override fun getIsItemSelectable(position: Int) = !listItems[position].isSectionTitle && !listItems[position].isGridTypeDivider
override fun getItemSelectionKey(position: Int) = listItems.getOrNull(position)?.path?.hashCode()
@ -147,21 +149,28 @@ class ItemsAdapter(
}
override fun getItemViewType(position: Int): Int {
return if (listItems[position].isSectionTitle) {
TYPE_SECTION
} else {
TYPE_FILE_DIR
return when {
listItems[position].isGridTypeDivider -> TYPE_GRID_TYPE_DIVIDER
listItems[position].isSectionTitle -> TYPE_SECTION
listItems[position].mIsDirectory -> TYPE_DIR
else -> TYPE_FILE
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val layout = if (viewType == TYPE_SECTION) {
R.layout.item_section
} else if (viewType == TYPE_GRID_TYPE_DIVIDER) {
R.layout.item_empty
} else {
if (isListViewType) {
R.layout.item_file_dir_list
} else {
R.layout.item_file_dir_grid
if (viewType == TYPE_DIR) {
R.layout.item_dir_grid
} else {
R.layout.item_file_grid
}
}
}
return createViewHolder(layout, parent)
@ -789,6 +798,8 @@ class ItemsAdapter(
fun isASectionTitle(position: Int) = listItems.getOrNull(position)?.isSectionTitle ?: false
fun isGridTypeDivider(position: Int) = listItems.getOrNull(position)?.isGridTypeDivider ?: false
override fun onViewRecycled(holder: ViewHolder) {
super.onViewRecycled(holder)
if (!activity.isDestroyed && !activity.isFinishing) {
@ -804,11 +815,10 @@ class ItemsAdapter(
view.apply {
if (listItem.isSectionTitle) {
item_icon.setImageDrawable(folderDrawable)
item_section.text = if (textToHighlight.isEmpty()) listItem.mName else listItem.mName.highlightTextPart(textToHighlight, adjustedPrimaryColor)
item_section.setTextColor(textColor)
item_section.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
} else {
} else if (!listItem.isGridTypeDivider) {
item_frame.isSelected = isSelected
val fileName = listItem.name
item_name.text = if (textToHighlight.isEmpty()) fileName else fileName.highlightTextPart(textToHighlight, adjustedPrimaryColor)

View File

@ -102,6 +102,17 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
FileDirItem.sorting = context!!.config.getFolderSorting(currentPath)
listItems.sort()
if (context!!.config.getFolderViewType(currentPath) == VIEW_TYPE_GRID && listItems.none { it.isSectionTitle }) {
if (listItems.any { it.mIsDirectory } && listItems.any { !it.mIsDirectory }) {
val firstFileIndex = listItems.indexOfFirst { !it.mIsDirectory }
if (firstFileIndex != -1) {
val sectionTitle = ListItem("", "", false, 0, 0, 0, false, true)
listItems.add(firstFileIndex, sectionTitle)
}
}
}
activity?.runOnUiThread {
activity?.invalidateOptionsMenu()
addItems(listItems, forceRefresh)
@ -241,13 +252,13 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
lastModified = file.lastModified()
}
return ListItem(curPath, curName, isDirectory, children, size, lastModified, false)
return ListItem(curPath, curName, isDirectory, children, size, lastModified, false, false)
}
private fun getListItemsFromFileDirItems(fileDirItems: ArrayList<FileDirItem>): ArrayList<ListItem> {
val listItems = ArrayList<ListItem>()
fileDirItems.forEach {
val listItem = ListItem(it.path, it.name, it.isDirectory, it.children, it.size, it.modified, false)
val listItem = ListItem(it.path, it.name, it.isDirectory, it.children, it.size, it.modified, false, false)
listItems.add(listItem)
}
return listItems
@ -303,13 +314,13 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
files.forEach {
val parent = it.mPath.getParentPath()
if (!it.isDirectory && parent != previousParent && context != null) {
val sectionTitle = ListItem(parent, context!!.humanizePath(parent), false, 0, 0, 0, true)
val sectionTitle = ListItem(parent, context!!.humanizePath(parent), false, 0, 0, 0, true, false)
listItems.add(sectionTitle)
previousParent = parent
}
if (it.isDirectory) {
val sectionTitle = ListItem(it.path, context!!.humanizePath(it.path), true, 0, 0, 0, true)
val sectionTitle = ListItem(it.path, context!!.humanizePath(it.path), true, 0, 0, 0, true, false)
listItems.add(sectionTitle)
previousParent = parent
}
@ -418,7 +429,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
layoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
return if (getRecyclerAdapter()?.isASectionTitle(position) == true) {
return if (getRecyclerAdapter()?.isASectionTitle(position) == true || getRecyclerAdapter()?.isGridTypeDivider(position) == true) {
layoutManager.spanCount
} else {
1

View File

@ -142,7 +142,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
val name = cursor.getStringValue(FileColumns.DISPLAY_NAME) ?: path.getFilenameFromPath()
val size = cursor.getLongValue(FileColumns.SIZE)
val modified = cursor.getLongValue(FileColumns.DATE_MODIFIED) * 1000
val fileDirItem = ListItem(path, name, false, 0, size, modified, false)
val fileDirItem = ListItem(path, name, false, 0, size, modified, false, false)
if ((showHidden || !name.startsWith(".")) && activity?.getDoesFilePathExist(path) == true) {
listItems.add(fileDirItem)
}

View File

@ -44,7 +44,7 @@ class RootHelpers(val activity: Activity) {
val file = File(path, line)
val fullLine = fullLines.firstOrNull { it.endsWith(" $line") }
val isDirectory = fullLine?.startsWith('d') ?: file.isDirectory
val fileDirItem = ListItem(file.absolutePath, line, isDirectory, 0, 0, 0, false)
val fileDirItem = ListItem(file.absolutePath, line, isDirectory, 0, 0, 0, false, false)
files.add(fileDirItem)
super.commandOutput(id, line)
}

View File

@ -3,5 +3,7 @@ package com.simplemobiletools.filemanager.pro.models
import com.simplemobiletools.commons.models.FileDirItem
// isSectionTitle is used only at search results for showing the current folders path
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,
var isSectionTitle: Boolean) : FileDirItem(mPath, mName, mIsDirectory, mChildren, mSize, mModified)
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,
var isSectionTitle: Boolean, val isGridTypeDivider: Boolean
) : FileDirItem(mPath, mName, mIsDirectory, mChildren, mSize, mModified)

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:foreground="@drawable/selector"
android:paddingStart="@dimen/small_margin"
android:paddingTop="@dimen/tiny_margin"
android:paddingEnd="@dimen/small_margin"
android:paddingBottom="@dimen/tiny_margin">
<RelativeLayout
android:id="@+id/item_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/medium_margin">
<ImageView
android:id="@+id/item_icon"
android:layout_width="@dimen/grid_view_icon_size"
android:layout_height="@dimen/grid_view_icon_size"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:src="@drawable/ic_folder_vector" />
<TextView
android:id="@+id/item_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/item_icon"
android:ellipsize="middle"
android:gravity="center_horizontal"
android:paddingStart="@dimen/small_margin"
android:paddingEnd="@dimen/small_margin"
android:singleLine="true"
tools:text="Directory" />
<ImageView
android:id="@+id/item_check"
android:layout_width="@dimen/selection_check_size"
android:layout_height="@dimen/selection_check_size"
android:layout_alignEnd="@+id/item_icon"
android:layout_alignParentTop="true"
android:layout_margin="@dimen/small_margin"
android:background="@drawable/circle_background"
android:contentDescription="@null"
android:padding="@dimen/tiny_margin"
android:src="@drawable/ic_check_vector"
android:visibility="gone" />
</RelativeLayout>
</FrameLayout>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

View File

@ -17,7 +17,7 @@
android:id="@+id/item_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_margin">
android:layout_marginBottom="@dimen/normal_margin">
<com.simplemobiletools.filemanager.pro.views.MySquareImageView
android:id="@+id/item_icon"
@ -25,7 +25,7 @@
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:padding="@dimen/small_margin"
android:src="@drawable/ic_folder_vector" />
android:src="@drawable/ic_file_generic" />
<TextView
android:id="@+id/item_name"

View File

@ -1,4 +1,4 @@
<resources>
<dimen name="grid_view_icon_size">60dp</dimen>
<dimen name="grid_view_icon_size">50dp</dimen>
<dimen name="storage_free_space_text_size">46sp</dimen>
</resources>