use of com.odysee.app.model.lbryinc.LbryNotification in project odysee-android by OdyseeTeam.
the class MainActivity method updateLocalNotifications.
private void updateLocalNotifications(List<LbryNotification> notifications) {
findViewById(R.id.notification_list_empty_container).setVisibility(notifications.isEmpty() ? View.VISIBLE : View.GONE);
findViewById(R.id.notifications_progress).setVisibility(View.GONE);
loadUnseenNotificationsCount();
if (notificationListAdapter == null) {
notificationListAdapter = new NotificationListAdapter(notifications, MainActivity.this);
notificationListAdapter.setSelectionModeListener(MainActivity.this);
((RecyclerView) findViewById(R.id.notifications_list)).setAdapter(notificationListAdapter);
} else {
notificationListAdapter.addNotifications(notifications);
}
resolveCommentAuthors(notificationListAdapter.getAuthorUrls());
notificationListAdapter.setClickListener(new NotificationListAdapter.NotificationClickListener() {
@Override
public void onNotificationClicked(LbryNotification notification) {
// set as seen and read
Map<String, String> options = new HashMap<>();
options.put("notification_ids", String.valueOf(notification.getRemoteId()));
options.put("is_seen", "true");
// so let's not mark the notification as read
if (!notification.getTargetUrl().equalsIgnoreCase("lbry://?subscriptions")) {
options.put("is_read", "true");
} else {
options.put("is_read", "false");
}
AccountManager am = AccountManager.get(getApplicationContext());
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) {
Supplier<Boolean> supplier = new NotificationUpdateSupplier(options);
CompletableFuture.supplyAsync(supplier);
} else {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
Lbryio.call("notification", "edit", options, null);
} catch (LbryioResponseException | LbryioRequestException e) {
e.printStackTrace();
}
}
});
t.start();
}
if (!notification.getTargetUrl().equalsIgnoreCase("lbry://?subscriptions")) {
markNotificationReadAndSeen(notification.getId());
}
String targetUrl = notification.getTargetUrl();
if (targetUrl.startsWith(SPECIAL_URL_PREFIX)) {
openSpecialUrl(targetUrl, "notification");
} else {
LbryUri target = LbryUri.tryParse(notification.getTargetUrl());
if (target != null) {
if (target.isChannel()) {
openChannelUrl(notification.getTargetUrl(), "notification");
} else {
openFileUrl(notification.getTargetUrl(), "notification");
}
}
}
hideNotifications(false);
}
});
}
use of com.odysee.app.model.lbryinc.LbryNotification in project odysee-android by OdyseeTeam.
the class LbrynetMessagingService method onMessageReceived.
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (firebaseAnalytics == null) {
firebaseAnalytics = FirebaseAnalytics.getInstance(this);
}
Map<String, String> payload = remoteMessage.getData();
if (payload != null) {
String type = payload.get("type");
String url = payload.get("target");
String title = payload.get("title");
String body = payload.get("body");
// notification name
String name = payload.get("name");
// comment hash
String hash = payload.get("hash");
if (type != null && getEnabledTypes().contains(type) && body != null && body.trim().length() > 0) {
// only log the receive event for valid notifications received
if (firebaseAnalytics != null) {
Bundle bundle = new Bundle();
bundle.putString("name", name);
firebaseAnalytics.logEvent(LbryAnalytics.EVENT_LBRY_NOTIFICATION_RECEIVE, bundle);
}
if (!Helper.isNullOrEmpty(hash)) {
url = String.format("%s?comment_hash=%s", url, hash);
}
sendNotification(title, body, type, url, name);
}
// persist the notification data
try {
DatabaseHelper helper = DatabaseHelper.getInstance();
SQLiteDatabase db = helper.getWritableDatabase();
LbryNotification lnotification = new LbryNotification();
lnotification.setTitle(title);
lnotification.setDescription(body);
lnotification.setTargetUrl(url);
lnotification.setTimestamp(new Date());
DatabaseHelper.createOrUpdateNotification(lnotification, db);
// send a broadcast
Intent intent = new Intent(ACTION_NOTIFICATION_RECEIVED);
intent.putExtra("title", title);
intent.putExtra("body", body);
intent.putExtra("url", url);
intent.putExtra("timestamp", lnotification.getTimestamp().getTime());
sendBroadcast(intent);
} catch (Exception ex) {
// don't fail if any error occurs while saving a notification
Log.e(TAG, "could not save notification", ex);
}
}
}
use of com.odysee.app.model.lbryinc.LbryNotification in project odysee-android by OdyseeTeam.
the class GetLocalNotificationsSupplier method get.
@Override
public List<LbryNotification> get() {
List<LbryNotification> notifications = new ArrayList<>();
DatabaseHelper dbHelper = DatabaseHelper.getInstance();
try {
SQLiteDatabase db = dbHelper.getReadableDatabase();
notifications = DatabaseHelper.getNotifications(db);
} catch (Exception ex) {
ex.printStackTrace();
}
return notifications;
}
use of com.odysee.app.model.lbryinc.LbryNotification in project odysee-android by OdyseeTeam.
the class NotificationListSupplier method get.
@Override
public List<LbryNotification> get() {
List<LbryNotification> notifications = new ArrayList<>();
try {
JSONArray array = (JSONArray) Lbryio.parseResponse(Lbryio.call("notification", "list", options, null));
if (array != null) {
for (int i = 0; i < array.length(); i++) {
JSONObject item = array.getJSONObject(i);
if (item.has("notification_parameters")) {
LbryNotification notification = new LbryNotification();
JSONObject notificationParams = item.getJSONObject("notification_parameters");
if (notificationParams.has("device")) {
JSONObject device = notificationParams.getJSONObject("device");
notification.setTitle(Helper.getJSONString("title", null, device));
notification.setDescription(Helper.getJSONString("text", null, device));
notification.setTargetUrl(Helper.getJSONString("target", null, device));
}
if (notificationParams.has("dynamic") && !notificationParams.isNull("dynamic")) {
JSONObject dynamic = notificationParams.getJSONObject("dynamic");
if (dynamic.has("comment_author") || dynamic.has("channel_thumbnail")) {
String url = null;
if (dynamic.has("comment_author"))
url = Helper.getJSONString("comment_author", null, dynamic);
else if (dynamic.has("channel_thumbnail"))
url = Helper.getJSONString("channel_thumbnail", null, dynamic);
notification.setAuthorThumbnailUrl(url);
}
if (dynamic.has("channelURI")) {
String channelUrl = Helper.getJSONString("channelURI", null, dynamic);
if (!Helper.isNullOrEmpty(channelUrl)) {
notification.setTargetUrl(channelUrl);
}
}
if (dynamic.has("claim_thumbnail")) {
String claimThumbnailUrl = Helper.getJSONString("claim_thumbnail", null, dynamic);
if (!Helper.isNullOrEmpty(claimThumbnailUrl)) {
notification.setClaimThumbnailUrl(claimThumbnailUrl);
}
}
if (dynamic.has("hash") && "comment".equalsIgnoreCase(Helper.getJSONString("notification_rule", null, item))) {
notification.setTargetUrl(String.format("%s?comment_hash=%s", notification.getTargetUrl(), dynamic.getString("hash")));
}
}
notification.setRule(Helper.getJSONString("notification_rule", null, item));
notification.setRemoteId(Helper.getJSONLong("id", 0, item));
notification.setRead(Helper.getJSONBoolean("is_read", false, item));
notification.setSeen(Helper.getJSONBoolean("is_seen", false, item));
try {
SimpleDateFormat dateFormat = new SimpleDateFormat(Helper.ISO_DATE_FORMAT_JSON, Locale.US);
notification.setTimestamp(dateFormat.parse(Helper.getJSONString("created_at", dateFormat.format(new Date()), item)));
} catch (ParseException ex) {
notification.setTimestamp(new Date());
}
if (notification.getRemoteId() > 0 && !Helper.isNullOrEmpty(notification.getDescription())) {
notifications.add(notification);
}
}
}
}
} catch (ClassCastException | LbryioRequestException | LbryioResponseException | JSONException | IllegalStateException ex) {
ex.printStackTrace();
return null;
}
return notifications;
}
use of com.odysee.app.model.lbryinc.LbryNotification in project odysee-android by OdyseeTeam.
the class NotificationListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(NotificationListAdapter.ViewHolder vh, int position) {
LbryNotification notification = items.get(position);
vh.layoutView.setBackgroundColor(ContextCompat.getColor(context, notification.isRead() ? android.R.color.transparent : R.color.odyseePinkSemiTransparent));
vh.selectedOverlayView.setVisibility(isNotificationSelected(notification) ? View.VISIBLE : View.GONE);
vh.titleView.setVisibility(!Helper.isNullOrEmpty(notification.getTitle()) ? View.VISIBLE : View.GONE);
vh.titleView.setText(notification.getTitle());
vh.bodyView.setText(notification.getDescription());
vh.timeView.setText(DateUtils.getRelativeTimeSpanString(getLocalNotificationTime(notification), System.currentTimeMillis(), 0, DateUtils.FORMAT_ABBREV_RELATIVE));
vh.authorThumbnailView.setVisibility(notification.getCommentAuthor() == null || notification.getAuthorThumbnailUrl() == null ? View.INVISIBLE : View.VISIBLE);
if (notification.getAuthorThumbnailUrl() != null)
vh.authorThumbnailView.setVisibility(View.VISIBLE);
if (notification.getCommentAuthor() != null || notification.getAuthorThumbnailUrl() != null) {
String turl;
if (notification.getCommentAuthor() != null)
turl = notification.getCommentAuthor().getThumbnailUrl(vh.authorThumbnailView.getLayoutParams().width, vh.authorThumbnailView.getLayoutParams().height, 85);
else {
turl = getThumbnailUrl(vh.authorThumbnailView, notification.getAuthorThumbnailUrl());
}
Glide.with(context.getApplicationContext()).load(turl).apply(RequestOptions.circleCropTransform()).into(vh.authorThumbnailView);
}
if (notification.getClaimThumbnailUrl() != null) {
vh.bodyView.getLayoutParams().width = (int) (200 * context.getApplicationContext().getResources().getDisplayMetrics().density);
Configuration config = context.getApplicationContext().getResources().getConfiguration();
if (config.smallestScreenWidthDp > 359) {
String turl = getThumbnailUrl(vh.claimThumbnailView, notification.getClaimThumbnailUrl());
Glide.with(context.getApplicationContext()).asBitmap().load(turl).into(vh.claimThumbnailView);
vh.claimThumbnailView.setVisibility(View.VISIBLE);
} else {
vh.claimThumbnailView.setVisibility(View.GONE);
}
} else {
vh.bodyView.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
vh.claimThumbnailView.setVisibility(View.GONE);
}
vh.iconView.setVisibility(notification.getCommentAuthor() != null || notification.getAuthorThumbnailUrl() != null ? View.INVISIBLE : View.VISIBLE);
vh.iconView.setText(getStringIdForRule(notification.getRule()));
vh.iconView.setTextColor(getColorForRule(notification.getRule()));
vh.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (inSelectionMode) {
toggleSelectedNotification(notification);
} else {
if (clickListener != null) {
clickListener.onNotificationClicked(notification);
}
notification.setRead(true);
notification.setSeen(true);
notifyItemChanged(position);
}
}
});
vh.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
if (!inSelectionMode) {
inSelectionMode = true;
if (selectionModeListener != null) {
selectionModeListener.onEnterSelectionMode();
}
}
toggleSelectedNotification(notification);
return true;
}
});
}
Aggregations