From 59a8d1ac40bd0ca1a244793ea1a383e6c99ff69d Mon Sep 17 00:00:00 2001 From: Eryn O'Neil Date: Tue, 15 Dec 2015 13:44:54 -0600 Subject: [PATCH 01/28] Fixed grammar in section about release notifications. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 893e4f50b..766dc11aa 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ It's also on Google Play: src="https://developer.android.com/images/brand/en_generic_rgb_wo_60.png" /> -Having the application installed is a good way to be notified of new releases. Although Watching this +Having the application installed is a good way to be notified of new releases. However, watching this repository will allow GitHub to email you whenever we publish a release. From d2275b7a7775a4b4128c24ec765c76d74c873f10 Mon Sep 17 00:00:00 2001 From: Dan Lew Date: Tue, 15 Dec 2015 14:52:03 -0600 Subject: [PATCH 02/28] User generics with List For type safety --- .../habitrpg/android/habitica/userpicture/UserPicture.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java b/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java index 6697703dc..0eca7d9ea 100644 --- a/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java +++ b/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java @@ -38,7 +38,7 @@ public class UserPicture { private String currentCacheFileName; - List layers = new ArrayList(); + final List layers = new ArrayList<>(); public UserPicture(HabitRPGUser user, Context context) { this.user = user; @@ -176,7 +176,7 @@ public class UserPicture { Integer layerNumber = 0; this.numOfTasks.set(layerNames.size()); for (String layer : layerNames) { - layers.add(0); + layers.add(null); SpriteTarget target = new SpriteTarget(layerNumber, layer); Picasso.with(this.context).load("https://habitica-assets.s3.amazonaws.com/mobileApp/images/" + layer + ".png").into(target); layerNumber = layerNumber + 1; From b3b59cbb4d7e70b0cc5bb3c0eefd5051a4d069bb Mon Sep 17 00:00:00 2001 From: Dan Lew Date: Tue, 15 Dec 2015 14:52:52 -0600 Subject: [PATCH 03/28] Ensure layers is reset when generating new images Otherwise we keep adding layers infinitely (even if we only use a handful of them). Worst-case scenario, this leads to memory leaks with Bitmaps retained at the end of the layer list. --- .../com/habitrpg/android/habitica/userpicture/UserPicture.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java b/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java index 0eca7d9ea..90e1fd43b 100644 --- a/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java +++ b/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java @@ -175,6 +175,7 @@ public class UserPicture { private void generateImage(List layerNames) { Integer layerNumber = 0; this.numOfTasks.set(layerNames.size()); + layers.clear(); for (String layer : layerNames) { layers.add(null); SpriteTarget target = new SpriteTarget(layerNumber, layer); From 0c038dab977d16975cacf126370b1836fac871f8 Mon Sep 17 00:00:00 2001 From: Dan Lew Date: Tue, 15 Dec 2015 15:00:43 -0600 Subject: [PATCH 04/28] Clear current UserPicture before loading new one Otherwise, when scrolling quickly through a recycled environment (like an Adapter), existing loads would continue even when the same ImageView has been assigned a new UserPicture. This would result in member avatars flashing from one thing to the next. --- .../android/habitica/userpicture/UserPicture.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java b/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java index 90e1fd43b..32f1c4101 100644 --- a/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java +++ b/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java @@ -92,8 +92,7 @@ public class UserPicture { } public void setPictureOn(final ImageView imageView) { - UserPicture.this.imageView = imageView; - + this.imageView = imageView; List layerNames = UserPicture.this.getLayerNames(); final Bitmap cache = UserPicture.this.getCachedImage(layerNames); @@ -104,9 +103,12 @@ public class UserPicture { return; } + // Clear out current image while loading the new one + imageView.setImageBitmap(null); + Picasso.with(context).cancelRequest(imageView); + // no => generate it generateImage(layerNames); - } public void setPictureWithRunnable(UserPictureRunnable runnable) { @@ -121,6 +123,10 @@ public class UserPicture { return; } + // Clear out current image while loading the new one + runnable.run(null); + + // no => generate it generateImage(layerNames); } From f64d831e77b532e89343397e204bb01c604ffe3f Mon Sep 17 00:00:00 2001 From: Dan Lew Date: Tue, 15 Dec 2015 15:14:51 -0600 Subject: [PATCH 05/28] Ensured constants are static final (and private if possible) --- .../android/habitica/HabiticaPurchaseVerifier.java | 2 +- .../habitica/ui/adapter/ChatRecyclerViewAdapter.java | 6 +++--- .../ui/adapter/HabitItemRecyclerViewAdapter.java | 4 ++-- .../ui/adapter/SkillTasksRecyclerViewAdapter.java | 2 +- .../habitica/ui/fragments/GemsPurchaseFragment.java | 2 +- .../android/habitica/ui/fragments/TasksFragment.java | 4 ++-- .../android/habitica/userpicture/UserPicture.java | 8 ++++---- .../habitrpgwrapper/lib/models/ChatMessage.java | 2 +- .../habitrpgwrapper/lib/models/tasks/Task.java | 12 ++++++------ 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Habitica/src/com/habitrpg/android/habitica/HabiticaPurchaseVerifier.java b/Habitica/src/com/habitrpg/android/habitica/HabiticaPurchaseVerifier.java index 053747583..1e6d3fb0c 100644 --- a/Habitica/src/com/habitrpg/android/habitica/HabiticaPurchaseVerifier.java +++ b/Habitica/src/com/habitrpg/android/habitica/HabiticaPurchaseVerifier.java @@ -23,7 +23,7 @@ import java.util.Set; public class HabiticaPurchaseVerifier extends BasePurchaseVerifier { private Set purchasedOrderList = new HashSet<>(); - static String PURCHASED_PRODUCTS_KEY = "PURCHASED_PRODUCTS"; + private static final String PURCHASED_PRODUCTS_KEY = "PURCHASED_PRODUCTS"; private SharedPreferences preferences; public HabiticaPurchaseVerifier(Context context) { diff --git a/Habitica/src/com/habitrpg/android/habitica/ui/adapter/ChatRecyclerViewAdapter.java b/Habitica/src/com/habitrpg/android/habitica/ui/adapter/ChatRecyclerViewAdapter.java index 07482ddb2..72340fe3b 100644 --- a/Habitica/src/com/habitrpg/android/habitica/ui/adapter/ChatRecyclerViewAdapter.java +++ b/Habitica/src/com/habitrpg/android/habitica/ui/adapter/ChatRecyclerViewAdapter.java @@ -42,9 +42,9 @@ import de.greenrobot.event.EventBus; * Created by Negue on 20.08.2015. */ public class ChatRecyclerViewAdapter extends RecyclerView.Adapter { - static final int TYPE_DANIEL = 0; - static final int TYPE_NEW_MESSAGE = 1; - static final int TYPE_MESSAGE = 2; + private static final int TYPE_DANIEL = 0; + private static final int TYPE_NEW_MESSAGE = 1; + private static final int TYPE_MESSAGE = 2; private List messages; private Context viewContext; diff --git a/Habitica/src/com/habitrpg/android/habitica/ui/adapter/HabitItemRecyclerViewAdapter.java b/Habitica/src/com/habitrpg/android/habitica/ui/adapter/HabitItemRecyclerViewAdapter.java index b47ae0c3a..f1fb9f530 100644 --- a/Habitica/src/com/habitrpg/android/habitica/ui/adapter/HabitItemRecyclerViewAdapter.java +++ b/Habitica/src/com/habitrpg/android/habitica/ui/adapter/HabitItemRecyclerViewAdapter.java @@ -71,8 +71,8 @@ public class HabitItemRecyclerViewAdapter Context context; public int dailyResetOffset; - static final int TYPE_HEADER = 0; - static final int TYPE_CELL = 1; + private static final int TYPE_HEADER = 0; + private static final int TYPE_CELL = 1; private RecyclerView.Adapter parentAdapter; private TagsHelper tagsHelper; private IAdditionalEntries additionalEntries; diff --git a/Habitica/src/com/habitrpg/android/habitica/ui/adapter/SkillTasksRecyclerViewAdapter.java b/Habitica/src/com/habitrpg/android/habitica/ui/adapter/SkillTasksRecyclerViewAdapter.java index 9d4c14f41..ad1a6a55e 100644 --- a/Habitica/src/com/habitrpg/android/habitica/ui/adapter/SkillTasksRecyclerViewAdapter.java +++ b/Habitica/src/com/habitrpg/android/habitica/ui/adapter/SkillTasksRecyclerViewAdapter.java @@ -30,7 +30,7 @@ public class SkillTasksRecyclerViewAdapter extends RecyclerView.Adapter observableContent; SkillTasksActivity activity; - static final int TYPE_CELL = 1; + private static final int TYPE_CELL = 1; private RecyclerView.Adapter parentAdapter; public SkillTasksRecyclerViewAdapter(String taskType, SkillTasksActivity activity) { diff --git a/Habitica/src/com/habitrpg/android/habitica/ui/fragments/GemsPurchaseFragment.java b/Habitica/src/com/habitrpg/android/habitica/ui/fragments/GemsPurchaseFragment.java index 82cbab636..e8fe52725 100644 --- a/Habitica/src/com/habitrpg/android/habitica/ui/fragments/GemsPurchaseFragment.java +++ b/Habitica/src/com/habitrpg/android/habitica/ui/fragments/GemsPurchaseFragment.java @@ -30,7 +30,7 @@ import io.fabric.sdk.android.Fabric; */ public class GemsPurchaseFragment extends BaseFragment { - static final int GEMS_TO_ADD = 21; + private static final int GEMS_TO_ADD = 21; private BillingRequests billingRequests; diff --git a/Habitica/src/com/habitrpg/android/habitica/ui/fragments/TasksFragment.java b/Habitica/src/com/habitrpg/android/habitica/ui/fragments/TasksFragment.java index dc4c2a527..3225dfd92 100644 --- a/Habitica/src/com/habitrpg/android/habitica/ui/fragments/TasksFragment.java +++ b/Habitica/src/com/habitrpg/android/habitica/ui/fragments/TasksFragment.java @@ -71,8 +71,8 @@ import retrofit.client.Response; public class TasksFragment extends BaseFragment implements OnCheckedChangeListener { - static final int TASK_CREATED_RESULT = 1; - static final int TASK_UPDATED_RESULT = 2; + private static final int TASK_CREATED_RESULT = 1; + private static final int TASK_UPDATED_RESULT = 2; public ViewPager viewPager; Drawer filterDrawer; diff --git a/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java b/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java index 6697703dc..72823613f 100644 --- a/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java +++ b/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java @@ -22,10 +22,10 @@ import java.util.concurrent.atomic.AtomicInteger; public class UserPicture { - static Integer width = 140; - static Integer height = 147; - static Integer compactWidth = 103; - static Integer compactHeight = 90; + private static final Integer width = 140; + private static final Integer height = 147; + private static final Integer compactWidth = 103; + private static final Integer compactHeight = 90; private HabitRPGUser user; private ImageView imageView; diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/ChatMessage.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/ChatMessage.java index bca4aa70b..9acec34d2 100644 --- a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/ChatMessage.java +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/ChatMessage.java @@ -11,7 +11,7 @@ import java.util.HashMap; */ public class ChatMessage { - static HashMap contributorColorDict; + private static final HashMap contributorColorDict; static { contributorColorDict = new HashMap<>(); diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Task.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Task.java index fab32482e..d7ec4d302 100644 --- a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Task.java +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/tasks/Task.java @@ -27,12 +27,12 @@ import java.util.concurrent.TimeUnit; @ModelContainer @Table(databaseName = HabitDatabase.NAME) public class Task extends BaseModel { - public static String TYPE_HABIT = "habit"; - public static String TYPE_TODO = "todo"; - public static String TYPE_DAILY = "daily"; - public static String TYPE_REWARD = "reward"; - public static String FREQUENCY_WEEKLY = "weekly"; - public static String FREQUENCY_DAILY = "daily"; + public static final String TYPE_HABIT = "habit"; + public static final String TYPE_TODO = "todo"; + public static final String TYPE_DAILY = "daily"; + public static final String TYPE_REWARD = "reward"; + public static final String FREQUENCY_WEEKLY = "weekly"; + public static final String FREQUENCY_DAILY = "daily"; @Column From a1a8fb7384193f0dc19aea639ed6e99e06f350cf Mon Sep 17 00:00:00 2001 From: Dan Lew Date: Tue, 15 Dec 2015 15:16:05 -0600 Subject: [PATCH 06/28] Ensured constants use ALL_CAPS naming, as per Java convention --- .../habitica/userpicture/UserPicture.java | 12 ++++---- .../lib/models/ChatMessage.java | 28 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java b/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java index 72823613f..a19564f90 100644 --- a/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java +++ b/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java @@ -22,10 +22,10 @@ import java.util.concurrent.atomic.AtomicInteger; public class UserPicture { - private static final Integer width = 140; - private static final Integer height = 147; - private static final Integer compactWidth = 103; - private static final Integer compactHeight = 90; + private static final Integer WIDTH = 140; + private static final Integer HEIGHT = 147; + private static final Integer COMPACT_WIDTH = 103; + private static final Integer COMPACT_HEIGHT = 90; private HabitRPGUser user; private ImageView imageView; @@ -63,7 +63,7 @@ public class UserPicture { BitmapFactory.Options o = new BitmapFactory.Options(); o.inScaled = false; - Bitmap res = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + Bitmap res = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888); Canvas myCanvas = new Canvas(res); Integer layerNumber = 0; for (Object layer : this.layers) { @@ -74,7 +74,7 @@ public class UserPicture { layerNumber++; } if (!this.hasPetMount) { - res = Bitmap.createBitmap(res, 25, 18, compactWidth, compactHeight); + res = Bitmap.createBitmap(res, 25, 18, COMPACT_WIDTH, COMPACT_HEIGHT); } BitmapUtils.saveToFile(currentCacheFileName, res); if (this.imageView != null) { diff --git a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/ChatMessage.java b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/ChatMessage.java index 9acec34d2..4640c2f18 100644 --- a/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/ChatMessage.java +++ b/Habitica/src/com/magicmicky/habitrpgwrapper/lib/models/ChatMessage.java @@ -11,20 +11,20 @@ import java.util.HashMap; */ public class ChatMessage { - private static final HashMap contributorColorDict; + private static final HashMap CONTRIBUTOR_COLOR_DICT; static { - contributorColorDict = new HashMap<>(); - contributorColorDict.put(0, R.color.contributor_0); - contributorColorDict.put(1, R.color.contributor_1); - contributorColorDict.put(2, R.color.contributor_2); - contributorColorDict.put(3, R.color.contributor_3); - contributorColorDict.put(4, R.color.contributor_4); - contributorColorDict.put(5, R.color.contributor_5); - contributorColorDict.put(6, R.color.contributor_6); - contributorColorDict.put(7, R.color.contributor_7); - contributorColorDict.put(8, R.color.contributor_mod); - contributorColorDict.put(9, R.color.contributor_staff); + CONTRIBUTOR_COLOR_DICT = new HashMap<>(); + CONTRIBUTOR_COLOR_DICT.put(0, R.color.contributor_0); + CONTRIBUTOR_COLOR_DICT.put(1, R.color.contributor_1); + CONTRIBUTOR_COLOR_DICT.put(2, R.color.contributor_2); + CONTRIBUTOR_COLOR_DICT.put(3, R.color.contributor_3); + CONTRIBUTOR_COLOR_DICT.put(4, R.color.contributor_4); + CONTRIBUTOR_COLOR_DICT.put(5, R.color.contributor_5); + CONTRIBUTOR_COLOR_DICT.put(6, R.color.contributor_6); + CONTRIBUTOR_COLOR_DICT.put(7, R.color.contributor_7); + CONTRIBUTOR_COLOR_DICT.put(8, R.color.contributor_mod); + CONTRIBUTOR_COLOR_DICT.put(9, R.color.contributor_staff); } @@ -51,8 +51,8 @@ public class ChatMessage { if (contributor != null) { - if (contributorColorDict.containsKey(contributor.level)) { - rColor = contributorColorDict.get(contributor.level); + if (CONTRIBUTOR_COLOR_DICT.containsKey(contributor.level)) { + rColor = CONTRIBUTOR_COLOR_DICT.get(contributor.level); } } From d169613478efea6bd72b69e21eb9a0469451d813 Mon Sep 17 00:00:00 2001 From: Dan Lew Date: Tue, 15 Dec 2015 15:16:37 -0600 Subject: [PATCH 07/28] Converted Integer constants -> int Integer isn't necessary and actually just slows things down due to autoboxing. --- .../android/habitica/userpicture/UserPicture.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java b/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java index a19564f90..d6cb22bc9 100644 --- a/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java +++ b/Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java @@ -22,10 +22,10 @@ import java.util.concurrent.atomic.AtomicInteger; public class UserPicture { - private static final Integer WIDTH = 140; - private static final Integer HEIGHT = 147; - private static final Integer COMPACT_WIDTH = 103; - private static final Integer COMPACT_HEIGHT = 90; + private static final int WIDTH = 140; + private static final int HEIGHT = 147; + private static final int COMPACT_WIDTH = 103; + private static final int COMPACT_HEIGHT = 90; private HabitRPGUser user; private ImageView imageView; From 388358cb859503f5e07d2df86a1ada522dac9acb Mon Sep 17 00:00:00 2001 From: Eryn O'Neil Date: Tue, 15 Dec 2015 23:05:09 -0600 Subject: [PATCH 08/28] Cleaned up README grammar and formatting --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 766dc11aa..af327c450 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ It's also on Google Play: src="https://developer.android.com/images/brand/en_generic_rgb_wo_60.png" /> -Having the application installed is a good way to be notified of new releases. However, watching this +Having the application installed is a good way to be notified of new releases. However, clicking "Watch" on this repository will allow GitHub to email you whenever we publish a release. @@ -25,7 +25,7 @@ If you Watch this repository, GitHub will send you an email every time we publis For an introduction to the technologies used and how the software is organized, refer to [Contributing to Habitica](http://habitica.wikia.com/wiki/Contributing_to_Habitica#Coders_.28Web_.26_Mobile.29) - "Coders (Web & Mobile)" section. -Thank you very much [for all contributors](https://github.com/HabitRPG/habitrpg-android/graphs/contributors) +Thank you very much [to all contributors](https://github.com/HabitRPG/habitrpg-android/graphs/contributors). #### Steps for contributing to this repository: @@ -34,5 +34,5 @@ Thank you very much [for all contributors](https://github.com/HabitRPG/habitrpg- 3. Commit your changes: `git commit -am 'Add some feature'` 4. Push to the branch: `git push origin my-new-feature` 5. Create new Pull Request - Don't forget to include your Habitica User ID, so that we can count your contributrion towards your contributor tier + * Don't forget to include your Habitica User ID, so that we can count your contributrion towards your contributor tier From 5851bacb986858c16b700076a7b0ec3fffd17033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20D=C3=B6rfler?= Date: Wed, 16 Dec 2015 14:39:32 +0100 Subject: [PATCH 09/28] optical feedback on habit button +/- touch --- .../res/drawable-v21/btn_habit_background.xml | 6 +++ .../res/drawable/btn_habit_background.xml | 5 ++- Habitica/res/layout/habit_item_card.xml | 42 ++++++++++++------- 3 files changed, 37 insertions(+), 16 deletions(-) create mode 100644 Habitica/res/drawable-v21/btn_habit_background.xml diff --git a/Habitica/res/drawable-v21/btn_habit_background.xml b/Habitica/res/drawable-v21/btn_habit_background.xml new file mode 100644 index 000000000..3a8206c07 --- /dev/null +++ b/Habitica/res/drawable-v21/btn_habit_background.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/Habitica/res/drawable/btn_habit_background.xml b/Habitica/res/drawable/btn_habit_background.xml index d37216452..15f0d9b3a 100644 --- a/Habitica/res/drawable/btn_habit_background.xml +++ b/Habitica/res/drawable/btn_habit_background.xml @@ -1,12 +1,13 @@ - + - + + diff --git a/Habitica/res/layout/habit_item_card.xml b/Habitica/res/layout/habit_item_card.xml index ba2794a53..3d30bddc1 100644 --- a/Habitica/res/layout/habit_item_card.xml +++ b/Habitica/res/layout/habit_item_card.xml @@ -25,26 +25,40 @@ android:layout_height="match_parent" android:orientation="horizontal" android:id="@+id/btnLayout"> -