From 31fdbf20e98bab4ed1bad494cbcdbb5d07b6a760 Mon Sep 17 00:00:00 2001 From: stom79 Date: Sat, 11 Nov 2017 10:05:37 +0100 Subject: [PATCH] Improves service --- .../mastodon/activities/BaseMainActivity.java | 3 ++ .../fragments/DisplayStatusFragment.java | 6 +-- .../mastodon/fragments/SettingsFragment.java | 38 +++++++++++++++---- .../SettingsNotificationsFragment.java | 17 +++++++-- .../fragments/TabLayoutSettingsFragment.java | 3 +- .../gouv/etalab/mastodon/helper/Helper.java | 3 +- .../mastodon/services/StreamingService.java | 7 +++- .../res/layout-sw600dp/fragment_settings.xml | 7 +++- app/src/main/res/layout/fragment_settings.xml | 6 +++ app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values-nl/strings.xml | 1 + app/src/main/res/values-pt/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 14 files changed, 76 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java index b2eeca367..64ea5dab8 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java @@ -1464,4 +1464,7 @@ public abstract class BaseMainActivity extends AppCompatActivity return activityPaused; } + public void setstreamingIntent(Intent streamService){ + streamingIntent = streamService; + } } \ No newline at end of file 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 a484ca70a..7e18449e0 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 @@ -78,7 +78,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn private String lastReadStatus; private Intent streamingFederatedIntent, streamingLocalIntent; LinearLayoutManager mLayoutManager; - private boolean liveNotifications; public DisplayStatusFragment(){ } @@ -118,7 +117,6 @@ 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); @@ -435,7 +433,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn if( statuses != null && statuses.size() > 0) retrieveMissingToots(statuses.get(0).getId()); }else { - if( streamingFederatedIntent != null && !liveNotifications){ + if( streamingFederatedIntent != null ){ SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedpreferences.edit(); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); @@ -456,7 +454,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn if( statuses != null && statuses.size() > 0) retrieveMissingToots(statuses.get(0).getId()); }else { - if( streamingLocalIntent != null && !liveNotifications){ + if( streamingLocalIntent != null ){ SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedpreferences.edit(); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java index 642485368..8c4501566 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java @@ -16,6 +16,7 @@ package fr.gouv.etalab.mastodon.fragments; import android.annotation.SuppressLint; import android.annotation.TargetApi; +import android.support.annotation.NonNull; import android.support.v7.app.AlertDialog; import android.content.ContentUris; import android.content.Context; @@ -72,10 +73,11 @@ public class SettingsFragment extends Fragment { int count2 = 0; @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.fragment_settings, container, false); context = getContext(); + assert context != null; final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); @@ -206,7 +208,25 @@ public class SettingsFragment extends Fragment { SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putBoolean(Helper.SET_DISPLAY_LOCAL, set_display_local.isChecked()); editor.apply(); - getActivity().recreate(); + if( getActivity() != null) + getActivity().recreate(); + Intent intent = new Intent(context, MainActivity.class); + intent.putExtra(INTENT_ACTION, CHANGE_THEME_INTENT); + startActivity(intent); + } + }); + + boolean livenotif = sharedpreferences.getBoolean(Helper.SET_LIVE_NOTIFICATIONS, true); + final CheckBox set_live_notif = rootView.findViewById(R.id.set_live_notify); + set_live_notif.setChecked(livenotif); + set_live_notif.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putBoolean(Helper.SET_LIVE_NOTIFICATIONS, set_live_notif.isChecked()); + editor.apply(); + if( getActivity() != null) + getActivity().recreate(); Intent intent = new Intent(context, MainActivity.class); intent.putExtra(INTENT_ACTION, CHANGE_THEME_INTENT); startActivity(intent); @@ -224,7 +244,8 @@ public class SettingsFragment extends Fragment { SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putBoolean(Helper.SET_DISPLAY_GLOBAL, set_display_global.isChecked()); editor.apply(); - getActivity().recreate(); + if( getActivity() != null) + getActivity().recreate(); Intent intent = new Intent(context, MainActivity.class); intent.putExtra(INTENT_ACTION, CHANGE_THEME_INTENT); startActivity(intent); @@ -311,9 +332,11 @@ public class SettingsFragment extends Fragment { editor.putInt(Helper.SET_THEME, isChecked?Helper.THEME_DARK:Helper.THEME_LIGHT); editor.apply(); if( isChecked){ - getActivity().setTheme(R.style.AppThemeDark); + if( getActivity() != null) + getActivity().setTheme(R.style.AppThemeDark); }else { - getActivity().setTheme(R.style.AppTheme); + if( getActivity() != null) + getActivity().setTheme(R.style.AppTheme); } getActivity().recreate(); Intent intent = new Intent(context, MainActivity.class); @@ -450,7 +473,7 @@ public class SettingsFragment extends Fragment { }); final Spinner translation_layout_spinner = rootView.findViewById(R.id.translation_layout_spinner); - ArrayAdapter adapterTrans = ArrayAdapter.createFromResource(getActivity(), + ArrayAdapter adapterTrans = ArrayAdapter.createFromResource(getContext(), R.array.settings_translation, android.R.layout.simple_spinner_item); translation_layout_spinner.setAdapter(adapterTrans); @@ -483,7 +506,8 @@ public class SettingsFragment extends Fragment { editor.apply(); break; } - getActivity().recreate(); + if( getActivity() != null) + getActivity().recreate(); Intent intent = new Intent(context, MainActivity.class); intent.putExtra(INTENT_ACTION, CHANGE_THEME_INTENT); startActivity(intent); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsNotificationsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsNotificationsFragment.java index 9ec9a1d7d..92415b8c3 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsNotificationsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsNotificationsFragment.java @@ -16,9 +16,12 @@ package fr.gouv.etalab.mastodon.fragments; import android.app.TimePickerDialog; import android.content.Context; +import android.content.Intent; import android.content.SharedPreferences; +import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.v4.app.Fragment; import android.support.v7.widget.SwitchCompat; @@ -38,7 +41,14 @@ import android.widget.TimePicker; import android.widget.Toast; +import java.util.List; + +import fr.gouv.etalab.mastodon.activities.BaseMainActivity; +import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.helper.Helper; +import fr.gouv.etalab.mastodon.services.StreamingService; +import fr.gouv.etalab.mastodon.sqlite.AccountDAO; +import fr.gouv.etalab.mastodon.sqlite.Sqlite; import mastodon.etalab.gouv.fr.mastodon.R; import static fr.gouv.etalab.mastodon.helper.Helper.compareDate; @@ -57,10 +67,11 @@ public class SettingsNotificationsFragment extends Fragment { int count = 0; @Override - public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { + public View onCreateView(@NonNull LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_settings_notifications, container, false); context = getContext(); + assert context != null; final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); @@ -93,6 +104,7 @@ public class SettingsNotificationsFragment extends Fragment { }); + boolean notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, true); boolean notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true); boolean notif_ask = sharedpreferences.getBoolean(Helper.SET_NOTIF_ASK, true); @@ -277,8 +289,7 @@ public class SettingsNotificationsFragment extends Fragment { ledLabel.setEnabled(true); led_colour_spinner.setEnabled(true); - ArrayAdapter adapterLEDColour = ArrayAdapter.createFromResource(getActivity(), - R.array.led_colours, android.R.layout.simple_spinner_item); + ArrayAdapter adapterLEDColour = ArrayAdapter.createFromResource(getContext(), R.array.led_colours, android.R.layout.simple_spinner_item); led_colour_spinner.setAdapter(adapterLEDColour); int positionSpinnerLEDColour = (sharedpreferences.getInt(Helper.SET_LED_COLOUR, Helper.LED_COLOUR)); led_colour_spinner.setSelection(positionSpinnerLEDColour); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/TabLayoutSettingsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/TabLayoutSettingsFragment.java index a865b95b6..769f45ba0 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/TabLayoutSettingsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/TabLayoutSettingsFragment.java @@ -14,6 +14,7 @@ package fr.gouv.etalab.mastodon.fragments; * You should have received a copy of the GNU General Public License along with Mastalab; if not, * see . */ import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; @@ -35,7 +36,7 @@ public class TabLayoutSettingsFragment extends Fragment { @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View inflatedView = inflater.inflate(R.layout.tablayout_settings, container, false); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index 8c71e4c91..ffab82d35 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -215,7 +215,7 @@ public class Helper { public static final String SET_SHOW_BOOSTS = "set_show_boost"; public static final String SET_SHOW_REPLIES = "set_show_replies"; public static final String INSTANCE_VERSION = "instance_version"; - + public static final String SET_LIVE_NOTIFICATIONS = "set_show_replies"; public static final int ATTACHMENT_ALWAYS = 1; public static final int ATTACHMENT_WIFI = 2; @@ -229,7 +229,6 @@ public class Helper { public static final int TRANS_NONE = 2; public static final String SET_TRANS_FORCED = "set_trans_forced"; - public static final String SET_LIVE_NOTIFICATIONS = "set_live_notifications"; public static final String SET_NOTIFY = "set_notify"; public static final String SET_NOTIF_FOLLOW = "set_notif_follow"; public static final String SET_NOTIF_ADD = "set_notif_follow_add"; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/services/StreamingService.java b/app/src/main/java/fr/gouv/etalab/mastodon/services/StreamingService.java index e046e3122..f263c6220 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/services/StreamingService.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/services/StreamingService.java @@ -25,6 +25,7 @@ import android.os.IBinder; import android.os.SystemClock; import android.support.annotation.Nullable; import android.support.v4.content.LocalBroadcastManager; +import android.util.Log; import android.view.View; @@ -150,6 +151,7 @@ public class StreamingService extends Service { BufferedReader reader = null; try { httpsURLConnections.get(accountStream.getAcct() + accountStream.getInstance()).disconnect(); + Log.v(Helper.TAG,accountStream.getAcct() + " - streamOnUser: " + httpsURLConnections.get(accountStream.getAcct() + accountStream.getInstance()).getInputStream()); }catch (Exception ignored){} SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); if( accountStream != null){ @@ -171,8 +173,11 @@ public class StreamingService extends Service { String event; EventStreaming eventStreaming; while((event = reader.readLine()) != null) { - if( !sharedpreferences.getBoolean(Helper.SHOULD_CONTINUE_STREAMING + accountStream.getId(), true) ) + Log.v(Helper.TAG,accountStream.getAcct() + " - continue: " + sharedpreferences.getBoolean(Helper.SHOULD_CONTINUE_STREAMING + accountStream.getId(), true) ); + if( !sharedpreferences.getBoolean(Helper.SHOULD_CONTINUE_STREAMING + accountStream.getId(), true) ) { stopSelf(); + return; + } if ((lastEvent == EventStreaming.NONE || lastEvent == null) && !event.startsWith("data: ")) { switch (event.trim()) { case "event: update": diff --git a/app/src/main/res/layout-sw600dp/fragment_settings.xml b/app/src/main/res/layout-sw600dp/fragment_settings.xml index 3a6239f72..0811afc73 100644 --- a/app/src/main/res/layout-sw600dp/fragment_settings.xml +++ b/app/src/main/res/layout-sw600dp/fragment_settings.xml @@ -112,7 +112,12 @@ android:text="@string/set_display_global" android:layout_height="wrap_content" /> - + + + + Das Profil wird möglicherweise unvollständig wiedergegeben. Emoji einfügen The app did not collect custom emojis for the moment. + Live notifications diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 09f4891e3..18e1c50c8 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -438,4 +438,5 @@ Les données ci-dessous peuvent ne pas refléter ce profil dans sa totalité. Insérer un émoji L\'application n\'a pas encore collecté d\'emojis personnalisés + Notifications en direct diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index b6c07548c..b05cc4e6c 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -435,4 +435,5 @@ De informatie hieronder kan mogelijk een incompleet beeld geven van dit gebruikersprofiel. Emoji toevoegen The app did not collect custom emojis for the moment. + Live notifications diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index cad77dcb3..e11342d3f 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -437,4 +437,5 @@ Information below may reflect the user\'s profile incompletely. Inserir Emoji The app did not collect custom emojis for the moment. + Live notifications diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d236ca297..6fc0e1ff9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -96,6 +96,7 @@ Information below may reflect the user\'s profile incompletely. Insert emoji The app did not collect custom emojis for the moment. + Live notifications No toot to display The toot was added to favourites