Skip to content

Commit 6684235

Browse files
authored
Merge pull request #525 from SimpleMobileTools/KryptKode-feat/scoped-storage
Krypt kode feat/scoped storage
2 parents ba186c0 + ed304ca commit 6684235

File tree

9 files changed

+58
-108
lines changed

9 files changed

+58
-108
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ android {
5757
}
5858

5959
dependencies {
60-
implementation 'com.github.SimpleMobileTools:Simple-Commons:4e6eeb901f'
60+
implementation 'com.github.SimpleMobileTools:Simple-Commons:51f1996098'
6161
implementation 'com.github.Stericson:RootTools:df729dcb13'
6262
implementation 'com.github.Stericson:RootShell:1.6'
6363
implementation 'com.alexvasilkov:gesture-views:2.5.2'

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

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
6161
ensureBackgroundThread {
6262
reFetchItems()
6363
}
64+
65+
val adjustedPrimaryColor = getAdjustedPrimaryColor()
66+
mimetypes_fastscroller.updateColors(adjustedPrimaryColor, adjustedPrimaryColor.getContrastColor())
6467
}
6568

6669
override fun onCreateOptionsMenu(menu: Menu): Boolean {
@@ -130,13 +133,13 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
130133
lastSearchedText = searchText
131134
when {
132135
searchText.isEmpty() -> {
133-
mimetypes_list.beVisible()
136+
mimetypes_fastscroller.beVisible()
134137
getRecyclerAdapter()?.updateItems(storedItems)
135138
mimetypes_placeholder.beGoneIf(storedItems.isNotEmpty())
136139
mimetypes_placeholder_2.beGone()
137140
}
138141
searchText.length == 1 -> {
139-
mimetypes_list.beGone()
142+
mimetypes_fastscroller.beGone()
140143
mimetypes_placeholder.beVisible()
141144
mimetypes_placeholder_2.beVisible()
142145
}
@@ -150,14 +153,9 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
150153

151154
runOnUiThread {
152155
getRecyclerAdapter()?.updateItems(listItems, text)
153-
mimetypes_list.beVisibleIf(listItems.isNotEmpty())
156+
mimetypes_fastscroller.beVisibleIf(listItems.isNotEmpty())
154157
mimetypes_placeholder.beVisibleIf(listItems.isEmpty())
155158
mimetypes_placeholder_2.beGone()
156-
157-
mimetypes_list.onGlobalLayout {
158-
items_fastscroller.setScrollToY(mimetypes_list.computeVerticalScrollOffset())
159-
calculateContentHeight(listItems)
160-
}
161159
}
162160
}
163161
}
@@ -232,7 +230,7 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
232230
isSearchOpen = false
233231
lastSearchedText = ""
234232

235-
mimetypes_list.beVisible()
233+
mimetypes_fastscroller.beVisible()
236234
mimetypes_placeholder.beGoneIf(storedItems.isNotEmpty())
237235
mimetypes_placeholder_2.beGone()
238236
}
@@ -321,7 +319,7 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
321319
}
322320

323321
storedItems = items
324-
ItemsAdapter(this as SimpleActivity, storedItems, this, mimetypes_list, false, items_fastscroller, null) {
322+
ItemsAdapter(this as SimpleActivity, storedItems, this, mimetypes_list, false, null) {
325323
tryOpenPathIntent((it as ListItem).path, false)
326324
}.apply {
327325
setupZoomListener(zoomListener)
@@ -332,13 +330,6 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
332330
mimetypes_list.scheduleLayoutAnimation()
333331
}
334332

335-
val dateFormat = config.dateFormat
336-
val timeFormat = getTimeFormat()
337-
items_fastscroller.setViews(mimetypes_list) {
338-
val listItem = getRecyclerAdapter()?.listItems?.getOrNull(it)
339-
items_fastscroller.updateBubbleText(listItem?.getBubbleText(this, dateFormat, timeFormat) ?: "")
340-
}
341-
342333
mimetypes_placeholder.beVisibleIf(items.isEmpty())
343334
}
344335

@@ -390,18 +381,9 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
390381
invalidateOptionsMenu()
391382
getRecyclerAdapter()?.apply {
392383
notifyItemRangeChanged(0, listItems.size)
393-
calculateContentHeight(listItems)
394384
}
395385
}
396386

397-
private fun calculateContentHeight(items: MutableList<ListItem>) {
398-
val layoutManager = mimetypes_list.layoutManager as MyGridLayoutManager
399-
val thumbnailHeight = layoutManager.getChildAt(0)?.height ?: 0
400-
val fullHeight = ((items.size - 1) / layoutManager.spanCount + 1) * thumbnailHeight
401-
items_fastscroller.setContentHeight(fullHeight)
402-
items_fastscroller.setScrollToY(mimetypes_list.computeVerticalScrollOffset())
403-
}
404-
405387
private fun setupLayoutManager() {
406388
if (config.getFolderViewType(currentMimeType) == VIEW_TYPE_GRID) {
407389
currentViewType = VIEW_TYPE_GRID

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
1212
import com.bumptech.glide.request.RequestOptions
1313
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
1414
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
15-
import com.simplemobiletools.commons.extensions.getFileSignature
1615
import com.simplemobiletools.commons.extensions.getTextSize
1716
import com.simplemobiletools.commons.extensions.getTimeFormat
1817
import com.simplemobiletools.commons.helpers.getFilePlaceholderDrawables
@@ -25,7 +24,7 @@ import kotlinx.android.synthetic.main.item_file_dir_list.view.*
2524
import java.util.*
2625

2726
class DecompressItemsAdapter(activity: SimpleActivity, var listItems: MutableList<ListItem>, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) :
28-
MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
27+
MyRecyclerViewAdapter(activity, recyclerView, itemClick) {
2928

3029
private lateinit var fileDrawable: Drawable
3130
private lateinit var folderDrawable: Drawable

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ import com.bumptech.glide.load.resource.bitmap.CenterCrop
2424
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
2525
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
2626
import com.bumptech.glide.request.RequestOptions
27+
import com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
2728
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
2829
import com.simplemobiletools.commons.dialogs.*
2930
import com.simplemobiletools.commons.extensions.*
3031
import com.simplemobiletools.commons.helpers.*
3132
import com.simplemobiletools.commons.models.FileDirItem
3233
import com.simplemobiletools.commons.models.RadioItem
33-
import com.simplemobiletools.commons.views.FastScroller
3434
import com.simplemobiletools.commons.views.MyRecyclerView
3535
import com.simplemobiletools.filemanager.pro.R
3636
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
@@ -41,13 +41,13 @@ 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 java.io.BufferedInputStream
4544
import kotlinx.android.synthetic.main.item_file_dir_grid.view.*
4645
import kotlinx.android.synthetic.main.item_file_dir_list.view.*
4746
import kotlinx.android.synthetic.main.item_file_dir_list.view.item_frame
4847
import kotlinx.android.synthetic.main.item_file_dir_list.view.item_icon
4948
import kotlinx.android.synthetic.main.item_file_dir_list.view.item_name
5049
import kotlinx.android.synthetic.main.item_section.view.*
50+
import java.io.BufferedInputStream
5151
import java.io.Closeable
5252
import java.io.File
5353
import java.util.*
@@ -57,9 +57,9 @@ import java.util.zip.ZipOutputStream
5757

5858
class ItemsAdapter(
5959
activity: SimpleActivity, var listItems: MutableList<ListItem>, val listener: ItemOperationsListener?, recyclerView: MyRecyclerView,
60-
val isPickMultipleIntent: Boolean, fastScroller: FastScroller?, val swipeRefreshLayout: SwipeRefreshLayout?, itemClick: (Any) -> Unit
60+
val isPickMultipleIntent: Boolean, val swipeRefreshLayout: SwipeRefreshLayout?, itemClick: (Any) -> Unit
6161
) :
62-
MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
62+
MyRecyclerViewAdapter(activity, recyclerView, itemClick), RecyclerViewFastScroller.OnPopupTextUpdate {
6363

6464
private val TYPE_FILE_DIR = 1
6565
private val TYPE_SECTION = 2
@@ -326,6 +326,7 @@ class ItemsAdapter(
326326
}
327327
}
328328

329+
@SuppressLint("NewApi")
329330
private fun addFileUris(path: String, paths: ArrayList<String>) {
330331
if (activity.getIsPathDirectory(path)) {
331332
val shouldShowHidden = activity.config.shouldShowHidden
@@ -621,6 +622,7 @@ class ItemsAdapter(
621622
}
622623
}
623624

625+
@SuppressLint("NewApi")
624626
private fun compressPaths(sourcePaths: List<String>, targetPath: String): Boolean {
625627
val queue = LinkedList<String>()
626628
val fos = activity.getFileOutputStreamSync(targetPath, "application/zip") ?: return false
@@ -759,7 +761,6 @@ class ItemsAdapter(
759761
textToHighlight = highlightText
760762
notifyDataSetChanged()
761763
}
762-
fastScroller?.measureRecyclerView()
763764
}
764765

765766
fun updateFontSizes() {
@@ -899,4 +900,6 @@ class ItemsAdapter(
899900
fileDrawable = resources.getDrawable(R.drawable.ic_file_generic)
900901
fileDrawables = getFilePlaceholderDrawables(activity)
901902
}
903+
904+
override fun onChange(position: Int) = listItems.getOrNull(position)?.getBubbleText(activity, dateFormat, timeFormat) ?: ""
902905
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import com.simplemobiletools.filemanager.pro.extensions.config
1212
import kotlinx.android.synthetic.main.item_manage_favorite.view.*
1313
import java.util.*
1414

15-
class ManageFavoritesAdapter(activity: BaseSimpleActivity, var favorites: ArrayList<String>, val listener: RefreshRecyclerViewListener?,
16-
recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
15+
class ManageFavoritesAdapter(
16+
activity: BaseSimpleActivity, var favorites: ArrayList<String>, val listener: RefreshRecyclerViewListener?,
17+
recyclerView: MyRecyclerView, itemClick: (Any) -> Unit
18+
) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) {
1719

1820
private val config = activity.config
1921

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

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.simplemobiletools.filemanager.pro.fragments
22

3+
import android.annotation.SuppressLint
34
import android.content.Context
45
import android.os.Parcelable
56
import android.util.AttributeSet
@@ -50,15 +51,14 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
5051

5152
override fun onResume(textColor: Int, primaryColor: Int) {
5253
context!!.updateTextColors(this)
53-
items_fastscroller.updatePrimaryColor()
5454
storedItems = ArrayList()
5555
getRecyclerAdapter()?.apply {
5656
updatePrimaryColor(primaryColor)
5757
updateTextColor(textColor)
5858
initDrawables()
5959
}
6060

61-
items_fastscroller.updateBubbleColors()
61+
items_fastscroller.updateColors(primaryColor, primaryColor.getContrastColor())
6262

6363
if (currentPath != "") {
6464
breadcrumbs.updateColor(textColor)
@@ -124,10 +124,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
124124
breadcrumbs.updateFontSize(context!!.getTextSize())
125125
}
126126

127-
ItemsAdapter(
128-
activity as SimpleActivity, storedItems, this, items_list, isPickMultipleIntent, items_fastscroller,
129-
items_swipe_refresh
130-
) {
127+
ItemsAdapter(activity as SimpleActivity, storedItems, this, items_list, isPickMultipleIntent, items_swipe_refresh) {
131128
if ((it as? ListItem)?.isSectionTitle == true) {
132129
openDirectory(it.mPath)
133130
searchClosed()
@@ -143,25 +140,15 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
143140
items_list.scheduleLayoutAnimation()
144141
}
145142

146-
val dateFormat = context!!.config.dateFormat
147-
val timeFormat = context!!.getTimeFormat()
148-
items_fastscroller.setViews(items_list, items_swipe_refresh) {
149-
val listItem = getRecyclerAdapter()?.listItems?.getOrNull(it)
150-
items_fastscroller.updateBubbleText(listItem?.getBubbleText(context, dateFormat, timeFormat) ?: "")
151-
}
152-
153143
getRecyclerLayoutManager().onRestoreInstanceState(scrollStates[currentPath])
154-
items_list.onGlobalLayout {
155-
items_fastscroller.setScrollToY(items_list.computeVerticalScrollOffset())
156-
calculateContentHeight(storedItems)
157-
}
158144
}
159145
}
160146

161147
private fun getScrollState() = getRecyclerLayoutManager().onSaveInstanceState()
162148

163149
private fun getRecyclerLayoutManager() = (items_list.layoutManager as MyGridLayoutManager)
164150

151+
@SuppressLint("NewApi")
165152
private fun getItems(path: String, callback: (originalPath: String, items: ArrayList<ListItem>) -> Unit) {
166153
skipItemUpdating = false
167154
ensureBackgroundThread {
@@ -289,13 +276,13 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
289276

290277
when {
291278
searchText.isEmpty() -> {
292-
items_list.beVisible()
279+
items_fastscroller.beVisible()
293280
getRecyclerAdapter()?.updateItems(storedItems)
294281
items_placeholder.beGone()
295282
items_placeholder_2.beGone()
296283
}
297284
searchText.length == 1 -> {
298-
items_list.beGone()
285+
items_fastscroller.beGone()
299286
items_placeholder.beVisible()
300287
items_placeholder_2.beVisible()
301288
}
@@ -332,14 +319,9 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
332319

333320
activity?.runOnUiThread {
334321
getRecyclerAdapter()?.updateItems(listItems, text)
335-
items_list.beVisibleIf(listItems.isNotEmpty())
322+
items_fastscroller.beVisibleIf(listItems.isNotEmpty())
336323
items_placeholder.beVisibleIf(listItems.isEmpty())
337324
items_placeholder_2.beGone()
338-
339-
items_list.onGlobalLayout {
340-
items_fastscroller.setScrollToY(items_list.computeVerticalScrollOffset())
341-
calculateContentHeight(listItems)
342-
}
343325
}
344326
}
345327
}
@@ -391,13 +373,13 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
391373
isSearchOpen = false
392374
if (!skipItemUpdating) {
393375
getRecyclerAdapter()?.updateItems(storedItems)
394-
calculateContentHeight(storedItems)
395376
}
377+
396378
skipItemUpdating = false
397379
lastSearchedText = ""
398380

399381
items_swipe_refresh.isEnabled = true
400-
items_list.beVisible()
382+
items_fastscroller.beVisible()
401383
items_placeholder.beGone()
402384
items_placeholder_2.beGone()
403385
}
@@ -472,14 +454,6 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
472454
}
473455
}
474456

475-
private fun calculateContentHeight(items: MutableList<ListItem>) {
476-
val layoutManager = items_list.layoutManager as MyGridLayoutManager
477-
val thumbnailHeight = layoutManager.getChildAt(0)?.height ?: 0
478-
val fullHeight = ((items.size - 1) / layoutManager.spanCount + 1) * thumbnailHeight
479-
items_fastscroller.setContentHeight(fullHeight)
480-
items_fastscroller.setScrollToY(items_list.computeVerticalScrollOffset())
481-
}
482-
483457
override fun increaseColumnCount() {
484458
if (currentViewType == VIEW_TYPE_GRID) {
485459
context?.config?.fileColumnCnt = ++(items_list.layoutManager as MyGridLayoutManager).spanCount
@@ -498,7 +472,6 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
498472
activity?.invalidateOptionsMenu()
499473
getRecyclerAdapter()?.apply {
500474
notifyItemRangeChanged(0, listItems.size)
501-
calculateContentHeight(listItems)
502475
}
503476
}
504477

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
@@ -55,7 +55,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
5555
return
5656
}
5757

58-
ItemsAdapter(activity as SimpleActivity, recents, this, recents_list, isPickMultipleIntent, null, recents_swipe_refresh) {
58+
ItemsAdapter(activity as SimpleActivity, recents, this, recents_list, isPickMultipleIntent, recents_swipe_refresh) {
5959
clickedPath((it as FileDirItem).path)
6060
}.apply {
6161
recents_list.adapter = this

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

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,20 @@
3535
android:textStyle="italic"
3636
android:visibility="gone" />
3737

38-
<com.simplemobiletools.commons.views.MyRecyclerView
39-
android:id="@+id/mimetypes_list"
38+
<com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
39+
android:id="@+id/mimetypes_fastscroller"
4040
android:layout_width="match_parent"
41-
android:layout_height="match_parent"
42-
android:clipToPadding="false"
43-
android:layoutAnimation="@anim/layout_animation"
44-
android:paddingTop="@dimen/small_margin"
45-
android:scrollbars="none"
46-
app:layoutManager="com.simplemobiletools.commons.views.MyGridLayoutManager" />
41+
android:layout_height="wrap_content">
4742

48-
<com.simplemobiletools.commons.views.FastScroller
49-
android:id="@+id/items_fastscroller"
50-
android:layout_width="wrap_content"
51-
android:layout_height="match_parent"
52-
android:layout_alignParentEnd="true"
53-
android:paddingStart="@dimen/normal_margin">
54-
55-
<include layout="@layout/fastscroller_handle_vertical" />
43+
<com.simplemobiletools.commons.views.MyRecyclerView
44+
android:id="@+id/mimetypes_list"
45+
android:layout_width="match_parent"
46+
android:layout_height="match_parent"
47+
android:clipToPadding="false"
48+
android:layoutAnimation="@anim/layout_animation"
49+
android:paddingTop="@dimen/small_margin"
50+
android:scrollbars="none"
51+
app:layoutManager="com.simplemobiletools.commons.views.MyGridLayoutManager" />
5652

57-
</com.simplemobiletools.commons.views.FastScroller>
53+
</com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller>
5854
</RelativeLayout>

0 commit comments

Comments
 (0)