Add bibliogram support for the lite version

This commit is contained in:
Thomas 2020-07-15 14:58:27 +02:00
parent 03cad20b28
commit f22c5b98d1
6 changed files with 323 additions and 318 deletions

View File

@ -15,10 +15,10 @@
package app.fedilab.android.activities; package app.fedilab.android.activities;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.graphics.drawable.ColorDrawable;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
@ -27,34 +27,33 @@ import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.SwitchCompat; import androidx.appcompat.widget.SwitchCompat;
import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat;
import com.jaredrummler.materialspinner.MaterialSpinner; import app.fedilab.android.R;
import app.fedilab.android.client.Entities.Account;
import app.fedilab.lite.R; import app.fedilab.android.helper.Helper;
import app.fedilab.lite.client.Entities.Account; import app.fedilab.android.jobs.ApplicationJob;
import app.fedilab.lite.helper.Helper; import app.fedilab.android.jobs.NotificationsSyncJob;
import app.fedilab.lite.jobs.ApplicationJob; import app.fedilab.android.services.LiveNotificationDelayedService;
import app.fedilab.lite.jobs.NotificationsSyncJob; import app.fedilab.android.services.LiveNotificationService;
import app.fedilab.lite.services.LiveNotificationDelayedService; import app.fedilab.android.services.StopDelayedNotificationReceiver;
import app.fedilab.lite.services.LiveNotificationService; import app.fedilab.android.services.StopLiveNotificationReceiver;
import app.fedilab.lite.services.StopDelayedNotificationReceiver; import app.fedilab.android.sqlite.AccountDAO;
import app.fedilab.lite.services.StopLiveNotificationReceiver; import app.fedilab.android.sqlite.Sqlite;
import app.fedilab.lite.sqlite.AccountDAO;
import app.fedilab.lite.sqlite.Sqlite;
import es.dmoral.toasty.Toasty; import es.dmoral.toasty.Toasty;
/** /**
@ -66,9 +65,11 @@ public class SettingsActivity extends BaseActivity {
private int count1, count2, count3, count4, count5;
private int style; private int style;
protected int res; protected int res;
private int liveNotificationCount;
public static boolean needRestart;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -79,43 +80,30 @@ public class SettingsActivity extends BaseActivity {
case Helper.THEME_LIGHT: case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme); setTheme(R.style.AppTheme);
break; break;
case Helper.THEME_DARK:
setTheme(R.style.AppThemeDark);
break;
case Helper.THEME_BLACK: case Helper.THEME_BLACK:
setTheme(R.style.AppThemeBlack); setTheme(R.style.AppThemeBlack);
break; break;
default: default:
setTheme(R.style.AppThemeDark); setTheme(R.style.AppThemeDark);
} }
needRestart = false;
if (getSupportActionBar() != null) if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar(); ActionBar actionBar = getSupportActionBar();
if (actionBar != null) { if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null; assert inflater != null;
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false); View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(SettingsActivity.this), false);
view.setBackground(new ColorDrawable(ContextCompat.getColor(SettingsActivity.this, R.color.cyanea_primary)));
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close); ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title); TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title);
toolbar_close.setOnClickListener(new View.OnClickListener() { toolbar_close.setOnClickListener(v -> finish());
@Override
public void onClick(View v) {
finish();
}
});
toolbar_title.setText(R.string.settings); toolbar_title.setText(R.string.settings);
if (theme == Helper.THEME_LIGHT) {
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
Helper.colorizeToolbar(toolbar, R.color.black, SettingsActivity.this);
}
} }
setContentView(R.layout.activity_settings); setContentView(R.layout.activity_settings);
if (theme == Helper.THEME_DARK) { if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark; style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK) { } else if (theme == Helper.THEME_BLACK) {
@ -128,39 +116,30 @@ public class SettingsActivity extends BaseActivity {
boolean display_content_after_fetch_more = sharedpreferences.getBoolean(Helper.SET_DISPLAY_CONTENT_AFTER_FM, true); boolean display_content_after_fetch_more = sharedpreferences.getBoolean(Helper.SET_DISPLAY_CONTENT_AFTER_FM, true);
final SwitchCompat set_display_content_after_fetch_more = findViewById(R.id.set_display_content_after_fetch_more); final SwitchCompat set_display_content_after_fetch_more = findViewById(R.id.set_display_content_after_fetch_more);
set_display_content_after_fetch_more.setChecked(display_content_after_fetch_more); set_display_content_after_fetch_more.setChecked(display_content_after_fetch_more);
set_display_content_after_fetch_more.setOnClickListener(new View.OnClickListener() { set_display_content_after_fetch_more.setOnClickListener(v -> {
@Override SharedPreferences.Editor editor = sharedpreferences.edit();
public void onClick(View v) { editor.putBoolean(Helper.SET_DISPLAY_CONTENT_AFTER_FM, set_display_content_after_fetch_more.isChecked());
SharedPreferences.Editor editor = sharedpreferences.edit(); editor.apply();
editor.putBoolean(Helper.SET_DISPLAY_CONTENT_AFTER_FM, set_display_content_after_fetch_more.isChecked());
editor.apply();
}
}); });
boolean notif_validation = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION, false); boolean notif_validation = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION, false);
final SwitchCompat set_share_validation = findViewById(R.id.set_share_validation); final SwitchCompat set_share_validation = findViewById(R.id.set_share_validation);
set_share_validation.setChecked(notif_validation); set_share_validation.setChecked(notif_validation);
set_share_validation.setOnClickListener(new View.OnClickListener() { set_share_validation.setOnClickListener(v -> {
@Override SharedPreferences.Editor editor = sharedpreferences.edit();
public void onClick(View v) { editor.putBoolean(Helper.SET_NOTIF_VALIDATION, set_share_validation.isChecked());
SharedPreferences.Editor editor = sharedpreferences.edit(); editor.apply();
editor.putBoolean(Helper.SET_NOTIF_VALIDATION, set_share_validation.isChecked());
editor.apply();
}
}); });
boolean notif_validation_fav = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION_FAV, false); boolean notif_validation_fav = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION_FAV, false);
final SwitchCompat set_share_validation_fav = findViewById(R.id.set_share_validation_fav); final SwitchCompat set_share_validation_fav = findViewById(R.id.set_share_validation_fav);
set_share_validation_fav.setChecked(notif_validation_fav); set_share_validation_fav.setChecked(notif_validation_fav);
set_share_validation_fav.setOnClickListener(new View.OnClickListener() { set_share_validation_fav.setOnClickListener(v -> {
@Override SharedPreferences.Editor editor = sharedpreferences.edit();
public void onClick(View v) { editor.putBoolean(Helper.SET_NOTIF_VALIDATION_FAV, set_share_validation_fav.isChecked());
SharedPreferences.Editor editor = sharedpreferences.edit(); editor.apply();
editor.putBoolean(Helper.SET_NOTIF_VALIDATION_FAV, set_share_validation_fav.isChecked());
editor.apply();
}
}); });
EditText set_invidious_host = findViewById(R.id.set_invidious_host); EditText set_invidious_host = findViewById(R.id.set_invidious_host);
@ -220,30 +199,55 @@ public class SettingsActivity extends BaseActivity {
}); });
TextView set_bibliogram_host = findViewById(R.id.set_bibliogram_host);
String bibliogramHost = sharedpreferences.getString(Helper.SET_BIBLIOGRAM_HOST, null);
if (bibliogramHost != null) {
set_bibliogram_host.setText(bibliogramHost);
}
set_bibliogram_host.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
SharedPreferences.Editor editor = sharedpreferences.edit();
if (s.toString().trim().length() > 0) {
editor.putString(Helper.SET_BIBLIOGRAM_HOST, s.toString().toLowerCase().trim());
} else {
editor.putString(Helper.SET_BIBLIOGRAM_HOST, null);
}
editor.apply();
}
});
boolean expand_cw = sharedpreferences.getBoolean(Helper.SET_EXPAND_CW, false); boolean expand_cw = sharedpreferences.getBoolean(Helper.SET_EXPAND_CW, false);
final SwitchCompat set_expand_cw = findViewById(R.id.set_expand_cw); final SwitchCompat set_expand_cw = findViewById(R.id.set_expand_cw);
set_expand_cw.setChecked(expand_cw); set_expand_cw.setChecked(expand_cw);
set_expand_cw.setOnClickListener(new View.OnClickListener() { set_expand_cw.setOnClickListener(v -> {
@Override SharedPreferences.Editor editor = sharedpreferences.edit();
public void onClick(View v) { editor.putBoolean(Helper.SET_EXPAND_CW, set_expand_cw.isChecked());
SharedPreferences.Editor editor = sharedpreferences.edit(); editor.apply();
editor.putBoolean(Helper.SET_EXPAND_CW, set_expand_cw.isChecked());
editor.apply();
}
}); });
boolean expand_media = sharedpreferences.getBoolean(Helper.SET_EXPAND_MEDIA, false); boolean expand_media = sharedpreferences.getBoolean(Helper.SET_EXPAND_MEDIA, false);
final SwitchCompat set_expand_media = findViewById(R.id.set_expand_image); final SwitchCompat set_expand_media = findViewById(R.id.set_expand_image);
set_expand_media.setChecked(expand_media); set_expand_media.setChecked(expand_media);
set_expand_media.setOnClickListener(new View.OnClickListener() { set_expand_media.setOnClickListener(v -> {
@Override SharedPreferences.Editor editor = sharedpreferences.edit();
public void onClick(View v) { editor.putBoolean(Helper.SET_EXPAND_MEDIA, set_expand_media.isChecked());
SharedPreferences.Editor editor = sharedpreferences.edit(); editor.apply();
editor.putBoolean(Helper.SET_EXPAND_MEDIA, set_expand_media.isChecked());
editor.apply();
}
}); });
@ -276,129 +280,87 @@ public class SettingsActivity extends BaseActivity {
final SwitchCompat set_quick_reply = findViewById(R.id.set_quick_reply); final SwitchCompat set_quick_reply = findViewById(R.id.set_quick_reply);
set_quick_reply.setChecked(quick_reply); set_quick_reply.setChecked(quick_reply);
set_quick_reply.setOnClickListener(new View.OnClickListener() { set_quick_reply.setOnClickListener(v -> {
@Override SharedPreferences.Editor editor = sharedpreferences.edit();
public void onClick(View v) { editor.putBoolean(Helper.SET_QUICK_REPLY, set_quick_reply.isChecked());
SharedPreferences.Editor editor = sharedpreferences.edit(); editor.apply();
editor.putBoolean(Helper.SET_QUICK_REPLY, set_quick_reply.isChecked());
editor.apply();
}
}); });
boolean fit_preview = sharedpreferences.getBoolean(Helper.SET_FULL_PREVIEW, false); boolean fit_preview = sharedpreferences.getBoolean(Helper.SET_FULL_PREVIEW, false);
final SwitchCompat set_fit_preview = findViewById(R.id.set_fit_preview); final SwitchCompat set_fit_preview = findViewById(R.id.set_fit_preview);
set_fit_preview.setChecked(fit_preview); set_fit_preview.setChecked(fit_preview);
set_fit_preview.setOnClickListener(new View.OnClickListener() { set_fit_preview.setOnClickListener(v -> {
@Override SharedPreferences.Editor editor = sharedpreferences.edit();
public void onClick(View v) { editor.putBoolean(Helper.SET_FULL_PREVIEW, set_fit_preview.isChecked());
SharedPreferences.Editor editor = sharedpreferences.edit(); editor.apply();
editor.putBoolean(Helper.SET_FULL_PREVIEW, set_fit_preview.isChecked());
editor.apply();
}
}); });
boolean disableGif = sharedpreferences.getBoolean(Helper.SET_DISABLE_GIF, false); boolean disableGif = sharedpreferences.getBoolean(Helper.SET_DISABLE_GIF, false);
final SwitchCompat set_disable_gif = findViewById(R.id.set_disable_gif); final SwitchCompat set_disable_gif = findViewById(R.id.set_disable_gif);
set_disable_gif.setChecked(disableGif); set_disable_gif.setChecked(disableGif);
set_disable_gif.setOnClickListener(new View.OnClickListener() { set_disable_gif.setOnClickListener(v -> {
@Override SharedPreferences.Editor editor = sharedpreferences.edit();
public void onClick(View v) { editor.putBoolean(Helper.SET_DISABLE_GIF, set_disable_gif.isChecked());
SharedPreferences.Editor editor = sharedpreferences.edit(); editor.apply();
editor.putBoolean(Helper.SET_DISABLE_GIF, set_disable_gif.isChecked()); recreate();
editor.apply();
recreate();
}
}); });
boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false); boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false);
final SwitchCompat set_disable_animated_emoji = findViewById(R.id.set_disable_animated_emoji); final SwitchCompat set_disable_animated_emoji = findViewById(R.id.set_disable_animated_emoji);
set_disable_animated_emoji.setChecked(disableAnimatedEmoji); set_disable_animated_emoji.setChecked(disableAnimatedEmoji);
set_disable_animated_emoji.setOnClickListener(new View.OnClickListener() { set_disable_animated_emoji.setOnClickListener(v -> {
@Override SharedPreferences.Editor editor = sharedpreferences.edit();
public void onClick(View v) { editor.putBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, set_disable_animated_emoji.isChecked());
SharedPreferences.Editor editor = sharedpreferences.edit(); editor.apply();
editor.putBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, set_disable_animated_emoji.isChecked());
editor.apply();
}
}); });
boolean display_card = sharedpreferences.getBoolean(Helper.SET_DISPLAY_CARD, false); boolean display_card = sharedpreferences.getBoolean(Helper.SET_DISPLAY_CARD, false);
final SwitchCompat set_display_card = findViewById(R.id.set_display_card); final SwitchCompat set_display_card = findViewById(R.id.set_display_card);
set_display_card.setChecked(display_card); set_display_card.setChecked(display_card);
set_display_card.setOnClickListener(new View.OnClickListener() { set_display_card.setOnClickListener(v -> {
@Override SharedPreferences.Editor editor = sharedpreferences.edit();
public void onClick(View v) { editor.putBoolean(Helper.SET_DISPLAY_CARD, set_display_card.isChecked());
SharedPreferences.Editor editor = sharedpreferences.edit(); editor.apply();
editor.putBoolean(Helper.SET_DISPLAY_CARD, set_display_card.isChecked());
editor.apply();
}
}); });
boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true); boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true);
final SwitchCompat switchCompatNotify = findViewById(R.id.set_notify); final SwitchCompat switchCompatNotify = findViewById(R.id.set_notify);
switchCompatNotify.setChecked(notify); switchCompatNotify.setChecked(notify);
switchCompatNotify.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { switchCompatNotify.setOnCheckedChangeListener((buttonView, isChecked) -> {
@Override // Save the state here
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { SharedPreferences.Editor editor = sharedpreferences.edit();
// Save the state here editor.putBoolean(Helper.SET_NOTIFY, isChecked);
SharedPreferences.Editor editor = sharedpreferences.edit(); editor.apply();
editor.putBoolean(Helper.SET_NOTIFY, isChecked); if (isChecked) {
editor.apply(); try {
if (isChecked) { switch (Helper.liveNotifType(getApplicationContext())) {
try { case Helper.NOTIF_LIVE:
switch (Helper.liveNotifType(getApplicationContext())) { Intent streamingIntent = new Intent(getApplicationContext(), LiveNotificationService.class);
case Helper.NOTIF_LIVE: startService(streamingIntent);
Intent streamingIntent = new Intent(getApplicationContext(), LiveNotificationService.class); break;
startService(streamingIntent); case Helper.NOTIF_DELAYED:
break; streamingIntent = new Intent(getApplicationContext(), LiveNotificationDelayedService.class);
case Helper.NOTIF_DELAYED: startService(streamingIntent);
streamingIntent = new Intent(getApplicationContext(), LiveNotificationDelayedService.class); break;
startService(streamingIntent); }
break; } catch (Exception ignored) {}
} }else {
} catch (Exception ignored) {} sendBroadcast(new Intent(getApplicationContext(), StopLiveNotificationReceiver.class));
}else { if (Build.VERSION.SDK_INT >= 26) {
sendBroadcast(new Intent(getApplicationContext(), StopLiveNotificationReceiver.class)); NotificationManager notif = ((NotificationManager) getSystemService(NOTIFICATION_SERVICE));
if (Build.VERSION.SDK_INT >= 26) { if (notif != null) {
NotificationManager notif = ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)); notif.deleteNotificationChannel(LiveNotificationDelayedService.CHANNEL_ID);
if (notif != null) {
notif.deleteNotificationChannel(LiveNotificationDelayedService.CHANNEL_ID);
}
} }
} }
} }
}); });
//Live notification mode
final MaterialSpinner 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<>(getApplicationContext(),
android.R.layout.simple_spinner_dropdown_item,labels );
set_live_type.setAdapter(adapterLive);
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(getApplicationContext())){
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;
}
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
@ -409,25 +371,22 @@ public class SettingsActivity extends BaseActivity {
set_allow_live_notifications_title.setText(getString(R.string.set_allow_live_notifications, account.getAcct() + "@" + account.getInstance())); 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); 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.setChecked(allow_live_notifications);
set_allow_live_notifications.setOnClickListener(new View.OnClickListener() { set_allow_live_notifications.setOnClickListener(v -> {
@Override SharedPreferences.Editor editor = sharedpreferences.edit();
public void onClick(View v) { editor.putBoolean(Helper.SET_ALLOW_STREAM + userId + instance, set_allow_live_notifications.isChecked());
SharedPreferences.Editor editor = sharedpreferences.edit(); editor.apply();
editor.putBoolean(Helper.SET_ALLOW_STREAM + userId + instance, set_allow_live_notifications.isChecked()); if (set_allow_live_notifications.isChecked()) {
editor.apply(); LiveNotificationDelayedService.totalAccount++;
if (set_allow_live_notifications.isChecked()) { } else {
LiveNotificationDelayedService.totalAccount++; LiveNotificationDelayedService.totalAccount--;
} else {
LiveNotificationDelayedService.totalAccount--;
}
if (set_allow_live_notifications.isChecked()) {
LiveNotificationDelayedService.totalAccount++;
} else {
LiveNotificationDelayedService.totalAccount--;
}
Helper.startStreaming(SettingsActivity.this);
} }
if (set_allow_live_notifications.isChecked()) {
LiveNotificationDelayedService.totalAccount++;
} else {
LiveNotificationDelayedService.totalAccount--;
}
Helper.startStreaming(SettingsActivity.this);
}); });
final ImageButton set_allow_live_notifications_others = findViewById(R.id.set_allow_live_notifications_others); final ImageButton set_allow_live_notifications_others = findViewById(R.id.set_allow_live_notifications_others);
set_allow_live_notifications_others.setOnClickListener(view -> { set_allow_live_notifications_others.setOnClickListener(view -> {
@ -435,68 +394,84 @@ public class SettingsActivity extends BaseActivity {
startActivity(intent); startActivity(intent);
}); });
set_live_type.setSelectedIndex(Helper.liveNotifType(getApplicationContext())); //Live notification mode
Helper.changeMaterialSpinnerColor(SettingsActivity.this, set_live_type); final Spinner set_live_type = findViewById(R.id.set_live_type);
set_live_type.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener() { 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;
}
set_live_type.setSelection(Helper.liveNotifType(SettingsActivity.this));
liveNotificationCount = 0;
set_live_type.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override @Override
public void onItemSelected(MaterialSpinner view, int position, long id, Object item) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (count2 > 0) { if (liveNotificationCount > 0) {
SharedPreferences.Editor editor = sharedpreferences.edit(); 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) { switch (position) {
case Helper.NOTIF_LIVE: case Helper.NOTIF_LIVE:
editor.putBoolean(Helper.SET_LIVE_NOTIFICATIONS, true); editor.putBoolean(Helper.SET_LIVE_NOTIFICATIONS, true);
editor.putBoolean(Helper.SET_DELAYED_NOTIFICATIONS, false); editor.putBoolean(Helper.SET_DELAYED_NOTIFICATIONS, false);
live_notif_per_account.setVisibility(View.VISIBLE); live_notif_per_account.setVisibility(View.VISIBLE);
editor.apply(); editor.commit();
sendBroadcast(new Intent(SettingsActivity.this, StopDelayedNotificationReceiver.class)); set_live_type_indication.setText(R.string.live_notif_indication);
ApplicationJob.cancelAllJob(NotificationsSyncJob.NOTIFICATION_REFRESH); Helper.startStreaming(SettingsActivity.this);
break; break;
case Helper.NOTIF_DELAYED: case Helper.NOTIF_DELAYED:
editor.putBoolean(Helper.SET_LIVE_NOTIFICATIONS, false); editor.putBoolean(Helper.SET_LIVE_NOTIFICATIONS, false);
editor.putBoolean(Helper.SET_DELAYED_NOTIFICATIONS, true); editor.putBoolean(Helper.SET_DELAYED_NOTIFICATIONS, true);
live_notif_per_account.setVisibility(View.VISIBLE); live_notif_per_account.setVisibility(View.VISIBLE);
sendBroadcast(new Intent(SettingsActivity.this, StopLiveNotificationReceiver.class)); set_live_type_indication.setText(R.string.set_live_type_indication);
editor.apply(); editor.commit();
ApplicationJob.cancelAllJob(NotificationsSyncJob.NOTIFICATION_REFRESH); Helper.startStreaming(SettingsActivity.this);
break; break;
case Helper.NOTIF_NONE: case Helper.NOTIF_NONE:
editor.putBoolean(Helper.SET_LIVE_NOTIFICATIONS, false); editor.putBoolean(Helper.SET_LIVE_NOTIFICATIONS, false);
editor.putBoolean(Helper.SET_DELAYED_NOTIFICATIONS, false); editor.putBoolean(Helper.SET_DELAYED_NOTIFICATIONS, false);
live_notif_per_account.setVisibility(View.GONE); editor.commit();
sendBroadcast(new Intent(SettingsActivity.this, StopLiveNotificationReceiver.class));
sendBroadcast(new Intent(SettingsActivity.this, StopDelayedNotificationReceiver.class));
NotificationsSyncJob.schedule(false);
editor.apply();
break;
}
Helper.startStreaming(SettingsActivity.this);
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); set_live_type_indication.setText(R.string.no_live_indication);
live_notif_per_account.setVisibility(View.GONE);
NotificationsSyncJob.schedule(false);
break; break;
} }
} else {
liveNotificationCount++;
} }
count2++; }
@Override
public void onNothingSelected(AdapterView<?> parent) {
} }
}); });
boolean clear_cache_exit = sharedpreferences.getBoolean(Helper.SET_CLEAR_CACHE_EXIT, false); 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); final SwitchCompat set_clear_cache_exit = findViewById(R.id.set_clear_cache_exit);
set_clear_cache_exit.setChecked(clear_cache_exit); set_clear_cache_exit.setChecked(clear_cache_exit);
set_clear_cache_exit.setOnClickListener(new View.OnClickListener() { set_clear_cache_exit.setOnClickListener(v -> {
@Override SharedPreferences.Editor editor = sharedpreferences.edit();
public void onClick(View v) { editor.putBoolean(Helper.SET_CLEAR_CACHE_EXIT, set_clear_cache_exit.isChecked());
SharedPreferences.Editor editor = sharedpreferences.edit(); editor.apply();
editor.putBoolean(Helper.SET_CLEAR_CACHE_EXIT, set_clear_cache_exit.isChecked());
editor.apply();
}
}); });
@ -534,8 +509,6 @@ public class SettingsActivity extends BaseActivity {
LinearLayout toot_visibility_container = findViewById(R.id.toot_visibility_container);
final ImageView set_toot_visibility = findViewById(R.id.set_toot_visibility); final ImageView set_toot_visibility = findViewById(R.id.set_toot_visibility);
if (theme == Helper.THEME_DARK) { if (theme == Helper.THEME_DARK) {
Helper.changeDrawableColor(getApplicationContext(), set_toot_visibility, R.color.dark_text); Helper.changeDrawableColor(getApplicationContext(), set_toot_visibility, R.color.dark_text);
@ -543,86 +516,67 @@ public class SettingsActivity extends BaseActivity {
Helper.changeDrawableColor(getApplicationContext(), set_toot_visibility, R.color.white); Helper.changeDrawableColor(getApplicationContext(), set_toot_visibility, R.color.white);
} }
//Only displayed for non locked accounts //Only displayed for non locked accounts
if (account != null) { String defaultVisibility = account.isLocked() ? "private" : "public";
String defaultVisibility = account.isLocked() ? "private" : "public"; String tootVisibility = sharedpreferences.getString(Helper.SET_TOOT_VISIBILITY + "@" + account.getAcct() + "@" + account.getInstance(), defaultVisibility);
String tootVisibility = sharedpreferences.getString(Helper.SET_TOOT_VISIBILITY + "@" + account.getAcct() + "@" + account.getInstance(), defaultVisibility); switch (tootVisibility) {
switch (tootVisibility) { case "public":
case "public": set_toot_visibility.setImageResource(R.drawable.ic_public);
set_toot_visibility.setImageResource(R.drawable.ic_public); break;
break; case "unlisted":
case "unlisted": set_toot_visibility.setImageResource(R.drawable.ic_lock_open);
set_toot_visibility.setImageResource(R.drawable.ic_lock_open); break;
break; case "private":
case "private": set_toot_visibility.setImageResource(R.drawable.ic_lock_outline);
set_toot_visibility.setImageResource(R.drawable.ic_lock_outline); break;
break; case "direct":
case "direct": set_toot_visibility.setImageResource(R.drawable.ic_mail_outline);
set_toot_visibility.setImageResource(R.drawable.ic_mail_outline); break;
break;
}
} else {
toot_visibility_container.setVisibility(View.GONE);
} }
set_toot_visibility.setOnClickListener(new View.OnClickListener() { set_toot_visibility.setOnClickListener(v -> {
@Override final SharedPreferences sharedpreferences1 = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
public void onClick(View v) { if (theme == Helper.THEME_DARK) {
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); style = R.style.DialogDark;
if (theme == Helper.THEME_DARK) { } else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogDark; style = R.style.DialogBlack;
} else if (theme == Helper.THEME_BLACK) { } else {
style = R.style.DialogBlack; style = R.style.Dialog;
} else {
style = R.style.Dialog;
}
AlertDialog.Builder dialog = new AlertDialog.Builder(SettingsActivity.this, style);
dialog.setTitle(R.string.toot_visibility_tilte);
final String[] stringArray = getResources().getStringArray(R.array.toot_visibility);
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getApplicationContext(), android.R.layout.simple_list_item_1, stringArray);
dialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int position) {
dialog.dismiss();
}
});
dialog.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int position) {
String visibility = "public";
switch (position) {
case 0:
visibility = "public";
set_toot_visibility.setImageResource(R.drawable.ic_public);
break;
case 1:
visibility = "unlisted";
set_toot_visibility.setImageResource(R.drawable.ic_lock_open);
break;
case 2:
visibility = "private";
set_toot_visibility.setImageResource(R.drawable.ic_lock_outline);
break;
case 3:
visibility = "direct";
set_toot_visibility.setImageResource(R.drawable.ic_mail_outline);
break;
}
if (account != null) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.SET_TOOT_VISIBILITY + "@" + account.getAcct() + "@" + account.getInstance(), visibility);
editor.apply();
Toasty.info(getApplicationContext(), getString(R.string.toast_visibility_changed, "@" + account.getAcct() + "@" + account.getInstance()), Toast.LENGTH_SHORT).show();
} else {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
}
dialog.dismiss();
}
});
dialog.show();
} }
AlertDialog.Builder dialog = new AlertDialog.Builder(SettingsActivity.this, style);
dialog.setTitle(R.string.toot_visibility_tilte);
final String[] stringArray = getResources().getStringArray(R.array.toot_visibility);
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getApplicationContext(), android.R.layout.simple_list_item_1, stringArray);
dialog.setNegativeButton(R.string.cancel, (dialog12, position) -> dialog12.dismiss());
dialog.setAdapter(arrayAdapter, (dialog1, position) -> {
String visibility = "public";
switch (position) {
case 0:
visibility = "public";
set_toot_visibility.setImageResource(R.drawable.ic_public);
break;
case 1:
visibility = "unlisted";
set_toot_visibility.setImageResource(R.drawable.ic_lock_open);
break;
case 2:
visibility = "private";
set_toot_visibility.setImageResource(R.drawable.ic_lock_outline);
break;
case 3:
visibility = "direct";
set_toot_visibility.setImageResource(R.drawable.ic_mail_outline);
break;
}
SharedPreferences.Editor editor = sharedpreferences1.edit();
editor.putString(Helper.SET_TOOT_VISIBILITY + "@" + account.getAcct() + "@" + account.getInstance(), visibility);
editor.apply();
Toasty.info(getApplicationContext(), getString(R.string.toast_visibility_changed, "@" + account.getAcct() + "@" + account.getInstance()), Toast.LENGTH_SHORT).show();
dialog1.dismiss();
});
dialog.show();
}); });
int split_size_val = sharedpreferences.getInt(Helper.SET_AUTOMATICALLY_SPLIT_TOOTS_SIZE + userId + instance, Helper.SPLIT_TOOT_SIZE); int split_size_val = sharedpreferences.getInt(Helper.SET_AUTOMATICALLY_SPLIT_TOOTS_SIZE + userId + instance, Helper.SPLIT_TOOT_SIZE);
@ -660,17 +614,14 @@ public class SettingsActivity extends BaseActivity {
} }
final SwitchCompat set_split_toot = findViewById(R.id.set_automatically_split_toot); final SwitchCompat set_split_toot = findViewById(R.id.set_automatically_split_toot);
set_split_toot.setChecked(split_toot); set_split_toot.setChecked(split_toot);
set_split_toot.setOnClickListener(new View.OnClickListener() { set_split_toot.setOnClickListener(v -> {
@Override SharedPreferences.Editor editor = sharedpreferences.edit();
public void onClick(View v) { editor.putBoolean(Helper.SET_AUTOMATICALLY_SPLIT_TOOTS + userId + instance, set_split_toot.isChecked());
SharedPreferences.Editor editor = sharedpreferences.edit(); editor.apply();
editor.putBoolean(Helper.SET_AUTOMATICALLY_SPLIT_TOOTS + userId + instance, set_split_toot.isChecked()); if (set_split_toot.isChecked()) {
editor.apply(); set_split_container.setVisibility(View.VISIBLE);
if (set_split_toot.isChecked()) { } else {
set_split_container.setVisibility(View.VISIBLE); set_split_container.setVisibility(View.GONE);
} else {
set_split_container.setVisibility(View.GONE);
}
} }
}); });

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?><!-- <?xml version="1.0" encoding="utf-8"?><!--
Copyright 2017 Thomas Schneider Copyright 2020 Thomas Schneider
This file is a part of Fedilab This file is a part of Fedilab
@ -364,9 +364,10 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"> android:orientation="horizontal">
<com.jaredrummler.materialspinner.MaterialSpinner <Spinner
android:id="@+id/set_live_type" android:id="@+id/set_live_type"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
@ -596,5 +597,20 @@
android:hint="@string/set_nitter_host" android:hint="@string/set_nitter_host"
android:inputType="textWebEditText" /> android:inputType="textWebEditText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/set_bibliogram"
android:textSize="16sp" />
<EditText
android:id="@+id/set_bibliogram_host"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/settings_option_margin"
android:hint="@string/set_bibliogram_host"
android:inputType="textWebEditText" />
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

View File

@ -277,7 +277,7 @@ public class Status implements Parcelable {
String content = status.getReblog() != null ? status.getReblog().getContent() : status.getContent(); String content = status.getReblog() != null ? status.getReblog().getContent() : status.getContent();
Matcher matcher = Helper.youtubePattern.matcher(content); Matcher matcher = Helper.youtubePattern.matcher(content);
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean invidious = sharedpreferences.getBoolean(Helper.SET_INVIDIOUS, false); boolean invidious = Helper.getSharedValue(context, Helper.SET_INVIDIOUS);
if (invidious) { if (invidious) {
while (matcher.find()) { while (matcher.find()) {
final String youtubeId = matcher.group(3); final String youtubeId = matcher.group(3);
@ -295,7 +295,7 @@ public class Status implements Parcelable {
} }
matcher = Helper.nitterPattern.matcher(content); matcher = Helper.nitterPattern.matcher(content);
boolean nitter = sharedpreferences.getBoolean(Helper.SET_NITTER, false); boolean nitter = Helper.getSharedValue(context, Helper.SET_NITTER);
if (nitter) { if (nitter) {
while (matcher.find()) { while (matcher.find()) {
final String nitter_directory = matcher.group(2); final String nitter_directory = matcher.group(2);
@ -306,7 +306,7 @@ public class Status implements Parcelable {
} }
matcher = Helper.bibliogramPattern.matcher(content); matcher = Helper.bibliogramPattern.matcher(content);
boolean bibliogram = sharedpreferences.getBoolean(Helper.SET_BIBLIOGRAM, false); boolean bibliogram = Helper.getSharedValue(context, Helper.SET_BIBLIOGRAM);
if (bibliogram) { if (bibliogram) {
while (matcher.find()) { while (matcher.find()) {
final String bibliogram_directory = matcher.group(2); final String bibliogram_directory = matcher.group(2);
@ -525,7 +525,7 @@ public class Status implements Parcelable {
@Override @Override
public void onClick(@NonNull View textView) { public void onClick(@NonNull View textView) {
Intent intent; Intent intent;
boolean nitter = sharedpreferences.getBoolean(Helper.SET_NITTER, false); boolean nitter = Helper.getSharedValue(context, Helper.SET_NITTER);
if (nitter) { if (nitter) {
String nitterHost = sharedpreferences.getString(Helper.SET_NITTER_HOST, Helper.DEFAULT_NITTER_HOST).toLowerCase(); String nitterHost = sharedpreferences.getString(Helper.SET_NITTER_HOST, Helper.DEFAULT_NITTER_HOST).toLowerCase();
assert twittername != null; assert twittername != null;
@ -1585,8 +1585,8 @@ public class Status implements Parcelable {
public void setViewType(Context context) { public void setViewType(Context context) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false); boolean isCompactMode = Helper.getSharedValue(context, Helper.SET_COMPACT_MODE);
boolean isConsoleMode = sharedpreferences.getBoolean(Helper.SET_CONSOLE_MODE, false); boolean isConsoleMode = Helper.getSharedValue(context, Helper.SET_CONSOLE_MODE);
if (isCompactMode) if (isCompactMode)
this.viewType = COMPACT_STATUS; this.viewType = COMPACT_STATUS;
else if (isConsoleMode) else if (isConsoleMode)

View File

@ -684,8 +684,8 @@ public abstract class BaseStatusListAdapter extends RecyclerView.Adapter<Recycle
boolean fullAttachement = sharedpreferences.getBoolean(Helper.SET_FULL_PREVIEW, false); boolean fullAttachement = sharedpreferences.getBoolean(Helper.SET_FULL_PREVIEW, false);
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false); boolean isCompactMode = Helper.getSharedValue(context, Helper.SET_COMPACT_MODE);
boolean isConsoleMode = sharedpreferences.getBoolean(Helper.SET_CONSOLE_MODE, false); boolean isConsoleMode = Helper.getSharedValue(context, Helper.SET_CONSOLE_MODE);
int iconSizePercent = sharedpreferences.getInt(Helper.SET_ICON_SIZE, 130); int iconSizePercent = sharedpreferences.getInt(Helper.SET_ICON_SIZE, 130);
int textSizePercent = sharedpreferences.getInt(Helper.SET_TEXT_SIZE, 110); int textSizePercent = sharedpreferences.getInt(Helper.SET_TEXT_SIZE, 110);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
@ -2160,7 +2160,7 @@ public abstract class BaseStatusListAdapter extends RecyclerView.Adapter<Recycle
holder.status_cardview_video.setVisibility(View.GONE); holder.status_cardview_video.setVisibility(View.GONE);
holder.status_cardview.setOnClickListener(view -> { holder.status_cardview.setOnClickListener(view -> {
String url = card.getUrl(); String url = card.getUrl();
boolean nitter = sharedpreferences.getBoolean(Helper.SET_NITTER, false); boolean nitter = Helper.getSharedValue(context, Helper.SET_NITTER);
if (nitter) { if (nitter) {
Matcher matcher = Helper.nitterPattern.matcher(url); Matcher matcher = Helper.nitterPattern.matcher(url);
while (matcher.find()) { while (matcher.find()) {
@ -2169,7 +2169,7 @@ public abstract class BaseStatusListAdapter extends RecyclerView.Adapter<Recycle
url = url.replaceAll("https://" + Pattern.quote(matcher.group()), Matcher.quoteReplacement("https://" + nitterHost + nitter_directory)); url = url.replaceAll("https://" + Pattern.quote(matcher.group()), Matcher.quoteReplacement("https://" + nitterHost + nitter_directory));
} }
} }
boolean bibliogram = sharedpreferences.getBoolean(Helper.SET_BIBLIOGRAM, false); boolean bibliogram = Helper.getSharedValue(context, Helper.SET_BIBLIOGRAM);
if (bibliogram) { if (bibliogram) {
Matcher matcher = Helper.bibliogramPattern.matcher(url); Matcher matcher = Helper.bibliogramPattern.matcher(url);
while (matcher.find()) { while (matcher.find()) {
@ -2201,7 +2201,7 @@ public abstract class BaseStatusListAdapter extends RecyclerView.Adapter<Recycle
holder.webview_preview.setOnClickListener(v -> { holder.webview_preview.setOnClickListener(v -> {
String url = finalSrc; String url = finalSrc;
if (url != null) { if (url != null) {
boolean invidious = sharedpreferences.getBoolean(Helper.SET_INVIDIOUS, false); boolean invidious = Helper.getSharedValue(context, Helper.SET_INVIDIOUS);
if (invidious) { if (invidious) {
Matcher matcher = Helper.youtubePattern.matcher(url); Matcher matcher = Helper.youtubePattern.matcher(url);
while (matcher.find()) { while (matcher.find()) {

View File

@ -1336,8 +1336,8 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
ArrayAdapter<String> adapterMode = new ArrayAdapter<>(Objects.requireNonNull(getActivity()), ArrayAdapter<String> adapterMode = new ArrayAdapter<>(Objects.requireNonNull(getActivity()),
android.R.layout.simple_spinner_dropdown_item, mode_labels); android.R.layout.simple_spinner_dropdown_item, mode_labels);
set_mode.setAdapter(adapterMode); set_mode.setAdapter(adapterMode);
boolean compact_mode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false); boolean compact_mode = Helper.getSharedValue(context, Helper.SET_COMPACT_MODE);
boolean console_mode = sharedpreferences.getBoolean(Helper.SET_CONSOLE_MODE, false); boolean console_mode = Helper.getSharedValue(context, Helper.SET_CONSOLE_MODE);
if (compact_mode) { if (compact_mode) {
set_mode.setSelection(1); set_mode.setSelection(1);
@ -2035,7 +2035,7 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
TextView set_invidious_host = rootView.findViewById(R.id.set_invidious_host); TextView set_invidious_host = rootView.findViewById(R.id.set_invidious_host);
boolean invidious = sharedpreferences.getBoolean(Helper.SET_INVIDIOUS, false); boolean invidious = Helper.getSharedValue(context, Helper.SET_INVIDIOUS);
final SwitchCompat set_invidious = rootView.findViewById(R.id.set_invidious); final SwitchCompat set_invidious = rootView.findViewById(R.id.set_invidious);
set_invidious.setChecked(invidious); set_invidious.setChecked(invidious);
@ -2120,7 +2120,7 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
}); });
TextView set_nitter_host = rootView.findViewById(R.id.set_nitter_host); TextView set_nitter_host = rootView.findViewById(R.id.set_nitter_host);
boolean nitter = sharedpreferences.getBoolean(Helper.SET_NITTER, false); boolean nitter = Helper.getSharedValue(context, Helper.SET_NITTER);
final SwitchCompat set_nitter = rootView.findViewById(R.id.set_nitter); final SwitchCompat set_nitter = rootView.findViewById(R.id.set_nitter);
set_nitter.setChecked(nitter); set_nitter.setChecked(nitter);
@ -2169,7 +2169,7 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
TextView set_bibliogram_host = rootView.findViewById(R.id.set_bibliogram_host); TextView set_bibliogram_host = rootView.findViewById(R.id.set_bibliogram_host);
boolean bibliogram = sharedpreferences.getBoolean(Helper.SET_BIBLIOGRAM, false); boolean bibliogram = Helper.getSharedValue(context, Helper.SET_BIBLIOGRAM);
final SwitchCompat set_bibliogram = rootView.findViewById(R.id.set_bibliogram); final SwitchCompat set_bibliogram = rootView.findViewById(R.id.set_bibliogram);
set_bibliogram.setChecked(bibliogram); set_bibliogram.setChecked(bibliogram);

View File

@ -4562,5 +4562,43 @@ public class BaseHelper {
} }
} }
public static boolean getSharedValue(Context context, String type) {
SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
if( type.compareTo(Helper.SET_INVIDIOUS) == 0 ) {
if( BuildConfig.lite) {
return true;
}else {
return sharedpreferences.getBoolean(type, false);
}
}else if( type.compareTo(Helper.SET_BIBLIOGRAM) == 0 ) {
if( BuildConfig.lite) {
return true;
}else {
return sharedpreferences.getBoolean(type, false);
}
}else if( type.compareTo(Helper.SET_NITTER) == 0 ) {
if( BuildConfig.lite) {
return true;
}else {
return sharedpreferences.getBoolean(type, false);
}
}
else if( type.compareTo(Helper.SET_CONSOLE_MODE) == 0 ) {
if( BuildConfig.lite) {
return false;
}else {
return sharedpreferences.getBoolean(type, false);
}
}
else if( type.compareTo(Helper.SET_COMPACT_MODE) == 0 ) {
if( BuildConfig.lite) {
return true;
}else {
return sharedpreferences.getBoolean(type, false);
}
}
return sharedpreferences.getBoolean(type, false);
}
} }