-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ANDROAPP-5829-adapt-input-image-to-new-mobile-ui-functionality (#3462)
* Handle `Intent.ACTION_SEND` in form view for sharing files * Open chooser intent when share button is clicked in `ImageInput` * Open chooser intent when share button is clicked in `InputSignature`` * Move `getBitmap` extension to commons module * Move `FormFileProvider` to commons module * Add image detail activity Currently we don't have a working "save image" functionality. So, it didn't make sense to copy the implementation that is not working. So for the time being I marked it as TODO * Launch `ImageDetailActivity` instead of `ImageDetailBottomDialog` * Remove `ImageDetailBottomDialog`
- Loading branch information
1 parent
645f70e
commit 2b383a2
Showing
15 changed files
with
177 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...a/org/dhis2/form/data/FormFileProvider.kt → ...rg/dhis2/commons/data/FormFileProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.dhis2.form.data | ||
package org.dhis2.commons.data | ||
|
||
import android.content.Context | ||
|
||
|
79 changes: 79 additions & 0 deletions
79
commons/src/main/java/org/dhis2/commons/dialogs/imagedetail/ImageDetailActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package org.dhis2.commons.dialogs.imagedetail | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.activity.compose.setContent | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.graphics.asImageBitmap | ||
import androidx.compose.ui.graphics.painter.BitmapPainter | ||
import androidx.core.content.FileProvider | ||
import org.dhis2.commons.R | ||
import org.dhis2.commons.data.FormFileProvider | ||
import org.dhis2.commons.extensions.getBitmap | ||
import org.hisp.dhis.mobile.ui.designsystem.component.FullScreenImage | ||
import timber.log.Timber | ||
import java.io.File | ||
import java.io.IOException | ||
|
||
class ImageDetailActivity : AppCompatActivity() { | ||
|
||
companion object { | ||
|
||
private const val ARG_IMAGE_TITLE = "arg_image_title" | ||
private const val ARG_IMAGE_PATH = "arg_image_path" | ||
|
||
fun intent(context: Context, title: String?, imagePath: String): Intent { | ||
return Intent(context, ImageDetailActivity::class.java).apply { | ||
putExtra(ARG_IMAGE_TITLE, title) | ||
putExtra(ARG_IMAGE_PATH, imagePath) | ||
} | ||
} | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
val title = intent.getStringExtra(ARG_IMAGE_TITLE) | ||
val imagePath = intent.getStringExtra(ARG_IMAGE_PATH)!! | ||
|
||
setContent { | ||
val painter = remember(imagePath) { | ||
imagePath.getBitmap()?.let { BitmapPainter(it.asImageBitmap()) } | ||
} | ||
|
||
FullScreenImage( | ||
painter = painter!!, | ||
title = title.orEmpty(), | ||
onDismiss = { finish() }, | ||
onDownloadButtonClick = { saveImage(imagePath) }, | ||
onShareButtonClick = { shareImage(imagePath) }, | ||
) | ||
} | ||
} | ||
|
||
private fun saveImage(image: String) { | ||
// TODO: Implement saving image to disk | ||
} | ||
|
||
private fun shareImage(image: String) { | ||
val intent = Intent(Intent.ACTION_SEND).apply { | ||
val contentUri = FileProvider.getUriForFile( | ||
this@ImageDetailActivity, | ||
FormFileProvider.fileProviderAuthority, | ||
File(image), | ||
) | ||
setDataAndType(contentUri, contentResolver.getType(contentUri)) | ||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) | ||
putExtra(Intent.EXTRA_STREAM, contentUri) | ||
} | ||
|
||
val title = resources.getString(R.string.open_with) | ||
val chooser = Intent.createChooser(intent, title) | ||
try { | ||
startActivity(chooser) | ||
} catch (e: IOException) { | ||
Timber.e(e) | ||
} | ||
} | ||
} |
83 changes: 0 additions & 83 deletions
83
commons/src/main/java/org/dhis2/commons/dialogs/imagedetail/ImageDetailBottomDialog.kt
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
commons/src/main/java/org/dhis2/commons/extensions/PictureBindings.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.dhis2.commons.extensions | ||
|
||
import android.graphics.Bitmap | ||
import android.graphics.BitmapFactory | ||
import java.io.File | ||
|
||
fun String.getBitmap(): Bitmap? = File(this) | ||
.takeIf { it.exists() } | ||
?.let { BitmapFactory.decodeFile(it.absolutePath) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.