Skip to content

Commit c80b981

Browse files
committed
adding a grid item layout file
1 parent 2749e68 commit c80b981

File tree

2 files changed

+62
-10
lines changed

2 files changed

+62
-10
lines changed

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

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ class ItemsAdapter(activity: SimpleActivity, var listItems: MutableList<ListItem
6767
private var dateFormat = ""
6868
private var timeFormat = ""
6969

70+
private val config = activity.config
71+
private val viewType = config.getFolderViewType(listItems.firstOrNull { !it.isSectionTitle }?.mPath ?: "")
72+
private val isListViewType = viewType == VIEW_TYPE_LIST
73+
7074
init {
7175
setupDragListener(true)
7276
initDrawables()
@@ -138,7 +142,15 @@ class ItemsAdapter(activity: SimpleActivity, var listItems: MutableList<ListItem
138142
}
139143

140144
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
141-
val layout = if (viewType == TYPE_SECTION) R.layout.item_section else R.layout.item_file_dir_list
145+
val layout = if (viewType == TYPE_SECTION) {
146+
R.layout.item_section
147+
} else {
148+
if (isListViewType) {
149+
R.layout.item_file_dir_list
150+
} else {
151+
R.layout.item_file_dir_grid
152+
}
153+
}
142154
return createViewHolder(layout, parent)
143155
}
144156

@@ -696,20 +708,20 @@ class ItemsAdapter(activity: SimpleActivity, var listItems: MutableList<ListItem
696708
item_name.setTextColor(textColor)
697709
item_name.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
698710

699-
item_details.setTextColor(textColor)
700-
item_details.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
711+
item_details?.setTextColor(textColor)
712+
item_details?.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
701713

702-
item_date.setTextColor(textColor)
703-
item_date.setTextSize(TypedValue.COMPLEX_UNIT_PX, smallerFontSize)
714+
item_date?.setTextColor(textColor)
715+
item_date?.setTextSize(TypedValue.COMPLEX_UNIT_PX, smallerFontSize)
704716

705717
if (listItem.isDirectory) {
706718
item_icon.setImageDrawable(folderDrawable)
707-
item_details.text = getChildrenCnt(listItem)
708-
item_date.beGone()
719+
item_details?.text = getChildrenCnt(listItem)
720+
item_date?.beGone()
709721
} else {
710-
item_details.text = listItem.size.formatSize()
711-
item_date.beVisible()
712-
item_date.text = listItem.modified.formatDate(activity, dateFormat, timeFormat)
722+
item_details?.text = listItem.size.formatSize()
723+
item_date?.beVisible()
724+
item_date?.text = listItem.modified.formatDate(activity, dateFormat, timeFormat)
713725

714726
val drawable = fileDrawables.getOrElse(fileName.substringAfterLast(".").toLowerCase(), { fileDrawable })
715727
val options = RequestOptions()
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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="wrap_content"
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:paddingTop="@dimen/tiny_margin"
12+
android:paddingBottom="@dimen/tiny_margin">
13+
14+
<RelativeLayout
15+
android:id="@+id/item_holder"
16+
android:layout_width="match_parent"
17+
android:layout_height="wrap_content"
18+
android:paddingEnd="@dimen/activity_margin">
19+
20+
<ImageView
21+
android:id="@+id/item_icon"
22+
android:layout_width="@dimen/file_picker_icon_size"
23+
android:layout_height="@dimen/file_picker_icon_size"
24+
android:layout_centerVertical="true"
25+
android:padding="@dimen/medium_margin"
26+
android:src="@drawable/ic_folder_vector" />
27+
28+
<TextView
29+
android:id="@+id/item_name"
30+
android:layout_width="wrap_content"
31+
android:layout_height="wrap_content"
32+
android:layout_below="@+id/item_icon"
33+
android:ellipsize="end"
34+
android:maxLines="2"
35+
android:paddingStart="@dimen/tiny_margin"
36+
android:paddingTop="@dimen/small_margin"
37+
tools:text="Directory" />
38+
39+
</RelativeLayout>
40+
</FrameLayout>

0 commit comments

Comments
 (0)