@@ -7,8 +7,10 @@ import android.content.Context
77import android.content.Intent
88import android.net.Uri
99import android.os.Bundle
10+ import android.text.SpannableStringBuilder
1011import android.view.View
1112import androidx.activity.result.contract.ActivityResultContracts
13+ import androidx.core.text.color
1214import com.autocrop.activities.IntentExtraIdentifier
1315import com.autocrop.activities.cropping.CroppingActivity
1416import com.autocrop.activities.main.fragments.MainActivityFragment
@@ -36,31 +38,20 @@ class FlowFieldFragment:
3638 private fun setMenuInflationButtonOnClickListener () =
3739 binding.menuInflationButton.setOnClickListener { popupMenu.show() }
3840
39- private val popupMenu: FlowFieldFragmentMenu by lazy {
41+ private val popupMenu by lazy {
4042 FlowFieldFragmentMenu (
4143 mapOf (
42- R .id.main_menu_item_change_save_destination_dir to { pickSaveDestinationDirContract.launch( CropFileSaveDestinationPreferences .treeUri) } ,
44+ R .id.main_menu_item_change_save_destination_dir to ::pickCropSaveDestinationDir ,
4345 R .id.main_menu_item_rate_the_app to ::goToPlayStoreListing,
44- R .id.main_menu_item_about_the_app to { castedActivity.replaceCurrentFragmentWith( AboutFragment (), false ) }
46+ R .id.main_menu_item_about_the_app to ::invokeAboutFragment
4547 ),
4648 requireView().context,
4749 binding.menuInflationButton
4850 )
4951 }
5052
51- private fun goToPlayStoreListing () =
52- try {
53- startActivity(
54- Intent (Intent .ACTION_VIEW ).apply {
55- data = Uri .parse(" https://play.google.com/store/apps/details?id=${requireContext().packageName} " )
56- setPackage(" com.android.vending" )
57- }
58- )
59- } catch (e: ActivityNotFoundException ){
60- requireActivity()
61- .snacky(" Seems like you're not signed into the Play Store, pal \uD83E\uDD14 " )
62- .show()
63- }
53+ private fun pickCropSaveDestinationDir () =
54+ pickSaveDestinationDirContract.launch(CropFileSaveDestinationPreferences .treeUri)
6455
6556 private val pickSaveDestinationDirContract = registerForActivityResult(
6657 object : ActivityResultContracts .OpenDocumentTree (){
@@ -75,14 +66,46 @@ class FlowFieldFragment:
7566 }
7667 ) {
7768 it?.let { treeUri ->
78- requireActivity().applicationContext.contentResolver.takePersistableUriPermission(
79- treeUri,
80- Intent .FLAG_GRANT_READ_URI_PERMISSION or Intent .FLAG_GRANT_WRITE_URI_PERMISSION
81- )
82- CropFileSaveDestinationPreferences .treeUri = treeUri
69+ if (CropFileSaveDestinationPreferences .treeUri != treeUri){
70+ CropFileSaveDestinationPreferences .treeUri = treeUri
71+
72+ with (requireActivity()){
73+ applicationContext.contentResolver.takePersistableUriPermission(
74+ treeUri,
75+ Intent .FLAG_GRANT_READ_URI_PERMISSION or Intent .FLAG_GRANT_WRITE_URI_PERMISSION
76+ )
77+ snacky(
78+ SpannableStringBuilder ()
79+ .append(" Crops will be saved to " )
80+ .color(getColorInt(NotificationColor .SUCCESS , requireContext())){
81+ append(
82+ documentUriPathIdentifier(CropFileSaveDestinationPreferences .documentUri!! )
83+ )
84+ }
85+ )
86+ .show()
87+ }
88+ }
8389 }
8490 }
8591
92+ private fun invokeAboutFragment () =
93+ castedActivity.replaceCurrentFragmentWith(AboutFragment (), false )
94+
95+ private fun goToPlayStoreListing () =
96+ try {
97+ startActivity(
98+ Intent (Intent .ACTION_VIEW ).apply {
99+ data = Uri .parse(" https://play.google.com/store/apps/details?id=${requireContext().packageName} " )
100+ setPackage(" com.android.vending" )
101+ }
102+ )
103+ } catch (e: ActivityNotFoundException ){
104+ requireActivity()
105+ .snacky(" Seems like you're not signed into the Play Store, pal \uD83E\uDD14 " )
106+ .show()
107+ }
108+
86109 // $$$$$$$$$$$$$$$$$$
87110 // Image Selection $
88111 // $$$$$$$$$$$$$$$$$$
0 commit comments