@@ -55,6 +57,7 @@ public String getExtension(){
}
}
+ @NonNull
@Override
public String toString() {
return mDescription;
diff --git a/app/src/main/java/org/gnucash/android/export/ExportParams.java b/app/src/main/java/org/gnucash/android/export/ExportParams.java
index 9194ab843..fe4b6ddea 100644
--- a/app/src/main/java/org/gnucash/android/export/ExportParams.java
+++ b/app/src/main/java/org/gnucash/android/export/ExportParams.java
@@ -23,6 +23,8 @@
import java.sql.Timestamp;
+import androidx.annotation.NonNull;
+
/**
* Encapsulation of the parameters used for exporting transactions.
* The parameters are determined by the user in the export dialog and are then transmitted to the asynchronous task which
@@ -190,6 +192,7 @@ public void setCsvSeparator(char separator) {
mCsvSeparator = separator;
}
+ @NonNull
@Override
public String toString() {
return "Export all transactions created since " + TimestampHelper.getUtcStringFromTimestamp(mExportStartTime) + " UTC"
diff --git a/app/src/main/java/org/gnucash/android/importer/ImportAsyncTask.java b/app/src/main/java/org/gnucash/android/importer/ImportAsyncTask.java
index a5029161f..286547586 100644
--- a/app/src/main/java/org/gnucash/android/importer/ImportAsyncTask.java
+++ b/app/src/main/java/org/gnucash/android/importer/ImportAsyncTask.java
@@ -86,14 +86,9 @@ protected Boolean doInBackground(Uri... uris) {
final String err_msg = exception.getLocalizedMessage();
Crashlytics.log(err_msg);
- mContext.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- Toast.makeText(mContext,
- mContext.getString(R.string.toast_error_importing_accounts) + "\n" + err_msg,
- Toast.LENGTH_LONG).show();
- }
- });
+ mContext.runOnUiThread(() -> Toast.makeText(mContext,
+ mContext.getString(R.string.toast_error_importing_accounts) + "\n" + err_msg,
+ Toast.LENGTH_LONG).show());
return false;
}
diff --git a/app/src/main/java/org/gnucash/android/model/Commodity.java b/app/src/main/java/org/gnucash/android/model/Commodity.java
index 7fa136989..702087d12 100644
--- a/app/src/main/java/org/gnucash/android/model/Commodity.java
+++ b/app/src/main/java/org/gnucash/android/model/Commodity.java
@@ -18,6 +18,8 @@
import org.gnucash.android.app.GnuCashApplication;
import org.gnucash.android.db.adapter.CommoditiesDbAdapter;
+import androidx.annotation.NonNull;
+
/**
* Commodities are the currencies used in the application.
* At the moment only ISO4217 currencies are supported
@@ -190,6 +192,7 @@ public void setQuoteFlag(int quoteFlag) {
this.mQuoteFlag = quoteFlag;
}
+ @NonNull
@Override
/**
* Returns the full name of the currency, or the currency code if there is no full name
diff --git a/app/src/main/java/org/gnucash/android/model/Money.java b/app/src/main/java/org/gnucash/android/model/Money.java
index 2ec44af29..774642a69 100644
--- a/app/src/main/java/org/gnucash/android/model/Money.java
+++ b/app/src/main/java/org/gnucash/android/model/Money.java
@@ -450,7 +450,8 @@ public String toLocaleString(){
* to the default locale
* @return String representation of the amount formatted with default locale
*/
- @Override
+ @NonNull
+ @Override
public String toString() {
return formattedString(Locale.getDefault());
}
@@ -506,7 +507,7 @@ public boolean isAmountZero() {
return mAmount.compareTo(BigDecimal.ZERO) == 0;
}
- public class CurrencyMismatchException extends IllegalArgumentException{
+ public static class CurrencyMismatchException extends IllegalArgumentException{
@Override
public String getMessage() {
return "Cannot perform operation on Money instances with different currencies";
diff --git a/app/src/main/java/org/gnucash/android/model/Price.java b/app/src/main/java/org/gnucash/android/model/Price.java
index 6c02e8d5e..30eb0ce72 100644
--- a/app/src/main/java/org/gnucash/android/model/Price.java
+++ b/app/src/main/java/org/gnucash/android/model/Price.java
@@ -8,6 +8,8 @@
import java.text.DecimalFormat;
import java.text.NumberFormat;
+import androidx.annotation.NonNull;
+
/**
* Model for commodity prices
*/
@@ -150,6 +152,7 @@ private void reduce() {
*
* Example: "0.123456"
*/
+ @NonNull
@Override
public String toString() {
BigDecimal numerator = new BigDecimal(mValueNum);
diff --git a/app/src/main/java/org/gnucash/android/model/ScheduledAction.java b/app/src/main/java/org/gnucash/android/model/ScheduledAction.java
index a8432532c..afb8352eb 100644
--- a/app/src/main/java/org/gnucash/android/model/ScheduledAction.java
+++ b/app/src/main/java/org/gnucash/android/model/ScheduledAction.java
@@ -593,6 +593,7 @@ public static ScheduledAction parseScheduledAction(Transaction transaction, long
return scheduledAction;
}
+ @NonNull
@Override
public String toString() {
return mActionType.name() + " - " + getRepeatString();
diff --git a/app/src/main/java/org/gnucash/android/model/Split.java b/app/src/main/java/org/gnucash/android/model/Split.java
index a16b8729c..5e37179ca 100644
--- a/app/src/main/java/org/gnucash/android/model/Split.java
+++ b/app/src/main/java/org/gnucash/android/model/Split.java
@@ -376,6 +376,7 @@ public void setReconcileDate(Timestamp reconcileDate) {
this.mReconcileDate = reconcileDate;
}
+ @NonNull
@Override
public String toString() {
diff --git a/app/src/main/java/org/gnucash/android/ui/account/AccountsListFragment.java b/app/src/main/java/org/gnucash/android/ui/account/AccountsListFragment.java
index 4d45bb639..24ee5b996 100644
--- a/app/src/main/java/org/gnucash/android/ui/account/AccountsListFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/account/AccountsListFragment.java
@@ -217,7 +217,7 @@ public void onResume() {
}
@Override
- public void onAttach(Activity activity) {
+ public void onAttach(@NonNull Activity activity) {
super.onAttach(activity);
try {
mAccountSelectedListener = (OnAccountClickedListener) activity;
@@ -271,7 +271,7 @@ public void showConfirmationDialog(long id) {
}
@Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
if (mParentAccountUID != null)
inflater.inflate(R.menu.sub_account_actions, menu);
else {
@@ -313,7 +313,7 @@ public void refresh() {
}
@Override
- public void onSaveInstanceState(Bundle outState) {
+ public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable(STATE_DISPLAY_MODE, mDisplayMode);
}
@@ -341,6 +341,7 @@ public void openCreateOrEditActivity(long accountId){
startActivityForResult(editAccountIntent, AccountsActivity.REQUEST_EDIT_ACCOUNT);
}
+ @NonNull
@Override
public Loader onCreateLoader(int id, Bundle args) {
Log.d(TAG, "Creating the accounts loader");
@@ -355,14 +356,14 @@ public Loader onCreateLoader(int id, Bundle args) {
}
@Override
- public void onLoadFinished(Loader loaderCursor, Cursor cursor) {
+ public void onLoadFinished(@NonNull Loader loaderCursor, Cursor cursor) {
Log.d(TAG, "Accounts loader finished. Swapping in cursor");
mAccountRecyclerAdapter.swapCursor(cursor);
mAccountRecyclerAdapter.notifyDataSetChanged();
}
@Override
- public void onLoaderReset(Loader arg0) {
+ public void onLoaderReset(@NonNull Loader arg0) {
Log.d(TAG, "Resetting the accounts loader");
mAccountRecyclerAdapter.swapCursor(null);
}
diff --git a/app/src/main/java/org/gnucash/android/ui/account/DeleteAccountDialogFragment.java b/app/src/main/java/org/gnucash/android/ui/account/DeleteAccountDialogFragment.java
index d7a457bd8..9366c1c9f 100644
--- a/app/src/main/java/org/gnucash/android/ui/account/DeleteAccountDialogFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/account/DeleteAccountDialogFragment.java
@@ -190,59 +190,39 @@ public void onActivityCreated(Bundle savedInstanceState) {
* Binds click listeners for the dialog buttons
*/
protected void setListeners(){
- mMoveAccountsRadioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- mAccountsDestinationAccountSpinner.setEnabled(isChecked);
- }
- });
-
- mMoveTransactionsRadioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- mTransactionsDestinationAccountSpinner.setEnabled(isChecked);
- }
- });
-
- mCancelButton.setOnClickListener(new View.OnClickListener() {
+ mMoveAccountsRadioButton.setOnCheckedChangeListener((buttonView, isChecked) -> mAccountsDestinationAccountSpinner.setEnabled(isChecked));
- @Override
- public void onClick(View v) {
- dismiss();
- }
- });
+ mMoveTransactionsRadioButton.setOnCheckedChangeListener((buttonView, isChecked) -> mTransactionsDestinationAccountSpinner.setEnabled(isChecked));
- mOkButton.setOnClickListener(new View.OnClickListener() {
+ mCancelButton.setOnClickListener(v -> dismiss());
- @Override
- public void onClick(View v) {
- BackupManager.backupActiveBook();
+ mOkButton.setOnClickListener(v -> {
+ BackupManager.backupActiveBook();
- AccountsDbAdapter accountsDbAdapter = AccountsDbAdapter.getInstance();
+ AccountsDbAdapter accountsDbAdapter = AccountsDbAdapter.getInstance();
- if ((mTransactionCount > 0) && mMoveTransactionsRadioButton.isChecked()){
- long targetAccountId = mTransactionsDestinationAccountSpinner.getSelectedItemId();
- //move all the splits
- SplitsDbAdapter.getInstance().updateRecords(DatabaseSchema.SplitEntry.COLUMN_ACCOUNT_UID + " = ?",
- new String[]{mOriginAccountUID}, DatabaseSchema.SplitEntry.COLUMN_ACCOUNT_UID, accountsDbAdapter.getUID(targetAccountId));
- }
+ if ((mTransactionCount > 0) && mMoveTransactionsRadioButton.isChecked()){
+ long targetAccountId = mTransactionsDestinationAccountSpinner.getSelectedItemId();
+ //move all the splits
+ SplitsDbAdapter.getInstance().updateRecords(DatabaseSchema.SplitEntry.COLUMN_ACCOUNT_UID + " = ?",
+ new String[]{mOriginAccountUID}, DatabaseSchema.SplitEntry.COLUMN_ACCOUNT_UID, accountsDbAdapter.getUID(targetAccountId));
+ }
- if ((mSubAccountCount > 0) && mMoveAccountsRadioButton.isChecked()){
- long targetAccountId = mAccountsDestinationAccountSpinner.getSelectedItemId();
- AccountsDbAdapter.getInstance().reassignDescendantAccounts(mOriginAccountUID, accountsDbAdapter.getUID(targetAccountId));
- }
+ if ((mSubAccountCount > 0) && mMoveAccountsRadioButton.isChecked()){
+ long targetAccountId = mAccountsDestinationAccountSpinner.getSelectedItemId();
+ AccountsDbAdapter.getInstance().reassignDescendantAccounts(mOriginAccountUID, accountsDbAdapter.getUID(targetAccountId));
+ }
- if (GnuCashApplication.isDoubleEntryEnabled()){ //reassign splits to imbalance
- TransactionsDbAdapter.getInstance().deleteTransactionsForAccount(mOriginAccountUID);
- }
+ if (GnuCashApplication.isDoubleEntryEnabled()){ //reassign splits to imbalance
+ TransactionsDbAdapter.getInstance().deleteTransactionsForAccount(mOriginAccountUID);
+ }
- //now kill them all!!
- accountsDbAdapter.recursiveDeleteAccount(accountsDbAdapter.getID(mOriginAccountUID));
+ //now kill them all!!
+ accountsDbAdapter.recursiveDeleteAccount(accountsDbAdapter.getID(mOriginAccountUID));
- WidgetConfigurationActivity.updateAllWidgets(getActivity());
- ((Refreshable)getTargetFragment()).refresh();
- dismiss();
- }
+ WidgetConfigurationActivity.updateAllWidgets(getActivity());
+ ((Refreshable)getTargetFragment()).refresh();
+ dismiss();
});
}
diff --git a/app/src/main/java/org/gnucash/android/ui/budget/BudgetAmountEditorFragment.java b/app/src/main/java/org/gnucash/android/ui/budget/BudgetAmountEditorFragment.java
index 8efe742f1..1a879ced5 100644
--- a/app/src/main/java/org/gnucash/android/ui/budget/BudgetAmountEditorFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/budget/BudgetAmountEditorFragment.java
@@ -47,6 +47,7 @@
import java.util.ArrayList;
import java.util.List;
+import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
@@ -114,7 +115,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
}
@Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.budget_amount_editor_actions, menu);
}
@@ -259,12 +260,9 @@ public void onNothingSelected(AdapterView> parent) {
}
});
- removeItemBtn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- mBudgetAmountTableLayout.removeView(itemView);
- mBudgetAmountViews.remove(itemView);
- }
+ removeItemBtn.setOnClickListener(v -> {
+ mBudgetAmountTableLayout.removeView(itemView);
+ mBudgetAmountViews.remove(itemView);
});
}
diff --git a/app/src/main/java/org/gnucash/android/ui/budget/BudgetDetailFragment.java b/app/src/main/java/org/gnucash/android/ui/budget/BudgetDetailFragment.java
index c7f90e71a..aae108b24 100644
--- a/app/src/main/java/org/gnucash/android/ui/budget/BudgetDetailFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/budget/BudgetDetailFragment.java
@@ -54,6 +54,7 @@
import java.util.ArrayList;
import java.util.List;
+import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
@@ -157,7 +158,7 @@ public void refresh(String budgetUID) {
}
@Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.budget_actions, menu);
}
@@ -194,8 +195,9 @@ public BudgetAmountAdapter(){
mBudgetAmounts = mBudget.getCompactedBudgetAmounts();
}
+ @NonNull
@Override
- public BudgetAmountViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+ public BudgetAmountViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(getActivity()).inflate(R.layout.cardview_budget_amount, parent, false);
return new BudgetAmountViewHolder(view);
}
@@ -228,13 +230,10 @@ public void onBindViewHolder(BudgetAmountViewHolder holder, final int position)
generateChartData(holder.budgetChart, budgetAmount);
- holder.itemView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent intent = new Intent(getActivity(), TransactionsActivity.class);
- intent.putExtra(UxArgument.SELECTED_ACCOUNT_UID, mBudgetAmounts.get(position).getAccountUID());
- startActivityForResult(intent, 0x10);
- }
+ holder.itemView.setOnClickListener(v -> {
+ Intent intent = new Intent(getActivity(), TransactionsActivity.class);
+ intent.putExtra(UxArgument.SELECTED_ACCOUNT_UID, mBudgetAmounts.get(position).getAccountUID());
+ startActivityForResult(intent, 0x10);
});
}
diff --git a/app/src/main/java/org/gnucash/android/ui/budget/BudgetFormFragment.java b/app/src/main/java/org/gnucash/android/ui/budget/BudgetFormFragment.java
index 1772886b1..97b23e020 100644
--- a/app/src/main/java/org/gnucash/android/ui/budget/BudgetFormFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/budget/BudgetFormFragment.java
@@ -66,6 +66,7 @@
import java.util.Date;
import java.util.GregorianCalendar;
+import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
@@ -262,7 +263,7 @@ private void saveBudget(){
}
@Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.default_save_actions, menu);
}
diff --git a/app/src/main/java/org/gnucash/android/ui/budget/BudgetListFragment.java b/app/src/main/java/org/gnucash/android/ui/budget/BudgetListFragment.java
index 7ac7308fd..2bd88b90d 100644
--- a/app/src/main/java/org/gnucash/android/ui/budget/BudgetListFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/budget/BudgetListFragment.java
@@ -51,6 +51,7 @@
import java.math.BigDecimal;
import java.math.RoundingMode;
+import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.PopupMenu;
@@ -113,6 +114,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
getLoaderManager().initLoader(0, null, this);
}
+ @NonNull
@Override
public Loader onCreateLoader(int id, Bundle args) {
Log.d(LOG_TAG, "Creating the accounts loader");
@@ -120,14 +122,14 @@ public Loader onCreateLoader(int id, Bundle args) {
}
@Override
- public void onLoadFinished(Loader loaderCursor, Cursor cursor) {
+ public void onLoadFinished(@NonNull Loader loaderCursor, Cursor cursor) {
Log.d(LOG_TAG, "Budget loader finished. Swapping in cursor");
mBudgetRecyclerAdapter.swapCursor(cursor);
mBudgetRecyclerAdapter.notifyDataSetChanged();
}
@Override
- public void onLoaderReset(Loader arg0) {
+ public void onLoaderReset(@NonNull Loader arg0) {
Log.d(LOG_TAG, "Resetting the accounts loader");
mBudgetRecyclerAdapter.swapCursor(null);
}
@@ -243,14 +245,10 @@ public void onBindViewHolderCursor(BudgetViewHolder holder, Cursor cursor) {
holder.budgetAmount.setTextColor(BudgetsActivity.getBudgetProgressColor(1 - budgetProgress));
- holder.itemView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- onClickBudget(budget.getUID());
- }
- });
+ holder.itemView.setOnClickListener(v -> onClickBudget(budget.getUID()));
}
+ @NonNull
@Override
public BudgetViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
@@ -272,15 +270,12 @@ public BudgetViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
- optionsMenu.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- PopupMenu popup = new PopupMenu(getActivity(), v);
- popup.setOnMenuItemClickListener(BudgetViewHolder.this);
- MenuInflater inflater = popup.getMenuInflater();
- inflater.inflate(R.menu.budget_context_menu, popup.getMenu());
- popup.show();
- }
+ optionsMenu.setOnClickListener(v -> {
+ PopupMenu popup = new PopupMenu(getActivity(), v);
+ popup.setOnMenuItemClickListener(BudgetViewHolder.this);
+ MenuInflater inflater = popup.getMenuInflater();
+ inflater.inflate(R.menu.budget_context_menu, popup.getMenu());
+ popup.show();
});
}
diff --git a/app/src/main/java/org/gnucash/android/ui/colorpicker/ColorPickerDialog.java b/app/src/main/java/org/gnucash/android/ui/colorpicker/ColorPickerDialog.java
index db440600e..f673b6f66 100644
--- a/app/src/main/java/org/gnucash/android/ui/colorpicker/ColorPickerDialog.java
+++ b/app/src/main/java/org/gnucash/android/ui/colorpicker/ColorPickerDialog.java
@@ -27,6 +27,7 @@
import org.gnucash.android.R;
import org.gnucash.android.ui.colorpicker.ColorPickerSwatch.OnColorSelectedListener;
+import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
/**
@@ -101,6 +102,7 @@ public void onCreate(Bundle savedInstanceState) {
}
}
+ @NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Activity activity = getActivity();
@@ -195,7 +197,7 @@ public int getSelectedColor() {
}
@Override
- public void onSaveInstanceState(Bundle outState) {
+ public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putIntArray(KEY_COLORS, mColors);
outState.putSerializable(KEY_SELECTED_COLOR, mSelectedColor);
diff --git a/app/src/main/java/org/gnucash/android/ui/homescreen/WidgetConfigurationActivity.java b/app/src/main/java/org/gnucash/android/ui/homescreen/WidgetConfigurationActivity.java
index f02b6a6e9..bf606ac74 100644
--- a/app/src/main/java/org/gnucash/android/ui/homescreen/WidgetConfigurationActivity.java
+++ b/app/src/main/java/org/gnucash/android/ui/homescreen/WidgetConfigurationActivity.java
@@ -157,44 +157,34 @@ public void onNothingSelected(AdapterView> parent) {
}
});
- mOkButton.setOnClickListener(new View.OnClickListener() {
+ mOkButton.setOnClickListener(v -> {
+ Intent intent = getIntent();
+ Bundle extras = intent.getExtras();
+ if (extras != null) {
+ mAppWidgetId = extras.getInt(
+ AppWidgetManager.EXTRA_APPWIDGET_ID,
+ AppWidgetManager.INVALID_APPWIDGET_ID);
+ }
- @Override
- public void onClick(View v) {
- Intent intent = getIntent();
- Bundle extras = intent.getExtras();
- if (extras != null) {
- mAppWidgetId = extras.getInt(
- AppWidgetManager.EXTRA_APPWIDGET_ID,
- AppWidgetManager.INVALID_APPWIDGET_ID);
- }
-
- if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
- finish();
- return;
- }
-
- String bookUID = BooksDbAdapter.getInstance().getUID(mBooksSpinner.getSelectedItemId());
- String accountUID = mAccountsDbAdapter.getUID(mAccountsSpinner.getSelectedItemId());
- boolean hideAccountBalance = mHideAccountBalance.isChecked();
-
- configureWidget(WidgetConfigurationActivity.this, mAppWidgetId, bookUID, accountUID, hideAccountBalance);
- updateWidget(WidgetConfigurationActivity.this, mAppWidgetId);
-
- Intent resultValue = new Intent();
- resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
- setResult(RESULT_OK, resultValue);
+ if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
+ return;
}
- });
- mCancelButton.setOnClickListener(new View.OnClickListener() {
+ String bookUID = BooksDbAdapter.getInstance().getUID(mBooksSpinner.getSelectedItemId());
+ String accountUID = mAccountsDbAdapter.getUID(mAccountsSpinner.getSelectedItemId());
+ boolean hideAccountBalance = mHideAccountBalance.isChecked();
- @Override
- public void onClick(View v) {
- finish();
- }
+ configureWidget(WidgetConfigurationActivity.this, mAppWidgetId, bookUID, accountUID, hideAccountBalance);
+ updateWidget(WidgetConfigurationActivity.this, mAppWidgetId);
+
+ Intent resultValue = new Intent();
+ resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
+ setResult(RESULT_OK, resultValue);
+ finish();
});
+
+ mCancelButton.setOnClickListener(v -> finish());
}
/**
@@ -352,12 +342,9 @@ public static void updateAllWidgets(final Context context) {
//update widgets asynchronously so as not to block method which called the update
//inside the computation of the account balance
- new Thread(new Runnable() {
- @Override
- public void run() {
- for (final int widgetId : appWidgetIds) {
- updateWidget(context, widgetId);
- }
+ new Thread(() -> {
+ for (final int widgetId : appWidgetIds) {
+ updateWidget(context, widgetId);
}
}).start();
}
diff --git a/app/src/main/java/org/gnucash/android/ui/passcode/KeyboardFragment.java b/app/src/main/java/org/gnucash/android/ui/passcode/KeyboardFragment.java
index cfdeceee6..4fd8c22c6 100644
--- a/app/src/main/java/org/gnucash/android/ui/passcode/KeyboardFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/passcode/KeyboardFragment.java
@@ -26,6 +26,7 @@
import org.gnucash.android.R;
+import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
/**
@@ -59,86 +60,33 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
pass3 = rootView.findViewById(R.id.passcode3);
pass4 = rootView.findViewById(R.id.passcode4);
- rootView.findViewById(R.id.one_btn).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- add("1");
- }
- });
- rootView.findViewById(R.id.two_btn).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- add("2");
- }
- });
- rootView.findViewById(R.id.three_btn).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- add("3");
- }
- });
- rootView.findViewById(R.id.four_btn).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- add("4");
- }
- });
- rootView.findViewById(R.id.five_btn).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- add("5");
- }
- });
- rootView.findViewById(R.id.six_btn).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- add("6");
- }
- });
- rootView.findViewById(R.id.seven_btn).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- add("7");
- }
- });
- rootView.findViewById(R.id.eight_btn).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- add("8");
- }
- });
- rootView.findViewById(R.id.nine_btn).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- add("9");
- }
- });
- rootView.findViewById(R.id.zero_btn).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- add("0");
- }
- });
- rootView.findViewById(R.id.delete_btn).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- switch (length) {
- case 1:
- pass1.setText(null);
- length--;
- break;
- case 2:
- pass2.setText(null);
- length--;
- break;
- case 3:
- pass3.setText(null);
- length--;
- break;
- case 4:
- pass4.setText(null);
- length--;
- }
+ rootView.findViewById(R.id.one_btn).setOnClickListener(v -> add("1"));
+ rootView.findViewById(R.id.two_btn).setOnClickListener(v -> add("2"));
+ rootView.findViewById(R.id.three_btn).setOnClickListener(v -> add("3"));
+ rootView.findViewById(R.id.four_btn).setOnClickListener(v -> add("4"));
+ rootView.findViewById(R.id.five_btn).setOnClickListener(v -> add("5"));
+ rootView.findViewById(R.id.six_btn).setOnClickListener(v -> add("6"));
+ rootView.findViewById(R.id.seven_btn).setOnClickListener(v -> add("7"));
+ rootView.findViewById(R.id.eight_btn).setOnClickListener(v -> add("8"));
+ rootView.findViewById(R.id.nine_btn).setOnClickListener(v -> add("9"));
+ rootView.findViewById(R.id.zero_btn).setOnClickListener(v -> add("0"));
+ rootView.findViewById(R.id.delete_btn).setOnClickListener(v -> {
+ switch (length) {
+ case 1:
+ pass1.setText(null);
+ length--;
+ break;
+ case 2:
+ pass2.setText(null);
+ length--;
+ break;
+ case 3:
+ pass3.setText(null);
+ length--;
+ break;
+ case 4:
+ pass4.setText(null);
+ length--;
}
});
@@ -146,7 +94,7 @@ public void onClick(View v) {
}
@Override
- public void onAttach(Activity activity) {
+ public void onAttach(@NonNull Activity activity) {
super.onAttach(activity);
try {
listener = (OnPasscodeEnteredListener) activity;
@@ -174,16 +122,14 @@ private void add(String num) {
pass4.setText(num);
length++;
- new Handler().postDelayed(new Runnable() {
- public void run() {
- listener.onPasscodeEntered(pass1.getText().toString() + pass2.getText()
- + pass3.getText() + pass4.getText());
- pass1.setText(null);
- pass2.setText(null);
- pass3.setText(null);
- pass4.setText(null);
- length = 0;
- }
+ new Handler().postDelayed(() -> {
+ listener.onPasscodeEntered(pass1.getText().toString() + pass2.getText()
+ + pass3.getText() + pass4.getText());
+ pass1.setText(null);
+ pass2.setText(null);
+ pass3.setText(null);
+ pass4.setText(null);
+ length = 0;
}, DELAY);
}
}
diff --git a/app/src/main/java/org/gnucash/android/ui/report/BaseReportFragment.java b/app/src/main/java/org/gnucash/android/ui/report/BaseReportFragment.java
index c5d48d31a..d09bc4a60 100644
--- a/app/src/main/java/org/gnucash/android/ui/report/BaseReportFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/report/BaseReportFragment.java
@@ -41,6 +41,7 @@
import org.joda.time.Years;
import androidx.annotation.LayoutRes;
+import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.app.ActionBar;
@@ -204,7 +205,7 @@ public void onResume() {
}
@Override
- public void onAttach(Context context) {
+ public void onAttach(@NonNull Context context) {
super.onAttach(context);
if (!(getActivity() instanceof ReportsActivity))
throw new RuntimeException("Report fragments can only be used with the ReportsActivity");
@@ -266,7 +267,7 @@ protected int getQuarter(LocalDateTime date) {
@Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.chart_actions, menu);
}
diff --git a/app/src/main/java/org/gnucash/android/ui/report/ReportType.java b/app/src/main/java/org/gnucash/android/ui/report/ReportType.java
index 4070f4548..420a3875c 100644
--- a/app/src/main/java/org/gnucash/android/ui/report/ReportType.java
+++ b/app/src/main/java/org/gnucash/android/ui/report/ReportType.java
@@ -127,7 +127,7 @@ public List getReportNames(){
//
//
- mReportNames = new ArrayList();
+ mReportNames = new ArrayList<>();
mReportNames.add(context.getString(R.string.title_pie_chart));
mReportNames.add(context.getString(R.string.title_bar_chart));
diff --git a/app/src/main/java/org/gnucash/android/ui/report/ReportsActivity.java b/app/src/main/java/org/gnucash/android/ui/report/ReportsActivity.java
index 513ffcea6..d0f004390 100644
--- a/app/src/main/java/org/gnucash/android/ui/report/ReportsActivity.java
+++ b/app/src/main/java/org/gnucash/android/ui/report/ReportsActivity.java
@@ -23,6 +23,7 @@
import android.os.Build;
import android.os.Bundle;
+import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.core.content.ContextCompat;
@@ -177,7 +178,7 @@ public void onNothingSelected(AdapterView> adapterView) {
}
@Override
- public void onAttachFragment(Fragment fragment) {
+ public void onAttachFragment(@NonNull Fragment fragment) {
super.onAttachFragment(fragment);
if (fragment instanceof BaseReportFragment) {
@@ -224,7 +225,7 @@ public void updateReportTypeSpinner(ReportType reportType, String reportName) {
@Override
public View getView(final int position,
final View convertView,
- final ViewGroup parent) {
+ @NonNull final ViewGroup parent) {
View view = super.getView(position,
convertView,
@@ -480,7 +481,7 @@ public void refresh(String uid) {
}
@Override
- protected void onSaveInstanceState(Bundle outState) {
+ protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable(STATE_REPORT_TYPE, mReportType);
diff --git a/app/src/main/java/org/gnucash/android/ui/report/sheet/BalanceSheetFragment.java b/app/src/main/java/org/gnucash/android/ui/report/sheet/BalanceSheetFragment.java
index 7d0488237..ad1b6308f 100644
--- a/app/src/main/java/org/gnucash/android/ui/report/sheet/BalanceSheetFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/report/sheet/BalanceSheetFragment.java
@@ -35,6 +35,7 @@
import java.util.List;
+import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import butterknife.BindView;
@@ -108,7 +109,7 @@ protected void displayReport() {
}
@Override
- public void onPrepareOptionsMenu(Menu menu) {
+ public void onPrepareOptionsMenu(@NonNull Menu menu) {
super.onPrepareOptionsMenu(menu);
menu.findItem(R.id.menu_group_reports_by).setVisible(false);
}
diff --git a/app/src/main/java/org/gnucash/android/ui/settings/AboutPreferenceFragment.java b/app/src/main/java/org/gnucash/android/ui/settings/AboutPreferenceFragment.java
index 5d71743e6..eefc576d0 100644
--- a/app/src/main/java/org/gnucash/android/ui/settings/AboutPreferenceFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/settings/AboutPreferenceFragment.java
@@ -57,12 +57,9 @@ public void onResume() {
if (BuildConfig.FLAVOR.equals("development")) {
pref.setSummary(pref.getSummary() + " - Built: " + BuildConfig.BUILD_TIME);
}
- pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- AccountsActivity.showWhatsNewDialog(getActivity());
- return true;
- }
+ pref.setOnPreferenceClickListener(preference -> {
+ AccountsActivity.showWhatsNewDialog(getActivity());
+ return true;
});
}
}
\ No newline at end of file
diff --git a/app/src/main/java/org/gnucash/android/ui/settings/AccountPreferencesFragment.java b/app/src/main/java/org/gnucash/android/ui/settings/AccountPreferencesFragment.java
index 7ada09c0c..73ccf002e 100644
--- a/app/src/main/java/org/gnucash/android/ui/settings/AccountPreferencesFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/settings/AccountPreferencesFragment.java
@@ -124,18 +124,8 @@ public void onResume() {
.setTitle(R.string.title_create_default_accounts)
.setMessage(R.string.msg_confirm_create_default_accounts_setting)
.setIcon(R.drawable.ic_warning_black_24dp)
- .setPositiveButton(R.string.btn_create_accounts, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- AccountsActivity.createDefaultAccounts(Money.DEFAULT_CURRENCY_CODE, getActivity());
- }
- })
- .setNegativeButton(R.string.btn_cancel, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- dialogInterface.dismiss();
- }
- })
+ .setPositiveButton(R.string.btn_create_accounts, (dialogInterface, i) -> AccountsActivity.createDefaultAccounts(Money.DEFAULT_CURRENCY_CODE, getActivity()))
+ .setNegativeButton(R.string.btn_cancel, (dialogInterface, i) -> dialogInterface.dismiss())
.create()
.show();
diff --git a/app/src/main/java/org/gnucash/android/ui/settings/BackupPreferenceFragment.java b/app/src/main/java/org/gnucash/android/ui/settings/BackupPreferenceFragment.java
index d4723f99a..6853f08da 100644
--- a/app/src/main/java/org/gnucash/android/ui/settings/BackupPreferenceFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/settings/BackupPreferenceFragment.java
@@ -19,7 +19,6 @@
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentSender;
import android.content.SharedPreferences;
@@ -33,9 +32,7 @@
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
-import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.drive.Drive;
-import com.google.android.gms.drive.DriveFolder;
import com.google.android.gms.drive.MetadataChangeSet;
import org.gnucash.android.R;
@@ -109,6 +106,7 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar = ((AppCompatActivity)getActivity()).getSupportActionBar();
+ assert actionBar != null;
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(R.string.title_backup_prefs);
@@ -126,9 +124,10 @@ public void onResume() {
String keyDefaultEmail = getString(R.string.key_default_export_email);
Preference pref = findPreference(keyDefaultEmail);
+ assert pref != null;
String defaultEmail = sharedPrefs.getString(keyDefaultEmail, null);
if (defaultEmail != null && !defaultEmail.trim().isEmpty()){
- pref.setSummary(defaultEmail);
+ pref.setSummary(defaultEmail);
}
pref.setOnPreferenceChangeListener(this);
@@ -313,23 +312,19 @@ public void onConnected(Bundle bundle) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
String appFolderId = sharedPreferences.getString(context.getString(R.string.key_google_drive_app_folder_id), null);
if (appFolderId == null) {
- MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
- .setTitle(context.getString(R.string.app_name)).build();
+ MetadataChangeSet changeSet = new MetadataChangeSet.Builder().setTitle(context.getString(R.string.app_name)).build();
Drive.DriveApi.getRootFolder(mGoogleApiClient).createFolder(
- mGoogleApiClient, changeSet).setResultCallback(new ResultCallback() {
- @Override
- public void onResult(DriveFolder.DriveFolderResult result) {
- if (!result.getStatus().isSuccess()) {
- Log.e(LOG_TAG, "Error creating the application folder");
- return;
- }
-
- String folderId = result.getDriveFolder().getDriveId().toString();
- PreferenceManager.getDefaultSharedPreferences(context)
- .edit().putString(context.getString(R.string.key_google_drive_app_folder_id),
- folderId).commit(); //commit because we need it to be saved *now*
- }
- });
+ mGoogleApiClient, changeSet).setResultCallback(result -> {
+ if (!result.getStatus().isSuccess()) {
+ Log.e(LOG_TAG, "Error creating the application folder");
+ return;
+ }
+
+ String folderId = result.getDriveFolder().getDriveId().toString();
+ PreferenceManager.getDefaultSharedPreferences(context)
+ .edit().putString(context.getString(R.string.key_google_drive_app_folder_id),
+ folderId).commit(); //commit because we need it to be saved *now*
+ });
}
Toast.makeText(context, R.string.toast_connected_to_google_drive, Toast.LENGTH_SHORT).show();
@@ -340,24 +335,21 @@ public void onConnectionSuspended(int i) {
Toast.makeText(context, "Connection to Google Drive suspended!", Toast.LENGTH_LONG).show();
}
})
- .addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
- @Override
- public void onConnectionFailed(ConnectionResult connectionResult) {
- Log.e(PreferenceActivity.class.getName(), "Connection to Google Drive failed");
- if (connectionResult.hasResolution() && context instanceof Activity) {
- try {
- Log.e(BackupPreferenceFragment.class.getName(), "Trying resolution of Google API connection failure");
- connectionResult.startResolutionForResult((Activity) context, REQUEST_RESOLVE_CONNECTION);
- } catch (IntentSender.SendIntentException e) {
- Log.e(BackupPreferenceFragment.class.getName(), e.getMessage());
- Toast.makeText(context, R.string.toast_unable_to_connect_to_google_drive, Toast.LENGTH_LONG).show();
- }
- } else {
- if (context instanceof Activity)
- GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), (Activity) context, 0).show();
- }
- }
- })
+ .addOnConnectionFailedListener(connectionResult -> {
+ Log.e(PreferenceActivity.class.getName(), "Connection to Google Drive failed");
+ if (connectionResult.hasResolution() && context instanceof Activity) {
+ try {
+ Log.e(BackupPreferenceFragment.class.getName(), "Trying resolution of Google API connection failure");
+ connectionResult.startResolutionForResult((Activity) context, REQUEST_RESOLVE_CONNECTION);
+ } catch (IntentSender.SendIntentException e) {
+ Log.e(BackupPreferenceFragment.class.getName(), e.getMessage());
+ Toast.makeText(context, R.string.toast_unable_to_connect_to_google_drive, Toast.LENGTH_LONG).show();
+ }
+ } else {
+ if (context instanceof Activity)
+ GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), (Activity) context, 0).show();
+ }
+ })
.build();
}
@@ -373,18 +365,8 @@ private void restoreBackup() {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
.setTitle(R.string.title_confirm_restore_backup)
.setMessage(R.string.msg_confirm_restore_backup_into_new_book)
- .setNegativeButton(R.string.btn_cancel, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.dismiss();
- }
- })
- .setPositiveButton(R.string.btn_restore, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- new ImportAsyncTask(getActivity()).execute(Uri.parse(defaultBackupFile));
- }
- });
+ .setNegativeButton(R.string.btn_cancel, (dialog, which) -> dialog.dismiss())
+ .setPositiveButton(R.string.btn_restore, (dialogInterface, i) -> new ImportAsyncTask(getActivity()).execute(Uri.parse(defaultBackupFile)));
builder.create().show();
return; //stop here if the default backup file exists
}
@@ -394,12 +376,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
.setTitle(R.string.title_no_backups_found)
.setMessage(R.string.msg_no_backups_to_restore_from)
- .setNegativeButton(R.string.label_dismiss, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.dismiss();
- }
- });
+ .setNegativeButton(R.string.label_dismiss, (dialog, which) -> dialog.dismiss());
builder.create().show();
return;
}
@@ -417,19 +394,10 @@ public void onClick(DialogInterface dialog, int which) {
AlertDialog.Builder restoreDialogBuilder = new AlertDialog.Builder(getActivity());
restoreDialogBuilder.setTitle(R.string.title_select_backup_to_restore);
- restoreDialogBuilder.setNegativeButton(R.string.alert_dialog_cancel,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.dismiss();
- }
- });
- restoreDialogBuilder.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- File backupFile = BackupManager.getBackupList(bookUID).get(which);
- new ImportAsyncTask(getActivity()).execute(Uri.fromFile(backupFile));
- }
+ restoreDialogBuilder.setNegativeButton(R.string.alert_dialog_cancel, (dialog, which) -> dialog.dismiss());
+ restoreDialogBuilder.setAdapter(arrayAdapter, (dialog, which) -> {
+ File backupFile = BackupManager.getBackupList(bookUID).get(which);
+ new ImportAsyncTask(getActivity()).execute(Uri.fromFile(backupFile));
});
restoreDialogBuilder.create().show();
diff --git a/app/src/main/java/org/gnucash/android/ui/settings/BookManagerFragment.java b/app/src/main/java/org/gnucash/android/ui/settings/BookManagerFragment.java
index ae597f623..1b83f0da7 100644
--- a/app/src/main/java/org/gnucash/android/ui/settings/BookManagerFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/settings/BookManagerFragment.java
@@ -17,7 +17,6 @@
package org.gnucash.android.ui.settings;
import android.content.Context;
-import android.content.DialogInterface;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
@@ -50,6 +49,7 @@
import java.sql.Timestamp;
+import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
@@ -108,7 +108,7 @@ public void onResume() {
}
@Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.book_list_actions, menu);
}
@@ -135,6 +135,7 @@ public void refresh(String uid) {
refresh();
}
+ @NonNull
@Override
public Loader onCreateLoader(int id, Bundle args) {
Log.d(LOG_TAG, "Creating loader for books");
@@ -142,14 +143,14 @@ public Loader onCreateLoader(int id, Bundle args) {
}
@Override
- public void onLoadFinished(Loader loader, Cursor data) {
+ public void onLoadFinished(@NonNull Loader loader, Cursor data) {
Log.d(LOG_TAG, "Finished loading books from database");
mCursorAdapter.swapCursor(data);
mCursorAdapter.notifyDataSetChanged();
}
@Override
- public void onLoaderReset(Loader loader) {
+ public void onLoaderReset(@NonNull Loader loader) {
Log.d(LOG_TAG, "Resetting books list loader");
mCursorAdapter.swapCursor(null);
}
@@ -170,13 +171,10 @@ public void bindView(View view, final Context context, Cursor cursor) {
setStatisticsText(view, bookUID);
setUpMenu(view, context, cursor, bookUID);
- view.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- //do nothing if the active book is tapped
- if (!BooksDbAdapter.getInstance().getActiveBookUID().equals(bookUID)) {
- BookUtils.loadBook(bookUID);
- }
+ view.setOnClickListener(v -> {
+ //do nothing if the active book is tapped
+ if (!BooksDbAdapter.getInstance().getActiveBookUID().equals(bookUID)) {
+ BookUtils.loadBook(bookUID);
}
});
}
@@ -185,36 +183,30 @@ private void setUpMenu(View view, final Context context, Cursor cursor, final St
final String bookName = cursor.getString(
cursor.getColumnIndexOrThrow(BookEntry.COLUMN_DISPLAY_NAME));
ImageView optionsMenu = view.findViewById(R.id.options_menu);
- optionsMenu.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- PopupMenu popupMenu = new PopupMenu(context, v);
- MenuInflater menuInflater = popupMenu.getMenuInflater();
- menuInflater.inflate(R.menu.book_context_menu, popupMenu.getMenu());
-
- popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
- @Override
- public boolean onMenuItemClick(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.ctx_menu_rename_book:
- return handleMenuRenameBook(bookName, bookUID);
- case R.id.ctx_menu_sync_book:
- //TODO implement sync
- return false;
- case R.id.ctx_menu_delete_book:
- return handleMenuDeleteBook(bookUID);
- default:
- return true;
- }
- }
- });
-
- String activeBookUID = BooksDbAdapter.getInstance().getActiveBookUID();
- if (activeBookUID.equals(bookUID)) {//we cannot delete the active book
- popupMenu.getMenu().findItem(R.id.ctx_menu_delete_book).setEnabled(false);
+ optionsMenu.setOnClickListener(v -> {
+ PopupMenu popupMenu = new PopupMenu(context, v);
+ MenuInflater menuInflater = popupMenu.getMenuInflater();
+ menuInflater.inflate(R.menu.book_context_menu, popupMenu.getMenu());
+
+ popupMenu.setOnMenuItemClickListener(item -> {
+ switch (item.getItemId()) {
+ case R.id.ctx_menu_rename_book:
+ return handleMenuRenameBook(bookName, bookUID);
+ case R.id.ctx_menu_sync_book:
+ //TODO implement sync
+ return false;
+ case R.id.ctx_menu_delete_book:
+ return handleMenuDeleteBook(bookUID);
+ default:
+ return true;
}
- popupMenu.show();
+ });
+
+ String activeBookUID = BooksDbAdapter.getInstance().getActiveBookUID();
+ if (activeBookUID.equals(bookUID)) {//we cannot delete the active book
+ popupMenu.getMenu().findItem(R.id.ctx_menu_delete_book).setEnabled(false);
}
+ popupMenu.show();
});
}
@@ -236,23 +228,15 @@ private boolean handleMenuRenameBook(String bookName, final String bookUID) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
dialogBuilder.setTitle(R.string.title_rename_book)
.setView(R.layout.dialog_rename_book)
- .setPositiveButton(R.string.btn_rename, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- EditText bookTitle = ((AlertDialog) dialog).findViewById(R.id.input_book_title);
- BooksDbAdapter.getInstance()
- .updateRecord(bookUID,
- BookEntry.COLUMN_DISPLAY_NAME,
- bookTitle.getText().toString().trim());
- refresh();
- }
+ .setPositiveButton(R.string.btn_rename, (dialog, which) -> {
+ EditText bookTitle = ((AlertDialog) dialog).findViewById(R.id.input_book_title);
+ BooksDbAdapter.getInstance()
+ .updateRecord(bookUID,
+ BookEntry.COLUMN_DISPLAY_NAME,
+ bookTitle.getText().toString().trim());
+ refresh();
})
- .setNegativeButton(R.string.btn_cancel, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.dismiss();
- }
- });
+ .setNegativeButton(R.string.btn_cancel, (dialog, which) -> dialog.dismiss());
AlertDialog dialog = dialogBuilder.create();
dialog.show();
((TextView) dialog.findViewById(R.id.input_book_title)).setText(bookName);
diff --git a/app/src/main/java/org/gnucash/android/ui/settings/GeneralPreferenceFragment.java b/app/src/main/java/org/gnucash/android/ui/settings/GeneralPreferenceFragment.java
index 75bc60fe3..9220302e3 100644
--- a/app/src/main/java/org/gnucash/android/ui/settings/GeneralPreferenceFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/settings/GeneralPreferenceFragment.java
@@ -82,18 +82,15 @@ public void onResume() {
mCheckBoxPreference = findPreference(getString(R.string.key_enable_passcode));
assert mCheckBoxPreference != null;
- mCheckBoxPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- if ((Boolean) newValue) {
- startActivityForResult(intent, PASSCODE_REQUEST_CODE);
- } else {
- Intent passIntent = new Intent(getActivity(), PasscodeLockScreenActivity.class);
- passIntent.putExtra(UxArgument.DISABLE_PASSCODE, UxArgument.DISABLE_PASSCODE);
- startActivityForResult(passIntent, REQUEST_DISABLE_PASSCODE);
- }
- return true;
+ mCheckBoxPreference.setOnPreferenceChangeListener((preference, newValue) -> {
+ if ((Boolean) newValue) {
+ startActivityForResult(intent, PASSCODE_REQUEST_CODE);
+ } else {
+ Intent passIntent = new Intent(getActivity(), PasscodeLockScreenActivity.class);
+ passIntent.putExtra(UxArgument.DISABLE_PASSCODE, UxArgument.DISABLE_PASSCODE);
+ startActivityForResult(passIntent, REQUEST_DISABLE_PASSCODE);
}
+ return true;
});
findPreference(getString(R.string.key_change_passcode)).setOnPreferenceClickListener(this);
}
diff --git a/app/src/main/java/org/gnucash/android/ui/settings/PreferenceActivity.java b/app/src/main/java/org/gnucash/android/ui/settings/PreferenceActivity.java
index a9e9ba7b1..509cabd7d 100644
--- a/app/src/main/java/org/gnucash/android/ui/settings/PreferenceActivity.java
+++ b/app/src/main/java/org/gnucash/android/ui/settings/PreferenceActivity.java
@@ -47,8 +47,7 @@ public class PreferenceActivity extends PasscodeLockActivity implements
public static final String ACTION_MANAGE_BOOKS = "org.gnucash.android.intent.action.MANAGE_BOOKS";
- @BindView(R.id.slidingpane_layout)
- SlidingPaneLayout mSlidingPaneLayout;
+ @BindView(R.id.slidingpane_layout) SlidingPaneLayout mSlidingPaneLayout;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -128,8 +127,7 @@ public boolean onPreferenceStartFragment(PreferenceFragmentCompat caller, Prefer
*/
private void loadFragment(Fragment fragment) {
FragmentManager fragmentManager = getSupportFragmentManager();
- FragmentTransaction fragmentTransaction = fragmentManager
- .beginTransaction();
+ FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();
diff --git a/app/src/main/java/org/gnucash/android/ui/settings/TransactionsPreferenceFragment.java b/app/src/main/java/org/gnucash/android/ui/settings/TransactionsPreferenceFragment.java
index 5b0c50849..94b902742 100644
--- a/app/src/main/java/org/gnucash/android/ui/settings/TransactionsPreferenceFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/settings/TransactionsPreferenceFragment.java
@@ -76,12 +76,10 @@ public void onResume() {
//
String keyDefaultTransactionType = getString(R.string.key_default_transaction_type);
- String defaultTransactionTypeKey = sharedPreferences.getString(keyDefaultTransactionType,
- AccountType.KEY_USE_NORMAL_BALANCE_EXPENSE);
+ String defaultTransactionTypeKey = sharedPreferences.getString(keyDefaultTransactionType, AccountType.KEY_USE_NORMAL_BALANCE_EXPENSE);
Preference pref = findPreference(keyDefaultTransactionType);
- setPrefSummary(pref,
- defaultTransactionTypeKey);
+ setPrefSummary(pref, defaultTransactionTypeKey);
pref.setOnPreferenceChangeListener(this);
@@ -97,7 +95,8 @@ public void onResume() {
//
String keyCompactView = getString(R.string.key_use_compact_list);
- SwitchPreferenceCompat switchPref = (SwitchPreferenceCompat) findPreference(keyCompactView);
+ SwitchPreferenceCompat switchPref = findPreference(keyCompactView);
+ assert switchPref != null;
switchPref.setChecked(sharedPreferences.getBoolean(keyCompactView, false));
//
@@ -105,7 +104,8 @@ public void onResume() {
//
String keyDisplayNegativeSignumInSplits = getString(R.string.key_display_negative_signum_in_splits);
- switchPref = (SwitchPreferenceCompat) findPreference(keyDisplayNegativeSignumInSplits);
+ switchPref = findPreference(keyDisplayNegativeSignumInSplits);
+ assert switchPref != null;
switchPref.setChecked(sharedPreferences.getBoolean(keyDisplayNegativeSignumInSplits,
false));
switchPref.setOnPreferenceChangeListener(this);
@@ -115,21 +115,18 @@ public void onResume() {
//
String keySaveBalance = getString(R.string.key_save_opening_balances);
- switchPref = (SwitchPreferenceCompat) findPreference(keySaveBalance);
+ switchPref = findPreference(keySaveBalance);
switchPref.setChecked(sharedPreferences.getBoolean(keySaveBalance, false));
String keyDoubleEntry = getString(R.string.key_use_double_entry);
- switchPref = (SwitchPreferenceCompat) findPreference(keyDoubleEntry);
+ switchPref = findPreference(keyDoubleEntry);
switchPref.setChecked(sharedPreferences.getBoolean(keyDoubleEntry, true));
Preference preference = findPreference(getString(R.string.key_delete_all_transactions));
- preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- showDeleteTransactionsDialog();
- return true;
- }
- });
+ preference.setOnPreferenceClickListener(preference1 -> {
+ showDeleteTransactionsDialog();
+ return true;
+ });
}
@Override
@@ -142,25 +139,21 @@ public boolean onPreferenceChange(Preference preference,
// Preference : key_default_transaction_type
//
- if (preference.getKey()
- .equals(getString(R.string.key_default_transaction_type))) {
+ if (preference.getKey().equals(getString(R.string.key_default_transaction_type))) {
// Store the new value of the Preference
sharedPreferences.edit()
- .putString(getString(R.string.key_default_transaction_type),
- newValue.toString())
- .commit();
+ .putString(getString(R.string.key_default_transaction_type), newValue.toString())
+ .apply();
- setPrefSummary(preference,
- ((String) newValue));
+ setPrefSummary(preference, ((String) newValue));
}
//
// Preference : key_use_double_entry
//
- if (preference.getKey()
- .equals(getString(R.string.key_use_double_entry))) {
+ if (preference.getKey().equals(getString(R.string.key_use_double_entry))) {
boolean useDoubleEntry = (Boolean) newValue;
setImbalanceAccountsHidden(useDoubleEntry);
@@ -171,14 +164,12 @@ public boolean onPreferenceChange(Preference preference,
// Preference : key_display_negative_signum_in_splits
//
- if (preference.getKey()
- .equals(getString(R.string.key_display_negative_signum_in_splits))) {
+ if (preference.getKey().equals(getString(R.string.key_display_negative_signum_in_splits))) {
// Store the new value of the Preference
sharedPreferences.edit()
- .putBoolean(getString(R.string.key_display_negative_signum_in_splits),
- Boolean.parseBoolean(newValue.toString()))
- .commit();
+ .putBoolean(getString(R.string.key_display_negative_signum_in_splits), Boolean.parseBoolean(newValue.toString()))
+ .apply();
}
return true;
@@ -225,8 +216,7 @@ private void setPrefSummary(Preference preference,
: AccountType.KEY_DEBIT.equals(defaultTransactionTypeKey)
? getString(R.string.label_debit)
: getString(R.string.label_credit);
-
-
+
preference.setSummary(localizedLabel);
}
diff --git a/app/src/main/java/org/gnucash/android/ui/settings/dialog/DeleteAllAccountsConfirmationDialog.java b/app/src/main/java/org/gnucash/android/ui/settings/dialog/DeleteAllAccountsConfirmationDialog.java
index b01c7881e..18278cd7b 100644
--- a/app/src/main/java/org/gnucash/android/ui/settings/dialog/DeleteAllAccountsConfirmationDialog.java
+++ b/app/src/main/java/org/gnucash/android/ui/settings/dialog/DeleteAllAccountsConfirmationDialog.java
@@ -18,7 +18,6 @@
import android.app.Dialog;
import android.content.Context;
-import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.Toast;
@@ -27,6 +26,8 @@
import org.gnucash.android.ui.homescreen.WidgetConfigurationActivity;
import org.gnucash.android.util.BackupManager;
+import androidx.annotation.NonNull;
+
/**
* Confirmation dialog for deleting all accounts from the system.
* This class currently only works with HONEYCOMB and above.
@@ -40,20 +41,19 @@ public static DeleteAllAccountsConfirmationDialog newInstance() {
return frag;
}
+ @NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return getDialogBuilder()
.setIcon(android.R.drawable.ic_delete)
.setTitle(R.string.title_confirm_delete).setMessage(R.string.confirm_delete_all_accounts)
.setPositiveButton(R.string.alert_dialog_ok_delete,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- Context context = getDialog().getContext();
- BackupManager.backupActiveBook();
- AccountsDbAdapter.getInstance().deleteAllRecords();
- Toast.makeText(context, R.string.toast_all_accounts_deleted, Toast.LENGTH_SHORT).show();
- WidgetConfigurationActivity.updateAllWidgets(context);
- }
+ (dialog, whichButton) -> {
+ Context context = getDialog().getContext();
+ BackupManager.backupActiveBook();
+ AccountsDbAdapter.getInstance().deleteAllRecords();
+ Toast.makeText(context, R.string.toast_all_accounts_deleted, Toast.LENGTH_SHORT).show();
+ WidgetConfigurationActivity.updateAllWidgets(context);
}
)
.create();
diff --git a/app/src/main/java/org/gnucash/android/ui/settings/dialog/DeleteAllTransactionsConfirmationDialog.java b/app/src/main/java/org/gnucash/android/ui/settings/dialog/DeleteAllTransactionsConfirmationDialog.java
index 840aa0cde..96f00d16b 100644
--- a/app/src/main/java/org/gnucash/android/ui/settings/dialog/DeleteAllTransactionsConfirmationDialog.java
+++ b/app/src/main/java/org/gnucash/android/ui/settings/dialog/DeleteAllTransactionsConfirmationDialog.java
@@ -18,7 +18,6 @@
import android.app.Dialog;
import android.content.Context;
-import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
@@ -56,27 +55,25 @@ public static DeleteAllTransactionsConfirmationDialog newInstance() {
.setIcon(android.R.drawable.ic_delete)
.setTitle(R.string.title_confirm_delete).setMessage(R.string.msg_delete_all_transactions_confirmation)
.setPositiveButton(R.string.alert_dialog_ok_delete,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- BackupManager.backupActiveBook();
+ (dialog, whichButton) -> {
+ BackupManager.backupActiveBook();
- Context context = getActivity();
- AccountsDbAdapter accountsDbAdapter = AccountsDbAdapter.getInstance();
- List openingBalances = new ArrayList<>();
- boolean preserveOpeningBalances = GnuCashApplication.shouldSaveOpeningBalances(false);
- if (preserveOpeningBalances) {
- openingBalances = accountsDbAdapter.getAllOpeningBalanceTransactions();
- }
- TransactionsDbAdapter transactionsDbAdapter = TransactionsDbAdapter.getInstance();
- int count = transactionsDbAdapter.deleteAllNonTemplateTransactions();
- Log.i("DeleteDialog", String.format("Deleted %d transactions successfully", count));
+ Context context = getActivity();
+ AccountsDbAdapter accountsDbAdapter = AccountsDbAdapter.getInstance();
+ List openingBalances = new ArrayList<>();
+ boolean preserveOpeningBalances = GnuCashApplication.shouldSaveOpeningBalances(false);
+ if (preserveOpeningBalances) {
+ openingBalances = accountsDbAdapter.getAllOpeningBalanceTransactions();
+ }
+ TransactionsDbAdapter transactionsDbAdapter = TransactionsDbAdapter.getInstance();
+ int count = transactionsDbAdapter.deleteAllNonTemplateTransactions();
+ Log.i("DeleteDialog", String.format("Deleted %d transactions successfully", count));
- if (preserveOpeningBalances) {
- transactionsDbAdapter.bulkAddRecords(openingBalances, DatabaseAdapter.UpdateMethod.insert);
- }
- Toast.makeText(context, R.string.toast_all_transactions_deleted, Toast.LENGTH_SHORT).show();
- WidgetConfigurationActivity.updateAllWidgets(getActivity());
+ if (preserveOpeningBalances) {
+ transactionsDbAdapter.bulkAddRecords(openingBalances, DatabaseAdapter.UpdateMethod.insert);
}
+ Toast.makeText(context, R.string.toast_all_transactions_deleted, Toast.LENGTH_SHORT).show();
+ WidgetConfigurationActivity.updateAllWidgets(getActivity());
}
).create();
diff --git a/app/src/main/java/org/gnucash/android/ui/settings/dialog/DeleteBookConfirmationDialog.java b/app/src/main/java/org/gnucash/android/ui/settings/dialog/DeleteBookConfirmationDialog.java
index 65366b3f7..75ec182b5 100644
--- a/app/src/main/java/org/gnucash/android/ui/settings/dialog/DeleteBookConfirmationDialog.java
+++ b/app/src/main/java/org/gnucash/android/ui/settings/dialog/DeleteBookConfirmationDialog.java
@@ -17,7 +17,6 @@
package org.gnucash.android.ui.settings.dialog;
import android.app.Dialog;
-import android.content.DialogInterface;
import android.os.Bundle;
import org.gnucash.android.R;
@@ -49,15 +48,11 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
.setTitle(R.string.title_confirm_delete_book)
.setIcon(R.drawable.ic_close_black_24dp)
.setMessage(R.string.msg_all_book_data_will_be_deleted)
- .setPositiveButton(R.string.btn_delete_book, new DialogInterface.OnClickListener() {
- @SuppressWarnings("ConstantConditions")
- @Override
- public void onClick(DialogInterface dialogInterface, int which) {
- final String bookUID = getArguments().getString("bookUID");
- BackupManager.backupBook(bookUID);
- BooksDbAdapter.getInstance().deleteBook(bookUID);
- ((Refreshable) getTargetFragment()).refresh();
- }
+ .setPositiveButton(R.string.btn_delete_book, (dialogInterface, which) -> {
+ final String bookUID = getArguments().getString("bookUID");
+ BackupManager.backupBook(bookUID);
+ BooksDbAdapter.getInstance().deleteBook(bookUID);
+ ((Refreshable) getTargetFragment()).refresh();
})
.create();
}
diff --git a/app/src/main/java/org/gnucash/android/ui/settings/dialog/DoubleConfirmationDialog.java b/app/src/main/java/org/gnucash/android/ui/settings/dialog/DoubleConfirmationDialog.java
index 0a542814c..3ce488978 100644
--- a/app/src/main/java/org/gnucash/android/ui/settings/dialog/DoubleConfirmationDialog.java
+++ b/app/src/main/java/org/gnucash/android/ui/settings/dialog/DoubleConfirmationDialog.java
@@ -16,9 +16,7 @@
package org.gnucash.android.ui.settings.dialog;
-import android.content.DialogInterface;
import android.widget.CheckBox;
-import android.widget.CompoundButton;
import org.gnucash.android.R;
@@ -58,12 +56,7 @@ public abstract class DoubleConfirmationDialog extends DialogFragment {
protected AlertDialog.Builder getDialogBuilder() {
return new AlertDialog.Builder(getActivity())
.setView(R.layout.dialog_double_confirm)
- .setNegativeButton(R.string.btn_cancel, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- onNegativeButton();
- }
- });
+ .setNegativeButton(R.string.btn_cancel, (dialog, which) -> onNegativeButton());
}
@Override
@@ -79,12 +72,7 @@ public void onStart() {
private void setUpConfirmCheckBox() {
final AlertDialog dialog = (AlertDialog) getDialog();
CheckBox confirmCheckBox = dialog.findViewById(R.id.checkbox_confirm);
- confirmCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
- dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(b);
- }
- });
+ confirmCheckBox.setOnCheckedChangeListener((compoundButton, b) -> dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(b));
}
/**
diff --git a/app/src/main/java/org/gnucash/android/ui/settings/dialog/OwnCloudDialogFragment.java b/app/src/main/java/org/gnucash/android/ui/settings/dialog/OwnCloudDialogFragment.java
index f6c061a33..16a0e8654 100644
--- a/app/src/main/java/org/gnucash/android/ui/settings/dialog/OwnCloudDialogFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/settings/dialog/OwnCloudDialogFragment.java
@@ -175,36 +175,33 @@ private void checkData() {
final Handler mHandler = new Handler();
- OnRemoteOperationListener listener = new OnRemoteOperationListener() {
- @Override
- public void onRemoteOperationFinish(RemoteOperation caller, RemoteOperationResult result) {
- if (!result.isSuccess()) {
- Log.e("OC", result.getLogMessage(), result.getException());
-
- if (caller instanceof GetRemoteStatusOperation) {
- mServerError.setTextColor(ContextCompat.getColor(getContext(), R.color.debit_red));
- mServerError.setText(getString(R.string.owncloud_server_invalid));
- mServerError.setVisibility(View.VISIBLE);
-
- } else if (caller instanceof GetRemoteUserInfoOperation &&
- mServerError.getText().toString().equals(getString(R.string.owncloud_server_ok))) {
- mUsernameError.setTextColor(ContextCompat.getColor(getContext(), R.color.debit_red));
- mUsernameError.setText(getString(R.string.owncloud_user_invalid));
- mUsernameError.setVisibility(View.VISIBLE);
- }
- } else {
- if (caller instanceof GetRemoteStatusOperation) {
- mServerError.setTextColor(ContextCompat.getColor(getContext(), R.color.theme_primary));
- mServerError.setText(getString(R.string.owncloud_server_ok));
- mServerError.setVisibility(View.VISIBLE);
- } else if (caller instanceof GetRemoteUserInfoOperation) {
- mUsernameError.setTextColor(ContextCompat.getColor(getContext(), R.color.theme_primary));
- mUsernameError.setText(getString(R.string.owncloud_user_ok));
- mUsernameError.setVisibility(View.VISIBLE);
- }
+ OnRemoteOperationListener listener = (caller, result) -> {
+ if (!result.isSuccess()) {
+ Log.e("OC", result.getLogMessage(), result.getException());
+
+ if (caller instanceof GetRemoteStatusOperation) {
+ mServerError.setTextColor(ContextCompat.getColor(getContext(), R.color.debit_red));
+ mServerError.setText(getString(R.string.owncloud_server_invalid));
+ mServerError.setVisibility(View.VISIBLE);
+
+ } else if (caller instanceof GetRemoteUserInfoOperation &&
+ mServerError.getText().toString().equals(getString(R.string.owncloud_server_ok))) {
+ mUsernameError.setTextColor(ContextCompat.getColor(getContext(), R.color.debit_red));
+ mUsernameError.setText(getString(R.string.owncloud_user_invalid));
+ mUsernameError.setVisibility(View.VISIBLE);
+ }
+ } else {
+ if (caller instanceof GetRemoteStatusOperation) {
+ mServerError.setTextColor(ContextCompat.getColor(getContext(), R.color.theme_primary));
+ mServerError.setText(getString(R.string.owncloud_server_ok));
+ mServerError.setVisibility(View.VISIBLE);
+ } else if (caller instanceof GetRemoteUserInfoOperation) {
+ mUsernameError.setTextColor(ContextCompat.getColor(getContext(), R.color.theme_primary));
+ mUsernameError.setText(getString(R.string.owncloud_user_ok));
+ mUsernameError.setVisibility(View.VISIBLE);
}
- saveButton();
}
+ saveButton();
};
GetRemoteStatusOperation g = new GetRemoteStatusOperation(mContext);
@@ -230,29 +227,19 @@ public void onRemoteOperationFinish(RemoteOperation caller, RemoteOperationResul
*/
private void setListeners(){
- mCancelButton.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
- dismiss();
- }
- });
-
- mOkButton.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
- // If data didn't change
- if(mOkButton.getText().toString().equals(getString(R.string.btn_save)) &&
- mOC_server.equals(mServer.getText().toString().trim()) &&
- mOC_username.equals(mUsername.getText().toString().trim()) &&
- mOC_password.equals(mPassword.getText().toString().trim()) &&
- mOC_dir.equals(mDir.getText().toString().trim())
- )
- save();
- else
- checkData();
- }
+ mCancelButton.setOnClickListener(v -> dismiss());
+
+ mOkButton.setOnClickListener(v -> {
+ // If data didn't change
+ if(mOkButton.getText().toString().equals(getString(R.string.btn_save)) &&
+ mOC_server.equals(mServer.getText().toString().trim()) &&
+ mOC_username.equals(mUsername.getText().toString().trim()) &&
+ mOC_password.equals(mPassword.getText().toString().trim()) &&
+ mOC_dir.equals(mDir.getText().toString().trim())
+ )
+ save();
+ else
+ checkData();
});
}
}
diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/ScheduledActionsActivity.java b/app/src/main/java/org/gnucash/android/ui/transaction/ScheduledActionsActivity.java
index a265aff73..9446d170f 100644
--- a/app/src/main/java/org/gnucash/android/ui/transaction/ScheduledActionsActivity.java
+++ b/app/src/main/java/org/gnucash/android/ui/transaction/ScheduledActionsActivity.java
@@ -23,6 +23,7 @@
import org.gnucash.android.model.ScheduledAction;
import org.gnucash.android.ui.common.BaseDrawerActivity;
+import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
@@ -106,6 +107,7 @@ public CharSequence getPageTitle(int position) {
}
}
+ @NonNull
@Override
public Fragment getItem(int position) {
switch (position){
diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/ScheduledActionsListFragment.java b/app/src/main/java/org/gnucash/android/ui/transaction/ScheduledActionsListFragment.java
index 622352e2e..113b1e553 100644
--- a/app/src/main/java/org/gnucash/android/ui/transaction/ScheduledActionsListFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/transaction/ScheduledActionsListFragment.java
@@ -248,7 +248,7 @@ public void onResume() {
@Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
if (mActionType == ScheduledAction.ActionType.BACKUP)
inflater.inflate(R.menu.scheduled_export_actions, menu);
}
@@ -267,7 +267,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
@Override
- public void onListItemClick(ListView l, View v, int position, long id) {
+ public void onListItemClick(@NonNull ListView l, @NonNull View v, int position, long id) {
super.onListItemClick(l, v, position, id);
if (mActionMode != null){
CheckBox checkbox = v.findViewById(R.id.checkbox);
@@ -306,6 +306,7 @@ public void openTransactionForEdit(String accountUID, String transactionUID, Str
startActivity(createTransactionIntent);
}
+ @NonNull
@Override
public Loader onCreateLoader(int arg0, Bundle arg1) {
Log.d(TAG, "Creating transactions loader");
@@ -318,14 +319,14 @@ else if (mActionType == ScheduledAction.ActionType.BACKUP){
}
@Override
- public void onLoadFinished(Loader loader, Cursor cursor) {
+ public void onLoadFinished(@NonNull Loader loader, Cursor cursor) {
Log.d(TAG, "Transactions loader finished. Swapping in cursor");
mCursorAdapter.swapCursor(cursor);
mCursorAdapter.notifyDataSetChanged();
}
@Override
- public void onLoaderReset(Loader loader) {
+ public void onLoaderReset(@NonNull Loader loader) {
Log.d(TAG, "Resetting transactions loader");
mCursorAdapter.swapCursor(null);
}
@@ -424,18 +425,14 @@ public View getView(int position, View convertView, ViewGroup parent) {
final TextView secondaryText = view.findViewById(R.id.secondary_text);
- checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
-
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- getListView().setItemChecked(itemPosition, isChecked);
- if (isChecked) {
- startActionMode();
- } else {
- stopActionMode();
- }
- setActionModeTitle();
+ checkbox.setOnCheckedChangeListener((buttonView, isChecked) -> {
+ getListView().setItemChecked(itemPosition, isChecked);
+ if (isChecked) {
+ startActionMode();
+ } else {
+ stopActionMode();
}
+ setActionModeTitle();
});
@@ -452,19 +449,16 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
final View checkBoxView = checkbox;
final View parentView = view;
- parentView.post(new Runnable() {
- @Override
- public void run() {
- if (isAdded()){ //may be run when fragment has been unbound from activity
- float extraPadding = getResources().getDimension(R.dimen.edge_padding);
- final android.graphics.Rect hitRect = new Rect();
- checkBoxView.getHitRect(hitRect);
- hitRect.right += extraPadding;
- hitRect.bottom += 3*extraPadding;
- hitRect.top -= extraPadding;
- hitRect.left -= 2*extraPadding;
- parentView.setTouchDelegate(new TouchDelegate(hitRect, checkBoxView));
- }
+ parentView.post(() -> {
+ if (isAdded()){ //may be run when fragment has been unbound from activity
+ float extraPadding = getResources().getDimension(R.dimen.edge_padding);
+ final Rect hitRect = new Rect();
+ checkBoxView.getHitRect(hitRect);
+ hitRect.right += extraPadding;
+ hitRect.bottom += 3*extraPadding;
+ hitRect.top -= extraPadding;
+ hitRect.left -= 2*extraPadding;
+ parentView.setTouchDelegate(new TouchDelegate(hitRect, checkBoxView));
}
});
@@ -525,18 +519,14 @@ public View getView(int position, View convertView, ViewGroup parent) {
final TextView secondaryText = view.findViewById(R.id.secondary_text);
- checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
-
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- getListView().setItemChecked(itemPosition, isChecked);
- if (isChecked) {
- startActionMode();
- } else {
- stopActionMode();
- }
- setActionModeTitle();
+ checkbox.setOnCheckedChangeListener((buttonView, isChecked) -> {
+ getListView().setItemChecked(itemPosition, isChecked);
+ if (isChecked) {
+ startActionMode();
+ } else {
+ stopActionMode();
}
+ setActionModeTitle();
});
@@ -553,19 +543,16 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
final View checkBoxView = checkbox;
final View parentView = view;
- parentView.post(new Runnable() {
- @Override
- public void run() {
- if (isAdded()){ //may be run when fragment has been unbound from activity
- float extraPadding = getResources().getDimension(R.dimen.edge_padding);
- final android.graphics.Rect hitRect = new Rect();
- checkBoxView.getHitRect(hitRect);
- hitRect.right += extraPadding;
- hitRect.bottom += 3*extraPadding;
- hitRect.top -= extraPadding;
- hitRect.left -= 2*extraPadding;
- parentView.setTouchDelegate(new TouchDelegate(hitRect, checkBoxView));
- }
+ parentView.post(() -> {
+ if (isAdded()){ //may be run when fragment has been unbound from activity
+ float extraPadding = getResources().getDimension(R.dimen.edge_padding);
+ final Rect hitRect = new Rect();
+ checkBoxView.getHitRect(hitRect);
+ hitRect.right += extraPadding;
+ hitRect.bottom += 3*extraPadding;
+ hitRect.top -= extraPadding;
+ hitRect.left -= 2*extraPadding;
+ parentView.setTouchDelegate(new TouchDelegate(hitRect, checkBoxView));
}
});
diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/SplitEditorFragment.java b/app/src/main/java/org/gnucash/android/ui/transaction/SplitEditorFragment.java
index 979f14ccb..47d138c9a 100644
--- a/app/src/main/java/org/gnucash/android/ui/transaction/SplitEditorFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/transaction/SplitEditorFragment.java
@@ -66,6 +66,7 @@
import java.util.ArrayList;
import java.util.List;
+import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cursoradapter.widget.SimpleCursorAdapter;
@@ -162,7 +163,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
}
@Override
- public void onConfigurationChanged(Configuration newConfig) {
+ public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mCalculatorKeyboard = new CalculatorKeyboard(getActivity(), mKeyboardView, R.xml.calculator_keyboard);
}
@@ -174,7 +175,7 @@ private void loadSplitViews(List splitList) {
}
@Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.split_editor_actions, menu);
}
@@ -425,14 +426,11 @@ private void setListeners() {
// Listeners on removeSplitButton
//
- removeSplitButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
+ removeSplitButton.setOnClickListener(view -> {
- mSplitsLinearLayout.removeView(splitView);
- mSplitItemViewList.remove(splitView);
- mImbalanceWatcher.afterTextChanged(null);
- }
+ mSplitsLinearLayout.removeView(splitView);
+ mSplitItemViewList.remove(splitView);
+ mImbalanceWatcher.afterTextChanged(null);
});
//
@@ -449,14 +447,7 @@ public void onClick(View view) {
// Set a ColorizeOnTransactionTypeChange listener
splitTypeSwitch.setColorizeOnCheckedChangeListener();
- splitTypeSwitch.addOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView,
- boolean isChecked) {
-
- mImbalanceWatcher.afterTextChanged(null);
- }
- });
+ splitTypeSwitch.addOnCheckedChangeListener((buttonView, isChecked) -> mImbalanceWatcher.afterTextChanged(null));
}
private void initViews(final Split split) {
diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java
index c2256ebca..694c74a8e 100644
--- a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java
@@ -271,13 +271,7 @@ public View onCreateView(LayoutInflater inflater,
mAmountEditText.bindListeners(mKeyboardView);
- mOpenSplitEditor.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
-
- openSplitEditor();
- }
- });
+ mOpenSplitEditor.setOnClickListener(v1 -> openSplitEditor());
return v;
}
@@ -305,7 +299,7 @@ private void startTransferFunds() {
}
@Override
- public void onConfigurationChanged(Configuration newConfig) {
+ public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mAmountEditText.bindListeners(mKeyboardView);
}
@@ -470,62 +464,47 @@ private void initTransactionNameAutocomplete() {
SimpleCursorAdapter adapter = new DropDownCursorAdapter(
getActivity(), R.layout.dropdown_item_2lines, null, from, to);
- adapter.setCursorToStringConverter(new SimpleCursorAdapter.CursorToStringConverter() {
- @Override
- public CharSequence convertToString(Cursor cursor) {
- final int colIndex = cursor.getColumnIndexOrThrow(DatabaseSchema.TransactionEntry.COLUMN_DESCRIPTION);
- return cursor.getString(colIndex);
- }
+ adapter.setCursorToStringConverter(cursor -> {
+ final int colIndex = cursor.getColumnIndexOrThrow(DatabaseSchema.TransactionEntry.COLUMN_DESCRIPTION);
+ return cursor.getString(colIndex);
});
- adapter.setFilterQueryProvider(new FilterQueryProvider() {
- @Override
- public Cursor runQuery(CharSequence name) {
- return mTransactionsDbAdapter.fetchTransactionSuggestions(name == null ? "" : name.toString(), mAccountUID);
- }
- });
-
- mDescriptionEditText.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ adapter.setFilterQueryProvider(name -> mTransactionsDbAdapter.fetchTransactionSuggestions(name == null ? "" : name.toString(), mAccountUID));
- @Override
- public void onItemClick(AdapterView> adapterView,
- View view,
- int position,
- long id) {
+ mDescriptionEditText.setOnItemClickListener((adapterView, view, position, id) -> {
- mTransaction = new Transaction(mTransactionsDbAdapter.getRecord(id),
- true);
+ mTransaction = new Transaction(mTransactionsDbAdapter.getRecord(id),
+ true);
- mTransaction.setTime(System.currentTimeMillis());
+ mTransaction.setTime(System.currentTimeMillis());
- //we check here because next method will modify it and we want to catch user-modification
- boolean amountEntered = mAmountEditText.isInputModified();
+ //we check here because next method will modify it and we want to catch user-modification
+ boolean amountEntered = mAmountEditText.isInputModified();
- initializeViewsWithTransaction();
+ initializeViewsWithTransaction();
- List splitList = mTransaction.getSplits();
- boolean isSplitPair = splitList.size() == 2 && splitList.get(0)
- .isPairOf(splitList.get(1));
- if (isSplitPair) {
+ List splitList = mTransaction.getSplits();
+ boolean isSplitPair = splitList.size() == 2 && splitList.get(0)
+ .isPairOf(splitList.get(1));
+ if (isSplitPair) {
+ mSplitsList.clear();
+ if (!amountEntered) //if user already entered an amount
+ {
+ mAmountEditText.setValue(splitList.get(0)
+ .getValue()
+ .asBigDecimal());
+ }
+ } else {
+ if (amountEntered) { //if user entered own amount, clear loaded splits and use the user value
mSplitsList.clear();
- if (!amountEntered) //if user already entered an amount
- {
- mAmountEditText.setValue(splitList.get(0)
- .getValue()
- .asBigDecimal());
- }
+ setDoubleEntryViewsVisibility(View.VISIBLE);
} else {
- if (amountEntered) { //if user entered own amount, clear loaded splits and use the user value
- mSplitsList.clear();
- setDoubleEntryViewsVisibility(View.VISIBLE);
- } else {
- if (mUseDoubleEntry) { //don't hide the view in single entry mode
- setDoubleEntryViewsVisibility(View.GONE);
- }
+ if (mUseDoubleEntry) { //don't hide the view in single entry mode
+ setDoubleEntryViewsVisibility(View.GONE);
}
}
- mTransaction = null; //we are creating a new transaction after all
}
+ mTransaction = null; //we are creating a new transaction after all
});
mDescriptionEditText.setAdapter(adapter);
@@ -634,12 +613,7 @@ private void toggleAmountInputEntryMode(boolean enabled){
mAmountEditText.bindListeners(mKeyboardView);
} else {
mAmountEditText.setFocusable(false);
- mAmountEditText.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- openSplitEditor();
- }
- });
+ mAmountEditText.setOnClickListener(v -> openSplitEditor());
}
}
@@ -783,51 +757,43 @@ private void setListeners() {
mTransactionTypeSwitch.setColorizeOnCheckedChangeListener();
- mDateTextView.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
- long dateMillis = 0;
- try {
- Date date = DATE_FORMATTER.parse(mDateTextView.getText().toString());
- dateMillis = date.getTime();
- } catch (ParseException e) {
- Log.e(getTag(), "Error converting input time to Date object");
- }
- Calendar calendar = Calendar.getInstance();
- calendar.setTimeInMillis(dateMillis);
-
- int year = calendar.get(Calendar.YEAR);
- int monthOfYear = calendar.get(Calendar.MONTH);
- int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
- CalendarDatePickerDialogFragment datePickerDialog = new CalendarDatePickerDialogFragment()
- .setOnDateSetListener(TransactionFormFragment.this)
- .setPreselectedDate(year, monthOfYear, dayOfMonth);
- datePickerDialog.show(getFragmentManager(), "date_picker_fragment");
+ mDateTextView.setOnClickListener(v -> {
+ long dateMillis = 0;
+ try {
+ Date date = DATE_FORMATTER.parse(mDateTextView.getText().toString());
+ dateMillis = date.getTime();
+ } catch (ParseException e) {
+ Log.e(getTag(), "Error converting input time to Date object");
}
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTimeInMillis(dateMillis);
+
+ int year = calendar.get(Calendar.YEAR);
+ int monthOfYear = calendar.get(Calendar.MONTH);
+ int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
+ CalendarDatePickerDialogFragment datePickerDialog = new CalendarDatePickerDialogFragment()
+ .setOnDateSetListener(TransactionFormFragment.this)
+ .setPreselectedDate(year, monthOfYear, dayOfMonth);
+ datePickerDialog.show(getFragmentManager(), "date_picker_fragment");
});
- mTimeTextView.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
- long timeMillis = 0;
- try {
- Date date = TIME_FORMATTER.parse(mTimeTextView.getText().toString());
- timeMillis = date.getTime();
- } catch (ParseException e) {
- Log.e(getTag(), "Error converting input time to Date object");
- }
+ mTimeTextView.setOnClickListener(v -> {
+ long timeMillis = 0;
+ try {
+ Date date = TIME_FORMATTER.parse(mTimeTextView.getText().toString());
+ timeMillis = date.getTime();
+ } catch (ParseException e) {
+ Log.e(getTag(), "Error converting input time to Date object");
+ }
- Calendar calendar = Calendar.getInstance();
- calendar.setTimeInMillis(timeMillis);
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTimeInMillis(timeMillis);
- RadialTimePickerDialogFragment timePickerDialog = new RadialTimePickerDialogFragment()
- .setOnTimeSetListener(TransactionFormFragment.this)
- .setStartTime(calendar.get(Calendar.HOUR_OF_DAY),
- calendar.get(Calendar.MINUTE));
- timePickerDialog.show(getFragmentManager(), "time_picker_dialog_fragment");
- }
+ RadialTimePickerDialogFragment timePickerDialog = new RadialTimePickerDialogFragment()
+ .setOnTimeSetListener(TransactionFormFragment.this)
+ .setStartTime(calendar.get(Calendar.HOUR_OF_DAY),
+ calendar.get(Calendar.MINUTE));
+ timePickerDialog.show(getFragmentManager(), "time_picker_dialog_fragment");
});
mRecurrenceTextView.setOnClickListener(new RecurrenceViewClickListener((AppCompatActivity) getActivity(), mRecurrenceRule, this));
@@ -1107,7 +1073,7 @@ public void onDestroyView() {
}
@Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.default_save_actions, menu);
}
diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionsActivity.java b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionsActivity.java
index b7bbe4ec8..2073e77c8 100644
--- a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionsActivity.java
+++ b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionsActivity.java
@@ -169,14 +169,9 @@ public void onNothingSelected(AdapterView> parent) {
}
};
- private DialogInterface.OnClickListener mSearchableSpinnerPositiveBtnOnClickListener = new DialogInterface.OnClickListener() {
+ private DialogInterface.OnClickListener mSearchableSpinnerPositiveBtnOnClickListener = (dialog, which) -> {
- @Override
- public void onClick(DialogInterface dialog,
- int which) {
-
- // NTD
- }
+ // NTD
};
private PagerAdapter mPagerAdapter;
@@ -191,6 +186,7 @@ public AccountViewPagerAdapter(FragmentManager fm){
super(fm);
}
+ @NonNull
@Override
public Fragment getItem(int i) {
if (mIsPlaceholderAccount){
@@ -216,7 +212,7 @@ public Fragment getItem(int i) {
}
@Override
- public void destroyItem(ViewGroup container, int position, Object object) {
+ public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
super.destroyItem(container, position, object);
mFragmentPageReferenceMap.remove(position);
}
@@ -363,24 +359,21 @@ public void onTabReselected(TabLayout.Tab tab) {
mViewPager.setCurrentItem(INDEX_TRANSACTIONS_FRAGMENT);
}
- mCreateFloatingButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- switch (mViewPager.getCurrentItem()) {
- case INDEX_SUB_ACCOUNTS_FRAGMENT:
- Intent addAccountIntent = new Intent(TransactionsActivity.this, FormActivity.class);
- addAccountIntent.setAction(Intent.ACTION_INSERT_OR_EDIT);
- addAccountIntent.putExtra(UxArgument.FORM_TYPE, FormActivity.FormType.ACCOUNT.name());
- addAccountIntent.putExtra(UxArgument.PARENT_ACCOUNT_UID,
- getCurrentAccountUID());
- startActivityForResult(addAccountIntent, AccountsActivity.REQUEST_EDIT_ACCOUNT);
- break;
-
- case INDEX_TRANSACTIONS_FRAGMENT:
- createNewTransaction(getCurrentAccountUID());
- break;
+ mCreateFloatingButton.setOnClickListener(v -> {
+ switch (mViewPager.getCurrentItem()) {
+ case INDEX_SUB_ACCOUNTS_FRAGMENT:
+ Intent addAccountIntent = new Intent(TransactionsActivity.this, FormActivity.class);
+ addAccountIntent.setAction(Intent.ACTION_INSERT_OR_EDIT);
+ addAccountIntent.putExtra(UxArgument.FORM_TYPE, FormActivity.FormType.ACCOUNT.name());
+ addAccountIntent.putExtra(UxArgument.PARENT_ACCOUNT_UID,
+ getCurrentAccountUID());
+ startActivityForResult(addAccountIntent, AccountsActivity.REQUEST_EDIT_ACCOUNT);
+ break;
+
+ case INDEX_TRANSACTIONS_FRAGMENT:
+ createNewTransaction(getCurrentAccountUID());
+ break;
- }
}
});
}
diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionsListFragment.java b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionsListFragment.java
index 976b8f745..38f874e88 100644
--- a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionsListFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionsListFragment.java
@@ -56,6 +56,7 @@
import java.util.List;
+import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
@@ -108,7 +109,7 @@ public void onCreate(Bundle savedInstanceState) {
}
@Override
- public void onSaveInstanceState(Bundle outState) {
+ public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(getString(R.string.key_use_compact_list), mUseCompactView);
}
@@ -193,12 +194,12 @@ public void onTransactionListItemClick(long transactionListItemId) {
}
@Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.transactions_list_actions, menu);
}
@Override
- public void onPrepareOptionsMenu(Menu menu) {
+ public void onPrepareOptionsMenu(@NonNull Menu menu) {
super.onPrepareOptionsMenu(menu);
MenuItem item = menu.findItem(R.id.menu_compact_trn_view);
item.setChecked(mUseCompactView);
@@ -218,6 +219,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
}
+ @NonNull
@Override
public Loader onCreateLoader(int arg0, Bundle arg1) {
Log.d(LOG_TAG, "Creating transactions loader");
@@ -225,14 +227,14 @@ public Loader onCreateLoader(int arg0, Bundle arg1) {
}
@Override
- public void onLoadFinished(Loader loader, Cursor cursor) {
+ public void onLoadFinished(@NonNull Loader loader, Cursor cursor) {
Log.d(LOG_TAG, "Transactions loader finished. Swapping in cursor");
mTransactionRecyclerAdapter.swapCursor(cursor);
mTransactionRecyclerAdapter.notifyDataSetChanged();
}
@Override
- public void onLoaderReset(Loader loader) {
+ public void onLoaderReset(@NonNull Loader loader) {
Log.d(LOG_TAG, "Resetting transactions loader");
mTransactionRecyclerAdapter.swapCursor(null);
}
@@ -268,6 +270,7 @@ public TransactionRecyclerAdapter(Cursor cursor) {
super(cursor);
}
+ @NonNull
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
int layoutRes = viewType == ITEM_TYPE_COMPACT ? R.layout.cardview_compact_transaction : R.layout.cardview_transaction;
@@ -304,13 +307,10 @@ public void onBindViewHolderCursor(ViewHolder holder, Cursor cursor) {
final long transactionListItemId = holder.transactionId;
// Listener when user clicks on a transaction list item
- holder.itemView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
+ holder.itemView.setOnClickListener(v -> {
- // Handle click on a transaction list item
- onTransactionListItemClick(transactionListItemId);
- }
+// Handle click on a transaction list item
+onTransactionListItemClick(transactionListItemId);
});
if (mUseCompactView) {
@@ -346,15 +346,12 @@ public void onClick(View v) {
// to open transaction editor
//
- holder.editTransaction.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent intent = new Intent(getActivity(), FormActivity.class);
- intent.putExtra(UxArgument.FORM_TYPE, FormActivity.FormType.TRANSACTION.name());
- intent.putExtra(UxArgument.SELECTED_TRANSACTION_UID, transactionUID);
- intent.putExtra(UxArgument.SELECTED_ACCOUNT_UID, mAccountUID);
- startActivity(intent);
- }
+ holder.editTransaction.setOnClickListener(v -> {
+ Intent intent = new Intent(getActivity(), FormActivity.class);
+ intent.putExtra(UxArgument.FORM_TYPE, FormActivity.FormType.TRANSACTION.name());
+ intent.putExtra(UxArgument.SELECTED_TRANSACTION_UID, transactionUID);
+ intent.putExtra(UxArgument.SELECTED_ACCOUNT_UID, mAccountUID);
+ startActivity(intent);
});
}
}
@@ -381,78 +378,71 @@ public ViewHolder(View itemView) {
// Define action when clicking on the secondary text to jump to this account transaction list
//
- secondaryText.setOnClickListener(new View.OnClickListener() {
+ secondaryText.setOnClickListener(view -> {
- @Override
- public void onClick(View view) {
+ // Prepare Intent to jump to the Transaction List of the Account selected by the user (when clicking on the secondary text)
+ Intent jumpToSelectedAccountTransactionListIntent = new Intent(getActivity(),
+ TransactionsActivity.class);
- // Prepare Intent to jump to the Transaction List of the Account selected by the user (when clicking on the secondary text)
- Intent jumpToSelectedAccountTransactionListIntent = new Intent(getActivity(),
- TransactionsActivity.class);
+ // Get Transaction UID for the transactionId nth item of the transaction list
+ String transactionUID = mTransactionsDbAdapter.getUID(transactionId);
- // Get Transaction UID for the transactionId nth item of the transaction list
- String transactionUID = mTransactionsDbAdapter.getUID(transactionId);
+ // Get all Splits of Transaction transactionUID
+ final List splitsForTransaction = mTransactionsDbAdapter.getSplitDbAdapter()
+ .getSplitsForTransaction(transactionUID);
- // Get all Splits of Transaction transactionUID
- final List splitsForTransaction = mTransactionsDbAdapter.getSplitDbAdapter()
- .getSplitsForTransaction(transactionUID);
+ // Get the Account UID to jump to
+ String jumpToAccountUID = "";
+ for (int i = 0; i < splitsForTransaction.size(); i++) {
- // Get the Account UID to jump to
- String jumpToAccountUID = "";
- for (int i = 0; i < splitsForTransaction.size(); i++) {
+ // Get the UID of the i-nth account involved in the Transaction
+ jumpToAccountUID = splitsForTransaction.get(i)
+ .getAccountUID();
- // Get the UID of the i-nth account involved in the Transaction
- jumpToAccountUID = splitsForTransaction.get(i)
- .getAccountUID();
+ if (!mAccountUID.equals(jumpToAccountUID)) {
+ // The account transaction list to jump to is not the current one
- if (!mAccountUID.equals(jumpToAccountUID)) {
- // The account transaction list to jump to is not the current one
-
- // Stop searching
- break;
+ // Stop searching
+ break;
- } else {
- // The account transaction list to jump to is the current one
+ } else {
+ // The account transaction list to jump to is the current one
- // NTD : Continue to look for another Account
- }
- } // for
+ // NTD : Continue to look for another Account
+ }
+ } // for
- jumpToSelectedAccountTransactionListIntent.setAction(Intent.ACTION_VIEW);
+ jumpToSelectedAccountTransactionListIntent.setAction(Intent.ACTION_VIEW);
- // Indicate the Account Transaction List to jump to
- jumpToSelectedAccountTransactionListIntent.putExtra(UxArgument.SELECTED_ACCOUNT_UID,
- jumpToAccountUID);
+ // Indicate the Account Transaction List to jump to
+ jumpToSelectedAccountTransactionListIntent.putExtra(UxArgument.SELECTED_ACCOUNT_UID,
+ jumpToAccountUID);
- // Start the Activity to display the Account Transaction List of the other Account
- startActivity(jumpToSelectedAccountTransactionListIntent);
- }
- });
+ // Start the Activity to display the Account Transaction List of the other Account
+ startActivity(jumpToSelectedAccountTransactionListIntent);
+ });
//
// Define action when clicking on the three dot icon of a cardview_transaction
// to open a menu
//
- optionsMenu.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
+ optionsMenu.setOnClickListener(v -> {
- // Build pop-menu
- PopupMenu popupMenu = new PopupMenu(getActivity(),
- v);
+// Build pop-menu
+PopupMenu popupMenu = new PopupMenu(getActivity(),
+v);
- // Current ViewHolder instance will handle the click on a menu item
- popupMenu.setOnMenuItemClickListener(ViewHolder.this);
+// Current ViewHolder instance will handle the click on a menu item
+popupMenu.setOnMenuItemClickListener(ViewHolder.this);
- // Unserialize the menu defined in transactions_context_menu.xml
- MenuInflater inflater = popupMenu.getMenuInflater();
- inflater.inflate(R.menu.transactions_context_menu,
- popupMenu.getMenu());
+// Unserialize the menu defined in transactions_context_menu.xml
+MenuInflater inflater = popupMenu.getMenuInflater();
+inflater.inflate(R.menu.transactions_context_menu,
+popupMenu.getMenu());
- // Display pop-menu
- popupMenu.show();
- }
+// Display pop-menu
+popupMenu.show();
});
}
diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/dialog/BulkMoveDialogFragment.java b/app/src/main/java/org/gnucash/android/ui/transaction/dialog/BulkMoveDialogFragment.java
index e287e5f8a..d0997c0c4 100644
--- a/app/src/main/java/org/gnucash/android/ui/transaction/dialog/BulkMoveDialogFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/transaction/dialog/BulkMoveDialogFragment.java
@@ -139,39 +139,29 @@ public void onActivityCreated(Bundle savedInstanceState) {
* Binds click listeners for the dialog buttons
*/
protected void setListeners(){
- mCancelButton.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
+ mCancelButton.setOnClickListener(v -> dismiss());
+
+ mOkButton.setOnClickListener(v -> {
+ if (mTransactionIds == null) {
dismiss();
}
- });
-
- mOkButton.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
- if (mTransactionIds == null) {
- dismiss();
- }
- long dstAccountId = mDestinationAccountSpinner.getSelectedItemId();
- String dstAccountUID = AccountsDbAdapter.getInstance().getUID(dstAccountId);
- TransactionsDbAdapter trxnAdapter = TransactionsDbAdapter.getInstance();
- if (!trxnAdapter.getAccountCurrencyCode(dstAccountUID).equals(trxnAdapter.getAccountCurrencyCode(mOriginAccountUID))) {
- Toast.makeText(getActivity(), R.string.toast_incompatible_currency, Toast.LENGTH_LONG).show();
- return;
- }
- String srcAccountUID = ((TransactionsActivity) getActivity()).getCurrentAccountUID();
-
- for (long trxnId : mTransactionIds) {
- trxnAdapter.moveTransaction(trxnAdapter.getUID(trxnId), srcAccountUID, dstAccountUID);
- }
+ long dstAccountId = mDestinationAccountSpinner.getSelectedItemId();
+ String dstAccountUID = AccountsDbAdapter.getInstance().getUID(dstAccountId);
+ TransactionsDbAdapter trxnAdapter = TransactionsDbAdapter.getInstance();
+ if (!trxnAdapter.getAccountCurrencyCode(dstAccountUID).equals(trxnAdapter.getAccountCurrencyCode(mOriginAccountUID))) {
+ Toast.makeText(getActivity(), R.string.toast_incompatible_currency, Toast.LENGTH_LONG).show();
+ return;
+ }
+ String srcAccountUID = ((TransactionsActivity) getActivity()).getCurrentAccountUID();
- WidgetConfigurationActivity.updateAllWidgets(getActivity());
- ((Refreshable) getTargetFragment()).refresh();
- dismiss();
+ for (long trxnId : mTransactionIds) {
+ trxnAdapter.moveTransaction(trxnAdapter.getUID(trxnId), srcAccountUID, dstAccountUID);
}
+
+ WidgetConfigurationActivity.updateAllWidgets(getActivity());
+ ((Refreshable) getTargetFragment()).refresh();
+ dismiss();
});
}
}
diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/dialog/TransactionsDeleteConfirmationDialogFragment.java b/app/src/main/java/org/gnucash/android/ui/transaction/dialog/TransactionsDeleteConfirmationDialogFragment.java
index 3e5abe217..feb04dd49 100644
--- a/app/src/main/java/org/gnucash/android/ui/transaction/dialog/TransactionsDeleteConfirmationDialogFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/transaction/dialog/TransactionsDeleteConfirmationDialogFragment.java
@@ -35,6 +35,7 @@
import java.util.ArrayList;
import java.util.List;
+import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
/**
@@ -54,6 +55,7 @@ public static TransactionsDeleteConfirmationDialogFragment newInstance(int title
return frag;
}
+ @NonNull
@Override public Dialog onCreateDialog(Bundle savedInstanceState) {
int title = getArguments().getInt("title");
final long rowId = getArguments().getLong(UxArgument.SELECTED_TRANSACTION_IDS);
@@ -62,38 +64,32 @@ public static TransactionsDeleteConfirmationDialogFragment newInstance(int title
.setIcon(android.R.drawable.ic_delete)
.setTitle(title).setMessage(message)
.setPositiveButton(R.string.alert_dialog_ok_delete,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- TransactionsDbAdapter transactionsDbAdapter = TransactionsDbAdapter.getInstance();
- if (rowId == 0) {
- BackupManager.backupActiveBook(); //create backup before deleting everything
- List openingBalances = new ArrayList();
- boolean preserveOpeningBalances = GnuCashApplication.shouldSaveOpeningBalances(false);
- if (preserveOpeningBalances) {
- openingBalances = AccountsDbAdapter.getInstance().getAllOpeningBalanceTransactions();
- }
+ (dialog, whichButton) -> {
+ TransactionsDbAdapter transactionsDbAdapter = TransactionsDbAdapter.getInstance();
+ if (rowId == 0) {
+ BackupManager.backupActiveBook(); //create backup before deleting everything
+ List openingBalances = new ArrayList();
+ boolean preserveOpeningBalances = GnuCashApplication.shouldSaveOpeningBalances(false);
+ if (preserveOpeningBalances) {
+ openingBalances = AccountsDbAdapter.getInstance().getAllOpeningBalanceTransactions();
+ }
- transactionsDbAdapter.deleteAllRecords();
+ transactionsDbAdapter.deleteAllRecords();
- if (preserveOpeningBalances) {
- transactionsDbAdapter.bulkAddRecords(openingBalances, DatabaseAdapter.UpdateMethod.insert);
- }
- } else {
- transactionsDbAdapter.deleteRecord(rowId);
- }
- if (getTargetFragment() instanceof Refreshable) {
- ((Refreshable) getTargetFragment()).refresh();
+ if (preserveOpeningBalances) {
+ transactionsDbAdapter.bulkAddRecords(openingBalances, DatabaseAdapter.UpdateMethod.insert);
}
- WidgetConfigurationActivity.updateAllWidgets(getActivity());
+ } else {
+ transactionsDbAdapter.deleteRecord(rowId);
+ }
+ if (getTargetFragment() instanceof Refreshable) {
+ ((Refreshable) getTargetFragment()).refresh();
}
+ WidgetConfigurationActivity.updateAllWidgets(getActivity());
}
)
.setNegativeButton(R.string.alert_dialog_cancel,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- dismiss();
- }
- }
+ (dialog, whichButton) -> dismiss()
)
.create();
}
diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/dialog/TransferFundsDialogFragment.java b/app/src/main/java/org/gnucash/android/ui/transaction/dialog/TransferFundsDialogFragment.java
index 8b10444e0..8e66d4184 100644
--- a/app/src/main/java/org/gnucash/android/ui/transaction/dialog/TransferFundsDialogFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/transaction/dialog/TransferFundsDialogFragment.java
@@ -137,51 +137,32 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
mExchangeRateInput.addTextChangedListener(textChangeListener);
mConvertedAmountInput.addTextChangedListener(textChangeListener);
- mConvertedAmountRadioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- mConvertedAmountInput.setEnabled(isChecked);
- mConvertedAmountInputLayout.setErrorEnabled(isChecked);
- mExchangeRateRadioButton.setChecked(!isChecked);
- if (isChecked) {
- mConvertedAmountInput.requestFocus();
- }
+ mConvertedAmountRadioButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
+ mConvertedAmountInput.setEnabled(isChecked);
+ mConvertedAmountInputLayout.setErrorEnabled(isChecked);
+ mExchangeRateRadioButton.setChecked(!isChecked);
+ if (isChecked) {
+ mConvertedAmountInput.requestFocus();
}
});
- mExchangeRateRadioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- mExchangeRateInput.setEnabled(isChecked);
- mExchangeRateInputLayout.setErrorEnabled(isChecked);
- mFetchExchangeRateButton.setEnabled(isChecked);
- mConvertedAmountRadioButton.setChecked(!isChecked);
- if (isChecked) {
- mExchangeRateInput.requestFocus();
- }
+ mExchangeRateRadioButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
+ mExchangeRateInput.setEnabled(isChecked);
+ mExchangeRateInputLayout.setErrorEnabled(isChecked);
+ mFetchExchangeRateButton.setEnabled(isChecked);
+ mConvertedAmountRadioButton.setChecked(!isChecked);
+ if (isChecked) {
+ mExchangeRateInput.requestFocus();
}
});
- mFetchExchangeRateButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- //TODO: Pull the exchange rate for the currency here
- }
+ mFetchExchangeRateButton.setOnClickListener(v -> {
+ //TODO: Pull the exchange rate for the currency here
});
- mCancelButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- dismiss();
- }
- });
+ mCancelButton.setOnClickListener(v -> dismiss());
- mSaveButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- transferFunds();
- }
- });
+ mSaveButton.setOnClickListener(v -> transferFunds());
return view;
}
diff --git a/app/src/main/java/org/gnucash/android/ui/util/CursorRecyclerAdapter.java b/app/src/main/java/org/gnucash/android/ui/util/CursorRecyclerAdapter.java
index 71d351880..521f3fbff 100644
--- a/app/src/main/java/org/gnucash/android/ui/util/CursorRecyclerAdapter.java
+++ b/app/src/main/java/org/gnucash/android/ui/util/CursorRecyclerAdapter.java
@@ -32,6 +32,7 @@
import android.widget.FilterQueryProvider;
import android.widget.Filterable;
+import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
/**
@@ -91,7 +92,7 @@ void init(Cursor c) {
* @param i {@inheritDoc}
*/
@Override
- public void onBindViewHolder(VH holder, int i){
+ public void onBindViewHolder(@NonNull VH holder, int i){
if (!mDataValid) {
throw new IllegalStateException("this should only be called when the cursor is valid");
}
diff --git a/app/src/main/java/org/gnucash/android/ui/util/ScrollingFABBehavior.java b/app/src/main/java/org/gnucash/android/ui/util/ScrollingFABBehavior.java
index cc3583fef..aeaf1db0e 100644
--- a/app/src/main/java/org/gnucash/android/ui/util/ScrollingFABBehavior.java
+++ b/app/src/main/java/org/gnucash/android/ui/util/ScrollingFABBehavior.java
@@ -26,6 +26,7 @@
import org.gnucash.android.R;
+import androidx.annotation.NonNull;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
/**
@@ -41,12 +42,12 @@ public ScrollingFABBehavior(Context context, AttributeSet attrs) {
}
@Override
- public boolean layoutDependsOn(CoordinatorLayout parent, FloatingActionButton fab, View dependency) {
+ public boolean layoutDependsOn(@NonNull CoordinatorLayout parent, @NonNull FloatingActionButton fab, @NonNull View dependency) {
return dependency instanceof AppBarLayout;
}
@Override
- public boolean onDependentViewChanged(CoordinatorLayout parent, FloatingActionButton fab, View dependency) {
+ public boolean onDependentViewChanged(@NonNull CoordinatorLayout parent, @NonNull FloatingActionButton fab, @NonNull View dependency) {
if (dependency instanceof AppBarLayout) {
CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
int fabBottomMargin = lp.bottomMargin;
diff --git a/app/src/main/java/org/gnucash/android/ui/util/dialog/DatePickerDialogFragment.java b/app/src/main/java/org/gnucash/android/ui/util/dialog/DatePickerDialogFragment.java
index 2a3149402..81e04ddd0 100644
--- a/app/src/main/java/org/gnucash/android/ui/util/dialog/DatePickerDialogFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/util/dialog/DatePickerDialogFragment.java
@@ -24,6 +24,7 @@
import java.util.Calendar;
import java.util.GregorianCalendar;
+import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
/**
@@ -70,6 +71,7 @@ public static DatePickerDialogFragment newInstance(OnDateSetListener callback, l
/**
* Creates and returns an Android {@link DatePickerDialog}
*/
+ @NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Calendar cal = mDate == null ? Calendar.getInstance() : mDate;
diff --git a/app/src/main/java/org/gnucash/android/ui/util/dialog/DateRangePickerDialogFragment.java b/app/src/main/java/org/gnucash/android/ui/util/dialog/DateRangePickerDialogFragment.java
index cac29d1f0..2d90fc155 100644
--- a/app/src/main/java/org/gnucash/android/ui/util/dialog/DateRangePickerDialogFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/util/dialog/DateRangePickerDialogFragment.java
@@ -85,27 +85,19 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
.withSelectedDate(today);
mDoneButton.setText(R.string.done_label);
- mDoneButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- List selectedDates = mCalendarPickerView.getSelectedDates();
- Date startDate = selectedDates.get(0);
- // If only one day is selected (no interval) start and end should be the same (the selected one)
- Date endDate = selectedDates.size() > 1 ? selectedDates.get(selectedDates.size() - 1) : new Date(startDate.getTime());
- // CaledarPicker returns the start of the selected day but we want all transactions of that day to be included.
- // Therefore we have to add 24 hours to the endDate.
- endDate.setTime(endDate.getTime() + ONE_DAY_IN_MILLIS);
- mDateRangeSetListener.onDateRangeSet(startDate, endDate);
- dismiss();
- }
+ mDoneButton.setOnClickListener(v -> {
+ List selectedDates = mCalendarPickerView.getSelectedDates();
+ Date startDate = selectedDates.get(0);
+ // If only one day is selected (no interval) start and end should be the same (the selected one)
+ Date endDate = selectedDates.size() > 1 ? selectedDates.get(selectedDates.size() - 1) : new Date(startDate.getTime());
+ // CaledarPicker returns the start of the selected day but we want all transactions of that day to be included.
+ // Therefore we have to add 24 hours to the endDate.
+ endDate.setTime(endDate.getTime() + ONE_DAY_IN_MILLIS);
+ mDateRangeSetListener.onDateRangeSet(startDate, endDate);
+ dismiss();
});
- mCancelButton.setOnClickListener(new View.OnClickListener(){
- @Override
- public void onClick(View v) {
- dismiss();
- }
- });
+ mCancelButton.setOnClickListener(v -> dismiss());
return view;
}
diff --git a/app/src/main/java/org/gnucash/android/ui/util/dialog/TimePickerDialogFragment.java b/app/src/main/java/org/gnucash/android/ui/util/dialog/TimePickerDialogFragment.java
index 52c95bed4..77ba2f88c 100644
--- a/app/src/main/java/org/gnucash/android/ui/util/dialog/TimePickerDialogFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/util/dialog/TimePickerDialogFragment.java
@@ -23,6 +23,7 @@
import java.util.Calendar;
import java.util.GregorianCalendar;
+import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
/**
@@ -68,7 +69,8 @@ public static TimePickerDialogFragment newInstance(OnTimeSetListener listener, l
/**
* Creates and returns an Android {@link TimePickerDialog}
*/
- @Override
+ @NonNull
+ @Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Calendar cal = mCurrentTime == null ? Calendar.getInstance() : mCurrentTime;
diff --git a/app/src/main/java/org/gnucash/android/ui/util/widget/CalculatorEditText.java b/app/src/main/java/org/gnucash/android/ui/util/widget/CalculatorEditText.java
index e37f07ca8..70cebf7b3 100644
--- a/app/src/main/java/org/gnucash/android/ui/util/widget/CalculatorEditText.java
+++ b/app/src/main/java/org/gnucash/android/ui/util/widget/CalculatorEditText.java
@@ -122,28 +122,20 @@ public void afterTextChanged(Editable s) {
public void bindListeners(CalculatorKeyboard calculatorKeyboard){
mCalculatorKeyboard = calculatorKeyboard;
mContext = calculatorKeyboard.getContext();
- setOnFocusChangeListener(new OnFocusChangeListener() {
- @Override
- public void onFocusChange(View v, boolean hasFocus) {
- if (hasFocus) {
- setSelection(getText().length());
- mCalculatorKeyboard.showCustomKeyboard(v);
- } else {
- mCalculatorKeyboard.hideCustomKeyboard();
- evaluate();
- }
- }
- });
-
- setOnClickListener(new OnClickListener() {
- // NOTE By setting the on click listener we can show the custom keyboard again,
- // by tapping on an edit box that already had focus (but that had the keyboard hidden).
- @Override
- public void onClick(View v) {
+ setOnFocusChangeListener((v, hasFocus) -> {
+ if (hasFocus) {
+ setSelection(getText().length());
mCalculatorKeyboard.showCustomKeyboard(v);
+ } else {
+ mCalculatorKeyboard.hideCustomKeyboard();
+ evaluate();
}
});
+ // NOTE By setting the on click listener we can show the custom keyboard again,
+// by tapping on an edit box that already had focus (but that had the keyboard hidden).
+ setOnClickListener(v -> mCalculatorKeyboard.showCustomKeyboard(v));
+
// Disable spell check (hex strings look like words to Android)
setInputType(getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
@@ -156,13 +148,10 @@ public void onClick(View v) {
// Although this handler doesn't make sense, if removed, the standard keyboard
// shows up in addition to the calculator one when the EditText gets a touch event.
- setOnTouchListener(new OnTouchListener() {
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- // XXX: Use dispatchTouchEvent()?
- onTouchEvent(event);
- return false;
- }
+ setOnTouchListener((v, event) -> {
+ // XXX: Use dispatchTouchEvent()?
+ onTouchEvent(event);
+ return false;
});
((FormActivity)mContext).setOnBackListener(mCalculatorKeyboard);
diff --git a/app/src/main/java/org/gnucash/android/ui/util/widget/searchablespinner/SearchableListDialogFragment.java b/app/src/main/java/org/gnucash/android/ui/util/widget/searchablespinner/SearchableListDialogFragment.java
index 8e916d557..247a846dd 100644
--- a/app/src/main/java/org/gnucash/android/ui/util/widget/searchablespinner/SearchableListDialogFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/util/widget/searchablespinner/SearchableListDialogFragment.java
@@ -12,7 +12,6 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
diff --git a/app/src/main/java/org/gnucash/android/ui/wizard/CurrencySelectFragment.java b/app/src/main/java/org/gnucash/android/ui/wizard/CurrencySelectFragment.java
index 487f06a7b..ee5ee1a0b 100644
--- a/app/src/main/java/org/gnucash/android/ui/wizard/CurrencySelectFragment.java
+++ b/app/src/main/java/org/gnucash/android/ui/wizard/CurrencySelectFragment.java
@@ -29,6 +29,7 @@
import org.gnucash.android.db.adapter.CommoditiesDbAdapter;
import org.gnucash.android.util.CommoditiesCursorAdapter;
+import androidx.annotation.NonNull;
import androidx.fragment.app.ListFragment;
import butterknife.ButterKnife;
@@ -81,7 +82,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
}
@Override
- public void onAttach(Activity activity) {
+ public void onAttach(@NonNull Activity activity) {
super.onAttach(activity);
if (!(activity instanceof PageFragmentCallbacks)) {
throw new ClassCastException("Activity must implement PageFragmentCallbacks");
@@ -97,7 +98,7 @@ public void onDetach() {
}
@Override
- public void onListItemClick(ListView l, View v, int position, long id) {
+ public void onListItemClick(@NonNull ListView l, @NonNull View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String currencyCode = mCommoditiesDbAdapter.getCurrencyCode(mCommoditiesDbAdapter.getUID(id));
diff --git a/app/src/main/java/org/gnucash/android/ui/wizard/FirstRunWizardActivity.java b/app/src/main/java/org/gnucash/android/ui/wizard/FirstRunWizardActivity.java
index ef0b038ba..3b6c71240 100644
--- a/app/src/main/java/org/gnucash/android/ui/wizard/FirstRunWizardActivity.java
+++ b/app/src/main/java/org/gnucash/android/ui/wizard/FirstRunWizardActivity.java
@@ -45,6 +45,7 @@
import java.util.ArrayList;
import java.util.List;
+import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatButton;
import androidx.core.content.ContextCompat;
@@ -94,14 +95,11 @@ public void onCreate(Bundle savedInstanceState) {
mPagerAdapter = new MyPagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
mStepPagerStrip
- .setOnPageSelectedListener(new StepPagerStrip.OnPageSelectedListener() {
- @Override
- public void onPageStripSelected(int position) {
- position = Math.min(mPagerAdapter.getCount() - 1,
- position);
- if (mPager.getCurrentItem() != position) {
- mPager.setCurrentItem(position);
- }
+ .setOnPageSelectedListener(position -> {
+ position = Math.min(mPagerAdapter.getCount() - 1,
+ position);
+ if (mPager.getCurrentItem() != position) {
+ mPager.setCurrentItem(position);
}
});
@@ -121,49 +119,46 @@ public void onPageSelected(int position) {
}
});
- mNextButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if (mPager.getCurrentItem() == mCurrentPageSequence.size()) {
- ArrayList reviewItems = new ArrayList<>();
- for (Page page : mCurrentPageSequence) {
- page.getReviewItems(reviewItems);
- }
+ mNextButton.setOnClickListener(view -> {
+ if (mPager.getCurrentItem() == mCurrentPageSequence.size()) {
+ ArrayList reviewItems = new ArrayList<>();
+ for (Page page : mCurrentPageSequence) {
+ page.getReviewItems(reviewItems);
+ }
- mCurrencyCode = GnuCashApplication.getDefaultCurrencyCode();
- mAccountOptions = getString(R.string.wizard_option_let_me_handle_it); //default value, do nothing
- String feedbackOption = getString(R.string.wizard_option_disable_crash_reports);
- for (ReviewItem reviewItem : reviewItems) {
- String title = reviewItem.getTitle();
- if (title.equals(getString(R.string.wizard_title_default_currency))){
- mCurrencyCode = reviewItem.getDisplayValue();
- } else if (title.equals(getString(R.string.wizard_title_select_currency))){
- mCurrencyCode = reviewItem.getDisplayValue();
- } else if (title.equals(getString(R.string.wizard_title_account_setup))){
- mAccountOptions = reviewItem.getDisplayValue();
- } else if (title.equals(getString(R.string.wizard_title_feedback_options))){
- feedbackOption = reviewItem.getDisplayValue();
- }
+ mCurrencyCode = GnuCashApplication.getDefaultCurrencyCode();
+ mAccountOptions = getString(R.string.wizard_option_let_me_handle_it); //default value, do nothing
+ String feedbackOption = getString(R.string.wizard_option_disable_crash_reports);
+ for (ReviewItem reviewItem : reviewItems) {
+ String title = reviewItem.getTitle();
+ if (title.equals(getString(R.string.wizard_title_default_currency))){
+ mCurrencyCode = reviewItem.getDisplayValue();
+ } else if (title.equals(getString(R.string.wizard_title_select_currency))){
+ mCurrencyCode = reviewItem.getDisplayValue();
+ } else if (title.equals(getString(R.string.wizard_title_account_setup))){
+ mAccountOptions = reviewItem.getDisplayValue();
+ } else if (title.equals(getString(R.string.wizard_title_feedback_options))){
+ feedbackOption = reviewItem.getDisplayValue();
}
+ }
- GnuCashApplication.setDefaultCurrencyCode(mCurrencyCode);
- SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(FirstRunWizardActivity.this);
- SharedPreferences.Editor preferenceEditor = preferences.edit();
+ GnuCashApplication.setDefaultCurrencyCode(mCurrencyCode);
+ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(FirstRunWizardActivity.this);
+ SharedPreferences.Editor preferenceEditor = preferences.edit();
- if (feedbackOption.equals(getString(R.string.wizard_option_auto_send_crash_reports))){
- preferenceEditor.putBoolean(getString(R.string.key_enable_crashlytics), true);
- } else {
- preferenceEditor.putBoolean(getString(R.string.key_enable_crashlytics), false);
- }
- preferenceEditor.apply();
+ if (feedbackOption.equals(getString(R.string.wizard_option_auto_send_crash_reports))){
+ preferenceEditor.putBoolean(getString(R.string.key_enable_crashlytics), true);
+ } else {
+ preferenceEditor.putBoolean(getString(R.string.key_enable_crashlytics), false);
+ }
+ preferenceEditor.apply();
- createAccountsAndFinish();
+ createAccountsAndFinish();
+ } else {
+ if (mEditingAfterReview) {
+ mPager.setCurrentItem(mPagerAdapter.getCount() - 1);
} else {
- if (mEditingAfterReview) {
- mPager.setCurrentItem(mPagerAdapter.getCount() - 1);
- } else {
- mPager.setCurrentItem(mPager.getCurrentItem() + 1);
- }
+ mPager.setCurrentItem(mPager.getCurrentItem() + 1);
}
}
});
@@ -175,12 +170,7 @@ public void onClick(View view) {
mPrevButton.setTextAppearance(this, v.resourceId);
mNextButton.setTextAppearance(this, v.resourceId);
- mPrevButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- mPager.setCurrentItem(mPager.getCurrentItem() - 1);
- }
- });
+ mPrevButton.setOnClickListener(view -> mPager.setCurrentItem(mPager.getCurrentItem() - 1));
onPageTreeChanged();
updateBottomBar();
@@ -276,7 +266,7 @@ protected void onDestroy() {
}
@Override
- protected void onSaveInstanceState(Bundle outState) {
+ protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBundle("model", mWizardModel.save());
}
@@ -341,6 +331,7 @@ public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
+ @NonNull
@Override
public Fragment getItem(int i) {
if (i >= mCurrentPageSequence.size()) {
@@ -351,7 +342,7 @@ public Fragment getItem(int i) {
}
@Override
- public int getItemPosition(Object object) {
+ public int getItemPosition(@NonNull Object object) {
// TODO: be smarter about this
if (object == mPrimaryItem) {
// Re-use the current fragment (its position never changes)
@@ -362,8 +353,8 @@ public int getItemPosition(Object object) {
}
@Override
- public void setPrimaryItem(ViewGroup container, int position,
- Object object) {
+ public void setPrimaryItem(@NonNull ViewGroup container, int position,
+ @NonNull Object object) {
super.setPrimaryItem(container, position, object);
mPrimaryItem = (Fragment) object;
}
diff --git a/app/src/main/java/org/gnucash/android/util/KeyboardUtils.java b/app/src/main/java/org/gnucash/android/util/KeyboardUtils.java
index 2894d5076..c2cc02393 100644
--- a/app/src/main/java/org/gnucash/android/util/KeyboardUtils.java
+++ b/app/src/main/java/org/gnucash/android/util/KeyboardUtils.java
@@ -39,14 +39,11 @@ public static void hideKeyboard(final View editTextView,
// editTextView.requestFocus();
// Delay the keyboard hiding
- editTextView.postDelayed(new Runnable() {
- @Override
- public void run() {
-
- // Hide keyboard
- hideKeyboard(editTextView);
- }
- },
+ editTextView.postDelayed(() -> {
+
+ // Hide keyboard
+ hideKeyboard(editTextView);
+ },
delay);
}
diff --git a/app/src/main/java/org/gnucash/android/util/QualifiedAccountNameCursorAdapter.java b/app/src/main/java/org/gnucash/android/util/QualifiedAccountNameCursorAdapter.java
index 1b266339f..03459535a 100644
--- a/app/src/main/java/org/gnucash/android/util/QualifiedAccountNameCursorAdapter.java
+++ b/app/src/main/java/org/gnucash/android/util/QualifiedAccountNameCursorAdapter.java
@@ -111,46 +111,43 @@ public QualifiedAccountNameCursorAdapter(Context context,
setCursorWhereArgs(cursorWhereArgs);
// Define filter
- setFilterQueryProvider(new FilterQueryProvider() {
+ setFilterQueryProvider(constraint -> {
- public Cursor runQuery(CharSequence constraint) {
-
- //
- // Add %constraint% at the end of the whereArgs
- //
+ //
+ // Add %constraint% at the end of the whereArgs
+ //
- // Convert WhereArgs into List
- final String[] cursorWhereArgs = getCursorWhereArgs();
- final List whereArgsAsList = (cursorWhereArgs != null)
- ? new ArrayList<>(Arrays.asList(cursorWhereArgs))
- : new ArrayList<>();
+ // Convert WhereArgs into List
+ final String[] cursorWhereArgs1 = getCursorWhereArgs();
+ final List whereArgsAsList = (cursorWhereArgs1 != null)
+ ? new ArrayList<>(Arrays.asList(cursorWhereArgs1))
+ : new ArrayList<>();
- // Add the %constraint% for the LIKE added in the where clause
- whereArgsAsList.add("%" + ((constraint != null)
- ? constraint.toString()
- : "") + "%");
+ // Add the %constraint% for the LIKE added in the where clause
+ whereArgsAsList.add("%" + ((constraint != null)
+ ? constraint.toString()
+ : "") + "%");
- // Convert List into WhereArgs
- final String[] whereArgs = whereArgsAsList.toArray(new String[whereArgsAsList.size()]);
+ // Convert List into WhereArgs
+ final String[] whereArgs = whereArgsAsList.toArray(new String[whereArgsAsList.size()]);
- //
- // Run the original query but constrained with full account name containing constraint
- //
+ //
+ // Run the original query but constrained with full account name containing constraint
+ //
- final AccountsDbAdapter accountsDbAdapter = AccountsDbAdapter.getInstance();
+ final AccountsDbAdapter accountsDbAdapter = AccountsDbAdapter.getInstance();
- final String where = ((getCursorWhere() != null)
- ? getCursorWhere() + " AND "
- : "")
- + DatabaseSchema.AccountEntry.COLUMN_FULL_NAME
- + " LIKE ?";
+ final String where = ((getCursorWhere() != null)
+ ? getCursorWhere() + " AND "
+ : "")
+ + DatabaseSchema.AccountEntry.COLUMN_FULL_NAME
+ + " LIKE ?";
- final Cursor accountsCursor = accountsDbAdapter.fetchAccountsOrderedByFavoriteAndFullName(where,
- whereArgs);
+ final Cursor accountsCursor = accountsDbAdapter.fetchAccountsOrderedByFavoriteAndFullName(where,
+ whereArgs);
- return accountsCursor;
- }
+ return accountsCursor;
});
}