Search in sources :

Example 1 with DailyNews

use of io.github.izzyleung.zhihudailypurify.bean.DailyNews in project ZhihuDailyPurify by izzyleung.

the class NewsListFromZhihuObservable method convertToDailyNews.

private static Optional<DailyNews> convertToDailyNews(Pair<Story, Document> pair) {
    DailyNews result = null;
    Story story = pair.first;
    Document document = pair.second;
    String dailyTitle = story.getDailyTitle();
    List<Question> questions = getQuestions(document, dailyTitle);
    if (Stream.of(questions).allMatch(Question::isValidZhihuQuestion)) {
        result = new DailyNews();
        result.setDailyTitle(dailyTitle);
        result.setThumbnailUrl(story.getThumbnailUrl());
        result.setQuestions(questions);
    }
    return Optional.ofNullable(result);
}
Also used : Question(io.github.izzyleung.zhihudailypurify.bean.Question) DailyNews(io.github.izzyleung.zhihudailypurify.bean.DailyNews) Document(org.jsoup.nodes.Document) Story(io.github.izzyleung.zhihudailypurify.bean.Story)

Example 2 with DailyNews

use of io.github.izzyleung.zhihudailypurify.bean.DailyNews in project ZhihuDailyPurify by izzyleung.

the class NewsAdapter method share.

private void share(Context context, int position) {
    DailyNews dailyNews = newsList.get(position);
    if (dailyNews.hasMultipleQuestions()) {
        AlertDialog dialog = createDialog(context, dailyNews, makeShareQuestionDialogClickListener(context, dailyNews));
        dialog.show();
    } else {
        shareQuestion(context, dailyNews.getQuestions().get(0).getTitle(), dailyNews.getQuestions().get(0).getUrl());
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DailyNews(io.github.izzyleung.zhihudailypurify.bean.DailyNews)

Example 3 with DailyNews

use of io.github.izzyleung.zhihudailypurify.bean.DailyNews in project ZhihuDailyPurify by izzyleung.

the class NewsAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(CardViewHolder holder, int position) {
    DailyNews dailyNews = newsList.get(position);
    imageLoader.displayImage(dailyNews.getThumbnailUrl(), holder.newsImage, options, animateFirstListener);
    if (dailyNews.getQuestions().size() > 1) {
        holder.questionTitle.setText(dailyNews.getDailyTitle());
        holder.dailyTitle.setText(Constants.Strings.MULTIPLE_DISCUSSION);
    } else {
        holder.questionTitle.setText(dailyNews.getQuestions().get(0).getTitle());
        holder.dailyTitle.setText(dailyNews.getDailyTitle());
    }
}
Also used : DailyNews(io.github.izzyleung.zhihudailypurify.bean.DailyNews)

Example 4 with DailyNews

use of io.github.izzyleung.zhihudailypurify.bean.DailyNews in project ZhihuDailyPurify by izzyleung.

the class NewsAdapter method browse.

private void browse(Context context, int position) {
    DailyNews dailyNews = newsList.get(position);
    if (dailyNews.hasMultipleQuestions()) {
        AlertDialog dialog = createDialog(context, dailyNews, makeGoToZhihuDialogClickListener(context, dailyNews));
        dialog.show();
    } else {
        goToZhihu(context, dailyNews.getQuestions().get(0).getUrl());
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DailyNews(io.github.izzyleung.zhihudailypurify.bean.DailyNews)

Example 5 with DailyNews

use of io.github.izzyleung.zhihudailypurify.bean.DailyNews in project ZhihuDailyPurify by izzyleung.

the class DailyNewsDataSource method insertDailyNewsList.

public List<DailyNews> insertDailyNewsList(String date, String content) {
    ContentValues values = new ContentValues();
    values.put(DBHelper.COLUMN_DATE, date);
    values.put(DBHelper.COLUMN_CONTENT, content);
    long insertId = database.insert(DBHelper.TABLE_NAME, null, values);
    Cursor cursor = database.query(DBHelper.TABLE_NAME, allColumns, DBHelper.COLUMN_ID + " = " + insertId, null, null, null, null);
    cursor.moveToFirst();
    List<DailyNews> newsList = cursorToNewsList(cursor);
    cursor.close();
    return newsList;
}
Also used : ContentValues(android.content.ContentValues) DailyNews(io.github.izzyleung.zhihudailypurify.bean.DailyNews) Cursor(android.database.Cursor)

Aggregations

DailyNews (io.github.izzyleung.zhihudailypurify.bean.DailyNews)7 Cursor (android.database.Cursor)2 AlertDialog (android.support.v7.app.AlertDialog)2 ContentValues (android.content.ContentValues)1 GsonBuilder (com.google.gson.GsonBuilder)1 Question (io.github.izzyleung.zhihudailypurify.bean.Question)1 Story (io.github.izzyleung.zhihudailypurify.bean.Story)1 DailyNewsDataSource (io.github.izzyleung.zhihudailypurify.db.DailyNewsDataSource)1 Document (org.jsoup.nodes.Document)1