diff --git a/app/build.gradle b/app/build.gradle index 3844a4d3..f9a6b19f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/DecompressActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/DecompressActivity.kt index 3a62d782..9e3048b4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/DecompressActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/DecompressActivity.kt @@ -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) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MimeTypesActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MimeTypesActivity.kt index 700d64a7..7fe47ce5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MimeTypesActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MimeTypesActivity.kt @@ -333,7 +333,7 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener { private fun getListItemsFromFileDirItems(fileDirItems: ArrayList): ArrayList { val listItems = ArrayList() 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 diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ItemsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ItemsAdapter.kt index 6cea0693..e3d35801 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ItemsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ItemsAdapter.kt @@ -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() @@ -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) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt index 2bbe7199..29397f14 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt @@ -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): ArrayList { val listItems = ArrayList() 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 diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt index 1c11f054..79821da4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt @@ -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) } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/RootHelpers.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/RootHelpers.kt index cec73ca2..7efc5a6e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/RootHelpers.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/RootHelpers.kt @@ -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) } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/models/ListItem.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/models/ListItem.kt index 6250d79b..91be21a1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/models/ListItem.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/models/ListItem.kt @@ -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) diff --git a/app/src/main/res/layout/item_dir_grid.xml b/app/src/main/res/layout/item_dir_grid.xml new file mode 100644 index 00000000..a0907638 --- /dev/null +++ b/app/src/main/res/layout/item_dir_grid.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/item_empty.xml b/app/src/main/res/layout/item_empty.xml new file mode 100644 index 00000000..803858a1 --- /dev/null +++ b/app/src/main/res/layout/item_empty.xml @@ -0,0 +1,5 @@ + + diff --git a/app/src/main/res/layout/item_file_dir_grid.xml b/app/src/main/res/layout/item_file_grid.xml similarity index 94% rename from app/src/main/res/layout/item_file_dir_grid.xml rename to app/src/main/res/layout/item_file_grid.xml index f1eead90..eb8c67c8 100644 --- a/app/src/main/res/layout/item_file_dir_grid.xml +++ b/app/src/main/res/layout/item_file_grid.xml @@ -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"> + android:src="@drawable/ic_file_generic" /> - 60dp + 50dp 46sp