Skip to content

Commit 7c4f5b7

Browse files
committed
Crop pager refinements
1 parent 4ce5c30 commit 7c4f5b7

File tree

9 files changed

+191
-107
lines changed

9 files changed

+191
-107
lines changed

.idea/caches/deviceStreaming.xml

Lines changed: 97 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/kotlin/com/w2sv/autocrop/MainActivity.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {
1010

1111
override fun onCreate(savedInstanceState: Bundle?) {
1212
installSplashScreen()
13-
1413
super.onCreate(savedInstanceState)
1514
}
1615
}

app/src/main/kotlin/com/w2sv/autocrop/ui/screen/pager/CropPagerScreenFragment.kt

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class CropPagerScreenFragment :
5555
CropsProcedureDialogFragment.ResultListener,
5656
RecropDialogFragment.Listener {
5757

58+
private val cropBundleVM by cropNavGraphViewModel<CropBundleViewModel>()
5859
private val viewModel by viewModels<CropPagerScreenViewModel>(
5960
extrasProducer = {
6061
defaultViewModelCreationExtras
@@ -63,7 +64,6 @@ class CropPagerScreenFragment :
6364
}
6465
}
6566
)
66-
private val cropBundleVM by cropNavGraphViewModel<CropBundleViewModel>()
6767

6868
private lateinit var cropPagerWrapper: CropPagerWrapper
6969

@@ -107,22 +107,24 @@ class CropPagerScreenFragment :
107107
}
108108
)
109109

110-
viewModel.setLiveDataObservers()
111-
binding.setOnClickListeners()
112-
}
110+
with(binding) {
111+
// viewPager.setPageTransformer(AccordionTransformer())
113112

114-
private fun CropPagerScreenViewModel.setLiveDataObservers() {
115-
dataSet.livePosition.observe(viewLifecycleOwner) {
116-
binding.onDataSetPositionChanged(it)
117-
}
113+
setOnClickListeners()
114+
with(viewModel) {
115+
dataSet.livePosition.observe(viewLifecycleOwner) {
116+
onDataSetPositionChanged(it)
117+
}
118118

119-
autoScrolling.observe(viewLifecycleOwner) {
120-
binding.onDoAutoScrollChanged(it)
121-
}
119+
autoScrolling.observe(viewLifecycleOwner) {
120+
onDoAutoScrollChanged(it)
121+
}
122122

123-
dataSet.observe(viewLifecycleOwner) {
124-
if (it.containsSingularElement && lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)) {
125-
binding.allCropsButtonsWLabel.animate(Techniques.ZoomOut)
123+
dataSet.observe(viewLifecycleOwner) {
124+
if (it.containsSingularElement && lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)) {
125+
allCropsButtonRow.animate(Techniques.ZoomOut)
126+
}
127+
}
126128
}
127129
}
128130
}
@@ -172,7 +174,7 @@ class CropPagerScreenFragment :
172174
buildList {
173175
add(currentCropLayout)
174176
if (!viewModel.dataSet.containsSingularElement) {
175-
add(allCropsButtonsWLabel)
177+
add(allCropsButtonRow)
176178
}
177179
}
178180
.visualize(
@@ -183,7 +185,6 @@ class CropPagerScreenFragment :
183185
viewModel.showCropResultsToastIfApplicable(requireContext())
184186
}
185187

186-
viewPager.setPageTransformer(CubeOutPageTransformer())
187188
cancelAutoScrollButton.hide()
188189
}
189190
}
@@ -356,6 +357,15 @@ private class CubeOutPageTransformer : ViewPager2.PageTransformer {
356357
}
357358
}
358359

360+
private class AccordionTransformer : ViewPager2.PageTransformer {
361+
override fun transformPage(page: View, position: Float) {
362+
with(page) {
363+
pivotX = if (position < 0) 0f else width.toFloat()
364+
scaleX = if (position < 0) 1f + position else 1f - position
365+
}
366+
}
367+
}
368+
359369
private fun ViewPager2.scrollPeriodically(
360370
coroutineScope: CoroutineScope,
361371
maxScrolls: Int,

app/src/main/kotlin/com/w2sv/autocrop/ui/screen/pager/dialog/cropsaving/CropProcedureDialogFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CropProcedureDialogFragment : AbstractCropProcedureDialogFragment() {
2424
}
2525

2626
private val resultListener
27-
get() = requireParentFragment() as ResultListener
27+
get() = parentFragment as ResultListener
2828

2929
interface ResultListener {
3030
fun onSaveCrop(dataSetPosition: Int)

app/src/main/kotlin/com/w2sv/autocrop/ui/screen/pager/dialog/cropsaving/CropsProcedureDialogFragment.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
package com.w2sv.autocrop.ui.screen.pager.dialog.cropsaving
22

33
import androidx.appcompat.app.AlertDialog
4-
import androidx.fragment.app.activityViewModels
54
import com.w2sv.autocrop.R
65
import com.w2sv.autocrop.ui.screen.CropBundleViewModel
6+
import com.w2sv.autocrop.ui.screen.cropNavGraphViewModel
77

88
class CropsProcedureDialogFragment : AbstractCropProcedureDialogFragment() {
99

10-
private val cropViewModel by activityViewModels<CropBundleViewModel>()
10+
private val cropViewModel by cropNavGraphViewModel<CropBundleViewModel>()
1111

1212
override fun AlertDialog.Builder.build(): AlertDialog.Builder =
1313
apply {
14-
setTitle("Save ${cropViewModel.cropBundleCount} crops?")
14+
setTitle(getString(R.string.crops_procedure_dialog_title, cropViewModel.cropBundleCount))
1515
setIcon(R.drawable.ic_save_24)
16-
setDeleteCorrespondingScreenshotsOption("Delete corresponding screenshots")
16+
setDeleteCorrespondingScreenshotsOption(getString(R.string.delete_corresponding_screenshots))
1717
setPositiveButton(getString(R.string.yes)) { _, _ ->
1818
(parentFragment as ResultListener)
1919
.onSaveAllCrops()
2020
}
21-
setNegativeButton("No, discard all") { _, _ ->
21+
setNegativeButton(getString(R.string.no_discard_all)) { _, _ ->
2222
(parentFragment as ResultListener)
2323
.onDiscardAllCrops()
2424
}
25-
26-
2725
}
2826

2927
interface ResultListener {

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

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,48 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
35
android:layout_width="match_parent"
4-
android:layout_height="match_parent"
5-
android:gravity="center_horizontal"
6-
android:orientation="vertical"
7-
android:weightSum="1">
8-
9-
<Space
10-
android:layout_width="0dp"
11-
android:layout_height="0dp"
12-
android:layout_weight="0.4" />
6+
android:layout_height="match_parent">
137

148
<TextView
159
android:layout_width="wrap_content"
1610
android:layout_height="wrap_content"
1711

1812
android:text="@string/cropping_dot_dot_dot"
1913
android:textColor="@color/highlight"
20-
android:textSize="@dimen/text_size_medium_large" />
21-
22-
<Space
23-
android:layout_width="0dp"
24-
android:layout_height="0dp"
25-
android:layout_weight="0.1" />
14+
android:textSize="@dimen/text_size_medium_large"
15+
app:layout_constraintBottom_toTopOf="@+id/cropping_progress_bar"
16+
app:layout_constraintEnd_toEndOf="parent"
17+
app:layout_constraintStart_toStartOf="parent"
18+
app:layout_constraintTop_toTopOf="parent"
19+
app:layout_constraintVertical_bias="0.75" />
2620

2721
<ProgressBar
2822
android:id="@+id/cropping_progress_bar"
2923
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
30-
3124
android:layout_width="match_parent"
32-
android:layout_height="25dp"
33-
android:layout_marginHorizontal="@dimen/margin_horizontal_large"
34-
35-
android:progress="0"
36-
android:progressDrawable="@drawable/gradient_crop_progress_bar" />
37-
38-
<Space
39-
android:layout_width="0dp"
40-
android:layout_height="0dp"
41-
android:layout_weight="0.1" />
25+
android:layout_height="28dp"
26+
android:layout_marginHorizontal="48dp"
27+
android:progressDrawable="@drawable/gradient_crop_progress_bar"
28+
app:layout_constraintBottom_toBottomOf="parent"
29+
app:layout_constraintEnd_toEndOf="parent"
30+
app:layout_constraintStart_toStartOf="parent"
31+
app:layout_constraintTop_toTopOf="parent"
32+
tools:progress="65" />
4233

4334
<com.w2sv.autocrop.ui.designsystem.FractionTextView
4435
android:id="@+id/progress_tv"
4536
android:layout_width="wrap_content"
4637
android:layout_height="wrap_content"
4738

4839
android:text="@string/fraction"
49-
android:textSize="@dimen/text_size_medium" />
50-
51-
<Space
52-
android:layout_width="0dp"
53-
android:layout_height="0dp"
54-
android:layout_weight="0.4" />
55-
56-
</LinearLayout>
40+
android:textSize="@dimen/text_size_medium"
41+
app:layout_constraintBottom_toBottomOf="parent"
42+
app:layout_constraintEnd_toEndOf="parent"
43+
app:layout_constraintStart_toStartOf="parent"
44+
app:layout_constraintTop_toBottomOf="@+id/cropping_progress_bar"
45+
app:layout_constraintVertical_bias="0.25"
46+
tools:text="7/12" />
47+
48+
</androidx.constraintlayout.widget.ConstraintLayout>

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
android:id="@+id/crop_iv"
44
android:layout_width="match_parent"
55
android:layout_height="match_parent"
6-
76
android:adjustViewBounds="true"
87
android:scaleType="fitCenter" />

0 commit comments

Comments
 (0)