forked from dhis2/dhis2-android-capture-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
REI 16 - Implement error list to the app and design improvements (#20)
* 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
1 parent
0db52fc
commit a47860a
Showing
18 changed files
with
342 additions
and
73 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
...ort-module/src/main/java/com/saudigitus/support_module/data/local/SyncErrorsRepository.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,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>> | ||
} |
32 changes: 32 additions & 0 deletions
32
...main/java/com/saudigitus/support_module/data/local/repository/SyncErrorsRepositoryImpl.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,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()) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
support-module/src/main/java/com/saudigitus/support_module/data/models/erros/ErrorModel.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,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, | ||
) |
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
41 changes: 41 additions & 0 deletions
41
...rt-module/src/main/java/com/saudigitus/support_module/ui/SupportScreen/ErrorsViewModel.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,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() | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
support-module/src/main/java/com/saudigitus/support_module/ui/errorsScreen/ErrorUiState.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,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() | ||
) |
Oops, something went wrong.