import net.ktnx.mobileledger.model.LedgerTransactionAccount;
import net.ktnx.mobileledger.model.MobileLedgerProfile;
import net.ktnx.mobileledger.utils.Globals;
+import net.ktnx.mobileledger.utils.Logger;
import net.ktnx.mobileledger.utils.NetworkUtil;
import net.ktnx.mobileledger.utils.UrlEncodedFormData;
private String session;
private LedgerTransaction ltr;
private MobileLedgerProfile mProfile;
+ private boolean simulate = false;
+ public SendTransactionTask(TaskCallback callback, MobileLedgerProfile profile,
+ boolean simulate) {
+ taskCallback = callback;
+ mProfile = profile;
+ this.simulate = simulate;
+ }
public SendTransactionTask(TaskCallback callback, MobileLedgerProfile profile) {
taskCallback = callback;
mProfile = profile;
+ simulate = false;
}
private boolean sendOK() throws IOException {
-// if (BuildConfig.DEBUG) {
-// try {
-// Thread.sleep(1500);
-// if (Math.random() > 0.3)
-// throw new RuntimeException("Simulated test exception");
-// }
-// catch (InterruptedException ex) {
-// Logger.debug("network", ex.toString());
-// }
-//
-// return true;
-// }
+ if (simulate) {
+ try {
+ Thread.sleep(1500);
+ if (Math.random() > 0.3)
+ throw new RuntimeException("Simulated test exception");
+ }
+ catch (InterruptedException ex) {
+ Logger.debug("network", ex.toString());
+ }
+
+ return true;
+ }
HttpURLConnection http = NetworkUtil.prepareConnection(mProfile, "add");
http.setRequestMethod("PUT");
import android.view.MenuItem;
import androidx.appcompat.widget.Toolbar;
+import androidx.lifecycle.ViewModelProviders;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
public class NewTransactionActivity extends ProfileThemedActivity implements TaskCallback,
NewTransactionFragment.OnNewTransactionFragmentInteractionListener {
private NavController navController;
+ private NewTransactionModel model;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Objects.requireNonNull(getSupportActionBar())
.setDisplayHomeAsUpEnabled(true);
+
+ model = ViewModelProviders.of(this)
+ .get(NewTransactionModel.class);
}
@Override
protected void initProfile() {
navController.navigate(R.id.action_newTransactionFragment_to_newTransactionSavingFragment);
try {
- SendTransactionTask saver = new SendTransactionTask(this, mProfile);
+ SendTransactionTask saver =
+ new SendTransactionTask(this, mProfile, model.getSimulateSave());
saver.execute(tr);
}
catch (Exception e) {
if (BuildConfig.DEBUG) {
menu.findItem(R.id.action_simulate_crash)
.setVisible(true);
+ menu.findItem(R.id.action_simulate_save)
+ .setVisible(true);
}
+ model.observeSimulateSave(this, state -> menu.findItem(R.id.action_simulate_save)
+ .setChecked(state));
+
return true;
}
else
navController.navigate(R.id.action_newTransactionSavingFragment_Success, b);
}
+ public void toggleSimulateSave(MenuItem item) {
+ model.toggleSimulateSave();
+ }
private class AsyncCrasher extends AsyncTask<Void, Void, Void> {
@Override
private final MutableLiveData<Boolean> isSubmittable = new MutableLiveData<>(false);
private final MutableLiveData<Integer> focusedItem = new MutableLiveData<>(0);
private final MutableLiveData<Integer> accountCount = new MutableLiveData<>(0);
+ private final MutableLiveData<Boolean> simulateSave = new MutableLiveData<>(false);
+ public boolean getSimulateSave() {
+ return simulateSave.getValue();
+ }
+ public void setSimulateSave(boolean simulateSave) {
+ this.simulateSave.setValue(simulateSave);
+ }
+ public void toggleSimulateSave() {
+ simulateSave.setValue(!simulateSave.getValue());
+ }
+ public void observeSimulateSave(@NonNull @NotNull androidx.lifecycle.LifecycleOwner owner,
+ @NonNull
+ androidx.lifecycle.Observer<? super Boolean> observer) {
+ this.simulateSave.observe(owner, observer);
+ }
public int getAccountCount() {
return items.size();
}
android:onClick="simulateCrash"
android:visible="false"
app:showAsAction="never" />
+ <item
+ android:id="@+id/action_simulate_save"
+ android:checkable="true"
+ android:checked="false"
+ android:onClick="toggleSimulateSave"
+ android:title="@string/simulate_save_label"
+ android:titleCondensed="@string/simulate_save_condensed_label"
+ android:visible="false"
+ app:showAsAction="never" />
</menu>
\ No newline at end of file
<string name="insecure_scheme_with_auth">ВНИМАНИЕ: Използване на удостоверяване с несигурна схема на достъп</string>
<string name="zero_amount">0,00</string>
<string name="new_transaction_saving">Запазване…</string>
+ <string name="simulate_save_label">Симулиране на заявките за съхраняване</string>
+ <string name="simulate_save_condensed_label">Симул. съхр.</string>
</resources>
<string name="insecure_scheme_with_auth">WARNING: Insecure http used with authentication</string>
<string name="zero_amount">0.00</string>
<string name="new_transaction_saving">Saving…</string>
+ <string name="simulate_save_label">Simulate save requests</string>
+ <string name="simulate_save_condensed_label">Simul. save</string>
</resources>