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) { if( streamingIntent != null) {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit(); 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); stopService(streamingIntent);
editor.apply(); 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); int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
instance = sharedpreferences.getString(Helper.PREF_INSTANCE, context!=null?Helper.getLiveInstance(context):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); notificationsListAdapter = new NotificationsListAdapter(context,isOnWifi, behaviorWithAttachments,this.notifications);
lv_notifications.setAdapter(notificationsListAdapter); lv_notifications.setAdapter(notificationsListAdapter);
mLayoutManager = new LinearLayoutManager(context); mLayoutManager = new LinearLayoutManager(context);

View File

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

View File

@ -81,7 +81,8 @@ public class StreamingFederatedTimelineService extends IntentService {
} }
SharedPreferences.Editor editor = sharedpreferences.edit(); SharedPreferences.Editor editor = sharedpreferences.edit();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); 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(); editor.apply();
} }
@ -117,7 +118,7 @@ public class StreamingFederatedTimelineService extends IntentService {
reader = new BufferedReader(new InputStreamReader(inputStream)); reader = new BufferedReader(new InputStreamReader(inputStream));
String event; String event;
while((event = reader.readLine()) != null) { 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(); httpsURLConnection.disconnect();
stopSelf(); stopSelf();
return; return;
@ -140,7 +141,7 @@ public class StreamingFederatedTimelineService extends IntentService {
reader.close(); reader.close();
}catch (IOException ignored){} }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); SystemClock.sleep(1000);
sendBroadcast(new Intent("RestartStreamingFederatedService")); sendBroadcast(new Intent("RestartStreamingFederatedService"));
} }

View File

@ -80,7 +80,8 @@ public class StreamingLocalTimelineService extends IntentService {
} }
SharedPreferences.Editor editor = sharedpreferences.edit(); SharedPreferences.Editor editor = sharedpreferences.edit();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); 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(); editor.apply();
} }
@ -116,7 +117,7 @@ public class StreamingLocalTimelineService extends IntentService {
reader = new BufferedReader(new InputStreamReader(inputStream)); reader = new BufferedReader(new InputStreamReader(inputStream));
String event; String event;
while((event = reader.readLine()) != null) { 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(); httpsURLConnection.disconnect();
stopSelf(); stopSelf();
return; return;
@ -139,7 +140,7 @@ public class StreamingLocalTimelineService extends IntentService {
reader.close(); reader.close();
}catch (IOException ignored){} }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); SystemClock.sleep(1000);
sendBroadcast(new Intent("RestartStreamingLocalService")); 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 sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit(); SharedPreferences.Editor editor = sharedpreferences.edit();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); 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(); editor.apply();
} }
@ -115,7 +116,7 @@ public class StreamingService extends IntentService {
String event; String event;
Helper.EventStreaming eventStreaming; Helper.EventStreaming eventStreaming;
while((event = reader.readLine()) != null) { 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(); stopSelf();
if ((lastEvent == Helper.EventStreaming.NONE || lastEvent == null) && !event.startsWith("data: ")) { if ((lastEvent == Helper.EventStreaming.NONE || lastEvent == null) && !event.startsWith("data: ")) {
switch (event.trim()) { switch (event.trim()) {