X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FNewTransactionActivity.java;h=7499641741c4a09c19725fbcfac141bc67587492;hb=7ba876d1237f7ceb636035e0d6753195922c8b39;hp=660be19773891fa62c3cd85341719fef2e6752ff;hpb=2a016b0b3e56869059fa1831940c0cb96bdf3402;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionActivity.java index 660be197..74996417 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionActivity.java @@ -1,5 +1,5 @@ /* - * Copyright © 2019 Damyan Ivanov. + * Copyright © 2020 Damyan Ivanov. * This file is part of MoLe. * MoLe is free software: you can distribute it and/or modify it * under the term of the GNU General Public License as published by @@ -17,16 +17,16 @@ package net.ktnx.mobileledger.ui.activity; -import android.os.AsyncTask; import android.os.Bundle; import android.util.TypedValue; import android.view.Menu; import android.view.MenuItem; +import android.view.View; import androidx.appcompat.widget.Toolbar; -import androidx.lifecycle.ViewModelProviders; +import androidx.lifecycle.ViewModelProvider; import androidx.navigation.NavController; -import androidx.navigation.Navigation; +import androidx.navigation.fragment.NavHostFragment; import net.ktnx.mobileledger.BuildConfig; import net.ktnx.mobileledger.R; @@ -39,13 +39,6 @@ import java.util.Objects; import static net.ktnx.mobileledger.utils.Logger.debug; -/* - * TODO: nicer progress while transaction is submitted - * TODO: reports - * TODO: get rid of the custom session/cookie and auth code? - * (the last problem with the POST was the missing content-length header) - * */ - public class NewTransactionActivity extends ProfileThemedActivity implements TaskCallback, NewTransactionFragment.OnNewTransactionFragmentInteractionListener { private NavController navController; @@ -57,16 +50,17 @@ public class NewTransactionActivity extends ProfileThemedActivity implements Tas setContentView(R.layout.activity_new_transaction); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); - Data.profile.observe(this, + Data.observeProfile(this, mobileLedgerProfile -> toolbar.setSubtitle(mobileLedgerProfile.getName())); - navController = Navigation.findNavController(this, R.id.new_transaction_nav); + NavHostFragment navHostFragment = (NavHostFragment) Objects.requireNonNull( + getSupportFragmentManager().findFragmentById(R.id.new_transaction_nav)); + navController = navHostFragment.getNavController(); Objects.requireNonNull(getSupportActionBar()) .setDisplayHomeAsUpEnabled(true); - model = ViewModelProviders.of(this) - .get(NewTransactionModel.class); + model = new ViewModelProvider(this).get(NewTransactionModel.class); } @Override protected void initProfile() { @@ -94,12 +88,6 @@ public class NewTransactionActivity extends ProfileThemedActivity implements Tas } return super.onOptionsItemSelected(item); } - - @Override - protected void onStart() { - super.onStart(); - // FIXME if (tvDescription.getText().toString().isEmpty()) tvDescription.requestFocus(); - } public void onTransactionSave(LedgerTransaction tr) { navController.navigate(R.id.action_newTransactionFragment_to_newTransactionSavingFragment); try { @@ -131,8 +119,11 @@ public class NewTransactionActivity extends ProfileThemedActivity implements Tas .setVisible(true); } - model.observeSimulateSave(this, state -> menu.findItem(R.id.action_simulate_save) - .setChecked(state)); + model.observeSimulateSave(this, state -> { + menu.findItem(R.id.action_simulate_save) + .setChecked(state); + findViewById(R.id.simulationLabel).setVisibility(state ? View.VISIBLE : View.GONE); + }); return true; } @@ -156,11 +147,4 @@ public class NewTransactionActivity extends ProfileThemedActivity implements Tas model.toggleSimulateSave(); } - private class AsyncCrasher extends AsyncTask { - @Override - protected Void doInBackground(Void... voids) { - throw new RuntimeException("Simulated crash"); - } - } - }