adding an initial implementation of Mimetypes activity

This commit is contained in:
tibbi 2021-10-13 12:02:54 +02:00
parent b30fa5e154
commit 591c4c56ad
5 changed files with 186 additions and 13 deletions

View File

@ -54,6 +54,8 @@
</intent-filter>
</activity>
<activity android:name=".activities.MimeTypesActivity" />
<activity
android:name=".activities.ReadTextActivity"
android:label="@string/file_editor">

View File

@ -0,0 +1,151 @@
package com.simplemobiletools.filemanager.pro.activities
import android.app.SearchManager
import android.content.Context
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuItemCompat
import com.simplemobiletools.commons.extensions.handleHiddenFolderPasswordProtection
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.helpers.VIEW_TYPE_GRID
import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.dialogs.ChangeSortingDialog
import com.simplemobiletools.filemanager.pro.dialogs.ChangeViewTypeDialog
import com.simplemobiletools.filemanager.pro.extensions.config
import com.simplemobiletools.filemanager.pro.helpers.*
class MimeTypesActivity : SimpleActivity() {
private var isSearchOpen = false
private var searchMenuItem: MenuItem? = null
private var currentMimeType = ""
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_mimetypes)
currentMimeType = intent.getStringExtra(SHOW_MIMETYPE) ?: return
title = getString(
when (currentMimeType) {
IMAGES -> R.string.images
VIDEOS -> R.string.videos
AUDIO -> R.string.audio
DOCUMENTS -> R.string.documents
ARCHIVES -> R.string.archives
OTHERS -> R.string.others
else -> {
toast(R.string.unknown_error_occurred)
finish()
return
}
}
)
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu, menu)
setupSearch(menu)
updateMenuItemColors(menu)
return true
}
override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
val currentViewType = config.getFolderViewType(currentMimeType)
menu!!.apply {
findItem(R.id.add_favorite).isVisible = false
findItem(R.id.remove_favorite).isVisible = false
findItem(R.id.go_to_favorite).isVisible = false
findItem(R.id.toggle_filename).isVisible = currentViewType == VIEW_TYPE_GRID
findItem(R.id.go_home).isVisible = false
findItem(R.id.set_as_home).isVisible = false
findItem(R.id.settings).isVisible = false
findItem(R.id.about).isVisible = false
findItem(R.id.temporarily_show_hidden).isVisible = !config.shouldShowHidden
findItem(R.id.stop_showing_hidden).isVisible = config.temporarilyShowHidden
findItem(R.id.increase_column_count).isVisible = currentViewType == VIEW_TYPE_GRID && config.fileColumnCnt < MAX_COLUMN_COUNT
findItem(R.id.reduce_column_count).isVisible = currentViewType == VIEW_TYPE_GRID && config.fileColumnCnt > 1
}
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.sort -> showSortingDialog()
R.id.toggle_filename -> toggleFilenameVisibility()
R.id.change_view_type -> changeViewType()
R.id.temporarily_show_hidden -> tryToggleTemporarilyShowHidden()
R.id.stop_showing_hidden -> tryToggleTemporarilyShowHidden()
R.id.increase_column_count -> increaseColumnCount()
R.id.reduce_column_count -> reduceColumnCount()
else -> return super.onOptionsItemSelected(item)
}
return true
}
private fun setupSearch(menu: Menu) {
val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager
searchMenuItem = menu.findItem(R.id.search)
(searchMenuItem!!.actionView as SearchView).apply {
setSearchableInfo(searchManager.getSearchableInfo(componentName))
isSubmitButtonEnabled = false
queryHint = getString(R.string.search)
setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String) = false
override fun onQueryTextChange(newText: String): Boolean {
if (isSearchOpen) {
}
return true
}
})
}
MenuItemCompat.setOnActionExpandListener(searchMenuItem, object : MenuItemCompat.OnActionExpandListener {
override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
isSearchOpen = true
return true
}
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
isSearchOpen = false
return true
}
})
}
private fun showSortingDialog() {
ChangeSortingDialog(this, currentMimeType) {
}
}
private fun toggleFilenameVisibility() {
config.displayFilenames = !config.displayFilenames
}
private fun increaseColumnCount() {}
private fun reduceColumnCount() {}
private fun changeViewType() {
ChangeViewTypeDialog(this, currentMimeType, true) { }
}
private fun tryToggleTemporarilyShowHidden() {
if (config.temporarilyShowHidden) {
toggleTemporarilyShowHidden(false)
} else {
handleHiddenFolderPasswordProtection {
toggleTemporarilyShowHidden(true)
}
}
}
private fun toggleTemporarilyShowHidden(show: Boolean) {
config.temporarilyShowHidden = show
}
}

View File

@ -12,20 +12,15 @@ import androidx.appcompat.app.AppCompatActivity
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.activities.MimeTypesActivity
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
import com.simplemobiletools.filemanager.pro.extensions.formatSizeThousand
import com.simplemobiletools.filemanager.pro.helpers.*
import kotlinx.android.synthetic.main.storage_fragment.view.*
import java.util.*
import kotlin.collections.HashMap
class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
private val IMAGES = "images"
private val VIDEOS = "videos"
private val AUDIO = "audio"
private val DOCUMENTS = "documents"
private val ARCHIVES = "archives"
private val OTHERS = "others"
private val SIZE_DIVIDER = 100000
// what else should we count as an audio except "audio/*" mimetype
@ -96,12 +91,12 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
}
}
images_holder.setOnClickListener { }
videos_holder.setOnClickListener { }
audio_holder.setOnClickListener { }
documents_holder.setOnClickListener { }
archives_holder.setOnClickListener { }
others_holder.setOnClickListener { }
images_holder.setOnClickListener { launchMimetypeActivity(IMAGES) }
videos_holder.setOnClickListener { launchMimetypeActivity(VIDEOS) }
audio_holder.setOnClickListener { launchMimetypeActivity(AUDIO) }
documents_holder.setOnClickListener { launchMimetypeActivity(DOCUMENTS) }
archives_holder.setOnClickListener { launchMimetypeActivity(ARCHIVES) }
others_holder.setOnClickListener { launchMimetypeActivity(OTHERS) }
}
override fun refreshFragment() {}
@ -137,6 +132,13 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
others_progressbar.trackColor = pinkColor.adjustAlpha(0.3f)
}
private fun launchMimetypeActivity(mimetype: String) {
Intent(context, MimeTypesActivity::class.java).apply {
putExtra(SHOW_MIMETYPE, mimetype)
context.startActivity(this)
}
}
private fun getSizesByMimeType(): HashMap<String, Long> {
val uri = MediaStore.Files.getContentUri("external")
val projection = arrayOf(

View File

@ -33,3 +33,11 @@ const val OPEN_AS_OTHER = 5
const val ALL_TABS_MASK = TAB_FILES or TAB_RECENT_FILES or TAB_STORAGE_ANALYSIS
val tabsList = arrayListOf(TAB_FILES, TAB_RECENT_FILES, TAB_STORAGE_ANALYSIS)
const val IMAGES = "images"
const val VIDEOS = "videos"
const val AUDIO = "audio"
const val DOCUMENTS = "documents"
const val ARCHIVES = "archives"
const val OTHERS = "others"
const val SHOW_MIMETYPE = "show_mimetype"

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<com.simplemobiletools.commons.views.MyRecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/mimetypes_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:layoutAnimation="@anim/layout_animation"
android:scrollbars="none"
app:layoutManager="com.simplemobiletools.commons.views.MyGridLayoutManager" />