Fix settings for the lite version

This commit is contained in:
Thomas 2021-10-24 18:22:53 +02:00
parent d554244413
commit 6f1f63854d
3 changed files with 26 additions and 150 deletions

View File

@ -14,6 +14,7 @@
* see <http://www.gnu.org/licenses>. */
package app.fedilab.android.activities;
import android.annotation.SuppressLint;
import android.app.NotificationManager;
import android.content.Intent;
import android.content.SharedPreferences;
@ -44,21 +45,16 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.SwitchCompat;
import androidx.core.content.ContextCompat;
import java.util.Locale;
import app.fedilab.android.R;
import app.fedilab.android.client.Entities.Account;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.jobs.ApplicationJob;
import app.fedilab.android.jobs.NotificationsSyncJob;
import app.fedilab.android.services.LiveNotificationDelayedService;
import app.fedilab.android.services.LiveNotificationService;
import app.fedilab.android.services.StopDelayedNotificationReceiver;
import app.fedilab.android.services.StopLiveNotificationReceiver;
import app.fedilab.android.helper.PushHelper;
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
@ -357,123 +353,61 @@ public class SettingsActivity extends BaseActivity {
final SwitchCompat switchCompatNotify = findViewById(R.id.set_notify);
switchCompatNotify.setChecked(notify);
switchCompatNotify.setOnCheckedChangeListener((buttonView, isChecked) -> {
// Save the state here
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_NOTIFY, isChecked);
editor.apply();
if (isChecked) {
startStreaming(SettingsActivity.this);
/*if (isChecked) {
notification_container.setVisibility(View.VISIBLE);
} else {
sendBroadcast(new Intent(getApplicationContext(), StopLiveNotificationReceiver.class));
if (Build.VERSION.SDK_INT >= 26) {
NotificationManager notif = ((NotificationManager) getSystemService(NOTIFICATION_SERVICE));
if (notif != null) {
notif.deleteNotificationChannel(LiveNotificationDelayedService.CHANNEL_ID);
}
}
}
notification_container.setVisibility(View.GONE);
}*/
PushHelper.startStreaming(SettingsActivity.this);
});
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getApplicationContext()));
final Account account = new AccountDAO(getApplicationContext(), db).getUniqAccount(userId, instance);
boolean allow_live_notifications = sharedpreferences.getBoolean(Helper.SET_ALLOW_STREAM + userId + instance, true);
TextView set_allow_live_notifications_title = findViewById(R.id.set_allow_live_notifications_title);
set_allow_live_notifications_title.setText(getString(R.string.set_allow_live_notifications, account.getAcct() + "@" + account.getInstance()));
final SwitchCompat set_allow_live_notifications = findViewById(R.id.set_allow_live_notifications);
set_allow_live_notifications.setChecked(allow_live_notifications);
set_allow_live_notifications.setOnClickListener(v -> {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_ALLOW_STREAM + userId + instance, set_allow_live_notifications.isChecked());
editor.apply();
if (set_allow_live_notifications.isChecked()) {
LiveNotificationDelayedService.totalAccount++;
} else {
LiveNotificationDelayedService.totalAccount--;
}
if (set_allow_live_notifications.isChecked()) {
LiveNotificationDelayedService.totalAccount++;
} else {
LiveNotificationDelayedService.totalAccount--;
}
startStreaming(SettingsActivity.this);
});
final ImageButton set_allow_live_notifications_others = findViewById(R.id.set_allow_live_notifications_others);
set_allow_live_notifications_others.setOnClickListener(view -> {
Intent intent = new Intent(SettingsActivity.this, LiveNotificationSettingsAccountsActivity.class);
startActivity(intent);
});
//Live notification mode
final Spinner set_live_type = findViewById(R.id.set_live_type);
String[] labels = {getString(R.string.live_notif), getString(R.string.live_delayed), getString(R.string.no_live_notif)};
ArrayAdapter<String> adapterLive = new ArrayAdapter<>(SettingsActivity.this,
android.R.layout.simple_spinner_dropdown_item, labels);
LinearLayout live_notif_per_account = findViewById(R.id.live_notif_per_account);
set_live_type.setAdapter(adapterLive);
if (Helper.liveNotifType(SettingsActivity.this) == Helper.NOTIF_NONE) {
live_notif_per_account.setVisibility(View.GONE);
}
TextView set_live_type_indication = findViewById(R.id.set_live_type_indication);
switch (Helper.liveNotifType(SettingsActivity.this)) {
case Helper.NOTIF_LIVE:
set_live_type_indication.setText(R.string.live_notif_indication);
break;
case Helper.NOTIF_DELAYED:
set_live_type_indication.setText(R.string.set_live_type_indication);
break;
case Helper.NOTIF_NONE:
set_live_type_indication.setText(R.string.no_live_indication);
break;
if (Helper.liveNotifType(SettingsActivity.this) == Helper.NOTIF_NONE) {
set_live_type_indication.setText(R.string.no_live_indication);
} else {
set_live_type_indication.setText(R.string.set_push_notifications);
}
set_live_type.setSelection(Helper.liveNotifType(SettingsActivity.this));
liveNotificationCount = 0;
set_live_type.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@SuppressLint("ApplySharedPref")
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (liveNotificationCount > 0) {
SharedPreferences.Editor editor = sharedpreferences.edit();
sendBroadcast(new Intent(SettingsActivity.this, StopLiveNotificationReceiver.class));
sendBroadcast(new Intent(SettingsActivity.this, StopDelayedNotificationReceiver.class));
ApplicationJob.cancelAllJob(NotificationsSyncJob.NOTIFICATION_REFRESH);
switch (position) {
case Helper.NOTIF_LIVE:
editor.putBoolean(Helper.SET_LIVE_NOTIFICATIONS, true);
editor.putBoolean(Helper.SET_DELAYED_NOTIFICATIONS, false);
live_notif_per_account.setVisibility(View.VISIBLE);
case Helper.NOTIF_PUSH:
editor.putBoolean(Helper.SET_PUSH_NOTIFICATIONS, true);
editor.commit();
set_live_type_indication.setText(R.string.live_notif_indication);
Handler handler = new Handler();
handler.postDelayed(() -> {
startStreaming(SettingsActivity.this);
}, 1000);
break;
case Helper.NOTIF_DELAYED:
editor.putBoolean(Helper.SET_LIVE_NOTIFICATIONS, false);
editor.putBoolean(Helper.SET_DELAYED_NOTIFICATIONS, true);
live_notif_per_account.setVisibility(View.VISIBLE);
set_live_type_indication.setText(R.string.set_live_type_indication);
editor.commit();
handler = new Handler();
handler.postDelayed(() -> {
startStreaming(SettingsActivity.this);
}, 1000);
set_live_type_indication.setText(R.string.set_push_notifications);
break;
case Helper.NOTIF_NONE:
editor.putBoolean(Helper.SET_LIVE_NOTIFICATIONS, false);
editor.putBoolean(Helper.SET_DELAYED_NOTIFICATIONS, false);
editor.putBoolean(Helper.SET_PUSH_NOTIFICATIONS, false);
editor.commit();
set_live_type_indication.setText(R.string.no_live_indication);
live_notif_per_account.setVisibility(View.GONE);
NotificationsSyncJob.schedule(false);
break;
}
PushHelper.startStreaming(SettingsActivity.this);
} else {
liveNotificationCount++;
}
@ -485,6 +419,7 @@ public class SettingsActivity extends BaseActivity {
}
});
boolean clear_cache_exit = sharedpreferences.getBoolean(Helper.SET_CLEAR_CACHE_EXIT, false);
final SwitchCompat set_clear_cache_exit = findViewById(R.id.set_clear_cache_exit);
set_clear_cache_exit.setChecked(clear_cache_exit);

View File

@ -380,60 +380,6 @@
android:layout_marginBottom="@dimen/settings_option_margin"
android:textColor="@color/mastodonC2" />
<LinearLayout
android:id="@+id/live_notif_per_account"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/settings_option_margin"
android:layout_marginBottom="@dimen/settings_option_margin"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/set_allow_live_notifications_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/set_allow_live_notifications"
android:textSize="16sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/set_allow_live_notifications_indication"
android:textColor="@color/mastodonC2"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/set_allow_live_notifications"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageButton
android:id="@+id/set_allow_live_notifications_others"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="end"
android:contentDescription="@string/live_notif"
android:padding="5dp"
android:src="@drawable/ic_account_circle_acct" />
</LinearLayout>
</LinearLayout>
<!-- TRUNCATE LONG TOOTS -->
<TextView

View File

@ -53,13 +53,8 @@
android:usesCleartextTraffic="true"
tools:replace="android:allowBackup">
<service
android:name="app.fedilab.android.services.LiveNotificationDelayedService"
android:exported="false" />
<service
android:name="app.fedilab.android.services.LiveNotificationService"
android:exported="false" />
<service
<service
android:name="app.fedilab.android.services.BackupStatusService"
android:exported="false" />
<service