Skip to content

Commit

Permalink
use lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Yu committed May 21, 2020
1 parent 41c745c commit a9c14e7
Show file tree
Hide file tree
Showing 61 changed files with 765 additions and 1,116 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ android {
buildTypes {
//todo re-enable proguard and test coverage
release {
// minifyEnabled true
minifyEnabled true
// shrinkResources true
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
if (project.hasProperty("RELEASE_STORE_FILE")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,12 +497,7 @@ public void shouldShowWizardOnFirstRun() throws Throwable {
editor.remove(mAccountsActivity.getString(R.string.key_first_run)).commit();


mActivityRule.runOnUiThread(new Runnable() {
@Override
public void run() {
mAccountsActivity.recreate();
}
});
mActivityRule.runOnUiThread(() -> mAccountsActivity.recreate());

//check that wizard is shown
onView(withText(mAccountsActivity.getString(R.string.title_setup_gnucash)))
Expand All @@ -523,12 +518,9 @@ public void tearDown() throws Exception {
*/
private void refreshAccountsList() {
try {
mActivityRule.runOnUiThread(new Runnable() {
@Override
public void run() {
Fragment fragment = mAccountsActivity.getCurrentAccountListFragment();
((AccountsListFragment) fragment).refresh();
}
mActivityRule.runOnUiThread(() -> {
Fragment fragment = mAccountsActivity.getCurrentAccountListFragment();
((AccountsListFragment) fragment).refresh();
});
} catch (Throwable throwable) {
System.err.println("Failed to refresh fragment");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,13 @@ public void testSpinner() throws Exception {
public static ViewAction clickXY(final Position horizontal, final Position vertical){
return new GeneralClickAction(
Tap.SINGLE,
new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
int[] xy = new int[2];
view.getLocationOnScreen(xy);

float x = horizontal.getPosition(xy[0], view.getWidth());
float y = vertical.getPosition(xy[1], view.getHeight());
return new float[]{x, y};
}
view -> {
int[] xy = new int[2];
view.getLocationOnScreen(xy);

float x = horizontal.getPosition(xy[0], view.getWidth());
float y = vertical.getPosition(xy[1], view.getHeight());
return new float[]{x, y};
},
Press.FINGER);
}
Expand Down Expand Up @@ -267,12 +264,7 @@ public float getPosition(int viewPos, int viewLength) {
*/
private void refreshReport(){
try {
mActivityRule.runOnUiThread(new Runnable() {
@Override
public void run() {
mReportsActivity.refresh();
}
});
mActivityRule.runOnUiThread(() -> mReportsActivity.refresh());
} catch (Throwable t){
System.err.println("Faile to refresh reports");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -884,12 +884,7 @@ private void clickOnView(int viewId) {
*/
private void refreshTransactionsList() {
try {
mActivityRule.runOnUiThread(new Runnable() {
@Override
public void run() {
mTransactionsActivity.refresh();
}
});
mActivityRule.runOnUiThread(() -> mTransactionsActivity.refresh());
} catch (Throwable throwable) {
System.err.println("Failed to refresh fragment");
}
Expand Down
98 changes: 46 additions & 52 deletions app/src/main/java/org/gnucash/android/db/MigrationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,43 +188,40 @@ static void moveFile(File src, File dst) throws IOException {
* <p>The new folder structure also futher enables parallel installation of multiple flavours of
* the program (like development and production) on the same device.</p>
*/
static final Runnable moveExportedFilesToNewDefaultLocation = new Runnable() {
@Override
public void run() {
File oldExportFolder = new File(Environment.getExternalStorageDirectory() + "/gnucash");
if (oldExportFolder.exists()){
for (File src : oldExportFolder.listFiles()) {
if (src.isDirectory())
continue;
File dst = new File(Exporter.LEGACY_BASE_FOLDER_PATH + "/exports/" + src.getName());
try {
MigrationHelper.moveFile(src, dst);
} catch (IOException e) {
Log.e(LOG_TAG, "Error migrating " + src.getName());
Crashlytics.logException(e);
}
static final Runnable moveExportedFilesToNewDefaultLocation = () -> {
File oldExportFolder = new File(Environment.getExternalStorageDirectory() + "/gnucash");
if (oldExportFolder.exists()){
for (File src : oldExportFolder.listFiles()) {
if (src.isDirectory())
continue;
File dst = new File(Exporter.LEGACY_BASE_FOLDER_PATH + "/exports/" + src.getName());
try {
MigrationHelper.moveFile(src, dst);
} catch (IOException e) {
Log.e(LOG_TAG, "Error migrating " + src.getName());
Crashlytics.logException(e);
}
} else {
//if the base folder does not exist, no point going one level deeper
return;
}
} else {
//if the base folder does not exist, no point going one level deeper
return;
}

File oldBackupFolder = new File(oldExportFolder, "backup");
if (oldBackupFolder.exists()){
for (File src : new File(oldExportFolder, "backup").listFiles()) {
File dst = new File(Exporter.LEGACY_BASE_FOLDER_PATH + "/backups/" + src.getName());
try {
MigrationHelper.moveFile(src, dst);
} catch (IOException e) {
Log.e(LOG_TAG, "Error migrating backup: " + src.getName());
Crashlytics.logException(e);
}
File oldBackupFolder = new File(oldExportFolder, "backup");
if (oldBackupFolder.exists()){
for (File src : new File(oldExportFolder, "backup").listFiles()) {
File dst = new File(Exporter.LEGACY_BASE_FOLDER_PATH + "/backups/" + src.getName());
try {
MigrationHelper.moveFile(src, dst);
} catch (IOException e) {
Log.e(LOG_TAG, "Error migrating backup: " + src.getName());
Crashlytics.logException(e);
}
}

if (oldBackupFolder.delete())
oldExportFolder.delete();
}

if (oldBackupFolder.delete())
oldExportFolder.delete();
};

/**
Expand Down Expand Up @@ -1548,28 +1545,25 @@ public static int upgradeDbToVersion14(SQLiteDatabase db){
File backupFolder = new File(Exporter.BASE_FOLDER_PATH);
backupFolder.mkdir();

new Thread(new Runnable() {
@Override
public void run() {
File srcDir = new File(Exporter.LEGACY_BASE_FOLDER_PATH);
File dstDir = new File(Exporter.BASE_FOLDER_PATH);
try {
moveDirectory(srcDir, dstDir);
File readmeFile = new File(Exporter.LEGACY_BASE_FOLDER_PATH, "README.txt");
FileWriter writer = null;
writer = new FileWriter(readmeFile);
writer.write("Backup files have been moved to " + dstDir.getPath() +
"\nYou can now delete this folder");
writer.flush();
} catch (IOException | IllegalArgumentException ex) {
ex.printStackTrace();
String msg = String.format("Error moving files from %s to %s", srcDir.getPath(), dstDir.getPath());
Log.e(LOG_TAG, msg);
Crashlytics.log(msg);
Crashlytics.logException(ex);
}

new Thread(() -> {
File srcDir = new File(Exporter.LEGACY_BASE_FOLDER_PATH);
File dstDir = new File(Exporter.BASE_FOLDER_PATH);
try {
moveDirectory(srcDir, dstDir);
File readmeFile = new File(Exporter.LEGACY_BASE_FOLDER_PATH, "README.txt");
FileWriter writer = null;
writer = new FileWriter(readmeFile);
writer.write("Backup files have been moved to " + dstDir.getPath() +
"\nYou can now delete this folder");
writer.flush();
} catch (IOException | IllegalArgumentException ex) {
ex.printStackTrace();
String msg = String.format("Error moving files from %s to %s", srcDir.getPath(), dstDir.getPath());
Log.e(LOG_TAG, msg);
Crashlytics.log(msg);
Crashlytics.logException(ex);
}

}).start();

return 14;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ public boolean isActive(String bookUID){
if (cursor.getCount() == 0) {
NoActiveBookFoundException e = new NoActiveBookFoundException(
"There is no active book in the app."
+ "This should NEVER happen, fix your bugs!\n"
+ getNoActiveBookFoundExceptionInfo());
+ "This should NEVER happen, fix your bugs!\n"
+ getNoActiveBookFoundExceptionInfo());
e.printStackTrace();
throw e;
}
Expand All @@ -187,7 +187,7 @@ private String getNoActiveBookFoundExceptionInfo() {
return info.toString();
}

public class NoActiveBookFoundException extends RuntimeException {
public static class NoActiveBookFoundException extends RuntimeException {
public NoActiveBookFoundException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public Pair<Long, Long> getPrice(@NonNull String commodityUID, @NonNull String c
valueNum = valueDenom;
valueDenom = t;
}
return new Pair<Long, Long>(valueNum, valueDenom);
return new Pair<>(valueNum, valueDenom);
} else {
return pairZero;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,10 @@ protected Boolean doInBackground(ExportParams... params) {
Crashlytics.logException(e);
e.printStackTrace();
if (mContext instanceof Activity) {
((Activity)mContext).runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(mContext,
mContext.getString(R.string.toast_export_error, mExportParams.getExportFormat().name())
+ "\n" + e.getMessage(),
Toast.LENGTH_SHORT).show();
}
});
((Activity)mContext).runOnUiThread(() -> Toast.makeText(mContext,
mContext.getString(R.string.toast_export_error, mExportParams.getExportFormat().name())
+ "\n" + e.getMessage(),
Toast.LENGTH_SHORT).show());
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.gnucash.android.export;

import androidx.annotation.NonNull;

/**
* Enumeration of the different export formats supported by the application
* @author Ngewi Fet <[email protected]>
Expand Down Expand Up @@ -55,6 +57,7 @@ public String getExtension(){
}
}

@NonNull
@Override
public String toString() {
return mDescription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/org/gnucash/android/model/Commodity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/org/gnucash/android/model/Money.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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";
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/org/gnucash/android/model/Price.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.text.DecimalFormat;
import java.text.NumberFormat;

import androidx.annotation.NonNull;

/**
* Model for commodity prices
*/
Expand Down Expand Up @@ -150,6 +152,7 @@ private void reduce() {
*
* <p>Example: "0.123456"
*/
@NonNull
@Override
public String toString() {
BigDecimal numerator = new BigDecimal(mValueNum);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ public static ScheduledAction parseScheduledAction(Transaction transaction, long
return scheduledAction;
}

@NonNull
@Override
public String toString() {
return mActionType.name() + " - " + getRepeatString();
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/org/gnucash/android/model/Split.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ public void setReconcileDate(Timestamp reconcileDate) {
this.mReconcileDate = reconcileDate;
}

@NonNull
@Override
public String toString() {

Expand Down
Loading

0 comments on commit a9c14e7

Please sign in to comment.