add a menu item for Adding favorites at the manage favorites screen
This commit is contained in:
parent
54b13bb54e
commit
fde83fdc5a
4 changed files with 41 additions and 7 deletions
|
@ -32,7 +32,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.simplemobiletools:commons:2.12.7'
|
||||
compile 'com.simplemobiletools:commons:2.12.8'
|
||||
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@ package com.simplemobiletools.filemanager.activities
|
|||
|
||||
import android.graphics.PorterDuff
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.filemanager.R
|
||||
import com.simplemobiletools.filemanager.extensions.config
|
||||
|
@ -38,4 +41,24 @@ class FavoritesActivity : SimpleActivity() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_favorites, menu)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.add_favorite -> addFavorite()
|
||||
else -> return super.onOptionsItemSelected(item)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun addFavorite() {
|
||||
FilePickerDialog(this, pickFile = false, showHidden = config.showHidden) {
|
||||
config.addFavorite(it)
|
||||
updateFavorites()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
|
|||
breadcrumbs.setTextColor(mStoredTextColor)
|
||||
openPath(currentPath)
|
||||
}
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
|
@ -82,12 +83,13 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
|
|||
}
|
||||
|
||||
private fun openPath(path: String) {
|
||||
breadcrumbs.setBreadcrumb(path)
|
||||
val realPath = path.trimEnd('/')
|
||||
breadcrumbs.setBreadcrumb(realPath)
|
||||
val bundle = Bundle()
|
||||
bundle.putString(PATH, path)
|
||||
bundle.putString(PATH, realPath)
|
||||
|
||||
if (mScrollStates.containsKey(path.trimEnd('/'))) {
|
||||
bundle.putParcelable(SCROLL_STATE, mScrollStates[path.trimEnd('/')])
|
||||
if (mScrollStates.containsKey(realPath)) {
|
||||
bundle.putParcelable(SCROLL_STATE, mScrollStates[realPath])
|
||||
}
|
||||
|
||||
if (latestFragment != null) {
|
||||
|
@ -97,9 +99,9 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
|
|||
latestFragment = ItemsFragment().apply {
|
||||
arguments = bundle
|
||||
setListener(this@MainActivity)
|
||||
supportFragmentManager.beginTransaction().replace(R.id.fragment_holder, this).addToBackStack(path).commitAllowingStateLoss()
|
||||
supportFragmentManager.beginTransaction().replace(R.id.fragment_holder, this).addToBackStack(realPath).commitAllowingStateLoss()
|
||||
}
|
||||
currentPath = path
|
||||
currentPath = realPath
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
|
||||
|
|
9
app/src/main/res/menu/menu_favorites.xml
Normal file
9
app/src/main/res/menu/menu_favorites.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/add_favorite"
|
||||
android:icon="@drawable/ic_plus"
|
||||
android:title="@string/add_to_favorites"
|
||||
app:showAsAction="ifRoom"/>
|
||||
</menu>
|
Loading…
Reference in a new issue