Search in sources :

Example 1 with ViewHistory

use of com.odysee.app.model.ViewHistory in project odysee-android by OdyseeTeam.

the class DatabaseHelper method getViewHistory.

public static List<ViewHistory> getViewHistory(String lastTimestamp, int pageLimit, SQLiteDatabase db) {
    List<ViewHistory> history = new ArrayList<>();
    Cursor cursor = null;
    try {
        String arg = lastTimestamp == null ? "" : lastTimestamp;
        cursor = db.rawQuery(String.format(SQL_GET_VIEW_HISTORY, pageLimit), new String[] { arg, arg });
        while (cursor.moveToNext()) {
            ViewHistory item = new ViewHistory();
            int cursorIndex = 0;
            item.setUri(LbryUri.tryParse(cursor.getString(cursorIndex++)));
            item.setClaimId(cursor.getString(cursorIndex++));
            item.setClaimName(cursor.getString(cursorIndex++));
            item.setCost(new BigDecimal(cursor.getDouble(cursorIndex++)));
            item.setCurrency(cursor.getString(cursorIndex++));
            item.setTitle(cursor.getString(cursorIndex++));
            item.setPublisherClaimId(cursor.getString(cursorIndex++));
            item.setPublisherName(cursor.getString(cursorIndex++));
            item.setPublisherTitle(cursor.getString(cursorIndex++));
            item.setThumbnailUrl(cursor.getString(cursorIndex++));
            item.setDevice(cursor.getString(cursorIndex++));
            item.setReleaseTime(cursor.getLong(cursorIndex++));
            try {
                item.setTimestamp(new SimpleDateFormat(Helper.ISO_DATE_FORMAT_PATTERN).parse(cursor.getString(cursorIndex)));
            } catch (ParseException ex) {
                // invalid timestamp (which shouldn't happen). Skip this item
                continue;
            }
            history.add(item);
        }
    } finally {
        Helper.closeCursor(cursor);
    }
    return history;
}
Also used : ViewHistory(com.odysee.app.model.ViewHistory) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) Cursor(android.database.Cursor) SimpleDateFormat(java.text.SimpleDateFormat) SuppressLint(android.annotation.SuppressLint) BigDecimal(java.math.BigDecimal)

Example 2 with ViewHistory

use of com.odysee.app.model.ViewHistory in project odysee-android by OdyseeTeam.

the class Helper method saveViewHistory.

public static void saveViewHistory(String url, Claim claim) {
    DatabaseHelper dbHelper = DatabaseHelper.getInstance();
    if (dbHelper != null) {
        ViewHistory viewHistory = ViewHistory.fromClaimWithUrlAndDeviceName(claim, url, getDeviceName());
        new SaveViewHistoryTask(viewHistory, dbHelper, null).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
}
Also used : SaveViewHistoryTask(com.odysee.app.tasks.localdata.SaveViewHistoryTask) DatabaseHelper(com.odysee.app.data.DatabaseHelper) ViewHistory(com.odysee.app.model.ViewHistory)

Example 3 with ViewHistory

use of com.odysee.app.model.ViewHistory in project odysee-android by OdyseeTeam.

the class LibraryFragment method loadRecent.

private void loadRecent() {
    contentListLoading = true;
    Helper.setViewVisibility(layoutListEmpty, View.GONE);
    DatabaseHelper dbHelper = DatabaseHelper.getInstance();
    if (dbHelper != null) {
        FetchViewHistoryTask task = new FetchViewHistoryTask(lastDate, PAGE_SIZE, dbHelper, new FetchViewHistoryTask.FetchViewHistoryHandler() {

            @Override
            public void onSuccess(List<ViewHistory> history, boolean hasReachedEnd) {
                listReachedEnd = hasReachedEnd;
                if (history.size() > 0) {
                    lastDate = history.get(history.size() - 1).getTimestamp();
                }
                List<Claim> claims = Helper.claimsFromViewHistory(history);
                if (contentListAdapter == null) {
                    initRecentAdapter(claims);
                }
                if (contentListAdapter != null && recentList.getAdapter() == null) {
                    recentList.setAdapter(contentListAdapter);
                }
                checkListEmpty();
                contentListLoading = false;
            }
        });
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else {
        checkListEmpty();
        contentListLoading = false;
    }
}
Also used : FetchViewHistoryTask(com.odysee.app.tasks.localdata.FetchViewHistoryTask) DatabaseHelper(com.odysee.app.data.DatabaseHelper) ViewHistory(com.odysee.app.model.ViewHistory) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

ViewHistory (com.odysee.app.model.ViewHistory)3 DatabaseHelper (com.odysee.app.data.DatabaseHelper)2 ArrayList (java.util.ArrayList)2 SuppressLint (android.annotation.SuppressLint)1 Cursor (android.database.Cursor)1 FetchViewHistoryTask (com.odysee.app.tasks.localdata.FetchViewHistoryTask)1 SaveViewHistoryTask (com.odysee.app.tasks.localdata.SaveViewHistoryTask)1 BigDecimal (java.math.BigDecimal)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 List (java.util.List)1