updating main and settings activities

This commit is contained in:
tibbi 2022-07-27 12:03:34 +02:00
parent c5f56edf66
commit 4ed9b0be5c
5 changed files with 1191 additions and 1128 deletions

View file

@ -78,7 +78,7 @@ android {
} }
dependencies { dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:2327fff588' implementation 'com.github.SimpleMobileTools:Simple-Commons:becd38a3b7'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'it.sephiroth.android.exif:library:1.0.1'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.24' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.24'

View file

@ -109,6 +109,9 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
mIsThirdPartyIntent = mIsPickImageIntent || mIsPickVideoIntent || mIsGetImageContentIntent || mIsGetVideoContentIntent || mIsThirdPartyIntent = mIsPickImageIntent || mIsPickVideoIntent || mIsGetImageContentIntent || mIsGetVideoContentIntent ||
mIsGetAnyContentIntent || mIsSetWallpaperIntent mIsGetAnyContentIntent || mIsSetWallpaperIntent
setupOptionsMenu()
refreshMenuItems()
directories_refresh_layout.setOnRefreshListener { getDirectories() } directories_refresh_layout.setOnRefreshListener { getDirectories() }
storeStateVariables() storeStateVariables()
checkWhatsNewDialog() checkWhatsNewDialog()
@ -179,6 +182,9 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
mDateFormat = config.dateFormat mDateFormat = config.dateFormat
mTimeFormat = getTimeFormat() mTimeFormat = getTimeFormat()
setupToolbar(directories_toolbar, searchMenuItem = mSearchMenuItem)
refreshMenuItems()
if (mStoredAnimateGifs != config.animateGifs) { if (mStoredAnimateGifs != config.animateGifs) {
getRecyclerAdapter()?.updateAnimateGifs(config.animateGifs) getRecyclerAdapter()?.updateAnimateGifs(config.animateGifs)
} }
@ -221,7 +227,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
directories_empty_placeholder_2.bringToFront() directories_empty_placeholder_2.bringToFront()
if (!mIsSearchOpen) { if (!mIsSearchOpen) {
invalidateOptionsMenu() refreshMenuItems()
if (mIsPasswordProtectionPending && !mWasProtectionHandled) { if (mIsPasswordProtectionPending && !mWasProtectionHandled) {
handleAppPasswordProtection { handleAppPasswordProtection {
mWasProtectionHandled = it mWasProtectionHandled = it
@ -278,7 +284,9 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
} }
override fun onBackPressed() { override fun onBackPressed() {
if (config.groupDirectSubfolders) { if (mIsSearchOpen && mSearchMenuItem != null) {
mSearchMenuItem!!.collapseActionView()
} else if (config.groupDirectSubfolders) {
if (mCurrentPathPrefix.isEmpty()) { if (mCurrentPathPrefix.isEmpty()) {
super.onBackPressed() super.onBackPressed()
} else { } else {
@ -291,13 +299,10 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
} }
} }
override fun onCreateOptionsMenu(menu: Menu): Boolean { private fun refreshMenuItems() {
if (mIsThirdPartyIntent) { if (!mIsThirdPartyIntent) {
menuInflater.inflate(R.menu.menu_main_intent, menu)
} else {
menuInflater.inflate(R.menu.menu_main, menu)
val useBin = config.useRecycleBin val useBin = config.useRecycleBin
menu.apply { directories_toolbar.menu.apply {
findItem(R.id.increase_column_count).isVisible = config.viewTypeFolders == VIEW_TYPE_GRID && config.dirColumnCnt < MAX_COLUMN_COUNT findItem(R.id.increase_column_count).isVisible = config.viewTypeFolders == VIEW_TYPE_GRID && config.dirColumnCnt < MAX_COLUMN_COUNT
findItem(R.id.reduce_column_count).isVisible = config.viewTypeFolders == VIEW_TYPE_GRID && config.dirColumnCnt > 1 findItem(R.id.reduce_column_count).isVisible = config.viewTypeFolders == VIEW_TYPE_GRID && config.dirColumnCnt > 1
findItem(R.id.hide_the_recycle_bin).isVisible = useBin && config.showRecycleBinAtFolders findItem(R.id.hide_the_recycle_bin).isVisible = useBin && config.showRecycleBinAtFolders
@ -307,18 +312,30 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
} }
} }
menu.findItem(R.id.temporarily_show_hidden).isVisible = (!isRPlus() || isExternalStorageManager()) && !config.shouldShowHidden directories_toolbar.menu.apply {
menu.findItem(R.id.stop_showing_hidden).isVisible = (!isRPlus() || isExternalStorageManager()) && config.temporarilyShowHidden findItem(R.id.temporarily_show_hidden).isVisible = (!isRPlus() || isExternalStorageManager()) && !config.shouldShowHidden
findItem(R.id.stop_showing_hidden).isVisible = (!isRPlus() || isExternalStorageManager()) && config.temporarilyShowHidden
menu.findItem(R.id.temporarily_show_excluded).isVisible = !menu.findItem(R.id.temporarily_show_hidden).isVisible && !config.temporarilyShowExcluded findItem(R.id.temporarily_show_excluded).isVisible = !findItem(R.id.temporarily_show_hidden).isVisible && !config.temporarilyShowExcluded
menu.findItem(R.id.stop_showing_excluded).isVisible = !menu.findItem(R.id.temporarily_show_hidden).isVisible && config.temporarilyShowExcluded findItem(R.id.stop_showing_excluded).isVisible = !findItem(R.id.temporarily_show_hidden).isVisible && config.temporarilyShowExcluded
}
updateMenuItemColors(menu)
return true
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { private fun setupOptionsMenu() {
when (item.itemId) { val menuId = if (mIsThirdPartyIntent) {
R.menu.menu_main_intent
} else {
R.menu.menu_main
}
directories_toolbar.inflateMenu(menuId)
if (!mIsThirdPartyIntent) {
setupSearch(directories_toolbar.menu)
}
directories_toolbar.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) {
R.id.sort -> showSortingDialog() R.id.sort -> showSortingDialog()
R.id.filter -> showFilterMediaDialog() R.id.filter -> showFilterMediaDialog()
R.id.open_camera -> launchCamera() R.id.open_camera -> launchCamera()
@ -336,9 +353,10 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
R.id.set_as_default_folder -> setAsDefaultFolder() R.id.set_as_default_folder -> setAsDefaultFolder()
R.id.settings -> launchSettings() R.id.settings -> launchSettings()
R.id.about -> launchAbout() R.id.about -> launchAbout()
else -> return super.onOptionsItemSelected(item) else -> return@setOnMenuItemClickListener false
}
return@setOnMenuItemClickListener true
} }
return true
} }
override fun onSaveInstanceState(outState: Bundle) { override fun onSaveInstanceState(outState: Bundle) {
@ -553,7 +571,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
private fun changeViewType() { private fun changeViewType() {
ChangeViewTypeDialog(this, true) { ChangeViewTypeDialog(this, true) {
invalidateOptionsMenu() refreshMenuItems()
setupLayoutManager() setupLayoutManager()
directories_grid.adapter = null directories_grid.adapter = null
setupAdapter(getRecyclerAdapter()?.dirs ?: mDirs) setupAdapter(getRecyclerAdapter()?.dirs ?: mDirs)
@ -575,7 +593,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
config.temporarilyShowHidden = show config.temporarilyShowHidden = show
directories_grid.adapter = null directories_grid.adapter = null
getDirectories() getDirectories()
invalidateOptionsMenu() refreshMenuItems()
} }
private fun tryToggleTemporarilyShowExcluded() { private fun tryToggleTemporarilyShowExcluded() {
@ -593,7 +611,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
config.temporarilyShowExcluded = show config.temporarilyShowExcluded = show
directories_grid.adapter = null directories_grid.adapter = null
getDirectories() getDirectories()
invalidateOptionsMenu() refreshMenuItems()
} }
override fun deleteFolders(folders: ArrayList<File>) { override fun deleteFolders(folders: ArrayList<File>) {
@ -724,7 +742,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
private fun toggleRecycleBin(show: Boolean) { private fun toggleRecycleBin(show: Boolean) {
config.showRecycleBinAtFolders = show config.showRecycleBinAtFolders = show
invalidateOptionsMenu() refreshMenuItems()
ensureBackgroundThread { ensureBackgroundThread {
var dirs = getCurrentlyDisplayedDirs() var dirs = getCurrentlyDisplayedDirs()
if (!show) { if (!show) {
@ -756,7 +774,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
} }
private fun columnCountChanged() { private fun columnCountChanged() {
invalidateOptionsMenu() refreshMenuItems()
getRecyclerAdapter()?.apply { getRecyclerAdapter()?.apply {
notifyItemRangeChanged(0, dirs.size) notifyItemRangeChanged(0, dirs.size)
} }
@ -1162,7 +1180,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
private fun setAsDefaultFolder() { private fun setAsDefaultFolder() {
config.defaultFolder = "" config.defaultFolder = ""
invalidateOptionsMenu() refreshMenuItems()
} }
private fun openDefaultFolder() { private fun openDefaultFolder() {

View file

@ -35,6 +35,7 @@ class SettingsActivity : SimpleActivity() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
setupToolbar(settings_toolbar, NavigationIcon.Arrow)
setupSettingItems() setupSettingItems()
} }
@ -89,7 +90,6 @@ class SettingsActivity : SimpleActivity() {
setupClearCache() setupClearCache()
setupExportSettings() setupExportSettings()
setupImportSettings() setupImportSettings()
invalidateOptionsMenu()
arrayOf( arrayOf(
settings_color_customization_label, settings_color_customization_label,

View file

@ -1,10 +1,31 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/directories_holder" android:id="@+id/directories_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/directories_app_bar_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/directories_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/color_primary"
app:title="@string/app_launcher_name"
app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" />
</com.google.android.material.appbar.AppBarLayout>
<RelativeLayout
android:id="@+id/directories_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<com.simplemobiletools.commons.views.MyTextView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/directories_switch_searching" android:id="@+id/directories_switch_searching"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -66,3 +87,4 @@
</com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller> </com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout> </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</RelativeLayout> </RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -1,10 +1,32 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/settings_scrollview" android:id="@+id/settings_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/settings_app_bar_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/settings_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/color_primary"
app:title="@string/settings"
app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/settings_scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout <LinearLayout
android:id="@+id/settings_holder" android:id="@+id/settings_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -1043,4 +1065,5 @@
</RelativeLayout> </RelativeLayout>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>