use of com.winsonchiu.reader.data.reddit.Link in project Reader by TheKeeperOfPie.
the class ControllerSearch method setNsfwLinksSubreddit.
public void setNsfwLinksSubreddit(String name, boolean over18) {
for (int index = 0; index < linksSubreddit.getChildren().size(); index++) {
Thing thing = linksSubreddit.getChildren().get(index);
if (thing.getName().equals(name)) {
((Link) thing).setOver18(over18);
eventHolder.callLinksSubreddit(new RxAdapterEvent<>(getLinksSubredditModel(), RxAdapterEvent.Type.CHANGE, index + 1));
return;
}
}
}
use of com.winsonchiu.reader.data.reddit.Link in project Reader by TheKeeperOfPie.
the class TableLink method query.
public Thing query(String id) {
Link link = null;
ObjectMapper objectMapper = ComponentStatic.getObjectMapper();
Cursor query = sqLiteDatabase.query(NAME, new String[] { COLUMN_JSON, COLUMN_COMMENTS }, _ID + " IN (?) LIMIT 1", new String[] { id }, null, null, null);
if (query != null) {
if (query.moveToFirst()) {
String json = query.getString(query.getColumnIndex(COLUMN_JSON));
String comments = query.getString(query.getColumnIndex(COLUMN_COMMENTS));
try {
link = Link.fromJson(objectMapper.readValue(json, JsonNode.class));
if (!TextUtils.isEmpty(comments)) {
link.setComments(Listing.fromJson(objectMapper.readValue(comments, JsonNode.class)));
}
} catch (IOException e) {
e.printStackTrace();
}
}
query.close();
}
return link;
}
use of com.winsonchiu.reader.data.reddit.Link in project Reader by TheKeeperOfPie.
the class TableLink method storeLinks.
public Action1<SQLiteDatabase> storeLinks(final List<Link> links) {
return new Action1<SQLiteDatabase>() {
@Override
public void call(SQLiteDatabase sqLiteDatabase) {
List<Link> linksWithComments = new ArrayList<>();
for (int index = links.size() - 1; index >= 0; index--) {
if (!links.get(index).getComments().getChildren().isEmpty()) {
linksWithComments.add(links.remove(index));
}
}
TransactionInsertOrReplace transaction = getInsertOrReplace(sqLiteDatabase, COLUMN_TITLE, COLUMN_AUTHOR, COLUMN_JSON);
sqLiteDatabase.beginTransaction();
for (Link link : links) {
transaction.insertOrReplace(link.getId(), System.currentTimeMillis(), link.getCreatedUtc(), link.getTitle(), link.getAuthor(), link.getJson());
}
sqLiteDatabase.setTransactionSuccessful();
sqLiteDatabase.endTransaction();
TransactionInsertOrReplace transactionWithComments = getInsertOrReplace(sqLiteDatabase, COLUMN_TITLE, COLUMN_AUTHOR, COLUMN_JSON, COLUMN_COMMENTS);
sqLiteDatabase.beginTransaction();
for (Link link : linksWithComments) {
transactionWithComments.insertOrReplace(link.getId(), System.currentTimeMillis(), link.getCreatedUtc(), link.getTitle(), link.getAuthor(), link.getJson(), link.getJsonComments());
}
sqLiteDatabase.setTransactionSuccessful();
sqLiteDatabase.endTransaction();
}
};
}
use of com.winsonchiu.reader.data.reddit.Link in project Reader by TheKeeperOfPie.
the class ControllerProfile method getViewType.
public int getViewType(int position) {
List<Thing> children = data.getChildren();
if (position < 0 || position >= children.size()) {
throw new IndexOutOfBoundsException("ControllerProfile position invalid: " + position);
}
Thing thing = children.get(position);
if (thing instanceof Link) {
return VIEW_TYPE_LINK;
} else if (thing instanceof Comment) {
return VIEW_TYPE_COMMENT;
}
throw new IllegalStateException(thing + " is not a valid view type");
}
Aggregations