2017-11-12 08:33:24 +01:00
|
|
|
package fr.gouv.etalab.mastodon.services;
|
|
|
|
/* Copyright 2017 Thomas Schneider
|
|
|
|
*
|
|
|
|
* This file is a part of Mastalab
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
2017-12-17 14:20:04 +01:00
|
|
|
|
2018-01-03 15:25:35 +01:00
|
|
|
import android.app.Service;
|
2017-11-12 08:33:24 +01:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
2017-11-30 18:18:58 +01:00
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.BitmapFactory;
|
|
|
|
import android.os.Bundle;
|
2017-12-02 14:17:06 +01:00
|
|
|
import android.os.Handler;
|
2017-11-12 08:33:24 +01:00
|
|
|
import android.os.IBinder;
|
2017-12-02 14:17:06 +01:00
|
|
|
import android.os.Looper;
|
2017-11-30 18:18:58 +01:00
|
|
|
import android.os.SystemClock;
|
2017-11-12 08:33:24 +01:00
|
|
|
import android.support.annotation.Nullable;
|
2017-11-30 18:18:58 +01:00
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
|
|
|
|
2017-12-02 11:02:25 +01:00
|
|
|
import com.bumptech.glide.Glide;
|
|
|
|
import com.bumptech.glide.load.DataSource;
|
|
|
|
import com.bumptech.glide.load.engine.GlideException;
|
|
|
|
import com.bumptech.glide.request.RequestListener;
|
|
|
|
import com.bumptech.glide.request.target.SimpleTarget;
|
|
|
|
import com.bumptech.glide.request.target.Target;
|
|
|
|
import com.bumptech.glide.request.transition.Transition;
|
2017-11-30 18:18:58 +01:00
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
import java.io.BufferedInputStream;
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.ArrayList;
|
2018-01-03 19:39:42 +01:00
|
|
|
import java.util.HashMap;
|
2017-11-12 08:33:24 +01:00
|
|
|
import java.util.List;
|
2017-11-30 18:18:58 +01:00
|
|
|
|
|
|
|
import javax.net.ssl.HttpsURLConnection;
|
|
|
|
|
|
|
|
import fr.gouv.etalab.mastodon.R;
|
|
|
|
import fr.gouv.etalab.mastodon.activities.BaseMainActivity;
|
|
|
|
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
|
|
|
import fr.gouv.etalab.mastodon.client.API;
|
2017-11-12 08:33:24 +01:00
|
|
|
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
2017-11-30 18:18:58 +01:00
|
|
|
import fr.gouv.etalab.mastodon.client.Entities.Notification;
|
|
|
|
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
|
|
|
import fr.gouv.etalab.mastodon.client.TLSSocketFactory;
|
2017-11-12 08:33:24 +01:00
|
|
|
import fr.gouv.etalab.mastodon.helper.Helper;
|
|
|
|
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
|
|
|
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
|
|
|
|
2017-11-30 18:18:58 +01:00
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
|
2018-01-06 14:07:49 +01:00
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_TARGETED_ACCOUNT;
|
2017-11-30 18:18:58 +01:00
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.NOTIFICATION_INTENT;
|
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.PREF_KEY_ID;
|
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.notify_user;
|
|
|
|
|
2017-11-12 08:33:24 +01:00
|
|
|
|
|
|
|
/**
|
2017-11-30 07:16:18 +01:00
|
|
|
* Created by Thomas on 29/11/2017.
|
2017-11-12 08:33:24 +01:00
|
|
|
* Manage service for streaming api and new notifications
|
|
|
|
*/
|
|
|
|
|
2018-01-03 15:25:35 +01:00
|
|
|
public class LiveNotificationService extends Service {
|
2017-11-12 08:33:24 +01:00
|
|
|
|
|
|
|
|
2017-11-14 15:11:31 +01:00
|
|
|
|
2017-11-12 08:33:24 +01:00
|
|
|
protected Account account;
|
2018-01-03 15:25:35 +01:00
|
|
|
private boolean stop = false;
|
2018-01-03 19:39:42 +01:00
|
|
|
private static HashMap<String, Boolean> isRunning = new HashMap<>();
|
2017-11-12 08:33:24 +01:00
|
|
|
public void onCreate() {
|
|
|
|
super.onCreate();
|
|
|
|
}
|
|
|
|
|
2018-01-05 10:32:08 +01:00
|
|
|
static {
|
|
|
|
Helper.installProvider();
|
|
|
|
}
|
2018-01-02 14:47:13 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
|
|
|
2018-01-03 15:25:35 +01:00
|
|
|
if( intent == null || intent.getBooleanExtra("stop", false) ) {
|
|
|
|
stop = true;
|
|
|
|
stopSelf();
|
|
|
|
}
|
2017-11-12 08:33:24 +01:00
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
2017-11-30 07:16:18 +01:00
|
|
|
boolean liveNotifications = sharedpreferences.getBoolean(Helper.SET_LIVE_NOTIFICATIONS, true);
|
|
|
|
boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true);
|
2017-11-30 07:32:14 +01:00
|
|
|
String userId;
|
2018-01-03 15:25:35 +01:00
|
|
|
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
2017-11-30 07:16:18 +01:00
|
|
|
if( liveNotifications && notify){
|
2018-01-03 15:25:35 +01:00
|
|
|
|
2017-11-30 18:18:58 +01:00
|
|
|
if( intent == null || intent.getStringExtra("userId") == null) {
|
2018-01-02 11:29:54 +01:00
|
|
|
|
2017-11-30 07:32:14 +01:00
|
|
|
List<Account> accountStreams = new AccountDAO(getApplicationContext(), db).getAllAccount();
|
|
|
|
if (accountStreams != null){
|
|
|
|
for (final Account accountStream : accountStreams) {
|
2018-01-02 14:47:13 +01:00
|
|
|
Thread thread = new Thread() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
taks(accountStream);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
thread.start();
|
2018-01-03 15:25:35 +01:00
|
|
|
|
2018-01-02 14:47:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
userId = intent.getStringExtra("userId");
|
|
|
|
final Account accountStream = new AccountDAO(getApplicationContext(), db).getAccountByID(userId);
|
|
|
|
if (accountStream != null) {
|
2017-11-30 18:18:58 +01:00
|
|
|
Thread thread = new Thread() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
taks(accountStream);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
thread.start();
|
2018-01-03 15:25:35 +01:00
|
|
|
|
2017-11-12 08:33:24 +01:00
|
|
|
}
|
2017-11-30 07:32:14 +01:00
|
|
|
}
|
2017-11-12 08:33:24 +01:00
|
|
|
}
|
2018-01-03 15:25:35 +01:00
|
|
|
return START_STICKY;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public IBinder onBind(Intent intent) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
if( !stop)
|
|
|
|
sendBroadcast(new Intent("RestartLiveNotificationService"));
|
2017-11-12 08:33:24 +01:00
|
|
|
}
|
|
|
|
|
2017-11-30 18:18:58 +01:00
|
|
|
private void taks(Account account){
|
|
|
|
InputStream inputStream = null;
|
2018-01-03 18:34:40 +01:00
|
|
|
HttpsURLConnection httpsURLConnection = null;
|
2017-11-30 18:18:58 +01:00
|
|
|
BufferedReader reader = null;
|
|
|
|
Helper.EventStreaming lastEvent = null;
|
2018-01-03 15:25:35 +01:00
|
|
|
|
2017-11-30 18:18:58 +01:00
|
|
|
if( account != null){
|
2018-01-03 19:39:42 +01:00
|
|
|
isRunning.get(account.getAcct()+account.getInstance());
|
|
|
|
if(!isRunning.containsKey(account.getAcct()+account.getInstance()) || ! isRunning.get(account.getAcct()+account.getInstance())) {
|
|
|
|
try {
|
|
|
|
URL url = new URL("https://" + account.getInstance() + "/api/v1/streaming/user");
|
|
|
|
httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
|
|
|
httpsURLConnection.setRequestProperty("Content-Type", "application/json");
|
|
|
|
httpsURLConnection.setRequestProperty("Authorization", "Bearer " + account.getToken());
|
|
|
|
httpsURLConnection.setRequestProperty("Connection", "Keep-Alive");
|
|
|
|
httpsURLConnection.setRequestProperty("Keep-Alive", "header");
|
|
|
|
httpsURLConnection.setRequestProperty("Connection", "close");
|
|
|
|
httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory());
|
|
|
|
httpsURLConnection.setRequestMethod("GET");
|
|
|
|
if (httpsURLConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
|
|
|
inputStream = new BufferedInputStream(httpsURLConnection.getInputStream());
|
|
|
|
reader = new BufferedReader(new InputStreamReader(inputStream));
|
|
|
|
String event;
|
|
|
|
Helper.EventStreaming eventStreaming;
|
|
|
|
while ((event = reader.readLine()) != null) {
|
|
|
|
isRunning.put(account.getAcct()+account.getInstance(), true);
|
|
|
|
if ((lastEvent == Helper.EventStreaming.NONE || lastEvent == null) && !event.startsWith("data: ")) {
|
|
|
|
switch (event.trim()) {
|
|
|
|
case "event: update":
|
|
|
|
lastEvent = Helper.EventStreaming.UPDATE;
|
|
|
|
break;
|
|
|
|
case "event: notification":
|
|
|
|
lastEvent = Helper.EventStreaming.NOTIFICATION;
|
|
|
|
break;
|
|
|
|
case "event: delete":
|
|
|
|
lastEvent = Helper.EventStreaming.DELETE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lastEvent = Helper.EventStreaming.NONE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!event.startsWith("data: ")) {
|
2017-11-30 18:18:58 +01:00
|
|
|
lastEvent = Helper.EventStreaming.NONE;
|
2018-01-03 19:39:42 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
event = event.substring(6);
|
|
|
|
if (lastEvent == Helper.EventStreaming.UPDATE) {
|
|
|
|
eventStreaming = Helper.EventStreaming.UPDATE;
|
|
|
|
} else if (lastEvent == Helper.EventStreaming.NOTIFICATION) {
|
|
|
|
eventStreaming = Helper.EventStreaming.NOTIFICATION;
|
|
|
|
} else if (lastEvent == Helper.EventStreaming.DELETE) {
|
|
|
|
eventStreaming = Helper.EventStreaming.DELETE;
|
|
|
|
event = "{id:" + event + "}";
|
|
|
|
} else {
|
|
|
|
eventStreaming = Helper.EventStreaming.UPDATE;
|
|
|
|
}
|
2017-11-30 18:18:58 +01:00
|
|
|
lastEvent = Helper.EventStreaming.NONE;
|
2018-01-03 19:39:42 +01:00
|
|
|
try {
|
|
|
|
JSONObject eventJson = new JSONObject(event);
|
|
|
|
onRetrieveStreaming(eventStreaming, account, eventJson);
|
2018-01-04 15:29:23 +01:00
|
|
|
} catch (JSONException ignored) { ignored.printStackTrace();
|
2018-01-03 19:39:42 +01:00
|
|
|
}
|
2017-11-30 18:18:58 +01:00
|
|
|
}
|
|
|
|
}
|
2018-01-03 19:39:42 +01:00
|
|
|
isRunning.put(account.getAcct() + account.getInstance(), false);
|
2017-11-30 18:18:58 +01:00
|
|
|
}
|
|
|
|
|
2018-01-03 19:39:42 +01:00
|
|
|
} catch (Exception ignored) {
|
|
|
|
isRunning.put(account.getAcct() + account.getInstance(), false);
|
|
|
|
ignored.printStackTrace();
|
|
|
|
} finally {
|
|
|
|
if (reader != null) {
|
|
|
|
try {
|
|
|
|
reader.close();
|
|
|
|
} catch (IOException ignored) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (inputStream != null) {
|
|
|
|
try {
|
|
|
|
inputStream.close();
|
|
|
|
} catch (IOException ignored) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (inputStream != null) {
|
|
|
|
httpsURLConnection.disconnect();
|
|
|
|
}
|
|
|
|
SystemClock.sleep(5000);
|
|
|
|
Intent streamingIntent = new Intent(this, LiveNotificationService.class);
|
|
|
|
streamingIntent.putExtra("userId", account.getId());
|
2017-11-30 18:18:58 +01:00
|
|
|
try {
|
2018-01-03 19:39:42 +01:00
|
|
|
startService(streamingIntent);
|
|
|
|
} catch (Exception ignored) {
|
|
|
|
}
|
2018-01-03 18:34:40 +01:00
|
|
|
}
|
2017-11-30 18:18:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void onRetrieveStreaming(Helper.EventStreaming event, final Account account, JSONObject response) {
|
|
|
|
if( response == null )
|
|
|
|
return;
|
|
|
|
//No previous notifications in cache, so no notification will be sent
|
|
|
|
fr.gouv.etalab.mastodon.client.Entities.Status status ;
|
|
|
|
final Notification notification;
|
|
|
|
String dataId = null;
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
if( event == Helper.EventStreaming.NOTIFICATION){
|
|
|
|
notification = API.parseNotificationResponse(getApplicationContext(), response);
|
|
|
|
b.putParcelable("data", notification);
|
|
|
|
boolean activityPaused;
|
|
|
|
try {
|
|
|
|
activityPaused = BaseMainActivity.activityState();
|
|
|
|
}catch (Exception e){
|
|
|
|
activityPaused = true;
|
|
|
|
}
|
|
|
|
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
|
|
boolean liveNotifications = sharedpreferences.getBoolean(Helper.SET_LIVE_NOTIFICATIONS, true);
|
|
|
|
boolean canNotify = Helper.canNotify(getApplicationContext());
|
|
|
|
boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true);
|
|
|
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
2018-01-06 14:07:49 +01:00
|
|
|
String targeted_account = null;
|
2017-11-30 18:18:58 +01:00
|
|
|
if((userId == null || !userId.equals(account.getId()) || activityPaused) && liveNotifications && canNotify && notify) {
|
|
|
|
boolean notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, true);
|
|
|
|
boolean notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true);
|
|
|
|
boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true);
|
|
|
|
boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true);
|
|
|
|
boolean somethingToPush = (notif_follow || notif_add || notif_mention || notif_share);
|
|
|
|
String title = null;
|
|
|
|
if( somethingToPush && notification != null){
|
|
|
|
switch (notification.getType()){
|
|
|
|
case "mention":
|
|
|
|
if(notif_mention){
|
|
|
|
if( notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0 )
|
|
|
|
title = String.format("%s %s", Helper.shortnameToUnicode(notification.getAccount().getDisplay_name(), true),getString(R.string.notif_mention));
|
|
|
|
else
|
|
|
|
title = String.format("@%s %s", notification.getAccount().getAcct(),getString(R.string.notif_mention));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "reblog":
|
|
|
|
if(notif_share){
|
|
|
|
if( notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0 )
|
|
|
|
title = String.format("%s %s", Helper.shortnameToUnicode(notification.getAccount().getDisplay_name(), true),getString(R.string.notif_reblog));
|
|
|
|
else
|
|
|
|
title = String.format("@%s %s", notification.getAccount().getAcct(),getString(R.string.notif_reblog));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "favourite":
|
|
|
|
if(notif_add){
|
|
|
|
if( notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0 )
|
|
|
|
title = String.format("%s %s", Helper.shortnameToUnicode(notification.getAccount().getDisplay_name(), true),getString(R.string.notif_favourite));
|
|
|
|
else
|
|
|
|
title = String.format("@%s %s", notification.getAccount().getAcct(),getString(R.string.notif_favourite));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "follow":
|
|
|
|
if(notif_follow){
|
|
|
|
if( notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0 )
|
|
|
|
title = String.format("%s %s", Helper.shortnameToUnicode(notification.getAccount().getDisplay_name(), true),getString(R.string.notif_follow));
|
|
|
|
else
|
|
|
|
title = String.format("@%s %s", notification.getAccount().getAcct(),getString(R.string.notif_follow));
|
2018-01-06 14:07:49 +01:00
|
|
|
targeted_account = notification.getAccount().getId();
|
2017-11-30 18:18:58 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
//Some others notification
|
|
|
|
final Intent intent = new Intent(getApplicationContext(), MainActivity.class);
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK );
|
|
|
|
intent.putExtra(INTENT_ACTION, NOTIFICATION_INTENT);
|
|
|
|
intent.putExtra(PREF_KEY_ID, account.getId());
|
2018-01-06 14:07:49 +01:00
|
|
|
if( targeted_account != null )
|
|
|
|
intent.putExtra(INTENT_TARGETED_ACCOUNT, targeted_account);
|
2017-11-30 18:18:58 +01:00
|
|
|
long notif_id = Long.parseLong(account.getId());
|
|
|
|
final int notificationId = ((notif_id + 1) > 2147483647) ? (int) (2147483647 - notif_id - 1) : (int) (notif_id + 1);
|
|
|
|
if( notification.getAccount().getAvatar() != null ) {
|
2017-12-02 11:02:25 +01:00
|
|
|
|
2017-11-30 18:18:58 +01:00
|
|
|
|
|
|
|
final String finalTitle = title;
|
2017-12-02 14:17:06 +01:00
|
|
|
|
|
|
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
|
|
|
|
|
|
Runnable myRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if( finalTitle != null) {
|
|
|
|
|
|
|
|
Glide.with(getApplicationContext())
|
|
|
|
.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) {
|
|
|
|
notify_user(getApplicationContext(), intent, notificationId, BitmapFactory.decodeResource(getResources(),
|
|
|
|
R.drawable.mastodonlogo), finalTitle, "@"+account.getAcct()+"@"+account.getInstance());
|
2017-12-28 17:56:03 +01:00
|
|
|
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
|
2017-12-02 14:17:06 +01:00
|
|
|
if (lastNotif == null || Long.parseLong(notification.getId()) > Long.parseLong(lastNotif)) {
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
2017-12-28 17:56:03 +01:00
|
|
|
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), notification.getId());
|
2017-12-02 14:17:06 +01:00
|
|
|
editor.apply();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.into(new SimpleTarget<Bitmap>() {
|
|
|
|
@Override
|
|
|
|
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
|
|
|
|
notify_user(getApplicationContext(), intent, notificationId, resource, finalTitle, "@"+account.getAcct()+"@"+account.getInstance());
|
2017-12-28 17:56:03 +01:00
|
|
|
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
|
2017-12-02 14:17:06 +01:00
|
|
|
if (lastNotif == null || Long.parseLong(notification.getId()) > Long.parseLong(lastNotif)) {
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
2017-12-28 17:56:03 +01:00
|
|
|
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), notification.getId());
|
2017-12-02 14:17:06 +01:00
|
|
|
editor.apply();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
mainHandler.post(myRunnable);
|
2017-11-30 18:18:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else if ( event == Helper.EventStreaming.UPDATE){
|
|
|
|
status = API.parseStatuses(getApplicationContext(), response);
|
|
|
|
status.setReplies(new ArrayList<Status>());
|
|
|
|
status.setNew(true);
|
|
|
|
b.putParcelable("data", status);
|
|
|
|
}else if( event == Helper.EventStreaming.DELETE){
|
|
|
|
try {
|
|
|
|
dataId = response.getString("id");
|
2017-12-02 14:54:25 +01:00
|
|
|
} catch (JSONException ignored) {}
|
2017-11-30 18:18:58 +01:00
|
|
|
}
|
|
|
|
if( account != null)
|
|
|
|
b.putString("userIdService",account.getId());
|
|
|
|
Intent intentBC = new Intent(Helper.RECEIVE_DATA);
|
|
|
|
intentBC.putExtra("eventStreaming", event);
|
|
|
|
intentBC.putExtras(b);
|
|
|
|
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intentBC);
|
|
|
|
}
|
2017-11-12 08:33:24 +01:00
|
|
|
|
|
|
|
}
|