import android.database.sqlite.SQLiteDatabase;
import android.os.Build;
import android.os.Bundle;
-import android.os.Handler;
import android.preference.PreferenceManager;
import android.provider.FontsContract;
-import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AppCompatActivity;
public class NewTransactionActivity extends AppCompatActivity implements TaskCallback {
private TableLayout table;
- private FloatingActionButton fab;
- boolean fab_should_be_visible;
private ProgressBar progress;
private TextView text_date;
private TextView text_descr;
private static SaveTransactionTask saver;
- FloatingActionButton.OnVisibilityChangedListener fab_visibility_changed_listener = new FloatingActionButton.OnVisibilityChangedListener() {
- @Override
- public void onShown(FloatingActionButton fab) {
- Log.d("visuals", "FAB shown");
- super.onShown(fab);
- if (!fab_should_be_visible) fab.hide();
- }
-
- @Override
- public void onHidden(FloatingActionButton fab) {
- Log.d("visuals", "FAB hidden");
- fab.setImageResource(R.drawable.ic_save_white_24dp);
- fab.setEnabled(true);
-// super.onHidden(fab);
- if (fab_should_be_visible) fab.show();
- }
- };
-
- private void hide_fab() {
- hide_fab(false);
- }
-
- private void hide_fab(boolean force) {
- if (!fab_should_be_visible && !force) return;
-
- fab_should_be_visible = false;
- fab.hide(fab_visibility_changed_listener);
- }
-
- private void show_fab() {
- show_fab(false);
- }
-
- private void show_fab(boolean force) {
- if (fab_should_be_visible && !force) return;
-
- fab_should_be_visible = true;
- fab.show(fab_visibility_changed_listener);
- }
+ private MenuItem mSave;
@Override
protected void onCreate(Bundle savedInstanceState) {
text_descr.setAutofillHints("");
}
- fab = findViewById(R.id.fab);
- fab.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- new_transaction_save_clicked(view);
- }
- });
progress = findViewById(R.id.save_transaction_progress);
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
}
}
- public void new_transaction_save_clicked(View view) {
- fab.setEnabled(false);
+ @Override
+ public void finish() {
+ super.finish();
+ overridePendingTransition(R.anim.dummy, R.anim.slide_out_right);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ finish();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ public void save_transaction() {
+ if (mSave != null) mSave.setVisible(false);
+ toggle_all_editing(false);
progress.setVisibility(View.VISIBLE);
saver = new SaveTransactionTask(this);
}
saver.execute(tr);
}
+
+ private void toggle_all_editing(boolean enabled) {
+ TableLayout table = findViewById(R.id.new_transaction_accounts_table);
+ for (int i = 0; i < table.getChildCount(); i++) {
+ TableRow row = (TableRow) table.getChildAt(i);
+ for (int j = 0; j < row.getChildCount(); j++) {
+ row.getChildAt(j).setEnabled(enabled);
+ }
+ }
+ }
+
private void hook_swipe_listener(final TableRow row) {
row.getChildAt(0).setOnTouchListener(new OnSwipeTouchListener(this) {
public void onSwipeLeft() {
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.new_transaction, menu);
+ mSave = menu.findItem(R.id.action_submit_transaction);
+ assert mSave != null;
return true;
}
do_add_account_row(true);
}
+ public void saveTransactionFromMenu(MenuItem item) {
+ save_transaction();
+ }
+
private void check_transaction_submittable() {
TableLayout table = findViewById(R.id.new_transaction_accounts_table);
int accounts = 0;
}
if ((accounts >= 2) && (accounts_with_values >= (accounts - 1))) {
- show_fab();
- } else hide_fab();
+ if (mSave != null) mSave.setVisible(true);
+ } else {
+ if (mSave != null) mSave.setVisible(false);
+ }
}
@Override
public void done() {
- fab.setImageResource(R.drawable.ic_check_white_24dp);
progress.setVisibility(View.INVISIBLE);
Log.d("visuals", "hiding progress");
- fab_should_be_visible = false;
- final Handler fade_out = new Handler();
- fade_out.postDelayed(new Runnable() {
- @Override
- public void run() {
- Log.d("visuals", "hiding FAB");
-
- hide_fab(true);
- }
- }, 1000);
reset_form();
+ toggle_all_editing(true);
}
private void reset_form() {