mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-14 00:05:04 +01:00
i18n and loading after connection issues
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
d3f38a720f
commit
06ed99f3ad
@ -22,18 +22,14 @@
|
||||
|
||||
package com.nextcloud.talk.newarch.data.model
|
||||
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication
|
||||
|
||||
/**
|
||||
* This class designed to show different types of errors through error status & message
|
||||
*
|
||||
* */
|
||||
|
||||
private const val NO_CONNECTION_ERROR_MESSAGE = "No connection"
|
||||
private const val BAD_RESPONSE_ERROR_MESSAGE = "Bad response"
|
||||
private const val TIME_OUT_ERROR_MESSAGE = "Time out"
|
||||
private const val EMPTY_RESPONSE_ERROR_MESSAGE = "Empty response"
|
||||
private const val NOT_DEFINED_ERROR_MESSAGE = "Not defined"
|
||||
private const val UNAUTHORIZED_ERROR_MESSAGE = "Unauthorized"
|
||||
|
||||
data class ErrorModel(
|
||||
val message: String?,
|
||||
val code: Int?,
|
||||
@ -48,12 +44,23 @@ data class ErrorModel(
|
||||
|
||||
fun getErrorMessage(): String {
|
||||
return when (errorStatus) {
|
||||
ErrorStatus.NO_CONNECTION -> NO_CONNECTION_ERROR_MESSAGE
|
||||
ErrorStatus.BAD_RESPONSE -> BAD_RESPONSE_ERROR_MESSAGE
|
||||
ErrorStatus.TIMEOUT -> TIME_OUT_ERROR_MESSAGE
|
||||
ErrorStatus.EMPTY_RESPONSE -> EMPTY_RESPONSE_ERROR_MESSAGE
|
||||
ErrorStatus.NOT_DEFINED -> NOT_DEFINED_ERROR_MESSAGE
|
||||
ErrorStatus.UNAUTHORIZED -> UNAUTHORIZED_ERROR_MESSAGE
|
||||
ErrorStatus.NO_CONNECTION -> NextcloudTalkApplication.sharedApplication?.resources!!.getString(
|
||||
R.string.nc_no_connection_error
|
||||
)
|
||||
ErrorStatus.BAD_RESPONSE -> NextcloudTalkApplication.sharedApplication?.resources!!.getString(
|
||||
R.string.nc_bad_response_error
|
||||
)
|
||||
ErrorStatus.TIMEOUT -> NextcloudTalkApplication.sharedApplication?.resources!!.getString(
|
||||
R.string.nc_timeout_error
|
||||
)
|
||||
ErrorStatus.EMPTY_RESPONSE -> NextcloudTalkApplication.sharedApplication?.resources!!.getString(
|
||||
R.string.nc_empty_response_error
|
||||
)
|
||||
ErrorStatus.NOT_DEFINED -> NextcloudTalkApplication.sharedApplication?.resources!!.getString(
|
||||
R.string.nc_not_defined_error
|
||||
)
|
||||
ErrorStatus.UNAUTHORIZED -> NextcloudTalkApplication.sharedApplication?.resources!!
|
||||
.getString(R.string.nc_unauthorized_error)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,12 +23,13 @@
|
||||
|
||||
package com.nextcloud.talk.newarch.data.source.remote
|
||||
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication
|
||||
import com.nextcloud.talk.newarch.data.model.ErrorModel
|
||||
import okhttp3.ResponseBody
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
import java.net.SocketTimeoutException
|
||||
import java.net.UnknownHostException
|
||||
|
||||
/**
|
||||
* This class trace exceptions(api call or parse data or connection errors) &
|
||||
@ -62,7 +63,9 @@ class ApiErrorHandler {
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
return errorModel ?: ErrorModel("No Defined Error!", 0, ErrorModel.ErrorStatus.BAD_RESPONSE)
|
||||
return errorModel ?: ErrorModel(
|
||||
NextcloudTalkApplication.sharedApplication?.resources!!.getString(R.string.nc_not_defined_error), 0, ErrorModel.ErrorStatus.BAD_RESPONSE
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -191,7 +191,7 @@ class ConversationsListView : BaseView(), OnQueryTextListener,
|
||||
LOADED -> {
|
||||
view?.loadingStateView?.visibility = View.GONE
|
||||
view?.stateWithMessageView?.visibility = View.GONE
|
||||
view!!.dataStateView.visibility = View.VISIBLE
|
||||
view?.dataStateView?.visibility = View.VISIBLE
|
||||
view?.floatingActionButton?.visibility = View.GONE
|
||||
searchItem?.isVisible = true
|
||||
}
|
||||
@ -207,7 +207,8 @@ class ConversationsListView : BaseView(), OnQueryTextListener,
|
||||
R.drawable.ic_announcement_white_24dp
|
||||
)
|
||||
} else {
|
||||
view?.stateWithMessageView?.errorStateTextView?.text = resources?.getText(R.string.nc_conversations_empty)
|
||||
view?.stateWithMessageView?.errorStateTextView?.text =
|
||||
resources?.getText(R.string.nc_conversations_empty)
|
||||
view?.stateWithMessageView?.errorStateImageView?.setImageResource(R.drawable.ic_logo)
|
||||
}
|
||||
|
||||
@ -255,8 +256,10 @@ class ConversationsListView : BaseView(), OnQueryTextListener,
|
||||
dataSource.subscribe(object : BaseBitmapDataSubscriber() {
|
||||
override fun onNewResultImpl(bitmap: Bitmap?) {
|
||||
if (bitmap != null && resources != null) {
|
||||
val roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(resources as Resources,
|
||||
bitmap)
|
||||
val roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(
|
||||
resources as Resources,
|
||||
bitmap
|
||||
)
|
||||
roundedBitmapDrawable.isCircular = true
|
||||
roundedBitmapDrawable.setAntiAlias(true)
|
||||
menuItem.icon = roundedBitmapDrawable
|
||||
|
@ -21,6 +21,7 @@
|
||||
package com.nextcloud.talk.newarch.features.conversationsList
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.nextcloud.talk.models.database.UserEntity
|
||||
import com.nextcloud.talk.models.json.conversations.Conversation
|
||||
import com.nextcloud.talk.newarch.conversationsList.mvp.BaseViewModel
|
||||
@ -42,20 +43,22 @@ class ConversationsListViewModel constructor(
|
||||
|
||||
val conversationsListData = MutableLiveData<List<Conversation>>()
|
||||
val viewState = MutableLiveData<ViewState>(LOADING)
|
||||
var messageData : String? = null
|
||||
var messageData: String? = null
|
||||
val searchQuery = MutableLiveData<String>()
|
||||
var currentUser: UserEntity = userUtils.currentUser
|
||||
|
||||
fun loadConversations() {
|
||||
currentUser = userUtils.currentUser
|
||||
|
||||
if (!conversationsUseCase.isUserInitialized() || conversationsUseCase.user != currentUser) {
|
||||
if (viewState.value?.equals(FAILED)!! || !conversationsUseCase.isUserInitialized() ||
|
||||
conversationsUseCase.user != currentUser
|
||||
) {
|
||||
conversationsUseCase.user = currentUser
|
||||
viewState.value = LOADING
|
||||
}
|
||||
|
||||
conversationsUseCase.invoke(
|
||||
backgroundAndUIScope, null, object : UseCaseResponse<List<Conversation>> {
|
||||
viewModelScope, null, object : UseCaseResponse<List<Conversation>> {
|
||||
override fun onSuccess(result: List<Conversation>) {
|
||||
val newConversations = result.toMutableList()
|
||||
|
||||
@ -68,7 +71,7 @@ class ConversationsListViewModel constructor(
|
||||
|
||||
conversationsListData.value = newConversations
|
||||
viewState.value = if (newConversations.isNotEmpty()) LOADED else LOADED_EMPTY
|
||||
|
||||
messageData = ""
|
||||
}
|
||||
|
||||
override fun onError(errorModel: ErrorModel?) {
|
||||
|
@ -298,4 +298,13 @@
|
||||
<string name="nc_lobby_waiting_with_date">You are currently waiting in the lobby.\n This
|
||||
meeting is scheduled for %1$s.</string>
|
||||
<string name="nc_manual">Not set</string>
|
||||
|
||||
<!-- Errors -->
|
||||
<string name="nc_no_connection_error">No connection</string>
|
||||
<string name="nc_bad_response_error">Bad response</string>
|
||||
<string name="nc_timeout_error">Timeout</string>
|
||||
<string name="nc_empty_response_error">Empty response</string>
|
||||
<string name="nc_not_defined_error">Unknown error</string>
|
||||
<string name="nc_unauthorized_error">No Unauthorized</string>
|
||||
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user