ui: Replace ErrorMessages getter with indexing operator

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-03-27 15:16:30 +05:30
parent b9fd3d37f2
commit 536a6f3f83
8 changed files with 12 additions and 12 deletions

View File

@ -185,7 +185,7 @@ class LogViewerActivity : AppCompatActivity() {
saveButton?.isEnabled = true
Snackbar.make(findViewById(android.R.id.content),
if (exception == null) getString(R.string.log_export_success, outputFile?.fileName)
else getString(R.string.log_export_error, ErrorMessages.get(exception)),
else getString(R.string.log_export_error, ErrorMessages[exception]),
if (exception == null) Snackbar.LENGTH_SHORT else Snackbar.LENGTH_LONG)
.setAnchorView(binding.shareFab)
.show()

View File

@ -32,7 +32,7 @@ class TunnelToggleActivity : AppCompatActivity() {
private fun onToggleFinished(throwable: Throwable?) {
if (throwable == null) return
val error = ErrorMessages.get(throwable)
val error = ErrorMessages[throwable]
val message = getString(R.string.toggle_error, error)
Log.e(TAG, message, throwable)
Toast.makeText(this, message, Toast.LENGTH_LONG).show()

View File

@ -42,7 +42,7 @@ class AppListDialogFragment : DialogFragment() {
appData.clear()
appData.addAll(data)
} else {
val error = ErrorMessages.get(throwable)
val error = ErrorMessages[throwable]
val message = activity.getString(R.string.error_fetching_apps, error)
Toast.makeText(activity, message, Toast.LENGTH_LONG).show()
dismissAllowingStateLoss()

View File

@ -87,7 +87,7 @@ abstract class BaseFragment : Fragment(), OnSelectedTunnelChangedListener {
private fun setTunnelStateWithPermissionsResult(tunnel: ObservableTunnel, checked: Boolean) {
tunnel.setStateAsync(Tunnel.State.of(checked)).whenComplete { _, throwable ->
if (throwable == null) return@whenComplete
val error = ErrorMessages.get(throwable)
val error = ErrorMessages[throwable]
val messageResId = if (checked) R.string.error_up else R.string.error_down
val message = requireContext().getString(messageResId, error)
val view = view

View File

@ -46,7 +46,7 @@ class TunnelEditorFragment : BaseFragment(), AppExclusionListener {
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
onFinished()
} else {
val error = ErrorMessages.get(throwable)
val error = ErrorMessages[throwable]
message = getString(R.string.config_save_error, savedTunnel.name, error)
Log.e(TAG, message, throwable)
binding?.let {
@ -114,7 +114,7 @@ class TunnelEditorFragment : BaseFragment(), AppExclusionListener {
val newConfig = try {
binding!!.config!!.resolve()
} catch (e: Exception) {
val error = ErrorMessages.get(e)
val error = ErrorMessages[e]
val tunnelName = if (tunnel == null) binding!!.name else tunnel!!.name
val message = getString(R.string.config_save_error, tunnelName, error)
Log.e(TAG, message, e)
@ -179,7 +179,7 @@ class TunnelEditorFragment : BaseFragment(), AppExclusionListener {
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
onFinished()
} else {
val error = ErrorMessages.get(throwable)
val error = ErrorMessages[throwable]
message = getString(R.string.tunnel_create_error, error)
Log.e(TAG, message, throwable)
binding?.let {
@ -198,7 +198,7 @@ class TunnelEditorFragment : BaseFragment(), AppExclusionListener {
Log.d(TAG, "Attempting to save config of renamed tunnel " + tunnel!!.name)
renamedTunnel.setConfigAsync(newConfig).whenComplete { _, t -> onConfigSaved(renamedTunnel, t) }
} else {
val error = ErrorMessages.get(throwable)
val error = ErrorMessages[throwable]
message = getString(R.string.tunnel_rename_error, error)
Log.e(TAG, message, throwable)
binding?.let {

View File

@ -235,7 +235,7 @@ class TunnelListFragment : BaseFragment() {
if (throwable == null) {
message = resources.getQuantityString(R.plurals.delete_success, count, count)
} else {
val error = ErrorMessages.get(throwable)
val error = ErrorMessages[throwable]
message = resources.getQuantityString(R.plurals.delete_error, count, count, error)
Log.e(TAG, message, throwable)
}
@ -245,7 +245,7 @@ class TunnelListFragment : BaseFragment() {
private fun onTunnelImportFinished(tunnels: List<ObservableTunnel>, throwables: Collection<Throwable>) {
var message = ""
for (throwable in throwables) {
val error = ErrorMessages.get(throwable)
val error = ErrorMessages[throwable]
message = getString(R.string.import_error, error)
Log.e(TAG, message, throwable)
}

View File

@ -34,7 +34,7 @@ class ModuleDownloaderPreference(context: Context, attrs: AttributeSet?) : Prefe
when {
throwable != null -> {
setState(State.FAILURE)
Toast.makeText(context, ErrorMessages.get(throwable), Toast.LENGTH_LONG).show()
Toast.makeText(context, ErrorMessages[throwable], Toast.LENGTH_LONG).show()
}
result == OsConstants.ENOENT -> setState(State.NOTFOUND)
result == OsConstants.EXIT_SUCCESS -> {

View File

@ -63,7 +63,7 @@ class ZipExporterPreference(context: Context, attrs: AttributeSet?) : Preference
private fun exportZipComplete(filePath: String?, throwable: Throwable?) {
if (throwable != null) {
val error = ErrorMessages.get(throwable)
val error = ErrorMessages[throwable]
val message = context.getString(R.string.zip_export_error, error)
Log.e(TAG, message, throwable)
Snackbar.make(