From c25906400b26040797a2fab7b6bf53ed057a3ea5 Mon Sep 17 00:00:00 2001 From: derekcsm Date: Sun, 1 May 2016 23:53:35 -0700 Subject: [PATCH 01/10] update readme --- README.md | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a5c89aa..eae675c 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Discover and read about the Hubble Telescope's best images. ![icon](http://i.imgur.com/wEWW2OH.png) ---- -### [Google Play listing →](https://play.google.com/store/apps/details?id=com.getflow.tasks) +### [Google Play listing →](https://play.google.com/store/apps/details?id=com.derek_s.hubble_gallery) Maintained by [derekcsm](http://derekcsm.xyz/) @@ -17,15 +17,4 @@ Contributions by: - use 2 space `indents` and 4 space `continuation indents` for Java and Kotlin, and 2 space for indents & continuation in XML, we're slowing moving to that - try your best not to exceed horizontal line length -- don't include "created by" tags at top of classes, and if you find one remove it - -## Things to do - -- write tests for details activity -- re-write remaining classes from Java to Kotlin -- reconsider & improve Dagger2 implementation -- add shared element transition animation to details activity -- re-implement details activity loading -- improve details view layout setup -- use RecyclerView for main grid list -- improve Toolbar show/hide on scroll +- don't include "created by" or any other tags at top of classes, if you find any please remove them \ No newline at end of file From be0314b8f1fd5d066e81e2904f4af93604f38420 Mon Sep 17 00:00:00 2001 From: derekcsm Date: Mon, 2 May 2016 13:14:45 -0700 Subject: [PATCH 02/10] V+ 1.5.0 / 20 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index af8d9a7..93b7f5c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -29,8 +29,8 @@ android { compileSdkVersion 23 buildToolsVersion "23.0.2" - def verName = "1.2.5" - def verCode = 16 + def verName = "1.5.0" + def verCode = 20 defaultConfig { applicationId 'com.derek_s.hubble_gallery' From 71c8d76f063e5f546c684403a2b926163b084995 Mon Sep 17 00:00:00 2001 From: derekcsm Date: Mon, 2 May 2016 13:16:46 -0700 Subject: [PATCH 03/10] remove unused classes --- .../widgets/AnimatedExpandableListView.java | 534 ------------------ .../ui/widgets/ScrimInsetsFrameLayout.java | 154 ----- 2 files changed, 688 deletions(-) delete mode 100644 app/src/main/java/com/derek_s/hubble_gallery/ui/widgets/AnimatedExpandableListView.java delete mode 100644 app/src/main/java/com/derek_s/hubble_gallery/ui/widgets/ScrimInsetsFrameLayout.java diff --git a/app/src/main/java/com/derek_s/hubble_gallery/ui/widgets/AnimatedExpandableListView.java b/app/src/main/java/com/derek_s/hubble_gallery/ui/widgets/AnimatedExpandableListView.java deleted file mode 100644 index db23d14..0000000 --- a/app/src/main/java/com/derek_s/hubble_gallery/ui/widgets/AnimatedExpandableListView.java +++ /dev/null @@ -1,534 +0,0 @@ -package com.derek_s.hubble_gallery.ui.widgets; - -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.drawable.Drawable; -import android.util.AttributeSet; -import android.util.SparseArray; -import android.view.View; -import android.view.ViewGroup; -import android.view.animation.Animation; -import android.view.animation.Animation.AnimationListener; -import android.view.animation.Transformation; -import android.widget.BaseExpandableListAdapter; -import android.widget.ExpandableListAdapter; -import android.widget.ExpandableListView; - -import java.util.ArrayList; -import java.util.List; - -/** - * Created by dereksmith on 15-03-05. - */ -public class AnimatedExpandableListView extends ExpandableListView { - /* - * A detailed explanation for how this class works: - * - * Animating the ExpandableListView was no easy task. The way that this - * class does it is by exploiting how an ExpandableListView works. - * - * Normally when {@link ExpandableListView#collapseGroup(int)} or - * {@link ExpandableListView#expandGroup(int)} is called, the view toggles - * the flag for a group and calls notifyDataSetChanged to cause the ListView - * to refresh all of it's view. This time however, depending on whether a - * group is expanded or collapsed, certain childViews will either be ignored - * or added to the list. - * - * Knowing this, we can come up with a way to animate our views. For - * instance for group expansion, we tell the adapter to animate the - * children of a certain group. We then expand the group which causes the - * ExpandableListView to refresh all views on screen. The way that - * ExpandableListView does this is by calling getView() in the adapter. - * However since the adapter knows that we are animating a certain group, - * instead of returning the real views for the children of the group being - * animated, it will return a fake dummy view. This dummy view will then - * draw the real child views within it's dispatchDraw function. The reason - * we do this is so that we can animate all of it's children by simply - * animating the dummy view. After we complete the animation, we tell the - * adapter to stop animating the group and call notifyDataSetChanged. Now - * the ExpandableListView is forced to refresh it's views again, except this - * time, it will get the real views for the expanded group. - * - * So, to list it all out, when {@link #expandGroupWithAnimation(int)} is - * called the following happens: - * - * 1. The ExpandableListView tells the adapter to animate a certain group. - * 2. The ExpandableListView calls expandGroup. - * 3. ExpandGroup calls notifyDataSetChanged. - * 4. As an result, getChildView is called for expanding group. - * 5. Since the adapter is in "animating mode", it will return a dummy view. - * 6. This dummy view draws the actual children of the expanding group. - * 7. This dummy view's height is animated from 0 to it's expanded height. - * 8. Once the animation completes, the adapter is notified to stop - * animating the group and notifyDataSetChanged is called again. - * 9. This forces the ExpandableListView to refresh all of it's views again. - * 10.This time when getChildView is called, it will return the actual - * child views. - * - * For animating the collapse of a group is a bit more difficult since we - * can't call collapseGroup from the start as it would just ignore the - * child items, giving up no chance to do any sort of animation. Instead - * what we have to do is play the animation first and call collapseGroup - * after the animation is done. - * - * So, to list it all out, when {@link #collapseGroupWithAnimation(int)} is - * called the following happens: - * - * 1. The ExpandableListView tells the adapter to animate a certain group. - * 2. The ExpandableListView calls notifyDataSetChanged. - * 3. As an result, getChildView is called for expanding group. - * 4. Since the adapter is in "animating mode", it will return a dummy view. - * 5. This dummy view draws the actual children of the expanding group. - * 6. This dummy view's height is animated from it's current height to 0. - * 7. Once the animation completes, the adapter is notified to stop - * animating the group and notifyDataSetChanged is called again. - * 8. collapseGroup is finally called. - * 9. This forces the ExpandableListView to refresh all of it's views again. - * 10.This time when the ListView will not get any of the child views for - * the collapsed group. - */ - - /** - * The duration of the expand/collapse animations - */ - private static final int ANIMATION_DURATION = 215; - - private AnimatedExpandableListAdapter adapter; - - public AnimatedExpandableListView(Context context) { - super(context); - } - - public AnimatedExpandableListView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public AnimatedExpandableListView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - - /** - * @see android.widget.ExpandableListView#setAdapter(android.widget.ExpandableListAdapter) - */ - public void setAdapter(ExpandableListAdapter adapter) { - super.setAdapter(adapter); - - // Make sure that the adapter extends AnimatedExpandableListAdapter - if(adapter instanceof AnimatedExpandableListAdapter) { - this.adapter = (AnimatedExpandableListAdapter) adapter; - this.adapter.setParent(this); - } else { - throw new ClassCastException(adapter.toString() + " must implement AnimatedExpandableListAdapter"); - } - } - - /** - * Expands the given group with an animation. - * @param groupPos The position of the group to expand - * @return Returns true if the group was expanded. False if the group was - * already expanded. - */ - public boolean expandGroupWithAnimation(int groupPos) { - int groupFlatPos = getFlatListPosition(getPackedPositionForGroup(groupPos)); - if (groupFlatPos != -1) { - int childIndex = groupFlatPos - getFirstVisiblePosition(); - if (childIndex < getChildCount()) { - // Get the view for the group is it is on screen... - View v = getChildAt(childIndex); - if (v.getBottom() >= getBottom()) { - // If the user is not going to be able to see the animation - // we just expand the group without an animation. - // This resolves the case where getChildView will not be - // called if the children of the group is not on screen - return expandGroup(groupPos); - } - } - } - - // Let the adapter know that we are starting the animation... - adapter.startExpandAnimation(groupPos, 0); - // Finally call expandGroup (note that expandGroup will call - // notifyDataSetChanged so we don't need to) - return expandGroup(groupPos); - } - - /** - * Collapses the given group with an animation. - * @param groupPos The position of the group to collapse - * @return Returns true if the group was collapsed. False if the group was - * already collapsed. - */ - public boolean collapseGroupWithAnimation(int groupPos) { - int groupFlatPos = getFlatListPosition(getPackedPositionForGroup(groupPos)); - if (groupFlatPos != -1) { - int childIndex = groupFlatPos - getFirstVisiblePosition(); - if (childIndex >= 0 && childIndex < getChildCount()) { - // Get the view for the group is it is on screen... - View v = getChildAt(childIndex); - if (v.getBottom() >= getBottom()) { - // If the user is not going to be able to see the animation - // we just collapse the group without an animation. - // This resolves the case where getChildView will not be - // called if the children of the group is not on screen - return collapseGroup(groupPos); - } - } else { - // If the group is offscreen, we can just collapse it without an - // animation... - return collapseGroup(groupPos); - } - } - - // Get the position of the firstChild visible from the top of the screen - long packedPos = getExpandableListPosition(getFirstVisiblePosition()); - int firstChildPos = getPackedPositionChild(packedPos); - int firstGroupPos = getPackedPositionGroup(packedPos); - - // If the first visible view on the screen is a child view AND it's a - // child of the group we are trying to collapse, then set that - // as the first child position of the group... see - // {@link #startCollapseAnimation(int, int)} for why this is necessary - firstChildPos = firstChildPos == -1 || firstGroupPos != groupPos ? 0 : firstChildPos; - - // Let the adapter know that we are going to start animating the - // collapse animation. - adapter.startCollapseAnimation(groupPos, firstChildPos); - - // Force the listview to refresh it's views - adapter.notifyDataSetChanged(); - return isGroupExpanded(groupPos); - } - - private int getAnimationDuration() { - return ANIMATION_DURATION; - } - - /** - * Used for holding information regarding the group. - */ - private static class GroupInfo { - boolean animating = false; - boolean expanding = false; - int firstChildPosition; - - /** - * This variable contains the last known height value of the dummy view. - * We save this information so that if the user collapses a group - * before it fully expands, the collapse animation will start from the - * CURRENT height of the dummy view and not from the full expanded - * height. - */ - int dummyHeight = -1; - } - - /** - * A specialized adapter for use with the AnimatedExpandableListView. All - * adapters used with AnimatedExpandableListView MUST extend this class. - */ - public static abstract class AnimatedExpandableListAdapter extends BaseExpandableListAdapter { - private SparseArray groupInfo = new SparseArray<>(); - private AnimatedExpandableListView parent; - - private void setParent(AnimatedExpandableListView parent) { - this.parent = parent; - } - - public int getRealChildType(int groupPosition, int childPosition) { - return 0; - } - - public int getRealChildTypeCount() { - return 1; - } - - public abstract View getRealChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent); - public abstract int getRealChildrenCount(int groupPosition); - - private GroupInfo getGroupInfo(int groupPosition) { - GroupInfo info = groupInfo.get(groupPosition); - if (info == null) { - info = new GroupInfo(); - groupInfo.put(groupPosition, info); - } - return info; - } - - private void startExpandAnimation(int groupPosition, int firstChildPosition) { - GroupInfo info = getGroupInfo(groupPosition); - info.animating = true; - info.firstChildPosition = firstChildPosition; - info.expanding = true; - } - - private void startCollapseAnimation(int groupPosition, int firstChildPosition) { - GroupInfo info = getGroupInfo(groupPosition); - info.animating = true; - info.firstChildPosition = firstChildPosition; - info.expanding = false; - } - - private void stopAnimation(int groupPosition) { - GroupInfo info = getGroupInfo(groupPosition); - info.animating = false; - } - - /** - * Override {@link #getRealChildType(int, int)} instead. - */ - @Override - public final int getChildType(int groupPosition, int childPosition) { - GroupInfo info = getGroupInfo(groupPosition); - if (info.animating) { - // If we are animating this group, then all of it's children - // are going to be dummy views which we will say is type 0. - return 0; - } else { - // If we are not animating this group, then we will add 1 to - // the type it has so that no type id conflicts will occur - // unless getRealChildType() returns MAX_INT - return getRealChildType(groupPosition, childPosition) + 1; - } - } - - /** - * Override {@link #getRealChildTypeCount()} instead. - */ - @Override - public final int getChildTypeCount() { - // Return 1 more than the childTypeCount to account for DummyView - return getRealChildTypeCount() + 1; - } - - /** - * Override {@link #getChildView(int, int, boolean, android.view.View, android.view.ViewGroup)} instead. - */ - @Override - public final View getChildView(final int groupPosition, int childPosition, boolean isLastChild, View convertView, final ViewGroup parent) { - final GroupInfo info = getGroupInfo(groupPosition); - - if (info.animating) { - // If this group is animating, return the a DummyView... - if (convertView == null) { - convertView = new DummyView(parent.getContext()); - convertView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 0)); - } - - if (childPosition < info.firstChildPosition) { - // The reason why we do this is to support the collapse - // this group when the group view is not visible but the - // children of this group are. When notifyDataSetChanged - // is called, the ExpandableListView tries to keep the - // list position the same by saving the first visible item - // and jumping back to that item after the views have been - // refreshed. Now the problem is, if a group has 2 items - // and the first visible item is the 2nd child of the group - // and this group is collapsed, then the dummy view will be - // used for the group. But now the group only has 1 item - // which is the dummy view, thus when the ListView is trying - // to restore the scroll position, it will try to jump to - // the second item of the group. But this group no longer - // has a second item, so it is forced to jump to the next - // group. This will cause a very ugly visual glitch. So - // the way that we counteract this is by creating as many - // dummy views as we need to maintain the scroll position - // of the ListView after notifyDataSetChanged has been - // called. - convertView.getLayoutParams().height = 0; - return convertView; - } - - final ExpandableListView listView = (ExpandableListView) parent; - - DummyView dummyView = (DummyView) convertView; - - // Clear the views that the dummy view draws. - dummyView.clearViews(); - - // Set the style of the divider - dummyView.setDivider(listView.getDivider(), parent.getMeasuredWidth(), listView.getDividerHeight()); - - // Make measure specs to measure child views - final int measureSpecW = MeasureSpec.makeMeasureSpec(parent.getWidth(), MeasureSpec.EXACTLY); - final int measureSpecH = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); - - int totalHeight = 0; - int clipHeight = parent.getHeight(); - - final int len = getRealChildrenCount(groupPosition); - for (int i = info.firstChildPosition; i < len; i++) { - View childView = getRealChildView(groupPosition, i, (i == len - 1), null, parent); - childView.measure(measureSpecW, measureSpecH); - totalHeight += childView.getMeasuredHeight(); - - if (totalHeight < clipHeight) { - // we only need to draw enough views to fool the user... - dummyView.addFakeView(childView); - } else { - dummyView.addFakeView(childView); - - // if this group has too many views, we don't want to - // calculate the height of everything... just do a light - // approximation and break - int averageHeight = totalHeight / (i + 1); - totalHeight += (len - i - 1) * averageHeight; - break; - } - } - - if (info.expanding) { - ExpandAnimation ani = new ExpandAnimation(dummyView, 0, totalHeight, info); - ani.setDuration(this.parent.getAnimationDuration()); - ani.setAnimationListener(new AnimationListener() { - - @Override - public void onAnimationEnd(Animation animation) { - stopAnimation(groupPosition); - notifyDataSetChanged(); - } - - @Override - public void onAnimationRepeat(Animation animation) {} - - @Override - public void onAnimationStart(Animation animation) {} - - }); - dummyView.startAnimation(ani); - } else { - if (info.dummyHeight == -1) { - info.dummyHeight = totalHeight; - } - - ExpandAnimation ani = new ExpandAnimation(dummyView, info.dummyHeight, 0, info); - ani.setDuration(this.parent.getAnimationDuration()); - ani.setAnimationListener(new AnimationListener() { - - @Override - public void onAnimationEnd(Animation animation) { - stopAnimation(groupPosition); - listView.collapseGroup(groupPosition); - notifyDataSetChanged(); - info.dummyHeight = -1; - } - - @Override - public void onAnimationRepeat(Animation animation) {} - - @Override - public void onAnimationStart(Animation animation) {} - - }); - dummyView.startAnimation(ani); - } - - return convertView; - } else { - return getRealChildView(groupPosition, childPosition, isLastChild, convertView, parent); - } - } - - @Override - public final int getChildrenCount(int groupPosition) { - GroupInfo info = getGroupInfo(groupPosition); - if (info.animating) { - return info.firstChildPosition + 1; - } else { - return getRealChildrenCount(groupPosition); - } - } - - } - - private static class DummyView extends View { - private List views = new ArrayList(); - private Drawable divider; - private int dividerWidth; - private int dividerHeight; - - public DummyView(Context context) { - super(context); - } - - public void setDivider(Drawable divider, int dividerWidth, int dividerHeight) { - this.divider = divider; - this.dividerWidth = dividerWidth; - this.dividerHeight = dividerHeight; - - divider.setBounds(0, 0, dividerWidth, dividerHeight); - } - - /** - * Add a view for the DummyView to draw. - * @param childView View to draw - */ - public void addFakeView(View childView) { - childView.layout(0, 0, getWidth(), getHeight()); - views.add(childView); - } - - @Override - protected void onLayout(boolean changed, int left, int top, int right, int bottom) { - super.onLayout(changed, left, top, right, bottom); - final int len = views.size(); - for(int i = 0; i < len; i++) { - View v = views.get(i); - v.layout(left, top, right, bottom); - } - } - - public void clearViews() { - views.clear(); - } - - @Override - public void dispatchDraw(Canvas canvas) { - canvas.save(); - - divider.setBounds(0, 0, dividerWidth, dividerHeight); - - final int len = views.size(); - for(int i = 0; i < len; i++) { - View v = views.get(i); - v.draw(canvas); - canvas.translate(0, v.getMeasuredHeight()); - divider.draw(canvas); - canvas.translate(0, dividerHeight); - } - - canvas.restore(); - } - } - - private static class ExpandAnimation extends Animation { - private int baseHeight; - private int delta; - private View view; - private GroupInfo groupInfo; - - private ExpandAnimation(View v, int startHeight, int endHeight, GroupInfo info) { - baseHeight = startHeight; - delta = endHeight - startHeight; - view = v; - groupInfo = info; - - view.getLayoutParams().height = startHeight; - view.requestLayout(); - } - - @Override - protected void applyTransformation(float interpolatedTime, Transformation t) { - super.applyTransformation(interpolatedTime, t); - if (interpolatedTime < 1.0f) { - int val = baseHeight + (int) (delta * interpolatedTime); - view.getLayoutParams().height = val; - groupInfo.dummyHeight = val; - view.requestLayout(); - } else { - int val = baseHeight + delta; - view.getLayoutParams().height = val; - groupInfo.dummyHeight = val; - view.requestLayout(); - } - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/derek_s/hubble_gallery/ui/widgets/ScrimInsetsFrameLayout.java b/app/src/main/java/com/derek_s/hubble_gallery/ui/widgets/ScrimInsetsFrameLayout.java deleted file mode 100644 index 852fc5b..0000000 --- a/app/src/main/java/com/derek_s/hubble_gallery/ui/widgets/ScrimInsetsFrameLayout.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.derek_s.hubble_gallery.ui.widgets; - -/* -* Copyright 2014 Google Inc. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Canvas; -import android.graphics.Rect; -import android.graphics.drawable.Drawable; -import android.support.v4.view.ViewCompat; -import android.util.AttributeSet; -import android.widget.FrameLayout; - -import com.derek_s.hubble_gallery.R; - -/** - * A layout that draws something in the insets passed to - * {@link #fitSystemWindows(Rect)}, i.e. the area above UI chrome - * (status and navigation bars, overlay action bars). - */ -public class ScrimInsetsFrameLayout extends FrameLayout { - private Drawable mInsetForeground; - - private Rect mInsets; - private Rect mTempRect = new Rect(); - private OnInsetsCallback mOnInsetsCallback; - - public ScrimInsetsFrameLayout(Context context) { - super(context); - init(context, null, 0); - } - - public ScrimInsetsFrameLayout(Context context, AttributeSet attrs) { - super(context, attrs); - init(context, attrs, 0); - } - - public ScrimInsetsFrameLayout( - Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - init(context, attrs, defStyle); - } - - private void init(Context context, AttributeSet attrs, int defStyle) { - final TypedArray a = context.obtainStyledAttributes(attrs, - R.styleable.ScrimInsetsView, defStyle, 0); - if (a == null) { - return; - } - mInsetForeground = a.getDrawable( - R.styleable.ScrimInsetsView_insetForeground); - a.recycle(); - - setWillNotDraw(true); - } - - @Override - protected boolean fitSystemWindows(Rect insets) { - mInsets = new Rect(insets); - setWillNotDraw(mInsetForeground == null); - ViewCompat.postInvalidateOnAnimation(this); - if (mOnInsetsCallback != null) { - mOnInsetsCallback.onInsetsChanged(insets); - } - return true; // consume insets - } - - @Override - public void draw(Canvas canvas) { - super.draw(canvas); - - int width = getWidth(); - int height = getHeight(); - if (mInsets != null && mInsetForeground != null) { - int sc = canvas.save(); - canvas.translate(getScrollX(), getScrollY()); - - // Top - mTempRect.set(0, 0, width, mInsets.top); - mInsetForeground.setBounds(mTempRect); - mInsetForeground.draw(canvas); - - // Bottom - mTempRect.set(0, height - mInsets.bottom, width, height); - mInsetForeground.setBounds(mTempRect); - mInsetForeground.draw(canvas); - - // Left - mTempRect.set( - 0, - mInsets.top, - mInsets.left, - height - mInsets.bottom); - mInsetForeground.setBounds(mTempRect); - mInsetForeground.draw(canvas); - - // Right - mTempRect.set( - width - mInsets.right, - mInsets.top, width, - height - mInsets.bottom); - mInsetForeground.setBounds(mTempRect); - mInsetForeground.draw(canvas); - - canvas.restoreToCount(sc); - } - } - - @Override - protected void onAttachedToWindow() { - super.onAttachedToWindow(); - if (mInsetForeground != null) { - mInsetForeground.setCallback(this); - } - } - - @Override - protected void onDetachedFromWindow() { - super.onDetachedFromWindow(); - if (mInsetForeground != null) { - mInsetForeground.setCallback(null); - } - } - - /** - * Allows the calling container to specify a callback for custom - * processing when insets change (i.e. when {@link #fitSystemWindows(Rect)} - * is called. This is useful for setting padding on UI elements - * based on UI chrome insets (e.g. a Google Map or a ListView). - * When using with ListView or GridView, remember to set - * clipToPadding to false. - */ - public void setOnInsetsCallback(OnInsetsCallback onInsetsCallback) { - mOnInsetsCallback = onInsetsCallback; - } - - public static interface OnInsetsCallback { - public void onInsetsChanged(Rect insets); - } -} \ No newline at end of file From 69a9ea19447022d3cd72ae14cb8e6ef5d550b23c Mon Sep 17 00:00:00 2001 From: derekcsm Date: Mon, 2 May 2016 13:17:33 -0700 Subject: [PATCH 04/10] cleanup NetworkUtil --- .../utils/network/NetworkUtil.java | 91 +++++++++---------- 1 file changed, 42 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/com/derek_s/hubble_gallery/utils/network/NetworkUtil.java b/app/src/main/java/com/derek_s/hubble_gallery/utils/network/NetworkUtil.java index b756ce0..29eb42e 100644 --- a/app/src/main/java/com/derek_s/hubble_gallery/utils/network/NetworkUtil.java +++ b/app/src/main/java/com/derek_s/hubble_gallery/utils/network/NetworkUtil.java @@ -9,58 +9,51 @@ import javax.inject.Inject; -/** - * Created by dereksmith on 15-04-12. - */ public class NetworkUtil { - public static int TYPE_WIFI = 1; - public static int TYPE_MOBILE = 2; - public static int TYPE_NOT_CONNECTED = 0; - - private final ConnectivityManager connectivityManager; - private Context context; - - @Inject - public NetworkUtil(ConnectivityManager connectivityManager, Context context) { - this.connectivityManager = connectivityManager; - this.context = context; - } - - public int getConnectivityStatus() { - NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo(); - if (null != activeNetwork) { - if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) - return TYPE_WIFI; - - if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) - return TYPE_MOBILE; - } - return TYPE_NOT_CONNECTED; + public static int TYPE_WIFI = 1; + public static int TYPE_MOBILE = 2; + public static int TYPE_NOT_CONNECTED = 0; + + private final ConnectivityManager connectivityManager; + private Context context; + + @Inject + public NetworkUtil(ConnectivityManager connectivityManager, Context context) { + this.connectivityManager = connectivityManager; + this.context = context; + } + + public int getConnectivityStatus() { + NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo(); + if (null != activeNetwork) { + if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) + return TYPE_WIFI; + + if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) + return TYPE_MOBILE; } - - public String getConnectivityStatusString() { - int conn = getConnectivityStatus(); - String status = null; - if (conn == NetworkUtil.TYPE_WIFI) { - status = "Wifi enabled"; - } else if (conn == NetworkUtil.TYPE_MOBILE) { - status = "Mobile data enabled"; - } else if (conn == NetworkUtil.TYPE_NOT_CONNECTED) { - status = "Not connected to Internet"; - } - return status; + return TYPE_NOT_CONNECTED; + } + + public String getConnectivityStatusString() { + int conn = getConnectivityStatus(); + String status = null; + if (conn == NetworkUtil.TYPE_WIFI) { + status = "Wifi enabled"; + } else if (conn == NetworkUtil.TYPE_MOBILE) { + status = "Mobile data enabled"; + } else if (conn == NetworkUtil.TYPE_NOT_CONNECTED) { + status = "Not connected to Internet"; } + return status; + } - public void toastNoConnection() { - Toasty.show(context, R.string.no_connection, Toasty.LENGTH_MEDIUM); - } + public void toastNoConnection() { + Toasty.show(context, R.string.no_connection, Toasty.LENGTH_MEDIUM); + } - public boolean isConnected() { - int conn = getConnectivityStatus(); - if (conn == NetworkUtil.TYPE_NOT_CONNECTED) { - return false; - } else { - return true; - } - } + public boolean isConnected() { + int conn = getConnectivityStatus(); + return conn != NetworkUtil.TYPE_NOT_CONNECTED; + } } \ No newline at end of file From dee43f5a2a1c9cfd620af7ecc9de4f565ea81287 Mon Sep 17 00:00:00 2001 From: derekcsm Date: Tue, 3 May 2016 16:21:22 -0700 Subject: [PATCH 05/10] rem key wow super secure commit history :P --- app/src/main/AndroidManifest.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52115c0..543cf59 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -30,10 +30,6 @@ android:value=".act_main.ActMain"/> - - From a7e01f18f689b7289e5f59b7f68eca301c46708b Mon Sep 17 00:00:00 2001 From: derekcsm Date: Tue, 3 May 2016 16:53:40 -0700 Subject: [PATCH 06/10] update info_3 welcome text --- .../hubble_gallery/ui/fragments/FragWelcomeInfo.java | 7 +++++-- app/src/main/res/values/strings.xml | 11 ++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/derek_s/hubble_gallery/ui/fragments/FragWelcomeInfo.java b/app/src/main/java/com/derek_s/hubble_gallery/ui/fragments/FragWelcomeInfo.java index f08d969..38de299 100644 --- a/app/src/main/java/com/derek_s/hubble_gallery/ui/fragments/FragWelcomeInfo.java +++ b/app/src/main/java/com/derek_s/hubble_gallery/ui/fragments/FragWelcomeInfo.java @@ -2,6 +2,8 @@ import android.content.Intent; import android.os.Bundle; +import android.text.Html; +import android.text.method.LinkMovementMethod; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -23,7 +25,7 @@ public class FragWelcomeInfo extends FragBase { private static int pagePos = 1; - public static final FragWelcomeInfo newInstance(int position) { + public static FragWelcomeInfo newInstance(int position) { final FragWelcomeInfo fragment = new FragWelcomeInfo(); // Supply int position as an argument. Bundle args = new Bundle(); @@ -68,7 +70,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, tvInfo.setText(getActivity().getResources().getText(R.string.info_2)); break; case (3): - tvInfo.setText(getActivity().getResources().getText(R.string.info_3)); + tvInfo.setText(Html.fromHtml(getActivity().getResources().getString(R.string.info_3))); + tvInfo.setMovementMethod(LinkMovementMethod.getInstance()); break; case (4): tvInfo.setVisibility(View.INVISIBLE); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7847b38..c142f3f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -54,9 +54,14 @@ Hubble observations have led to breakthroughs in astrophysics, such as accurately determining the rate of expansion of the universe. - The content showcased in this app comes from HubbleSite, run by - the Space Telescope Science Institute\'s Office of Public Outreach. - This is not an official app, though I wish it was (if you\'re from NASA email me), I just think Hubble is awesome. + open source project. + Maintained by @drkcsm. If you\'re feeling generous, + send some grocery money to paypal.me/derekcsm + to help keep this project going! + ]]> Built by — From 93d2cda0adcd3c739a94afbe3c8332031e8ba619 Mon Sep 17 00:00:00 2001 From: derekcsm Date: Tue, 3 May 2016 16:59:08 -0700 Subject: [PATCH 07/10] update Readme add Apache License --- README.md | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index eae675c..e5ae440 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,24 @@ Contributions by: - [PedroVictorB](https://github.com/PedroVictorB) -## General code style +General code style +------- - use 2 space `indents` and 4 space `continuation indents` for Java and Kotlin, and 2 space for indents & continuation in XML, we're slowing moving to that - try your best not to exceed horizontal line length -- don't include "created by" or any other tags at top of classes, if you find any please remove them \ No newline at end of file +- don't include "created by" or any other tags at top of classes, if you find any please remove them + +License +------- + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. From 85cb49344bf09f2281d56c8981badeb50372ffb1 Mon Sep 17 00:00:00 2001 From: derekcsm Date: Tue, 3 May 2016 17:17:06 -0700 Subject: [PATCH 08/10] remove bottom padding from about dialog body / tweak bit about licensing --- .../nav_drawer/dialog/DialogAbout.kt | 17 ++++++++++++++--- app/src/main/res/values/strings.xml | 5 +++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/derek_s/hubble_gallery/nav_drawer/dialog/DialogAbout.kt b/app/src/main/kotlin/com/derek_s/hubble_gallery/nav_drawer/dialog/DialogAbout.kt index be3ba04..492a6c4 100644 --- a/app/src/main/kotlin/com/derek_s/hubble_gallery/nav_drawer/dialog/DialogAbout.kt +++ b/app/src/main/kotlin/com/derek_s/hubble_gallery/nav_drawer/dialog/DialogAbout.kt @@ -26,7 +26,7 @@ class DialogAbout(context: Context, listener: DialogAboutListener) { this.listener = listener } - fun getDialog() : MaterialDialog { + fun getDialog(): MaterialDialog { if (dialog == null) { return MaterialDialog.Builder(context) .customView(R.layout.dialog_about, false) @@ -34,7 +34,7 @@ class DialogAbout(context: Context, listener: DialogAboutListener) { .theme(Theme.DARK) .forceStacking(true) .positiveText(context.resources.getString(R.string.show_intro)) - .onPositive { materialDialog, dialogAction -> listener.onShowIntroClicked()} + .onPositive { materialDialog, dialogAction -> listener.onShowIntroClicked() } .build() } else { return dialog!! @@ -53,7 +53,18 @@ class DialogAbout(context: Context, listener: DialogAboutListener) { tvVersion!!.text = "V " + version tvBody!!.movementMethod = LinkMovementMethod.getInstance() - tvBody!!.text = Html.fromHtml(context.resources.getString(R.string.about_body)) + tvBody!!.text = removeHtmlBottomPadding(Html.fromHtml(context.resources.getString(R.string.about_body))) + } + + private fun removeHtmlBottomPadding(mText: CharSequence?): CharSequence? { + var text: CharSequence = mText ?: return null + if (text.length == 0) + return text + + while (text[text.length - 1] == '\n') { + text = text.subSequence(0, text.length - 1) + } + return text } private fun findViews(dView: View?) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c142f3f..b52b1bd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -97,8 +97,9 @@

- This is not an official app, I have no affiliation with NASA or JPL. All source code and client - content is under the MIT Open Source License. + This is not an official app, I have no affiliation with NASA or JPL. All source code for + this project is licensed under the + Apache License Version 2.0.

]]> From d6edd9613fa963779de49a598892654401c4d8ac Mon Sep 17 00:00:00 2001 From: derekcsm Date: Tue, 3 May 2016 17:17:57 -0700 Subject: [PATCH 09/10] capitalise "Gallery" for info_3 String --- app/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b52b1bd..c9142e0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -56,7 +56,7 @@ open source project. Maintained by @drkcsm. If you\'re feeling generous, send some grocery money to paypal.me/derekcsm From 5e938d7ee4d512c9c67597652df7278db5e21871 Mon Sep 17 00:00:00 2001 From: derekcsm Date: Tue, 3 May 2016 17:25:39 -0700 Subject: [PATCH 10/10] remove extra vertical padding from nav footer --- .../hubble_gallery/nav_drawer/presenters/NavigationPresenter.kt | 2 +- app/src/main/res-navigation/layout/item_footer_nav_drawer.xml | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/derek_s/hubble_gallery/nav_drawer/presenters/NavigationPresenter.kt b/app/src/main/kotlin/com/derek_s/hubble_gallery/nav_drawer/presenters/NavigationPresenter.kt index dccb24e..6d32345 100644 --- a/app/src/main/kotlin/com/derek_s/hubble_gallery/nav_drawer/presenters/NavigationPresenter.kt +++ b/app/src/main/kotlin/com/derek_s/hubble_gallery/nav_drawer/presenters/NavigationPresenter.kt @@ -138,7 +138,7 @@ class NavigationPresenter constructor(view: NavigationView, context: Context) : starItems.add(createChildObject("White Dwarf", "star/white_dwarf")) drawerItems.add(NavigationAdapterItem(SectionChildObject("Stars", "star"), - NavigationAdapterItem.GROUP, nebulaItems)) + NavigationAdapterItem.GROUP, starItems)) mAdapter = NavDrawerAdapter(context, drawerItems, this) diff --git a/app/src/main/res-navigation/layout/item_footer_nav_drawer.xml b/app/src/main/res-navigation/layout/item_footer_nav_drawer.xml index 4d10e94..5534c25 100644 --- a/app/src/main/res-navigation/layout/item_footer_nav_drawer.xml +++ b/app/src/main/res-navigation/layout/item_footer_nav_drawer.xml @@ -5,14 +5,12 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" - android:paddingBottom="@dimen/first_keyline_half" tools:ignore="rtlHardcoded">