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);
+ public void save_transaction() {
+ mSave.setVisible(false);
toggle_all_editing(false);
progress.setVisibility(View.VISIBLE);
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();
+ mSave.setVisible(true);
+ } else {
+ 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);
}
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
- <android.support.design.widget.FloatingActionButton
- android:id="@+id/fab"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:padding="@dimen/fab_margin"
- android:tint="@android:color/white"
- android:visibility="visible"
- app:backgroundTint="@color/colorPrimary"
- app:layout_constraintBottom_toBottomOf="@id/save_transaction_progress"
- app:layout_constraintEnd_toEndOf="@id/save_transaction_progress"
- app:layout_constraintStart_toStartOf="@id/save_transaction_progress"
- app:layout_constraintTop_toTopOf="@id/save_transaction_progress"
- app:srcCompat="@drawable/ic_save_white_24dp" />
-
</android.support.constraint.ConstraintLayout>
</android.support.design.widget.CoordinatorLayout>
\ No newline at end of file
android:id="@+id/transaction_details"
android:layout_width="match_parent"
android:layout_height="0dp"
- android:layout_marginBottom="8dp"
- app:layout_constraintBottom_toTopOf="@+id/constraintLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
+ android:autofillHints=""
android:ems="10"
android:hint="@string/new_transaction_description_hint"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_weight="30"
app:layout_constraintStart_toEndOf="@+id/new_transaction_date"
- app:layout_constraintTop_toTopOf="parent"
- android:autofillHints="" />
+ app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<TableLayout
</LinearLayout>
</ScrollView>
- <android.support.constraint.ConstraintLayout
- android:id="@+id/constraintLayout"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginBottom="8dp"
- android:visibility="gone"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent">
-
- <ProgressBar
- android:id="@+id/progressBar3"
- style="?android:attr/progressBarStyle"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
-
- <TextView
- android:id="@+id/textView3"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_marginStart="8dp"
- android:layout_marginTop="8dp"
- android:layout_marginEnd="8dp"
- android:layout_marginBottom="8dp"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintHorizontal_bias="0.0"
- app:layout_constraintStart_toEndOf="@+id/progressBar3"
- app:layout_constraintTop_toTopOf="parent"
- app:layout_constraintVertical_bias="0.615" />
- </android.support.constraint.ConstraintLayout>
-
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
+ <item
+ android:id="@+id/action_submit_transaction"
+ android:icon="@drawable/ic_save_white_24dp"
+ android:onClick="saveTransactionFromMenu"
+ android:title="@string/action_submit_transaction_title"
+ android:visible="false"
+ app:showAsAction="always" />
<item
android:id="@+id/action_add_account"
android:icon="@drawable/svg_thick_plus_white"
android:onClick="addTransactionAccountFromMenu"
android:orderInCategory="100"
android:title="@string/menu_add_account"
+ android:visible="false"
app:showAsAction="never|ifRoom" />
-</menu>
\ No newline at end of file
+ </menu>
\ No newline at end of file
<string name="progress_connecting">Свързване…</string>
<string name="new_transaction_description_hint">Описание</string>
<string name="progress_N_accounts_loaded">Заредени са %d сметки</string>
+ <string name="action_submit_transaction_title">Запазване</string>
</resources>
\ No newline at end of file
<string name="progress_connecting">Connecting…</string>
<string name="progress_N_accounts_loaded">%d accounts loaded</string>
<string name="new_transaction_description_hint">Description</string>
+ <string name="action_submit_transaction_title">Save</string>
</resources>