From: Damyan Ivanov Date: Fri, 30 Nov 2018 17:44:02 +0000 (+0000) Subject: start the new transaction interface X-Git-Tag: v0.3~381 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=b3fff85cf8314bb335eab4e9e9aa0fa9681ad12b;p=mobile-ledger.git start the new transaction interface --- 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 index 00000000..4ea1f8b3 --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/DatePickerFragment.java @@ -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)); + } + } +} diff --git a/app/src/main/java/net/ktnx/mobileledger/LatestTransactions.java b/app/src/main/java/net/ktnx/mobileledger/LatestTransactions.java index 38dd1e48..98391f29 100644 --- a/app/src/main/java/net/ktnx/mobileledger/LatestTransactions.java +++ b/app/src/main/java/net/ktnx/mobileledger/LatestTransactions.java @@ -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 index 00000000..1c1f863a --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java @@ -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 index 00000000..e6aff486 --- /dev/null +++ b/app/src/main/res/layout-v26/content_new_transaction.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + \ 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 index 00000000..69ef23ec --- /dev/null +++ b/app/src/main/res/layout/activity_new_transaction.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/app_bar_latest_transactions.xml b/app/src/main/res/layout/app_bar_latest_transactions.xml index 96b62fd4..45daa4e2 100644 --- a/app/src/main/res/layout/app_bar_latest_transactions.xml +++ b/app/src/main/res/layout/app_bar_latest_transactions.xml @@ -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 index 00000000..58ce7170 --- /dev/null +++ b/app/src/main/res/layout/content_new_transaction.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + \ 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 index fd7a0584..00000000 --- a/app/src/main/res/values-v21/styles.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1f202f27..2213bfd3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -56,4 +56,8 @@ Vibrate Username Password + New Transaction + Account + Transaction date + amount diff --git a/app/src/main/res/xml/backup_descriptor.xml b/app/src/main/res/xml/backup_descriptor.xml new file mode 100644 index 00000000..cfcd5630 --- /dev/null +++ b/app/src/main/res/xml/backup_descriptor.xml @@ -0,0 +1,4 @@ + + + +