diff --git a/README.md b/README.md index d87553ca9..fc3da1afd 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,22 @@ There are different ways to get the Gnucash app for Android; through the app sto ### With Gradle -Run `gradlew build installDebug` from the within the project folder. +This project requires the [Android SDK](http://developer.android.com/sdk/index.html) +to be installed in your development environment. In addition you'll need to set +the `ANDROID_HOME` environment variable to the location of your SDK. For example: + + export ANDROID_HOME=/home//tools/android-sdk + +After satisfying those requirements, the build is pretty simple: + +* Run `gradlew build installDebug` from the within the project folder. It will build the project for you and install it to the connected Android device or running emulator. +You might find that your device doesn't let you install your build if you +already have the version from the Android Market installed. This is standard +Android security as it it won't let you directly replace an app that's been +signed with a different key. Manually uninstall GnuCash from your device and +you will then be able to install your own built version. ### With Android Studio The easiest way to build is to install [Android Studio](https://developer.android.com/sdk/index.html) v1.+ @@ -38,27 +51,6 @@ Once installed, then you can import the project into Android Studio: Then, Gradle will do everything for you. -### With Maven -The build requires [Maven](http://maven.apache.org/download.html) -v3.1.1+ and the [Android SDK](http://developer.android.com/sdk/index.html) -to be installed in your development environment. In addition you'll need to set -the `ANDROID_HOME` environment variable to the location of your SDK: - - export ANDROID_HOME=/home//tools/android-sdk - -After satisfying those requirements, the build is pretty simple: - -* Run `mvn clean package` from the `app` directory to build the APK only -* Run `mvn clean install` from the root directory to build the app and also run - the integration tests, this requires a connected Android device or running - emulator. (see this [blog post](http://goo.gl/TprMw) for details) - -You might find that your device doesn't let you install your build if you -already have the version from the Android Market installed. This is standard -Android security as it it won't let you directly replace an app that's been -signed with a different key. Manually uninstall GnuCash from your device and -you will then be able to install your own built version. - ## Contributing There are several ways you could contribute to the development. diff --git a/app/pom.xml b/app/pom.xml deleted file mode 100644 index 2c6885dde..000000000 --- a/app/pom.xml +++ /dev/null @@ -1,83 +0,0 @@ - - - - 4.0.0 - gnucash-android - apk - Gnucash for Android - App - Gnucash Android companion application - - - 1.5.4-SNAPSHOT - org.gnucash.android - gnucash-android-parent - - - - 4.4.0 - 2.4.1 - 1.5.2 - - - - - com.google.android - android - provided - ${android.version} - - - com.actionbarsherlock - actionbarsherlock - ${abs.version} - apklib - - - com.google.android - support-v4 - - - - - com.viewpagerindicator - library - ${viewpagerindicator.version} - apklib - - - com.google.android - support-v4 - - - - - com.doomonafireball.betterpickers - library - ${betterpickers.version} - aar - - - - - - com.simpligility.maven.plugins - android-maven-plugin - - - - - \ No newline at end of file diff --git a/app/src/main/java/org/gnucash/android/model/ScheduledEvent.java b/app/src/main/java/org/gnucash/android/model/ScheduledEvent.java index ef2950e1a..54a034fee 100644 --- a/app/src/main/java/org/gnucash/android/model/ScheduledEvent.java +++ b/app/src/main/java/org/gnucash/android/model/ScheduledEvent.java @@ -62,6 +62,7 @@ public enum EventType {TRANSACTION}; public ScheduledEvent(EventType eventType){ mUID = UUID.randomUUID().toString().replaceAll("-", ""); mEventType = eventType; + mStartDate = System.currentTimeMillis(); } public String getUID(){ @@ -123,7 +124,12 @@ public void setEndTime(long endDate) { @Override public String toString() { SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy"); - return mEventType.name() + " recurring every " + mPeriod/ RecurrenceParser.DAY_MILLIS + " days starting on " + String eventString = mEventType.name() + " recurring every " + mPeriod/ RecurrenceParser.DAY_MILLIS + " days starting on " + dateFormat.format(new Date(mStartDate)); + if (mEndDate > 0){ + eventString += " until " + dateFormat.format(mEndDate); + } + + return eventString; } } 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 06101fcef..579a2dcbb 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 @@ -709,11 +709,10 @@ private void scheduleRecurringTransaction() { ScheduledEventDbAdapter scheduledEventDbAdapter = GnuCashApplication.getScheduledEventDbAdapter(); Toast.makeText(getActivity(), "Found " + events.size() + " events", Toast.LENGTH_LONG).show(); for (ScheduledEvent event : events) { - scheduledEventDbAdapter.addScheduledEvent(event); event.setEventUID(recurringTransaction.getUID()); scheduledEventDbAdapter.addScheduledEvent(event); - Log.d("TransactionFormFragment", event.toString()); + Log.i("TransactionFormFragment", event.toString()); } } diff --git a/app/src/main/java/org/gnucash/android/ui/util/RecurrenceParser.java b/app/src/main/java/org/gnucash/android/ui/util/RecurrenceParser.java index 8c57a6f80..e9b356d29 100644 --- a/app/src/main/java/org/gnucash/android/ui/util/RecurrenceParser.java +++ b/app/src/main/java/org/gnucash/android/ui/util/RecurrenceParser.java @@ -35,7 +35,7 @@ public class RecurrenceParser { public static final long MINUTE_MILLIS = 60*SECOND_MILLIS; public static final long DAY_MILLIS = 24*60*MINUTE_MILLIS; public static final long WEEK_MILLIS = 7*DAY_MILLIS; - public static final long MONTH_MILLIS = 4*WEEK_MILLIS; + public static final long MONTH_MILLIS = 30*DAY_MILLIS; public static final long YEAR_MILLIS = 12*MONTH_MILLIS; @@ -51,60 +51,62 @@ public static List parse(EventRecurrence eventRecurrence, Schedu long period = 0; List scheduledEventList = new ArrayList(); switch(eventRecurrence.freq){ - case EventRecurrence.DAILY: - period = DAY_MILLIS; + case EventRecurrence.DAILY: { + if (eventRecurrence.interval == 0) //I assume this is a bug from the picker library + period = DAY_MILLIS; + else + period = eventRecurrence.interval * DAY_MILLIS; + + ScheduledEvent scheduledEvent = new ScheduledEvent(eventType); + scheduledEvent.setPeriod(period); + parseEndTime(eventRecurrence, scheduledEvent); + scheduledEventList.add(scheduledEvent); + } break; case EventRecurrence.WEEKLY: { - period = WEEK_MILLIS; + if (eventRecurrence.interval == 0) + period = WEEK_MILLIS; + else + period = eventRecurrence.interval * WEEK_MILLIS; for (int day : eventRecurrence.byday) { ScheduledEvent scheduledEvent = new ScheduledEvent(eventType); scheduledEvent.setPeriod(period); - scheduledEvent.setStartTime(nextDayOfWeek(day).getTimeInMillis()); - if (eventRecurrence.until != null && eventRecurrence.until.length() > 0) { - Time endTime = new Time(); - endTime.parse(eventRecurrence.until); - scheduledEvent.setEndTime(endTime.toMillis(false)); - } else if (eventRecurrence.count > 0){ - scheduledEvent.setEndTime(scheduledEvent.getStartTime() + (scheduledEvent.getPeriod() * eventRecurrence.count)); - } + scheduledEvent.setStartTime(nextDayOfWeek(day2CalendarDay(day)).getTimeInMillis()); + parseEndTime(eventRecurrence, scheduledEvent); scheduledEventList.add(scheduledEvent); } } break; case EventRecurrence.MONTHLY: { + if (eventRecurrence.interval == 0) + period = MONTH_MILLIS; + else + period = eventRecurrence.interval * MONTH_MILLIS; ScheduledEvent event = new ScheduledEvent(eventType); - event.setPeriod(MONTH_MILLIS); + event.setPeriod(period); Calendar now = Calendar.getInstance(); now.add(Calendar.MONTH, 1); event.setStartTime(now.getTimeInMillis()); - if (eventRecurrence.until != null && eventRecurrence.until.length() > 0) { - Time endTime = new Time(); - endTime.parse(eventRecurrence.until); - event.setEndTime(endTime.toMillis(false)); - } else if (eventRecurrence.count > 0){ - event.setEndTime(event.getStartTime() + (event.getPeriod()*eventRecurrence.count)); - } + parseEndTime(eventRecurrence, event); scheduledEventList.add(event); } break; case EventRecurrence.YEARLY: { + if (eventRecurrence.interval == 0) + period = YEAR_MILLIS; + else + period = eventRecurrence.interval * YEAR_MILLIS; ScheduledEvent event = new ScheduledEvent(eventType); - event.setPeriod(YEAR_MILLIS); + event.setPeriod(period); Calendar now = Calendar.getInstance(); now.add(Calendar.YEAR, 1); event.setStartTime(now.getTimeInMillis()); - if (eventRecurrence.until != null && eventRecurrence.until.length() > 0) { - Time endTime = new Time(); - endTime.parse(eventRecurrence.until); - event.setEndTime(endTime.toMillis(false)); - } else if (eventRecurrence.count > 0){ - event.setEndTime(event.getStartTime() + (event.getPeriod()*eventRecurrence.count)); - } + parseEndTime(eventRecurrence, event); scheduledEventList.add(event); } break; @@ -112,6 +114,27 @@ public static List parse(EventRecurrence eventRecurrence, Schedu return scheduledEventList; } + /** + * Parses the end time from an EventRecurrence object and sets it to the scheduledEvent. + * The end time is specified in the dialog either by number of occurences or a date. + * @param eventRecurrence Event recurrence pattern obtained from dialog + * @param scheduledEvent ScheduledEvent to be to updated + */ + private static void parseEndTime(EventRecurrence eventRecurrence, ScheduledEvent scheduledEvent) { + if (eventRecurrence.until != null && eventRecurrence.until.length() > 0) { + Time endTime = new Time(); + endTime.parse(eventRecurrence.until); + scheduledEvent.setEndTime(endTime.toMillis(false)); + } else if (eventRecurrence.count > 0){ + scheduledEvent.setEndTime(scheduledEvent.getStartTime() + (scheduledEvent.getPeriod() * eventRecurrence.count)); + } + } + + /** + * Returns the date for the next day of the week + * @param dow Day of the week (Calendar constants) + * @return Calendar instance with the next day of the week + */ private static Calendar nextDayOfWeek(int dow) { Calendar date = Calendar.getInstance(); int diff = dow - date.get(Calendar.DAY_OF_WEEK); @@ -121,4 +144,32 @@ private static Calendar nextDayOfWeek(int dow) { date.add(Calendar.DAY_OF_MONTH, diff); return date; } + + /** + * Converts one of the SU, MO, etc. constants to the Calendar.SUNDAY + * constants. btw, I think we should switch to those here too, to + * get rid of this function, if possible. + */ + public static int day2CalendarDay(int day) + { + switch (day) + { + case EventRecurrence.SU: + return Calendar.SUNDAY; + case EventRecurrence.MO: + return Calendar.MONDAY; + case EventRecurrence.TU: + return Calendar.TUESDAY; + case EventRecurrence.WE: + return Calendar.WEDNESDAY; + case EventRecurrence.TH: + return Calendar.THURSDAY; + case EventRecurrence.FR: + return Calendar.FRIDAY; + case EventRecurrence.SA: + return Calendar.SATURDAY; + default: + throw new RuntimeException("bad day of week: " + day); + } + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5d6f0947f..c5d60b16b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -17,7 +17,6 @@ GnuCash - 1.5.4 Create Account Edit Account Info diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml deleted file mode 100644 index 7ad84b2d5..000000000 --- a/integration-tests/pom.xml +++ /dev/null @@ -1,111 +0,0 @@ - - - - 4.0.0 - - 1.5.4-SNAPSHOT - org.gnucash.android - gnucash-android-parent - - gnucash-android-integration-tests - apk - Gnucash for Android - Integration Tests - Instrumentation tests for Gnucash for Android - - - 5.2.1 - 1.1.2 - 1.0.6 - usb - - - - - com.jayway.android.robotium - robotium-solo - ${robotium.version} - - - com.google.android - android - provided - ${android.version} - - - - com.google.android - android-test - provided - ${android.version} - - - com.squareup - fest-android - ${fest-android.version} - - - - org.gnucash.android - gnucash-android - ${project.version} - apk - provided - - - - - org.gnucash.android - gnucash-android - ${project.version} - provided - jar - - - com.google.android - support-v4 - r7 - - - - - - - com.simpligility.maven.plugins - android-maven-plugin - true - - - com.squareup.spoon - spoon-maven-plugin - ${spoon-client.version} - - GnuCash Android Integration Tests - true - - - - integration-test - - run - - - - - - - diff --git a/pom.xml b/pom.xml deleted file mode 100644 index b32f2dbf4..000000000 --- a/pom.xml +++ /dev/null @@ -1,85 +0,0 @@ - - - - - 4.0.0 - 1.5.4-SNAPSHOT - org.gnucash.android - gnucash-android-parent - GnuCash Android parent - Parent project of Gnucash for Android - pom - - - app - integration-tests - - - - UTF-8 - 4.1.1.4 - 4.1.1 - - - - - - - com.simpligility.maven.plugins - android-maven-plugin - ${android.maven.plugin.version} - true - - - ${env.ANDROID_HOME} - 19 - - true - - - - - - - - https://github.com/codinguser/gnucash-android/issues - GitHub Issues - - - - - Apache License Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.html - repo - - - - - https://github.com/codinguser/gnucash-android - scm:git:git://github.com/codinguser/gnucash-android.git - scm:git:git@github.com:codinguser/gnucash-android.git - - - - - Ngewi Fet - ngewif@gmail.com - http://www.codinguser.com - codinguser - - -