use of com.odysee.app.model.lbryinc.LbryNotification in project odysee-android by OdyseeTeam.
the class NotificationListAdapter method clearNotifications.
public void clearNotifications() {
// Using a for-each loop will throw an exception, so a simple for should be used
for (Iterator<LbryNotification> iterator = getItems().iterator(); iterator.hasNext(); ) {
LbryNotification notification = iterator.next();
iterator.remove();
}
notifyDataSetChanged();
}
use of com.odysee.app.model.lbryinc.LbryNotification in project odysee-android by OdyseeTeam.
the class DatabaseHelper method getNotifications.
public static List<LbryNotification> getNotifications(SQLiteDatabase db) {
List<LbryNotification> notifications = new ArrayList<>();
Cursor cursor = null;
try {
cursor = db.rawQuery(SQL_GET_NOTIFICATIONS, null);
while (cursor.moveToNext()) {
LbryNotification notification = new LbryNotification();
int columnIndex = 0;
notification.setId(cursor.getLong(columnIndex++));
notification.setRemoteId(cursor.getLong(columnIndex++));
notification.setAuthorThumbnailUrl(cursor.getString(columnIndex++));
notification.setClaimThumbnailUrl(cursor.getString(columnIndex++));
notification.setTitle(cursor.getString(columnIndex++));
notification.setDescription(cursor.getString(columnIndex++));
notification.setRule(cursor.getString(columnIndex++));
notification.setTargetUrl(cursor.getString(columnIndex++));
notification.setRead(cursor.getInt(columnIndex++) == 1);
notification.setSeen(cursor.getInt(columnIndex++) == 1);
try {
notification.setTimestamp(new SimpleDateFormat(Helper.ISO_DATE_FORMAT_PATTERN).parse(cursor.getString(columnIndex++)));
} catch (ParseException ex) {
// invalid timestamp (which shouldn't happen). Skip this item
continue;
}
notifications.add(notification);
}
} finally {
Helper.closeCursor(cursor);
}
return notifications;
}
use of com.odysee.app.model.lbryinc.LbryNotification in project odysee-android by OdyseeTeam.
the class MainActivity method handleDeleteSelectedNotifications.
private void handleDeleteSelectedNotifications(List<LbryNotification> notifications) {
List<Long> remoteIds = new ArrayList<>();
for (LbryNotification notification : notifications) {
remoteIds.add(notification.getRemoteId());
}
(new AsyncTask<Void, Void, Void>() {
protected Void doInBackground(Void... params) {
try {
SQLiteDatabase db = dbHelper.getWritableDatabase();
DatabaseHelper.deleteNotifications(notifications, db);
} catch (Exception ex) {
// pass
}
return null;
}
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new NotificationDeleteTask(remoteIds).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (notificationListAdapter != null) {
notificationListAdapter.removeNotifications(notifications);
}
if (actionMode != null) {
actionMode.finish();
}
}
use of com.odysee.app.model.lbryinc.LbryNotification in project odysee-android by OdyseeTeam.
the class MainActivity method onActionItemClicked.
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (R.id.action_delete == item.getItemId()) {
if (notificationListAdapter != null && notificationListAdapter.getSelectedCount() > 0) {
final List<LbryNotification> selectedNotifications = new ArrayList<>(notificationListAdapter.getSelectedItems());
String message = getResources().getQuantityString(R.plurals.confirm_delete_notifications, selectedNotifications.size());
AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(R.string.delete_selection).setMessage(message).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
handleDeleteSelectedNotifications(selectedNotifications);
}
}).setNegativeButton(R.string.no, null);
builder.show();
return true;
}
}
return false;
}
use of com.odysee.app.model.lbryinc.LbryNotification in project odysee-android by OdyseeTeam.
the class MainActivity method markNotificationsSeen.
private void markNotificationsSeen() {
List<LbryNotification> all = notificationListAdapter != null ? notificationListAdapter.getItems() : null;
if (all != null) {
List<Long> unseenIds = new ArrayList<>();
for (LbryNotification notification : all) {
if (!notification.isSeen() && notification.getRemoteId() > 0) {
unseenIds.add(notification.getRemoteId());
}
}
if (!unseenIds.isEmpty()) {
AccountManager am = AccountManager.get(this);
Map<String, String> options = new HashMap<>();
options.put("notification_ids", Helper.joinL(unseenIds, ","));
options.put("is_seen", "true");
if (am != null) {
String at = am.peekAuthToken(Helper.getOdyseeAccount(am.getAccounts()), "auth_token_type");
if (at != null)
options.put("auth_token", at);
}
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
ExecutorService executorService = Executors.newSingleThreadExecutor();
Supplier<Boolean> task = new NotificationUpdateSupplier(options);
CompletableFuture<Boolean> cf = CompletableFuture.supplyAsync(task, executorService);
cf.thenAcceptAsync(result -> {
if (result) {
SQLiteDatabase db = dbHelper.getWritableDatabase();
DatabaseHelper.markNotificationsSeen(db);
loadUnseenNotificationsCount();
}
}, executorService);
} else {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
Lbryio.call("notification", "edit", options, null);
SQLiteDatabase db = dbHelper.getWritableDatabase();
DatabaseHelper.markNotificationsSeen(db);
db.close();
loadUnseenNotificationsCount();
} catch (LbryioRequestException | LbryioResponseException e) {
e.printStackTrace();
}
}
});
t.start();
}
}
}
}
Aggregations