updating the viewpager activity style
This commit is contained in:
parent
aa3a9fdc88
commit
592b8133a6
2 changed files with 138 additions and 100 deletions
|
@ -21,8 +21,11 @@ import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.provider.MediaStore.Images
|
import android.provider.MediaStore.Images
|
||||||
import android.view.*
|
import android.view.MenuItem
|
||||||
|
import android.view.View
|
||||||
|
import android.view.WindowManager
|
||||||
import android.view.animation.DecelerateInterpolator
|
import android.view.animation.DecelerateInterpolator
|
||||||
|
import android.widget.RelativeLayout
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.exifinterface.media.ExifInterface
|
import androidx.exifinterface.media.ExifInterface
|
||||||
import androidx.print.PrintHelper
|
import androidx.print.PrintHelper
|
||||||
|
@ -86,12 +89,17 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
useDynamicTheme = false
|
useDynamicTheme = false
|
||||||
|
showTransparentTop = true
|
||||||
|
showTransparentNavigation = true
|
||||||
|
|
||||||
if (config.isUsingSystemTheme) {
|
if (config.isUsingSystemTheme) {
|
||||||
setTheme(R.style.AppTheme_Material)
|
setTheme(R.style.AppTheme_Material)
|
||||||
}
|
}
|
||||||
|
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_medium)
|
setContentView(R.layout.activity_medium)
|
||||||
|
setupOptionsMenu()
|
||||||
|
refreshMenuItems()
|
||||||
|
|
||||||
window.decorView.setBackgroundColor(getProperBackgroundColor())
|
window.decorView.setBackgroundColor(getProperBackgroundColor())
|
||||||
top_shadow.layoutParams.height = statusBarHeight + actionBarHeight
|
top_shadow.layoutParams.height = statusBarHeight + actionBarHeight
|
||||||
|
@ -108,10 +116,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
|
|
||||||
initFavorites()
|
initFavorites()
|
||||||
|
|
||||||
if (isRPlus()) {
|
|
||||||
window.insetsController?.setSystemBarsAppearance(0, WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
|
@ -138,10 +142,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
setupOrientation()
|
setupOrientation()
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
|
|
||||||
supportActionBar?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
|
|
||||||
val filename = getCurrentMedium()?.name ?: mPath.getFilenameFromPath()
|
val filename = getCurrentMedium()?.name ?: mPath.getFilenameFromPath()
|
||||||
supportActionBar?.title = filename
|
medium_viewer_toolbar?.title = filename
|
||||||
window.statusBarColor = Color.TRANSPARENT
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
|
@ -164,14 +166,14 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
private fun refreshMenuItems() {
|
||||||
menuInflater.inflate(R.menu.menu_viewpager, menu)
|
val currentMedium = getCurrentMedium() ?: return
|
||||||
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
|
val visibleBottomActions = if (config.bottomActions) config.visibleBottomActions else 0
|
||||||
|
|
||||||
|
runOnUiThread {
|
||||||
val rotationDegrees = getCurrentPhotoFragment()?.mCurrentRotationDegrees ?: 0
|
val rotationDegrees = getCurrentPhotoFragment()?.mCurrentRotationDegrees ?: 0
|
||||||
menu.apply {
|
medium_viewer_toolbar.menu.apply {
|
||||||
findItem(R.id.menu_show_on_map).isVisible = visibleBottomActions and BOTTOM_ACTION_SHOW_ON_MAP == 0
|
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_slideshow).isVisible = visibleBottomActions and BOTTOM_ACTION_SLIDESHOW == 0
|
||||||
findItem(R.id.menu_properties).isVisible = visibleBottomActions and BOTTOM_ACTION_PROPERTIES == 0
|
findItem(R.id.menu_properties).isVisible = visibleBottomActions and BOTTOM_ACTION_PROPERTIES == 0
|
||||||
|
@ -214,16 +216,17 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
if (visibleBottomActions != 0) {
|
if (visibleBottomActions != 0) {
|
||||||
updateBottomActionIcons(currentMedium)
|
updateBottomActionIcons(currentMedium)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
updateMenuItemColors(menu, forceWhiteIcons = true)
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
private fun setupOptionsMenu() {
|
||||||
if (getCurrentMedium() == null)
|
(medium_viewer_appbar.layoutParams as RelativeLayout.LayoutParams).topMargin = statusBarHeight
|
||||||
return true
|
medium_viewer_toolbar.setOnMenuItemClickListener { menuItem ->
|
||||||
|
if (getCurrentMedium() == null) {
|
||||||
|
return@setOnMenuItemClickListener true
|
||||||
|
}
|
||||||
|
|
||||||
when (item.itemId) {
|
when (menuItem.itemId) {
|
||||||
R.id.menu_set_as -> setAs(getCurrentPath())
|
R.id.menu_set_as -> setAs(getCurrentPath())
|
||||||
R.id.menu_slideshow -> initSlideshow()
|
R.id.menu_slideshow -> initSlideshow()
|
||||||
R.id.menu_copy_to -> checkMediaManagementAndCopy(true)
|
R.id.menu_copy_to -> checkMediaManagementAndCopy(true)
|
||||||
|
@ -251,9 +254,14 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
R.id.menu_create_shortcut -> createShortcut()
|
R.id.menu_create_shortcut -> createShortcut()
|
||||||
R.id.menu_resize -> resizeImage()
|
R.id.menu_resize -> resizeImage()
|
||||||
R.id.menu_settings -> launchSettings()
|
R.id.menu_settings -> launchSettings()
|
||||||
else -> return super.onOptionsItemSelected(item)
|
else -> return@setOnMenuItemClickListener false
|
||||||
|
}
|
||||||
|
return@setOnMenuItemClickListener true
|
||||||
|
}
|
||||||
|
|
||||||
|
medium_viewer_toolbar.setNavigationOnClickListener {
|
||||||
|
finish()
|
||||||
}
|
}
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
||||||
|
@ -685,7 +693,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
getCurrentMedia()[mPos] = this
|
getCurrentMedia()[mPos] = this
|
||||||
}
|
}
|
||||||
|
|
||||||
invalidateOptionsMenu()
|
refreshMenuItems()
|
||||||
callback?.invoke()
|
callback?.invoke()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -705,13 +713,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
|
|
||||||
private fun rotateBy(degrees: Int) {
|
private fun rotateBy(degrees: Int) {
|
||||||
getCurrentPhotoFragment()?.rotateImageViewBy(degrees)
|
getCurrentPhotoFragment()?.rotateImageViewBy(degrees)
|
||||||
supportInvalidateOptionsMenu()
|
refreshMenuItems()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleOrientation(orientation: Int) {
|
private fun toggleOrientation(orientation: Int) {
|
||||||
requestedOrientation = orientation
|
requestedOrientation = orientation
|
||||||
mIsOrientationLocked = orientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
mIsOrientationLocked = orientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
||||||
invalidateOptionsMenu()
|
refreshMenuItems()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getChangeOrientationIcon(): Int {
|
private fun getChangeOrientationIcon(): Int {
|
||||||
|
@ -741,7 +749,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
saveRotatedImageToFile(currPath, newPath, photoFragment.mCurrentRotationDegrees, true) {
|
saveRotatedImageToFile(currPath, newPath, photoFragment.mCurrentRotationDegrees, true) {
|
||||||
toast(R.string.file_saved)
|
toast(R.string.file_saved)
|
||||||
getCurrentPhotoFragment()?.mCurrentRotationDegrees = 0
|
getCurrentPhotoFragment()?.mCurrentRotationDegrees = 0
|
||||||
invalidateOptionsMenu()
|
refreshMenuItems()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -819,6 +827,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
} else {
|
} else {
|
||||||
bottom_actions.beGone()
|
bottom_actions.beGone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!portrait && navigationBarRight && navigationBarWidth > 0) {
|
||||||
|
medium_viewer_toolbar.setPadding(0, 0, navigationBarWidth, 0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initBottomActionButtons() {
|
private fun initBottomActionButtons() {
|
||||||
|
@ -953,7 +965,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
} else {
|
} else {
|
||||||
mFavoritePaths.remove(medium.path)
|
mFavoritePaths.remove(medium.path)
|
||||||
}
|
}
|
||||||
invalidateOptionsMenu()
|
|
||||||
|
runOnUiThread {
|
||||||
|
refreshMenuItems()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1268,7 +1283,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
updateActionbarTitle()
|
updateActionbarTitle()
|
||||||
updatePagerItems(mMediaFiles.toMutableList())
|
updatePagerItems(mMediaFiles.toMutableList())
|
||||||
|
|
||||||
invalidateOptionsMenu()
|
refreshMenuItems()
|
||||||
checkOrientation()
|
checkOrientation()
|
||||||
initBottomActions()
|
initBottomActions()
|
||||||
}
|
}
|
||||||
|
@ -1400,13 +1415,19 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}.withEndAction {
|
}.withEndAction {
|
||||||
bottom_actions.beVisibleIf(newAlpha == 1f)
|
bottom_actions.beVisibleIf(newAlpha == 1f)
|
||||||
}.start()
|
}.start()
|
||||||
|
|
||||||
|
medium_viewer_appbar.animate().alpha(newAlpha).withStartAction {
|
||||||
|
medium_viewer_appbar.beVisible()
|
||||||
|
}.withEndAction {
|
||||||
|
medium_viewer_appbar.beVisibleIf(newAlpha == 1f)
|
||||||
|
}.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateActionbarTitle() {
|
private fun updateActionbarTitle() {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
if (mPos < getCurrentMedia().size) {
|
if (mPos < getCurrentMedia().size) {
|
||||||
supportActionBar?.title = getCurrentMedia()[mPos].path.getFilenameFromPath()
|
medium_viewer_toolbar.title = getCurrentMedia()[mPos].path.getFilenameFromPath()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1429,7 +1450,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
if (mPos != position) {
|
if (mPos != position) {
|
||||||
mPos = position
|
mPos = position
|
||||||
updateActionbarTitle()
|
updateActionbarTitle()
|
||||||
invalidateOptionsMenu()
|
refreshMenuItems()
|
||||||
scheduleSwipe()
|
scheduleSwipe()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/fragment_holder"
|
android:id="@+id/fragment_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
@ -8,17 +8,34 @@
|
||||||
<com.simplemobiletools.commons.views.MyViewPager
|
<com.simplemobiletools.commons.views.MyViewPager
|
||||||
android:id="@+id/view_pager"
|
android:id="@+id/view_pager"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"/>
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
<include
|
<include
|
||||||
android:id="@+id/bottom_actions"
|
android:id="@+id/bottom_actions"
|
||||||
layout="@layout/bottom_actions"/>
|
layout="@layout/bottom_actions" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/top_shadow"
|
android:id="@+id/top_shadow"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="@dimen/default_status_action_height"
|
android:layout_height="@dimen/default_status_action_height"
|
||||||
android:contentDescription="@null"
|
android:background="@drawable/gradient_background_flipped"
|
||||||
android:background="@drawable/gradient_background_flipped"/>
|
android:contentDescription="@null" />
|
||||||
|
|
||||||
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
|
android:id="@+id/medium_viewer_appbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:background="@android:color/transparent"
|
||||||
|
android:elevation="0dp"
|
||||||
|
app:elevation="0dp">
|
||||||
|
|
||||||
|
<com.google.android.material.appbar.MaterialToolbar
|
||||||
|
android:id="@+id/medium_viewer_toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
app:menu="@menu/menu_viewpager"
|
||||||
|
app:navigationIcon="@drawable/ic_arrow_left_vector" />
|
||||||
|
|
||||||
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
Loading…
Reference in a new issue