Improves service

This commit is contained in:
stom79 2017-11-11 10:05:37 +01:00
parent 542b677d65
commit 31fdbf20e9
14 changed files with 76 additions and 19 deletions

View File

@ -1464,4 +1464,7 @@ public abstract class BaseMainActivity extends AppCompatActivity
return activityPaused;
}
public void setstreamingIntent(Intent streamService){
streamingIntent = streamService;
}
}

View File

@ -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);

View File

@ -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<CharSequence> adapterTrans = ArrayAdapter.createFromResource(getActivity(),
ArrayAdapter<CharSequence> 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);

View File

@ -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<CharSequence> adapterLEDColour = ArrayAdapter.createFromResource(getActivity(),
R.array.led_colours, android.R.layout.simple_spinner_item);
ArrayAdapter<CharSequence> 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);

View File

@ -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 <http://www.gnu.org/licenses>. */
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);

View File

@ -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";

View File

@ -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":

View File

@ -112,7 +112,12 @@
android:text="@string/set_display_global"
android:layout_height="wrap_content" />
<!-- LIVE NOTIFICATIONS SETTINGS -->
<CheckBox
android:id="@+id/set_live_notify"
android:layout_width="wrap_content"
android:text="@string/live_notif"
android:layout_height="wrap_content" />
<!-- TABS Layout -->
<LinearLayout

View File

@ -113,6 +113,12 @@
android:layout_height="wrap_content" />
<!-- LIVE NOTIFICATIONS SETTINGS -->
<CheckBox
android:id="@+id/set_live_notify"
android:layout_width="wrap_content"
android:text="@string/live_notif"
android:layout_height="wrap_content" />
<!-- Translation engine -->
<LinearLayout

View File

@ -431,4 +431,5 @@
<string name="disclaimer_full">Das Profil wird möglicherweise unvollständig wiedergegeben.</string>
<string name="insert_emoji">Emoji einfügen</string>
<string name="no_emoji">The app did not collect custom emojis for the moment.</string>
<string name="live_notif">Live notifications</string>
</resources>

View File

@ -438,4 +438,5 @@
<string name="disclaimer_full">Les données ci-dessous peuvent ne pas refléter ce profil dans sa totalité.</string>
<string name="insert_emoji">Insérer un émoji</string>
<string name="no_emoji">L\'application n\'a pas encore collecté d\'emojis personnalisés</string>
<string name="live_notif">Notifications en direct</string>
</resources>

View File

@ -435,4 +435,5 @@
<string name="disclaimer_full">De informatie hieronder kan mogelijk een incompleet beeld geven van dit gebruikersprofiel.</string>
<string name="insert_emoji">Emoji toevoegen</string>
<string name="no_emoji">The app did not collect custom emojis for the moment.</string>
<string name="live_notif">Live notifications</string>
</resources>

View File

@ -437,4 +437,5 @@
<string name="disclaimer_full">Information below may reflect the user\'s profile incompletely.</string>
<string name="insert_emoji">Inserir Emoji</string>
<string name="no_emoji">The app did not collect custom emojis for the moment.</string>
<string name="live_notif">Live notifications</string>
</resources>

View File

@ -96,6 +96,7 @@
<string name="disclaimer_full">Information below may reflect the user\'s profile incompletely.</string>
<string name="insert_emoji">Insert emoji</string>
<string name="no_emoji">The app did not collect custom emojis for the moment.</string>
<string name="live_notif">Live notifications</string>
<!-- Status -->
<string name="no_status">No toot to display</string>
<string name="fav_added">The toot was added to favourites</string>