Skip to content

Commit 9b85e50

Browse files
committed
use a separate DecompressItemsAdapter at decompression
1 parent 72a10cc commit 9b85e50

File tree

4 files changed

+175
-5
lines changed

4 files changed

+175
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import com.simplemobiletools.commons.extensions.showErrorToast
99
import com.simplemobiletools.commons.extensions.toast
1010
import com.simplemobiletools.commons.helpers.isOreoPlus
1111
import com.simplemobiletools.filemanager.pro.R
12-
import com.simplemobiletools.filemanager.pro.adapters.ItemsAdapter
12+
import com.simplemobiletools.filemanager.pro.adapters.DecompressItemsAdapter
1313
import com.simplemobiletools.filemanager.pro.models.ListItem
1414
import kotlinx.android.synthetic.main.activity_decompress.*
1515
import java.io.BufferedInputStream
@@ -27,13 +27,13 @@ class DecompressActivity : SimpleActivity() {
2727
return
2828
}
2929

30-
getRealPathFromURI(uri)?.apply {
31-
title = getFilenameFromPath()
32-
}
30+
val realPath = getRealPathFromURI(uri)
31+
title = realPath?.getFilenameFromPath() ?: uri.toString().getFilenameFromPath()
3332

3433
try {
3534
val listItems = getListItems(uri)
36-
ItemsAdapter(this, listItems, null, decompress_list, false, null) {
35+
DecompressItemsAdapter(this, listItems, decompress_list) {
36+
3737
}.apply {
3838
decompress_list.adapter = this
3939
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
package com.simplemobiletools.filemanager.pro.adapters
2+
3+
import android.content.pm.PackageManager
4+
import android.graphics.drawable.Drawable
5+
import android.util.TypedValue
6+
import android.view.Menu
7+
import android.view.View
8+
import android.view.ViewGroup
9+
import com.bumptech.glide.Glide
10+
import com.bumptech.glide.load.engine.DiskCacheStrategy
11+
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
12+
import com.bumptech.glide.request.RequestOptions
13+
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
14+
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
15+
import com.simplemobiletools.commons.extensions.getFileSignature
16+
import com.simplemobiletools.commons.extensions.getTextSize
17+
import com.simplemobiletools.commons.extensions.getTimeFormat
18+
import com.simplemobiletools.commons.helpers.getFilePlaceholderDrawables
19+
import com.simplemobiletools.commons.views.MyRecyclerView
20+
import com.simplemobiletools.filemanager.pro.R
21+
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
22+
import com.simplemobiletools.filemanager.pro.extensions.config
23+
import com.simplemobiletools.filemanager.pro.models.ListItem
24+
import kotlinx.android.synthetic.main.item_list_file_dir.view.*
25+
import java.util.*
26+
27+
class DecompressItemsAdapter(activity: SimpleActivity, var listItems: MutableList<ListItem>, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) :
28+
MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
29+
30+
private lateinit var fileDrawable: Drawable
31+
private lateinit var folderDrawable: Drawable
32+
private var fileDrawables = HashMap<String, Drawable>()
33+
private var fontSize = 0f
34+
private var smallerFontSize = 0f
35+
private var dateFormat = ""
36+
private var timeFormat = ""
37+
38+
init {
39+
initDrawables()
40+
fontSize = activity.getTextSize()
41+
smallerFontSize = fontSize * 0.8f
42+
dateFormat = activity.config.dateFormat
43+
timeFormat = activity.getTimeFormat()
44+
}
45+
46+
override fun getActionMenuId() = 0
47+
48+
override fun prepareActionMode(menu: Menu) {}
49+
50+
override fun actionItemPressed(id: Int) {}
51+
52+
override fun getSelectableItemCount() = 0
53+
54+
override fun getIsItemSelectable(position: Int) = false
55+
56+
override fun getItemSelectionKey(position: Int) = 0
57+
58+
override fun getItemKeyPosition(key: Int) = 0
59+
60+
override fun onActionModeCreated() {}
61+
62+
override fun onActionModeDestroyed() {}
63+
64+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_decompression_list_file_dir, parent)
65+
66+
override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) {
67+
val fileDirItem = listItems[position]
68+
holder.bindView(fileDirItem, false, false) { itemView, layoutPosition ->
69+
setupView(itemView, fileDirItem)
70+
}
71+
bindViewHolder(holder)
72+
}
73+
74+
override fun getItemCount() = listItems.size
75+
76+
override fun onViewRecycled(holder: ViewHolder) {
77+
super.onViewRecycled(holder)
78+
if (!activity.isDestroyed && !activity.isFinishing) {
79+
val icon = holder.itemView.item_icon
80+
if (icon != null) {
81+
Glide.with(activity).clear(icon)
82+
}
83+
}
84+
}
85+
86+
private fun setupView(view: View, listItem: ListItem) {
87+
view.apply {
88+
val fileName = listItem.name
89+
item_name.text = fileName
90+
item_name.setTextColor(textColor)
91+
item_name.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
92+
93+
if (listItem.isDirectory) {
94+
item_icon.setImageDrawable(folderDrawable)
95+
} else {
96+
val drawable = fileDrawables.getOrElse(fileName.substringAfterLast(".").toLowerCase(), { fileDrawable })
97+
val options = RequestOptions()
98+
.signature(listItem.mPath.getFileSignature())
99+
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
100+
.error(drawable)
101+
.centerCrop()
102+
103+
val itemToLoad = getImagePathToLoad(listItem.path)
104+
if (!activity.isDestroyed) {
105+
Glide.with(activity)
106+
.load(itemToLoad)
107+
.transition(DrawableTransitionOptions.withCrossFade())
108+
.apply(options)
109+
.into(item_icon)
110+
}
111+
}
112+
}
113+
}
114+
115+
private fun getImagePathToLoad(path: String): Any {
116+
return if (path.endsWith(".apk", true)) {
117+
val packageInfo = activity.packageManager.getPackageArchiveInfo(path, PackageManager.GET_ACTIVITIES)
118+
if (packageInfo != null) {
119+
val appInfo = packageInfo.applicationInfo
120+
appInfo.sourceDir = path
121+
appInfo.publicSourceDir = path
122+
appInfo.loadIcon(activity.packageManager)
123+
} else {
124+
path
125+
}
126+
} else {
127+
path
128+
}
129+
}
130+
131+
private fun initDrawables() {
132+
folderDrawable = resources.getColoredDrawableWithColor(R.drawable.ic_folder_vector, textColor)
133+
folderDrawable.alpha = 180
134+
fileDrawable = resources.getDrawable(R.drawable.ic_file_generic)
135+
fileDrawables = getFilePlaceholderDrawables(activity)
136+
}
137+
}

app/src/main/res/layout/activity_decompress.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
android:layout_width="match_parent"
1111
android:layout_height="match_parent"
1212
android:clipToPadding="false"
13+
android:paddingTop="@dimen/small_margin"
1314
android:scrollbars="none"
1415
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
1516

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:id="@+id/item_holder"
5+
android:layout_width="match_parent"
6+
android:layout_height="wrap_content"
7+
android:paddingEnd="@dimen/activity_margin">
8+
9+
<ImageView
10+
android:id="@+id/item_icon"
11+
android:layout_width="@dimen/file_picker_icon_size"
12+
android:layout_height="@dimen/file_picker_icon_size"
13+
android:layout_centerVertical="true"
14+
android:padding="@dimen/medium_margin"
15+
android:src="@drawable/ic_folder_vector" />
16+
17+
<TextView
18+
android:id="@+id/item_name"
19+
android:layout_width="match_parent"
20+
android:layout_height="wrap_content"
21+
android:layout_alignTop="@+id/item_icon"
22+
android:layout_alignBottom="@+id/item_icon"
23+
android:layout_toEndOf="@+id/item_icon"
24+
android:ellipsize="end"
25+
android:gravity="center_vertical"
26+
android:maxLines="1"
27+
android:paddingStart="@dimen/tiny_margin"
28+
android:paddingTop="@dimen/small_margin"
29+
android:textSize="@dimen/bigger_text_size"
30+
tools:text="Directory" />
31+
32+
</RelativeLayout>

0 commit comments

Comments
 (0)