Skip to content

Commit fde83fd

Browse files
committed
add a menu item for Adding favorites at the manage favorites screen
1 parent 54b13bb commit fde83fd

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ android {
3232
}
3333

3434
dependencies {
35-
compile 'com.simplemobiletools:commons:2.12.7'
35+
compile 'com.simplemobiletools:commons:2.12.8'
3636
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'
3737
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
3838
}

app/src/main/kotlin/com/simplemobiletools/filemanager/activities/FavoritesActivity.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package com.simplemobiletools.filemanager.activities
22

33
import android.graphics.PorterDuff
44
import android.os.Bundle
5+
import android.view.Menu
6+
import android.view.MenuItem
7+
import com.simplemobiletools.commons.dialogs.FilePickerDialog
58
import com.simplemobiletools.commons.extensions.beVisibleIf
69
import com.simplemobiletools.filemanager.R
710
import com.simplemobiletools.filemanager.extensions.config
@@ -38,4 +41,24 @@ class FavoritesActivity : SimpleActivity() {
3841
}
3942
}
4043
}
44+
45+
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
46+
menuInflater.inflate(R.menu.menu_favorites, menu)
47+
return true
48+
}
49+
50+
override fun onOptionsItemSelected(item: MenuItem): Boolean {
51+
when (item.itemId) {
52+
R.id.add_favorite -> addFavorite()
53+
else -> return super.onOptionsItemSelected(item)
54+
}
55+
return true
56+
}
57+
58+
private fun addFavorite() {
59+
FilePickerDialog(this, pickFile = false, showHidden = config.showHidden) {
60+
config.addFavorite(it)
61+
updateFavorites()
62+
}
63+
}
4164
}

app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
5757
breadcrumbs.setTextColor(mStoredTextColor)
5858
openPath(currentPath)
5959
}
60+
invalidateOptionsMenu()
6061
}
6162

6263
override fun onPause() {
@@ -82,12 +83,13 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
8283
}
8384

8485
private fun openPath(path: String) {
85-
breadcrumbs.setBreadcrumb(path)
86+
val realPath = path.trimEnd('/')
87+
breadcrumbs.setBreadcrumb(realPath)
8688
val bundle = Bundle()
87-
bundle.putString(PATH, path)
89+
bundle.putString(PATH, realPath)
8890

89-
if (mScrollStates.containsKey(path.trimEnd('/'))) {
90-
bundle.putParcelable(SCROLL_STATE, mScrollStates[path.trimEnd('/')])
91+
if (mScrollStates.containsKey(realPath)) {
92+
bundle.putParcelable(SCROLL_STATE, mScrollStates[realPath])
9193
}
9294

9395
if (latestFragment != null) {
@@ -97,9 +99,9 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
9799
latestFragment = ItemsFragment().apply {
98100
arguments = bundle
99101
setListener(this@MainActivity)
100-
supportFragmentManager.beginTransaction().replace(R.id.fragment_holder, this).addToBackStack(path).commitAllowingStateLoss()
102+
supportFragmentManager.beginTransaction().replace(R.id.fragment_holder, this).addToBackStack(realPath).commitAllowingStateLoss()
101103
}
102-
currentPath = path
104+
currentPath = realPath
103105
invalidateOptionsMenu()
104106
}
105107

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<menu xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto">
4+
<item
5+
android:id="@+id/add_favorite"
6+
android:icon="@drawable/ic_plus"
7+
android:title="@string/add_to_favorites"
8+
app:showAsAction="ifRoom"/>
9+
</menu>

0 commit comments

Comments
 (0)