Skip to content

Commit

Permalink
Migrated post list to a RecyclerView
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumBadger committed Jul 30, 2016
1 parent f058a4e commit 32795fe
Show file tree
Hide file tree
Showing 36 changed files with 903 additions and 1,264 deletions.
1 change: 1 addition & 0 deletions assets/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Ability to send and reply to private messages
Music is no longer paused when GIFs play (thanks to noughtmare and ccrama)
Fixed saving images with slashes in the path (thanks to 0xKD)
Action bar back button extended to allow clicking on text
Migrated post list to a RecyclerView, fixing lots of bugs
Made blue theme darker
Ability to change navbar colour
Removed "Beta" from the app name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import org.quantumbadger.redreader.R;
import org.quantumbadger.redreader.account.RedditAccountChangeListener;
import org.quantumbadger.redreader.account.RedditAccountManager;
Expand Down Expand Up @@ -153,7 +154,11 @@ public void onRedditAccountChanged() {
@Override
protected void doRefresh(final RefreshableFragment which, final boolean force, final Bundle savedInstanceState) {
mFragment = controller.get(this, force, savedInstanceState);
setBaseActivityContentView(mFragment.getView());

final View view = mFragment.getView();
setBaseActivityContentView(view);
General.setLayoutMatchParent(view);

setTitle(controller.getCommentListingUrl().humanReadableName(this, false));
invalidateOptionsMenu();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ protected void doRefresh(final RefreshableFragment which, final boolean force, f
force ? CacheRequest.DOWNLOAD_FORCE : CacheRequest.DOWNLOAD_IF_NECESSARY);

mPane.removeAllViews();
mPane.addView(mFragment.getView());

final View view = mFragment.getView();
mPane.addView(view);
General.setLayoutMatchParent(view);

setTitle("More Comments");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.View;
import org.quantumbadger.redreader.R;
import org.quantumbadger.redreader.account.RedditAccount;
import org.quantumbadger.redreader.account.RedditAccountChangeListener;
Expand Down Expand Up @@ -213,7 +214,10 @@ public void onRedditAccountChanged() {
protected void doRefresh(final RefreshableFragment which, final boolean force, final Bundle savedInstanceState) {
if(fragment != null) fragment.cancel();
fragment = controller.get(this, force, savedInstanceState);
setBaseActivityContentView(fragment.getView());

final View view = fragment.getView();
setBaseActivityContentView(view);
General.setLayoutMatchParent(view);
}

public void onPostSelected(final RedditPreparedPost post) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*******************************************************************************
* This file is part of RedReader.
*
* RedReader is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RedReader is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RedReader. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

package org.quantumbadger.redreader.adapters;

import android.content.Context;
import android.support.annotation.Nullable;
import org.quantumbadger.redreader.reddit.RedditCommentListItem;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

public class FilteredCommentListingManager extends RedditListingManager {

@Nullable
private final String mSearchString;

public FilteredCommentListingManager(
final Context context,
@Nullable final String searchString) {

super(context);
mSearchString = searchString;
}

public void addComments(final Collection<RedditCommentListItem> comments) {
addItems(filter(comments));
}

private Collection<GroupedRecyclerViewAdapter.Item> filter(Collection<RedditCommentListItem> comments) {

final Collection<RedditCommentListItem> searchComments;

if (mSearchString == null) {
searchComments = comments;

} else {
searchComments = new ArrayList<>();
for (RedditCommentListItem comment : comments) {
if (!comment.isComment()) continue;
String commentStr = comment.asComment().getParsedComment().getRawComment().body;
if (commentStr != null) {
commentStr = commentStr.toLowerCase();
if (commentStr.contains(mSearchString)) {
searchComments.add(comment);
}
}
}
}

return Collections.<GroupedRecyclerViewAdapter.Item>unmodifiableCollection(searchComments);
}

public boolean isSearchListing() {
return mSearchString != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,16 @@ private Item getItemInternal(final int desiredPosition) {

@Override
public RecyclerView.ViewHolder onCreateViewHolder(final ViewGroup viewGroup, final int viewType) {
return mViewTypeItemMap.get(viewType).onCreateViewHolder(viewGroup);

final RecyclerView.ViewHolder viewHolder = mViewTypeItemMap.get(viewType).onCreateViewHolder(viewGroup);

final RecyclerView.LayoutParams layoutParams = new RecyclerView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);

viewHolder.itemView.setLayoutParams(layoutParams);

return viewHolder;
}

@Override
Expand Down Expand Up @@ -203,6 +212,23 @@ public void appendToGroup(final int group, final Collection<Item> items) {
notifyItemRangeInserted(position, items.size());
}

public void removeAllFromGroup(final int groupId) {

final ArrayList<Item> group = mItems[groupId];

for(int i = group.size() - 1; i >= 0; i--) {

final Item item = group.get(i);
final int position = getItemPositionInternal(groupId, i);

group.remove(i);

if(!item.mCurrentlyHidden) {
notifyItemRemoved(position);
}
}
}

public void removeFromGroup(final int groupId, final Item item) {

final ArrayList<Item> group = mItems[groupId];
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@
* along with RedReader. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

package org.quantumbadger.redreader.views.list;
package org.quantumbadger.redreader.adapters;

public interface RRTouchable {
void rrOnClick(int x, int y);
import android.content.Context;
import org.quantumbadger.redreader.reddit.RedditPostListItem;

void rrOnLongClick();
import java.util.Collection;
import java.util.Collections;

void rrOnFingerDown();
public class PostListingManager extends RedditListingManager {

void rrOnSwipeDelta(float dx);
public PostListingManager(final Context context) {
super(context);
}

void rrOnFingerUp();

void rrOnHighlightStart(int x, int y);

void rrOnHighlightEnd();

boolean rrAllowLongClick();
public void addPosts(final Collection<RedditPostListItem> posts) {
addItems(Collections.<GroupedRecyclerViewAdapter.Item>unmodifiableCollection(posts));
}
}

0 comments on commit 32795fe

Please sign in to comment.