Skip to content

Commit 4620435

Browse files
committed
Refine
1 parent f3bcfc1 commit 4620435

File tree

6 files changed

+156
-44
lines changed

6 files changed

+156
-44
lines changed

app/src/main/kotlin/com/w2sv/autocrop/activities/main/fragments/flowfield/FlowFieldFragment.kt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import androidx.lifecycle.SavedStateHandle
2020
import androidx.lifecycle.lifecycleScope
2121
import androidx.lifecycle.viewModelScope
2222
import com.daimajia.androidanimations.library.Techniques
23+
import com.daimajia.androidanimations.library.YoYo
2324
import com.w2sv.androidutils.BackPressListener
2425
import com.w2sv.androidutils.extensions.getColoredIcon
2526
import com.w2sv.androidutils.extensions.getLong
@@ -30,6 +31,7 @@ import com.w2sv.androidutils.extensions.launchDelayed
3031
import com.w2sv.androidutils.extensions.postValue
3132
import com.w2sv.androidutils.extensions.show
3233
import com.w2sv.androidutils.extensions.showSystemBars
34+
import com.w2sv.androidutils.extensions.toggle
3335
import com.w2sv.androidutils.extensions.uris
3436
import com.w2sv.autocrop.R
3537
import com.w2sv.autocrop.activities.ApplicationFragment
@@ -118,7 +120,11 @@ class FlowFieldFragment :
118120

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

121-
var liveShowingFlowField: LiveData<Boolean> = MutableLiveData(false)
123+
var hideForegroundLive: LiveData<Boolean> = MutableLiveData(false)
124+
val hideForegroundTogglingEnabled: Boolean
125+
get() = foregroundToggleAnimation?.let { !it.isStarted }
126+
?: true
127+
var foregroundToggleAnimation: YoYo.YoYoString? = null
122128

123129
val backPressHandler = BackPressListener(
124130
viewModelScope,
@@ -166,35 +172,34 @@ class FlowFieldFragment :
166172
}
167173

168174
private fun ViewModel.setLiveDataObservers() {
169-
liveShowingFlowField.observe(viewLifecycleOwner) {
175+
hideForegroundLive.observe(viewLifecycleOwner) {
170176
if (it) {
171177
requireActivity().hideSystemBars()
172178
with(binding.foregroundLayout) {
173179
if (lifecycle.currentState == Lifecycle.State.STARTED)
174180
hide()
175181
else
176-
fadeOut()
182+
foregroundToggleAnimation = fadeOut()
177183
}
178184
}
179185
else {
180186
requireActivity().showSystemBars()
181-
binding.foregroundLayout.fadeIn()
187+
foregroundToggleAnimation = binding.foregroundLayout.fadeIn()
182188
}
183189
}
184190
}
185191

186192
private fun showLayoutElements() {
187-
val fadeInButtons: List<View> = listOf(
188-
binding.navigationViewToggleButton,
189-
binding.imageSelectionButton
190-
)
191193
val savedAnyCrops: Boolean = viewModel.ioResults?.let { it.nSavedCrops != 0 }
192194
?: false
193195

194196
if (!viewModel.fadedInButtons) {
195-
fadeInButtons.forEach {
196-
it.fadeIn(resources.getLong(R.integer.duration_flowfield_buttons_fade_in))
197-
}
197+
fadeIn(
198+
binding.navigationViewToggleButton,
199+
binding.imageSelectionButton,
200+
binding.foregroundToggleButton,
201+
duration = resources.getLong(R.integer.duration_flowfield_buttons_fade_in)
202+
)
198203

199204
if (savedAnyCrops)
200205
lifecycleScope.launchDelayed(resources.getLong(R.integer.duration_flowfield_buttons_half_faded_in)) {
@@ -229,14 +234,9 @@ class FlowFieldFragment :
229234
)
230235
)
231236
}
232-
showFlowfieldButton.setOnClickListener {
233-
viewModel.liveShowingFlowField.postValue(true)
234-
}
235-
relativeLayout.setOnClickListener {
236-
with(viewModel.liveShowingFlowField) {
237-
if (value == true)
238-
postValue(false)
239-
}
237+
foregroundToggleButton.setOnClickListener {
238+
if (viewModel.hideForegroundTogglingEnabled)
239+
viewModel.hideForegroundLive.toggle()
240240
}
241241
}
242242

app/src/main/kotlin/com/w2sv/autocrop/activities/main/fragments/flowfield/views/FlowFieldDrawerLayout.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class FlowFieldDrawerLayout(context: Context, attributeSet: AttributeSet) : Draw
2929
val alphaOverlaidButtons = 1 - slideOffset
3030
imageSelectionButton.alpha = alphaOverlaidButtons
3131
shareCropsButton.alpha = alphaOverlaidButtons
32-
showFlowfieldButton.alpha = alphaOverlaidButtons
32+
foregroundToggleButton.alpha = alphaOverlaidButtons
3333
}
3434
}
3535
)

app/src/main/kotlin/com/w2sv/autocrop/ui/ViewAnimations.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,22 @@ import android.view.View
44
import com.daimajia.androidanimations.library.Techniques
55
import com.daimajia.androidanimations.library.YoYo
66
import com.w2sv.androidutils.extensions.getLong
7+
import com.w2sv.androidutils.extensions.hide
78
import com.w2sv.androidutils.extensions.show
89
import com.w2sv.autocrop.R
910

1011
fun View.animate(
1112
technique: Techniques,
12-
duration: Long? = null,
13-
delay: Long = 0L
13+
duration: Long? = null
1414
): YoYo.YoYoString =
15-
animationComposer(technique, duration, delay)
15+
animationComposer(technique, duration)
1616
.playOn(this)
1717

1818
fun View.animationComposer(
1919
technique: Techniques,
20-
duration: Long? = null,
21-
delay: Long = 0L
20+
duration: Long? = null
2221
): YoYo.AnimationComposer =
2322
YoYo.with(technique)
24-
.delay(delay)
2523
.duration(
2624
duration
2725
?: resources.getLong(R.integer.duration_view_animation)
@@ -32,13 +30,13 @@ fun crossFade(fadeOut: View, fadeIn: View, duration: Long? = null) {
3230
fadeIn.fadeIn(duration)
3331
}
3432

35-
fun fadeIn(vararg view: View, duration: Long? = null){
33+
fun fadeIn(vararg view: View, duration: Long? = null) {
3634
view.forEach {
3735
it.fadeIn(duration)
3836
}
3937
}
4038

41-
fun fadeOut(vararg view: View, duration: Long? = null){
39+
fun fadeOut(vararg view: View, duration: Long? = null) {
4240
view.forEach {
4341
it.fadeOut(duration)
4442
}
@@ -48,11 +46,13 @@ fun View.fadeIn(duration: Long? = null): YoYo.YoYoString =
4846
apply {
4947
show()
5048
}
51-
.animate(Techniques.FadeIn, duration)
49+
.animationComposer(Techniques.FadeIn, duration)
50+
.playOn(this)
5251

53-
fun View.fadeOut(duration: Long? = null, delay: Long = 0, onEndVisibility: Int = View.GONE): YoYo.YoYoString =
54-
animationComposer(Techniques.FadeOut, duration, delay)
52+
fun View.fadeOut(duration: Long? = null, delay: Long = 0): YoYo.YoYoString =
53+
animationComposer(Techniques.FadeOut, duration)
54+
.delay(delay)
5555
.onEnd {
56-
visibility = onEndVisibility
56+
hide()
5757
}
5858
.playOn(this)
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:id="@+id/layout"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent">
7+
8+
<com.w2sv.autocrop.activities.main.fragments.flowfield.views.FlowFieldLayout
9+
android:id="@+id/flowfield_layout"
10+
android:layout_width="match_parent"
11+
android:layout_height="match_parent" />
12+
13+
<com.w2sv.autocrop.activities.main.fragments.flowfield.views.FlowFieldDrawerLayout
14+
android:id="@+id/drawer_layout"
15+
android:layout_width="match_parent"
16+
android:layout_height="match_parent">
17+
18+
<RelativeLayout
19+
android:layout_width="match_parent"
20+
android:layout_height="match_parent">
21+
22+
<androidx.appcompat.widget.AppCompatImageButton
23+
android:id="@+id/foreground_toggle_button"
24+
25+
android:layout_width="30dp"
26+
android:layout_height="30dp"
27+
android:layout_alignParentEnd="true"
28+
android:layout_alignParentBottom="true"
29+
android:layout_marginEnd="56dp"
30+
android:layout_marginBottom="26dp"
31+
android:background="@drawable/ic_eye_24"
32+
android:backgroundTint="@color/low_alpha_gray" />
33+
34+
<RelativeLayout
35+
android:id="@+id/foreground_layout"
36+
android:layout_width="match_parent"
37+
android:layout_height="match_parent">
38+
39+
<com.airbnb.lottie.LottieAnimationView
40+
android:id="@+id/navigation_view_toggle_button"
41+
42+
android:layout_width="@dimen/size_lottie_button"
43+
android:layout_height="@dimen/size_lottie_button"
44+
android:layout_marginStart="@dimen/margin_top_left_image_button"
45+
android:layout_marginTop="@dimen/margin_top_left_image_button"
46+
47+
android:contentDescription="@string/main_menu_toggle"
48+
49+
app:lottie_rawRes="@raw/hamburger_to_backarrow" />
50+
51+
<androidx.appcompat.widget.AppCompatButton
52+
android:id="@+id/image_selection_button"
53+
54+
android:layout_width="143dp"
55+
android:layout_height="143dp"
56+
android:layout_centerInParent="true"
57+
58+
android:background="@drawable/shape_imageselection_button"
59+
60+
android:lineSpacingExtra="10dp"
61+
android:text="@string/select_images"
62+
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
63+
android:textColor="@color/image_selection_button_foreground" />
64+
65+
<androidx.coordinatorlayout.widget.CoordinatorLayout
66+
android:layout_width="match_parent"
67+
android:layout_height="wrap_content"
68+
android:layout_alignParentBottom="true">
69+
70+
<com.w2sv.androidutils.ui.SnackbarRepelledLayout
71+
android:id="@+id/snackbar_repelled_layout"
72+
73+
android:layout_width="match_parent"
74+
android:layout_height="match_parent"
75+
android:gravity="center_horizontal">
76+
77+
<androidx.appcompat.widget.AppCompatImageButton
78+
android:id="@+id/share_crops_button"
79+
android:layout_width="36dp"
80+
android:layout_height="36dp"
81+
android:layout_marginBottom="20dp"
82+
android:background="@drawable/ic_share_24"
83+
android:visibility="invisible" />
84+
85+
</com.w2sv.androidutils.ui.SnackbarRepelledLayout>
86+
87+
</androidx.coordinatorlayout.widget.CoordinatorLayout>
88+
89+
</RelativeLayout>
90+
91+
</RelativeLayout>
92+
93+
<com.w2sv.autocrop.activities.main.fragments.flowfield.views.FlowFieldNavigationView
94+
android:id="@+id/navigation_view"
95+
96+
android:layout_width="wrap_content"
97+
android:layout_height="match_parent"
98+
android:layout_alignTop="@+id/navigation_drawer_button_burger"
99+
android:layout_gravity="start"
100+
android:layout_marginTop="80dp"
101+
102+
android:background="@android:color/transparent"
103+
104+
app:headerLayout="@layout/navigation_view_header"
105+
app:itemIconTint="@color/highlight"
106+
app:menu="@menu/flowfield" />
107+
108+
</com.w2sv.autocrop.activities.main.fragments.flowfield.views.FlowFieldDrawerLayout>
109+
110+
</RelativeLayout>

app/src/main/res/layout/fragment_flowfield.xml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,21 @@
1616
android:layout_height="match_parent">
1717

1818
<RelativeLayout
19-
android:id="@+id/relative_layout"
2019
android:layout_width="match_parent"
2120
android:layout_height="match_parent">
2221

22+
<androidx.appcompat.widget.AppCompatImageButton
23+
android:id="@+id/foreground_toggle_button"
24+
25+
android:layout_width="30dp"
26+
android:layout_height="30dp"
27+
android:layout_alignParentEnd="true"
28+
android:layout_alignParentBottom="true"
29+
android:layout_marginEnd="26dp"
30+
android:layout_marginBottom="56dp"
31+
android:background="@drawable/ic_eye_24"
32+
android:backgroundTint="@color/low_alpha_gray" />
33+
2334
<RelativeLayout
2435
android:id="@+id/foreground_layout"
2536
android:layout_width="match_parent"
@@ -51,17 +62,6 @@
5162
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
5263
android:textColor="@color/image_selection_button_foreground" />
5364

54-
<androidx.appcompat.widget.AppCompatImageButton
55-
android:id="@+id/show_flowfield_button"
56-
57-
android:layout_alignParentBottom="true"
58-
android:layout_alignParentEnd="true"
59-
android:layout_marginBottom="56dp"
60-
android:layout_marginEnd="46dp"
61-
android:layout_width="28dp"
62-
android:layout_height="28dp"
63-
android:background="@drawable/ic_eye_24"/>
64-
6565
<androidx.coordinatorlayout.widget.CoordinatorLayout
6666
android:layout_width="match_parent"
6767
android:layout_height="wrap_content"

app/src/main/res/values/colors.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33
<color name="dark_gray">#656565</color>
4+
<color name="low_alpha_gray">#809B9B9B</color>
5+
46
<color name="pseudo_black">#1C1C1E</color>
57
<color name="magenta_bright">#BC275E</color>
68
<color name="magenta_saturated">#911945</color>

0 commit comments

Comments
 (0)