move bottom actions from fragments to the activity

This commit is contained in:
tibbi 2018-06-17 15:20:41 +02:00
parent 715b783a8a
commit a231a3af69
6 changed files with 98 additions and 31 deletions

View File

@ -53,6 +53,7 @@ dependencies {
implementation 'it.sephiroth.android.exif:library:1.0.1'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.12'
implementation 'com.github.chrisbanes:PhotoView:2.1.3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
kapt "android.arch.persistence.room:compiler:1.1.0"
implementation "android.arch.persistence.room:runtime:1.1.0"

View File

@ -69,6 +69,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private var mIsOrientationLocked = false
private var mStoredReplaceZoomableImages = false
private var mStoredBottomActions = true
private var mMediaFiles = ArrayList<Medium>()
companion object {
@ -92,6 +93,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}
storeStateVariables()
initBottomActions()
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@ -115,6 +117,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
refreshViewPager()
}
if (mStoredBottomActions != config.bottomActions) {
initBottomActions()
}
supportActionBar?.setBackgroundDrawable(resources.getDrawable(R.drawable.actionbar_gradient_background))
if (config.maxBrightness) {
@ -240,10 +246,18 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
view_pager.adapter?.let {
(it as MyPagerAdapter).toggleFullscreen(mIsFullScreen)
checkSystemUI()
if (!bottom_actions.isGone()) {
bottom_actions.animate().alpha(if (mIsFullScreen) 0f else 1f).start()
}
}
}
}
private fun initBottomActions() {
initBottomActionsLayout()
initBottomActionButtons()
}
private fun setupRotation() {
if (mIsOrientationLocked) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
@ -313,6 +327,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun storeStateVariables() {
config.apply {
mStoredReplaceZoomableImages = replaceZoomableImages
mStoredBottomActions = bottomActions
}
}
@ -719,6 +734,33 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
return (floatD + floatM / 60 + floatS / 3600).toFloat()
}
private fun initBottomActionsLayout() {
bottom_actions.layoutParams.height = resources.getDimension(R.dimen.bottom_actions_height).toInt() + navigationBarHeight
if (config.bottomActions) {
bottom_actions.beVisible()
} else {
bottom_actions.beGone()
}
}
private fun initBottomActionButtons() {
bottom_properties.setOnClickListener {
}
bottom_edit.setOnClickListener {
}
bottom_share.setOnClickListener {
}
bottom_delete.setOnClickListener {
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
if (requestCode == REQUEST_EDIT_IMAGE) {
if (resultCode == Activity.RESULT_OK && resultData != null) {

View File

@ -51,7 +51,6 @@ class PhotoFragment : ViewPagerFragment() {
private var storedShowExtendedDetails = false
private var storedHideExtendedDetails = false
private var storedBottomActions = false
private var storedExtendedDetails = 0
lateinit var view: ViewGroup
@ -118,7 +117,6 @@ class PhotoFragment : ViewPagerFragment() {
isFullscreen = activity!!.window.decorView.systemUiVisibility and View.SYSTEM_UI_FLAG_FULLSCREEN == View.SYSTEM_UI_FLAG_FULLSCREEN
loadImage()
initExtendedDetails()
initBottomActions()
wasInit = true
return view
@ -135,10 +133,6 @@ class PhotoFragment : ViewPagerFragment() {
initExtendedDetails()
}
if (wasInit && (context!!.config.bottomActions != storedBottomActions)) {
initBottomActions()
}
val allowPhotoGestures = context!!.config.allowPhotoGestures
val allowInstantChange = context!!.config.allowInstantChange
@ -168,7 +162,6 @@ class PhotoFragment : ViewPagerFragment() {
storedShowExtendedDetails = showExtendedDetails
storedHideExtendedDetails = hideExtendedDetails
storedExtendedDetails = extendedDetails
storedBottomActions = bottomActions
}
}
@ -404,14 +397,6 @@ class PhotoFragment : ViewPagerFragment() {
}
}
private fun initBottomActions() {
if (context!!.config.bottomActions) {
view.bottom_actions.beVisible()
} else {
view.bottom_actions.beGone()
}
}
override fun onDestroyView() {
super.onDestroyView()
if (activity?.isActivityDestroyed() == false) {
@ -424,7 +409,6 @@ class PhotoFragment : ViewPagerFragment() {
super.onConfigurationChanged(newConfig)
loadImage()
initExtendedDetails()
initBottomActions()
}
private fun photoClicked() {
@ -442,10 +426,6 @@ class PhotoFragment : ViewPagerFragment() {
}
}
}
if (storedBottomActions) {
view.bottom_actions.animate().alpha(if (isFullscreen) 0f else 1f).start()
}
}
private fun getExtendedDetailsY(height: Int): Float {

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<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">
@ -10,4 +11,57 @@
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.constraint.ConstraintLayout
android:id="@+id/bottom_actions"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_actions_height"
android:layout_alignParentBottom="true"
android:background="@drawable/gradient_background_lighter"
android:paddingTop="@dimen/medium_margin">
<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_edit"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"/>
<ImageView
android:id="@+id/bottom_edit"
style="@style/MyBorderlessBackgroundStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/medium_margin"
android:src="@drawable/ic_rename"
app:layout_constraintEnd_toStartOf="@+id/bottom_share"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/bottom_properties"/>
<ImageView
android:id="@+id/bottom_share"
style="@style/MyBorderlessBackgroundStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/medium_margin"
android:src="@drawable/ic_share"
app:layout_constraintEnd_toStartOf="@+id/bottom_delete"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/bottom_edit"/>
<ImageView
android:id="@+id/bottom_delete"
style="@style/MyBorderlessBackgroundStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/medium_margin"
android:src="@drawable/ic_delete"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/bottom_share"/>
</android.support.constraint.ConstraintLayout>
</RelativeLayout>

View File

@ -68,14 +68,4 @@
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/>
<LinearLayout
android:id="@+id/bottom_actions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@drawable/gradient_background_lighter"
android:minHeight="@dimen/bottom_actions_height"
android:orientation="horizontal">
</LinearLayout>
</RelativeLayout>

View File

@ -10,5 +10,5 @@
<dimen name="media_side_slider_width">60dp</dimen>
<dimen name="instant_change_bar_width">30dp</dimen>
<dimen name="list_view_folder_thumbnail_size">72dp</dimen>
<dimen name="bottom_actions_height">110dp</dimen>
<dimen name="bottom_actions_height">54dp</dimen>
</resources>