properly handle bottom action button visibility and functionality

This commit is contained in:
tibbi 2018-06-29 21:07:21 +02:00
parent 3cd0cf4e31
commit 13f873497e
3 changed files with 137 additions and 22 deletions

View file

@ -47,7 +47,7 @@ ext {
} }
dependencies { dependencies {
implementation 'com.simplemobiletools:commons:4.3.9' implementation 'com.simplemobiletools:commons:4.3.11'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
implementation 'com.android.support:multidex:1.0.3' implementation 'com.android.support:multidex:1.0.3'
implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'it.sephiroth.android.exif:library:1.0.1'

View file

@ -71,7 +71,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private var mIsOrientationLocked = false private var mIsOrientationLocked = false
private var mStoredReplaceZoomableImages = false private var mStoredReplaceZoomableImages = false
private var mStoredBottomActions = true
private var mMediaFiles = ArrayList<Medium>() private var mMediaFiles = ArrayList<Medium>()
private var mFavoritePaths = ArrayList<String>() private var mFavoritePaths = ArrayList<String>()
@ -121,10 +120,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
refreshViewPager() refreshViewPager()
} }
if (mStoredBottomActions != config.bottomActions) {
initBottomActions() initBottomActions()
}
supportActionBar?.setBackgroundDrawable(resources.getDrawable(R.drawable.actionbar_gradient_background)) supportActionBar?.setBackgroundDrawable(resources.getDrawable(R.drawable.actionbar_gradient_background))
if (config.maxBrightness) { if (config.maxBrightness) {
@ -287,19 +283,23 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
menuInflater.inflate(R.menu.menu_viewpager, menu) menuInflater.inflate(R.menu.menu_viewpager, menu)
val currentMedium = getCurrentMedium() ?: return true val currentMedium = getCurrentMedium() ?: return true
currentMedium.isFavorite = mFavoritePaths.contains(currentMedium.path) currentMedium.isFavorite = mFavoritePaths.contains(currentMedium.path)
val visibleBottomActions = if (config.bottomActions) config.visibleBottomActions else 0
menu.apply { menu.apply {
findItem(R.id.menu_delete).isVisible = !config.bottomActions findItem(R.id.menu_show_on_map).isVisible = visibleBottomActions and BOTTOM_ACTION_SHOW_ON_MAP == 0
findItem(R.id.menu_share).isVisible = !config.bottomActions findItem(R.id.menu_slideshow).isVisible = visibleBottomActions and BOTTOM_ACTION_SLIDESHOW == 0
findItem(R.id.menu_edit).isVisible = !config.bottomActions findItem(R.id.menu_properties).isVisible = visibleBottomActions and BOTTOM_ACTION_PROPERTIES == 0
findItem(R.id.menu_rotate).isVisible = currentMedium.isImage() findItem(R.id.menu_delete).isVisible = visibleBottomActions and BOTTOM_ACTION_DELETE == 0
findItem(R.id.menu_share).isVisible = visibleBottomActions and BOTTOM_ACTION_SHARE == 0
findItem(R.id.menu_edit).isVisible = visibleBottomActions and BOTTOM_ACTION_EDIT == 0
findItem(R.id.menu_rotate).isVisible = currentMedium.isImage() && visibleBottomActions and BOTTOM_ACTION_ROTATE == 0
findItem(R.id.menu_save_as).isVisible = mRotationDegrees != 0 findItem(R.id.menu_save_as).isVisible = mRotationDegrees != 0
findItem(R.id.menu_hide).isVisible = !currentMedium.name.startsWith('.') findItem(R.id.menu_hide).isVisible = !currentMedium.name.startsWith('.') && visibleBottomActions and BOTTOM_ACTION_TOGGLE_VISIBILITY == 0
findItem(R.id.menu_unhide).isVisible = currentMedium.name.startsWith('.') findItem(R.id.menu_unhide).isVisible = currentMedium.name.startsWith('.') && visibleBottomActions and BOTTOM_ACTION_TOGGLE_VISIBILITY == 0
findItem(R.id.menu_add_to_favorites).isVisible = !currentMedium.isFavorite && !config.bottomActions findItem(R.id.menu_add_to_favorites).isVisible = !currentMedium.isFavorite && visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE == 0
findItem(R.id.menu_remove_from_favorites).isVisible = currentMedium.isFavorite && !config.bottomActions findItem(R.id.menu_remove_from_favorites).isVisible = currentMedium.isFavorite && visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE == 0
findItem(R.id.menu_restore_file).isVisible = currentMedium.path.startsWith(filesDir.toString()) findItem(R.id.menu_restore_file).isVisible = currentMedium.path.startsWith(filesDir.toString())
findItem(R.id.menu_lock_orientation).isVisible = mRotationDegrees == 0 findItem(R.id.menu_lock_orientation).isVisible = mRotationDegrees == 0 && visibleBottomActions and BOTTOM_ACTION_ROTATE == 0
findItem(R.id.menu_lock_orientation).title = getString(if (mIsOrientationLocked) R.string.unlock_orientation else R.string.lock_orientation) 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( findItem(R.id.menu_rotate).setShowAsAction(
if (mRotationDegrees != 0) { if (mRotationDegrees != 0) {
@ -309,8 +309,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}) })
} }
if (config.bottomActions) { if (visibleBottomActions != 0) {
updateFavoriteIcon(currentMedium) updateBottomActionIcons(currentMedium)
} }
return true return true
} }
@ -350,7 +350,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun storeStateVariables() { private fun storeStateVariables() {
config.apply { config.apply {
mStoredReplaceZoomableImages = replaceZoomableImages mStoredReplaceZoomableImages = replaceZoomableImages
mStoredBottomActions = bottomActions
} }
} }
@ -767,34 +766,84 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} }
private fun initBottomActionButtons() { private fun initBottomActionButtons() {
val visibleBottomActions = config.visibleBottomActions
bottom_favorite.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE != 0)
bottom_favorite.setOnClickListener { bottom_favorite.setOnClickListener {
if (bottom_actions.alpha == 1f) { if (bottom_actions.alpha == 1f) {
toggleFavorite() toggleFavorite()
} }
} }
bottom_edit.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_EDIT != 0)
bottom_edit.setOnClickListener { bottom_edit.setOnClickListener {
if (bottom_actions.alpha == 1f) { if (bottom_actions.alpha == 1f) {
openEditor(getCurrentPath()) openEditor(getCurrentPath())
} }
} }
bottom_share.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_SHARE != 0)
bottom_share.setOnClickListener { bottom_share.setOnClickListener {
if (bottom_actions.alpha == 1f) { if (bottom_actions.alpha == 1f) {
shareMediumPath(getCurrentPath()) shareMediumPath(getCurrentPath())
} }
} }
bottom_delete.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_DELETE != 0)
bottom_delete.setOnClickListener { bottom_delete.setOnClickListener {
if (bottom_actions.alpha == 1f) { if (bottom_actions.alpha == 1f) {
checkDeleteConfirmation() checkDeleteConfirmation()
} }
} }
bottom_rotate.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_ROTATE != 0 && getCurrentMedium()?.isImage() == true)
bottom_rotate.setOnClickListener {
if (bottom_actions.alpha == 1f) {
}
} }
private fun updateFavoriteIcon(medium: Medium) { bottom_properties.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_PROPERTIES != 0)
val icon = if (medium.isFavorite) R.drawable.ic_star_on else R.drawable.ic_star_off bottom_properties.setOnClickListener {
bottom_favorite.setImageResource(icon) if (bottom_actions.alpha == 1f) {
showProperties()
}
}
bottom_lock_orientation.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_LOCK_ORIENTATION != 0)
bottom_lock_orientation.setOnClickListener {
if (bottom_actions.alpha == 1f) {
}
}
bottom_slideshow.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_SLIDESHOW != 0)
bottom_slideshow.setOnClickListener {
if (bottom_actions.alpha == 1f) {
initSlideshow()
}
}
bottom_show_on_map.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_SHOW_ON_MAP != 0)
bottom_show_on_map.setOnClickListener {
if (bottom_actions.alpha == 1f) {
showOnMap()
}
}
bottom_toggle_file_visibility.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_TOGGLE_VISIBILITY != 0)
bottom_toggle_file_visibility.setOnClickListener {
if (bottom_actions.alpha == 1f) {
}
}
}
private fun updateBottomActionIcons(medium: Medium) {
val favoriteIcon = if (medium.isFavorite) R.drawable.ic_star_on else R.drawable.ic_star_off
bottom_favorite.setImageResource(favoriteIcon)
val hideIcon = if (medium.name.startsWith('.')) R.drawable.ic_unhide else R.drawable.ic_hide
bottom_toggle_file_visibility.setImageResource(hideIcon)
} }
private fun toggleFavorite() { private fun toggleFavorite() {

View file

@ -49,8 +49,74 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="@dimen/medium_margin" android:padding="@dimen/medium_margin"
android:src="@drawable/ic_delete" android:src="@drawable/ic_delete"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toStartOf="@+id/bottom_rotate"
app:layout_constraintHorizontal_bias="0.5" app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/bottom_share"/> app:layout_constraintStart_toEndOf="@+id/bottom_share"/>
<ImageView
android:id="@+id/bottom_rotate"
style="@style/MyBorderlessBackgroundStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/medium_margin"
android:src="@drawable/ic_rotate_right"
app:layout_constraintEnd_toStartOf="@+id/bottom_properties"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/bottom_delete"/>
<ImageView
android:id="@+id/bottom_properties"
style="@style/MyBorderlessBackgroundStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/medium_margin"
android:src="@drawable/ic_properties"
app:layout_constraintEnd_toStartOf="@+id/bottom_lock_orientation"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/bottom_rotate"/>
<ImageView
android:id="@+id/bottom_lock_orientation"
style="@style/MyBorderlessBackgroundStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/medium_margin"
android:src="@drawable/ic_orientation_auto"
app:layout_constraintEnd_toStartOf="@+id/bottom_slideshow"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/bottom_properties"/>
<ImageView
android:id="@+id/bottom_slideshow"
style="@style/MyBorderlessBackgroundStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/medium_margin"
android:src="@drawable/ic_slideshow"
app:layout_constraintEnd_toStartOf="@+id/bottom_show_on_map"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/bottom_lock_orientation"/>
<ImageView
android:id="@+id/bottom_show_on_map"
style="@style/MyBorderlessBackgroundStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/medium_margin"
android:src="@drawable/ic_place"
app:layout_constraintEnd_toStartOf="@+id/bottom_toggle_file_visibility"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/bottom_slideshow"/>
<ImageView
android:id="@+id/bottom_toggle_file_visibility"
style="@style/MyBorderlessBackgroundStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/medium_margin"
android:src="@drawable/ic_hide"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/bottom_show_on_map"/>
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>