From 9cb365381f0daf6fc4dfb0638c714e8c0e9ba031 Mon Sep 17 00:00:00 2001 From: stom79 Date: Sat, 11 Nov 2017 07:43:11 +0100 Subject: [PATCH] Keeps the service awaken when in live mode --- .../fragments/DisplayNotificationsFragment.java | 3 ++- .../mastodon/fragments/DisplayStatusFragment.java | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java index 5c03ac605..2f816aa92 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java @@ -19,6 +19,7 @@ import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.os.Looper; +import android.support.annotation.NonNull; import android.support.v4.app.Fragment; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.DividerItemDecoration; @@ -71,7 +72,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_notifications, container, false); max_id = null; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java index 36535e15c..a484ca70a 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java @@ -21,10 +21,10 @@ import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.os.Parcelable; +import android.support.annotation.NonNull; import android.support.v4.app.Fragment; import android.support.v4.view.ViewCompat; import android.support.v4.widget.SwipeRefreshLayout; -import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; @@ -78,12 +78,13 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn private String lastReadStatus; private Intent streamingFederatedIntent, streamingLocalIntent; LinearLayoutManager mLayoutManager; + private boolean liveNotifications; public DisplayStatusFragment(){ } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_status, container, false); statuses = new ArrayList<>(); knownId = new ArrayList<>(); @@ -117,6 +118,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); isOnWifi = Helper.isOnWIFI(context); + liveNotifications = sharedpreferences.getBoolean(Helper.SET_LIVE_NOTIFICATIONS, true); positionSpinnerTrans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX); swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer); behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS); @@ -433,7 +435,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn if( statuses != null && statuses.size() > 0) retrieveMissingToots(statuses.get(0).getId()); }else { - if( streamingFederatedIntent != null){ + if( streamingFederatedIntent != null && !liveNotifications){ SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedpreferences.edit(); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); @@ -454,7 +456,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn if( statuses != null && statuses.size() > 0) retrieveMissingToots(statuses.get(0).getId()); }else { - if( streamingLocalIntent != null){ + if( streamingLocalIntent != null && !liveNotifications){ SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedpreferences.edit(); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);