Skip to content

Commit

Permalink
REI 16 - Implement error list to the app and design improvements (#20)
Browse files Browse the repository at this point in the history
* Prepare support error module and repository

* Implement navigation to support screen

* Implement errors list at the app

* Fix design and labels

* Clean the code

* Remove commentary from gradle file

* Rename Model
  • Loading branch information
NelsonChad authored Oct 18, 2024
1 parent 0db52fc commit a47860a
Show file tree
Hide file tree
Showing 18 changed files with 342 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.saudigitus.support_module.data.local

import com.saudigitus.support_module.data.models.erros.ErrorModel
import kotlinx.coroutines.flow.Flow

interface SyncErrorsRepository {
fun getSyncErrors(): Flow<List<ErrorModel>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.saudigitus.support_module.data.local.repository

import com.saudigitus.support_module.data.local.SyncErrorsRepository
import com.saudigitus.support_module.data.models.erros.ErrorModel
import com.saudigitus.support_module.utils.ErrorModelMapper
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import org.hisp.dhis.android.core.D2

class SyncErrorsRepositoryImpl(
private val d2: D2,
private val errorMapper: ErrorModelMapper,
): SyncErrorsRepository {
override fun getSyncErrors(): Flow<List<ErrorModel>> {

val errors: MutableList<ErrorModel> = ArrayList()
errors.addAll(
errorMapper.mapD2Error(d2.maintenanceModule().d2Errors().blockingGet()),
)
errors.addAll(
errorMapper.mapConflict(
d2.importModule().trackerImportConflicts().blockingGet(),
),
)
errors.addAll(
errorMapper.mapFKViolation(
d2.maintenanceModule().foreignKeyViolations().blockingGet(),
),
)
return flowOf(errors.toList())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.saudigitus.support_module.data.models.erros

import java.util.Date

data class ErrorModel(
val creationDate: Date?,
val errorCode: String?,
val errorDescription: String?,
val errorComponent: String?,
var isSelected: Boolean = false,
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.saudigitus.support_module.di

import android.app.Application
import androidx.compose.ui.res.stringResource
import androidx.room.Room
import com.saudigitus.support_module.R
import com.saudigitus.support_module.data.local.ManualsRepository
import com.saudigitus.support_module.data.local.SyncErrorsRepository
import com.saudigitus.support_module.data.local.database.AppDatabase
import com.saudigitus.support_module.data.local.repository.ManualsRepositoryImp
import com.saudigitus.support_module.data.local.repository.SyncErrorsRepositoryImpl
import com.saudigitus.support_module.utils.ErrorModelMapper
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand All @@ -28,10 +33,17 @@ object AppModule {
/**
* Inject ManualsRepository
*/

@Provides
@Singleton fun providesManualRepository(appDatabase: AppDatabase, d2: D2): ManualsRepository {
return ManualsRepositoryImp(appDatabase.manualsDAO(), d2 = d2)
}

/**
* Inject SyncErrorsRepository
*/
@Provides
@Singleton fun providesSyncErrorsRepository(app: Application, d2: D2): SyncErrorsRepository {
return SyncErrorsRepositoryImpl(errorMapper = ErrorModelMapper(fkMessage = app.getString(R.string.fk_message)), d2 = d2)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ sealed class Screen(val route: String) {
object Manuals : Screen("manuals")
object Support : Screen("support")
object ViewPdf : Screen("pdf_view/{path}")
object SyncErrors : Screen("sync_errors")
object GeneralErrors : Screen("general_errors")

}


Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.saudigitus.support_module.ui.SupportScreen

import android.content.Context
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.saudigitus.support_module.data.local.ManualsRepository
import com.saudigitus.support_module.data.local.SyncErrorsRepository
import com.saudigitus.support_module.ui.ManualsUiState
import com.saudigitus.support_module.ui.errorsScreen.ErrorUiState
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class ErrorsViewModel @Inject internal constructor(
private val repository: SyncErrorsRepository,
@ApplicationContext private val context: Context
) : ViewModel() {

private val _errorsUiState = MutableStateFlow(ErrorUiState())
val errorsUiState = _errorsUiState.asStateFlow()

private fun getErrors(){
viewModelScope.launch {
_errorsUiState.update {it.copy(isLoading = true)}
repository.getSyncErrors().collect{ errors ->
_errorsUiState.update {
it.copy(errorsItems = errors, isLoading = false)
}
}
}
}

init {
getErrors()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Warning
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand All @@ -15,10 +16,15 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavHostController
import com.saudigitus.support_module.R
import com.saudigitus.support_module.ui.Screen
import com.saudigitus.support_module.ui.SupportScreen.ErrorsViewModel
import com.saudigitus.support_module.ui.components.BasicApp
import com.saudigitus.support_module.ui.components.SimpleCard
import com.saudigitus.support_module.ui.manualScreen.ManualViewModel
import timber.log.Timber

@OptIn(ExperimentalMaterial3Api::class)
Expand All @@ -44,9 +50,19 @@ fun SupportScreen(
color = Color.Gray
)
Spacer(Modifier.height(20.dp))
SimpleCard(title = stringResource(id = R.string.sync_errord), icon = Icons.Default.Close)
SimpleCard(title = stringResource(
id = R.string.sync_errord),
icon = Icons.Default.Close,
onClick = {
navController.navigate(Screen.SyncErrors.route)
})
Spacer(Modifier.height(20.dp))
SimpleCard(title = stringResource(id = R.string.other_errors) , icon = Icons.Default.Warning)
SimpleCard(title = stringResource(
id = R.string.other_errors),
icon = Icons.Default.Warning,
onClick = {
navController.navigate(Screen.GeneralErrors.route)
})
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.saudigitus.support_module.ui.theme.Blue700
import org.hisp.dhis.mobile.ui.designsystem.theme.Radius
import org.hisp.dhis.mobile.ui.designsystem.theme.dropShadow

@Composable
fun CustomCard(imageResId: Int, title: String, onClick: () -> Unit) {
Card(
modifier = Modifier
.size(150.dp)
.shadow(2.dp, RoundedCornerShape(16.dp))
.clip(RoundedCornerShape(16.dp))
.dropShadow(shape = RoundedCornerShape(Radius.XS))
.clip(RoundedCornerShape(10.dp))
.clickable { onClick() },
shape = RoundedCornerShape(Radius.XS),
colors = CardDefaults.cardColors(containerColor = Color.White),
elevation = CardDefaults.cardElevation(50.dp),
) {
Expand All @@ -46,7 +50,7 @@ fun CustomCard(imageResId: Int, title: String, onClick: () -> Unit) {
Spacer(modifier = Modifier.height(8.dp))
Text(
text = title,
color = Color.Black,
color = Blue700,
fontWeight = FontWeight.Bold
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.saudigitus.support_module.ui.components
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
Expand All @@ -21,43 +22,49 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.viewtest.ui.manualScreen.ErrosScreen

@Composable
fun ErrorComponent(error: String) {
fun ErrorComponent(error: String, type: String, comp: String, date: String) {
Card(
shape = RoundedCornerShape(8.dp),
modifier = Modifier
.border(1.dp, Color.Red, RoundedCornerShape(8.dp)) // Red border
) {
// Applying background to the entire card content
Row(
Column(
modifier = Modifier
.fillMaxWidth()
.background(Color(0xFFFFCDD2))
.padding(8.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
){
) {

Row(
modifier = Modifier
.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
){
Text(
text = date,
fontSize = 12.sp,
color = Color.Gray
)
Text(
text = "$type $comp",
fontSize = 10.sp,
color = Color.Red
)
}
Text(
text = error,
)
Icon(
imageVector = Icons.Filled.Close,
contentDescription = "title",
modifier = Modifier
// .fillMaxWidth() // Ensures the text takes up the card width
.background(Color(0xFFFFCDD2))
.size(20.dp),

tint = Color.Gray
fontSize = 12.sp,
color = Color.Black
)
}


}
}
@Preview(showBackground = true)
@Composable
fun ScreenPreview() {
ErrorComponent("Error It is a long established fact reader")
ErrorComponent("Error It is a long established fact reader", "FK", "server","2012-15-54")
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.saudigitus.support_module.R
import com.saudigitus.support_module.ui.ManualsUiState
import org.hisp.dhis.mobile.ui.designsystem.theme.Radius
import org.hisp.dhis.mobile.ui.designsystem.theme.dropShadow

@Composable
fun ListCard(
Expand All @@ -45,11 +47,11 @@ fun ListCard(
modifier = Modifier
.fillMaxWidth()
.size(width = 0.dp, height = 80.dp)
.shadow(2.dp, RoundedCornerShape(16.dp))
.clip(RoundedCornerShape(16.dp))
.dropShadow(shape = RoundedCornerShape(Radius.XS))
.clickable(onClick = onClick),
shape = RoundedCornerShape(Radius.XS),
colors = CardDefaults.cardColors(containerColor = Color.White),
elevation = CardDefaults.cardElevation(50.dp),
elevation = CardDefaults.cardElevation(10.dp),
){
Row(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.saudigitus.support_module.ui.components

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -25,15 +26,23 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.saudigitus.support_module.ui.theme.Blue700
import org.hisp.dhis.mobile.ui.designsystem.theme.Radius
import org.hisp.dhis.mobile.ui.designsystem.theme.dropShadow

@Composable
fun SimpleCard(title: String, icon: androidx.compose.ui.graphics.vector.ImageVector) {
fun SimpleCard(
title: String,
icon: androidx.compose.ui.graphics.vector.ImageVector,
onClick: () -> Unit) {
Card(
modifier = Modifier
.fillMaxWidth()
.size(width = 0.dp, height = 70.dp)
.shadow(2.dp, RoundedCornerShape(16.dp))
.clip(RoundedCornerShape(16.dp)),
.dropShadow(shape = RoundedCornerShape(Radius.XS))
.clip(RoundedCornerShape(10.dp))
.clickable(onClick = onClick),
shape = RoundedCornerShape(Radius.XS),
colors = CardDefaults.cardColors(containerColor = Color.White),
elevation = CardDefaults.cardElevation(50.dp),
){
Expand All @@ -53,13 +62,12 @@ fun SimpleCard(title: String, icon: androidx.compose.ui.graphics.vector.ImageVec
text = title,
fontSize = 14.sp,
overflow = TextOverflow.Ellipsis,
color = Color.Black
color = Blue700
)
}
Icon(
imageVector = icon,
contentDescription = title,
// modifier = Modifier.size(48.dp),
tint = Color.Black
)
}
Expand All @@ -69,5 +77,5 @@ fun SimpleCard(title: String, icon: androidx.compose.ui.graphics.vector.ImageVec
@Preview(showBackground = true)
@Composable
fun SimpleCardPreview() {
SimpleCard(title = "Manual subtitle here alfa", icon = Icons.AutoMirrored.Filled.KeyboardArrowRight)
SimpleCard(title = "Manual subtitle here alfa", icon = Icons.AutoMirrored.Filled.KeyboardArrowRight, onClick = {})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.saudigitus.support_module.ui.errorsScreen

import com.saudigitus.support_module.data.models.erros.ErrorModel

data class ErrorUiState(
val isLoading: Boolean = false,
val errorsItems: List<ErrorModel> = emptyList()
)
Loading

0 comments on commit a47860a

Please sign in to comment.