Some other shared prefs

This commit is contained in:
stom79 2017-12-28 17:39:02 +01:00
parent 842afbbe8a
commit 03358f531d
6 changed files with 21 additions and 18 deletions

View File

@ -1232,7 +1232,7 @@ public abstract class BaseMainActivity extends BaseActivity
if( streamingIntent != null) {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED+userId, false);
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED + userId + instance, false);
stopService(streamingIntent);
editor.apply();
}

View File

@ -98,7 +98,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
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);
lastReadNotifications = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId + userId, null);
notificationsListAdapter = new NotificationsListAdapter(context,isOnWifi, behaviorWithAttachments,this.notifications);
lv_notifications.setAdapter(notificationsListAdapter);
mLayoutManager = new LinearLayoutManager(context);

View File

@ -411,7 +411,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
if( getUserVisibleHint() ){
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED+userId, true);
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED + userId + instance, true);
editor.apply();
streamingFederatedIntent = new Intent(context, StreamingFederatedTimelineService.class);
context.startService(streamingFederatedIntent);
@ -422,7 +422,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
if( getUserVisibleHint() ){
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_LOCAL+userId, true);
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_LOCAL + userId + instance, true);
editor.apply();
streamingLocalIntent = new Intent(context, StreamingLocalTimelineService.class);
context.startService(streamingLocalIntent);
@ -455,7 +455,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
} else if( type == RetrieveFeedsAsyncTask.Type.PUBLIC ){
if (visible) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED+userId, true);
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED + userId + instance, true);
editor.apply();
streamingFederatedIntent = new Intent(context, StreamingFederatedTimelineService.class);
context.startService(streamingFederatedIntent);
@ -464,7 +464,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
}else {
if( streamingFederatedIntent != null ){
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED+userId, false);
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED + userId + instance, false);
editor.apply();
context.stopService(streamingFederatedIntent);
}
@ -472,7 +472,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
}else if (type == RetrieveFeedsAsyncTask.Type.LOCAL){
if (visible) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_LOCAL+userId, true);
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_LOCAL + userId + instance, true);
editor.apply();
streamingLocalIntent = new Intent(context, StreamingLocalTimelineService.class);
context.startService(streamingLocalIntent);
@ -481,7 +481,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
}else {
if( streamingLocalIntent != null ){
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_LOCAL+userId, false);
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_LOCAL + userId + instance, false);
editor.apply();
context.stopService(streamingLocalIntent);
}
@ -494,12 +494,12 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
super.onStop();
if( type == RetrieveFeedsAsyncTask.Type.PUBLIC && streamingFederatedIntent != null){
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED+userId, false);
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED + userId + instance, false);
editor.apply();
context.stopService(streamingFederatedIntent);
}else if(type == RetrieveFeedsAsyncTask.Type.LOCAL && streamingLocalIntent != null){
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_LOCAL+userId, false);
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_LOCAL + userId + instance, false);
editor.apply();
context.stopService(streamingLocalIntent);
}

View File

@ -81,7 +81,8 @@ public class StreamingFederatedTimelineService extends IntentService {
}
SharedPreferences.Editor editor = sharedpreferences.edit();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED+userId, true);
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getApplicationContext()));
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED + userId + instance, true);
editor.apply();
}
@ -117,7 +118,7 @@ public class StreamingFederatedTimelineService extends IntentService {
reader = new BufferedReader(new InputStreamReader(inputStream));
String event;
while((event = reader.readLine()) != null) {
if (!sharedpreferences.getBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED + accountStream.getId(), true)) {
if (!sharedpreferences.getBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED + accountStream.getId() + accountStream.getInstance(), true)) {
httpsURLConnection.disconnect();
stopSelf();
return;
@ -140,7 +141,7 @@ public class StreamingFederatedTimelineService extends IntentService {
reader.close();
}catch (IOException ignored){}
}
if( sharedpreferences.getBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED + accountStream.getId(), true)) {
if( sharedpreferences.getBoolean(Helper.SHOULD_CONTINUE_STREAMING_FEDERATED + accountStream.getId() + accountStream.getInstance(), true)) {
SystemClock.sleep(1000);
sendBroadcast(new Intent("RestartStreamingFederatedService"));
}

View File

@ -80,7 +80,8 @@ public class StreamingLocalTimelineService extends IntentService {
}
SharedPreferences.Editor editor = sharedpreferences.edit();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_LOCAL+userId, true);
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getApplicationContext()));
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING_LOCAL + userId + instance, true);
editor.apply();
}
@ -116,7 +117,7 @@ public class StreamingLocalTimelineService extends IntentService {
reader = new BufferedReader(new InputStreamReader(inputStream));
String event;
while((event = reader.readLine()) != null) {
if (!sharedpreferences.getBoolean(Helper.SHOULD_CONTINUE_STREAMING_LOCAL + accountStream.getId(), true)) {
if (!sharedpreferences.getBoolean(Helper.SHOULD_CONTINUE_STREAMING_LOCAL + accountStream.getId() + accountStream.getInstance(), true)) {
httpsURLConnection.disconnect();
stopSelf();
return;
@ -139,7 +140,7 @@ public class StreamingLocalTimelineService extends IntentService {
reader.close();
}catch (IOException ignored){}
}
if( sharedpreferences.getBoolean(Helper.SHOULD_CONTINUE_STREAMING_LOCAL + accountStream.getId(), true)) {
if( sharedpreferences.getBoolean(Helper.SHOULD_CONTINUE_STREAMING_LOCAL + accountStream.getId() + accountStream.getInstance(), true)) {
SystemClock.sleep(1000);
sendBroadcast(new Intent("RestartStreamingLocalService"));
}

View File

@ -78,7 +78,8 @@ public class StreamingService extends IntentService {
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+userId, true);
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getApplicationContext()));
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING + userId + instance, true);
editor.apply();
}
@ -115,7 +116,7 @@ public class StreamingService extends IntentService {
String event;
Helper.EventStreaming eventStreaming;
while((event = reader.readLine()) != null) {
if( !sharedpreferences.getBoolean(Helper.SHOULD_CONTINUE_STREAMING + accountStream.getId(), true) )
if( !sharedpreferences.getBoolean(Helper.SHOULD_CONTINUE_STREAMING + accountStream.getId() + accountStream.getInstance(), true) )
stopSelf();
if ((lastEvent == Helper.EventStreaming.NONE || lastEvent == null) && !event.startsWith("data: ")) {
switch (event.trim()) {