Some fixes

This commit is contained in:
Thomas 2020-08-10 16:45:28 +02:00
parent 1fb093b30a
commit abf6953beb
7 changed files with 28 additions and 40 deletions

View File

@ -21,6 +21,7 @@ import android.database.sqlite.SQLiteDatabase;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
@ -56,6 +57,8 @@ import app.fedilab.android.sqlite.AccountDAO;
import app.fedilab.android.sqlite.Sqlite;
import es.dmoral.toasty.Toasty;
import static app.fedilab.android.helper.BaseHelper.startStreaming;
/**
* Created by Thomas on 01/07/2019.
* Settings activity
@ -332,19 +335,7 @@ public class SettingsActivity extends BaseActivity {
editor.putBoolean(Helper.SET_NOTIFY, isChecked);
editor.apply();
if (isChecked) {
try {
switch (Helper.liveNotifType(getApplicationContext())) {
case Helper.NOTIF_LIVE:
Intent streamingIntent = new Intent(getApplicationContext(), LiveNotificationService.class);
startService(streamingIntent);
break;
case Helper.NOTIF_DELAYED:
streamingIntent = new Intent(getApplicationContext(), LiveNotificationDelayedService.class);
startService(streamingIntent);
break;
}
} catch (Exception ignored) {
}
startStreaming(SettingsActivity.this);
} else {
sendBroadcast(new Intent(getApplicationContext(), StopLiveNotificationReceiver.class));
if (Build.VERSION.SDK_INT >= 26) {
@ -380,7 +371,7 @@ public class SettingsActivity extends BaseActivity {
} else {
LiveNotificationDelayedService.totalAccount--;
}
Helper.startStreaming(SettingsActivity.this);
startStreaming(SettingsActivity.this);
});
final ImageButton set_allow_live_notifications_others = findViewById(R.id.set_allow_live_notifications_others);
@ -430,7 +421,10 @@ public class SettingsActivity extends BaseActivity {
live_notif_per_account.setVisibility(View.VISIBLE);
editor.commit();
set_live_type_indication.setText(R.string.live_notif_indication);
Helper.startStreaming(SettingsActivity.this);
Handler handler = new Handler();
handler.postDelayed(() -> {
startStreaming(SettingsActivity.this);
}, 1000);
break;
case Helper.NOTIF_DELAYED:
editor.putBoolean(Helper.SET_LIVE_NOTIFICATIONS, false);
@ -438,7 +432,10 @@ public class SettingsActivity extends BaseActivity {
live_notif_per_account.setVisibility(View.VISIBLE);
set_live_type_indication.setText(R.string.set_live_type_indication);
editor.commit();
Helper.startStreaming(SettingsActivity.this);
handler = new Handler();
handler.postDelayed(() -> {
startStreaming(SettingsActivity.this);
}, 1000);
break;
case Helper.NOTIF_NONE:
editor.putBoolean(Helper.SET_LIVE_NOTIFICATIONS, false);

View File

@ -150,8 +150,6 @@ import app.fedilab.android.interfaces.OnRetrieveRemoteAccountInterface;
import app.fedilab.android.interfaces.OnSyncTimelineInterface;
import app.fedilab.android.interfaces.OnUpdateAccountInfoInterface;
import app.fedilab.android.services.BackupStatusService;
import app.fedilab.android.services.LiveNotificationDelayedService;
import app.fedilab.android.services.LiveNotificationService;
import app.fedilab.android.sqlite.AccountDAO;
import app.fedilab.android.sqlite.Sqlite;
import app.fedilab.android.sqlite.TempMuteDAO;
@ -161,6 +159,7 @@ import es.dmoral.toasty.Toasty;
import static app.fedilab.android.activities.WebviewActivity.trackingDomains;
import static app.fedilab.android.asynctasks.ManageFiltersAsyncTask.action.GET_ALL_FILTER;
import static app.fedilab.android.helper.BaseHelper.startStreaming;
import static app.fedilab.android.helper.Helper.changeDrawableColor;
@ -1211,15 +1210,13 @@ public abstract class BaseMainActivity extends BaseActivity
editor.putBoolean(Helper.SET_LIVE_NOTIFICATIONS, true);
editor.putBoolean(Helper.SET_DELAYED_NOTIFICATIONS, false);
editor.apply();
Intent streamingIntent = new Intent(BaseMainActivity.this, LiveNotificationService.class);
startService(streamingIntent);
startStreaming(BaseMainActivity.this);
break;
case Helper.NOTIF_DELAYED:
editor.putBoolean(Helper.SET_LIVE_NOTIFICATIONS, false);
editor.putBoolean(Helper.SET_DELAYED_NOTIFICATIONS, true);
streamingIntent = new Intent(BaseMainActivity.this, LiveNotificationDelayedService.class);
startService(streamingIntent);
editor.apply();
startStreaming(BaseMainActivity.this);
break;
case Helper.NOTIF_NONE:
editor.putBoolean(Helper.SET_LIVE_NOTIFICATIONS, false);

View File

@ -4340,11 +4340,12 @@ public class BaseHelper {
if (streamingIntent != null) {
try {
if (Build.VERSION.SDK_INT >= 26) {
context.startService(streamingIntent);
context.startForegroundService(streamingIntent);
} else {
context.startService(streamingIntent);
}
} catch (Exception ignored) {
context.startService(streamingIntent);
}
}
}

View File

@ -91,7 +91,6 @@ public class LiveNotificationDelayedService extends Service {
super.onCreate();
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true);
if (Build.VERSION.SDK_INT >= 26) {
channel = new NotificationChannel(CHANNEL_ID,
"Live notifications",
@ -261,7 +260,8 @@ public class LiveNotificationDelayedService extends Service {
gnuApi = new GNUAPI(LiveNotificationDelayedService.this, account.getInstance(), account.getToken());
apiResponse = gnuApi.getNotificationsSince(DisplayNotificationsFragment.Type.ALL, last_notifid);
}
} catch (Exception ignored) {
} catch (Exception e) {
e.printStackTrace();
}
if (apiResponse != null && apiResponse.getNotifications() != null && apiResponse.getNotifications().size() > 0) {
@ -490,7 +490,8 @@ public class LiveNotificationDelayedService extends Service {
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), notification.getId());
editor.apply();
}
} catch (Exception ignored) {
} catch (Exception e) {
e.printStackTrace();
}
}

View File

@ -18,10 +18,11 @@ import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.jobs.NotificationsSyncJob;
import static app.fedilab.android.helper.BaseHelper.startStreaming;
/**
* Created by Thomas on 22/09/2017.
* BroadcastReceiver for restarting the service
@ -34,21 +35,10 @@ public class RestartLiveNotificationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
int type = Helper.liveNotifType(context);
if (type == Helper.NOTIF_DELAYED) {
Intent streamingServiceIntent = new Intent(context, LiveNotificationDelayedService.class);
try {
context.startService(streamingServiceIntent);
} catch (Exception ignored) {
}
} else if (type == Helper.NOTIF_LIVE) {
Intent streamingServiceIntent = new Intent(context, LiveNotificationService.class);
try {
context.startService(streamingServiceIntent);
} catch (Exception ignored) {
}
if (type == Helper.NOTIF_DELAYED || type == Helper.NOTIF_LIVE) {
startStreaming(context);
} else {
NotificationsSyncJob.schedule(false);
}
}
}

View File

@ -20,6 +20,7 @@ import android.content.Context;
import android.content.Intent;
/**
* Created by Thomas on 22/09/2017.
* BroadcastReceiver for restarting the service

View File

@ -19,6 +19,7 @@ import android.content.Context;
import android.content.Intent;
public class UpgradeReceiver extends BroadcastReceiver {
@Override