handle 426 upgrade required / handle 503 Service Unavailable (+maintenance mode)

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2023-06-06 12:36:58 +02:00
parent a58925da93
commit 7a30940142
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
2 changed files with 102 additions and 3 deletions

View File

@ -30,6 +30,7 @@ package com.nextcloud.talk.conversationlist
import android.animation.AnimatorInflater
import android.annotation.SuppressLint
import android.app.SearchManager
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
@ -562,7 +563,6 @@ class ConversationsListActivity :
}, { throwable: Throwable ->
handleHttpExceptions(throwable)
binding?.swipeRefreshLayoutView?.isRefreshing = false
showErrorDialog()
dispose(roomsQueryDisposable)
}) {
dispose(roomsQueryDisposable)
@ -627,7 +627,7 @@ class ConversationsListActivity :
}
private fun showErrorDialog() {
binding?.floatingActionButton?.let {
binding.floatingActionButton.let {
val dialogBuilder = MaterialAlertDialogBuilder(it.context)
.setIcon(
viewThemeUtils.dialog.colorMaterialAlertDialogIcon(
@ -639,6 +639,13 @@ class ConversationsListActivity :
.setCancelable(false)
.setNegativeButton(R.string.close, null)
if (resources!!.getBoolean(R.bool.multiaccount_support) && userManager.users.blockingGet().size > 1) {
dialogBuilder.setPositiveButton(R.string.nc_switch_account) { _, _ ->
val newFragment: DialogFragment = ChooseAccountDialogFragment.newInstance()
newFragment.show(supportFragmentManager, ChooseAccountDialogFragment.TAG)
}
}
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(it.context, dialogBuilder)
val dialog = dialogBuilder.show()
viewThemeUtils.platform.colorTextButtons(
@ -701,9 +708,11 @@ class ConversationsListActivity :
if (throwable is HttpException) {
when (throwable.code()) {
HTTP_UNAUTHORIZED -> showUnauthorizedDialog()
HTTP_CLIENT_UPGRADE_REQUIRED -> showOutdatedClientDialog()
HTTP_SERVICE_UNAVAILABLE -> showServiceUnavailableDialog(throwable)
else -> {
Log.e(TAG, "Http exception in ConversationListActivity", throwable)
Toast.makeText(context, R.string.nc_common_error_sorry, Toast.LENGTH_LONG).show()
showErrorDialog()
}
}
}
@ -1279,6 +1288,83 @@ class ConversationsListActivity :
}
}
private fun showOutdatedClientDialog() {
binding.floatingActionButton.let {
val dialogBuilder = MaterialAlertDialogBuilder(it.context)
.setIcon(
viewThemeUtils.dialog.colorMaterialAlertDialogIcon(
context,
R.drawable.ic_info_white_24dp
)
)
.setTitle(R.string.nc_dialog_outdated_client)
.setMessage(R.string.nc_dialog_outdated_client_description)
.setCancelable(false)
.setPositiveButton(R.string.nc_dialog_outdated_client_option_update) { _, _ ->
try {
startActivity(
Intent(Intent.ACTION_VIEW, Uri.parse(CLIENT_UPGRADE_MARKET_LINK + packageName))
)
} catch (e: ActivityNotFoundException) {
startActivity(
Intent(Intent.ACTION_VIEW, Uri.parse(CLIENT_UPGRADE_GPLAY_LINK + packageName))
)
}
}
if (resources!!.getBoolean(R.bool.multiaccount_support) && userManager.users.blockingGet().size > 1) {
dialogBuilder.setNegativeButton(R.string.nc_switch_account) { _, _ ->
val newFragment: DialogFragment = ChooseAccountDialogFragment.newInstance()
newFragment.show(supportFragmentManager, ChooseAccountDialogFragment.TAG)
}
}
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(it.context, dialogBuilder)
val dialog = dialogBuilder.show()
viewThemeUtils.platform.colorTextButtons(
dialog.getButton(AlertDialog.BUTTON_POSITIVE),
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
)
}
}
private fun showServiceUnavailableDialog(httpException: HttpException) {
if (httpException.response()?.headers()?.get(MAINTENANCE_MODE_HEADER_KEY) == "1") {
binding.floatingActionButton.let {
val dialogBuilder = MaterialAlertDialogBuilder(it.context)
.setIcon(
viewThemeUtils.dialog.colorMaterialAlertDialogIcon(
context,
R.drawable.ic_info_white_24dp
)
)
.setTitle(R.string.nc_dialog_maintenance_mode)
.setMessage(R.string.nc_dialog_maintenance_mode_description)
.setCancelable(false)
if (resources!!.getBoolean(R.bool.multiaccount_support) && userManager.users.blockingGet().size > 1) {
dialogBuilder.setPositiveButton(R.string.nc_switch_account) { _, _ ->
val newFragment: DialogFragment = ChooseAccountDialogFragment.newInstance()
newFragment.show(supportFragmentManager, ChooseAccountDialogFragment.TAG)
}
} else {
dialogBuilder.setPositiveButton(R.string.nc_close_app) { _, _ ->
finishAffinity()
finish()
}
}
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(it.context, dialogBuilder)
val dialog = dialogBuilder.show()
viewThemeUtils.platform.colorTextButtons(
dialog.getButton(AlertDialog.BUTTON_POSITIVE)
)
}
} else {
showErrorDialog()
}
}
private fun showServerEOLDialog() {
binding?.floatingActionButton?.let {
val dialogBuilder = MaterialAlertDialogBuilder(it.context)
@ -1378,5 +1464,10 @@ class ConversationsListActivity :
const val SEARCH_DEBOUNCE_INTERVAL_MS = 300
const val SEARCH_MIN_CHARS = 2
const val HTTP_UNAUTHORIZED = 401
const val HTTP_CLIENT_UPGRADE_REQUIRED = 426
const val CLIENT_UPGRADE_MARKET_LINK = "market://details?id="
const val CLIENT_UPGRADE_GPLAY_LINK = "https://play.google.com/store/apps/details?id="
const val HTTP_SERVICE_UNAVAILABLE = 503
const val MAINTENANCE_MODE_HEADER_KEY = "X-Nextcloud-Maintenance-Mode"
}
}

View File

@ -560,6 +560,14 @@ How to translate with transifex:
<string name="nc_dialog_invalid_password">Invalid password</string>
<string name="nc_dialog_reauth_or_delete">Do you want to reauthorize or delete this account?</string>
<string name="nc_dialog_outdated_client">App is outdated</string>
<string name="nc_dialog_outdated_client_description">The app is too old and no longer supported by this server. Please update.</string>
<string name="nc_dialog_outdated_client_option_update">Update</string>
<string name="nc_switch_account">Switch account</string>
<string name="nc_dialog_maintenance_mode">Maintenance mode</string>
<string name="nc_dialog_maintenance_mode_description">Server is currently in maintenance mode.</string>
<string name="nc_close_app">Close app</string>
<!-- Take photo -->
<string name="take_photo">Take a photo</string>
<string name="take_photo_switch_camera">Switch camera</string>