updating the viewpager activity style

This commit is contained in:
tibbi 2022-07-27 15:41:24 +02:00
parent aa3a9fdc88
commit 592b8133a6
2 changed files with 138 additions and 100 deletions

View file

@ -21,8 +21,11 @@ import android.os.Build
import android.os.Bundle
import android.os.Handler
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.widget.RelativeLayout
import android.widget.Toast
import androidx.exifinterface.media.ExifInterface
import androidx.print.PrintHelper
@ -86,12 +89,17 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
override fun onCreate(savedInstanceState: Bundle?) {
useDynamicTheme = false
showTransparentTop = true
showTransparentNavigation = true
if (config.isUsingSystemTheme) {
setTheme(R.style.AppTheme_Material)
}
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_medium)
setupOptionsMenu()
refreshMenuItems()
window.decorView.setBackgroundColor(getProperBackgroundColor())
top_shadow.layoutParams.height = statusBarHeight + actionBarHeight
@ -108,10 +116,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}
initFavorites()
if (isRPlus()) {
window.insetsController?.setSystemBarsAppearance(0, WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS)
}
}
override fun onResume() {
@ -138,10 +142,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
setupOrientation()
invalidateOptionsMenu()
supportActionBar?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
val filename = getCurrentMedium()?.name ?: mPath.getFilenameFromPath()
supportActionBar?.title = filename
window.statusBarColor = Color.TRANSPARENT
medium_viewer_toolbar?.title = filename
}
override fun onPause() {
@ -164,14 +166,14 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_viewpager, menu)
val currentMedium = getCurrentMedium() ?: return true
private fun refreshMenuItems() {
val currentMedium = getCurrentMedium() ?: return
currentMedium.isFavorite = mFavoritePaths.contains(currentMedium.path)
val visibleBottomActions = if (config.bottomActions) config.visibleBottomActions else 0
runOnUiThread {
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_slideshow).isVisible = visibleBottomActions and BOTTOM_ACTION_SLIDESHOW == 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) {
updateBottomActionIcons(currentMedium)
}
updateMenuItemColors(menu, forceWhiteIcons = true)
return true
}
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (getCurrentMedium() == null)
return true
private fun setupOptionsMenu() {
(medium_viewer_appbar.layoutParams as RelativeLayout.LayoutParams).topMargin = statusBarHeight
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_slideshow -> initSlideshow()
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_resize -> resizeImage()
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?) {
@ -685,7 +693,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
getCurrentMedia()[mPos] = this
}
invalidateOptionsMenu()
refreshMenuItems()
callback?.invoke()
}
}
@ -705,13 +713,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun rotateBy(degrees: Int) {
getCurrentPhotoFragment()?.rotateImageViewBy(degrees)
supportInvalidateOptionsMenu()
refreshMenuItems()
}
private fun toggleOrientation(orientation: Int) {
requestedOrientation = orientation
mIsOrientationLocked = orientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
invalidateOptionsMenu()
refreshMenuItems()
}
private fun getChangeOrientationIcon(): Int {
@ -741,7 +749,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
saveRotatedImageToFile(currPath, newPath, photoFragment.mCurrentRotationDegrees, true) {
toast(R.string.file_saved)
getCurrentPhotoFragment()?.mCurrentRotationDegrees = 0
invalidateOptionsMenu()
refreshMenuItems()
}
}
}
@ -819,6 +827,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} else {
bottom_actions.beGone()
}
if (!portrait && navigationBarRight && navigationBarWidth > 0) {
medium_viewer_toolbar.setPadding(0, 0, navigationBarWidth, 0)
}
}
private fun initBottomActionButtons() {
@ -953,7 +965,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} else {
mFavoritePaths.remove(medium.path)
}
invalidateOptionsMenu()
runOnUiThread {
refreshMenuItems()
}
}
}
@ -1268,7 +1283,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
updateActionbarTitle()
updatePagerItems(mMediaFiles.toMutableList())
invalidateOptionsMenu()
refreshMenuItems()
checkOrientation()
initBottomActions()
}
@ -1400,13 +1415,19 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}.withEndAction {
bottom_actions.beVisibleIf(newAlpha == 1f)
}.start()
medium_viewer_appbar.animate().alpha(newAlpha).withStartAction {
medium_viewer_appbar.beVisible()
}.withEndAction {
medium_viewer_appbar.beVisibleIf(newAlpha == 1f)
}.start()
}
}
private fun updateActionbarTitle() {
runOnUiThread {
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) {
mPos = position
updateActionbarTitle()
invalidateOptionsMenu()
refreshMenuItems()
scheduleSwipe()
}
}

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fragment_holder"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -8,17 +8,34 @@
<com.simplemobiletools.commons.views.MyViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent" />
<include
android:id="@+id/bottom_actions"
layout="@layout/bottom_actions"/>
layout="@layout/bottom_actions" />
<ImageView
android:id="@+id/top_shadow"
android:layout_width="match_parent"
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>