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;
import android.app.NotificationManager;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
@ -27,34 +27,33 @@ import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.SwitchCompat;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import com.jaredrummler.materialspinner.MaterialSpinner;
import app.fedilab.lite.R;
import app.fedilab.lite.client.Entities.Account;
import app.fedilab.lite.helper.Helper;
import app.fedilab.lite.jobs.ApplicationJob;
import app.fedilab.lite.jobs.NotificationsSyncJob;
import app.fedilab.lite.services.LiveNotificationDelayedService;
import app.fedilab.lite.services.LiveNotificationService;
import app.fedilab.lite.services.StopDelayedNotificationReceiver;
import app.fedilab.lite.services.StopLiveNotificationReceiver;
import app.fedilab.lite.sqlite.AccountDAO;
import app.fedilab.lite.sqlite.Sqlite;
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.sqlite.AccountDAO;
import app.fedilab.android.sqlite.Sqlite;
import es.dmoral.toasty.Toasty;
/**
@ -66,9 +65,11 @@ public class SettingsActivity extends BaseActivity {
private int count1, count2, count3, count4, count5;
private int style;
protected int res;
private int liveNotificationCount;
public static boolean needRestart;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -79,43 +80,30 @@ public class SettingsActivity extends BaseActivity {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
break;
case Helper.THEME_DARK:
setTheme(R.style.AppThemeDark);
break;
case Helper.THEME_BLACK:
setTheme(R.style.AppThemeBlack);
break;
default:
setTheme(R.style.AppThemeDark);
}
needRestart = false;
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
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.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title);
toolbar_close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
toolbar_close.setOnClickListener(v -> finish());
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);
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} 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);
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.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_DISPLAY_CONTENT_AFTER_FM, set_display_content_after_fetch_more.isChecked());
editor.apply();
}
set_display_content_after_fetch_more.setOnClickListener(v -> {
SharedPreferences.Editor editor = sharedpreferences.edit();
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);
final SwitchCompat set_share_validation = findViewById(R.id.set_share_validation);
set_share_validation.setChecked(notif_validation);
set_share_validation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_NOTIF_VALIDATION, set_share_validation.isChecked());
editor.apply();
}
set_share_validation.setOnClickListener(v -> {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_NOTIF_VALIDATION, set_share_validation.isChecked());
editor.apply();
});
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);
set_share_validation_fav.setChecked(notif_validation_fav);
set_share_validation_fav.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_NOTIF_VALIDATION_FAV, set_share_validation_fav.isChecked());
editor.apply();
}
set_share_validation_fav.setOnClickListener(v -> {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_NOTIF_VALIDATION_FAV, set_share_validation_fav.isChecked());
editor.apply();
});
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);
final SwitchCompat set_expand_cw = findViewById(R.id.set_expand_cw);
set_expand_cw.setChecked(expand_cw);
set_expand_cw.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_EXPAND_CW, set_expand_cw.isChecked());
editor.apply();
}
set_expand_cw.setOnClickListener(v -> {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_EXPAND_CW, set_expand_cw.isChecked());
editor.apply();
});
boolean expand_media = sharedpreferences.getBoolean(Helper.SET_EXPAND_MEDIA, false);
final SwitchCompat set_expand_media = findViewById(R.id.set_expand_image);
set_expand_media.setChecked(expand_media);
set_expand_media.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_EXPAND_MEDIA, set_expand_media.isChecked());
editor.apply();
}
set_expand_media.setOnClickListener(v -> {
SharedPreferences.Editor editor = sharedpreferences.edit();
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);
set_quick_reply.setChecked(quick_reply);
set_quick_reply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_QUICK_REPLY, set_quick_reply.isChecked());
editor.apply();
}
set_quick_reply.setOnClickListener(v -> {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_QUICK_REPLY, set_quick_reply.isChecked());
editor.apply();
});
boolean fit_preview = sharedpreferences.getBoolean(Helper.SET_FULL_PREVIEW, false);
final SwitchCompat set_fit_preview = findViewById(R.id.set_fit_preview);
set_fit_preview.setChecked(fit_preview);
set_fit_preview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_FULL_PREVIEW, set_fit_preview.isChecked());
editor.apply();
}
set_fit_preview.setOnClickListener(v -> {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_FULL_PREVIEW, set_fit_preview.isChecked());
editor.apply();
});
boolean disableGif = sharedpreferences.getBoolean(Helper.SET_DISABLE_GIF, false);
final SwitchCompat set_disable_gif = findViewById(R.id.set_disable_gif);
set_disable_gif.setChecked(disableGif);
set_disable_gif.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_DISABLE_GIF, set_disable_gif.isChecked());
editor.apply();
recreate();
}
set_disable_gif.setOnClickListener(v -> {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_DISABLE_GIF, set_disable_gif.isChecked());
editor.apply();
recreate();
});
boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false);
final SwitchCompat set_disable_animated_emoji = findViewById(R.id.set_disable_animated_emoji);
set_disable_animated_emoji.setChecked(disableAnimatedEmoji);
set_disable_animated_emoji.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, set_disable_animated_emoji.isChecked());
editor.apply();
}
set_disable_animated_emoji.setOnClickListener(v -> {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, set_disable_animated_emoji.isChecked());
editor.apply();
});
boolean display_card = sharedpreferences.getBoolean(Helper.SET_DISPLAY_CARD, false);
final SwitchCompat set_display_card = findViewById(R.id.set_display_card);
set_display_card.setChecked(display_card);
set_display_card.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_DISPLAY_CARD, set_display_card.isChecked());
editor.apply();
}
set_display_card.setOnClickListener(v -> {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_DISPLAY_CARD, set_display_card.isChecked());
editor.apply();
});
boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true);
final SwitchCompat switchCompatNotify = findViewById(R.id.set_notify);
switchCompatNotify.setChecked(notify);
switchCompatNotify.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// Save the state here
SharedPreferences.Editor editor = sharedpreferences.edit();
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) {}
}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);
}
switchCompatNotify.setOnCheckedChangeListener((buttonView, isChecked) -> {
// Save the state here
SharedPreferences.Editor editor = sharedpreferences.edit();
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) {}
}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);
}
}
}
});
//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();
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()));
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(new View.OnClickListener() {
@Override
public void onClick(View 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--;
}
Helper.startStreaming(SettingsActivity.this);
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--;
}
Helper.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 -> {
@ -435,68 +394,84 @@ public class SettingsActivity extends BaseActivity {
startActivity(intent);
});
set_live_type.setSelectedIndex(Helper.liveNotifType(getApplicationContext()));
Helper.changeMaterialSpinnerColor(SettingsActivity.this, set_live_type);
set_live_type.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener() {
//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;
}
set_live_type.setSelection(Helper.liveNotifType(SettingsActivity.this));
liveNotificationCount = 0;
set_live_type.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(MaterialSpinner view, int position, long id, Object item) {
if (count2 > 0) {
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);
editor.apply();
sendBroadcast(new Intent(SettingsActivity.this, StopDelayedNotificationReceiver.class));
ApplicationJob.cancelAllJob(NotificationsSyncJob.NOTIFICATION_REFRESH);
editor.commit();
set_live_type_indication.setText(R.string.live_notif_indication);
Helper.startStreaming(SettingsActivity.this);
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);
sendBroadcast(new Intent(SettingsActivity.this, StopLiveNotificationReceiver.class));
editor.apply();
ApplicationJob.cancelAllJob(NotificationsSyncJob.NOTIFICATION_REFRESH);
set_live_type_indication.setText(R.string.set_live_type_indication);
editor.commit();
Helper.startStreaming(SettingsActivity.this);
break;
case Helper.NOTIF_NONE:
editor.putBoolean(Helper.SET_LIVE_NOTIFICATIONS, false);
editor.putBoolean(Helper.SET_DELAYED_NOTIFICATIONS, false);
live_notif_per_account.setVisibility(View.GONE);
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:
editor.commit();
set_live_type_indication.setText(R.string.no_live_indication);
live_notif_per_account.setVisibility(View.GONE);
NotificationsSyncJob.schedule(false);
break;
}
} else {
liveNotificationCount++;
}
count2++;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
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);
set_clear_cache_exit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_CLEAR_CACHE_EXIT, set_clear_cache_exit.isChecked());
editor.apply();
}
set_clear_cache_exit.setOnClickListener(v -> {
SharedPreferences.Editor editor = sharedpreferences.edit();
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);
if (theme == Helper.THEME_DARK) {
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);
}
//Only displayed for non locked accounts
if (account != null) {
String defaultVisibility = account.isLocked() ? "private" : "public";
String tootVisibility = sharedpreferences.getString(Helper.SET_TOOT_VISIBILITY + "@" + account.getAcct() + "@" + account.getInstance(), defaultVisibility);
switch (tootVisibility) {
case "public":
set_toot_visibility.setImageResource(R.drawable.ic_public);
break;
case "unlisted":
set_toot_visibility.setImageResource(R.drawable.ic_lock_open);
break;
case "private":
set_toot_visibility.setImageResource(R.drawable.ic_lock_outline);
break;
case "direct":
set_toot_visibility.setImageResource(R.drawable.ic_mail_outline);
break;
}
} else {
toot_visibility_container.setVisibility(View.GONE);
String defaultVisibility = account.isLocked() ? "private" : "public";
String tootVisibility = sharedpreferences.getString(Helper.SET_TOOT_VISIBILITY + "@" + account.getAcct() + "@" + account.getInstance(), defaultVisibility);
switch (tootVisibility) {
case "public":
set_toot_visibility.setImageResource(R.drawable.ic_public);
break;
case "unlisted":
set_toot_visibility.setImageResource(R.drawable.ic_lock_open);
break;
case "private":
set_toot_visibility.setImageResource(R.drawable.ic_lock_outline);
break;
case "direct":
set_toot_visibility.setImageResource(R.drawable.ic_mail_outline);
break;
}
set_toot_visibility.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
} 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();
set_toot_visibility.setOnClickListener(v -> {
final SharedPreferences sharedpreferences1 = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
} 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, (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);
@ -660,17 +614,14 @@ public class SettingsActivity extends BaseActivity {
}
final SwitchCompat set_split_toot = findViewById(R.id.set_automatically_split_toot);
set_split_toot.setChecked(split_toot);
set_split_toot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_AUTOMATICALLY_SPLIT_TOOTS + userId + instance, set_split_toot.isChecked());
editor.apply();
if (set_split_toot.isChecked()) {
set_split_container.setVisibility(View.VISIBLE);
} else {
set_split_container.setVisibility(View.GONE);
}
set_split_toot.setOnClickListener(v -> {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_AUTOMATICALLY_SPLIT_TOOTS + userId + instance, set_split_toot.isChecked());
editor.apply();
if (set_split_toot.isChecked()) {
set_split_container.setVisibility(View.VISIBLE);
} else {
set_split_container.setVisibility(View.GONE);
}
});

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2017 Thomas Schneider
Copyright 2020 Thomas Schneider
This file is a part of Fedilab
@ -364,9 +364,10 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<com.jaredrummler.materialspinner.MaterialSpinner
<Spinner
android:id="@+id/set_live_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
@ -596,5 +597,20 @@
android:hint="@string/set_nitter_host"
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>
</ScrollView>

View File

@ -277,7 +277,7 @@ public class Status implements Parcelable {
String content = status.getReblog() != null ? status.getReblog().getContent() : status.getContent();
Matcher matcher = Helper.youtubePattern.matcher(content);
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) {
while (matcher.find()) {
final String youtubeId = matcher.group(3);
@ -295,7 +295,7 @@ public class Status implements Parcelable {
}
matcher = Helper.nitterPattern.matcher(content);
boolean nitter = sharedpreferences.getBoolean(Helper.SET_NITTER, false);
boolean nitter = Helper.getSharedValue(context, Helper.SET_NITTER);
if (nitter) {
while (matcher.find()) {
final String nitter_directory = matcher.group(2);
@ -306,7 +306,7 @@ public class Status implements Parcelable {
}
matcher = Helper.bibliogramPattern.matcher(content);
boolean bibliogram = sharedpreferences.getBoolean(Helper.SET_BIBLIOGRAM, false);
boolean bibliogram = Helper.getSharedValue(context, Helper.SET_BIBLIOGRAM);
if (bibliogram) {
while (matcher.find()) {
final String bibliogram_directory = matcher.group(2);
@ -525,7 +525,7 @@ public class Status implements Parcelable {
@Override
public void onClick(@NonNull View textView) {
Intent intent;
boolean nitter = sharedpreferences.getBoolean(Helper.SET_NITTER, false);
boolean nitter = Helper.getSharedValue(context, Helper.SET_NITTER);
if (nitter) {
String nitterHost = sharedpreferences.getString(Helper.SET_NITTER_HOST, Helper.DEFAULT_NITTER_HOST).toLowerCase();
assert twittername != null;
@ -1585,8 +1585,8 @@ public class Status implements Parcelable {
public void setViewType(Context context) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false);
boolean isConsoleMode = sharedpreferences.getBoolean(Helper.SET_CONSOLE_MODE, false);
boolean isCompactMode = Helper.getSharedValue(context, Helper.SET_COMPACT_MODE);
boolean isConsoleMode = Helper.getSharedValue(context, Helper.SET_CONSOLE_MODE);
if (isCompactMode)
this.viewType = COMPACT_STATUS;
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 isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false);
boolean isConsoleMode = sharedpreferences.getBoolean(Helper.SET_CONSOLE_MODE, false);
boolean isCompactMode = Helper.getSharedValue(context, Helper.SET_COMPACT_MODE);
boolean isConsoleMode = Helper.getSharedValue(context, Helper.SET_CONSOLE_MODE);
int iconSizePercent = sharedpreferences.getInt(Helper.SET_ICON_SIZE, 130);
int textSizePercent = sharedpreferences.getInt(Helper.SET_TEXT_SIZE, 110);
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.setOnClickListener(view -> {
String url = card.getUrl();
boolean nitter = sharedpreferences.getBoolean(Helper.SET_NITTER, false);
boolean nitter = Helper.getSharedValue(context, Helper.SET_NITTER);
if (nitter) {
Matcher matcher = Helper.nitterPattern.matcher(url);
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));
}
}
boolean bibliogram = sharedpreferences.getBoolean(Helper.SET_BIBLIOGRAM, false);
boolean bibliogram = Helper.getSharedValue(context, Helper.SET_BIBLIOGRAM);
if (bibliogram) {
Matcher matcher = Helper.bibliogramPattern.matcher(url);
while (matcher.find()) {
@ -2201,7 +2201,7 @@ public abstract class BaseStatusListAdapter extends RecyclerView.Adapter<Recycle
holder.webview_preview.setOnClickListener(v -> {
String url = finalSrc;
if (url != null) {
boolean invidious = sharedpreferences.getBoolean(Helper.SET_INVIDIOUS, false);
boolean invidious = Helper.getSharedValue(context, Helper.SET_INVIDIOUS);
if (invidious) {
Matcher matcher = Helper.youtubePattern.matcher(url);
while (matcher.find()) {

View File

@ -1336,8 +1336,8 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
ArrayAdapter<String> adapterMode = new ArrayAdapter<>(Objects.requireNonNull(getActivity()),
android.R.layout.simple_spinner_dropdown_item, mode_labels);
set_mode.setAdapter(adapterMode);
boolean compact_mode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false);
boolean console_mode = sharedpreferences.getBoolean(Helper.SET_CONSOLE_MODE, false);
boolean compact_mode = Helper.getSharedValue(context, Helper.SET_COMPACT_MODE);
boolean console_mode = Helper.getSharedValue(context, Helper.SET_CONSOLE_MODE);
if (compact_mode) {
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);
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);
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);
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);
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);
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);
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);
}
}