mirror of
https://github.com/videolan/vlc-android
synced 2024-11-23 18:05:36 +08:00
OpenSubtitles: fix crash when logging in without connection
This commit is contained in:
parent
750bad3d64
commit
8b35f89743
@ -300,18 +300,38 @@ class SubtitlesModel(context: Context, private val mediaUri: Uri, private val na
|
|||||||
fun login(settings: SharedPreferences, username: String, password: String) {
|
fun login(settings: SharedPreferences, username: String, password: String) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val call = OpenSubtitleRepository.getInstance().login(username, password)
|
try {
|
||||||
if (call.isSuccessful) {
|
val call = OpenSubtitleRepository.getInstance().login(username, password)
|
||||||
val userResult = call.body()
|
if (call.isSuccessful) {
|
||||||
if (userResult != null) {
|
val userResult = call.body()
|
||||||
val openSubtitlesUser = OpenSubtitlesUser(true, userResult, username = username)
|
if (userResult != null) {
|
||||||
OpenSubtitlesUtils.saveUser(settings, openSubtitlesUser)
|
val openSubtitlesUser =
|
||||||
observableUser.set(openSubtitlesUser)
|
OpenSubtitlesUser(true, userResult, username = username)
|
||||||
checkUserInfos(settings)
|
OpenSubtitlesUtils.saveUser(settings, openSubtitlesUser)
|
||||||
return@withContext
|
observableUser.set(openSubtitlesUser)
|
||||||
|
checkUserInfos(settings)
|
||||||
|
return@withContext
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
observableUser.set(
|
||||||
|
OpenSubtitlesUser(
|
||||||
|
false,
|
||||||
|
null,
|
||||||
|
errorMessage = if (call.code() == 401) getContext().getString(R.string.login_error) else getContext().getString(
|
||||||
|
R.string.unknown_error
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} catch (e: NoConnectivityException) {
|
||||||
|
observableUser.set(
|
||||||
|
OpenSubtitlesUser(
|
||||||
|
false,
|
||||||
|
null,
|
||||||
|
errorMessage = getContext().getString(R.string.no_internet_connection)
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
observableUser.set(OpenSubtitlesUser(false, null, errorMessage = if (call.code() == 401) getContext().getString(R.string.login_error) else getContext().getString(R.string.unknown_error)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user