Skip to content

Commit

Permalink
Refine
Browse files Browse the repository at this point in the history
  • Loading branch information
w2sv committed Jan 9, 2023
1 parent f3bcfc1 commit 4620435
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.viewModelScope
import com.daimajia.androidanimations.library.Techniques
import com.daimajia.androidanimations.library.YoYo
import com.w2sv.androidutils.BackPressListener
import com.w2sv.androidutils.extensions.getColoredIcon
import com.w2sv.androidutils.extensions.getLong
Expand All @@ -30,6 +31,7 @@ import com.w2sv.androidutils.extensions.launchDelayed
import com.w2sv.androidutils.extensions.postValue
import com.w2sv.androidutils.extensions.show
import com.w2sv.androidutils.extensions.showSystemBars
import com.w2sv.androidutils.extensions.toggle
import com.w2sv.androidutils.extensions.uris
import com.w2sv.autocrop.R
import com.w2sv.autocrop.activities.ApplicationFragment
Expand Down Expand Up @@ -118,7 +120,11 @@ class FlowFieldFragment :

val liveCropSaveDirIdentifier: LiveData<String> = MutableLiveData(cropSaveDirPreferences.pathIdentifier)

var liveShowingFlowField: LiveData<Boolean> = MutableLiveData(false)
var hideForegroundLive: LiveData<Boolean> = MutableLiveData(false)
val hideForegroundTogglingEnabled: Boolean
get() = foregroundToggleAnimation?.let { !it.isStarted }
?: true
var foregroundToggleAnimation: YoYo.YoYoString? = null

val backPressHandler = BackPressListener(
viewModelScope,
Expand Down Expand Up @@ -166,35 +172,34 @@ class FlowFieldFragment :
}

private fun ViewModel.setLiveDataObservers() {
liveShowingFlowField.observe(viewLifecycleOwner) {
hideForegroundLive.observe(viewLifecycleOwner) {
if (it) {
requireActivity().hideSystemBars()
with(binding.foregroundLayout) {
if (lifecycle.currentState == Lifecycle.State.STARTED)
hide()
else
fadeOut()
foregroundToggleAnimation = fadeOut()
}
}
else {
requireActivity().showSystemBars()
binding.foregroundLayout.fadeIn()
foregroundToggleAnimation = binding.foregroundLayout.fadeIn()
}
}
}

private fun showLayoutElements() {
val fadeInButtons: List<View> = listOf(
binding.navigationViewToggleButton,
binding.imageSelectionButton
)
val savedAnyCrops: Boolean = viewModel.ioResults?.let { it.nSavedCrops != 0 }
?: false

if (!viewModel.fadedInButtons) {
fadeInButtons.forEach {
it.fadeIn(resources.getLong(R.integer.duration_flowfield_buttons_fade_in))
}
fadeIn(
binding.navigationViewToggleButton,
binding.imageSelectionButton,
binding.foregroundToggleButton,
duration = resources.getLong(R.integer.duration_flowfield_buttons_fade_in)
)

if (savedAnyCrops)
lifecycleScope.launchDelayed(resources.getLong(R.integer.duration_flowfield_buttons_half_faded_in)) {
Expand Down Expand Up @@ -229,14 +234,9 @@ class FlowFieldFragment :
)
)
}
showFlowfieldButton.setOnClickListener {
viewModel.liveShowingFlowField.postValue(true)
}
relativeLayout.setOnClickListener {
with(viewModel.liveShowingFlowField) {
if (value == true)
postValue(false)
}
foregroundToggleButton.setOnClickListener {
if (viewModel.hideForegroundTogglingEnabled)
viewModel.hideForegroundLive.toggle()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class FlowFieldDrawerLayout(context: Context, attributeSet: AttributeSet) : Draw
val alphaOverlaidButtons = 1 - slideOffset
imageSelectionButton.alpha = alphaOverlaidButtons
shareCropsButton.alpha = alphaOverlaidButtons
showFlowfieldButton.alpha = alphaOverlaidButtons
foregroundToggleButton.alpha = alphaOverlaidButtons
}
}
)
Expand Down
24 changes: 12 additions & 12 deletions app/src/main/kotlin/com/w2sv/autocrop/ui/ViewAnimations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@ import android.view.View
import com.daimajia.androidanimations.library.Techniques
import com.daimajia.androidanimations.library.YoYo
import com.w2sv.androidutils.extensions.getLong
import com.w2sv.androidutils.extensions.hide
import com.w2sv.androidutils.extensions.show
import com.w2sv.autocrop.R

fun View.animate(
technique: Techniques,
duration: Long? = null,
delay: Long = 0L
duration: Long? = null
): YoYo.YoYoString =
animationComposer(technique, duration, delay)
animationComposer(technique, duration)
.playOn(this)

fun View.animationComposer(
technique: Techniques,
duration: Long? = null,
delay: Long = 0L
duration: Long? = null
): YoYo.AnimationComposer =
YoYo.with(technique)
.delay(delay)
.duration(
duration
?: resources.getLong(R.integer.duration_view_animation)
Expand All @@ -32,13 +30,13 @@ fun crossFade(fadeOut: View, fadeIn: View, duration: Long? = null) {
fadeIn.fadeIn(duration)
}

fun fadeIn(vararg view: View, duration: Long? = null){
fun fadeIn(vararg view: View, duration: Long? = null) {
view.forEach {
it.fadeIn(duration)
}
}

fun fadeOut(vararg view: View, duration: Long? = null){
fun fadeOut(vararg view: View, duration: Long? = null) {
view.forEach {
it.fadeOut(duration)
}
Expand All @@ -48,11 +46,13 @@ fun View.fadeIn(duration: Long? = null): YoYo.YoYoString =
apply {
show()
}
.animate(Techniques.FadeIn, duration)
.animationComposer(Techniques.FadeIn, duration)
.playOn(this)

fun View.fadeOut(duration: Long? = null, delay: Long = 0, onEndVisibility: Int = View.GONE): YoYo.YoYoString =
animationComposer(Techniques.FadeOut, duration, delay)
fun View.fadeOut(duration: Long? = null, delay: Long = 0): YoYo.YoYoString =
animationComposer(Techniques.FadeOut, duration)
.delay(delay)
.onEnd {
visibility = onEndVisibility
hide()
}
.playOn(this)
110 changes: 110 additions & 0 deletions app/src/main/res/layout-land/fragment_flowfield.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?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/layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.w2sv.autocrop.activities.main.fragments.flowfield.views.FlowFieldLayout
android:id="@+id/flowfield_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<com.w2sv.autocrop.activities.main.fragments.flowfield.views.FlowFieldDrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/foreground_toggle_button"

android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="56dp"
android:layout_marginBottom="26dp"
android:background="@drawable/ic_eye_24"
android:backgroundTint="@color/low_alpha_gray" />

<RelativeLayout
android:id="@+id/foreground_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.airbnb.lottie.LottieAnimationView
android:id="@+id/navigation_view_toggle_button"

android:layout_width="@dimen/size_lottie_button"
android:layout_height="@dimen/size_lottie_button"
android:layout_marginStart="@dimen/margin_top_left_image_button"
android:layout_marginTop="@dimen/margin_top_left_image_button"

android:contentDescription="@string/main_menu_toggle"

app:lottie_rawRes="@raw/hamburger_to_backarrow" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/image_selection_button"

android:layout_width="143dp"
android:layout_height="143dp"
android:layout_centerInParent="true"

android:background="@drawable/shape_imageselection_button"

android:lineSpacingExtra="10dp"
android:text="@string/select_images"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="@color/image_selection_button_foreground" />

<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">

<com.w2sv.androidutils.ui.SnackbarRepelledLayout
android:id="@+id/snackbar_repelled_layout"

android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/share_crops_button"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginBottom="20dp"
android:background="@drawable/ic_share_24"
android:visibility="invisible" />

</com.w2sv.androidutils.ui.SnackbarRepelledLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

</RelativeLayout>

</RelativeLayout>

<com.w2sv.autocrop.activities.main.fragments.flowfield.views.FlowFieldNavigationView
android:id="@+id/navigation_view"

android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignTop="@+id/navigation_drawer_button_burger"
android:layout_gravity="start"
android:layout_marginTop="80dp"

android:background="@android:color/transparent"

app:headerLayout="@layout/navigation_view_header"
app:itemIconTint="@color/highlight"
app:menu="@menu/flowfield" />

</com.w2sv.autocrop.activities.main.fragments.flowfield.views.FlowFieldDrawerLayout>

</RelativeLayout>
24 changes: 12 additions & 12 deletions app/src/main/res/layout/fragment_flowfield.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,21 @@
android:layout_height="match_parent">

<RelativeLayout
android:id="@+id/relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/foreground_toggle_button"

android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="26dp"
android:layout_marginBottom="56dp"
android:background="@drawable/ic_eye_24"
android:backgroundTint="@color/low_alpha_gray" />

<RelativeLayout
android:id="@+id/foreground_layout"
android:layout_width="match_parent"
Expand Down Expand Up @@ -51,17 +62,6 @@
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="@color/image_selection_button_foreground" />

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/show_flowfield_button"

android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="56dp"
android:layout_marginEnd="46dp"
android:layout_width="28dp"
android:layout_height="28dp"
android:background="@drawable/ic_eye_24"/>

<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="dark_gray">#656565</color>
<color name="low_alpha_gray">#809B9B9B</color>

<color name="pseudo_black">#1C1C1E</color>
<color name="magenta_bright">#BC275E</color>
<color name="magenta_saturated">#911945</color>
Expand Down

0 comments on commit 4620435

Please sign in to comment.