Adds instance to sharedpref
This commit is contained in:
parent
6a4b7b7cce
commit
0707fb7570
|
@ -147,7 +147,8 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
private AppBarLayout appBar;
|
||||
private static boolean activityPaused;
|
||||
private String bookmark;
|
||||
|
||||
private String userId;
|
||||
private String instance;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -577,11 +578,13 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
}
|
||||
});
|
||||
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getApplicationContext()));
|
||||
|
||||
//Get the previous bookmark value
|
||||
//If null try to use the LAST_HOMETIMELINE_MAX_ID
|
||||
String lastHomeTimeline = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, null);
|
||||
bookmark = sharedpreferences.getString(Helper.BOOKMARK_ID + userId, lastHomeTimeline);
|
||||
String lastHomeTimeline = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId + instance, null);
|
||||
bookmark = sharedpreferences.getString(Helper.BOOKMARK_ID + userId + instance, lastHomeTimeline);
|
||||
Account account = new AccountDAO(getApplicationContext(), db).getAccountByID(userId);
|
||||
if( account == null){
|
||||
Helper.logout(getApplicationContext());
|
||||
|
@ -757,7 +760,6 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
}
|
||||
|
||||
//Check instance release for lists
|
||||
String instance = Helper.getLiveInstance(getApplicationContext());
|
||||
String instanceVersion = sharedpreferences.getString(Helper.INSTANCE_VERSION + userId + instance, null);
|
||||
if (instanceVersion != null) {
|
||||
Version currentVersion = new Version(instanceVersion);
|
||||
|
@ -834,7 +836,6 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
Helper.EventStreaming eventStreaming = (Helper.EventStreaming) intent.getSerializableExtra("eventStreaming");
|
||||
assert b != null;
|
||||
userIdService = b.getString("userIdService", null);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
if( userIdService != null && userIdService.equals(userId)) {
|
||||
if (eventStreaming == Helper.EventStreaming.NOTIFICATION) {
|
||||
Notification notification = b.getParcelable("data");
|
||||
|
@ -1192,14 +1193,12 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
@Override
|
||||
public void onStart(){
|
||||
super.onStart();
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
receive_federated_data = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Bundle b = intent.getExtras();
|
||||
assert b != null;
|
||||
userIdService = b.getString("userIdService", null);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
if( userIdService != null && userIdService.equals(userId)) {
|
||||
Status status = b.getParcelable("data");
|
||||
if (federatedFragment != null) {
|
||||
|
@ -1214,7 +1213,6 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
Bundle b = intent.getExtras();
|
||||
assert b != null;
|
||||
userIdService = b.getString("userIdService", null);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
if( userIdService != null && userIdService.equals(userId)) {
|
||||
Status status = b.getParcelable("data");
|
||||
if (localFragment != null) {
|
||||
|
@ -1234,7 +1232,6 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
if( streamingIntent != null) {
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED+userId, false);
|
||||
stopService(streamingIntent);
|
||||
editor.apply();
|
||||
|
@ -1392,8 +1389,6 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
startActivity(myIntent);
|
||||
finish();
|
||||
}else {
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
SQLiteDatabase db = Sqlite.getInstance(BaseMainActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(getApplicationContext(), db).getAccountByID(userId);
|
||||
updateHeaderAccountInfo(BaseMainActivity.this, account, headerLayout);
|
||||
|
@ -1436,8 +1431,6 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
Version minVersion = new Version("1.6");
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
String instance = Helper.getLiveInstance(getApplicationContext());
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
editor.putString(Helper.INSTANCE_VERSION + userId + instance, apiResponse.getInstance().getVersion());
|
||||
editor.apply();
|
||||
Helper.canPin = (currentVersion.compareTo(minVersion) == 1 || currentVersion.equals(minVersion));
|
||||
|
|
|
@ -188,11 +188,14 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount
|
|||
private AlertDialog alertDialogEmoji;
|
||||
private String mentionAccount;
|
||||
private String idRedirect;
|
||||
private String userId, instance;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getApplicationContext()));
|
||||
final int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||
if( theme == Helper.THEME_LIGHT){
|
||||
setTheme(R.style.AppTheme);
|
||||
|
@ -308,11 +311,11 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount
|
|||
setTitle(R.string.toot_title);
|
||||
}
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
String userId;
|
||||
String userIdReply;
|
||||
if( accountReply == null)
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
userIdReply = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
else
|
||||
userId = accountReply.getId();
|
||||
userIdReply = accountReply.getId();
|
||||
|
||||
if( mentionAccount != null){
|
||||
toot_content.setText(String.format("@%s\n", mentionAccount));
|
||||
|
@ -337,7 +340,7 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount
|
|||
initialContent = toot_content.getText().toString();
|
||||
Account account;
|
||||
if( accountReply == null)
|
||||
account = new AccountDAO(getApplicationContext(),db).getAccountByID(userId);
|
||||
account = new AccountDAO(getApplicationContext(),db).getAccountByID(userIdReply);
|
||||
else
|
||||
account = accountReply;
|
||||
|
||||
|
@ -1137,8 +1140,7 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount
|
|||
itemViewReply.setVisible(false);
|
||||
}
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String instance = Helper.getLiveInstance(getApplicationContext());
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
|
||||
String instanceVersion = sharedpreferences.getString(Helper.INSTANCE_VERSION + userId + instance, null);
|
||||
Version currentVersion = new Version(instanceVersion);
|
||||
Version minVersion = new Version("2.0");
|
||||
|
@ -1231,8 +1233,6 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount
|
|||
return false;
|
||||
}
|
||||
});
|
||||
String instance = Helper.getLiveInstance(getApplicationContext());
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instanceVersion = sharedpreferences.getString(Helper.INSTANCE_VERSION + userId + instance, null);
|
||||
if (instanceVersion != null) {
|
||||
Version currentVersion = new Version(instanceVersion);
|
||||
|
@ -1735,8 +1735,6 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount
|
|||
@Override
|
||||
public void onClick(View view) {
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||
String instance = Helper.getLiveInstance(getApplicationContext());
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instanceVersion = sharedpreferences.getString(Helper.INSTANCE_VERSION + userId + instance, null);
|
||||
if (instanceVersion != null) {
|
||||
Version currentVersion = new Version(instanceVersion);
|
||||
|
@ -1823,11 +1821,11 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount
|
|||
title.setText(getString(R.string.toot_title_reply));
|
||||
else
|
||||
setTitle(R.string.toot_title_reply);
|
||||
String userId;
|
||||
String userIdReply;
|
||||
if( accountReply == null)
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
userIdReply = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
else
|
||||
userId = accountReply.getId();
|
||||
userIdReply = accountReply.getId();
|
||||
|
||||
//If toot is not restored
|
||||
if( restored == -1 ){
|
||||
|
@ -1858,7 +1856,7 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount
|
|||
//Retrieves mentioned accounts + OP and adds them at the beginin of the toot
|
||||
ArrayList<String> mentionedAccountsAdded = new ArrayList<>();
|
||||
int cursorReply = 0;
|
||||
if( tootReply.getAccount() != null && tootReply.getAccount().getAcct() != null && !tootReply.getAccount().getId().equals(userId)) {
|
||||
if( tootReply.getAccount() != null && tootReply.getAccount().getAcct() != null && !tootReply.getAccount().getId().equals(userIdReply)) {
|
||||
toot_content.setText(String.format("@%s", tootReply.getAccount().getAcct()));
|
||||
mentionedAccountsAdded.add(tootReply.getAccount().getAcct());
|
||||
//Evaluate the cursor position => mention length + 1 char for carriage return
|
||||
|
@ -1868,7 +1866,7 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount
|
|||
//Put other accounts mentioned at the bottom
|
||||
toot_content.setText(String.format("%s", (toot_content.getText().toString() + "\n\n")));
|
||||
for(Mention mention : tootReply.getMentions()){
|
||||
if( mention.getAcct() != null && !mention.getId().equals(userId) && !mentionedAccountsAdded.contains(mention.getAcct())) {
|
||||
if( mention.getAcct() != null && !mention.getId().equals(userIdReply) && !mentionedAccountsAdded.contains(mention.getAcct())) {
|
||||
mentionedAccountsAdded.add(mention.getAcct());
|
||||
String tootTemp = String.format("@%s ", mention.getAcct());
|
||||
toot_content.setText(String.format("%s ", (toot_content.getText().toString() + tootTemp.trim())));
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.lang.ref.WeakReference;
|
|||
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveHomeTimelineServiceInterface;
|
||||
|
||||
/**
|
||||
|
@ -32,32 +33,27 @@ public class RetrieveHomeTimelineServiceAsyncTask extends AsyncTask<Void, Void,
|
|||
|
||||
private APIResponse apiResponse;
|
||||
private String since_id;
|
||||
private String acct, userId;
|
||||
private Account account;
|
||||
private OnRetrieveHomeTimelineServiceInterface listener;
|
||||
private String instance;
|
||||
private String token;
|
||||
private WeakReference<Context> contextReference;
|
||||
|
||||
public RetrieveHomeTimelineServiceAsyncTask(Context context, String instance, String token, String since_id, String acct, String userId, OnRetrieveHomeTimelineServiceInterface onRetrieveHomeTimelineServiceInterface){
|
||||
public RetrieveHomeTimelineServiceAsyncTask(Context context, Account account, String since_id, OnRetrieveHomeTimelineServiceInterface onRetrieveHomeTimelineServiceInterface){
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.since_id = since_id;
|
||||
this.listener = onRetrieveHomeTimelineServiceInterface;
|
||||
this.acct = acct;
|
||||
this.instance = instance;
|
||||
this.userId = userId;
|
||||
this.token = token;
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
API api = new API(this.contextReference.get(), instance, token);
|
||||
API api = new API(this.contextReference.get(), this.account.getInstance(), this.account.getToken());
|
||||
apiResponse = api.getHomeTimelineSinceId(since_id);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveHomeTimelineService(apiResponse, acct, userId);
|
||||
listener.onRetrieveHomeTimelineService(apiResponse, this.account);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
private boolean swiped;
|
||||
private RecyclerView lv_notifications;
|
||||
private String lastReadNotifications;
|
||||
private String userId;
|
||||
private String userId, instance;
|
||||
private SharedPreferences sharedpreferences;
|
||||
LinearLayoutManager mLayoutManager;
|
||||
|
||||
|
@ -96,6 +96,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
boolean isOnWifi = Helper.isOnWIFI(context);
|
||||
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
instance = sharedpreferences.getString(Helper.PREF_INSTANCE, context!=null?Helper.getLiveInstance(context):null);
|
||||
lastReadNotifications = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId, null);
|
||||
notificationsListAdapter = new NotificationsListAdapter(context,isOnWifi, behaviorWithAttachments,this.notifications);
|
||||
lv_notifications.setAdapter(notificationsListAdapter);
|
||||
|
@ -318,12 +319,12 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
*/
|
||||
private void updateNotificationLastId(String notificationId){
|
||||
|
||||
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId, null);
|
||||
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, null);
|
||||
if( lastNotif == null || Long.parseLong(notificationId) > Long.parseLong(lastNotif)){
|
||||
this.lastReadNotifications = notificationId;
|
||||
MainActivity.countNewNotifications = 0;
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId, notificationId);
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, notificationId);
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
LinearLayoutManager mLayoutManager;
|
||||
boolean firstTootsLoaded;
|
||||
private String lastReadStatus;
|
||||
private String userId;
|
||||
private String userId, instance;
|
||||
private SharedPreferences sharedpreferences;
|
||||
|
||||
public DisplayStatusFragment(){
|
||||
|
@ -118,7 +118,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
mLayoutManager = new LinearLayoutManager(context);
|
||||
lv_status.setLayoutManager(mLayoutManager);
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
lastReadStatus = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId, null);
|
||||
lastReadStatus = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, null);
|
||||
instance = sharedpreferences.getString(Helper.PREF_INSTANCE, context!=null?Helper.getLiveInstance(context):null);
|
||||
|
||||
lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy)
|
||||
|
@ -147,7 +148,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
if( context instanceof BaseMainActivity){
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
Long bookmarkL = Long.parseLong(statuses.get(firstVisibleItem).getId()) + 1;
|
||||
editor.putString(Helper.BOOKMARK_ID + userId, String.valueOf(bookmarkL));
|
||||
editor.putString(Helper.BOOKMARK_ID + userId + instance, String.valueOf(bookmarkL));
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
|
@ -300,7 +301,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
this.statuses.addAll(statuses);
|
||||
statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size());
|
||||
}else { //Toots are younger than the bookmark
|
||||
String currentMaxId = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, null);
|
||||
String currentMaxId = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId + instance, null);
|
||||
int position = 0;
|
||||
while (position < this.statuses.size() && Long.parseLong(statuses.get(0).getId()) < Long.parseLong(this.statuses.get(position).getId())) {
|
||||
position++;
|
||||
|
@ -551,12 +552,12 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
*/
|
||||
private void updateStatusLastId(String statusId){
|
||||
|
||||
String lastNotif = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, null);
|
||||
String lastNotif = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId + instance, null);
|
||||
if( lastNotif == null || Long.parseLong(statusId) > Long.parseLong(lastNotif)){
|
||||
this.lastReadStatus = statusId;
|
||||
MainActivity.countNewStatus = 0;
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, statusId);
|
||||
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId + instance, statusId);
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -882,6 +882,8 @@ public class Helper {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Converts dp to pixel
|
||||
* @param dp float - the value in dp to convert
|
||||
|
|
|
@ -16,11 +16,12 @@ package fr.gouv.etalab.mastodon.interfaces;
|
|||
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 20/05/2017.
|
||||
* Interface when home timeline toots have been retrieved
|
||||
*/
|
||||
public interface OnRetrieveHomeTimelineServiceInterface {
|
||||
void onRetrieveHomeTimelineService(APIResponse apiResponse, String acct, String userId);
|
||||
void onRetrieveHomeTimelineService(APIResponse apiResponse, Account account);
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@ import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
|||
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.HOME_TIMELINE_INTENT;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.PREF_INSTANCE;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.PREF_KEY_ID;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.canNotify;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.notify_user;
|
||||
|
@ -119,17 +120,17 @@ public class HomeTimelineSyncJob extends Job implements OnRetrieveHomeTimelineSe
|
|||
return;
|
||||
//Retrieve users in db that owner has.
|
||||
for (Account account: accounts) {
|
||||
String max_id = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_NOTIFICATION_MAX_ID + account.getId(), null);
|
||||
String lastHomeSeen = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + account.getId(), null);
|
||||
String max_id = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
|
||||
String lastHomeSeen = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + account.getId() + account.getInstance(), null);
|
||||
if( lastHomeSeen != null && max_id != null){
|
||||
if( Long.parseLong(lastHomeSeen) > Long.parseLong(max_id)){
|
||||
max_id = lastHomeSeen;
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_HOMETIMELINE_NOTIFICATION_MAX_ID + account.getId(), max_id);
|
||||
editor.putString(Helper.LAST_HOMETIMELINE_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), max_id);
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
new RetrieveHomeTimelineServiceAsyncTask(getContext(), account.getInstance(), account.getToken(), max_id, account.getAcct(), account.getId(), HomeTimelineSyncJob.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new RetrieveHomeTimelineServiceAsyncTask(getContext(), account, max_id, HomeTimelineSyncJob.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -137,13 +138,14 @@ public class HomeTimelineSyncJob extends Job implements OnRetrieveHomeTimelineSe
|
|||
|
||||
|
||||
@Override
|
||||
public void onRetrieveHomeTimelineService(APIResponse apiResponse, String acct, final String userId) {
|
||||
public void onRetrieveHomeTimelineService(APIResponse apiResponse, final Account account) {
|
||||
final List<Status> statuses = apiResponse.getStatuses();
|
||||
if( apiResponse.getError() != null || statuses == null || statuses.size() == 0)
|
||||
return;
|
||||
|
||||
final SharedPreferences sharedpreferences = getContext().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
|
||||
final String max_id = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_NOTIFICATION_MAX_ID + userId, null);
|
||||
final String max_id = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
|
||||
|
||||
//No previous notifications in cache, so no notification will be sent
|
||||
String message;
|
||||
|
@ -151,7 +153,7 @@ public class HomeTimelineSyncJob extends Job implements OnRetrieveHomeTimelineSe
|
|||
for(Status status: statuses){
|
||||
//The notification associated to max_id is discarded as it is supposed to have already been sent
|
||||
//Also, if the toot comes from the owner, we will avoid to warn him/her...
|
||||
if( max_id != null && (status.getId().equals(max_id)) || (acct != null && status.getAccount().getAcct().trim().equals(acct.trim()) ))
|
||||
if( max_id != null && (status.getId().equals(max_id)) || (account.getAcct() != null && status.getAccount().getAcct().trim().equals(account.getAcct().trim()) ))
|
||||
continue;
|
||||
String notificationUrl = status.getAccount().getAvatar();
|
||||
|
||||
|
@ -162,8 +164,9 @@ public class HomeTimelineSyncJob extends Job implements OnRetrieveHomeTimelineSe
|
|||
final Intent intent = new Intent(getContext(), MainActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK );
|
||||
intent.putExtra(INTENT_ACTION, HOME_TIMELINE_INTENT);
|
||||
intent.putExtra(PREF_KEY_ID, userId);
|
||||
long notif_id = Long.parseLong(userId);
|
||||
intent.putExtra(PREF_KEY_ID, account.getId());
|
||||
intent.putExtra(PREF_INSTANCE, account.getInstance());
|
||||
long notif_id = Long.parseLong(account.getId());
|
||||
final int notificationId = ((notif_id + 2) > 2147483647) ? (int) (2147483647 - notif_id - 2) : (int) (notif_id + 2);
|
||||
|
||||
if( notificationUrl != null){
|
||||
|
@ -190,7 +193,7 @@ public class HomeTimelineSyncJob extends Job implements OnRetrieveHomeTimelineSe
|
|||
notify_user(getContext(), intent, notificationId, BitmapFactory.decodeResource(getContext().getResources(),
|
||||
R.drawable.mastodonlogo), finalTitle, finalMessage);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_HOMETIMELINE_NOTIFICATION_MAX_ID + userId, statuses.get(0).getId());
|
||||
editor.putString(Helper.LAST_HOMETIMELINE_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), statuses.get(0).getId());
|
||||
editor.apply();
|
||||
return false;
|
||||
}
|
||||
|
@ -200,7 +203,7 @@ public class HomeTimelineSyncJob extends Job implements OnRetrieveHomeTimelineSe
|
|||
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
|
||||
notify_user(getContext(), intent, notificationId, resource, finalTitle, finalMessage);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_HOMETIMELINE_NOTIFICATION_MAX_ID + userId, statuses.get(0).getId());
|
||||
editor.putString(Helper.LAST_HOMETIMELINE_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), statuses.get(0).getId());
|
||||
editor.apply();
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue