]> git.ktnx.net Git - mobile-ledger.git/commitdiff
start the new transaction interface
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 30 Nov 2018 17:44:02 +0000 (17:44 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 30 Nov 2018 17:44:02 +0000 (17:44 +0000)
app/src/main/java/net/ktnx/mobileledger/DatePickerFragment.java [new file with mode: 0644]
app/src/main/java/net/ktnx/mobileledger/LatestTransactions.java
app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java [new file with mode: 0644]
app/src/main/res/layout-v26/content_new_transaction.xml [new file with mode: 0644]
app/src/main/res/layout/activity_new_transaction.xml [new file with mode: 0644]
app/src/main/res/layout/app_bar_latest_transactions.xml
app/src/main/res/layout/content_new_transaction.xml [new file with mode: 0644]
app/src/main/res/values-v21/styles.xml [deleted file]
app/src/main/res/values/strings.xml
app/src/main/res/xml/backup_descriptor.xml [new file with mode: 0644]

diff --git a/app/src/main/java/net/ktnx/mobileledger/DatePickerFragment.java b/app/src/main/java/net/ktnx/mobileledger/DatePickerFragment.java
new file mode 100644 (file)
index 0000000..4ea1f8b
--- /dev/null
@@ -0,0 +1,64 @@
+package net.ktnx.mobileledger;
+
+import android.annotation.TargetApi;
+import android.app.DatePickerDialog;
+import android.app.Dialog;
+import android.os.Build;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.v7.app.AppCompatDialogFragment;
+import android.widget.DatePicker;
+import android.widget.TextView;
+
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class DatePickerFragment extends AppCompatDialogFragment
+implements DatePickerDialog.OnDateSetListener
+{
+    @NonNull
+    @Override
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
+        final Calendar c = GregorianCalendar.getInstance();
+        int year = c.get(GregorianCalendar.YEAR);
+        int month = c.get(GregorianCalendar.MONTH);
+        int day = c.get(GregorianCalendar.DAY_OF_MONTH);
+        TextView date = getActivity().findViewById(R.id.new_transaction_date);
+
+        CharSequence present = date.getText();
+
+        Pattern re_mon_day = Pattern.compile("^\\s*(\\d+)\\s*/\\s*(\\d+)\\s*$");
+        Matcher m_mon_day = re_mon_day.matcher(present);
+
+        if (m_mon_day.matches()) {
+            month = Integer.parseInt(m_mon_day.group(0));
+            day = Integer.parseInt(m_mon_day.group(1));
+        }
+        else {
+            Pattern re_day = Pattern.compile("^\\s*(\\d{1,2})\\s*$");
+            Matcher m_day = re_day.matcher(present);
+            if (m_day.matches()) {
+                day = Integer.parseInt(m_day.group(0));
+            }
+        }
+
+        return new DatePickerDialog(Objects.requireNonNull(getActivity()), this, year, month, day);
+    }
+
+    @TargetApi(Build.VERSION_CODES.O)
+    public void onDateSet(DatePicker view, int year, int month, int day) {
+        TextView date = getActivity().findViewById(R.id.new_transaction_date);
+
+        final Calendar c = GregorianCalendar.getInstance();
+        if ( c.get(GregorianCalendar.YEAR) == year && c.get(GregorianCalendar.MONTH) == month) {
+            date.setText(String.format(Locale.US, "%d", day));
+        }
+        else {
+            date.setText(String.format(Locale.US, "%d/%d", month, day));
+        }
+    }
+}
index 38dd1e48f6a954e014cb288bb13cdc6a37a0de5d..98391f29f04d2fcd9a1a86ffc01efb852ffd5ac7 100644 (file)
@@ -3,8 +3,6 @@ package net.ktnx.mobileledger;
 import android.content.Intent;
 import android.content.pm.PackageInfo;
 import android.os.Bundle;
-import android.support.design.widget.FloatingActionButton;
-import android.support.design.widget.Snackbar;
 import android.support.v4.view.GravityCompat;
 import android.support.v4.widget.DrawerLayout;
 import android.support.v7.app.ActionBarDrawerToggle;
@@ -24,15 +22,6 @@ public class LatestTransactions extends AppCompatActivity {
         Toolbar toolbar = findViewById(R.id.toolbar);
         setSupportActionBar(toolbar);
 
-        FloatingActionButton fab = findViewById(R.id.btn_add_transaction);
-        fab.setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View view) {
-                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
-                        .setAction("Action", null).show();
-            }
-        });
-
         DrawerLayout drawer = findViewById(R.id.drawer_layout);
         ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                 this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
@@ -45,10 +34,14 @@ public class LatestTransactions extends AppCompatActivity {
             PackageInfo pi = getApplicationContext().getPackageManager().getPackageInfo(getPackageName(), 0);
             ver.setText(pi.versionName);
         } catch (Exception e) {
-            ver.setText("version");
         }
     }
 
+    public void fab_new_transaction_clicked(View view) {
+        Intent intent = new Intent(this, NewTransactionActivity.class);
+        startActivity(intent);
+    }
+
     public void nav_exit_clicked(View view) {
         Log.w("mobileledger", "exiting");
         finish();
diff --git a/app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java b/app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java
new file mode 100644 (file)
index 0000000..1c1f863
--- /dev/null
@@ -0,0 +1,40 @@
+package net.ktnx.mobileledger;
+
+import android.os.Bundle;
+import android.support.design.widget.FloatingActionButton;
+import android.support.design.widget.Snackbar;
+import android.support.v4.app.DialogFragment;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.Toolbar;
+import android.view.View;
+
+import java.util.Objects;
+
+public class NewTransactionActivity extends AppCompatActivity {
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_new_transaction);
+        Toolbar toolbar = findViewById(R.id.toolbar);
+        setSupportActionBar(toolbar);
+
+        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
+        fab.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
+                        .setAction("Action", null).show();
+            }
+        });
+        Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
+    }
+
+    public void pickTransactionDate(View view) {
+        DialogFragment picker = new DatePickerFragment();
+        picker.show(getSupportFragmentManager(), "datePicker");
+//        Snackbar.make(view, "Date editing not yet ready", Snackbar.LENGTH_LONG)
+//                .setAction("Action", null).show();
+    }
+
+}
diff --git a/app/src/main/res/layout-v26/content_new_transaction.xml b/app/src/main/res/layout-v26/content_new_transaction.xml
new file mode 100644 (file)
index 0000000..e6aff48
--- /dev/null
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    app:layout_behavior="@string/appbar_scrolling_view_behavior"
+    tools:context=".NewTransactionActivity"
+    tools:showIn="@layout/activity_new_transaction">
+
+    <ScrollView
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="vertical">
+
+            <EditText
+                android:id="@+id/new_transaction_date"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:ems="10"
+                android:hint="@string/new_transaction_date_hint"
+                android:importantForAutofill="no"
+                android:inputType="date"
+                android:onClick="pickTransactionDate"
+                android:textAlignment="center" />
+
+            <LinearLayout
+                android:importantForAutofill="noExcludeDescendants"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:orientation="vertical">
+
+                <AutoCompleteTextView
+                    android:id="@+id/autoCompleteTextView2"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:layout_weight="1"
+                    android:hint="@string/new_transaction_account_label"
+                    android:text="" />
+
+                <EditText
+                    android:id="@+id/editText4"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:layout_weight="1"
+                    android:ems="10"
+                    android:hint="@string/new_transaction_amount_hint"
+                    android:inputType="numberSigned|numberDecimal"
+                    android:textAlignment="viewEnd" />
+            </LinearLayout>
+
+        </LinearLayout>
+    </ScrollView>
+
+</android.support.constraint.ConstraintLayout>
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_new_transaction.xml b/app/src/main/res/layout/activity_new_transaction.xml
new file mode 100644 (file)
index 0000000..69ef23e
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context=".NewTransactionActivity">
+
+    <android.support.design.widget.AppBarLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:theme="@style/AppTheme.AppBarOverlay">
+
+        <android.support.v7.widget.Toolbar
+            android:id="@+id/toolbar"
+            android:layout_width="match_parent"
+            android:layout_height="?attr/actionBarSize"
+            android:background="?attr/colorPrimary"
+            app:popupTheme="@style/AppTheme.PopupOverlay" />
+
+    </android.support.design.widget.AppBarLayout>
+
+    <include layout="@layout/content_new_transaction" />
+
+    <android.support.design.widget.FloatingActionButton
+        android:id="@+id/fab"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="bottom|end"
+        android:layout_margin="@dimen/fab_margin"
+        app:backgroundTint="@color/colorPrimary"
+        app:srcCompat="@android:drawable/ic_menu_send" />
+
+    <android.support.design.widget.FloatingActionButton
+        android:id="@+id/fab_add_account"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_gravity="top|end"
+        android:layout_marginBottom="80dp"
+        android:clickable="true"
+        android:focusable="auto"
+        app:layout_anchor="@id/fab"
+        app:layout_anchorGravity="top"
+        app:srcCompat="@drawable/svg_thick_plus_white" />
+
+</android.support.design.widget.CoordinatorLayout>
\ No newline at end of file
index 96b62fd4dfefcfdd878290fb4cfac5f1816c85c1..45daa4e2ee5c4b75d6f2bd7cb84b24a202ee9683 100644 (file)
@@ -28,6 +28,7 @@
         android:layout_height="wrap_content"
         android:layout_gravity="bottom|end"
         android:layout_margin="@dimen/fab_margin"
+        android:onClick="fab_new_transaction_clicked"
         app:backgroundTint="@color/colorPrimary"
         app:srcCompat="@drawable/svg_thick_plus_white" />
 
diff --git a/app/src/main/res/layout/content_new_transaction.xml b/app/src/main/res/layout/content_new_transaction.xml
new file mode 100644 (file)
index 0000000..58ce717
--- /dev/null
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    app:layout_behavior="@string/appbar_scrolling_view_behavior"
+    tools:context=".NewTransactionActivity"
+    tools:showIn="@layout/activity_new_transaction">
+
+    <ScrollView
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="vertical">
+
+            <EditText
+                android:id="@+id/new_transaction_date"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:ems="10"
+                android:hint="@string/new_transaction_date_hint"
+                android:inputType="date"
+                android:onClick="pickTransactionDate"
+                android:textAlignment="center" />
+
+            <LinearLayout
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:orientation="vertical">
+
+                <AutoCompleteTextView
+                    android:id="@+id/autoCompleteTextView2"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:layout_weight="1"
+                    android:hint="@string/new_transaction_account_label"
+                    android:text="" />
+
+                <EditText
+                    android:id="@+id/editText4"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:layout_weight="1"
+                    android:ems="10"
+                    android:hint="@string/new_transaction_amount_hint"
+                    android:inputType="numberSigned|numberDecimal"
+                    android:textAlignment="viewEnd" />
+            </LinearLayout>
+
+        </LinearLayout>
+    </ScrollView>
+
+</android.support.constraint.ConstraintLayout>
\ No newline at end of file
diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v21/styles.xml
deleted file mode 100644 (file)
index fd7a058..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<resources>
-
-    <style name="AppTheme.NoActionBar">
-        <item name="windowActionBar">false</item>
-        <item name="windowNoTitle">true</item>
-        <item name="android:statusBarColor">@android:color/transparent</item>
-    </style>
-</resources>
index 1f202f277843ec879a94bbbe29dc27bff1e39963..2213bfd3cf252d65f9501348b871e687dd1eea39 100644 (file)
@@ -56,4 +56,8 @@
     <string name="pref_title_vibrate">Vibrate</string>
     <string name="pref_title_backend_auth_user">Username</string>
     <string name="pref_title_backend_auth_password">Password</string>
+    <string name="title_activity_new_transaction">New Transaction</string>
+    <string name="new_transaction_account_label">Account</string>
+    <string name="new_transaction_date_hint">Transaction date</string>
+    <string name="new_transaction_amount_hint">amount</string>
 </resources>
diff --git a/app/src/main/res/xml/backup_descriptor.xml b/app/src/main/res/xml/backup_descriptor.xml
new file mode 100644 (file)
index 0000000..cfcd563
--- /dev/null
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<full-backup-content>
+<!-- Exclude specific shared preferences that contain GCM registration Id -->
+</full-backup-content>