use of com.winsonchiu.reader.data.reddit.Thing in project Reader by TheKeeperOfPie.
the class ControllerComments method expandComment.
private void expandComment(int position) {
List<Thing> commentList = link.getComments().getChildren();
int index = commentList.indexOf(listingComments.getChildren().get(position));
if (index < 0) {
return;
}
List<Comment> commentsToInsert = new LinkedList<>();
Comment comment = (Comment) commentList.get(index);
int numAdded = 0;
while (++index < commentList.size() && ((Comment) commentList.get(index)).getLevel() > comment.getLevel()) {
commentsToInsert.add((Comment) commentList.get(index));
}
for (int insertIndex = commentsToInsert.size() - 1; insertIndex >= 0; insertIndex--) {
listingComments.getChildren().add(position + 1, commentsToInsert.get(insertIndex));
numAdded++;
}
comment.setCollapsed(0);
eventHolder.call(new RxAdapterEvent<>(getData(), RxAdapterEvent.Type.CHANGE, position + 1));
eventHolder.call(new RxAdapterEvent<>(getData(), RxAdapterEvent.Type.INSERT, position + 2, numAdded));
}
use of com.winsonchiu.reader.data.reddit.Thing in project Reader by TheKeeperOfPie.
the class ControllerComments method toggleComment.
/**
* Toggles children of comment
*
* @param comment
* @return true if comment is now expanded, false if collapsed
*/
@Override
public boolean toggleComment(Comment comment) {
int position = indexOf(comment);
if (position == listingComments.getChildren().size() - 1) {
expandComment(position);
return true;
}
List<Thing> commentList = listingComments.getChildren();
comment = (Comment) commentList.get(position);
Comment nextComment = (Comment) commentList.get(position + 1);
if (comment.getLevel() >= nextComment.getLevel()) {
expandComment(position);
return true;
} else {
collapseComment(position);
return false;
}
}
use of com.winsonchiu.reader.data.reddit.Thing in project Reader by TheKeeperOfPie.
the class ControllerComments method collapseComment.
private void collapseComment(int position, boolean notify) {
List<Thing> commentList = listingComments.getChildren();
Comment comment = (Comment) commentList.get(position);
position++;
int numRemoved = 0;
while (position < commentList.size() && ((Comment) commentList.get(position)).getLevel() > comment.getLevel()) {
commentList.remove(position);
numRemoved++;
}
if (numRemoved > 0) {
comment.setCollapsed(numRemoved);
}
if (notify) {
eventHolder.call(new RxAdapterEvent<>(getData(), RxAdapterEvent.Type.CHANGE, position));
eventHolder.call(new RxAdapterEvent<>(getData(), RxAdapterEvent.Type.INSERT, position + 1, numRemoved));
}
}
use of com.winsonchiu.reader.data.reddit.Thing in project Reader by TheKeeperOfPie.
the class TableLink method queryListing.
public List<Thing> queryListing(final List<String> ids) {
// StringBuilder statement = new StringBuilder("SELECT * from " + NAME + " inner join (select " + ids.get(0) + " as " + _ID);
//
// String union = " union all select ";
//
// for (int index = 1; index < ids.size(); index++) {
// statement.append(union)
// .append(DatabaseUtils.sqlEscapeString(ids.get(index)));
// }
//
// statement.append(") as x on " + NAME + "." + _ID + " = x." + _ID);
List<String> parameters = new ArrayList<>(ids.size());
for (int index = 0; index < ids.size(); index++) {
parameters.add("?");
}
List<Thing> links = new ArrayList<>();
ObjectMapper objectMapper = ComponentStatic.getObjectMapper();
String[] idArray = new String[ids.size()];
for (int index = 0; index < idArray.length; index++) {
idArray[index] = ids.get(index);
}
Cursor query = sqLiteDatabase.query(NAME, new String[] { COLUMN_JSON, COLUMN_COMMENTS }, _ID + " IN (" + TextUtils.join(",", parameters) + ")", idArray, null, null, null);
if (query != null) {
if (query.moveToFirst()) {
do {
String json = query.getString(query.getColumnIndex(COLUMN_JSON));
String comments = query.getString(query.getColumnIndex(COLUMN_COMMENTS));
try {
Link link = Link.fromJson(objectMapper.readValue(json, JsonNode.class));
if (!TextUtils.isEmpty(comments)) {
link.setComments(Listing.fromJson(objectMapper.readValue(comments, JsonNode.class)));
}
links.add(link);
} catch (IOException e) {
e.printStackTrace();
}
} while (query.moveToNext());
}
query.close();
}
Collections.sort(links, new Comparator<Thing>() {
@Override
public int compare(Thing lhs, Thing rhs) {
int first = ids.indexOf(lhs.getId());
int second = ids.indexOf(rhs.getId());
return first < second ? -1 : (first == second ? 0 : 1);
}
});
return links;
}
use of com.winsonchiu.reader.data.reddit.Thing in project Reader by TheKeeperOfPie.
the class ControllerProfile method setReplyText.
@Override
public boolean setReplyText(String name, String text, boolean collapsed) {
if (topLink != null && name.equals(topLink.getName())) {
topLink.setReplyText(text);
topLink.setReplyExpanded(!collapsed);
for (Listener listener : listeners) {
listener.getAdapter().notifyItemChanged(2);
}
return true;
}
if (topComment != null && name.equals(topComment.getName())) {
topComment.setReplyText(text);
topComment.setReplyExpanded(!collapsed);
for (Listener listener : listeners) {
listener.getAdapter().notifyItemChanged(4);
}
return true;
}
for (int index = 0; index < data.getChildren().size(); index++) {
Thing thing = data.getChildren().get(index);
if (thing.getName().equals(name)) {
((Replyable) thing).setReplyText(text);
((Replyable) thing).setReplyExpanded(!collapsed);
for (Listener listener : listeners) {
listener.getAdapter().notifyItemChanged(index + 6);
}
return true;
}
}
return false;
}
Aggregations