Skip to content

Commit

Permalink
approximate fix for #215 #163 and #126
Browse files Browse the repository at this point in the history
  • Loading branch information
T8RIN committed May 18, 2023
1 parent d8b1832 commit 61de597
Show file tree
Hide file tree
Showing 17 changed files with 359 additions and 64 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />

<application
android:name=".app.ImageApplication"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,18 @@ import ru.tech.imageresizershrinker.utils.BitmapUtils.shareBitmaps
import ru.tech.imageresizershrinker.utils.BitmapUtils.with
import ru.tech.imageresizershrinker.utils.ContextUtils.isExternalStorageWritable
import ru.tech.imageresizershrinker.utils.ContextUtils.requestStoragePermission
import ru.tech.imageresizershrinker.utils.ImagePickerMode
import ru.tech.imageresizershrinker.utils.LocalWindowSizeClass
import ru.tech.imageresizershrinker.utils.Picker
import ru.tech.imageresizershrinker.utils.SavingFolder
import ru.tech.imageresizershrinker.utils.localImagePickerMode
import ru.tech.imageresizershrinker.utils.modifier.alertDialog
import ru.tech.imageresizershrinker.utils.modifier.block
import ru.tech.imageresizershrinker.utils.modifier.drawHorizontalStroke
import ru.tech.imageresizershrinker.utils.modifier.fabBorder
import ru.tech.imageresizershrinker.utils.modifier.navBarsLandscapePadding
import ru.tech.imageresizershrinker.utils.modifier.scaleOnTap
import ru.tech.imageresizershrinker.utils.rememberImagePicker
import ru.tech.imageresizershrinker.widget.LocalToastHost
import ru.tech.imageresizershrinker.widget.Marquee
import ru.tech.imageresizershrinker.widget.Picture
Expand Down Expand Up @@ -200,8 +204,8 @@ fun BatchResizeScreen(
}

val pickImageLauncher =
rememberLauncherForActivityResult(
contract = ActivityResultContracts.PickMultipleVisualMedia()
rememberImagePicker(
mode = localImagePickerMode(Picker.Multiple)
) { list ->
list.takeIf { it.isNotEmpty() }?.let {
viewModel.updateUris(list)
Expand All @@ -226,9 +230,7 @@ fun BatchResizeScreen(
}

val pickImage = {
pickImageLauncher.launch(
PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)
)
pickImageLauncher.pickImage()
}

var showSaveLoading by rememberSaveable { mutableStateOf(false) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import android.content.res.Configuration
import android.net.Uri
import androidx.activity.ComponentActivity
import androidx.activity.compose.BackHandler
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.PickVisualMediaRequest
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.expandIn
Expand Down Expand Up @@ -143,13 +140,16 @@ import ru.tech.imageresizershrinker.utils.BitmapUtils.shareBitmaps
import ru.tech.imageresizershrinker.utils.ContextUtils.failedToSaveImages
import ru.tech.imageresizershrinker.utils.ContextUtils.isExternalStorageWritable
import ru.tech.imageresizershrinker.utils.LocalWindowSizeClass
import ru.tech.imageresizershrinker.utils.Picker
import ru.tech.imageresizershrinker.utils.SavingFolder
import ru.tech.imageresizershrinker.utils.localImagePickerMode
import ru.tech.imageresizershrinker.utils.modifier.alertDialog
import ru.tech.imageresizershrinker.utils.modifier.block
import ru.tech.imageresizershrinker.utils.modifier.drawHorizontalStroke
import ru.tech.imageresizershrinker.utils.modifier.fabBorder
import ru.tech.imageresizershrinker.utils.modifier.navBarsLandscapePadding
import ru.tech.imageresizershrinker.utils.modifier.scaleOnTap
import ru.tech.imageresizershrinker.utils.rememberImagePicker
import ru.tech.imageresizershrinker.widget.LocalToastHost
import ru.tech.imageresizershrinker.widget.Marquee
import ru.tech.imageresizershrinker.widget.Picture
Expand Down Expand Up @@ -205,8 +205,8 @@ fun BytesResizeScreen(
}

val pickImageLauncher =
rememberLauncherForActivityResult(
contract = ActivityResultContracts.PickMultipleVisualMedia()
rememberImagePicker(
mode = localImagePickerMode(Picker.Multiple)
) { list ->
list.takeIf { it.isNotEmpty() }?.let { uris ->
viewModel.updateUris(list)
Expand Down Expand Up @@ -234,9 +234,7 @@ fun BytesResizeScreen(
}

val pickImage = {
pickImageLauncher.launch(
PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)
)
pickImageLauncher.pickImage()
}

var showSaveLoading by rememberSaveable { mutableStateOf(false) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,14 @@ import ru.tech.imageresizershrinker.theme.blend
import ru.tech.imageresizershrinker.theme.outlineVariant
import ru.tech.imageresizershrinker.utils.BitmapUtils.getBitmapByUri
import ru.tech.imageresizershrinker.utils.LocalWindowSizeClass
import ru.tech.imageresizershrinker.utils.Picker
import ru.tech.imageresizershrinker.utils.localImagePickerMode
import ru.tech.imageresizershrinker.utils.modifier.block
import ru.tech.imageresizershrinker.utils.modifier.drawHorizontalStroke
import ru.tech.imageresizershrinker.utils.modifier.fabBorder
import ru.tech.imageresizershrinker.utils.modifier.navBarsPaddingOnlyIfTheyAtTheBottom
import ru.tech.imageresizershrinker.utils.modifier.scaleOnTap
import ru.tech.imageresizershrinker.utils.rememberImagePicker
import ru.tech.imageresizershrinker.widget.LocalToastHost
import ru.tech.imageresizershrinker.widget.Marquee

Expand Down Expand Up @@ -141,8 +144,8 @@ fun CompareScreen(
}

val pickImageLauncher =
rememberLauncherForActivityResult(
contract = ActivityResultContracts.PickMultipleVisualMedia(2)
rememberImagePicker(
mode = localImagePickerMode(Picker.Multiple)
) { uris ->
uris.takeIf { it.isNotEmpty() }?.let {
if (uris.size != 2) {
Expand Down Expand Up @@ -172,9 +175,7 @@ fun CompareScreen(
}

val pickImage = {
pickImageLauncher.launch(
PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)
)
pickImageLauncher.pickImage()
}

val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,15 @@ import ru.tech.imageresizershrinker.utils.BitmapUtils.shareBitmap
import ru.tech.imageresizershrinker.utils.ContextUtils.isExternalStorageWritable
import ru.tech.imageresizershrinker.utils.ContextUtils.requestStoragePermission
import ru.tech.imageresizershrinker.utils.LocalWindowSizeClass
import ru.tech.imageresizershrinker.utils.Picker
import ru.tech.imageresizershrinker.utils.SavingFolder
import ru.tech.imageresizershrinker.utils.localImagePickerMode
import ru.tech.imageresizershrinker.utils.modifier.alertDialog
import ru.tech.imageresizershrinker.utils.modifier.drawHorizontalStroke
import ru.tech.imageresizershrinker.utils.modifier.fabBorder
import ru.tech.imageresizershrinker.utils.modifier.navBarsPaddingOnlyIfTheyAtTheEnd
import ru.tech.imageresizershrinker.utils.modifier.scaleOnTap
import ru.tech.imageresizershrinker.utils.rememberImagePicker
import ru.tech.imageresizershrinker.widget.LocalToastHost
import ru.tech.imageresizershrinker.widget.Marquee

Expand Down Expand Up @@ -172,10 +175,10 @@ fun CropScreen(
}

val pickImageLauncher =
rememberLauncherForActivityResult(
contract = ActivityResultContracts.PickVisualMedia()
) { uri ->
uri?.let {
rememberImagePicker(
mode = localImagePickerMode(Picker.Single)
) { uris ->
uris.takeIf{it.isNotEmpty()}?.firstOrNull()?.let {
context.decodeBitmapFromUri(
uri = it,
onGetMimeType = {},
Expand All @@ -201,9 +204,7 @@ fun CropScreen(
}

val pickImage = {
pickImageLauncher.launch(
PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)
)
pickImageLauncher.pickImage()
}

var showSaveLoading by rememberSaveable { mutableStateOf(false) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,16 @@ import ru.tech.imageresizershrinker.utils.BitmapUtils.shareBitmaps
import ru.tech.imageresizershrinker.utils.ContextUtils.failedToSaveImages
import ru.tech.imageresizershrinker.utils.ContextUtils.isExternalStorageWritable
import ru.tech.imageresizershrinker.utils.LocalWindowSizeClass
import ru.tech.imageresizershrinker.utils.Picker
import ru.tech.imageresizershrinker.utils.SavingFolder
import ru.tech.imageresizershrinker.utils.localImagePickerMode
import ru.tech.imageresizershrinker.utils.modifier.alertDialog
import ru.tech.imageresizershrinker.utils.modifier.block
import ru.tech.imageresizershrinker.utils.modifier.drawHorizontalStroke
import ru.tech.imageresizershrinker.utils.modifier.fabBorder
import ru.tech.imageresizershrinker.utils.modifier.navBarsLandscapePadding
import ru.tech.imageresizershrinker.utils.modifier.scaleOnTap
import ru.tech.imageresizershrinker.utils.rememberImagePicker
import ru.tech.imageresizershrinker.widget.LocalToastHost
import ru.tech.imageresizershrinker.widget.Marquee
import ru.tech.imageresizershrinker.widget.Picture
Expand Down Expand Up @@ -181,8 +184,8 @@ fun DeleteExifScreen(
}

val pickImageLauncher =
rememberLauncherForActivityResult(
contract = ActivityResultContracts.PickMultipleVisualMedia()
rememberImagePicker(
mode = localImagePickerMode(Picker.Multiple)
) { list ->
list.takeIf { it.isNotEmpty() }?.let { uris ->
viewModel.updateUris(list)
Expand All @@ -207,9 +210,7 @@ fun DeleteExifScreen(
}

val pickImage = {
pickImageLauncher.launch(
PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)
)
pickImageLauncher.pickImage()
}

var showSaveLoading by rememberSaveable { mutableStateOf(false) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,14 @@ import ru.tech.imageresizershrinker.theme.PaletteSwatch
import ru.tech.imageresizershrinker.utils.BitmapUtils.decodeBitmapFromUri
import ru.tech.imageresizershrinker.utils.LocalNavController
import ru.tech.imageresizershrinker.utils.LocalWindowSizeClass
import ru.tech.imageresizershrinker.utils.Picker
import ru.tech.imageresizershrinker.utils.localImagePickerMode
import ru.tech.imageresizershrinker.utils.modifier.block
import ru.tech.imageresizershrinker.utils.modifier.drawHorizontalStroke
import ru.tech.imageresizershrinker.utils.modifier.fabBorder
import ru.tech.imageresizershrinker.utils.modifier.navBarsPaddingOnlyIfTheyAtTheBottom
import ru.tech.imageresizershrinker.utils.modifier.scaleOnTap
import ru.tech.imageresizershrinker.utils.rememberImagePicker
import ru.tech.imageresizershrinker.widget.LocalToastHost
import ru.tech.imageresizershrinker.widget.Marquee

Expand Down Expand Up @@ -142,10 +145,10 @@ fun GeneratePaletteScreen(
}

val pickImageLauncher =
rememberLauncherForActivityResult(
contract = ActivityResultContracts.PickVisualMedia()
) { uri ->
uri?.let {
rememberImagePicker(
mode = localImagePickerMode(Picker.Single)
) { uris ->
uris.takeIf{it.isNotEmpty()}?.firstOrNull()?.let {
viewModel.setUri(it)
context.decodeBitmapFromUri(
uri = it,
Expand All @@ -168,9 +171,7 @@ fun GeneratePaletteScreen(
}

val pickImage = {
pickImageLauncher.launch(
PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)
)
pickImageLauncher.pickImage()
}
val scrollState = rememberScrollState()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,12 @@ import ru.tech.imageresizershrinker.theme.EmojiItem
import ru.tech.imageresizershrinker.theme.outlineVariant
import ru.tech.imageresizershrinker.utils.BitmapUtils.decodeSampledBitmapFromUri
import ru.tech.imageresizershrinker.utils.LocalNavController
import ru.tech.imageresizershrinker.utils.Picker
import ru.tech.imageresizershrinker.utils.localImagePickerMode
import ru.tech.imageresizershrinker.utils.modifier.drawHorizontalStroke
import ru.tech.imageresizershrinker.utils.modifier.fabBorder
import ru.tech.imageresizershrinker.utils.modifier.scaleOnTap
import ru.tech.imageresizershrinker.utils.rememberImagePicker
import ru.tech.imageresizershrinker.widget.Marquee
import ru.tech.imageresizershrinker.widget.Picture

Expand Down Expand Up @@ -145,18 +148,16 @@ fun ImagePreviewScreen(
}

val pickImageLauncher =
rememberLauncherForActivityResult(
contract = ActivityResultContracts.PickMultipleVisualMedia()
rememberImagePicker(
mode = localImagePickerMode(Picker.Multiple)
) { list ->
list.takeIf { it.isNotEmpty() }?.let {
viewModel.updateUris(list)
}
}

val pickImage = {
pickImageLauncher.launch(
PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)
)
pickImageLauncher.pickImage()
}

var showImagePreviewDialog by rememberSaveable { mutableStateOf(false) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ import ru.tech.imageresizershrinker.utils.ContextUtils.needToShowStoragePermissi
import ru.tech.imageresizershrinker.utils.ContextUtils.requestStoragePermission
import ru.tech.imageresizershrinker.utils.IntentUtils.parcelable
import ru.tech.imageresizershrinker.utils.IntentUtils.parcelableArrayList
import ru.tech.imageresizershrinker.utils.LocalImagePickerModeInt
import ru.tech.imageresizershrinker.utils.LocalNavController
import ru.tech.imageresizershrinker.utils.SavingFolder
import ru.tech.imageresizershrinker.utils.constructFilename
Expand Down Expand Up @@ -185,7 +186,8 @@ class MainActivity : M3Activity() {
LocalEditPresets provides editPresetsState,
LocalAlignment provides viewModel.alignment.toAlignment(),
LocalSelectedEmoji provides Emoji.allIcons.getOrNull(viewModel.selectedEmoji),
LocalNavController provides viewModel.navController
LocalNavController provides viewModel.navController,
LocalImagePickerModeInt provides viewModel.imagePickerModeInt
) {
val showSelectSheet =
rememberSaveable(viewModel.showSelectDialog) { mutableStateOf(viewModel.showSelectDialog) }
Expand Down Expand Up @@ -906,8 +908,21 @@ class MainActivity : M3Activity() {

when (intent.action) {
Intent.ACTION_VIEW -> {
intent.data?.let {
viewModel.navController.navigate(Screen.ImagePreview(listOf(it)))
val data = intent.data
val clipData = intent.clipData
if (clipData != null) {
viewModel.navController.navigate(
Screen.ImagePreview(
List(
size = clipData.itemCount,
init = {
clipData.getItemAt(it).uri
}
)
)
)
} else if (data != null) {
viewModel.navController.navigate(Screen.ImagePreview(listOf(data)))
}
}

Expand Down
Loading

0 comments on commit 61de597

Please sign in to comment.