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 all 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
)

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.dhis2.commons.dialogs.media

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

data class DialogMediaEntity(
// Add uid
val title: String,
val duration: String,
val dateOfLastUpdate: String,
val url: String, // Todo: change to '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)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.dhis2.commons.dialogs.media

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

enum class DialogMediaType : Parcelable {
VIDEO,
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
@@ -0,0 +1,74 @@
package org.dhis2.commons.dialogs.media

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Card
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.fragment.app.DialogFragment

class LoadingMediaDialogFragment : DialogFragment() {

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
): View {
return ComposeView(requireContext()).apply {
setContent {
LoadingMediaDialog(onDismiss = { dismiss() })
}
}
}

companion object {
const val LOADING_MEDIA_DIALOG_TAG = "loading_media_dialog_tag"
fun loadingMediaDialog(): LoadingMediaDialogFragment {
return LoadingMediaDialogFragment()
}
}
}

@Composable
fun LoadingMediaDialog(onDismiss: () -> Unit) {
Dialog(onDismissRequest = { onDismiss() }) {
Card(
shape = RoundedCornerShape(8.dp),
modifier = Modifier,
elevation = 8.dp
) {
Column(
Modifier
.background(Color.White)
.padding(12.dp)
) {
Text(
text = "Loading.. Please wait..",
Modifier
.padding(8.dp), textAlign = TextAlign.Center
)

CircularProgressIndicator(
strokeWidth = 4.dp,
modifier = Modifier
.align(Alignment.CenterHorizontally)
.padding(8.dp)
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.dhis2.commons.dialogs
package org.dhis2.commons.dialogs.media

import android.content.res.Configuration
import android.os.Build
Expand Down 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.media

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 mediaDialog(
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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@ package org.dhis2.commons.extensions

import android.content.Context
import android.content.Intent
import android.widget.Toast
import androidx.core.content.ContextCompat
import org.dhis2.commons.R
import org.dhis2.commons.media.MediaActivity
import timber.log.Timber

fun Context.playMedia(mediaUrl: String) {
val intent = Intent(this, MediaActivity::class.java)
intent.putExtra(MediaActivity.KEY_MEDIA_URL_VALUE, mediaUrl)
ContextCompat.startActivity(this, intent, null)
if (mediaUrl.isEmpty()) {
Toast.makeText(
this,
getString(R.string.error_message_invalid_file_path),
Toast.LENGTH_LONG
).show()
Timber.d("Invalid Media Path = [$mediaUrl]")
} else {
val intent = Intent(this, MediaActivity::class.java)
intent.putExtra(MediaActivity.KEY_MEDIA_URL_VALUE, mediaUrl)
ContextCompat.startActivity(this, intent, null)
}
}
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 @@ -230,4 +230,5 @@
<string name="media_dialog_label_duration">Duration</string>
<string name="media_dialog_label_update">Update</string>
<string name="media_dialog_label_close">Close</string>
<string name="error_message_invalid_file_path">Invalid file path</string>
</resources>
2 changes: 1 addition & 1 deletion form/src/main/java/org/dhis2/form/data/FormRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ interface FormRepository {
fun clearFocusItem()
fun storeFile(id: String, filePath: String?): StoreResult?
fun getMediaDataStore(): Flow<MediaStoreConfig?>
suspend fun downloadMediaToLocal(uid: String): ResponseBody
suspend fun downloadMediaToLocal(uid: String): ResponseBody?
}
Loading