-
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.
Merge branch 'develop' into feature/fine-tuning-main-dashboard-and-list
- Loading branch information
Showing
41 changed files
with
958 additions
and
92 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
39 changes: 39 additions & 0 deletions
39
app/src/main/java/com/architectcoders/aacboard/datasource/ErrorUtils.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,39 @@ | ||
package com.architectcoders.aacboard.datasource | ||
|
||
import android.content.Context | ||
import com.architectcoders.aacboard.R | ||
import com.architectcoders.aacboard.domain.data.Error | ||
import com.architectcoders.aacboard.domain.data.Error.* | ||
import com.architectcoders.aacboard.domain.data.Response | ||
import com.architectcoders.aacboard.domain.data.Response.Failure | ||
import com.architectcoders.aacboard.domain.data.Response.Success | ||
import retrofit2.HttpException | ||
import java.io.IOException | ||
|
||
private const val HTTP_NOT_FOUND = 404 | ||
|
||
fun Error.getMessage(context: Context): String { | ||
return when (this) { | ||
is Server -> context.getString(R.string.serverError, code) | ||
is NoMatchFound -> context.getString(R.string.noMatchFoundError) | ||
is Connectivity -> context.getString(R.string.connectivityError) | ||
is Unknown -> message.ifEmpty { context.getString(R.string.unknownError) } | ||
} | ||
} | ||
|
||
fun Throwable.toError(): Error = when (this) { | ||
is IOException -> Connectivity | ||
is HttpException -> if (code() == HTTP_NOT_FOUND) { | ||
NoMatchFound | ||
} else { | ||
Server(code()) | ||
} | ||
else -> Unknown(message ?: "") | ||
} | ||
|
||
@Suppress("TooGenericExceptionCaught") | ||
inline fun <T> tryCall(action: () -> T): Response<T> = try { | ||
Success(action()) | ||
} catch (e: Exception) { | ||
Failure(e.toError()) | ||
} |
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
12 changes: 8 additions & 4 deletions
12
app/src/main/java/com/architectcoders/aacboard/datasource/remote/RemoteDataSourceImpl.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 |
---|---|---|
@@ -1,14 +1,18 @@ | ||
package com.architectcoders.aacboard.datasource.remote | ||
|
||
import com.architectcoders.aacboard.data.datasource.remote.RemoteDataSource | ||
import com.architectcoders.aacboard.domain.data.arasaac.ArasaacPictogram | ||
import com.architectcoders.aacboard.datasource.tryCall | ||
import com.architectcoders.aacboard.domain.data.Response | ||
import com.architectcoders.aacboard.domain.data.Response.Success | ||
import com.architectcoders.aacboard.domain.data.cell.CellPictogram | ||
import com.architectcoders.aacboard.network.service.ArasaacService | ||
|
||
class RemoteDataSourceImpl(private val arasaacService: ArasaacService) : RemoteDataSource { | ||
override suspend fun searchPictos( | ||
locale: String, | ||
searchStrnig: String, | ||
): List<ArasaacPictogram> = arasaacService.searchPictos(locale, searchStrnig).map { | ||
it.toArasaacPictogram() | ||
searchString: String, | ||
): Response<List<CellPictogram>> = tryCall { | ||
val list = arasaacService.searchPictos(locale, searchString) | ||
return Success(list.map { it.toCellPictogram() }) | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/architectcoders/aacboard/di/ViewModelModule.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 |
---|---|---|
@@ -1,11 +1,22 @@ | ||
package com.architectcoders.aacboard.di | ||
|
||
import androidx.lifecycle.SavedStateHandle | ||
import com.architectcoders.aacboard.ui.fragments.viewmodel.EditBoardCellViewModel | ||
import com.architectcoders.aacboard.ui.fragments.viewmodel.ListDashboardsViewModel | ||
import com.architectcoders.aacboard.ui.fragments.viewmodel.MainDashboardViewModel | ||
import com.architectcoders.aacboard.ui.fragments.viewmodel.SearchPictogramsViewModel | ||
import org.koin.androidx.viewmodel.dsl.viewModel | ||
import org.koin.dsl.module | ||
|
||
val viewModelModule = module { | ||
viewModel { ListDashboardsViewModel(get(), get(), get()) } | ||
viewModel { MainDashboardViewModel(get()) } | ||
viewModel { SearchPictogramsViewModel(get(), get()) } | ||
viewModel { (handle: SavedStateHandle) -> | ||
EditBoardCellViewModel( | ||
handle, | ||
get(), | ||
get(), | ||
) | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
app/src/main/java/com/architectcoders/aacboard/network/response/ArasaacKeywordDTO.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,3 @@ | ||
package com.architectcoders.aacboard.network.response | ||
|
||
data class ArasaacKeywordDTO(val keyword: String) |
25 changes: 15 additions & 10 deletions
25
app/src/main/java/com/architectcoders/aacboard/network/response/ArasaacPictogramDTO.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 |
---|---|---|
@@ -1,18 +1,23 @@ | ||
package com.architectcoders.aacboard.network.response | ||
|
||
import com.architectcoders.aacboard.domain.data.arasaac.ArasaacKeyword | ||
import com.architectcoders.aacboard.domain.data.arasaac.ArasaacPictogram | ||
import com.architectcoders.aacboard.domain.data.cell.CellPictogram | ||
import com.google.gson.annotations.SerializedName | ||
|
||
data class ArasaacPictogramDTO( | ||
@SerializedName("_id") | ||
val id: Int, | ||
val arasaacKeywords: List<ArasaacKeyword>, | ||
val sex: Boolean, | ||
val violence: Boolean, | ||
val keywords: List<ArasaacKeywordDTO>, | ||
) { | ||
fun toArasaacPictogram() = ArasaacPictogram( | ||
id = this.id, | ||
arasaacKeywords = this.arasaacKeywords, | ||
sex = this.sex, | ||
violence = this.violence, | ||
companion object { | ||
private const val CONST_ARASAAC_PICTOGRAM_BASE_URL = | ||
"https://static.arasaac.org/pictograms/" | ||
} | ||
|
||
val url: String | ||
get() = "${CONST_ARASAAC_PICTOGRAM_BASE_URL}$id/${id}_300.png" | ||
|
||
fun toCellPictogram() = CellPictogram( | ||
keywords.first().keyword, | ||
url, | ||
) | ||
} |
84 changes: 83 additions & 1 deletion
84
app/src/main/java/com/architectcoders/aacboard/ui/fragments/EditBoardCellFragment.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 |
---|---|---|
@@ -1,6 +1,88 @@ | ||
package com.architectcoders.aacboard.ui.fragments | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import com.architectcoders.aacboard.R | ||
import com.architectcoders.aacboard.databinding.FragmentEditBoardCellBinding | ||
import com.architectcoders.aacboard.ui.fragments.stateholder.EditBoardCellState | ||
import com.architectcoders.aacboard.ui.fragments.stateholder.buildEditBoardCellState | ||
import com.architectcoders.aacboard.ui.fragments.viewmodel.EditBoardCellViewModel | ||
import com.architectcoders.aacboard.ui.model.PictogramUI | ||
import com.architectcoders.aacboard.ui.utils.diff | ||
import com.architectcoders.aacboard.ui.utils.loadUrl | ||
import org.koin.androidx.viewmodel.ext.android.viewModel | ||
|
||
class EditBoardCellFragment : Fragment(R.layout.fragment_edit_board_cell) | ||
class EditBoardCellFragment : Fragment(R.layout.fragment_edit_board_cell) { | ||
private var _binding: FragmentEditBoardCellBinding? = null | ||
private val binding get() = _binding!! | ||
|
||
private val viewModel: EditBoardCellViewModel by viewModel() | ||
|
||
private lateinit var editBoardCellState: EditBoardCellState | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle?, | ||
): View { | ||
_binding = FragmentEditBoardCellBinding.inflate(inflater, container, false) | ||
editBoardCellState = buildEditBoardCellState() | ||
initViews() | ||
collectState() | ||
checkSearchResponse() | ||
return binding.root | ||
} | ||
|
||
private fun initViews() { | ||
binding.apply { | ||
pictogram.setOnClickListener { | ||
editBoardCellState.onSearchPictogram() | ||
} | ||
|
||
saveButton.setOnClickListener { | ||
viewModel.onSaveClicked(keyword.text.toString()) | ||
} | ||
|
||
cancelButton.setOnClickListener { | ||
editBoardCellState.onCancel() | ||
} | ||
} | ||
} | ||
|
||
private fun collectState() { | ||
viewModel.state.let { uiStateFlow -> | ||
diff(uiStateFlow, { it.column }, ::onColumnChanged) | ||
diff(uiStateFlow, { it.row }, ::onRowChanged) | ||
diff(uiStateFlow, { it.pictogram }, ::onPictogramChanged) | ||
diff(uiStateFlow, { it.exit }, ::onExitChanged) | ||
} | ||
} | ||
|
||
private fun onColumnChanged(column: Int) { | ||
binding.columnLabel.text = getString(R.string.column_label, column) | ||
} | ||
|
||
private fun onRowChanged(row: Int) { | ||
binding.rowLabel.text = getString(R.string.row_label, row) | ||
} | ||
|
||
private fun onPictogramChanged(pictogram: PictogramUI?) { | ||
pictogram?.let { | ||
binding.pictogram.loadUrl(it.url) | ||
binding.keyword.setText(it.keyword) | ||
} | ||
} | ||
|
||
private fun onExitChanged(exit: Boolean) { | ||
if (exit) editBoardCellState.onCancel() | ||
} | ||
|
||
private fun checkSearchResponse() { | ||
editBoardCellState.checkSearchResponse { | ||
viewModel.onUpdatePictogram(it) | ||
} | ||
} | ||
} |
Oops, something went wrong.