(misc) fix settings bugs
known issue is custom repo can't be added Signed-off-by: androidacy-user <opensource@androidacy.com>pull/27/head
parent
a96cee7e2e
commit
8ba2d2d98e
@ -1,47 +1,28 @@
|
|||||||
package com.fox2code.mmm.settings;
|
package com.fox2code.mmm.settings;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.preference.PreferenceDataStore;
|
import androidx.preference.PreferenceDataStore;
|
||||||
import androidx.security.crypto.EncryptedSharedPreferences;
|
|
||||||
import androidx.security.crypto.MasterKey;
|
|
||||||
|
|
||||||
import com.fox2code.mmm.MainApplication;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.security.GeneralSecurityException;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class EncryptedPreferenceDataStore extends PreferenceDataStore {
|
import timber.log.Timber;
|
||||||
|
|
||||||
private static final String CONFIG_FILE_NAME = "mmm";
|
public class SharedPreferenceDataStore extends PreferenceDataStore {
|
||||||
@SuppressLint("StaticFieldLeak")
|
|
||||||
private static EncryptedPreferenceDataStore mInstance;
|
|
||||||
private SharedPreferences mSharedPreferences;
|
|
||||||
|
|
||||||
EncryptedPreferenceDataStore(Context context) {
|
private final SharedPreferences mSharedPreferences;
|
||||||
try {
|
|
||||||
MasterKey mainKeyAlias;
|
|
||||||
try {
|
|
||||||
mainKeyAlias = new MasterKey.Builder(MainApplication.getINSTANCE().getApplicationContext()).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build();
|
|
||||||
} catch (GeneralSecurityException | IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
mSharedPreferences = EncryptedSharedPreferences.create(MainApplication.getINSTANCE().getApplicationContext(), "mmm", mainKeyAlias, EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Fallback
|
|
||||||
mSharedPreferences = context.getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_PRIVATE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PreferenceDataStore getInstance() {
|
public SharedPreferenceDataStore(@NonNull SharedPreferences sharedPreferences) {
|
||||||
if (mInstance == null) {
|
Timber.d("SharedPreferenceDataStore: %s", sharedPreferences);
|
||||||
mInstance = new EncryptedPreferenceDataStore(MainApplication.getINSTANCE().getApplicationContext());
|
mSharedPreferences = sharedPreferences;
|
||||||
}
|
}
|
||||||
return mInstance;
|
|
||||||
|
@NonNull
|
||||||
|
public SharedPreferences getSharedPreferences() {
|
||||||
|
Timber.d("getSharedPreferences: %s", mSharedPreferences);
|
||||||
|
return mSharedPreferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
@ -1,72 +0,0 @@
|
|||||||
package com.fox2code.mmm.utils;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
|
|
||||||
import androidx.annotation.IdRes;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import eightbitlab.com.blurview.BlurAlgorithm;
|
|
||||||
import eightbitlab.com.blurview.BlurView;
|
|
||||||
import eightbitlab.com.blurview.RenderEffectBlur;
|
|
||||||
import eightbitlab.com.blurview.RenderScriptBlur;
|
|
||||||
|
|
||||||
public enum BlurUtils {
|
|
||||||
;
|
|
||||||
|
|
||||||
public static void setupBlur(BlurView blurView, Activity activity, @IdRes int viewId) {
|
|
||||||
setupBlur(blurView, activity, activity.findViewById(viewId));
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public static void setupBlur(BlurView blurView, Activity activity, ViewGroup rootView) {
|
|
||||||
blurView.setupWith(rootView, new BlurAlgorithmWrapper(
|
|
||||||
Build.VERSION.SDK_INT < Build.VERSION_CODES.S ?
|
|
||||||
new RenderScriptBlur(blurView.getContext()) : new RenderEffectBlur()))
|
|
||||||
.setFrameClearDrawable(activity.getWindow().getDecorView().getBackground())
|
|
||||||
.setBlurRadius(4F).setBlurAutoUpdate(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allow to have fancy blur, use more performance.
|
|
||||||
private static final class BlurAlgorithmWrapper implements BlurAlgorithm {
|
|
||||||
private final BlurAlgorithm algorithm;
|
|
||||||
|
|
||||||
private BlurAlgorithmWrapper(BlurAlgorithm algorithm) {
|
|
||||||
this.algorithm = algorithm;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Bitmap blur(Bitmap bitmap, float blurRadius) {
|
|
||||||
return this.algorithm.blur(bitmap, blurRadius * 6f);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void destroy() {
|
|
||||||
this.algorithm.destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canModifyBitmap() {
|
|
||||||
return this.algorithm.canModifyBitmap();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Bitmap.Config getSupportedBitmapConfig() {
|
|
||||||
return this.algorithm.getSupportedBitmapConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float scaleFactor() {
|
|
||||||
return 1f;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(@NonNull Canvas canvas, @NonNull Bitmap bitmap) {
|
|
||||||
this.algorithm.render(canvas, bitmap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue