]> git.ktnx.net Git - mobile-ledger.git/commitdiff
toCamelCase
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 12 Jan 2019 07:47:28 +0000 (07:47 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 12 Jan 2019 07:47:28 +0000 (07:47 +0000)
14 files changed:
app/src/main/java/net/ktnx/mobileledger/MobileLedgerApplication.java
app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java
app/src/main/java/net/ktnx/mobileledger/async/SaveTransactionTask.java
app/src/main/java/net/ktnx/mobileledger/model/Data.java
app/src/main/java/net/ktnx/mobileledger/model/LedgerAccount.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionActivity.java
app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java
app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java
app/src/main/java/net/ktnx/mobileledger/utils/Globals.java
app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java
app/src/main/java/net/ktnx/mobileledger/utils/NetworkUtil.java
app/src/main/java/net/ktnx/mobileledger/utils/UrlEncodedFormData.java
app/src/main/res/layout/activity_main.xml

index ea4a3d663126c7a65de8cd8ea3d02b632f54b7a4..7f0dfeb68bd272d9533c37e130a82188073378c7 100644 (file)
@@ -59,14 +59,14 @@ public class MobileLedgerApplication extends Application {
         Resources rm = getResources();
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
             Resources.Theme theme = getTheme();
-            Globals.table_row_odd_bg = rm.getColor(R.color.table_row_odd_bg, theme);
-            Globals.table_row_even_bg = rm.getColor(R.color.table_row_even_bg, theme);
+            Globals.tableRowOddBG = rm.getColor(R.color.table_row_odd_bg, theme);
+            Globals.tableRowEvenBG = rm.getColor(R.color.table_row_even_bg, theme);
             Globals.primaryDark = rm.getColor(R.color.design_default_color_primary_dark, theme);
             Globals.defaultTextColor = rm.getColor(android.R.color.tab_indicator_text, theme);
         }
         else {
-            Globals.table_row_odd_bg = rm.getColor(R.color.table_row_odd_bg);
-            Globals.table_row_even_bg = rm.getColor(R.color.table_row_even_bg);
+            Globals.tableRowOddBG = rm.getColor(R.color.table_row_odd_bg);
+            Globals.tableRowEvenBG = rm.getColor(R.color.table_row_even_bg);
             Globals.primaryDark = rm.getColor(R.color.design_default_color_primary_dark);
             Globals.defaultTextColor = rm.getColor(android.R.color.tab_indicator_text);
         }
index 91ea8ffc55bfe394df8b7001c9d9b7ea90b76b9b..b13b9050e8294457e5167c73e126e4129568a7ed 100644 (file)
@@ -54,20 +54,20 @@ import java.util.regex.Pattern;
 public class RetrieveTransactionsTask
         extends AsyncTask<Void, RetrieveTransactionsTask.Progress, Void> {
     private static final int MATCHING_TRANSACTIONS_LIMIT = 50;
-    private static final Pattern commentPattern = Pattern.compile("^\\s*;");
-    private static final Pattern transactionStartPattern = Pattern.compile("<tr class=\"title\" " +
-                                                                           "id=\"transaction-(\\d+)\"><td class=\"date\"[^\"]*>([\\d.-]+)</td>");
-    private static final Pattern transactionDescriptionPattern =
+    private static final Pattern reComment = Pattern.compile("^\\s*;");
+    private static final Pattern reTransactionStart = Pattern.compile("<tr class=\"title\" " +
+                                                                      "id=\"transaction-(\\d+)\"><td class=\"date\"[^\"]*>([\\d.-]+)</td>");
+    private static final Pattern reTransactionDescription =
             Pattern.compile("<tr class=\"posting\" title=\"(\\S+)\\s(.+)");
-    private static final Pattern transactionDetailsPattern =
+    private static final Pattern reTransactionDetails =
             Pattern.compile("^\\s+(\\S[\\S\\s]+\\S)\\s\\s+([-+]?\\d[\\d,.]*)(?:\\s+(\\S+)$)?");
-    private static final Pattern endPattern = Pattern.compile("\\bid=\"addmodal\"");
+    private static final Pattern reEnd = Pattern.compile("\\bid=\"addmodal\"");
     private WeakReference<MainActivity> contextRef;
     private int error;
     // %3A is '='
     private boolean success;
-    private Pattern account_name_re = Pattern.compile("/register\\?q=inacct%3A([a-zA-Z0-9%]+)\"");
-    private Pattern account_value_re = Pattern.compile(
+    private Pattern reAccountName = Pattern.compile("/register\\?q=inacct%3A([a-zA-Z0-9%]+)\"");
+    private Pattern reAccountValue = Pattern.compile(
             "<span class=\"[^\"]*\\bamount\\b[^\"]*\">\\s*([-+]?[\\d.,]+)(?:\\s+(\\S+))?</span>");
     public RetrieveTransactionsTask(WeakReference<MainActivity> contextRef) {
         this.contextRef = contextRef;
@@ -117,7 +117,7 @@ public class RetrieveTransactionsTask
         boolean onlyStarred = Data.optShowOnlyStarred.get();
         Data.backgroundTaskCount.incrementAndGet();
         try {
-            HttpURLConnection http = NetworkUtil.prepare_connection("journal");
+            HttpURLConnection http = NetworkUtil.prepareConnection("journal");
             http.setAllowUserInteraction(false);
             publishProgress(progress);
             MainActivity ctx = getContext();
@@ -145,7 +145,7 @@ public class RetrieveTransactionsTask
                         while ((line = buf.readLine()) != null) {
                             throwIfCancelled();
                             Matcher m;
-                            m = commentPattern.matcher(line);
+                            m = reComment.matcher(line);
                             if (m.find()) {
                                 // TODO: comments are ignored for now
                                 Log.v("transaction-parser", "Ignoring comment");
@@ -160,7 +160,7 @@ public class RetrieveTransactionsTask
                                         Data.accounts.set(accountList);
                                         continue;
                                     }
-                                    m = account_name_re.matcher(line);
+                                    m = reAccountName.matcher(line);
                                     if (m.find()) {
                                         String acct_encoded = m.group(1);
                                         String acct_name = URLDecoder.decode(acct_encoded, "UTF-8");
@@ -206,7 +206,7 @@ public class RetrieveTransactionsTask
                                     break;
 
                                 case EXPECTING_ACCOUNT_AMOUNT:
-                                    m = account_value_re.matcher(line);
+                                    m = reAccountValue.matcher(line);
                                     boolean match_found = false;
                                     while (m.find()) {
                                         throwIfCancelled();
@@ -231,7 +231,7 @@ public class RetrieveTransactionsTask
 
                                 case EXPECTING_TRANSACTION:
                                     if (!line.isEmpty() && (line.charAt(0) == ' ')) continue;
-                                    m = transactionStartPattern.matcher(line);
+                                    m = reTransactionStart.matcher(line);
                                     if (m.find()) {
                                         transactionId = Integer.valueOf(m.group(1));
                                         state = ParserState.EXPECTING_TRANSACTION_DESCRIPTION;
@@ -246,7 +246,7 @@ public class RetrieveTransactionsTask
                                             progress.setTotal(transactionId);
                                         publishProgress(progress);
                                     }
-                                    m = endPattern.matcher(line);
+                                    m = reEnd.matcher(line);
                                     if (m.find()) {
                                         L("--- transaction value complete ---");
                                         success = true;
@@ -256,7 +256,7 @@ public class RetrieveTransactionsTask
 
                                 case EXPECTING_TRANSACTION_DESCRIPTION:
                                     if (!line.isEmpty() && (line.charAt(0) == ' ')) continue;
-                                    m = transactionDescriptionPattern.matcher(line);
+                                    m = reTransactionDescription.matcher(line);
                                     if (m.find()) {
                                         if (transactionId == 0)
                                             throw new TransactionParserException(
@@ -320,7 +320,7 @@ public class RetrieveTransactionsTask
 //                                            }
                                     }
                                     else {
-                                        m = transactionDetailsPattern.matcher(line);
+                                        m = reTransactionDetails.matcher(line);
                                         if (m.find()) {
                                             String acc_name = m.group(1);
                                             String amount = m.group(2);
index 913fddc5dd831bdd92a1d338ce80f7e6ddc7c53c..c4cc9a3ea7fa4171ac7844ef7d3fd671c965ea07 100644 (file)
@@ -41,18 +41,18 @@ import java.util.regex.Pattern;
 import static java.lang.Thread.sleep;
 
 public class SaveTransactionTask extends AsyncTask<LedgerTransaction, Void, Void> {
-    private final TaskCallback task_callback;
+    private final TaskCallback taskCallback;
     private String token;
     private String session;
-    private String backend_url;
+    private String backendUrl;
     private LedgerTransaction ltr;
     protected String error;
 
     public SaveTransactionTask(TaskCallback callback) {
-        task_callback = callback;
+        taskCallback = callback;
     }
-    private boolean send_ok() throws IOException {
-        HttpURLConnection http = NetworkUtil.prepare_connection("add");
+    private boolean sendOK() throws IOException {
+        HttpURLConnection http = NetworkUtil.prepareConnection("add");
         http.setRequestMethod("POST");
         http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
         http.setRequestProperty("Accept", "*/*");
@@ -63,15 +63,15 @@ public class SaveTransactionTask extends AsyncTask<LedgerTransaction, Void, Void
         http.setDoInput(true);
 
         UrlEncodedFormData params = new UrlEncodedFormData();
-        params.add_pair("_formid", "identify-add");
-        if (token != null) params.add_pair("_token", token);
-        params.add_pair("date", ltr.getDate());
-        params.add_pair("description", ltr.getDescription());
+        params.addPair("_formid", "identify-add");
+        if (token != null) params.addPair("_token", token);
+        params.addPair("date", ltr.getDate());
+        params.addPair("description", ltr.getDescription());
         for (LedgerTransactionAccount acc : ltr.getAccounts()) {
-            params.add_pair("account", acc.getAccountName());
+            params.addPair("account", acc.getAccountName());
             if (acc.isAmountSet())
-                params.add_pair("amount", String.format(Locale.US, "%1.2f", acc.getAmount()));
-            else params.add_pair("amount", "");
+                params.addPair("amount", String.format(Locale.US, "%1.2f", acc.getAmount()));
+            else params.addPair("amount", "");
         }
 
         String body = params.toString();
@@ -91,13 +91,13 @@ public class SaveTransactionTask extends AsyncTask<LedgerTransaction, Void, Void
                 } else if (http.getResponseCode() == 200) {
                     // get the new cookie
                     {
-                        Pattern sess_cookie_re = Pattern.compile("_SESSION=([^;]+);.*");
+                        Pattern reSessionCookie = Pattern.compile("_SESSION=([^;]+);.*");
 
                         Map<String, List<String>> header = http.getHeaderFields();
-                        List<String> cookie_header = header.get("Set-Cookie");
-                        if (cookie_header != null) {
-                            String cookie = cookie_header.get(0);
-                            Matcher m = sess_cookie_re.matcher(cookie);
+                        List<String> cookieHeader = header.get("Set-Cookie");
+                        if (cookieHeader != null) {
+                            String cookie = cookieHeader.get(0);
+                            Matcher m = reSessionCookie.matcher(cookie);
                             if (m.matches()) {
                                 session = m.group(1);
                                 Log.d("network", "new session is " + session);
@@ -135,11 +135,11 @@ public class SaveTransactionTask extends AsyncTask<LedgerTransaction, Void, Void
     protected Void doInBackground(LedgerTransaction... ledgerTransactions) {
         error = null;
         try {
-            backend_url = Data.profile.get().getUrl();
+            backendUrl = Data.profile.get().getUrl();
             ltr = ledgerTransactions[0];
 
             int tried = 0;
-            while (!send_ok()) {
+            while (!sendOK()) {
                 try {
                     tried++;
                     if (tried >= 2)
@@ -162,6 +162,6 @@ public class SaveTransactionTask extends AsyncTask<LedgerTransaction, Void, Void
     @Override
     protected void onPostExecute(Void aVoid) {
         super.onPostExecute(aVoid);
-        task_callback.done(error);
+        taskCallback.done(error);
     }
 }
index 7781f3285d5ab2bd4b8411bd6304838996d50b49..62aecd62e1bc10290816456a6780e09f0bd40e94 100644 (file)
@@ -36,7 +36,7 @@ public final class Data {
             new ObservableList<>(new ArrayList<>());
     public static ObservableValue<Boolean> optShowOnlyStarred = new ObservableValue<>();
     public static void setCurrentProfile(MobileLedgerProfile newProfile) {
-        MLDB.set_option_value(MLDB.OPT_PROFILE_UUID, newProfile.getUuid());
+        MLDB.setOption(MLDB.OPT_PROFILE_UUID, newProfile.getUuid());
         profile.set(newProfile);
     }
 }
index 4cf08f9ebf01b114ffd47a5a181ab6ebafafcc77..532642acddaf238e4393498539080ba966d33071 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2018 Damyan Ivanov.
+ * Copyright © 2019 Damyan Ivanov.
  * This file is part of Mobile-Ledger.
  * Mobile-Ledger is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
@@ -32,7 +32,7 @@ public class LedgerAccount {
     private boolean hidden;
     private boolean hiddenToBe;
     private List<LedgerAmount> amounts;
-    static Pattern higher_account = Pattern.compile("^[^:]+:");
+    static Pattern reHigherAccount = Pattern.compile("^[^:]+:");
 
     public LedgerAccount(String name) {
         this.setName(name);
@@ -64,7 +64,7 @@ public class LedgerAccount {
         shortName = name;
         StringBuilder parentBuilder = new StringBuilder();
         while (true) {
-            Matcher m = higher_account.matcher(shortName);
+            Matcher m = reHigherAccount.matcher(shortName);
             if (m.find()) {
                 level++;
                 parentBuilder.append(m.group(0));
index a59ec036bf579dfc90ff3d248e481e03ebc475c4..20460186e3cf90e787a20c7cb96d4f44d107e8bf 100644 (file)
@@ -172,7 +172,7 @@ public class MainActivity extends AppCompatActivity {
         Data.profiles.setList(MobileLedgerProfile.loadAllFromDB());
         MobileLedgerProfile profile = null;
 
-        String profileUUID = MLDB.get_option_value(MLDB.OPT_PROFILE_UUID, null);
+        String profileUUID = MLDB.getOption(MLDB.OPT_PROFILE_UUID, null);
         if (profileUUID == null) {
             if (Data.profiles.isEmpty()) {
                 Data.profiles.setList(MobileLedgerProfile.createInitialProfileList());
@@ -215,18 +215,18 @@ public class MainActivity extends AppCompatActivity {
             startActivity(intent, args);
         }
     }
-    public void fab_new_transaction_clicked(View view) {
+    public void fabNewTransactionClicked(View view) {
         Intent intent = new Intent(this, NewTransactionActivity.class);
         startActivity(intent);
         overridePendingTransition(R.anim.slide_in_right, R.anim.dummy);
     }
 
-    public void nav_exit_clicked(View view) {
+    public void navExitClicked(View view) {
         Log.w("app", "exiting");
         finish();
     }
 
-    public void nav_settings_clicked(View view) {
+    public void navSettingsClicked(View view) {
         Intent intent = new Intent(this, SettingsActivity.class);
         startActivity(intent);
         drawer.closeDrawers();
@@ -363,7 +363,7 @@ public class MainActivity extends AppCompatActivity {
             progressBar.setIndeterminate(false);
         }
     }
-    public void nav_profiles_clicked(View view) {
+    public void navProfilesClicked(View view) {
         drawer.closeDrawers();
         Intent intent = new Intent(this, ProfileListActivity.class);
         startActivity(intent);
index c2ca87b920b930f08bdab076b3d1fabfdf89cd27..0856bb543b0b199df26d498d832aab841d784de9 100644 (file)
@@ -69,10 +69,12 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal
     private static SaveTransactionTask saver;
     private TableLayout table;
     private ProgressBar progress;
-    private TextView text_date;
-    private AutoCompleteTextView text_descr;
+    private TextView tvDate;
+    private AutoCompleteTextView tvDescription;
     private MenuItem mSave;
-
+    private static boolean isZero(float f) {
+        return (f < 0.005) && (f > -0.005);
+    }
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -80,14 +82,14 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal
         Toolbar toolbar = findViewById(R.id.toolbar);
         setSupportActionBar(toolbar);
 
-        text_date = findViewById(R.id.new_transaction_date);
-        text_date.setOnFocusChangeListener((v, hasFocus) -> {
+        tvDate = findViewById(R.id.new_transaction_date);
+        tvDate.setOnFocusChangeListener((v, hasFocus) -> {
             if (hasFocus) pickTransactionDate(v);
         });
-        text_descr = findViewById(R.id.new_transaction_description);
-        MLDB.hook_autocompletion_adapter(this, text_descr, MLDB.DESCRIPTION_HISTORY_TABLE,
+        tvDescription = findViewById(R.id.new_transaction_description);
+        MLDB.hookAutocompletionAdapter(this, tvDescription, MLDB.DESCRIPTION_HISTORY_TABLE,
                 "description", false, findViewById(R.id.new_transaction_acc_1));
-        hook_text_change_listener(text_descr);
+        hookTextChangeListener(tvDescription);
 
         progress = findViewById(R.id.save_transaction_progress);
 
@@ -95,23 +97,17 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal
         table = findViewById(R.id.new_transaction_accounts_table);
         for (int i = 0; i < table.getChildCount(); i++) {
             TableRow row = (TableRow) table.getChildAt(i);
-            AutoCompleteTextView acc_name_view = (AutoCompleteTextView) row.getChildAt(0);
-            TextView amount_view = (TextView) row.getChildAt(1);
-            hook_swipe_listener(row);
-            MLDB.hook_autocompletion_adapter(this, acc_name_view, MLDB.ACCOUNTS_TABLE, "name", true,
-                    amount_view);
-            hook_text_change_listener(acc_name_view);
-            hook_text_change_listener(amount_view);
+            AutoCompleteTextView tvAccountName = (AutoCompleteTextView) row.getChildAt(0);
+            TextView tvAmount = (TextView) row.getChildAt(1);
+            hookSwipeListener(row);
+            MLDB.hookAutocompletionAdapter(this, tvAccountName, MLDB.ACCOUNTS_TABLE, "name", true,
+                    tvAmount);
+            hookTextChangeListener(tvAccountName);
+            hookTextChangeListener(tvAmount);
 //            Log.d("swipe", "hooked to row "+i);
         }
     }
 
-    @Override
-    protected void onStart() {
-        super.onStart();
-        if (text_descr.getText().toString().isEmpty()) text_descr.requestFocus();
-    }
-
     @Override
     public void finish() {
         super.finish();
@@ -127,17 +123,21 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal
         }
         return super.onOptionsItemSelected(item);
     }
-
-    public void save_transaction() {
+    @Override
+    protected void onStart() {
+        super.onStart();
+        if (tvDescription.getText().toString().isEmpty()) tvDescription.requestFocus();
+    }
+    public void saveTransaction() {
         if (mSave != null) mSave.setVisible(false);
-        toggle_all_editing(false);
+        toggleAllEditing(false);
         progress.setVisibility(View.VISIBLE);
 
         saver = new SaveTransactionTask(this);
 
-        String date = text_date.getText().toString();
+        String date = tvDate.getText().toString();
         if (date.isEmpty()) date = String.valueOf(new Date().getDate());
-        LedgerTransaction tr = new LedgerTransaction(date, text_descr.getText().toString());
+        LedgerTransaction tr = new LedgerTransaction(date, tvDescription.getText().toString());
 
         TableLayout table = findViewById(R.id.new_transaction_accounts_table);
         for (int i = 0; i < table.getChildCount(); i++) {
@@ -152,10 +152,9 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal
         }
         saver.execute(tr);
     }
-
-    private void toggle_all_editing(boolean enabled) {
-        text_date.setEnabled(enabled);
-        text_descr.setEnabled(enabled);
+    private void toggleAllEditing(boolean enabled) {
+        tvDate.setEnabled(enabled);
+        tvDescription.setEnabled(enabled);
         TableLayout table = findViewById(R.id.new_transaction_accounts_table);
         for (int i = 0; i < table.getChildCount(); i++) {
             TableRow row = (TableRow) table.getChildAt(i);
@@ -164,8 +163,7 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal
             }
         }
     }
-
-    private void hook_swipe_listener(final TableRow row) {
+    private void hookSwipeListener(final TableRow row) {
         row.getChildAt(0).setOnTouchListener(new OnSwipeTouchListener(this) {
             public void onSwipeLeft() {
 //                Log.d("swipe", "LEFT" + row.getId());
@@ -173,7 +171,7 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal
                     TableRow prev_row = (TableRow) table.getChildAt(table.indexOfChild(row) - 1);
                     TableRow next_row = (TableRow) table.getChildAt(table.indexOfChild(row) + 1);
                     TextView prev_amt =
-                            (prev_row != null) ? (TextView) prev_row.getChildAt(1) : text_descr;
+                            (prev_row != null) ? (TextView) prev_row.getChildAt(1) : tvDescription;
                     TextView next_acc =
                             (next_row != null) ? (TextView) next_row.getChildAt(0) : null;
 
@@ -212,27 +210,6 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal
         });
     }
 
-    private void hook_text_change_listener(final TextView view) {
-        view.addTextChangedListener(new TextWatcher() {
-            @Override
-            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
-
-            }
-
-            @Override
-            public void onTextChanged(CharSequence s, int start, int before, int count) {
-
-            }
-
-            @Override
-            public void afterTextChanged(Editable s) {
-//                Log.d("input", "text changed");
-                check_transaction_submittable();
-            }
-        });
-
-    }
-
     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);
@@ -253,8 +230,27 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal
         return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
                 getResources().getDisplayMetrics()));
     }
+    private void hookTextChangeListener(final TextView view) {
+        view.addTextChangedListener(new TextWatcher() {
+            @Override
+            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+
+            }
+
+            @Override
+            public void onTextChanged(CharSequence s, int start, int before, int count) {
+
+            }
 
-    private void do_add_account_row(boolean focus) {
+            @Override
+            public void afterTextChanged(Editable s) {
+//                Log.d("input", "text changed");
+                check_transaction_submittable();
+            }
+        });
+
+    }
+    private void doAddAccountRow(boolean focus) {
         final AutoCompleteTextView acc = new AutoCompleteTextView(this);
         acc.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
                 TableRow.LayoutParams.WRAP_CONTENT, 9f));
@@ -294,28 +290,20 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal
 
         if (focus) acc.requestFocus();
 
-        hook_swipe_listener(row);
-        MLDB.hook_autocompletion_adapter(this, acc, MLDB.ACCOUNTS_TABLE, "name", true, amt);
-        hook_text_change_listener(acc);
-        hook_text_change_listener(amt);
+        hookSwipeListener(row);
+        MLDB.hookAutocompletionAdapter(this, acc, MLDB.ACCOUNTS_TABLE, "name", true, amt);
+        hookTextChangeListener(acc);
+        hookTextChangeListener(amt);
     }
-
     public void addTransactionAccountFromMenu(MenuItem item) {
-        do_add_account_row(true);
+        doAddAccountRow(true);
     }
-
     public void resetTransactionFromMenu(MenuItem item) {
-        reset_form();
+        resetForm();
     }
-
     public void saveTransactionFromMenu(MenuItem item) {
-        save_transaction();
+        saveTransaction();
     }
-
-    private boolean is_zero(float f) {
-        return (f < 0.005) && (f > -0.005);
-    }
-
     // rules:
     // 1) at least two account names
     // 2) each amount must have account name
@@ -377,7 +365,7 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal
             if ((empty_rows == 0) &&
                 ((table.getChildCount() == accounts) || (table.getChildCount() == amounts)))
             {
-                do_add_account_row(false);
+                doAddAccountRow(false);
             }
 
             Log.d("submittable", String.format("accounts=%d, accounts_with_values=%s, " +
@@ -388,7 +376,7 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal
 
             if (have_description && (accounts >= 2) && (accounts_with_values >= (accounts - 1)) &&
                 (amounts_with_accounts == amounts) &&
-                (single_empty_amount && single_empty_amount_has_account || is_zero(running_total)))
+                (single_empty_amount && single_empty_amount_has_account || isZero(running_total)))
             {
                 if (mSave != null) mSave.setVisible(true);
             }
@@ -414,19 +402,19 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal
         progress.setVisibility(View.INVISIBLE);
         Log.d("visuals", "hiding progress");
 
-        if (error == null) reset_form();
+        if (error == null) resetForm();
         else Snackbar.make(findViewById(R.id.new_transaction_accounts_table), error,
                 BaseTransientBottomBar.LENGTH_LONG).show();
 
-        toggle_all_editing(true);
+        toggleAllEditing(true);
         check_transaction_submittable();
     }
 
-    private void reset_form() {
-        text_date.setText("");
-        text_descr.setText("");
+    private void resetForm() {
+        tvDate.setText("");
+        tvDescription.setText("");
 
-        text_descr.requestFocus();
+        tvDescription.requestFocus();
 
         while (table.getChildCount() > 2) {
             table.removeViewAt(2);
index 96933eeb84759cc43470eccef9a352510c30c96d..7004dd7d8d026aa1446bf6b64a51bc692460730b 100644 (file)
@@ -112,10 +112,10 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
                     holder.tvDate.setText(step.getTransaction().getDate());
 
                     if (step.getPosition() % 2 == 0) {
-                        holder.row.setBackgroundColor(Globals.table_row_even_bg);
+                        holder.row.setBackgroundColor(Globals.tableRowEvenBG);
                     }
                     else {
-                        holder.row.setBackgroundColor(Globals.table_row_odd_bg);
+                        holder.row.setBackgroundColor(Globals.tableRowOddBG);
                     }
 
                     break;
index d719259237c5ded76fd946123483aaac37fd9aff..f748ff1dd21344e67405b41e39582588af0484ff 100644 (file)
@@ -158,7 +158,7 @@ public class TransactionListFragment extends MobileLedgerListFragment {
         accNameFilter = mActivity.findViewById(R.id.transaction_filter_account_name);
 
         TransactionListFragment me = this;
-        MLDB.hook_autocompletion_adapter(mActivity, accNameFilter, "accounts", "name", true);
+        MLDB.hookAutocompletionAdapter(mActivity, accNameFilter, "accounts", "name", true);
         accNameFilter.setOnItemClickListener((parent, view, position, id) -> {
 //                Log.d("tmp", "direct onItemClick");
             TransactionListViewModel.scheduleTransactionListReload();
index e32a4321247261207e8286ae20ae309b49e55ee5..4cf2b755b12a27e6593ac61557b81a1239784203 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2018 Damyan Ivanov.
+ * Copyright © 2019 Damyan Ivanov.
  * This file is part of Mobile-Ledger.
  * Mobile-Ledger is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
@@ -25,9 +25,9 @@ import android.view.inputmethod.InputMethodManager;
 
 public final class Globals {
     @ColorInt
-    public static int table_row_even_bg;
+    public static int tableRowEvenBG;
     @ColorInt
-    public static int table_row_odd_bg;
+    public static int tableRowOddBG;
     @ColorInt
     public static int primaryDark, defaultTextColor;
     public static void hideSoftKeyboard(Activity act) {
index b35579361ea84fed32384b8256f88c5024b28c6b..76763d017677567af1a45a9e8ac5b444c6aa5f78 100644 (file)
@@ -78,8 +78,8 @@ public final class MLDB {
     public static SQLiteDatabase getWritableDatabase() {
         return getDatabase(WRITE);
     }
-    static public int get_option_value(String name, int default_value) {
-        String s = get_option_value(name, String.valueOf(default_value));
+    static public int getIntOption(String name, int default_value) {
+        String s = getOption(name, String.valueOf(default_value));
         try {
             return Integer.parseInt(s);
         }
@@ -88,8 +88,8 @@ public final class MLDB {
             return default_value;
         }
     }
-    static public long get_option_value(String name, long default_value) {
-        String s = get_option_value(name, String.valueOf(default_value));
+    static public long getLongOption(String name, long default_value) {
+        String s = getOption(name, String.valueOf(default_value));
         try {
             return Long.parseLong(s);
         }
@@ -98,7 +98,7 @@ public final class MLDB {
             return default_value;
         }
     }
-    static public String get_option_value(String name, String default_value) {
+    static public String getOption(String name, String default_value) {
         Log.d("db", "about to fetch option " + name);
         SQLiteDatabase db = getReadableDatabase();
         try (Cursor cursor = db.rawQuery("select value from options where profile = ? and name=?",
@@ -119,27 +119,28 @@ public final class MLDB {
             return default_value;
         }
     }
-    static public void set_option_value(String name, String value) {
+    static public void setOption(String name, String value) {
         Log.d("option", String.format("%s := %s", name, value));
         SQLiteDatabase db = MLDB.getWritableDatabase();
         db.execSQL("insert or replace into options(profile, name, value) values(?, ?, ?);",
                 new String[]{NO_PROFILE, name, value});
     }
-    static public void set_option_value(String name, long value) {
-        set_option_value(name, String.valueOf(value));
+    static public void setLongOption(String name, long value) {
+        setOption(name, String.valueOf(value));
     }
     @TargetApi(Build.VERSION_CODES.N)
-    public static void hook_autocompletion_adapter(final Context context,
-                                                   final AutoCompleteTextView view,
-                                                   final String table, final String field,
-                                                   final boolean profileSpecific) {
-        hook_autocompletion_adapter(context, view, table, field, profileSpecific, null);
+    public static void hookAutocompletionAdapter(final Context context,
+                                                 final AutoCompleteTextView view,
+                                                 final String table, final String field,
+                                                 final boolean profileSpecific) {
+        hookAutocompletionAdapter(context, view, table, field, profileSpecific, null);
     }
     @TargetApi(Build.VERSION_CODES.N)
-    public static void hook_autocompletion_adapter(final Context context,
-                                                   final AutoCompleteTextView view, final String table, final String field,
-                                                   final boolean profileSpecific,
-                                                   final View nextView) {
+    public static void hookAutocompletionAdapter(final Context context,
+                                                 final AutoCompleteTextView view,
+                                                 final String table, final String field,
+                                                 final boolean profileSpecific,
+                                                 final View nextView) {
         String[] from = {field};
         int[] to = {android.R.id.text1};
         SimpleCursorAdapter adapter =
index efb1ac973b7c6b874174394bca5de1367296199b..e6cc9acb73c5067bf5dfc5eac260bfcbf4821ef2 100644 (file)
@@ -29,7 +29,7 @@ import java.net.URL;
 
 public final class NetworkUtil {
     private static final int thirtySeconds = 30000;
-    public static HttpURLConnection prepare_connection(String path) throws IOException {
+    public static HttpURLConnection prepareConnection(String path) throws IOException {
         MobileLedgerProfile profile = Data.profile.get();
         final String backend_url = profile.getUrl();
         final boolean use_auth = profile.isAuthEnabled();
index 5d69da212cc90b6cc0734a14675678a5964b9fae..73d26ee1a9c01a60b94cb4121fada39a9a701e42 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2018 Damyan Ivanov.
+ * Copyright © 2019 Damyan Ivanov.
  * This file is part of Mobile-Ledger.
  * Mobile-Ledger is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
@@ -32,8 +32,8 @@ public class UrlEncodedFormData {
         pairs = new ArrayList<>();
     }
 
-    public void add_pair(String name, String value) {
-        pairs.add(new AbstractMap.SimpleEntry<String,String>(name, value));
+    public void addPair(String name, String value) {
+        pairs.add(new AbstractMap.SimpleEntry<>(name, value));
     }
 
     @NonNull
index e29e67390376ee6062cd262ac61519470d2b086b..01e4bb2add8b084fee04eebc746c3a47aefc0b66 100644 (file)
@@ -46,7 +46,7 @@
                 android:layout_height="wrap_content"
                 android:layout_gravity="bottom|end"
                 android:layout_margin="@dimen/fab_margin"
-                android:onClick="fab_new_transaction_clicked"
+                android:onClick="fabNewTransactionClicked"
                 app:backgroundTint="@color/colorPrimary"
                 app:layout_constraintBottom_toBottomOf="parent"
                 app:layout_constraintEnd_toEndOf="parent"
                         android:layout_width="match_parent"
                         android:layout_weight="1"
                         android:drawableStart="@drawable/ic_view_list_black_24dp"
-                        android:onClick="nav_profiles_clicked"
+                        android:onClick="navProfilesClicked"
                         android:text="@string/profiles" />
 
                     <TextView
                         style="@style/nav_button"
                         android:layout_weight="1"
                         android:drawableStart="@drawable/ic_settings_black_24dp"
-                        android:onClick="nav_settings_clicked"
+                        android:onClick="navSettingsClicked"
                         android:text="@string/action_settings" />
 
                     <TextView
                         style="@style/nav_button"
                         android:layout_weight="1"
                         android:drawableStart="@drawable/ic_exit_to_app_black_24dp"
-                        android:onClick="nav_exit_clicked"
+                        android:onClick="navExitClicked"
                         android:text="@string/nav_exit_title" />
 
                 </LinearLayout>