Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DAUB-29 #15

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/src/main/java/org/dhis2/data/service/SyncPresenterImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class SyncPresenterImpl(
).doOnError {
Timber.d("error while downloading Data store")
}.onErrorComplete()
.doOnComplete { Timber.d("finished datastore download") }
.doOnComplete { Timber.d("finished datastore download") }
)
.andThen(
Completable.fromObservable(
Expand All @@ -100,7 +100,7 @@ class SyncPresenterImpl(
).doOnError {
Timber.d("error while downloading File resources")
}.onErrorComplete()
.doOnComplete { Timber.d("finished file resources download") }
.doOnComplete { Timber.d("finished file resources download") }
)
.andThen(
Completable.fromObservable(
Expand Down
22 changes: 12 additions & 10 deletions app/src/main/java/org/dhis2/usescases/main/program/ProgramUi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ import org.dhis2.ui.MetadataIconData
import org.dhis2.usescases.uiboost.data.model.DataStoreAppConfig
import org.dhis2.usescases.uiboost.data.model.Program
import org.hisp.dhis.android.core.common.State
import timber.log.Timber

@Preview(showBackground = true)
@Composable
Expand Down Expand Up @@ -216,9 +215,11 @@ private fun getFilteredPrograms(
if ((flat.program == program.uid) &&
flat.hidden == "false"
) {
list.add(program.copy(
reference = flat.icon
))
list.add(
program.copy(
reference = flat.icon
)
)
}
}
}
Expand Down Expand Up @@ -484,9 +485,11 @@ fun ListLayout(
if ((flat.program == program.uid) &&
flat.hidden == "false"
) {
list.add(program.copy(
reference = flat.icon
))
list.add(
program.copy(
reference = flat.icon
)
)
}
}
}
Expand Down Expand Up @@ -551,7 +554,7 @@ fun ProgramItemCard(
metadataIconData = programViewModel.metadataIconData
)
} else {
when(programViewModel.reference) {
when (programViewModel.reference) {
"utente" -> {
Image(
painter = painterResource(id = R.drawable.utente2),
Expand Down Expand Up @@ -728,7 +731,7 @@ fun ProgramItem(
metadataIconData = programViewModel.metadataIconData
)
} else {
when(programViewModel.reference) {
when (programViewModel.reference) {
"stock" -> {
Image(
painter = painterResource(id = R.drawable.utente),
Expand Down Expand Up @@ -909,7 +912,6 @@ fun ProgramItemCustom(
}
}


@Composable
fun StateIcon(state: State, onClick: () -> Unit) {
if (state != State.RELATIONSHIP && state != State.SYNCED) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
package org.dhis2.usescases.uiboost.data

import androidx.compose.runtime.Composable
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ data class ProgramViewModelCustom(
val downloadActive: Boolean = false,
val reference: String
)

Original file line number Diff line number Diff line change
@@ -1,9 +1,47 @@
package org.dhis2.commons.dialogs

import android.os.Parcel
import android.os.Parcelable

data class DialogMediaEntity(
val title: String,
val duration: String,
val dateOfLastUpdate: String,
val url: String,
val dialogMediaType: DialogMediaType
)
) : Parcelable {

constructor(parcel: Parcel) : this(
parcel.readString() ?: "",
parcel.readString() ?: "",
parcel.readString() ?: "",
parcel.readString() ?: "",
parcel.readParcelable(DialogMediaType::class.java.classLoader) ?: DialogMediaType.UNKNOWN
)

override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(title)
parcel.writeString(duration)
parcel.writeString(dateOfLastUpdate)
parcel.writeString(url)
parcel.writeParcelable(dialogMediaType, flags)
}

override fun describeContents(): Int {
return 0
}

companion object {
@JvmField
val CREATOR: Parcelable.Creator<DialogMediaEntity> =
object : Parcelable.Creator<DialogMediaEntity> {
override fun createFromParcel(parcel: Parcel): DialogMediaEntity {
return DialogMediaEntity(parcel)
}

override fun newArray(size: Int): Array<DialogMediaEntity?> {
return arrayOfNulls(size)
}
}
}
}
30 changes: 28 additions & 2 deletions commons/src/main/java/org/dhis2/commons/dialogs/DialogMediaType.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
package org.dhis2.commons.dialogs

enum class DialogMediaType {
import android.os.Parcel
import android.os.Parcelable

enum class DialogMediaType : Parcelable {
VIDEO,
AUDIO
AUDIO,
UNKNOWN;

override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeInt(ordinal)
}

override fun describeContents(): Int {
return 0
}

companion object {
@JvmField
val CREATOR: Parcelable.Creator<DialogMediaType> =
object : Parcelable.Creator<DialogMediaType> {
override fun createFromParcel(parcel: Parcel): DialogMediaType {
return values()[parcel.readInt()]
}

override fun newArray(size: Int): Array<DialogMediaType?> {
return arrayOfNulls(size)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ fun MediaDialog(
LazyColumn(modifier = Modifier.fillMaxWidth()) {
items(sortedMediaEntities) { mediaEntity ->
when (mediaEntity.dialogMediaType) {
DialogMediaType.VIDEO, DialogMediaType.AUDIO -> {
DialogMediaType.VIDEO,
DialogMediaType.AUDIO,
DialogMediaType.UNKNOWN
-> {
MediaDialogItem(
dialogMediaType = mediaEntity.dialogMediaType,
title = mediaEntity.title,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.dhis2.commons.dialogs

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.ui.platform.ComposeView
import androidx.fragment.app.DialogFragment

class MediaDialogFragment : DialogFragment() {

private var title: String? = null
private var message: String? = null
private var mediaEntities: List<DialogMediaEntity>? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

arguments?.let {
title = it.getString(MEDIA_DIALOG_TITLE)
message = it.getString(MEDIA_DIALOG_MESSAGE)
mediaEntities = it.getParcelableArrayList(MEDIA_DIALOG_MEDIA_ENTITIES)
}
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return ComposeView(requireContext()).apply {
setContent {
MediaDialog(
title = title ?: randomTitle(),
subTitle = message ?: randomSubTitle(),
mediaEntities = mediaEntities ?: randomMediaEntities(),
onDismiss = {
dismiss()
}
)
}
}
}

companion object {
const val MEDIA_DIALOG_TAG = "media_dialog_tag"
private const val MEDIA_DIALOG_TITLE = "title"
private const val MEDIA_DIALOG_MESSAGE = "message"
private const val MEDIA_DIALOG_MEDIA_ENTITIES = "media_entities"

fun newInstance(
title: String,
message: String,
mediaEntities: List<DialogMediaEntity>
): MediaDialogFragment {
val mediaDialogFragment = MediaDialogFragment()
val arguments = Bundle()
arguments.putString(MEDIA_DIALOG_TITLE, title)
arguments.putString(MEDIA_DIALOG_MESSAGE, message)
arguments.putParcelableArrayList(MEDIA_DIALOG_MEDIA_ENTITIES, ArrayList(mediaEntities))
mediaDialogFragment.arguments = arguments
return mediaDialogFragment
}
}
}
5 changes: 3 additions & 2 deletions form/src/main/java/org/dhis2/form/model/FieldUiModelImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ data class FieldUiModelImpl(
override fun onDescriptionClick() {
callback?.recyclerViewUiEvents(
RecyclerViewUiEvents.ShowDescriptionLabelDialog(
label,
description
uid = uid,
title = label,
message = description
)
)
}
Expand Down
4 changes: 2 additions & 2 deletions form/src/main/java/org/dhis2/form/model/SectionUiModelImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ data class SectionUiModelImpl(
override fun onDescriptionClick() {
callback?.recyclerViewUiEvents(
RecyclerViewUiEvents.ShowDescriptionLabelDialog(
label,
description
title = label,
message = description
)
)
}
Expand Down
58 changes: 30 additions & 28 deletions form/src/main/java/org/dhis2/form/ui/FormView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ import android.widget.DatePicker
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.RequiresApi
import androidx.compose.ui.platform.ComposeView
import androidx.core.content.FileProvider
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.viewModels
Expand All @@ -42,18 +40,18 @@ import java.util.Calendar
import org.dhis2.commons.ActivityResultObservable
import org.dhis2.commons.ActivityResultObserver
import org.dhis2.commons.Constants
import org.dhis2.commons.bindings.dataElement
import org.dhis2.commons.bindings.getFileFrom
import org.dhis2.commons.bindings.getFileFromGallery
import org.dhis2.commons.bindings.rotateImage
import org.dhis2.commons.dialogs.AlertBottomDialog
import org.dhis2.commons.dialogs.CustomDialog
import org.dhis2.commons.dialogs.MediaDialog
import org.dhis2.commons.dialogs.MediaDialogFragment.Companion.MEDIA_DIALOG_TAG
import org.dhis2.commons.dialogs.MediaDialogFragment.Companion.newInstance
import org.dhis2.commons.dialogs.calendarpicker.CalendarPicker
import org.dhis2.commons.dialogs.calendarpicker.OnDatePickerListener
import org.dhis2.commons.dialogs.imagedetail.ImageDetailBottomDialog
import org.dhis2.commons.dialogs.randomMediaEntities
import org.dhis2.commons.dialogs.randomSubTitle
import org.dhis2.commons.dialogs.randomTitle
import org.dhis2.commons.extensions.closeKeyboard
import org.dhis2.commons.extensions.serializable
import org.dhis2.commons.extensions.truncate
Expand Down Expand Up @@ -89,6 +87,7 @@ import org.dhis2.maps.views.MapSelectorActivity.Companion.LOCATION_TYPE_EXTRA
import org.dhis2.ui.ErrorFieldList
import org.dhis2.ui.dialogs.bottomsheet.BottomSheetDialog
import org.dhis2.ui.dialogs.signature.SignatureDialog
import org.hisp.dhis.android.core.D2Manager.getD2
import org.hisp.dhis.android.core.arch.helpers.FileResourceDirectoryHelper
import org.hisp.dhis.android.core.arch.helpers.GeometryHelper
import org.hisp.dhis.android.core.common.FeatureType
Expand Down Expand Up @@ -521,7 +520,7 @@ class FormView : Fragment() {
)

is RecyclerViewUiEvents.OpenTimePicker -> showTimePicker(uiEvent)
is RecyclerViewUiEvents.ShowDescriptionLabelDialog -> showDescriptionLabelDialog()
is RecyclerViewUiEvents.ShowDescriptionLabelDialog -> showDialog(uiEvent)
is RecyclerViewUiEvents.RequestCurrentLocation -> requestCurrentLocation(uiEvent)
is RecyclerViewUiEvents.RequestLocationByMap -> requestLocationByMap(uiEvent)
is RecyclerViewUiEvents.DisplayQRCode -> displayQRImage(uiEvent)
Expand Down Expand Up @@ -733,32 +732,35 @@ class FormView : Fragment() {
.show()
}

private fun showDescriptionLabelDialog() {
ComposeDialogFragment()
.show(childFragmentManager, "ComposeDialog")
}
private fun showDialog(intent: RecyclerViewUiEvents.ShowDescriptionLabelDialog) {
val dataElement = getD2().dataElement(intent.uid)
jobguitiche marked this conversation as resolved.
Show resolved Hide resolved

class ComposeDialogFragment : DialogFragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return ComposeView(requireContext()).apply {
setContent {
MediaDialog(
title = randomTitle(),
subTitle = randomSubTitle(),
mediaEntities = randomMediaEntities(),
onDismiss = {
dismiss()
}
)
}
}
if (dataElement.valueType()?.isFile == true) {
jobguitiche marked this conversation as resolved.
Show resolved Hide resolved
val mediaDialogFragment = newInstance(
title = intent.title,
message = intent.message ?: requireContext().getString(R.string.empty_description),
mediaEntities = randomMediaEntities()
)
mediaDialogFragment.show(childFragmentManager, MEDIA_DIALOG_TAG)
} else {
showDescriptionLabelDialog(intent)
}
}

private fun showDescriptionLabelDialog(
intent: RecyclerViewUiEvents.ShowDescriptionLabelDialog
) {
CustomDialog(
requireContext(),
intent.title,
intent.message ?: requireContext().getString(R.string.empty_description),
requireContext().getString(R.string.action_close),
null,
Constants.DESCRIPTION_DIALOG,
null
).show()
}

private fun requestCurrentLocation(event: RecyclerViewUiEvents.RequestCurrentLocation) {
locationProvider?.getLastKnownLocation(
{ location ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ sealed class RecyclerViewUiEvents {
) : RecyclerViewUiEvents()

data class ShowDescriptionLabelDialog(
val uid: String = "",
val title: String,
val message: String?
) : RecyclerViewUiEvents()
Expand Down