mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 04:57:59 +01:00
handle Toggle favorite icon updating
This commit is contained in:
parent
8270aaa2f2
commit
7336fc263d
3 changed files with 30 additions and 3 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -34,6 +34,16 @@
|
|||
android:title="@string/rotate_one_eighty"/>
|
||||
</menu>
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/menu_add_to_favorites"
|
||||
android:icon="@drawable/ic_star_off"
|
||||
android:title="@string/add_to_favorites"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/menu_remove_from_favorites"
|
||||
android:icon="@drawable/ic_star_on"
|
||||
android:title="@string/remove_from_favorites"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/menu_lock_orientation"
|
||||
android:title="@string/lock_orientation"
|
||||
|
|
Loading…
Reference in a new issue