From: Damyan Ivanov Date: Mon, 28 Dec 2020 11:24:58 +0000 (+0200) Subject: detect and report API errors when saving new transactions X-Git-Tag: v0.16.0~10 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=db56efb04c4a1c260676e743481b8f67b36e60ed;p=mobile-ledger.git detect and report API errors when saving new transactions --- diff --git a/app/src/main/java/net/ktnx/mobileledger/async/SendTransactionTask.java b/app/src/main/java/net/ktnx/mobileledger/async/SendTransactionTask.java index 14d41f9f..dbe4bc88 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/SendTransactionTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/SendTransactionTask.java @@ -21,6 +21,7 @@ import android.os.AsyncTask; import android.util.Log; import net.ktnx.mobileledger.json.API; +import net.ktnx.mobileledger.json.ApiNotSupportedException; import net.ktnx.mobileledger.json.Gateway; import net.ktnx.mobileledger.model.LedgerTransaction; import net.ktnx.mobileledger.model.LedgerTransactionAccount; @@ -73,7 +74,7 @@ public class SendTransactionTask extends AsyncTask startEditProfileActivity(null)); + v -> MobileLedgerProfile.startEditProfileActivity(this, null)); findViewById(R.id.btn_add_transaction).setOnClickListener(this::fabNewTransactionClicked); findViewById(R.id.nav_new_profile_button).setOnClickListener( - v -> startEditProfileActivity(null)); + v -> MobileLedgerProfile.startEditProfileActivity(this, null)); findViewById(R.id.transaction_list_cancel_download).setOnClickListener( this::onStopTransactionRefreshClick); @@ -471,17 +470,6 @@ public class MainActivity extends ProfileThemedActivity { recreate(); } - public void startEditProfileActivity(MobileLedgerProfile profile) { - Intent intent = new Intent(this, ProfileDetailActivity.class); - Bundle args = new Bundle(); - if (profile != null) { - int index = Data.getProfileIndex(profile); - if (index != -1) - intent.putExtra(ProfileDetailFragment.ARG_ITEM_ID, index); - } - intent.putExtras(args); - startActivity(intent, args); - } public void fabNewTransactionClicked(View view) { Intent intent = new Intent(this, NewTransactionActivity.class); startActivity(intent); @@ -630,7 +618,7 @@ public class MainActivity extends ProfileThemedActivity { builder.setMessage(error); builder.setPositiveButton(R.string.btn_profile_options, (dialog, which) -> { Logger.debug("error", "will start profile editor"); - startEditProfileActivity(profile); + MobileLedgerProfile.startEditProfileActivity(this, profile); }); builder.create() .show(); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java index e705d1c1..d8271db4 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java @@ -18,6 +18,7 @@ package net.ktnx.mobileledger.ui.activity; import android.content.Context; +import android.content.res.Resources; import android.os.Bundle; import android.renderscript.RSInvalidStateException; import android.view.LayoutInflater; @@ -30,6 +31,7 @@ import android.widget.ProgressBar; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import androidx.lifecycle.ViewModelProvider; @@ -40,6 +42,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.snackbar.Snackbar; import net.ktnx.mobileledger.R; +import net.ktnx.mobileledger.json.API; import net.ktnx.mobileledger.model.Data; import net.ktnx.mobileledger.model.LedgerTransaction; import net.ktnx.mobileledger.model.LedgerTransactionAccount; @@ -152,8 +155,34 @@ public class NewTransactionFragment extends Fragment { String error = args.getString("error"); if (error != null) { Logger.debug("new-trans-f", String.format("Got error: %s", error)); - Snackbar.make(list, error, Snackbar.LENGTH_LONG) - .show(); + + Context context = getContext(); + if (context != null) { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + final Resources resources = context.getResources(); + final StringBuilder message = new StringBuilder(); + message.append(resources.getString(R.string.err_json_send_error_head)); + message.append("\n\n"); + message.append(error); + if (mProfile.getApiVersion() + .equals(API.auto)) + message.append( + resources.getString(R.string.err_json_send_error_unsupported)); + else { + message.append(resources.getString(R.string.err_json_send_error_tail)); + builder.setPositiveButton(R.string.btn_profile_options, (dialog, which) -> { + Logger.debug("error", "will start profile editor"); + MobileLedgerProfile.startEditProfileActivity(context, mProfile); + }); + } + builder.setMessage(message); + builder.create() + .show(); + } + else { + Snackbar.make(list, error, Snackbar.LENGTH_LONG) + .show(); + } keep = true; } } diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index dbdbb991..d52c59ce 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -162,6 +162,8 @@ Знак плюс Версия 1.19.1 Версия на сървъра - Грешка при разчитане на отговора от сървъра. Вероятно настроената врсия на протокола е грешна. + Грешка при разчитане на отговора от сървъра. Вероятно настроената врсия на протокола не се поддържа. Настройка на профила + Грешка при изпращане на движението към сървъра + Вероятно настроената версия на протокола не се поддържа. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ea7d1548..63fb70e4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -174,4 +174,7 @@ Server version Error parsing packend JSON response. Perhaps the configured API version doesn\'t match Configure profile + Error storing transaction on backend server + A mismatch in the configured API version could be causing this + Perhaps the API of the backend server is not supported by MoLe