Lite version split

This commit is contained in:
Thomas 2020-07-13 17:46:13 +02:00
parent e7489d3fd0
commit d46247f156
11 changed files with 272 additions and 769 deletions

View File

@ -26,6 +26,8 @@ android {
pseudoLocalesEnabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
@ -52,6 +54,19 @@ android {
buildConfigField "boolean", "lite", "false"
}
}
sourceSets {
playstore {
manifest.srcFile "src/main/AndroidManifest.xml"
}
fdroid {
manifest.srcFile "src/main/AndroidManifest.xml"
}
lite {
manifest.srcFile "src/lite/AndroidManifest.xml"
}
}
packagingOptions {
exclude 'META-INF/proguard/androidx-annotations.pro'
}
@ -134,7 +149,7 @@ dependencies {
implementation 'com.github.stom79:Android-WYSIWYG-Editor:3.2.1'
implementation 'com.github.smarteist:autoimageslider:1.3.2'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.2'
//debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.2'
//Flavors

View File

@ -1,33 +1,8 @@
package app.fedilab.android.activities;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.view.ActionMode;
import android.view.View;
import android.view.Window;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.franmontiel.localechanger.LocaleChanger;
import com.google.android.material.snackbar.Snackbar;
import com.jaredrummler.cyanea.app.CyaneaAppCompatActivity;
import com.vanniktech.emoji.EmojiManager;
import com.vanniktech.emoji.one.EmojiOneProvider;
import org.jetbrains.annotations.NotNull;
import java.util.Timer;
import app.fedilab.android.helper.Helper;
import es.dmoral.toasty.Toasty;
/**
* Created by Thomas on 12/12/2017.
@ -35,122 +10,11 @@ import es.dmoral.toasty.Toasty;
*/
@SuppressLint("Registered")
public class BaseActivity extends CyaneaAppCompatActivity {
public static final int READ_WRITE_STORAGE = 52;
public static Timer timer;
public static boolean canShowActionMode = true;
public class BaseActivity extends AllBaseActivity {
static {
Helper.installProvider();
EmojiManager.install(new EmojiOneProvider());
}
private ProgressDialog mProgressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
/*if (BuildConfig.DEBUG) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectAll()
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.detectLeakedRegistrationObjects()
.detectActivityLeaks()
.penaltyLog()
// .penaltyDeath()
.build());
}*/
canShowActionMode = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
}
super.onCreate(savedInstanceState);
}
@Override
public void onDestroy() {
super.onDestroy();
if (timer != null) {
timer.cancel();
timer = null;
}
}
@Override
public void onConfigurationChanged(@NotNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
LocaleChanger.onConfigurationChanged();
}
@Override
protected void attachBaseContext(@NotNull Context newBase) {
newBase = LocaleChanger.configureBaseContext(newBase);
super.attachBaseContext(newBase);
}
public boolean requestPermission(String permission) {
boolean isGranted = ContextCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED;
if (!isGranted) {
ActivityCompat.requestPermissions(
this,
new String[]{permission},
READ_WRITE_STORAGE);
}
return isGranted;
}
public void isPermissionGranted(boolean isGranted, String permission) {
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == READ_WRITE_STORAGE) {
isPermissionGranted(grantResults[0] == PackageManager.PERMISSION_GRANTED, permissions[0]);
}
}
protected void showLoading(@NonNull String message) {
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage(message);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mProgressDialog.setCancelable(false);
mProgressDialog.show();
}
protected void hideLoading() {
if (mProgressDialog != null) {
mProgressDialog.dismiss();
}
}
protected void showSnackbar(@NonNull String message) {
View view = findViewById(android.R.id.content);
if (view != null) {
Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show();
} else {
Toasty.info(BaseActivity.this, message, Toast.LENGTH_SHORT).show();
}
}
@Override
public void onActionModeStarted(ActionMode mode) {
if (!canShowActionMode) {
mode.finish();
}
super.onActionModeStarted(mode);
}
}

View File

@ -1,4 +1,36 @@
package app.fedilab.android.helper;
/* Copyright 2020 Thomas Schneider
*
* This file is a part of Fedilab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
import org.conscrypt.Conscrypt;
import java.security.Security;
public class Helper extends BaseHelper {
public static void installProvider() {
boolean patch_provider = true;
try {
Context ctx = MainApplication.getApp();
SharedPreferences sharedpreferences = ctx.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
patch_provider = sharedpreferences.getBoolean(Helper.SET_SECURITY_PROVIDER, true);
} catch (Exception ignored) {
}
if (patch_provider) {
try {
Security.insertProviderAt(Conscrypt.newProvider(), 1);
} catch (Exception ignored) {
}
}
}
}

View File

@ -383,25 +383,18 @@
android:launchMode="singleTask"
android:theme="@style/AppThemeDark_NoActionBar"
android:windowSoftInputMode="stateAlwaysHidden" />
<activity
android:name="app.fedilab.android.activities.OwnerNotificationChartsActivity"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTask"
android:windowSoftInputMode="stateAlwaysHidden" />
<activity
android:name="app.fedilab.android.activities.OwnerChartsActivity"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTask"
android:windowSoftInputMode="stateAlwaysHidden" />
<activity
android:name="app.fedilab.android.activities.OwnerNotificationActivity"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTask"
android:theme="@style/AppThemeDark_NoActionBar"
android:windowSoftInputMode="stateAlwaysHidden" />
<activity-alias
android:name=".activities.OwnerNotificationChartsActivity"
tools:node="remove"
android:targetActivity=".activities.OwnerNotificationChartsActivity" />
<activity-alias
android:name=".activities.OwnerChartsActivity"
tools:node="remove"
android:targetActivity=".activities.OwnerChartsActivity" />
<activity-alias
android:name=".activities.OwnerNotificationActivity"
tools:node="remove"
android:targetActivity=".activities.OwnerNotificationActivity" />
<activity
android:name="app.fedilab.android.activities.AboutActivity"
android:configChanges="orientation|screenSize"

View File

@ -1,156 +1,10 @@
package app.fedilab.android.activities;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.view.ActionMode;
import android.view.View;
import android.view.Window;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.franmontiel.localechanger.LocaleChanger;
import com.google.android.material.snackbar.Snackbar;
import com.jaredrummler.cyanea.app.CyaneaAppCompatActivity;
import com.vanniktech.emoji.EmojiManager;
import com.vanniktech.emoji.one.EmojiOneProvider;
import org.jetbrains.annotations.NotNull;
import java.util.Timer;
import app.fedilab.android.helper.Helper;
import es.dmoral.toasty.Toasty;
/**
* Created by Thomas on 12/12/2017.
* Base activity which updates security provider
*/
@SuppressLint("Registered")
public class BaseActivity extends AllBaseActivity {
public static final int READ_WRITE_STORAGE = 52;
public static Timer timer;
public static boolean canShowActionMode = true;
static {
Helper.installProvider();
EmojiManager.install(new EmojiOneProvider());
}
private ProgressDialog mProgressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
/*if (BuildConfig.DEBUG) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectAll()
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.detectLeakedRegistrationObjects()
.detectActivityLeaks()
.penaltyLog()
// .penaltyDeath()
.build());
}*/
canShowActionMode = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
}
super.onCreate(savedInstanceState);
}
@Override
public void onDestroy() {
super.onDestroy();
if (timer != null) {
timer.cancel();
timer = null;
}
}
@Override
public void onConfigurationChanged(@NotNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
LocaleChanger.onConfigurationChanged();
}
@Override
protected void attachBaseContext(@NotNull Context newBase) {
newBase = LocaleChanger.configureBaseContext(newBase);
super.attachBaseContext(newBase);
}
public boolean requestPermission(String permission) {
boolean isGranted = ContextCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED;
if (!isGranted) {
ActivityCompat.requestPermissions(
this,
new String[]{permission},
READ_WRITE_STORAGE);
}
return isGranted;
}
public void isPermissionGranted(boolean isGranted, String permission) {
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == READ_WRITE_STORAGE) {
isPermissionGranted(grantResults[0] == PackageManager.PERMISSION_GRANTED, permissions[0]);
}
}
protected void showLoading(@NonNull String message) {
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage(message);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mProgressDialog.setCancelable(false);
mProgressDialog.show();
}
protected void hideLoading() {
if (mProgressDialog != null) {
mProgressDialog.dismiss();
}
}
protected void showSnackbar(@NonNull String message) {
View view = findViewById(android.R.id.content);
if (view != null) {
Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show();
} else {
Toasty.info(BaseActivity.this, message, Toast.LENGTH_SHORT).show();
}
}
@Override
public void onActionModeStarted(ActionMode mode) {
if (!canShowActionMode) {
mode.finish();
}
super.onActionModeStarted(mode);
}
}

View File

@ -1,6 +1,6 @@
package app.fedilab.android.helper;
/* Copyright 2018 Thomas Schneider
/* Copyright 2020 Thomas Schneider
*
* This file is a part of Fedilab
*
@ -15,106 +15,23 @@ package app.fedilab.android.helper;
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.TypedArray;
import android.graphics.Paint;
import android.text.SpannableStringBuilder;
import android.util.AttributeSet;
import androidx.annotation.DimenRes;
import androidx.annotation.Px;
import androidx.appcompat.widget.AppCompatTextView;
import com.vanniktech.emoji.EmojiManager;
import app.fedilab.android.R;
/**
* Created by Thomas on 12/05/2018.
* Allows to fix crashes with selection see: https://stackoverflow.com/a/36740247
*/
public class CustomTextView extends AppCompatTextView {
private float emojiSize;
private boolean emoji;
public CustomTextView(Context context) {
super(context);
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
emoji = sharedpreferences.getBoolean(Helper.SET_DISPLAY_EMOJI, false);
}
public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
emoji = sharedpreferences.getBoolean(Helper.SET_DISPLAY_EMOJI, false);
final Paint.FontMetrics fontMetrics = getPaint().getFontMetrics();
final float defaultEmojiSize = fontMetrics.descent - fontMetrics.ascent;
if (attrs == null) {
emojiSize = defaultEmojiSize;
} else {
@SuppressLint("CustomViewStyleable") final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.EmojiTextView);
try {
emojiSize = a.getDimension(R.styleable.EmojiTextView_emojiSize, defaultEmojiSize);
} finally {
a.recycle();
}
}
setText(getText());
}
@Override
public void setText(final CharSequence rawText, final BufferType type) {
if (emoji) {
final CharSequence text = rawText == null ? "" : rawText;
final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text);
final Paint.FontMetrics fontMetrics = getPaint().getFontMetrics();
final float defaultEmojiSize = fontMetrics.descent - fontMetrics.ascent;
EmojiManager.getInstance().replaceWithImages(getContext(), spannableStringBuilder, emojiSize, defaultEmojiSize);
super.setText(spannableStringBuilder, type);
} else {
super.setText(rawText, type);
}
public CustomTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
/**
* sets the emoji size in pixels and automatically invalidates the text and renders it with the new size
*/
public final void setEmojiSize(@Px final int pixels) {
setEmojiSize(pixels, true);
}
/**
* sets the emoji size in pixels and automatically invalidates the text and renders it with the new size when {@code shouldInvalidate} is true
*/
public final void setEmojiSize(@Px final int pixels, final boolean shouldInvalidate) {
emojiSize = pixels;
if (shouldInvalidate) {
setText(getText());
}
}
/**
* sets the emoji size in pixels with the provided resource and automatically invalidates the text and renders it with the new size
*/
public final void setEmojiSizeRes(@DimenRes final int res) {
setEmojiSizeRes(res, true);
}
/**
* sets the emoji size in pixels with the provided resource and invalidates the text and renders it with the new size when {@code shouldInvalidate} is true
*/
public final void setEmojiSizeRes(@DimenRes final int res, final boolean shouldInvalidate) {
setEmojiSize(getResources().getDimensionPixelSize(res), shouldInvalidate);
}
}

View File

@ -1,4 +1,17 @@
package app.fedilab.android.helper;
public class Helper {
/* Copyright 2020 Thomas Schneider
*
* This file is a part of Fedilab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
public class Helper extends BaseHelper {
}

View File

@ -1,195 +1,33 @@
package app.fedilab.android.helper;
/* Copyright 2020 Thomas Schneider
*
* This file is a part of Fedilab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.TypedArray;
import android.graphics.Paint;
import android.os.Build;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import androidx.annotation.CallSuper;
import androidx.annotation.DimenRes;
import androidx.annotation.Px;
import androidx.core.view.inputmethod.EditorInfoCompat;
import androidx.core.view.inputmethod.InputConnectionCompat;
import androidx.core.view.inputmethod.InputContentInfoCompat;
import com.vanniktech.emoji.EmojiManager;
import com.vanniktech.emoji.emoji.Emoji;
import app.fedilab.android.R;
import static app.fedilab.android.activities.TootActivity.autocomplete;
public class MastalabAutoCompleteTextView extends androidx.appcompat.widget.AppCompatAutoCompleteTextView implements EmojiEditTextInterface {
private float emojiSize;
private boolean emoji;
private String[] imgTypeString;
private KeyBoardInputCallbackListener keyBoardInputCallbackListener;
final InputConnectionCompat.OnCommitContentListener callback =
new InputConnectionCompat.OnCommitContentListener() {
@Override
public boolean onCommitContent(InputContentInfoCompat inputContentInfo,
int flags, Bundle opts) {
// read and display inputContentInfo asynchronously
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 && (flags &
InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) {
try {
inputContentInfo.requestPermission();
} catch (Exception e) {
return false; // return false if failed
}
}
boolean supported = false;
for (final String mimeType : imgTypeString) {
if (inputContentInfo.getDescription().hasMimeType(mimeType)) {
supported = true;
break;
}
}
if (!supported) {
return false;
}
if (keyBoardInputCallbackListener != null) {
keyBoardInputCallbackListener.onCommitContent(inputContentInfo, flags, opts);
}
return true; // return true if succeeded
}
};
public class MastalabAutoCompleteTextView extends androidx.appcompat.widget.AppCompatAutoCompleteTextView {
public MastalabAutoCompleteTextView(Context context) {
super(context);
initView();
}
public MastalabAutoCompleteTextView(Context context, AttributeSet attrs) {
super(context, attrs);
final Paint.FontMetrics fontMetrics = getPaint().getFontMetrics();
final float defaultEmojiSize = fontMetrics.descent - fontMetrics.ascent;
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
emoji = sharedpreferences.getBoolean(Helper.SET_DISPLAY_EMOJI, false);
if (attrs == null) {
emojiSize = defaultEmojiSize;
} else {
@SuppressLint("CustomViewStyleable") final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.EmojiMultiAutoCompleteTextView);
try {
emojiSize = a.getDimension(R.styleable.EmojiMultiAutoCompleteTextView_emojiSize, defaultEmojiSize);
} finally {
a.recycle();
}
}
setText(getText());
initView();
}
public MastalabAutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView();
}
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
final InputConnection ic = super.onCreateInputConnection(outAttrs);
EditorInfoCompat.setContentMimeTypes(outAttrs,
imgTypeString);
return InputConnectionCompat.createWrapper(ic, outAttrs, callback);
}
private void initView() {
imgTypeString = new String[]{"image/png",
"image/gif",
"image/jpeg",
"image/webp"};
}
public void setKeyBoardInputCallbackListener(KeyBoardInputCallbackListener keyBoardInputCallbackListener) {
this.keyBoardInputCallbackListener = keyBoardInputCallbackListener;
}
@SuppressWarnings("unused")
public String[] getImgTypeString() {
return imgTypeString;
}
@SuppressWarnings("unused")
public void setImgTypeString(String[] imgTypeString) {
this.imgTypeString = imgTypeString;
}
@Override
@CallSuper
protected void onTextChanged(final CharSequence text, final int start, final int lengthBefore, final int lengthAfter) {
final Paint.FontMetrics fontMetrics = getPaint().getFontMetrics();
final float defaultEmojiSize = fontMetrics.descent - fontMetrics.ascent;
if (emoji && !autocomplete) {
EmojiManager.getInstance().replaceWithImages(getContext(), getText(), emojiSize, defaultEmojiSize);
}
}
@Override
public void backspace() {
final KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
dispatchKeyEvent(event);
}
@Override
public float getEmojiSize() {
return emojiSize;
}
@Override
public final void setEmojiSize(@Px final int pixels) {
setEmojiSize(pixels, true);
}
@Override
@CallSuper
public void input(final Emoji emoji) {
if (emoji != null && !autocomplete) {
final int start = getSelectionStart();
final int end = getSelectionEnd();
if (start < 0) {
append(emoji.getUnicode());
} else {
getText().replace(Math.min(start, end), Math.max(start, end), emoji.getUnicode(), 0, emoji.getUnicode().length());
}
}
}
@Override
public final void setEmojiSize(@Px final int pixels, final boolean shouldInvalidate) {
emojiSize = pixels;
if (shouldInvalidate && !autocomplete) {
setText(getText());
}
}
@Override
public final void setEmojiSizeRes(@DimenRes final int res) {
setEmojiSizeRes(res, true);
}
@Override
public final void setEmojiSizeRes(@DimenRes final int res, final boolean shouldInvalidate) {
setEmojiSize(getResources().getDimensionPixelSize(res), shouldInvalidate);
}
public interface KeyBoardInputCallbackListener {
void onCommitContent(InputContentInfoCompat inputContentInfo,
int flags, Bundle opts);
}
}

View File

@ -19,14 +19,12 @@ import androidx.core.content.ContextCompat;
import com.franmontiel.localechanger.LocaleChanger;
import com.google.android.material.snackbar.Snackbar;
import com.jaredrummler.cyanea.app.CyaneaAppCompatActivity;
import com.vanniktech.emoji.EmojiManager;
import com.vanniktech.emoji.one.EmojiOneProvider;
import org.jetbrains.annotations.NotNull;
import java.util.Timer;
import app.fedilab.android.helper.Helper;
import es.dmoral.toasty.Toasty;
/**
@ -35,17 +33,13 @@ import es.dmoral.toasty.Toasty;
*/
@SuppressLint("Registered")
public class BaseActivity extends CyaneaAppCompatActivity {
public class AllBaseActivity extends CyaneaAppCompatActivity {
public static final int READ_WRITE_STORAGE = 52;
public static Timer timer;
public static boolean canShowActionMode = true;
static {
Helper.installProvider();
EmojiManager.install(new EmojiOneProvider());
}
private ProgressDialog mProgressDialog;
@ -140,7 +134,7 @@ public class BaseActivity extends CyaneaAppCompatActivity {
if (view != null) {
Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show();
} else {
Toasty.info(BaseActivity.this, message, Toast.LENGTH_SHORT).show();
Toasty.info(AllBaseActivity.this, message, Toast.LENGTH_SHORT).show();
}
}

View File

@ -81,7 +81,7 @@ import app.fedilab.android.sqlite.StatusCacheDAO;
* Charts for owner notifications activity
*/
public class BaseOwnerNotificationChartsActivity extends BaseActivity implements OnRetrieveNotificationChartsInterface {
public class OwnerNotificationChartsActivity extends BaseActivity implements OnRetrieveNotificationChartsInterface {
private Button settings_time_from, settings_time_to;

View File

@ -134,7 +134,7 @@ import com.tonyodev.fetch2core.DownloadBlock;
import net.gotev.uploadservice.UploadService;
import net.gotev.uploadservice.okhttp.OkHttpStack;
import org.conscrypt.Conscrypt;
import org.jetbrains.annotations.NotNull;
import java.io.ByteArrayInputStream;
@ -156,7 +156,7 @@ import java.net.PasswordAuthentication;
import java.net.Proxy;
import java.net.URISyntaxException;
import java.nio.channels.FileChannel;
import java.security.Security;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@ -219,7 +219,6 @@ import app.fedilab.android.sqlite.Sqlite;
import app.fedilab.android.sqlite.StatusCacheDAO;
import app.fedilab.android.sqlite.TimelineCacheDAO;
import app.fedilab.android.webview.CustomWebview;
import app.fedilab.android.webview.ProxyHelper;
import es.dmoral.toasty.Toasty;
import info.guardianproject.netcipher.client.StrongBuilder;
import info.guardianproject.netcipher.client.StrongOkHttpClientBuilder;
@ -235,7 +234,6 @@ import static app.fedilab.android.activities.BaseMainActivity.regex_home;
import static app.fedilab.android.activities.BaseMainActivity.regex_local;
import static app.fedilab.android.activities.BaseMainActivity.regex_public;
import static app.fedilab.android.activities.BaseMainActivity.social;
import static app.fedilab.android.helper.Helper.NotifType.MENTION;
import static app.fedilab.android.sqlite.StatusCacheDAO.ARCHIVE_CACHE;
import static app.fedilab.android.sqlite.StatusCacheDAO.BOOKMARK_CACHE;
import static com.koushikdutta.async.util.StreamUtility.copyStream;
@ -248,7 +246,7 @@ import static com.koushikdutta.async.util.StreamUtility.copyStream;
*/
@SuppressWarnings({"WeakerAccess", "ResultOfMethodCallIgnored"})
public class Helper {
public class BaseHelper {
public static final String TAG = "mastodon_etalab";
@ -575,15 +573,15 @@ public class Helper {
private static boolean menuAccountsOpened = false;
public static int liveNotifType(Context context) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean live = sharedpreferences.getBoolean(Helper.SET_LIVE_NOTIFICATIONS, false);
boolean delayed = sharedpreferences.getBoolean(Helper.SET_DELAYED_NOTIFICATIONS, true);
SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
boolean live = sharedpreferences.getBoolean(SET_LIVE_NOTIFICATIONS, false);
boolean delayed = sharedpreferences.getBoolean(SET_DELAYED_NOTIFICATIONS, true);
if (delayed) {
return Helper.NOTIF_DELAYED;
return NOTIF_DELAYED;
} else if (live) {
return Helper.NOTIF_LIVE;
return NOTIF_LIVE;
} else {
return Helper.NOTIF_NONE;
return NOTIF_NONE;
}
}
@ -621,7 +619,7 @@ public class Helper {
* @return boolean
*/
public static boolean isLoggedIn(Context context) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
String prefKeyOauthTokenT = sharedpreferences.getString(PREF_KEY_OAUTH_TOKEN, null);
return (prefKeyOauthTokenT != null);
}
@ -632,11 +630,11 @@ public class Helper {
* @param activity Activity
*/
public static void logoutCurrentUser(Activity activity) {
SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences sharedpreferences = activity.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
//Current user
SQLiteDatabase db = Sqlite.getInstance(activity.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(activity));
String userId = sharedpreferences.getString(PREF_KEY_ID, null);
String instance = sharedpreferences.getString(PREF_INSTANCE, getLiveInstance(activity));
Account account = new AccountDAO(activity, db).getUniqAccount(userId, instance);
if (account != null) {
account.setToken("null");
@ -646,25 +644,25 @@ public class Helper {
Account newAccount = new AccountDAO(activity, db).getLastUsedAccount();
SharedPreferences.Editor editor = sharedpreferences.edit();
if (newAccount == null) {
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, null);
editor.putString(Helper.CLIENT_ID, null);
editor.putString(Helper.CLIENT_SECRET, null);
editor.putString(Helper.PREF_KEY_ID, null);
editor.putBoolean(Helper.PREF_IS_MODERATOR, false);
editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, false);
editor.putString(Helper.PREF_INSTANCE, null);
editor.putString(Helper.ID, null);
editor.putString(PREF_KEY_OAUTH_TOKEN, null);
editor.putString(CLIENT_ID, null);
editor.putString(CLIENT_SECRET, null);
editor.putString(PREF_KEY_ID, null);
editor.putBoolean(PREF_IS_MODERATOR, false);
editor.putBoolean(PREF_IS_ADMINISTRATOR, false);
editor.putString(PREF_INSTANCE, null);
editor.putString(ID, null);
editor.apply();
Intent loginActivity = new Intent(activity, LoginActivity.class);
activity.startActivity(loginActivity);
activity.finish();
} else {
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, newAccount.getToken());
editor.putString(Helper.PREF_KEY_ID, newAccount.getId());
editor.putString(Helper.PREF_INSTANCE, newAccount.getInstance().trim());
editor.putString(PREF_KEY_OAUTH_TOKEN, newAccount.getToken());
editor.putString(PREF_KEY_ID, newAccount.getId());
editor.putString(PREF_INSTANCE, newAccount.getInstance().trim());
editor.putBoolean(Helper.PREF_IS_MODERATOR, newAccount.isModerator());
editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, newAccount.isAdmin());
editor.putBoolean(PREF_IS_MODERATOR, newAccount.isModerator());
editor.putBoolean(PREF_IS_ADMINISTRATOR, newAccount.isAdmin());
editor.commit();
Intent changeAccount = new Intent(activity, MainActivity.class);
changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
@ -831,7 +829,7 @@ public class Helper {
public static void absoluteDateTimeReveal(final Context context, final TextView tvDate, final Date date) {
tvDate.setOnClickListener(v -> {
tvDate.setText(Helper.dateDiffFull(date));
tvDate.setText(dateDiffFull(date));
new CountDownTimer((5 * 1000), 1000) {
@ -839,7 +837,7 @@ public class Helper {
}
public void onFinish() {
tvDate.setText(Helper.dateDiff(context, date));
tvDate.setText(dateDiff(context, date));
}
}.start();
});
@ -939,8 +937,8 @@ public class Helper {
*/
public static void manageMessageStatusCode(Context context, int statusCode, API.StatusAction statusAction) {
String message = "";
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean display_confirm = sharedpreferences.getBoolean(Helper.SET_DISPLAY_CONFIRM, true);
final SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
boolean display_confirm = sharedpreferences.getBoolean(SET_DISPLAY_CONFIRM, true);
if (!display_confirm) {
return;
}
@ -1003,12 +1001,12 @@ public class Helper {
* @param url String download url
*/
public static void manageDownloads(final Context context, final String url) {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
final SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(SET_THEME, THEME_DARK);
int style;
if (theme == Helper.THEME_DARK) {
if (theme == THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK) {
} else if (theme == THEME_BLACK) {
style = R.style.DialogBlack;
} else {
style = R.style.Dialog;
@ -1047,7 +1045,7 @@ public class Helper {
* @param url String download url
*/
public static long manageDownloadsNoPopup(final Context context, final String url) {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
final SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
final DownloadManager.Request request;
try {
@ -1059,7 +1057,7 @@ public class Helper {
try {
final String fileName = URLUtil.guessFileName(url, null, null);
request.allowScanningByMediaScanner();
String myDir = sharedpreferences.getString(Helper.SET_FOLDER_RECORD, Environment.DIRECTORY_DOWNLOADS);
String myDir = sharedpreferences.getString(SET_FOLDER_RECORD, Environment.DIRECTORY_DOWNLOADS);
request.setDestinationInExternalPublicDir(myDir, fileName);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
DownloadManager dm = (DownloadManager) context.getSystemService(DOWNLOAD_SERVICE);
@ -1092,7 +1090,7 @@ public class Helper {
* @param message String message for the notification
*/
public static void notify_user(Context context, Account account, Intent intent, Bitmap icon, NotifType notifType, String title, String message) {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
final SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
// prepare intent which is triggered if the user click on the notification
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
int notificationId = (int) System.currentTimeMillis();
@ -1154,7 +1152,7 @@ public class Helper {
.setContentIntent(pIntent)
.setContentText(message);
int ledColour = Color.BLUE;
switch (sharedpreferences.getInt(Helper.SET_LED_COLOUR, Helper.LED_COLOUR)) {
switch (sharedpreferences.getInt(SET_LED_COLOUR, LED_COLOUR)) {
case 0: // BLUE
ledColour = Color.BLUE;
break;
@ -1182,7 +1180,7 @@ public class Helper {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel;
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (sharedpreferences.getBoolean(Helper.SET_NOTIF_SILENT, false)) {
if (sharedpreferences.getBoolean(SET_NOTIF_SILENT, false)) {
channel = new NotificationChannel(channelId, channelTitle, NotificationManager.IMPORTANCE_LOW);
channel.setSound(null, null);
channel.setVibrationPattern(new long[]{500, 500, 500});
@ -1190,7 +1188,7 @@ public class Helper {
channel.setLightColor(ledColour);
} else {
channel = new NotificationChannel(channelId, channelTitle, NotificationManager.IMPORTANCE_DEFAULT);
String soundUri = sharedpreferences.getString(Helper.SET_NOTIF_SOUND, ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.getPackageName() + "/" + R.raw.boop);
String soundUri = sharedpreferences.getString(SET_NOTIF_SOUND, ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.getPackageName() + "/" + R.raw.boop);
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
@ -1200,10 +1198,10 @@ public class Helper {
assert mNotificationManager != null;
mNotificationManager.createNotificationChannel(channel);
} else {
if (sharedpreferences.getBoolean(Helper.SET_NOTIF_SILENT, false)) {
if (sharedpreferences.getBoolean(SET_NOTIF_SILENT, false)) {
notificationBuilder.setVibrate(new long[]{500, 500, 500});
} else {
String soundUri = sharedpreferences.getString(Helper.SET_NOTIF_SOUND, ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.getPackageName() + "/" + R.raw.boop);
String soundUri = sharedpreferences.getString(SET_NOTIF_SOUND, ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.getPackageName() + "/" + R.raw.boop);
notificationBuilder.setSound(Uri.parse(soundUri));
}
notificationBuilder.setLights(ledColour, 500, 1000);
@ -1262,8 +1260,8 @@ public class Helper {
* @return String domain instance
*/
public static String getLiveInstance(Context context) {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
return sharedpreferences.getString(Helper.PREF_INSTANCE, null);
final SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
return sharedpreferences.getString(PREF_INSTANCE, null);
}
public static String getLiveInstanceWithProtocol(Context context) {
@ -1274,7 +1272,7 @@ public class Helper {
if (instance == null)
return null;
if (instance.endsWith(".onion")) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
String scheme = sharedpreferences.getString(SET_ONION_SCHEME + instance, "http");
return scheme + "://" + instance;
} else {
@ -1303,8 +1301,8 @@ public class Helper {
public static void menuAccounts(final Activity activity) {
final NavigationView navigationView = activity.findViewById(R.id.nav_view);
SharedPreferences mSharedPreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String currrentUserId = mSharedPreferences.getString(Helper.PREF_KEY_ID, null);
SharedPreferences mSharedPreferences = activity.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
String currrentUserId = mSharedPreferences.getString(PREF_KEY_ID, null);
final ImageView arrow = navigationView.getHeaderView(0).findViewById(R.id.owner_accounts);
if (currrentUserId == null)
return;
@ -1329,7 +1327,7 @@ public class Helper {
continue;
final MenuItem item = currentSubmenu.add("@" + account.getAcct());
item.setIcon(R.drawable.ic_person);
final SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
final SharedPreferences sharedpreferences = activity.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
boolean disableGif = sharedpreferences.getBoolean(SET_DISABLE_GIF, false);
String url = !disableGif ? account.getAvatar() : account.getAvatar_static();
if (url.startsWith("/")) {
@ -1538,10 +1536,10 @@ public class Helper {
if (!mainMenuItem.isNav_scheduled()) {
menu.findItem(R.id.nav_scheduled).setVisible(false);
}
final SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(activity));
boolean display_admin_menu = sharedpreferences.getBoolean(Helper.SET_DISPLAY_ADMIN_MENU + userId + instance, false);
final SharedPreferences sharedpreferences = activity.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
String userId = sharedpreferences.getString(PREF_KEY_ID, null);
String instance = sharedpreferences.getString(PREF_INSTANCE, getLiveInstance(activity));
boolean display_admin_menu = sharedpreferences.getBoolean(SET_DISPLAY_ADMIN_MENU + userId + instance, false);
if (!display_admin_menu) {
menu.findItem(R.id.nav_administration).setVisible(false);
}
@ -1568,7 +1566,7 @@ public class Helper {
@SuppressLint("ApplySharedPref")
public static void changeUser(Activity activity, String userID, String instance, boolean notificationIntent) {
final SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
final SharedPreferences sharedpreferences = activity.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
final NavigationView navigationView = activity.findViewById(R.id.nav_view);
navigationView.getMenu().clear();
MainActivity.lastNotificationId = null;
@ -1582,7 +1580,7 @@ public class Helper {
if (account == null)
return;
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
String token = sharedpreferences.getString(PREF_KEY_OAUTH_TOKEN, null);
if (!account.getToken().equals(token)) {
FragmentManager fm = activity.getFragmentManager();
for (int i = 0; i < fm.getBackStackEntryCount(); ++i) {
@ -1591,11 +1589,11 @@ public class Helper {
}
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, account.getToken());
editor.putString(Helper.PREF_KEY_ID, account.getId());
editor.putString(Helper.PREF_INSTANCE, account.getInstance().trim());
editor.putBoolean(Helper.PREF_IS_MODERATOR, account.isModerator());
editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, account.isAdmin());
editor.putString(PREF_KEY_OAUTH_TOKEN, account.getToken());
editor.putString(PREF_KEY_ID, account.getId());
editor.putString(PREF_INSTANCE, account.getInstance().trim());
editor.putBoolean(PREF_IS_MODERATOR, account.isModerator());
editor.putBoolean(PREF_IS_ADMINISTRATOR, account.isAdmin());
editor.commit();
Intent changeAccount = new Intent(activity, MainActivity.class);
changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
@ -1605,8 +1603,8 @@ public class Helper {
}
public static int getNotificationIcon(Context context) {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String logo = sharedpreferences.getString(Helper.LOGO_LAUNCHER, "bubbles");
final SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
String logo = sharedpreferences.getString(LOGO_LAUNCHER, "bubbles");
switch (logo) {
case "fediverse":
return R.drawable.ic_plain_fediverse;
@ -1624,8 +1622,8 @@ public class Helper {
}
public static int getMainLogo(Context context) {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String logo = sharedpreferences.getString(Helper.LOGO_LAUNCHER, "bubbles");
final SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
String logo = sharedpreferences.getString(LOGO_LAUNCHER, "bubbles");
switch (logo) {
case "fediverse":
return R.drawable.fedilab_logo_fediverse;
@ -1665,7 +1663,7 @@ public class Helper {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
int l_c = prefs.getInt("theme_link_color", -1);
if (l_c == -1) {
l_c = ThemeHelper.getAttColor(context, R.attr.linkColor);
l_c = ThemegetAttColor(context, R.attr.linkColor);
}
final int link_color = l_c;
SpannableString spannableString = new SpannableString(cw_mention);
@ -1730,9 +1728,9 @@ public class Helper {
TextView username = headerLayout.findViewById(R.id.username);
TextView displayedName = headerLayout.findViewById(R.id.displayedName);
LinearLayout more_account_container = headerLayout.findViewById(R.id.more_account_container);
SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences sharedpreferences = activity.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
int theme = sharedpreferences.getInt(SET_THEME, THEME_DARK);
ImageView icon;
@ -1743,11 +1741,11 @@ public class Helper {
boolean disableGif = sharedpreferences.getBoolean(SET_DISABLE_GIF, false);
if (accounts != null && accounts.size() > 1) {
FloatingActionButton.LayoutParams layoutparmansAcc = new FloatingActionButton.LayoutParams((int) Helper.convertDpToPixel(37, activity), (int) Helper.convertDpToPixel(37, activity));
FloatingActionButton.LayoutParams layoutparmanImgAcc = new FloatingActionButton.LayoutParams((int) Helper.convertDpToPixel(35, activity), (int) Helper.convertDpToPixel(35, activity));
FloatingActionButton.LayoutParams layoutparmansAcc = new FloatingActionButton.LayoutParams((int) convertDpToPixel(37, activity), (int) convertDpToPixel(37, activity));
FloatingActionButton.LayoutParams layoutparmanImgAcc = new FloatingActionButton.LayoutParams((int) convertDpToPixel(35, activity), (int) convertDpToPixel(35, activity));
MenuFloating actionButtonAcc = null;
SharedPreferences mSharedPreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String currrentUserId = mSharedPreferences.getString(Helper.PREF_KEY_ID, null);
SharedPreferences mSharedPreferences = activity.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
String currrentUserId = mSharedPreferences.getString(PREF_KEY_ID, null);
for (final Account accountChoice : accounts) {
if (!accountChoice.getAvatar().startsWith("http"))
accountChoice.setAvatar("https://" + accountChoice.getInstance() + accountChoice.getAvatar());
@ -1888,11 +1886,11 @@ public class Helper {
subActionButtonAcc.setOnClickListener(v -> {
if (!accountChoice.getToken().equals("null")) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, accountChoice.getToken());
editor.putString(Helper.PREF_KEY_ID, accountChoice.getId());
editor.putString(Helper.PREF_INSTANCE, accountChoice.getInstance().trim());
editor.putBoolean(Helper.PREF_IS_MODERATOR, accountChoice.isModerator());
editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, accountChoice.isAdmin());
editor.putString(PREF_KEY_OAUTH_TOKEN, accountChoice.getToken());
editor.putString(PREF_KEY_ID, accountChoice.getId());
editor.putString(PREF_INSTANCE, accountChoice.getInstance().trim());
editor.putBoolean(PREF_IS_MODERATOR, accountChoice.isModerator());
editor.putBoolean(PREF_IS_ADMINISTRATOR, accountChoice.isAdmin());
editor.commit();
if (accountChoice.getSocial() != null && accountChoice.getSocial().equals("PEERTUBE"))
Toasty.info(activity, activity.getString(R.string.toast_account_changed, "@" + accountChoice.getAcct()), Toast.LENGTH_LONG).show();
@ -1941,11 +1939,11 @@ public class Helper {
if (!currrentUserId.equals(accountChoice.getId())) {
if (!accountChoice.getToken().equals("null")) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, accountChoice.getToken());
editor.putString(Helper.PREF_KEY_ID, accountChoice.getId());
editor.putString(Helper.PREF_INSTANCE, accountChoice.getInstance().trim());
editor.putBoolean(Helper.PREF_IS_MODERATOR, accountChoice.isModerator());
editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, accountChoice.isAdmin());
editor.putString(PREF_KEY_OAUTH_TOKEN, accountChoice.getToken());
editor.putString(PREF_KEY_ID, accountChoice.getId());
editor.putString(PREF_INSTANCE, accountChoice.getInstance().trim());
editor.putBoolean(PREF_IS_MODERATOR, accountChoice.isModerator());
editor.putBoolean(PREF_IS_ADMINISTRATOR, accountChoice.isAdmin());
editor.commit();
Intent changeAccount = new Intent(activity, MainActivity.class);
changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
@ -1965,7 +1963,7 @@ public class Helper {
}
if (account == null) {
Helper.logoutCurrentUser(activity);
logoutCurrentUser(activity);
Intent myIntent = new Intent(activity, LoginActivity.class);
Toasty.error(activity, activity.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
activity.startActivity(myIntent);
@ -1979,7 +1977,7 @@ public class Helper {
loadGiF(activity, account, profilePicture);
String urlHeader = !disableGif ? account.getHeader() : account.getHeader_static();
if (urlHeader.startsWith("/")) {
urlHeader = Helper.getLiveInstanceWithProtocol(activity) + account.getHeader();
urlHeader = getLiveInstanceWithProtocol(activity) + account.getHeader();
}
if (!urlHeader.contains("missing.png")) {
ImageView backgroundImage = headerLayout.findViewById(R.id.back_ground_image);
@ -2114,7 +2112,7 @@ public class Helper {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
int l_c = prefs.getInt("theme_link_color", -1);
if (l_c == -1) {
l_c = ThemeHelper.getAttColor(context, R.attr.linkColor);
l_c = ThemegetAttColor(context, R.attr.linkColor);
}
final int link_color = l_c;
while (matcher.find()) {
@ -2127,7 +2125,7 @@ public class Helper {
spannableString.setSpan(new ClickableSpan() {
@Override
public void onClick(@NotNull View textView) {
Helper.openBrowser(context, url);
openBrowser(context, url);
}
@Override
@ -2221,7 +2219,7 @@ public class Helper {
}
}
matcher = Helper.xmppPattern.matcher(spannableString);
matcher = xmppPattern.matcher(spannableString);
while (matcher.find()) {
int matchStart = matcher.start(0);
int matchEnd = matcher.end();
@ -2262,8 +2260,8 @@ public class Helper {
} else {
webView = rootView.findViewById(webviewId);
}
final SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean javascript = sharedpreferences.getBoolean(Helper.SET_JAVASCRIPT, true);
final SharedPreferences sharedpreferences = activity.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
boolean javascript = sharedpreferences.getBoolean(SET_JAVASCRIPT, true);
webView.getSettings().setJavaScriptEnabled(javascript);
webView.getSettings().setUseWideViewPort(true);
@ -2275,10 +2273,10 @@ public class Helper {
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setSupportMultipleWindows(false);
webView.getSettings().setMediaPlaybackRequiresUserGesture(true);
String user_agent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, Helper.USER_AGENT);
String user_agent = sharedpreferences.getString(SET_CUSTOM_USER_AGENT, USER_AGENT);
webView.getSettings().setUserAgentString(user_agent);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
boolean cookies = sharedpreferences.getBoolean(Helper.SET_COOKIES, false);
boolean cookies = sharedpreferences.getBoolean(SET_COOKIES, false);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptThirdPartyCookies(webView, cookies);
}
@ -2292,11 +2290,11 @@ public class Helper {
return Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
}
});
boolean proxyEnabled = sharedpreferences.getBoolean(Helper.SET_PROXY_ENABLED, false);
boolean proxyEnabled = sharedpreferences.getBoolean(SET_PROXY_ENABLED, false);
if (proxyEnabled) {
String host = sharedpreferences.getString(Helper.SET_PROXY_HOST, "127.0.0.1");
int port = sharedpreferences.getInt(Helper.SET_PROXY_PORT, 8118);
ProxyHelper.setProxy(activity, webView, host, port, WebviewActivity.class.getName());
String host = sharedpreferences.getString(SET_PROXY_HOST, "127.0.0.1");
int port = sharedpreferences.getInt(SET_PROXY_PORT, 8118);
ProxysetProxy(activity, webView, host, port, WebviewActivity.class.getName());
}
return webView;
@ -2395,11 +2393,11 @@ public class Helper {
*/
public static boolean compareDate(Context context, String newDate, boolean shouldBeGreater) {
String dateRef;
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
final SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
if (shouldBeGreater) {
dateRef = sharedpreferences.getString(Helper.SET_TIME_FROM, "07:00");
dateRef = sharedpreferences.getString(SET_TIME_FROM, "07:00");
} else {
dateRef = sharedpreferences.getString(Helper.SET_TIME_TO, "22:00");
dateRef = sharedpreferences.getString(SET_TIME_TO, "22:00");
}
try {
Locale userLocale;
@ -2430,16 +2428,16 @@ public class Helper {
* @return boolean
*/
public static boolean canNotify(Context context) {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true);
final SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
boolean notify = sharedpreferences.getBoolean(SET_NOTIFY, true);
if (!notify)
return false;
boolean enable_time_slot = sharedpreferences.getBoolean(Helper.SET_ENABLE_TIME_SLOT, true);
boolean enable_time_slot = sharedpreferences.getBoolean(SET_ENABLE_TIME_SLOT, true);
if (!enable_time_slot)
return true;
String dateIni = sharedpreferences.getString(Helper.SET_TIME_FROM, "07:00");
String dateEnd = sharedpreferences.getString(Helper.SET_TIME_TO, "22:00");
int notification = sharedpreferences.getInt(Helper.SET_NOTIFICATION_ACTION, Helper.ACTION_ACTIVE);
String dateIni = sharedpreferences.getString(SET_TIME_FROM, "07:00");
String dateEnd = sharedpreferences.getString(SET_TIME_TO, "22:00");
int notification = sharedpreferences.getInt(SET_NOTIFICATION_ACTION, ACTION_ACTIVE);
Calendar now = Calendar.getInstance();
int hour = now.get(Calendar.HOUR_OF_DAY);
int minute = now.get(Calendar.MINUTE);
@ -2459,9 +2457,9 @@ public class Helper {
Date currentDateD = formatter.parse(currentDate);
boolean canNotify = false;
assert currentDateD != null;
if (currentDateD.before(dateEndD) && currentDateD.after(dateIniD) && notification == Helper.ACTION_ACTIVE)
if (currentDateD.before(dateEndD) && currentDateD.after(dateIniD) && notification == ACTION_ACTIVE)
canNotify = true;
else if (currentDateD.after(dateEndD) && currentDateD.before(dateIniD) && notification == Helper.ACTION_SILENT)
else if (currentDateD.after(dateEndD) && currentDateD.before(dateIniD) && notification == ACTION_SILENT)
canNotify = true;
return canNotify;
} catch (java.text.ParseException e) {
@ -2927,11 +2925,11 @@ public class Helper {
*/
public static void switchLayout(Activity activity) {
//Check if the class calling the method is an instance of MainActivity
final SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
final SharedPreferences sharedpreferences = activity.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
final NavigationView navigationView = activity.findViewById(R.id.nav_view);
TabLayout tableLayout = activity.findViewById(R.id.tabLayout);
String userID = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
String userID = sharedpreferences.getString(PREF_KEY_ID, null);
String instance = sharedpreferences.getString(PREF_INSTANCE, null);
SQLiteDatabase db = Sqlite.getInstance(activity.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
Account account = new AccountDAO(activity, db).getUniqAccount(userID, instance);
if (account != null) {
@ -2995,11 +2993,11 @@ public class Helper {
public static void loadGiF(final Context context, Account account, final ImageView imageView) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
boolean disableGif = sharedpreferences.getBoolean(SET_DISABLE_GIF, false);
String url = disableGif ? account.getAvatar_static() : account.getAvatar();
if (url != null && url.startsWith("/")) {
url = Helper.getLiveInstanceWithProtocol(context) + url;
url = getLiveInstanceWithProtocol(context) + url;
}
if (!(context instanceof MainApplication) && ((Activity) context).isFinishing()) {
return;
@ -3050,10 +3048,10 @@ public class Helper {
public static void loadGiF(final Context context, String url, final ImageView imageView) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
boolean disableGif = sharedpreferences.getBoolean(SET_DISABLE_GIF, false);
if (url != null && url.startsWith("/")) {
url = Helper.getLiveInstanceWithProtocol(context) + url;
url = getLiveInstanceWithProtocol(context) + url;
}
if (!(context instanceof MainApplication) && ((Activity) context).isFinishing()) {
return;
@ -3132,8 +3130,8 @@ public class Helper {
* @param url String url to open
*/
public static void openBrowser(Context context, String url) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
boolean embedded_browser = sharedpreferences.getBoolean(Helper.SET_EMBEDDED_BROWSER, true);
SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, android.content.Context.MODE_PRIVATE);
boolean embedded_browser = sharedpreferences.getBoolean(SET_EMBEDDED_BROWSER, true);
if (embedded_browser) {
Intent intent = new Intent(context, WebviewActivity.class);
Bundle b = new Bundle();
@ -3145,7 +3143,7 @@ public class Helper {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
} else {
boolean custom_tabs = sharedpreferences.getBoolean(Helper.SET_CUSTOM_TABS, true);
boolean custom_tabs = sharedpreferences.getBoolean(SET_CUSTOM_TABS, true);
if (custom_tabs) {
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
@ -3169,22 +3167,7 @@ public class Helper {
}
}
public static void installProvider() {
boolean patch_provider = true;
try {
Context ctx = MainApplication.getApp();
SharedPreferences sharedpreferences = ctx.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
patch_provider = sharedpreferences.getBoolean(Helper.SET_SECURITY_PROVIDER, true);
} catch (Exception ignored) {
}
if (patch_provider) {
try {
Security.insertProviderAt(Conscrypt.newProvider(), 1);
} catch (Exception ignored) {
}
}
}
public static String compressImagePath(Context context, android.net.Uri uriFile) {
@ -3218,8 +3201,8 @@ public class Helper {
matrix.preRotate(rotationDegree);
}
}
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
boolean compressed = sharedpreferences.getBoolean(Helper.SET_PICTURE_COMPRESSED, true);
SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, android.content.Context.MODE_PRIVATE);
boolean compressed = sharedpreferences.getBoolean(SET_PICTURE_COMPRESSED, true);
if (compressed) {
try {
return SiliCompressor.with(context).compress(uriFile.toString(), destinationDirectory);
@ -3227,8 +3210,8 @@ public class Helper {
}
}
} else {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
boolean compressed = sharedpreferences.getBoolean(Helper.SET_VIDEO_COMPRESSED, true);
SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, android.content.Context.MODE_PRIVATE);
boolean compressed = sharedpreferences.getBoolean(SET_VIDEO_COMPRESSED, true);
if (compressed) {
try {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
@ -3284,8 +3267,8 @@ public class Helper {
matrix.preRotate(rotationDegree);
}
}
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
boolean compressed = sharedpreferences.getBoolean(Helper.SET_PICTURE_COMPRESSED, true);
SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, android.content.Context.MODE_PRIVATE);
boolean compressed = sharedpreferences.getBoolean(SET_PICTURE_COMPRESSED, true);
if (compressed) {
try {
String filePath = SiliCompressor.with(context).compress(uriFile.toString(), destinationDirectory);
@ -3321,8 +3304,8 @@ public class Helper {
e.printStackTrace();
}
} else {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
boolean compressed = sharedpreferences.getBoolean(Helper.SET_VIDEO_COMPRESSED, true);
SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, android.content.Context.MODE_PRIVATE);
boolean compressed = sharedpreferences.getBoolean(SET_VIDEO_COMPRESSED, true);
if (compressed) {
String filePath = null;
try {
@ -3495,10 +3478,10 @@ public class Helper {
@SuppressWarnings({"WeakerAccess", "unused"})
public static void largeLog(String content) {
if (content.length() > 4000) {
Log.v(Helper.TAG, content.substring(0, 4000));
Log.v(TAG, content.substring(0, 4000));
largeLog(content.substring(4000));
} else {
Log.v(Helper.TAG, content);
Log.v(TAG, content);
}
}
@ -3697,8 +3680,8 @@ public class Helper {
public static int languageSpinnerPosition(Context context) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
String defaultLocaleString = sharedpreferences.getString(Helper.SET_DEFAULT_LOCALE_NEW, "NOT_DEFINED");
SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, android.content.Context.MODE_PRIVATE);
String defaultLocaleString = sharedpreferences.getString(SET_DEFAULT_LOCALE_NEW, "NOT_DEFINED");
switch (defaultLocaleString) {
case "en":
return 1;
@ -3827,8 +3810,8 @@ public class Helper {
if (original_content == null)
return original_content;
String cleaned_content = original_content;
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean utm_parameters = sharedpreferences.getBoolean(Helper.SET_FILTER_UTM, true);
final SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
boolean utm_parameters = sharedpreferences.getBoolean(SET_FILTER_UTM, true);
if (utm_parameters) {
for (String utm : UTM_PARAMS) {
cleaned_content = cleaned_content.replaceAll("&amp;" + utm + "=[0-9a-zA-Z._-]*", "");
@ -3894,19 +3877,19 @@ public class Helper {
if (download.getFileUri().getPath() != null) {
String url = download.getUrl();
final String fileName = URLUtil.guessFileName(url, null, null);
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String mime = Helper.getMimeType(url);
final SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
String mime = getMimeType(url);
File file = new File(download.getFileUri().getPath());
final Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
Uri uri = Uri.parse("file://" + file.getAbsolutePath());
intent.setDataAndType(uri, mime);
SQLiteDatabase db = Sqlite.getInstance(context.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(context));
String userId = sharedpreferences.getString(PREF_KEY_ID, null);
String instance = sharedpreferences.getString(PREF_INSTANCE, getLiveInstance(context));
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
Helper.notify_user(context, account, intent, BitmapFactory.decodeResource(context.getResources(),
R.mipmap.ic_launcher_bubbles), Helper.NotifType.STORE, context.getString(R.string.save_over), context.getString(R.string.download_from, fileName));
notify_user(context, account, intent, BitmapFactory.decodeResource(context.getResources(),
R.mipmap.ic_launcher_bubbles), NotifType.STORE, context.getString(R.string.save_over), context.getString(R.string.download_from, fileName));
}
}
@ -3943,7 +3926,7 @@ public class Helper {
.into(new CustomTarget<File>() {
@Override
public void onResourceReady(@NotNull File file, Transition<? super File> transition) {
Helper.notifyDownload(context, url, file, share);
notifyDownload(context, url, file, share);
}
@Override
@ -3964,8 +3947,8 @@ public class Helper {
private static void notifyDownload(Context context, String url, File sourceFile, boolean share) {
final String fileName = URLUtil.guessFileName(url, null, null);
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
final String targeted_folder = sharedpreferences.getString(Helper.SET_FOLDER_RECORD, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
final SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
final String targeted_folder = sharedpreferences.getString(SET_FOLDER_RECORD, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
FileInputStream fis = null;
FileOutputStream fos = null;
@ -3980,17 +3963,17 @@ public class Helper {
out = fos.getChannel();
long size = in.size();
in.transferTo(0, size, out);
String mime = Helper.getMimeType(url);
String mime = getMimeType(url);
final Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(backupFile);
intent.setDataAndType(uri, mime);
SQLiteDatabase db = Sqlite.getInstance(context.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(context));
String userId = sharedpreferences.getString(PREF_KEY_ID, null);
String instance = sharedpreferences.getString(PREF_INSTANCE, getLiveInstance(context));
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
if (!share) {
Helper.notify_user(context, account, intent, BitmapFactory.decodeResource(context.getResources(),
notify_user(context, account, intent, BitmapFactory.decodeResource(context.getResources(),
R.mipmap.ic_launcher_bubbles), NotifType.STORE, context.getString(R.string.save_over), context.getString(R.string.download_from, fileName));
Toasty.success(context, context.getString(R.string.save_over), Toasty.LENGTH_LONG).show();
} else {
@ -4060,8 +4043,8 @@ public class Helper {
}
public static OkHttpClient getHttpClient(Context context) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean proxyEnabled = sharedpreferences.getBoolean(Helper.SET_PROXY_ENABLED, false);
SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
boolean proxyEnabled = sharedpreferences.getBoolean(SET_PROXY_ENABLED, false);
int cacheSize = 30 * 1024 * 1024;
Cache cache = new Cache(context.getCacheDir(), cacheSize);
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder()
@ -4074,16 +4057,16 @@ public class Helper {
.cache(cache);
if (proxyEnabled) {
Proxy proxy;
int type = sharedpreferences.getInt(Helper.SET_PROXY_TYPE, 0);
int type = sharedpreferences.getInt(SET_PROXY_TYPE, 0);
try {
String host = sharedpreferences.getString(Helper.SET_PROXY_HOST, "127.0.0.1");
int port = sharedpreferences.getInt(Helper.SET_PROXY_PORT, 8118);
String host = sharedpreferences.getString(SET_PROXY_HOST, "127.0.0.1");
int port = sharedpreferences.getInt(SET_PROXY_PORT, 8118);
if (type == 0)
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port));
else
proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(host, port));
final String login = sharedpreferences.getString(Helper.SET_PROXY_LOGIN, null);
final String pwd = sharedpreferences.getString(Helper.SET_PROXY_PASSWORD, null);
final String login = sharedpreferences.getString(SET_PROXY_LOGIN, null);
final String pwd = sharedpreferences.getString(SET_PROXY_PASSWORD, null);
if (login != null) {
Authenticator authenticator = new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
@ -4155,12 +4138,12 @@ public class Helper {
if (domains == null) {
return;
}
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
final SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(SET_THEME, THEME_DARK);
int style;
if (theme == Helper.THEME_DARK) {
if (theme == THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK) {
} else if (theme == THEME_BLACK) {
style = R.style.DialogBlack;
} else {
style = R.style.Dialog;
@ -4223,10 +4206,10 @@ public class Helper {
Uri uri = Uri.fromFile(new File(filename));
intent.setDataAndType(uri, "text/csv");
SQLiteDatabase db = Sqlite.getInstance(context.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(context));
String userId = sharedpreferences.getString(PREF_KEY_ID, null);
String instance = sharedpreferences.getString(PREF_INSTANCE, getLiveInstance(context));
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
Helper.notify_user(context, account, intent, BitmapFactory.decodeResource(context.getResources(),
notify_user(context, account, intent, BitmapFactory.decodeResource(context.getResources(),
R.mipmap.ic_launcher_bubbles), NotifType.STORE, context.getString(R.string.muted_instance_exported), context.getString(R.string.download_from, backupDBPath));
}
}.start();
@ -4243,12 +4226,12 @@ public class Helper {
public static void importInstanceBlock(Context context, HashMap<String, String> instances) {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
final SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(SET_THEME, THEME_DARK);
int style;
if (theme == Helper.THEME_DARK) {
if (theme == THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK) {
} else if (theme == THEME_BLACK) {
style = R.style.DialogBlack;
} else {
style = R.style.Dialog;
@ -4333,13 +4316,13 @@ public class Helper {
}
public static void startStreaming(Context context) {
int liveNotifications = Helper.liveNotifType(context);
int liveNotifications = liveNotifType(context);
Intent streamingIntent = null;
switch (liveNotifications) {
case Helper.NOTIF_LIVE:
case NOTIF_LIVE:
streamingIntent = new Intent(context, LiveNotificationService.class);
break;
case Helper.NOTIF_DELAYED:
case NOTIF_DELAYED:
streamingIntent = new Intent(context, LiveNotificationDelayedService.class);
break;
}
@ -4356,13 +4339,13 @@ public class Helper {
}
public static boolean canFetchList(Context context, Account account) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String lastDateListRefresh = sharedpreferences.getString(Helper.LAST_DATE_LIST_FETCH + account.getId() + account.getInstance(), null);
SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
String lastDateListRefresh = sharedpreferences.getString(LAST_DATE_LIST_FETCH + account.getId() + account.getInstance(), null);
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.HOUR, -24);
Date dateAllowed = cal.getTime();
Date lastRefresh = Helper.stringToDate(context, lastDateListRefresh);
Date lastRefresh = stringToDate(context, lastDateListRefresh);
return (lastRefresh == null || lastRefresh.before(dateAllowed));
}
@ -4407,8 +4390,8 @@ public class Helper {
public static void makeEmojis(Context context, View customTextView, SpannableString contentSpan, List<Emojis> emojis) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false);
SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
boolean disableAnimatedEmoji = sharedpreferences.getBoolean(SET_DISABLE_ANIMATED_EMOJI, false);
if (emojis != null && emojis.size() > 0) {
for (final Emojis emoji : emojis) {
@ -4427,7 +4410,7 @@ public class Helper {
if (endPosition <= contentSpan.toString().length() && endPosition >= startPosition) {
ImageSpan imageSpan;
try {
resource.setBounds(0, 0, (int) Helper.convertDpToPixel(20, context), (int) Helper.convertDpToPixel(20, context));
resource.setBounds(0, 0, (int) convertDpToPixel(20, context), (int) convertDpToPixel(20, context));
resource.setVisible(true, true);
imageSpan = new ImageSpan(resource);
contentSpan.setSpan(
@ -4493,7 +4476,7 @@ public class Helper {
@Override
protected Void doInBackground(Void... params) {
long sizeCache = Helper.cacheSize(contextReference.get().getCacheDir().getParentFile());
long sizeCache = cacheSize(contextReference.get().getCacheDir().getParentFile());
cacheSize = 0;
if (sizeCache > 0) {
cacheSize = (float) sizeCache / 1000000.0f;
@ -4504,11 +4487,11 @@ public class Helper {
@Override
protected void onPostExecute(Void result) {
int style;
SharedPreferences sharedpreferences = contextReference.get().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
final int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if (theme == Helper.THEME_DARK) {
SharedPreferences sharedpreferences = contextReference.get().getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
final int theme = sharedpreferences.getInt(SET_THEME, THEME_DARK);
if (theme == THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK) {
} else if (theme == THEME_BLACK) {
style = R.style.DialogBlack;
} else {
style = R.style.Dialog;
@ -4533,7 +4516,7 @@ public class Helper {
String path = Objects.requireNonNull(contextReference.get().getCacheDir().getParentFile()).getPath();
File dir = new File(path);
if (dir.isDirectory()) {
Helper.deleteDir(dir);
deleteDir(dir);
}
SQLiteDatabase db = Sqlite.getInstance(contextReference.get().getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
new StatusCacheDAO(contextReference.get(), db).removeDuplicate();