diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index a357ff1b6..5b33873f0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -283,6 +283,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View findItem(R.id.menu_save_as).isVisible = mRotationDegrees != 0 findItem(R.id.menu_hide).isVisible = !currentMedium.name.startsWith('.') findItem(R.id.menu_unhide).isVisible = currentMedium.name.startsWith('.') + findItem(R.id.menu_add_to_favorites).isVisible = !currentMedium.isFavorite && !config.bottomActions + findItem(R.id.menu_remove_from_favorites).isVisible = currentMedium.isFavorite && !config.bottomActions findItem(R.id.menu_lock_orientation).isVisible = mRotationDegrees == 0 findItem(R.id.menu_lock_orientation).title = getString(if (mIsOrientationLocked) R.string.unlock_orientation else R.string.lock_orientation) findItem(R.id.menu_rotate).setShowAsAction( @@ -293,6 +295,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View }) } + if (config.bottomActions) { + updateFavoriteIcon(currentMedium) + } return true } @@ -316,6 +321,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View R.id.menu_show_on_map -> showOnMap() R.id.menu_rotate_right -> rotateImage(90) R.id.menu_rotate_left -> rotateImage(270) + R.id.menu_add_to_favorites -> toggleFavorite() + R.id.menu_remove_from_favorites -> toggleFavorite() R.id.menu_rotate_one_eighty -> rotateImage(180) R.id.menu_lock_orientation -> toggleLockOrientation() R.id.menu_save_as -> saveImageAs() @@ -746,7 +753,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun initBottomActionButtons() { bottom_favorite.setOnClickListener { - + toggleFavorite() } bottom_edit.setOnClickListener { @@ -762,6 +769,16 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } } + private fun updateFavoriteIcon(medium: Medium) { + val icon = if (medium.isFavorite) R.drawable.ic_star_on else R.drawable.ic_star_off + bottom_favorite.setImageResource(icon) + } + + private fun toggleFavorite() { + getCurrentMedium()!!.isFavorite = !getCurrentMedium()!!.isFavorite + invalidateOptionsMenu() + } + override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) { if (requestCode == REQUEST_EDIT_IMAGE) { if (resultCode == Activity.RESULT_OK && resultData != null) { @@ -972,7 +989,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View mPos = position updateActionbarTitle() mRotationDegrees = 0 - supportInvalidateOptionsMenu() + invalidateOptionsMenu() scheduleSwipe() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt index 5f167a180..60e551038 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -26,7 +26,7 @@ data class Medium( @ColumnInfo(name = "date_taken") var taken: Long, @ColumnInfo(name = "size") val size: Long, @ColumnInfo(name = "type") val type: Int, - @ColumnInfo(name = "is_favorite") val isFavorite: Boolean) : Serializable { + @ColumnInfo(name = "is_favorite") var isFavorite: Boolean) : Serializable { companion object { private const val serialVersionUID = -6553149366975455L diff --git a/app/src/main/res/menu/menu_viewpager.xml b/app/src/main/res/menu/menu_viewpager.xml index 6997ce606..c26c45eb8 100644 --- a/app/src/main/res/menu/menu_viewpager.xml +++ b/app/src/main/res/menu/menu_viewpager.xml @@ -34,6 +34,16 @@ android:title="@string/rotate_one_eighty"/> + +