Fix for videos

This commit is contained in:
Thomas 2020-05-17 17:47:35 +02:00
parent 129621c73c
commit a0563ce4c0
4 changed files with 201 additions and 203 deletions

View File

@ -559,7 +559,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory) videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, apiResponse.getPeertubes().get(0).isStreamService()))); .createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, apiResponse.getPeertubes().get(0).isStreamService())));
} else { } else {
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this, video_cache * 1024 * 1024, 5 * 1024 * 1024); CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory) videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, apiResponse.getPeertubes().get(0).isStreamService()))); .createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, apiResponse.getPeertubes().get(0).isStreamService())));
} }
@ -767,7 +767,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory) videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(Uri.parse(peertube.getFileUrl(res, peertube.isStreamService()))); .createMediaSource(Uri.parse(peertube.getFileUrl(res, peertube.isStreamService())));
} else { } else {
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this, video_cache * 1024 * 1024, 5 * 1024 * 1024); CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory) videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
.createMediaSource(Uri.parse(peertube.getFileUrl(res, peertube.isStreamService()))); .createMediaSource(Uri.parse(peertube.getFileUrl(res, peertube.isStreamService())));
} }

View File

@ -263,7 +263,7 @@ public class MediaSliderFragment extends Fragment implements MediaPlayer.OnCompl
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory) videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(uri); .createMediaSource(uri);
} else { } else {
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(context, video_cache * 1024 * 1024, 5 * 1024 * 1024); CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(context);
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory) videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
.createMediaSource(uri); .createMediaSource(uri);
} }

View File

@ -18,15 +18,15 @@ import java.io.File;
public class CacheDataSourceFactory implements DataSource.Factory { public class CacheDataSourceFactory implements DataSource.Factory {
private static SimpleCache sDownloadCache;
private final Context context; private final Context context;
private final DefaultDataSourceFactory defaultDatasourceFactory; private final DefaultDataSourceFactory defaultDatasourceFactory;
private final long maxFileSize, maxCacheSize; private final long maxFileSize;
public CacheDataSourceFactory(Context context, long maxCacheSize, long maxFileSize) { public CacheDataSourceFactory(Context context) {
super(); super();
this.context = context; this.context = context;
this.maxCacheSize = maxCacheSize; this.maxFileSize = 5 * 1024 * 1024;
this.maxFileSize = maxFileSize;
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userAgent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, Helper.USER_AGENT); String userAgent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, Helper.USER_AGENT);
DefaultBandwidthMeter.Builder bandwidthMeterBuilder = new DefaultBandwidthMeter.Builder(context); DefaultBandwidthMeter.Builder bandwidthMeterBuilder = new DefaultBandwidthMeter.Builder(context);
@ -36,11 +36,19 @@ public class CacheDataSourceFactory implements DataSource.Factory {
new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter)); new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter));
} }
public static SimpleCache getInstance(Context context) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB);
LeastRecentlyUsedCacheEvictor evictor = new LeastRecentlyUsedCacheEvictor(video_cache * 1024 * 1024);
ExoDatabaseProvider exoDatabaseProvider = new ExoDatabaseProvider(context);
if (sDownloadCache == null)
sDownloadCache = new SimpleCache(new File(context.getCacheDir(), "media"), evictor, exoDatabaseProvider);
return sDownloadCache;
}
@Override @Override
public DataSource createDataSource() { public DataSource createDataSource() {
LeastRecentlyUsedCacheEvictor evictor = new LeastRecentlyUsedCacheEvictor(maxCacheSize); SimpleCache simpleCache = getInstance(context);
ExoDatabaseProvider exoDatabaseProvider = new ExoDatabaseProvider(context);
SimpleCache simpleCache = new SimpleCache(new File(context.getCacheDir(), "media"), evictor, exoDatabaseProvider);
return new CacheDataSource(simpleCache, defaultDatasourceFactory.createDataSource(), return new CacheDataSource(simpleCache, defaultDatasourceFactory.createDataSource(),
new FileDataSource(), new CacheDataSink(simpleCache, maxFileSize), new FileDataSource(), new CacheDataSink(simpleCache, maxFileSize),
CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR, null); CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR, null);

View File

@ -172,6 +172,8 @@ public class LiveNotificationService extends Service implements NetworkStateRece
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true); boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true);
if (!notify || intent == null || intent.getBooleanExtra("stop", false)) { if (!notify || intent == null || intent.getBooleanExtra("stop", false)) {
totalAccount = 0; totalAccount = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@ -298,213 +300,202 @@ public class LiveNotificationService extends Service implements NetworkStateRece
if (response == null) if (response == null)
return; return;
final Notification notification; final Notification notification;
String dataId;
Bundle b = new Bundle(); Bundle b = new Bundle();
boolean canSendBroadCast = true; boolean canSendBroadCast = true;
Helper.EventStreaming event; Helper.EventStreaming event;
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
try { try {
switch (response.get("event").toString()) { if ("notification".equals(response.get("event").toString())) {
case "notification": eventsCount++;
eventsCount++; if (Build.VERSION.SDK_INT >= 26) {
if (Build.VERSION.SDK_INT >= 26) { channel = new NotificationChannel(CHANNEL_ID,
channel = new NotificationChannel(CHANNEL_ID, "Live notifications",
"Live notifications", NotificationManager.IMPORTANCE_DEFAULT);
NotificationManager.IMPORTANCE_DEFAULT); ((NotificationManager) Objects.requireNonNull(getSystemService(Context.NOTIFICATION_SERVICE))).createNotificationChannel(channel);
((NotificationManager) Objects.requireNonNull(getSystemService(Context.NOTIFICATION_SERVICE))).createNotificationChannel(channel); android.app.Notification notificationChannel = new NotificationCompat.Builder(this, CHANNEL_ID)
android.app.Notification notificationChannel = new NotificationCompat.Builder(this, CHANNEL_ID) .setContentTitle(getString(R.string.top_notification))
.setContentTitle(getString(R.string.top_notification)) .setSmallIcon(getNotificationIcon(LiveNotificationService.this))
.setSmallIcon(getNotificationIcon(LiveNotificationService.this)) .setContentText(getString(R.string.top_notification_message, String.valueOf(totalAccount), String.valueOf(eventsCount))).build();
.setContentText(getString(R.string.top_notification_message, String.valueOf(totalAccount), String.valueOf(eventsCount))).build();
startForeground(1, notificationChannel); startForeground(1, notificationChannel);
} }
event = Helper.EventStreaming.NOTIFICATION; event = Helper.EventStreaming.NOTIFICATION;
notification = API.parseNotificationResponse(LiveNotificationService.this, new JSONObject(response.get("payload").toString())); notification = API.parseNotificationResponse(LiveNotificationService.this, new JSONObject(response.get("payload").toString()));
b.putParcelable("data", notification); b.putParcelable("data", notification);
boolean liveNotifications = sharedpreferences.getBoolean(Helper.SET_LIVE_NOTIFICATIONS, true); boolean liveNotifications = sharedpreferences.getBoolean(Helper.SET_LIVE_NOTIFICATIONS, true);
boolean canNotify = Helper.canNotify(LiveNotificationService.this); boolean canNotify = Helper.canNotify(LiveNotificationService.this);
boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true); boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true);
String targeted_account = null; String targeted_account = null;
Helper.NotifType notifType = Helper.NotifType.MENTION; Helper.NotifType notifType = Helper.NotifType.MENTION;
boolean activityRunning = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("isMainActivityRunning", false); boolean activityRunning = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("isMainActivityRunning", false);
String key = account.getAcct() + "@" + account.getInstance(); String key = account.getAcct() + "@" + account.getInstance();
if (lastNotification.containsKey(key) && notification.getId().compareTo(Objects.requireNonNull(lastNotification.get(key))) <= 0) { if (lastNotification.containsKey(key) && notification.getId().compareTo(Objects.requireNonNull(lastNotification.get(key))) <= 0) {
canNotify = false; canNotify = false;
} }
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null); String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
if (notification.getId().compareTo(Objects.requireNonNull(lastNotif)) <= 0) { if (notification.getId().compareTo(Objects.requireNonNull(lastNotif)) <= 0) {
canNotify = false; canNotify = false;
} }
boolean allowStream = sharedpreferences.getBoolean(Helper.SET_ALLOW_STREAM + account.getId() + account.getInstance(), true); boolean allowStream = sharedpreferences.getBoolean(Helper.SET_ALLOW_STREAM + account.getId() + account.getInstance(), true);
if (!allowStream) { if (!allowStream) {
canNotify = false; canNotify = false;
} }
if ((userId == null || !userId.equals(account.getId()) || !activityRunning) && liveNotifications && canNotify && notify) { if ((userId == null || !userId.equals(account.getId()) || !activityRunning) && liveNotifications && canNotify && notify) {
lastNotification.put(key, notification.getId()); lastNotification.put(key, notification.getId());
boolean notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, true); boolean notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, true);
boolean notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true); boolean notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true);
boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true); boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true);
boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true); boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true);
boolean notif_poll = sharedpreferences.getBoolean(Helper.SET_NOTIF_POLL, true); boolean notif_poll = sharedpreferences.getBoolean(Helper.SET_NOTIF_POLL, true);
boolean somethingToPush = (notif_follow || notif_add || notif_mention || notif_share || notif_poll); boolean somethingToPush = (notif_follow || notif_add || notif_mention || notif_share || notif_poll);
String message = null; String message = null;
if (somethingToPush) { if (somethingToPush) {
switch (notification.getType()) { switch (notification.getType()) {
case "mention": case "mention":
notifType = Helper.NotifType.MENTION; notifType = Helper.NotifType.MENTION;
if (notif_mention) { if (notif_mention) {
if (notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0) if (notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0)
message = String.format("%s %s", notification.getAccount().getDisplay_name(), getString(R.string.notif_mention)); message = String.format("%s %s", notification.getAccount().getDisplay_name(), getString(R.string.notif_mention));
else else
message = String.format("@%s %s", notification.getAccount().getAcct(), getString(R.string.notif_mention)); message = String.format("@%s %s", notification.getAccount().getAcct(), getString(R.string.notif_mention));
if (notification.getStatus() != null) { if (notification.getStatus() != null) {
if (notification.getStatus().getSpoiler_text() != null && notification.getStatus().getSpoiler_text().length() > 0) { if (notification.getStatus().getSpoiler_text() != null && notification.getStatus().getSpoiler_text().length() > 0) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
message = "\n" + new SpannableString(Html.fromHtml(notification.getStatus().getSpoiler_text(), FROM_HTML_MODE_LEGACY)); message = "\n" + new SpannableString(Html.fromHtml(notification.getStatus().getSpoiler_text(), FROM_HTML_MODE_LEGACY));
else else
message = "\n" + new SpannableString(Html.fromHtml(notification.getStatus().getSpoiler_text())); message = "\n" + new SpannableString(Html.fromHtml(notification.getStatus().getSpoiler_text()));
} else { } else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
message = "\n" + new SpannableString(Html.fromHtml(notification.getStatus().getContent(), FROM_HTML_MODE_LEGACY)); message = "\n" + new SpannableString(Html.fromHtml(notification.getStatus().getContent(), FROM_HTML_MODE_LEGACY));
else else
message = "\n" + new SpannableString(Html.fromHtml(notification.getStatus().getContent())); message = "\n" + new SpannableString(Html.fromHtml(notification.getStatus().getContent()));
}
} }
} else {
canSendBroadCast = false;
} }
break; } else {
case "reblog": canSendBroadCast = false;
notifType = Helper.NotifType.BOOST;
if (notif_share) {
if (notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0)
message = String.format("%s %s", notification.getAccount().getDisplay_name(), getString(R.string.notif_reblog));
else
message = String.format("@%s %s", notification.getAccount().getAcct(), getString(R.string.notif_reblog));
} else {
canSendBroadCast = false;
}
break;
case "favourite":
notifType = Helper.NotifType.FAV;
if (notif_add) {
if (notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0)
message = String.format("%s %s", notification.getAccount().getDisplay_name(), getString(R.string.notif_favourite));
else
message = String.format("@%s %s", notification.getAccount().getAcct(), getString(R.string.notif_favourite));
} else {
canSendBroadCast = false;
}
break;
case "follow_request":
notifType = Helper.NotifType.FOLLLOW;
if (notif_follow) {
if (notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0)
message = String.format("%s %s", notification.getAccount().getDisplay_name(), getString(R.string.notif_follow_request));
else
message = String.format("@%s %s", notification.getAccount().getAcct(), getString(R.string.notif_follow_request));
targeted_account = notification.getAccount().getId();
} else {
canSendBroadCast = false;
}
break;
case "follow":
notifType = Helper.NotifType.FOLLLOW;
if (notif_follow) {
if (notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0)
message = String.format("%s %s", notification.getAccount().getDisplay_name(), getString(R.string.notif_follow));
else
message = String.format("@%s %s", notification.getAccount().getAcct(), getString(R.string.notif_follow));
targeted_account = notification.getAccount().getId();
} else {
canSendBroadCast = false;
}
break;
case "poll":
notifType = Helper.NotifType.POLL;
if (notif_poll) {
if (notification.getAccount().getId() != null && notification.getAccount().getId().equals(userId))
message = getString(R.string.notif_poll_self);
else
message = getString(R.string.notif_poll);
} else {
canSendBroadCast = false;
}
break;
default:
}
//Some others notification
final Intent intent = new Intent(LiveNotificationService.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Helper.INTENT_ACTION, Helper.NOTIFICATION_INTENT);
intent.putExtra(Helper.PREF_KEY_ID, account.getId());
intent.putExtra(Helper.PREF_INSTANCE, account.getInstance());
if (targeted_account != null) {
intent.putExtra(Helper.INTENT_TARGETED_ACCOUNT, targeted_account);
}
final String finalMessage = message;
Handler mainHandler = new Handler(Looper.getMainLooper());
Helper.NotifType finalNotifType = notifType;
Runnable myRunnable = () -> {
if (finalMessage != null) {
Glide.with(LiveNotificationService.this)
.asBitmap()
.load(notification.getAccount().getAvatar())
.listener(new RequestListener<Bitmap>() {
@Override
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
assert e != null;
Helper.notify_user(LiveNotificationService.this, account, intent, BitmapFactory.decodeResource(getResources(),
getMainLogo(LiveNotificationService.this)), finalNotifType, "@" + notification.getAccount().getAcct(), finalMessage);
return false;
}
})
.into(new CustomTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
Helper.notify_user(LiveNotificationService.this, account, intent, resource, finalNotifType, "@" + notification.getAccount().getAcct(), finalMessage);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
} }
}; break;
mainHandler.post(myRunnable); case "reblog":
notifType = Helper.NotifType.BOOST;
if (notif_share) {
if (notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0)
message = String.format("%s %s", notification.getAccount().getDisplay_name(), getString(R.string.notif_reblog));
else
message = String.format("@%s %s", notification.getAccount().getAcct(), getString(R.string.notif_reblog));
} else {
canSendBroadCast = false;
}
break;
case "favourite":
notifType = Helper.NotifType.FAV;
if (notif_add) {
if (notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0)
message = String.format("%s %s", notification.getAccount().getDisplay_name(), getString(R.string.notif_favourite));
else
message = String.format("@%s %s", notification.getAccount().getAcct(), getString(R.string.notif_favourite));
} else {
canSendBroadCast = false;
}
break;
case "follow_request":
notifType = Helper.NotifType.FOLLLOW;
if (notif_follow) {
if (notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0)
message = String.format("%s %s", notification.getAccount().getDisplay_name(), getString(R.string.notif_follow_request));
else
message = String.format("@%s %s", notification.getAccount().getAcct(), getString(R.string.notif_follow_request));
targeted_account = notification.getAccount().getId();
} else {
canSendBroadCast = false;
}
break;
case "follow":
notifType = Helper.NotifType.FOLLLOW;
if (notif_follow) {
if (notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0)
message = String.format("%s %s", notification.getAccount().getDisplay_name(), getString(R.string.notif_follow));
else
message = String.format("@%s %s", notification.getAccount().getAcct(), getString(R.string.notif_follow));
targeted_account = notification.getAccount().getId();
} else {
canSendBroadCast = false;
}
break;
case "poll":
notifType = Helper.NotifType.POLL;
if (notif_poll) {
if (notification.getAccount().getId() != null && notification.getAccount().getId().equals(userId))
message = getString(R.string.notif_poll_self);
else
message = getString(R.string.notif_poll);
} else {
canSendBroadCast = false;
}
break;
default:
} }
} //Some others notification
final Intent intent = new Intent(LiveNotificationService.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Helper.INTENT_ACTION, Helper.NOTIFICATION_INTENT);
intent.putExtra(Helper.PREF_KEY_ID, account.getId());
intent.putExtra(Helper.PREF_INSTANCE, account.getInstance());
if (targeted_account != null) {
intent.putExtra(Helper.INTENT_TARGETED_ACCOUNT, targeted_account);
}
final String finalMessage = message;
Handler mainHandler = new Handler(Looper.getMainLooper());
Helper.NotifType finalNotifType = notifType;
Runnable myRunnable = () -> {
if (finalMessage != null) {
Glide.with(LiveNotificationService.this)
.asBitmap()
.load(notification.getAccount().getAvatar())
.listener(new RequestListener<Bitmap>() {
@Override
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
if (canSendBroadCast) { @Override
b.putString("userIdService", account.getId()); public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
Intent intentBC = new Intent(Helper.RECEIVE_DATA); assert e != null;
intentBC.putExtra("eventStreaming", event); Helper.notify_user(LiveNotificationService.this, account, intent, BitmapFactory.decodeResource(getResources(),
intentBC.putExtras(b); getMainLogo(LiveNotificationService.this)), finalNotifType, "@" + notification.getAccount().getAcct(), finalMessage);
b.putParcelable("data", notification); return false;
LocalBroadcastManager.getInstance(LiveNotificationService.this).sendBroadcast(intentBC); }
SharedPreferences.Editor editor = sharedpreferences.edit(); })
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), notification.getId()); .into(new CustomTarget<Bitmap>() {
editor.apply(); @Override
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
Helper.notify_user(LiveNotificationService.this, account, intent, resource, finalNotifType, "@" + notification.getAccount().getAcct(), finalMessage);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
}
};
mainHandler.post(myRunnable);
} }
break; }
case "delete":
event = Helper.EventStreaming.DELETE; if (canSendBroadCast) {
try { b.putString("userIdService", account.getId());
dataId = response.getString("id"); Intent intentBC = new Intent(Helper.RECEIVE_DATA);
b.putString("dataId", dataId); intentBC.putExtra("eventStreaming", event);
} catch (JSONException ignored) { intentBC.putExtras(b);
} b.putParcelable("data", notification);
break; LocalBroadcastManager.getInstance(LiveNotificationService.this).sendBroadcast(intentBC);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), notification.getId());
editor.apply();
}
} }
} catch (Exception ignored) { } catch (Exception ignored) {
} }
@ -520,7 +511,6 @@ public class LiveNotificationService extends Service implements NetworkStateRece
for (Thread t : Thread.getAllStackTraces().keySet()) { for (Thread t : Thread.getAllStackTraces().keySet()) {
if (t.getName().startsWith("notif_live_")) { if (t.getName().startsWith("notif_live_")) {
t.interrupt(); t.interrupt();
t = null;
} }
} }
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();