diff --git a/app/app-release.apk b/app/app-release.apk index 5276f3b..213996f 100644 Binary files a/app/app-release.apk and b/app/app-release.apk differ diff --git a/app/build.gradle b/app/build.gradle index 9c638ce..f4d0dd4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,7 +10,6 @@ buildscript { } } apply plugin: 'com.android.application' -apply plugin: 'com.zeroturnaround.jrebel.android' apply plugin: 'io.fabric' repositories { @@ -25,8 +24,8 @@ android { applicationId "com.winsonchiu.reader" minSdkVersion 17 targetSdkVersion 22 - versionCode 43 - versionName "1.1.1" + versionCode 47 + versionName "1.1.2" } buildTypes { release { @@ -54,5 +53,5 @@ dependencies { compile 'com.android.support:design:22.2.1' compile 'com.android.support:palette-v7:22.2.1' compile 'com.squareup.picasso:picasso:2.5.2' - compile 'com.github.rjeschke:txtmark:0.13+' + compile 'com.github.rjeschke:txtmark:0.13' } diff --git a/app/src/main/java/com/winsonchiu/reader/FragmentAuth.java b/app/src/main/java/com/winsonchiu/reader/FragmentAuth.java index 2b03196..7e8ed24 100644 --- a/app/src/main/java/com/winsonchiu/reader/FragmentAuth.java +++ b/app/src/main/java/com/winsonchiu/reader/FragmentAuth.java @@ -249,11 +249,13 @@ public void onDestroy() { } public boolean navigateBack() { - if (webAuth.canGoBack()) { - webAuth.goBack(); - return false; + if (webAuth != null) { + if (webAuth.canGoBack()) { + webAuth.goBack(); + return false; + } + destroy(false); } - destroy(false); return true; } diff --git a/app/src/main/java/com/winsonchiu/reader/MainActivity.java b/app/src/main/java/com/winsonchiu/reader/MainActivity.java index 75d86f4..9498ed2 100644 --- a/app/src/main/java/com/winsonchiu/reader/MainActivity.java +++ b/app/src/main/java/com/winsonchiu/reader/MainActivity.java @@ -202,15 +202,6 @@ public void onDrawerStateChanged(int newState) { } } - if (getFragmentManager().findFragmentByTag(FragmentComments.TAG) != null) { - - hideFragment(FragmentThreadList.TAG); - hideFragment(FragmentProfile.TAG); - hideFragment(FragmentInbox.TAG); - hideFragment(FragmentSearch.TAG); - - } - eventListenerBase = new AdapterLink.ViewHolderBase.EventListener() { @Override @@ -572,16 +563,6 @@ public void loadNestedComments(Comment comment) { } } - @Override - public boolean isCommentExpanded(int position) { - return getControllerComments().isCommentExpanded(position); - } - - @Override - public boolean hasChildren(Comment comment) { - return getControllerComments().hasChildren(comment); - } - @Override public void voteComment(AdapterCommentList.ViewHolderComment viewHolderComment, Comment comment, @@ -638,13 +619,6 @@ public void jumpToParent(Comment comment) { } - private void hideFragment(String tag) { - Fragment fragment = getFragmentManager().findFragmentByTag(tag); - if (fragment != null) { - getFragmentManager().beginTransaction().hide(fragment).commit(); - } - } - private void inflateNavigationDrawer() { viewNavigation = (NavigationView) findViewById(R.id.navigation); @@ -1059,6 +1033,7 @@ public void onAuthFinished(boolean success) { loadAccountInfo(); getControllerUser().reloadUser(); getControllerSearch().reloadSubscriptionList(); + onNavigationBackClick(); } else { Toast.makeText(this, getString(R.string.login_failure), Toast.LENGTH_SHORT) diff --git a/app/src/main/java/com/winsonchiu/reader/comments/AdapterCommentList.java b/app/src/main/java/com/winsonchiu/reader/comments/AdapterCommentList.java index 16cda3d..64ab21b 100644 --- a/app/src/main/java/com/winsonchiu/reader/comments/AdapterCommentList.java +++ b/app/src/main/java/com/winsonchiu/reader/comments/AdapterCommentList.java @@ -300,6 +300,14 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { } + @Override + public void onViewRecycled(RecyclerView.ViewHolder holder) { + super.onViewRecycled(holder); + if (getItemViewType(holder.getAdapterPosition()) == VIEW_LINK) { + ((AdapterLink.ViewHolderBase) holder).onRecycle(); + } + } + @Override public int getItemCount() { int count = controllerComments.getItemCount(); @@ -485,6 +493,11 @@ public void onClick(View v) { final GestureDetectorCompat gestureDetectorCompat = new GestureDetectorCompat(itemView.getContext(), new GestureDetector.SimpleOnGestureListener() { + @Override + public void onLongPress(MotionEvent e) { + eventListener.toggleComment(getAdapterPosition()); + } + @Override public boolean onDoubleTap(MotionEvent e) { if (!TextUtils.isEmpty(userName)) { @@ -1009,8 +1022,6 @@ public void setVisibility(int visibility) { public interface EventListener { void loadNestedComments(Comment comment); - boolean isCommentExpanded(int position); - boolean hasChildren(Comment comment); void voteComment(ViewHolderComment viewHolderComment, Comment comment, int vote); boolean toggleComment(int position); void deleteComment(Comment comment); diff --git a/app/src/main/java/com/winsonchiu/reader/inbox/ControllerInbox.java b/app/src/main/java/com/winsonchiu/reader/inbox/ControllerInbox.java index d9db702..3a0683d 100644 --- a/app/src/main/java/com/winsonchiu/reader/inbox/ControllerInbox.java +++ b/app/src/main/java/com/winsonchiu/reader/inbox/ControllerInbox.java @@ -232,12 +232,16 @@ public void insertMessage(Message message) { public void insertComment(Comment comment) { + // Placeholder to use ArrayList.indexOf() properly Comment parentComment = new Comment(); parentComment.setId(comment.getParentId()); int commentIndex = data.getChildren().indexOf(parentComment); if (commentIndex > -1) { - comment.setLevel(((Comment) data.getChildren().get(commentIndex)).getLevel() + 1); + // Level and context are set as they are not provided by the send API + parentComment = (Comment) data.getChildren().get(commentIndex); + comment.setLevel(parentComment.getLevel() + 1); + comment.setContext(parentComment.getContext()); data.getChildren() .add(commentIndex + 1, comment); @@ -387,7 +391,8 @@ public void markAllRead() { new Response.Listener() { @Override public void onResponse(String response) { - + Log.d(TAG, "markAllRead response: " + response); + Toast.makeText(activity, R.string.marked_read, Toast.LENGTH_LONG).show(); } }, new Response.ErrorListener() { @Override diff --git a/app/src/main/java/com/winsonchiu/reader/inbox/FragmentInbox.java b/app/src/main/java/com/winsonchiu/reader/inbox/FragmentInbox.java index afcc83e..145574d 100644 --- a/app/src/main/java/com/winsonchiu/reader/inbox/FragmentInbox.java +++ b/app/src/main/java/com/winsonchiu/reader/inbox/FragmentInbox.java @@ -61,7 +61,6 @@ public class FragmentInbox extends FragmentBase implements Toolbar.OnMenuItemCli private ScrollAwareFloatingActionButtonBehavior behaviorFloatingActionButton; private PorterDuffColorFilter colorFilterIcon; private Menu menu; - private MenuItem itemMarkAllRead; public static FragmentInbox newInstance() { FragmentInbox fragment = new FragmentInbox(); @@ -96,7 +95,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, @Override public void setPage(Page page) { spinnerPage.setSelection(adapterInboxPage.getPages().indexOf(page)); - itemMarkAllRead.setVisible(ControllerInbox.UNREAD.equals(page.getPage())); } @Override @@ -211,16 +209,6 @@ public void loadNestedComments(Comment comment) { mListener.getControllerInbox().loadNestedComments(comment); } - @Override - public boolean isCommentExpanded(int position) { - return mListener.getControllerInbox().isCommentExpanded(position); - } - - @Override - public boolean hasChildren(Comment comment) { - return mListener.getControllerInbox().hasChildren(comment); - } - @Override public void voteComment(AdapterCommentList.ViewHolderComment viewHolderComment, Comment comment, @@ -322,7 +310,6 @@ private void setUpOptionsMenu() { toolbar.inflateMenu(R.menu.menu_inbox); toolbar.setOnMenuItemClickListener(this); menu = toolbar.getMenu(); - itemMarkAllRead = menu.findItem(R.id.item_mark_all_read); for (int index = 0; index < menu.size(); index++) { menu.getItem(index).getIcon().setColorFilter(colorFilterIcon); diff --git a/app/src/main/java/com/winsonchiu/reader/links/AdapterLink.java b/app/src/main/java/com/winsonchiu/reader/links/AdapterLink.java index b1ecf9f..b99714a 100644 --- a/app/src/main/java/com/winsonchiu/reader/links/AdapterLink.java +++ b/app/src/main/java/com/winsonchiu/reader/links/AdapterLink.java @@ -711,7 +711,6 @@ public void onClick(View v) { break; case R.id.image_thumbnail: onClickThumbnail(); - recyclerCallback.hideToolbar(); break; case R.id.button_send_reply: if (!TextUtils.isEmpty(editTextReply.getText())) { @@ -904,6 +903,7 @@ public void run() { public abstract float getRatio(); public void loadFull() { + recyclerCallback.hideToolbar(); addToHistory(); viewOverlay.setVisibility(View.GONE); @@ -919,7 +919,6 @@ public void loadFull() { } public void onClickThumbnail() { - viewOverlay.setVisibility(View.GONE); if (!loadSelfText()) { loadFull(); diff --git a/app/src/main/java/com/winsonchiu/reader/links/AdapterLinkGrid.java b/app/src/main/java/com/winsonchiu/reader/links/AdapterLinkGrid.java index ca0633a..9ec99ef 100644 --- a/app/src/main/java/com/winsonchiu/reader/links/AdapterLinkGrid.java +++ b/app/src/main/java/com/winsonchiu/reader/links/AdapterLinkGrid.java @@ -4,6 +4,7 @@ package com.winsonchiu.reader.links; +import android.animation.Animator; import android.app.Activity; import android.content.res.Resources; import android.graphics.ColorFilter; @@ -174,6 +175,7 @@ public void onBind(Link link, boolean showSubbreddit, String userName) { int position = getAdapterPosition(); + link.setBackgroundColor(colorBackgroundDefault); itemView.setBackgroundColor(colorBackgroundDefault); buttonComments.setColorFilter(colorFilterIconDefault); imagePlay.setColorFilter(colorFilterIconDefault); @@ -202,7 +204,7 @@ else if (Reddit.showThumbnail(link)) { loadThumbnail(link, position); return; } - else if (!TextUtils.isEmpty(link.getThumbnail())) { + else if (!TextUtils.isEmpty(link.getThumbnail()) && !Reddit.NSFW.equals(link.getThumbnail())) { imageFull.setVisibility(View.GONE); imageThumbnail.clearColorFilter(); imageThumbnail.setVisibility(View.VISIBLE); @@ -373,6 +375,11 @@ public void onError() { } public void loadBackgroundColor() { + if (link.getBackgroundColor() != colorBackgroundDefault) { + setBackgroundColor(link.getBackgroundColor()); + return; + } + Drawable drawable = imageFull.getDrawable(); if (drawable instanceof BitmapDrawable) { final int position = getAdapterPosition(); @@ -395,10 +402,32 @@ public void onGenerated(Palette palette) { public void setBackgroundColor(int color) { + link.setBackgroundColor(color); + AnimationUtils.animateBackgroundColor( itemView, ((ColorDrawable) itemView.getBackground()) - .getColor(), color); + .getColor(), color, new Animator.AnimatorListener() { + @Override + public void onAnimationStart(Animator animation) { + + } + + @Override + public void onAnimationEnd(Animator animation) { + itemView.setBackgroundColor(link.getBackgroundColor()); + } + + @Override + public void onAnimationCancel(Animator animation) { + + } + + @Override + public void onAnimationRepeat(Animator animation) { + + } + }); setTextColors(color); diff --git a/app/src/main/java/com/winsonchiu/reader/links/ControllerLinks.java b/app/src/main/java/com/winsonchiu/reader/links/ControllerLinks.java index 3fff1c9..4e40f3d 100644 --- a/app/src/main/java/com/winsonchiu/reader/links/ControllerLinks.java +++ b/app/src/main/java/com/winsonchiu/reader/links/ControllerLinks.java @@ -467,6 +467,11 @@ public void clearViewed(Historian historian) { } + public boolean isOnSpecificSubreddit() { + return !TextUtils.isEmpty(subreddit.getDisplayName()) && !"/r/all/".equalsIgnoreCase( + subreddit.getUrl()) && !subreddit.getUrl().contains("+"); + } + public interface Listener extends ControllerListener { void setSortAndTime(Sort sort, Time time); void showEmptyView(boolean isEmpty); diff --git a/app/src/main/java/com/winsonchiu/reader/profile/ControllerProfile.java b/app/src/main/java/com/winsonchiu/reader/profile/ControllerProfile.java index 172d53f..210d7b6 100644 --- a/app/src/main/java/com/winsonchiu/reader/profile/ControllerProfile.java +++ b/app/src/main/java/com/winsonchiu/reader/profile/ControllerProfile.java @@ -429,13 +429,17 @@ public Link remove(int position) { public void insertComment(Comment comment) { + // Placeholder to use ArrayList.indexOf() properly Comment parentComment = new Comment(); parentComment.setId(comment.getParentId()); + int commentIndex = data.getChildren() .indexOf(parentComment); - if (commentIndex > -1) { - comment.setLevel(((Comment) data.getChildren().get(commentIndex)).getLevel() + 1); + // Level and context are set as they are not provided by the send API + parentComment = (Comment) data.getChildren().get(commentIndex); + comment.setLevel(parentComment.getLevel() + 1); + comment.setContext(parentComment.getContext()); data.getChildren() .add(commentIndex + 1, comment); diff --git a/app/src/main/java/com/winsonchiu/reader/profile/FragmentProfile.java b/app/src/main/java/com/winsonchiu/reader/profile/FragmentProfile.java index 6a747e9..f34fe56 100644 --- a/app/src/main/java/com/winsonchiu/reader/profile/FragmentProfile.java +++ b/app/src/main/java/com/winsonchiu/reader/profile/FragmentProfile.java @@ -297,16 +297,6 @@ public void loadNestedComments(Comment comment) { mListener.getControllerProfile().loadNestedComments(comment); } - @Override - public boolean isCommentExpanded(int position) { - return mListener.getControllerProfile().isCommentExpanded(position); - } - - @Override - public boolean hasChildren(Comment comment) { - return mListener.getControllerProfile().hasChildren(comment); - } - @Override public void voteComment(AdapterCommentList.ViewHolderComment viewHolderComment, Comment comment, diff --git a/app/src/main/java/com/winsonchiu/reader/search/AdapterSearchSubreddits.java b/app/src/main/java/com/winsonchiu/reader/search/AdapterSearchSubreddits.java index 1671c86..dd15a0b 100644 --- a/app/src/main/java/com/winsonchiu/reader/search/AdapterSearchSubreddits.java +++ b/app/src/main/java/com/winsonchiu/reader/search/AdapterSearchSubreddits.java @@ -32,13 +32,13 @@ public class AdapterSearchSubreddits extends RecyclerView.Adapter requestsSubredditsRecommended; + private String currentSubreddit; + public ControllerSearch(Activity activity) { setActivity(activity); sort = Sort.RELEVANCE; @@ -80,8 +86,10 @@ public ControllerSearch(Activity activity) { query = ""; subredditsSubscribed = new Listing(); subreddits = new Listing(); + subredditsRecommended = new Listing(); links = new Listing(); linksSubreddit = new Listing(); + requestsSubredditsRecommended = new ArrayList<>(); } public void setActivity(Activity activity) { @@ -96,7 +104,6 @@ public void addListener(Listener listener) { setTitle(); listener.getAdapterSearchSubreddits().notifyDataSetChanged(); listener.setSort(sort); - reloadCurrentPage(); } public void removeListener(Listener listener) { @@ -244,7 +251,8 @@ public void onResponse(String response) { Collections.sort(subredditsSubscribed.getChildren(), new Comparator() { @Override public int compare(Thing lhs, Thing rhs) { - return ((Subreddit) lhs).getDisplayName().compareToIgnoreCase(((Subreddit) rhs).getDisplayName()); + return ((Subreddit) lhs).getDisplayName().compareToIgnoreCase( + ((Subreddit) rhs).getDisplayName()); } }); if (TextUtils.isEmpty(query)) { @@ -280,12 +288,15 @@ public void onResponse(String response) { try { Listing listing = Listing.fromJson(new JSONObject(response)); subredditsSubscribed.addChildren(listing.getChildren()); - Collections.sort(subredditsSubscribed.getChildren(), new Comparator() { - @Override - public int compare(Thing lhs, Thing rhs) { - return ((Subreddit) lhs).getDisplayName().compareToIgnoreCase(((Subreddit) rhs).getDisplayName()); - } - }); + Collections.sort(subredditsSubscribed.getChildren(), + new Comparator() { + @Override + public int compare(Thing lhs, Thing rhs) { + return ((Subreddit) lhs).getDisplayName() + .compareToIgnoreCase( + ((Subreddit) rhs).getDisplayName()); + } + }); if (TextUtils.isEmpty(query)) { subreddits = subredditsSubscribed; for (Listener listener : listeners) { @@ -328,10 +339,19 @@ public void reloadCurrentPage() { } break; case PAGE_LINKS: - reloadLinks(); + if (!TextUtils.isEmpty(query)) { + reloadLinks(); + } break; case PAGE_LINKS_SUBREDDIT: - reloadLinksSubreddit(); + if (!TextUtils.isEmpty(query)) { + reloadLinksSubreddit(); + } + break; + case PAGE_SUBREDDITS_RECOMMENDED: + if (!controllerLinks.getSubreddit().getDisplayName().equals(currentSubreddit)) { + reloadSubredditsRecommended(); + } break; } } @@ -399,6 +419,7 @@ public void run() { catch (JSONException e) { e.printStackTrace(); } + } }).start(); @@ -416,6 +437,102 @@ public void onErrorResponse(VolleyError error) { } + public void reloadSubredditsRecommended() { + Log.d(TAG, "reloadSubredditsRecommended"); + + for (Request request : requestsSubredditsRecommended) { + request.cancel(); + } + requestsSubredditsRecommended.clear(); + + subredditsRecommended.getChildren().clear(); + for (Listener listener : listeners) { + listener.getAdapterSearchSubredditsRecommended().notifyDataSetChanged(); + } + + StringBuilder builderOmit = new StringBuilder(); + for (Thing thing : subredditsSubscribed.getChildren()) { + Subreddit subreddit = (Subreddit) thing; + builderOmit.append(subreddit.getDisplayName()); + builderOmit.append(","); + } + + currentSubreddit = controllerLinks.getSubreddit().getDisplayName(); + + reddit.loadGet(Reddit.OAUTH_URL + "/api/recommend/sr/" + currentSubreddit + "?omit=" + builderOmit, new Response.Listener() { + @Override + public void onResponse(String response) { + + try { + final JSONArray jsonArray = new JSONArray(response); + + for (int index = 0; index < jsonArray.length(); index++) { + + /* + No idea why the API returns a {"sr_name": "subreddit"} rather than an + array of Strings, but we'll convert it. + */ + JSONObject dataSubreddit = jsonArray.getJSONObject(index); + String name = dataSubreddit.optString("sr_name"); + + requestsSubredditsRecommended.add(reddit.loadGet( + Reddit.OAUTH_URL + "/r/" + name + "/about", + new Response.Listener() { + @Override + public void onResponse(String response) { + try { + Subreddit subreddit = Subreddit + .fromJson(new JSONObject(response)); + subredditsRecommended.getChildren().add(subreddit); + + if (subredditsRecommended.getChildren() + .size() == jsonArray.length()) { + Collections + .sort(subredditsRecommended.getChildren(), + new Comparator() { + @Override + public int compare(Thing lhs, + Thing rhs) { + return ((Subreddit) lhs) + .getDisplayName() + .compareToIgnoreCase( + ((Subreddit) rhs) + .getDisplayName()); + } + }); + + for (Listener listener : listeners) { + listener.getAdapterSearchSubredditsRecommended() + .notifyDataSetChanged(); + } + + } + } + catch (JSONException e) { + e.printStackTrace(); + } + } + }, new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + + } + }, 0)); + } + } + catch (JSONException e) { + e.printStackTrace(); + } + + } + }, new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + + } + }, 0); + } + public void reloadLinks() { setLoadingLinks(true); @@ -514,11 +631,21 @@ public Subreddit getSubreddit(int position) { .get(position); } - public int getSubredditCount() { + public int getCountSubreddit() { return subreddits.getChildren() .size(); } + public Subreddit getSubredditRecommended(int position) { + return (Subreddit) subredditsRecommended.getChildren() + .get(position); + } + + public int getCountSubredditRecommended() { + return subredditsRecommended.getChildren() + .size(); + } + public Link getLink(int position) { return (Link) links.getChildren().get(position - 1); } @@ -765,6 +892,7 @@ public boolean setReplyTextLinksSubreddit(String name, String text, boolean coll public interface Listener extends ControllerListener { AdapterSearchSubreddits getAdapterSearchSubreddits(); + AdapterSearchSubreddits getAdapterSearchSubredditsRecommended(); AdapterLink getAdapterLinks(); AdapterLink getAdapterLinksSubreddit(); void setToolbarTitle(CharSequence title); diff --git a/app/src/main/java/com/winsonchiu/reader/search/ControllerSearchBase.java b/app/src/main/java/com/winsonchiu/reader/search/ControllerSearchBase.java new file mode 100644 index 0000000..2088fc0 --- /dev/null +++ b/app/src/main/java/com/winsonchiu/reader/search/ControllerSearchBase.java @@ -0,0 +1,16 @@ +/* + * Copyright 2015 Winson Chiu + */ + +package com.winsonchiu.reader.search; + +import com.winsonchiu.reader.data.reddit.Subreddit; + +/** + * Created by TheKeeperOfPie on 7/28/2015. + */ +public interface ControllerSearchBase { + + Subreddit getSubreddit(int position); + int getSubredditCount(); +} diff --git a/app/src/main/java/com/winsonchiu/reader/search/FragmentSearch.java b/app/src/main/java/com/winsonchiu/reader/search/FragmentSearch.java index cce087a..15794bb 100644 --- a/app/src/main/java/com/winsonchiu/reader/search/FragmentSearch.java +++ b/app/src/main/java/com/winsonchiu/reader/search/FragmentSearch.java @@ -43,7 +43,6 @@ public class FragmentSearch extends FragmentBase implements Toolbar.OnMenuItemClickListener { - private static final int PAGE_COUNT = 3; public static final String TAG = FragmentSearch.class.getCanonicalName(); private static final String ARG_HIDE_KEYBOARD = "hideKeyboard"; @@ -55,12 +54,15 @@ public class FragmentSearch extends FragmentBase implements Toolbar.OnMenuItemCl private RecyclerView recyclerSearchSubreddits; private RecyclerView recyclerSearchLinks; private RecyclerView recyclerSearchLinksSubreddit; + private RecyclerView recyclerSearchSubredditsRecommended; private LinearLayoutManager layoutManagerSubreddits; private LinearLayoutManager layoutManagerLinks; private LinearLayoutManager layoutManagerLinksSubreddit; + private LinearLayoutManager layoutManagerSubredditsRecommended; private AdapterSearchSubreddits adapterSearchSubreddits; private AdapterLink adapterLinks; private AdapterLink adapterLinksSubreddit; + private AdapterSearchSubreddits adapterSearchSubredditsRecommended; private ControllerSearch.Listener listenerSearch; private PagerAdapter pagerAdapter; private Menu menu; @@ -167,7 +169,7 @@ public void onDestroyOptionsMenu() { */ private void flashSearchView() { // Removed as this clears the search query - // TODO: Find f + // TODO: Find fix // if (itemSearch != null) { // itemSearch.expandActionView(); // itemSearch.collapseActionView(); @@ -186,6 +188,11 @@ public AdapterSearchSubreddits getAdapterSearchSubreddits() { return adapterSearchSubreddits; } + @Override + public AdapterSearchSubreddits getAdapterSearchSubredditsRecommended() { + return adapterSearchSubredditsRecommended; + } + @Override public AdapterLink getAdapterLinks() { return adapterLinks; @@ -222,6 +229,20 @@ public void setSort(Sort sort) { } }; + DisallowListener disallowListener = new DisallowListener() { + @Override + public void requestDisallowInterceptTouchEventVertical(boolean disallow) { + recyclerSearchLinks.requestDisallowInterceptTouchEvent(disallow); + recyclerSearchLinksSubreddit.requestDisallowInterceptTouchEvent(disallow); + viewPager.requestDisallowInterceptTouchEvent(disallow); + } + + @Override + public void requestDisallowInterceptTouchEventHorizontal(boolean disallow) { + + } + }; + TypedArray typedArray = activity.getTheme().obtainStyledAttributes( new int[]{R.attr.colorIconFilter}); int colorIconFilter = typedArray.getColor(0, 0xFFFFFFFF); @@ -245,7 +266,17 @@ public void onClick(View v) { layoutAppBar = (AppBarLayout) view.findViewById(R.id.layout_app_bar); adapterSearchSubreddits = new AdapterSearchSubreddits(activity, - mListener.getControllerSearch(), + new ControllerSearchBase() { + @Override + public Subreddit getSubreddit(int position) { + return mListener.getControllerSearch().getSubreddit(position); + } + + @Override + public int getSubredditCount() { + return mListener.getControllerSearch().getCountSubreddit(); + } + }, new AdapterSearchSubreddits.ViewHolder.EventListener() { @Override public void onClickSubreddit(Subreddit subreddit) { @@ -265,20 +296,6 @@ public void onClickSubreddit(Subreddit subreddit) { recyclerSearchSubreddits.setLayoutManager(layoutManagerSubreddits); recyclerSearchSubreddits.setAdapter(adapterSearchSubreddits); - DisallowListener disallowListener = new DisallowListener() { - @Override - public void requestDisallowInterceptTouchEventVertical(boolean disallow) { - recyclerSearchLinks.requestDisallowInterceptTouchEvent(disallow); - recyclerSearchLinksSubreddit.requestDisallowInterceptTouchEvent(disallow); - viewPager.requestDisallowInterceptTouchEvent(disallow); - } - - @Override - public void requestDisallowInterceptTouchEventHorizontal(boolean disallow) { - - } - }; - adapterLinks = new AdapterSearchLinkList(activity, new ControllerLinksBase() { @Override public Link getLink(int position) { @@ -350,7 +367,8 @@ public RecyclerView.LayoutManager getLayoutManager() { @Override public void hideToolbar() { AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior(); - behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true); + behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, + true); } }); @@ -442,6 +460,37 @@ public void hideToolbar() { recyclerSearchLinksSubreddit.setLayoutManager(layoutManagerLinksSubreddit); recyclerSearchLinksSubreddit.setAdapter(adapterLinksSubreddit); + adapterSearchSubredditsRecommended = new AdapterSearchSubreddits(activity, + new ControllerSearchBase() { + @Override + public Subreddit getSubreddit(int position) { + return mListener.getControllerSearch().getSubredditRecommended(position); + } + + @Override + public int getSubredditCount() { + return mListener.getControllerSearch().getCountSubredditRecommended(); + } + }, + new AdapterSearchSubreddits.ViewHolder.EventListener() { + @Override + public void onClickSubreddit(Subreddit subreddit) { + mListener.getControllerLinks() + .setParameters(subreddit.getDisplayName(), Sort.HOT, Time.ALL); + InputMethodManager inputManager = (InputMethodManager) activity + .getSystemService(Context.INPUT_METHOD_SERVICE); + inputManager.hideSoftInputFromWindow(view.getWindowToken(), + InputMethodManager.HIDE_NOT_ALWAYS); + getFragmentManager().popBackStack(); + } + }); + + layoutManagerSubredditsRecommended = new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false); + recyclerSearchSubredditsRecommended = (RecyclerView) view.findViewById( + R.id.recycler_search_subreddits_recommended); + recyclerSearchSubredditsRecommended.setLayoutManager(layoutManagerSubredditsRecommended); + recyclerSearchSubredditsRecommended.setAdapter(adapterSearchSubredditsRecommended); + pagerAdapter = new PagerAdapter() { @Override public Object instantiateItem(ViewGroup container, int position) { @@ -463,6 +512,8 @@ public CharSequence getPageTitle(int position) { case ControllerSearch.PAGE_LINKS_SUBREDDIT: return mListener.getControllerLinks() .getSubredditName(); + case ControllerSearch.PAGE_SUBREDDITS_RECOMMENDED: + return getString(R.string.recommended); } return super.getPageTitle(position); @@ -470,7 +521,7 @@ public CharSequence getPageTitle(int position) { @Override public int getCount() { - return PAGE_COUNT; + return mListener.getControllerLinks().isOnSpecificSubreddit() ? viewPager.getChildCount() : viewPager.getChildCount() - 1; } @Override diff --git a/app/src/main/java/com/winsonchiu/reader/utils/AnimationUtils.java b/app/src/main/java/com/winsonchiu/reader/utils/AnimationUtils.java index 095bb7d..b49eab6 100644 --- a/app/src/main/java/com/winsonchiu/reader/utils/AnimationUtils.java +++ b/app/src/main/java/com/winsonchiu/reader/utils/AnimationUtils.java @@ -4,6 +4,7 @@ package com.winsonchiu.reader.utils; +import android.animation.Animator; import android.animation.ValueAnimator; import android.content.Context; import android.graphics.Point; @@ -30,11 +31,10 @@ public class AnimationUtils { public static final long BACKGROUND_DURATION = 500; private static final String TAG = AnimationUtils.class.getCanonicalName(); - public static void animateBackgroundColor(final View view, final int start, final int end) { + public static void animateBackgroundColor(final View view, final int start, final int end, Animator.AnimatorListener listener) { ValueAnimator valueAnimator = ValueAnimator.ofInt(0, 255); valueAnimator.setDuration(BACKGROUND_DURATION); - valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { @@ -47,6 +47,7 @@ public void onAnimationUpdate(ValueAnimator animation) { } }); + valueAnimator.addListener(listener); valueAnimator.start(); } diff --git a/app/src/main/res/layout/fragment_search.xml b/app/src/main/res/layout/fragment_search.xml index 1ea4247..9b67379 100644 --- a/app/src/main/res/layout/fragment_search.xml +++ b/app/src/main/res/layout/fragment_search.xml @@ -66,6 +66,17 @@ android:clipToPadding="false" /> + + diff --git a/app/src/main/res/menu/menu_inbox.xml b/app/src/main/res/menu/menu_inbox.xml index e9a520b..8351832 100644 --- a/app/src/main/res/menu/menu_inbox.xml +++ b/app/src/main/res/menu/menu_inbox.xml @@ -13,7 +13,6 @@ android:title="@string/item_mark_all_read" android:icon="@drawable/ic_check_white_24dp" android:orderInCategory="100" - android:visible="false" app:showAsAction="ifRoom" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e730b05..83147f2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -226,4 +226,6 @@ Mark all messages as read Send message Submit post + All marked as read, may take time to update + Recommended