Skip to content

Commit 4ce5c30

Browse files
committed
Remove crop sharing from home screen
1 parent 75bf5fb commit 4ce5c30

File tree

8 files changed

+36
-153
lines changed

8 files changed

+36
-153
lines changed

app/src/main/kotlin/com/w2sv/autocrop/model/CropBundleIOResults.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ data class CropBundleIOResults(
2121
val anyCropsSaved: Boolean
2222
get() = cropUris.isNotEmpty()
2323

24-
fun getNotificationText(resources: Resources): CharSequence =
24+
fun notificationMessage(resources: Resources): CharSequence =
2525
if (nSavedCrops == 0)
2626
"Discarded all crops"
2727
else

app/src/main/kotlin/com/w2sv/autocrop/ui/screen/home/HomeScreenFragment.kt

Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,17 @@ import androidx.fragment.app.Fragment
1717
import androidx.fragment.app.viewModels
1818
import androidx.lifecycle.lifecycleScope
1919
import androidx.lifecycle.viewModelScope
20-
import com.daimajia.androidanimations.library.Techniques
21-
import com.w2sv.androidutils.view.show
2220
import com.w2sv.androidutils.widget.showToast
2321
import com.w2sv.autocrop.AppFragment
2422
import com.w2sv.autocrop.R
2523
import com.w2sv.autocrop.databinding.HomeScreenBinding
26-
import com.w2sv.autocrop.ui.util.animate
2724
import com.w2sv.autocrop.ui.util.fadeIn
2825
import com.w2sv.autocrop.ui.util.fadeInAnimationComposer
2926
import com.w2sv.autocrop.ui.util.fadeOut
3027
import com.w2sv.autocrop.ui.util.onHalfwayFinished
3128
import com.w2sv.autocrop.ui.util.resolution
3229
import com.w2sv.autocrop.util.getMediaUri
3330
import com.w2sv.common.AppPermissionHandler
34-
import com.w2sv.cropbundle.io.IMAGE_MIME_TYPE_MEDIA_STORE_IDENTIFIER
3531
import com.w2sv.domain.repository.PermissionRepository
3632
import com.w2sv.flowfield.PerlinNoiseFlowFieldSketch
3733
import dagger.hilt.android.AndroidEntryPoint
@@ -67,14 +63,23 @@ class HomeScreenFragment :
6763

6864
drawerLayout.onDrawerSlide(viewModel::setDrawerSlideOffset)
6965

70-
showLayoutElements()
71-
7266
navigationViewToggleButton.setOnClickListener { drawerLayout.toggleDrawer() }
7367
imageSelectionButton.setOnClickListener { launchImageSelection() }
74-
shareCropsButton.setOnClickListener { shareCrops() }
7568
foregroundElementsToggleButton.setOnClickListener { viewModel.toggleFullFlowFieldDisplay() }
7669

7770
with(viewModel) {
71+
if (!fadedInForegroundOnEntry) {
72+
foregroundLayout
73+
.fadeInAnimationComposer(duration = 3500L)
74+
.onHalfwayFinished(lifecycleScope) {
75+
viewModel.fadedInForegroundOnEntry = true
76+
viewModel.cropBundleIoResults?.notificationMessage(resources)?.let {
77+
requireContext().showToast(it)
78+
}
79+
}
80+
.play()
81+
}
82+
7883
fullFlowFieldDisplay.observe(viewLifecycleOwner) { hideForeground ->
7984
if (hideForeground) {
8085
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED)
@@ -94,47 +99,6 @@ class HomeScreenFragment :
9499
}
95100
}
96101

97-
private fun HomeScreenBinding.showLayoutElements() {
98-
val anyCropsSaved = viewModel.cropBundleIoResults?.anyCropsSaved == true
99-
100-
when (viewModel.fadedInForegroundOnEntry) {
101-
true -> if (anyCropsSaved) {
102-
shareCropsButton.show()
103-
}
104-
105-
false -> {
106-
foregroundLayout
107-
.fadeInAnimationComposer(duration = 3500L)
108-
.onHalfwayFinished(lifecycleScope) {
109-
viewModel.fadedInForegroundOnEntry = true
110-
viewModel.showIOResultsNotificationIfApplicable(requireContext())
111-
112-
if (anyCropsSaved) {
113-
with(shareCropsButton) {
114-
show()
115-
animate(Techniques.RotateInUpLeft)
116-
}
117-
}
118-
}
119-
.play()
120-
}
121-
}
122-
}
123-
124-
private fun shareCrops() {
125-
startActivity(
126-
Intent.createChooser(
127-
Intent(Intent.ACTION_SEND_MULTIPLE)
128-
.putExtra(
129-
Intent.EXTRA_STREAM,
130-
viewModel.cropBundleIoResults!!.cropUris
131-
)
132-
.setType(IMAGE_MIME_TYPE_MEDIA_STORE_IDENTIFIER),
133-
null
134-
)
135-
)
136-
}
137-
138102
/**
139103
* ActivityCallContractHandlers
140104
*/
@@ -255,7 +219,6 @@ private fun HomeScreenBinding.affectDrawerAssociatedViewsOnSlide(slideOffset: Fl
255219

256220
val associatedButtonAlpha = 1 - slideOffset
257221
imageSelectionButton.alpha = associatedButtonAlpha
258-
shareCropsButton.alpha = associatedButtonAlpha
259222
foregroundElementsToggleButton.alpha = associatedButtonAlpha
260223
}
261224

app/src/main/kotlin/com/w2sv/autocrop/ui/screen/home/HomeScreenViewModel.kt

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.w2sv.autocrop.ui.screen.home
33
import android.content.ContentResolver
44
import android.content.Context
55
import android.content.Intent
6-
import android.content.res.Resources
76
import android.net.Uri
87
import androidx.lifecycle.LiveData
98
import androidx.lifecycle.MutableLiveData
@@ -26,26 +25,13 @@ class HomeScreenViewModel @Inject constructor(
2625
savedStateHandle: SavedStateHandle,
2726
private val preferencesRepository: PreferencesRepository,
2827
// cancelledSSLFromNotification: ScreenshotListener.CancelledFromNotification,
29-
@ApplicationContext context: Context,
30-
private val resources: Resources
28+
@ApplicationContext context: Context
3129
) : androidx.lifecycle.ViewModel() {
3230

3331
val cropBundleIoResults: CropBundleIOResults? = savedStateHandle[CropBundleIOResults.EXTRA]
3432

3533
var fadedInForegroundOnEntry = false
3634

37-
/**
38-
* IO Results Notification
39-
*/
40-
41-
fun showIOResultsNotificationIfApplicable(
42-
context: Context
43-
) {
44-
cropBundleIoResults?.let {
45-
context.showToast(it.getNotificationText(resources))
46-
}
47-
}
48-
4935
val fullFlowFieldDisplay: LiveData<Boolean> get() = _fullFlowFieldDisplay
5036
private val _fullFlowFieldDisplay = MutableLiveData(false)
5137

@@ -64,6 +50,17 @@ class HomeScreenViewModel @Inject constructor(
6450
.mapState { cropSaveDirPathIdentifier(it, context) }
6551
.asLiveData()
6652

53+
val cropSaveDirTreeUri = preferencesRepository.cropSaveDirTreeUri
54+
55+
fun setCropSaveDirTreeUri(treeUri: Uri, contentResolver: ContentResolver) {
56+
contentResolver
57+
.takePersistableUriPermission(
58+
treeUri,
59+
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
60+
)
61+
viewModelScope.launch { preferencesRepository.saveCropSaveDirTreeUri(treeUri) }
62+
}
63+
6764
// val screenshotListenerRunning: LiveData<Boolean> get() = _screenshotListenerRunning
6865
// private val _screenshotListenerRunning = MutableLiveData(context.isServiceRunning<ScreenshotListener>())
6966
//
@@ -76,15 +73,4 @@ class HomeScreenViewModel @Inject constructor(
7673
// setScreenshotListenerRunning(false)
7774
// }
7875
// }
79-
80-
fun setCropSaveDirTreeUri(treeUri: Uri, contentResolver: ContentResolver) {
81-
contentResolver
82-
.takePersistableUriPermission(
83-
treeUri,
84-
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
85-
)
86-
viewModelScope.launch { preferencesRepository.saveCropSaveDirTreeUri(treeUri) }
87-
}
88-
89-
val cropSaveDirTreeUri = preferencesRepository.cropSaveDirTreeUri
9076
}

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

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.w2sv.autocrop.ui.screen.pager
22

33
import android.os.Bundle
44
import android.view.View
5-
import android.widget.PopupMenu
65
import androidx.fragment.app.viewModels
76
import androidx.lifecycle.Lifecycle
87
import androidx.lifecycle.coroutineScope
@@ -25,14 +24,11 @@ import com.w2sv.autocrop.ui.screen.pager.dialog.cropsaving.CropsProcedureDialogF
2524
import com.w2sv.autocrop.ui.screen.pager.dialog.recrop.RecropDialogFragment
2625
import com.w2sv.autocrop.ui.screen.pager.model.CropProcedure
2726
import com.w2sv.autocrop.ui.screen.pager.view.CropPagerWrapper
28-
import com.w2sv.autocrop.ui.util.nonNullValue
29-
import com.w2sv.autocrop.ui.util.KEEP_MENU_ITEM_OPEN_ON_CLICK
3027
import com.w2sv.autocrop.ui.util.VisualizationMethod
3128
import com.w2sv.autocrop.ui.util.animate
3229
import com.w2sv.autocrop.ui.util.currentViewHolder
33-
import com.w2sv.autocrop.ui.util.makeOnClickPersistent
30+
import com.w2sv.autocrop.ui.util.nonNullValue
3431
import com.w2sv.autocrop.ui.util.notifyCurrentItemChanged
35-
import com.w2sv.autocrop.ui.util.toggleCheck
3632
import com.w2sv.autocrop.ui.util.visualize
3733
import com.w2sv.autocrop.util.containsSingularElement
3834
import com.w2sv.autocrop.util.launchAfterShortDelay
@@ -175,7 +171,6 @@ class CropPagerScreenFragment :
175171

176172
buildList {
177173
add(currentCropLayout)
178-
add(popupMenuButton)
179174
if (!viewModel.dataSet.containsSingularElement) {
180175
add(allCropsButtonsWLabel)
181176
}
@@ -228,37 +223,6 @@ class CropPagerScreenFragment :
228223
)
229224
)
230225
}
231-
popupMenuButton.setOnClickListener {
232-
with(PopupMenu(requireContext(), it)) {
233-
menuInflater.inflate(
234-
R.menu.crop_pager,
235-
menu
236-
)
237-
menu
238-
.apply {
239-
findItem(R.id.crop_pager_item_auto_scroll)
240-
.apply {
241-
isCheckable = true
242-
isChecked = viewModel.doAutoScroll.value
243-
makeOnClickPersistent(requireContext())
244-
}
245-
setOnMenuItemClickListener { item ->
246-
when (item.itemId) {
247-
R.id.crop_pager_item_auto_scroll -> {
248-
item.toggleCheck { newValue ->
249-
viewModel.saveDoAutoScroll(newValue)
250-
}
251-
252-
KEEP_MENU_ITEM_OPEN_ON_CLICK
253-
}
254-
255-
else -> true
256-
}
257-
}
258-
}
259-
show()
260-
}
261-
}
262226
}
263227

264228
private fun showCropProcedureDialog() {

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

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
45
android:layout_width="match_parent"
56
android:layout_height="match_parent"
67
android:orientation="vertical"
@@ -19,7 +20,8 @@
1920
android:layout_height="wrap_content"
2021
android:background="@drawable/shape_rounded_rectangle_w_button_background"
2122
android:paddingVertical="@dimen/margin_button_row"
22-
android:visibility="invisible">
23+
android:visibility="invisible"
24+
tools:visibility="visible">
2325

2426
<androidx.appcompat.widget.AppCompatImageButton
2527
android:id="@+id/discard_all_button"
@@ -76,21 +78,8 @@
7678

7779
android:text="@string/fraction"
7880
android:textColor="@color/crop_pager_text"
79-
android:textSize="@dimen/text_size_medium" />
80-
81-
<Space
82-
android:layout_width="@dimen/margin_large"
83-
android:layout_height="0dp" />
84-
85-
<androidx.appcompat.widget.AppCompatImageButton
86-
android:id="@+id/popup_menu_button"
87-
android:layout_width="26dp"
88-
android:layout_height="26dp"
89-
android:layout_gravity="center_vertical"
90-
android:background="@drawable/ic_dot_menu_24"
91-
android:backgroundTint="@color/crop_pager_text"
92-
android:contentDescription="@string/open_popup_menu"
93-
android:visibility="invisible" />
81+
android:textSize="@dimen/text_size_medium"
82+
tools:text="9/12" />
9483

9584
</LinearLayout>
9685

@@ -147,7 +136,8 @@
147136
android:layout_width="match_parent"
148137
android:layout_height="match_parent"
149138
android:gravity="center_vertical"
150-
android:visibility="invisible">
139+
android:visibility="invisible"
140+
tools:visibility="visible">
151141

152142
<androidx.appcompat.widget.AppCompatTextView
153143
android:id="@+id/discarding_statistics_tv"
@@ -156,7 +146,8 @@
156146

157147
android:text="@string/discarding_statistics"
158148
android:textColor="@color/crop_pager_text"
159-
android:textSize="@dimen/text_size_small" />
149+
android:textSize="@dimen/text_size_small"
150+
tools:text="Removed 11%=8kb"/>
160151

161152
<Space
162153
android:layout_width="0dp"

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,6 @@
6666
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
6767
android:textColor="@color/image_selection_button" />
6868

69-
<androidx.appcompat.widget.AppCompatImageButton
70-
android:id="@+id/share_crops_button"
71-
android:layout_width="@dimen/size_image_button"
72-
android:layout_height="@dimen/size_image_button"
73-
android:layout_alignParentBottom="true"
74-
android:layout_centerHorizontal="true"
75-
android:layout_marginBottom="70dp"
76-
android:background="@drawable/ic_share_24"
77-
android:visibility="invisible"
78-
tools:visibility="visible" />
79-
8069
</RelativeLayout>
8170

8271
</LinearLayout>
@@ -93,7 +82,7 @@
9382
android:theme="@style/NavigationView"
9483
app:headerLayout="@layout/navigation_view_header"
9584
app:itemIconTint="@color/highlight"
96-
app:menu="@menu/flowfield" />
85+
app:menu="@menu/home_screen_navigation" />
9786

9887
</androidx.drawerlayout.widget.DrawerLayout>
9988

app/src/main/res/menu/crop_pager.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)