properly handle bottom action button visibility and functionality
This commit is contained in:
parent
3cd0cf4e31
commit
13f873497e
3 changed files with 137 additions and 22 deletions
|
@ -47,7 +47,7 @@ ext {
|
|||
}
|
||||
|
||||
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.android.support:multidex:1.0.3'
|
||||
implementation 'it.sephiroth.android.exif:library:1.0.1'
|
||||
|
|
|
@ -71,7 +71,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
private var mIsOrientationLocked = false
|
||||
|
||||
private var mStoredReplaceZoomableImages = false
|
||||
private var mStoredBottomActions = true
|
||||
private var mMediaFiles = ArrayList<Medium>()
|
||||
private var mFavoritePaths = ArrayList<String>()
|
||||
|
||||
|
@ -121,10 +120,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
refreshViewPager()
|
||||
}
|
||||
|
||||
if (mStoredBottomActions != config.bottomActions) {
|
||||
initBottomActions()
|
||||
}
|
||||
|
||||
supportActionBar?.setBackgroundDrawable(resources.getDrawable(R.drawable.actionbar_gradient_background))
|
||||
|
||||
if (config.maxBrightness) {
|
||||
|
@ -287,19 +283,23 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
menuInflater.inflate(R.menu.menu_viewpager, menu)
|
||||
val currentMedium = getCurrentMedium() ?: return true
|
||||
currentMedium.isFavorite = mFavoritePaths.contains(currentMedium.path)
|
||||
val visibleBottomActions = if (config.bottomActions) config.visibleBottomActions else 0
|
||||
|
||||
menu.apply {
|
||||
findItem(R.id.menu_delete).isVisible = !config.bottomActions
|
||||
findItem(R.id.menu_share).isVisible = !config.bottomActions
|
||||
findItem(R.id.menu_edit).isVisible = !config.bottomActions
|
||||
findItem(R.id.menu_rotate).isVisible = currentMedium.isImage()
|
||||
findItem(R.id.menu_show_on_map).isVisible = visibleBottomActions and BOTTOM_ACTION_SHOW_ON_MAP == 0
|
||||
findItem(R.id.menu_slideshow).isVisible = visibleBottomActions and BOTTOM_ACTION_SLIDESHOW == 0
|
||||
findItem(R.id.menu_properties).isVisible = visibleBottomActions and BOTTOM_ACTION_PROPERTIES == 0
|
||||
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_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_hide).isVisible = !currentMedium.name.startsWith('.') && visibleBottomActions and BOTTOM_ACTION_TOGGLE_VISIBILITY == 0
|
||||
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 && visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE == 0
|
||||
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_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_rotate).setShowAsAction(
|
||||
if (mRotationDegrees != 0) {
|
||||
|
@ -309,8 +309,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
})
|
||||
}
|
||||
|
||||
if (config.bottomActions) {
|
||||
updateFavoriteIcon(currentMedium)
|
||||
if (visibleBottomActions != 0) {
|
||||
updateBottomActionIcons(currentMedium)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -350,7 +350,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
private fun storeStateVariables() {
|
||||
config.apply {
|
||||
mStoredReplaceZoomableImages = replaceZoomableImages
|
||||
mStoredBottomActions = bottomActions
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -767,34 +766,84 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
}
|
||||
|
||||
private fun initBottomActionButtons() {
|
||||
val visibleBottomActions = config.visibleBottomActions
|
||||
bottom_favorite.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE != 0)
|
||||
bottom_favorite.setOnClickListener {
|
||||
if (bottom_actions.alpha == 1f) {
|
||||
toggleFavorite()
|
||||
}
|
||||
}
|
||||
|
||||
bottom_edit.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_EDIT != 0)
|
||||
bottom_edit.setOnClickListener {
|
||||
if (bottom_actions.alpha == 1f) {
|
||||
openEditor(getCurrentPath())
|
||||
}
|
||||
}
|
||||
|
||||
bottom_share.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_SHARE != 0)
|
||||
bottom_share.setOnClickListener {
|
||||
if (bottom_actions.alpha == 1f) {
|
||||
shareMediumPath(getCurrentPath())
|
||||
}
|
||||
}
|
||||
|
||||
bottom_delete.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_DELETE != 0)
|
||||
bottom_delete.setOnClickListener {
|
||||
if (bottom_actions.alpha == 1f) {
|
||||
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) {
|
||||
val icon = if (medium.isFavorite) R.drawable.ic_star_on else R.drawable.ic_star_off
|
||||
bottom_favorite.setImageResource(icon)
|
||||
bottom_properties.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_PROPERTIES != 0)
|
||||
bottom_properties.setOnClickListener {
|
||||
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() {
|
||||
|
|
|
@ -49,8 +49,74 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/medium_margin"
|
||||
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_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>
|
||||
|
|
Loading…
Reference in a new issue