ui: Replace ErrorMessages getter with indexing operator
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
b9fd3d37f2
commit
536a6f3f83
@ -185,7 +185,7 @@ class LogViewerActivity : AppCompatActivity() {
|
|||||||
saveButton?.isEnabled = true
|
saveButton?.isEnabled = true
|
||||||
Snackbar.make(findViewById(android.R.id.content),
|
Snackbar.make(findViewById(android.R.id.content),
|
||||||
if (exception == null) getString(R.string.log_export_success, outputFile?.fileName)
|
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)
|
if (exception == null) Snackbar.LENGTH_SHORT else Snackbar.LENGTH_LONG)
|
||||||
.setAnchorView(binding.shareFab)
|
.setAnchorView(binding.shareFab)
|
||||||
.show()
|
.show()
|
||||||
|
@ -32,7 +32,7 @@ class TunnelToggleActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private fun onToggleFinished(throwable: Throwable?) {
|
private fun onToggleFinished(throwable: Throwable?) {
|
||||||
if (throwable == null) return
|
if (throwable == null) return
|
||||||
val error = ErrorMessages.get(throwable)
|
val error = ErrorMessages[throwable]
|
||||||
val message = getString(R.string.toggle_error, error)
|
val message = getString(R.string.toggle_error, error)
|
||||||
Log.e(TAG, message, throwable)
|
Log.e(TAG, message, throwable)
|
||||||
Toast.makeText(this, message, Toast.LENGTH_LONG).show()
|
Toast.makeText(this, message, Toast.LENGTH_LONG).show()
|
||||||
|
@ -42,7 +42,7 @@ class AppListDialogFragment : DialogFragment() {
|
|||||||
appData.clear()
|
appData.clear()
|
||||||
appData.addAll(data)
|
appData.addAll(data)
|
||||||
} else {
|
} else {
|
||||||
val error = ErrorMessages.get(throwable)
|
val error = ErrorMessages[throwable]
|
||||||
val message = activity.getString(R.string.error_fetching_apps, error)
|
val message = activity.getString(R.string.error_fetching_apps, error)
|
||||||
Toast.makeText(activity, message, Toast.LENGTH_LONG).show()
|
Toast.makeText(activity, message, Toast.LENGTH_LONG).show()
|
||||||
dismissAllowingStateLoss()
|
dismissAllowingStateLoss()
|
||||||
|
@ -87,7 +87,7 @@ abstract class BaseFragment : Fragment(), OnSelectedTunnelChangedListener {
|
|||||||
private fun setTunnelStateWithPermissionsResult(tunnel: ObservableTunnel, checked: Boolean) {
|
private fun setTunnelStateWithPermissionsResult(tunnel: ObservableTunnel, checked: Boolean) {
|
||||||
tunnel.setStateAsync(Tunnel.State.of(checked)).whenComplete { _, throwable ->
|
tunnel.setStateAsync(Tunnel.State.of(checked)).whenComplete { _, throwable ->
|
||||||
if (throwable == null) return@whenComplete
|
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 messageResId = if (checked) R.string.error_up else R.string.error_down
|
||||||
val message = requireContext().getString(messageResId, error)
|
val message = requireContext().getString(messageResId, error)
|
||||||
val view = view
|
val view = view
|
||||||
|
@ -46,7 +46,7 @@ class TunnelEditorFragment : BaseFragment(), AppExclusionListener {
|
|||||||
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
|
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
|
||||||
onFinished()
|
onFinished()
|
||||||
} else {
|
} else {
|
||||||
val error = ErrorMessages.get(throwable)
|
val error = ErrorMessages[throwable]
|
||||||
message = getString(R.string.config_save_error, savedTunnel.name, error)
|
message = getString(R.string.config_save_error, savedTunnel.name, error)
|
||||||
Log.e(TAG, message, throwable)
|
Log.e(TAG, message, throwable)
|
||||||
binding?.let {
|
binding?.let {
|
||||||
@ -114,7 +114,7 @@ class TunnelEditorFragment : BaseFragment(), AppExclusionListener {
|
|||||||
val newConfig = try {
|
val newConfig = try {
|
||||||
binding!!.config!!.resolve()
|
binding!!.config!!.resolve()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
val error = ErrorMessages.get(e)
|
val error = ErrorMessages[e]
|
||||||
val tunnelName = if (tunnel == null) binding!!.name else tunnel!!.name
|
val tunnelName = if (tunnel == null) binding!!.name else tunnel!!.name
|
||||||
val message = getString(R.string.config_save_error, tunnelName, error)
|
val message = getString(R.string.config_save_error, tunnelName, error)
|
||||||
Log.e(TAG, message, e)
|
Log.e(TAG, message, e)
|
||||||
@ -179,7 +179,7 @@ class TunnelEditorFragment : BaseFragment(), AppExclusionListener {
|
|||||||
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
|
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
|
||||||
onFinished()
|
onFinished()
|
||||||
} else {
|
} else {
|
||||||
val error = ErrorMessages.get(throwable)
|
val error = ErrorMessages[throwable]
|
||||||
message = getString(R.string.tunnel_create_error, error)
|
message = getString(R.string.tunnel_create_error, error)
|
||||||
Log.e(TAG, message, throwable)
|
Log.e(TAG, message, throwable)
|
||||||
binding?.let {
|
binding?.let {
|
||||||
@ -198,7 +198,7 @@ class TunnelEditorFragment : BaseFragment(), AppExclusionListener {
|
|||||||
Log.d(TAG, "Attempting to save config of renamed tunnel " + tunnel!!.name)
|
Log.d(TAG, "Attempting to save config of renamed tunnel " + tunnel!!.name)
|
||||||
renamedTunnel.setConfigAsync(newConfig).whenComplete { _, t -> onConfigSaved(renamedTunnel, t) }
|
renamedTunnel.setConfigAsync(newConfig).whenComplete { _, t -> onConfigSaved(renamedTunnel, t) }
|
||||||
} else {
|
} else {
|
||||||
val error = ErrorMessages.get(throwable)
|
val error = ErrorMessages[throwable]
|
||||||
message = getString(R.string.tunnel_rename_error, error)
|
message = getString(R.string.tunnel_rename_error, error)
|
||||||
Log.e(TAG, message, throwable)
|
Log.e(TAG, message, throwable)
|
||||||
binding?.let {
|
binding?.let {
|
||||||
|
@ -235,7 +235,7 @@ class TunnelListFragment : BaseFragment() {
|
|||||||
if (throwable == null) {
|
if (throwable == null) {
|
||||||
message = resources.getQuantityString(R.plurals.delete_success, count, count)
|
message = resources.getQuantityString(R.plurals.delete_success, count, count)
|
||||||
} else {
|
} else {
|
||||||
val error = ErrorMessages.get(throwable)
|
val error = ErrorMessages[throwable]
|
||||||
message = resources.getQuantityString(R.plurals.delete_error, count, count, error)
|
message = resources.getQuantityString(R.plurals.delete_error, count, count, error)
|
||||||
Log.e(TAG, message, throwable)
|
Log.e(TAG, message, throwable)
|
||||||
}
|
}
|
||||||
@ -245,7 +245,7 @@ class TunnelListFragment : BaseFragment() {
|
|||||||
private fun onTunnelImportFinished(tunnels: List<ObservableTunnel>, throwables: Collection<Throwable>) {
|
private fun onTunnelImportFinished(tunnels: List<ObservableTunnel>, throwables: Collection<Throwable>) {
|
||||||
var message = ""
|
var message = ""
|
||||||
for (throwable in throwables) {
|
for (throwable in throwables) {
|
||||||
val error = ErrorMessages.get(throwable)
|
val error = ErrorMessages[throwable]
|
||||||
message = getString(R.string.import_error, error)
|
message = getString(R.string.import_error, error)
|
||||||
Log.e(TAG, message, throwable)
|
Log.e(TAG, message, throwable)
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class ModuleDownloaderPreference(context: Context, attrs: AttributeSet?) : Prefe
|
|||||||
when {
|
when {
|
||||||
throwable != null -> {
|
throwable != null -> {
|
||||||
setState(State.FAILURE)
|
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.ENOENT -> setState(State.NOTFOUND)
|
||||||
result == OsConstants.EXIT_SUCCESS -> {
|
result == OsConstants.EXIT_SUCCESS -> {
|
||||||
|
@ -63,7 +63,7 @@ class ZipExporterPreference(context: Context, attrs: AttributeSet?) : Preference
|
|||||||
|
|
||||||
private fun exportZipComplete(filePath: String?, throwable: Throwable?) {
|
private fun exportZipComplete(filePath: String?, throwable: Throwable?) {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
val error = ErrorMessages.get(throwable)
|
val error = ErrorMessages[throwable]
|
||||||
val message = context.getString(R.string.zip_export_error, error)
|
val message = context.getString(R.string.zip_export_error, error)
|
||||||
Log.e(TAG, message, throwable)
|
Log.e(TAG, message, throwable)
|
||||||
Snackbar.make(
|
Snackbar.make(
|
||||||
|
Loading…
Reference in New Issue
Block a user