Skip to content

Commit

Permalink
ANDROAPP-5829-adapt-input-image-to-new-mobile-ui-functionality (#3462)
Browse files Browse the repository at this point in the history
* 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
msasikanth authored Jan 16, 2024
1 parent 03b4bf4 commit 87b0e31
Show file tree
Hide file tree
Showing 15 changed files with 177 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import org.dhis2.commons.Constants.ENROLLMENT_UID
import org.dhis2.commons.Constants.PROGRAM_UID
import org.dhis2.commons.Constants.TEI_UID
import org.dhis2.commons.data.TeiAttributesInfo
import org.dhis2.commons.dialogs.imagedetail.ImageDetailBottomDialog
import org.dhis2.commons.dialogs.imagedetail.ImageDetailActivity
import org.dhis2.commons.featureconfig.data.FeatureConfigRepository
import org.dhis2.commons.featureconfig.model.Feature
import org.dhis2.databinding.EnrollmentActivityBinding
Expand Down Expand Up @@ -348,14 +348,13 @@ class EnrollmentActivity : ActivityGlobalAbstract(), EnrollmentView {
}

override fun displayTeiPicture(picturePath: String) {
// TODO replace ImageDetailBottomDialog with new mobile ui Image detail component
ImageDetailBottomDialog(
null,
File(picturePath),
).show(
supportFragmentManager,
ImageDetailBottomDialog.TAG,
val intent = ImageDetailActivity.intent(
context = this,
title = null,
imagePath = picturePath,
)

startActivity(intent)
}
/*endregion*/
/*region ACCESS*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import androidx.paging.PagedList
import androidx.recyclerview.widget.ConcatAdapter
import androidx.recyclerview.widget.RecyclerView
import org.dhis2.bindings.dp
import org.dhis2.commons.dialogs.imagedetail.ImageDetailBottomDialog
import org.dhis2.commons.dialogs.imagedetail.ImageDetailActivity
import org.dhis2.commons.filters.workingLists.WorkingListViewModel
import org.dhis2.commons.filters.workingLists.WorkingListViewModelFactory
import org.dhis2.commons.resources.ColorUtils
Expand All @@ -35,7 +35,6 @@ import org.dhis2.usescases.searchTrackEntity.ui.CreateNewButton
import org.dhis2.usescases.searchTrackEntity.ui.FullSearchButtonAndWorkingList
import org.dhis2.usescases.searchTrackEntity.ui.mapper.TEICardMapper
import org.dhis2.utils.isLandscape
import java.io.File
import javax.inject.Inject

const val ARG_FROM_RELATIONSHIP = "ARG_FROM_RELATIONSHIP"
Expand Down Expand Up @@ -232,8 +231,13 @@ class SearchTEList : FragmentGlobalAbstract() {

// TODO replace ImageDetailBottomDialog with new mobile ui Image detail component
private fun displayImageDetail(imagePath: String) {
ImageDetailBottomDialog(null, File(imagePath))
.show(childFragmentManager, ImageDetailBottomDialog.TAG)
val intent = ImageDetailActivity.intent(
context = requireContext(),
title = null,
imagePath = imagePath,
)

startActivity(intent)
}

private fun observeNewData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.dhis2.animations.CarouselViewAnimations
import org.dhis2.bindings.dp
import org.dhis2.commons.bindings.clipWithRoundedCorners
import org.dhis2.commons.data.RelationshipOwnerType
import org.dhis2.commons.dialogs.imagedetail.ImageDetailBottomDialog
import org.dhis2.commons.dialogs.imagedetail.ImageDetailActivity
import org.dhis2.commons.locationprovider.LocationSettingLauncher
import org.dhis2.commons.resources.ColorType
import org.dhis2.commons.resources.ColorUtils
Expand All @@ -33,7 +33,6 @@ import org.dhis2.usescases.searchTrackEntity.SearchTEIViewModel
import org.dhis2.usescases.searchTrackEntity.SearchTeiViewModelFactory
import org.dhis2.utils.NetworkUtils
import org.dhis2.utils.isPortrait
import java.io.File
import javax.inject.Inject

const val ARG_FROM_RELATIONSHIP = "ARG_FROM_RELATIONSHIP"
Expand Down Expand Up @@ -260,14 +259,15 @@ class SearchTEMap : FragmentGlobalAbstract(), MapboxMap.OnMapClickListener {
}
.addOnProfileImageClickListener { path: String? ->
if (binding.mapCarousel.carouselEnabled) {
// TODO replace ImageDetailBottomDialog with new mobile ui Image detail component
ImageDetailBottomDialog(
null,
File(path),
).show(
childFragmentManager,
ImageDetailBottomDialog.TAG,
)
if (!path.isNullOrBlank()) {
val intent = ImageDetailActivity.intent(
context = requireContext(),
title = null,
imagePath = path,
)

startActivity(intent)
}
}
Unit
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import org.dhis2.commons.data.EventViewModel
import org.dhis2.commons.data.StageSection
import org.dhis2.commons.dialogs.CustomDialog
import org.dhis2.commons.dialogs.DialogClickListener
import org.dhis2.commons.dialogs.imagedetail.ImageDetailBottomDialog
import org.dhis2.commons.dialogs.imagedetail.ImageDetailActivity
import org.dhis2.commons.filters.FilterItem
import org.dhis2.commons.filters.FilterManager
import org.dhis2.commons.filters.FilterManager.PeriodRequest
Expand Down Expand Up @@ -269,11 +269,13 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View {
val card = teiDashboardCardMapper.map(
dashboardModel = dashboardModel,
onImageClick = { fileToShow ->
// TODO replace ImageDetailBottomDialog with new mobile ui Image detail component
ImageDetailBottomDialog(
null,
fileToShow,
).show(childFragmentManager, ImageDetailBottomDialog.TAG)
val intent = ImageDetailActivity.intent(
context = requireActivity(),
title = null,
imagePath = fileToShow.path,
)

startActivity(intent)
},
phoneCallback = { openChooser(it, Intent.ACTION_DIAL) },
emailCallback = { openChooser(it, Intent.ACTION_SENDTO) },
Expand Down Expand Up @@ -538,11 +540,13 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View {
binding.cardFront.teiImage.setOnClickListener {
val fileToShow = File(filePath)
if (fileToShow.exists()) {
// TODO replace ImageDetailBottomDialog with new mobile ui Image detail component
ImageDetailBottomDialog(
null,
fileToShow,
).show(childFragmentManager, ImageDetailBottomDialog.TAG)
val intent = ImageDetailActivity.intent(
context = requireActivity(),
title = null,
imagePath = fileToShow.path,
)

startActivity(intent)
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion commons/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
android:name="org.dhis2.commons.featureconfig.ui.FeatureConfigView"
android:exported="false"/>

<activity android:name="org.dhis2.commons.dialogs.imagedetail.ImageDetailActivity"
android:exported="false" />

</application>

</manifest>
</manifest>
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

Expand Down
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)
}
}
}

This file was deleted.

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) }
1 change: 1 addition & 0 deletions commons/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,5 @@
<item quantity="one">%d year overdue</item>
<item quantity="other">%d years overdue</item>
</plurals>
<string name="open_with">Open with</string>
</resources>
Loading

0 comments on commit 87b0e31

Please sign in to comment.