Merge pull request #555 from vector-im/feature/room_search

Cleanup on the room search screen
This commit is contained in:
Benoit Marty 2019-09-17 15:28:54 +02:00 committed by GitHub
commit bf42b73713
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 32 additions and 5 deletions

View File

@ -11,7 +11,7 @@ Other changes:
-
Bugfix:
-
- Fix characters erased from the Search field when the result are coming (#545)
Translations:
-

View File

@ -31,6 +31,7 @@ import java.io.IOException
*/
sealed class Failure(cause: Throwable? = null) : Throwable(cause = cause) {
data class Unknown(val throwable: Throwable? = null) : Failure(throwable)
data class Cancelled(val throwable: Throwable? = null) : Failure(throwable)
data class NetworkConnection(val ioException: IOException? = null) : Failure(ioException)
data class ServerError(val error: MatrixError, val httpCode: Int) : Failure(RuntimeException(error.toString()))
// When server send an error, but it cannot be interpreted as a MatrixError

View File

@ -22,6 +22,7 @@ import im.vector.matrix.android.api.failure.ConsentNotGivenError
import im.vector.matrix.android.api.failure.Failure
import im.vector.matrix.android.api.failure.MatrixError
import im.vector.matrix.android.internal.di.MoshiProvider
import kotlinx.coroutines.CancellationException
import okhttp3.ResponseBody
import org.greenrobot.eventbus.EventBus
import retrofit2.Call
@ -49,6 +50,7 @@ internal class Request<DATA> {
is IOException -> Failure.NetworkConnection(exception)
is Failure.ServerError,
is Failure.OtherServerError -> exception
is CancellationException -> Failure.Cancelled(exception)
else -> Failure.Unknown(exception)
}
}

View File

@ -20,6 +20,7 @@ import im.vector.matrix.android.api.failure.Failure
import im.vector.matrix.android.api.failure.MatrixError
import im.vector.riotx.R
import im.vector.riotx.core.resources.StringProvider
import java.net.SocketTimeoutException
import javax.inject.Inject
class ErrorFormatter @Inject constructor(val stringProvider: StringProvider) {
@ -33,7 +34,13 @@ class ErrorFormatter @Inject constructor(val stringProvider: StringProvider) {
fun toHumanReadable(throwable: Throwable?): String {
return when (throwable) {
null -> null
is Failure.NetworkConnection -> stringProvider.getString(R.string.error_no_network)
is Failure.NetworkConnection -> {
if (throwable.ioException is SocketTimeoutException) {
stringProvider.getString(R.string.error_network_timeout)
} else {
stringProvider.getString(R.string.error_no_network)
}
}
is Failure.ServerError -> {
if (throwable.error.code == MatrixError.M_CONSENT_NOT_GIVEN) {
// Special case for terms and conditions

View File

@ -143,10 +143,15 @@ class PublicRoomsFragment : VectorBaseFragment(), PublicRoomsController.Callback
viewModel.loadMore()
}
var initialValueSet = false
override fun invalidate() = withState(viewModel) { state ->
if (publicRoomsFilter.query.toString() != state.currentFilter) {
// For initial filter
publicRoomsFilter.setQuery(state.currentFilter, false)
if (!initialValueSet) {
initialValueSet = true
if (publicRoomsFilter.query.toString() != state.currentFilter) {
// For initial filter
publicRoomsFilter.setQuery(state.currentFilter, false)
}
}
// Populate list with Epoxy

View File

@ -22,6 +22,7 @@ import com.airbnb.mvrx.*
import com.squareup.inject.assisted.Assisted
import com.squareup.inject.assisted.AssistedInject
import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.failure.Failure
import im.vector.matrix.android.api.session.Session
import im.vector.matrix.android.api.session.room.model.Membership
import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoom
@ -176,6 +177,11 @@ class RoomDirectoryViewModel @AssistedInject constructor(@Assisted initialState:
}
override fun onFailure(failure: Throwable) {
if (failure is Failure.Cancelled) {
// Ignore, another request should be already started
return
}
currentTask = null
setState {
@ -220,4 +226,9 @@ class RoomDirectoryViewModel @AssistedInject constructor(@Assisted initialState:
})
}
override fun onCleared() {
super.onCleared()
currentTask?.cancel()
}
}

View File

@ -11,5 +11,6 @@
<!-- This one is already defined in Riot, but not yet synced-->
<string name="error_user_already_logged_in">It looks like youre trying to connect to another homeserver. Do you want to sign out?</string>
<string name="error_network_timeout">Looks like the server is taking to long to respond, this can be caused by either poor connectivity or an error with our servers. Please try again in a while.</string>
</resources>