Search in sources :

Example 16 with Link

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;
        }
    }
}
Also used : Thing(com.winsonchiu.reader.data.reddit.Thing) Link(com.winsonchiu.reader.data.reddit.Link)

Example 17 with Link

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;
}
Also used : IOException(java.io.IOException) Cursor(android.database.Cursor) Link(com.winsonchiu.reader.data.reddit.Link) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 18 with 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();
        }
    };
}
Also used : Action1(rx.functions.Action1) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) TransactionInsertOrReplace(com.winsonchiu.reader.data.database.TransactionInsertOrReplace) ArrayList(java.util.ArrayList) Link(com.winsonchiu.reader.data.reddit.Link)

Example 19 with Link

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");
}
Also used : Comment(com.winsonchiu.reader.data.reddit.Comment) Thing(com.winsonchiu.reader.data.reddit.Thing) Link(com.winsonchiu.reader.data.reddit.Link)

Aggregations

Link (com.winsonchiu.reader.data.reddit.Link)19 AdapterLink (com.winsonchiu.reader.links.AdapterLink)8 RecyclerView (android.support.v7.widget.RecyclerView)7 View (android.view.View)7 AppBarLayout (android.support.design.widget.AppBarLayout)6 ViewGroup (android.view.ViewGroup)6 Thing (com.winsonchiu.reader.data.reddit.Thing)6 Bundle (android.os.Bundle)5 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)5 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)5 ImageView (android.widget.ImageView)5 AdapterListener (com.winsonchiu.reader.adapter.AdapterListener)5 Likes (com.winsonchiu.reader.data.reddit.Likes)5 Sort (com.winsonchiu.reader.data.reddit.Sort)5 BindView (butterknife.BindView)4 ActivityMain (com.winsonchiu.reader.ActivityMain)4 Source (com.winsonchiu.reader.comments.Source)4 Activity (android.app.Activity)3 Nullable (android.support.annotation.Nullable)3 GestureDetectorCompat (android.support.v4.view.GestureDetectorCompat)3