Merge branch 'master' of github.com:TheLastProject/loyalty-card-locker into feature/power_screen_widgets

This commit is contained in:
Sylvia van Os
2021-10-17 20:02:42 +02:00
56 changed files with 569 additions and 191 deletions

View File

@@ -63,6 +63,13 @@ public class CatimaBarcode {
return barcodeFormats.contains(mBarcodeFormat);
}
public boolean isSquare(){
return mBarcodeFormat == BarcodeFormat.AZTEC
|| mBarcodeFormat == BarcodeFormat.DATA_MATRIX
|| mBarcodeFormat == BarcodeFormat.MAXICODE
|| mBarcodeFormat == BarcodeFormat.QR_CODE;
}
public BarcodeFormat format() {
return mBarcodeFormat;
}

View File

@@ -7,6 +7,7 @@ import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.text.TextUtils;
import java.io.FileNotFoundException;
import java.math.BigDecimal;
@@ -20,7 +21,7 @@ public class DBHelper extends SQLiteOpenHelper
{
public static final String DATABASE_NAME = "Catima.db";
public static final int ORIGINAL_DATABASE_VERSION = 1;
public static final int DATABASE_VERSION = 12;
public static final int DATABASE_VERSION = 13;
public static class LoyaltyCardDbGroups
{
@@ -293,6 +294,24 @@ public class DBHelper extends SQLiteOpenHelper
insertFTS(db, loyaltyCard.id, loyaltyCard.store, loyaltyCard.note);
}
}
if(oldVersion < 13 && newVersion >= 13)
{
db.execSQL("DELETE FROM " + LoyaltyCardDbFTS.TABLE + ";");
Cursor cursor = db.rawQuery("SELECT * FROM " + LoyaltyCardDbIds.TABLE + ";", null, null);
if (cursor.moveToFirst()) {
LoyaltyCard loyaltyCard = LoyaltyCard.toLoyaltyCard(cursor);
insertFTS(db, loyaltyCard.id, loyaltyCard.store, loyaltyCard.note);
while (cursor.moveToNext()) {
loyaltyCard = LoyaltyCard.toLoyaltyCard(cursor);
insertFTS(db, loyaltyCard.id, loyaltyCard.store, loyaltyCard.note);
}
}
cursor.close();
}
}
private ContentValues generateFTSContentValues(final int id, final String store, final String note) {
@@ -663,38 +682,26 @@ public class DBHelper extends SQLiteOpenHelper
return db.rawQuery("SELECT " + LoyaltyCardDbIds.TABLE + ".* FROM " + LoyaltyCardDbIds.TABLE +
" JOIN " + LoyaltyCardDbFTS.TABLE +
" ON " + LoyaltyCardDbFTS.TABLE + "." + LoyaltyCardDbFTS.ID + " = " + LoyaltyCardDbIds.TABLE + "." + LoyaltyCardDbIds.ID +
(filter.isEmpty() ? " " : " AND " + LoyaltyCardDbFTS.TABLE + " MATCH ? ") +
(filter.trim().isEmpty() ? " " : " AND " + LoyaltyCardDbFTS.TABLE + " MATCH ? ") +
groupFilter.toString() +
" ORDER BY " + LoyaltyCardDbIds.TABLE + "." + LoyaltyCardDbIds.STAR_STATUS + " DESC, " +
" (CASE WHEN " + LoyaltyCardDbIds.TABLE + "." + orderField + " IS NULL THEN 1 ELSE 0 END), " +
LoyaltyCardDbIds.TABLE + "." + orderField + " COLLATE NOCASE " + getDbDirection(order, direction) + ", " +
LoyaltyCardDbIds.TABLE + "." + LoyaltyCardDbIds.STORE + " COLLATE NOCASE ASC " +
limitString, filter.isEmpty() ? null : new String[] { filter + '*' }, null);
limitString, filter.trim().isEmpty() ? null : new String[] { TextUtils.join("* ", filter.split(" ")) + '*' }, null);
}
/**
* Returns the amount of loyalty cards.
*
* @return Integer
*/
public int getLoyaltyCardCount()
{
SQLiteDatabase db = getReadableDatabase();
return (int) DatabaseUtils.queryNumEntries(db, LoyaltyCardDbIds.TABLE);
}
/**
* Returns the amount of loyalty cards with the filter text in either the store or note.
*
* @param filter
* @return Integer
*/
public int getLoyaltyCardCount(String filter)
{
if (filter.isEmpty()) {
return getLoyaltyCardCount();
}
SQLiteDatabase db = getReadableDatabase();
return (int) DatabaseUtils.queryNumEntries(db, LoyaltyCardDbFTS.TABLE,
LoyaltyCardDbFTS.TABLE + " MATCH ? ", withArgs(filter + '*'));
}
/**
* Returns a cursor to all groups.
*
@@ -709,20 +716,22 @@ public class DBHelper extends SQLiteOpenHelper
}
public List<Group> getGroups() {
try(Cursor data = getGroupCursor()) {
List<Group> groups = new ArrayList<>();
Cursor data = getGroupCursor();
if (!data.moveToFirst()) {
return groups;
}
groups.add(Group.toGroup(data));
while (data.moveToNext()) {
groups.add(Group.toGroup(data));
}
List<Group> groups = new ArrayList<>();
if (!data.moveToFirst()) {
data.close();
return groups;
}
groups.add(Group.toGroup(data));
while (data.moveToNext()) {
groups.add(Group.toGroup(data));
}
data.close();
return groups;
}
public void reorderGroups(final List<Group> groups)

View File

@@ -42,7 +42,7 @@ class GroupCursorAdapter extends BaseCursorAdapter<GroupCursorAdapter.GroupListI
public GroupCursorAdapter.GroupListItemViewHolder onCreateViewHolder(ViewGroup inputParent, int inputViewType)
{
View itemView = LayoutInflater.from(inputParent.getContext()).inflate(R.layout.group_layout, inputParent, false);
return new GroupCursorAdapter.GroupListItemViewHolder(itemView);
return new GroupListItemViewHolder(itemView);
}
public Cursor getCursor()
@@ -80,7 +80,7 @@ class GroupCursorAdapter extends BaseCursorAdapter<GroupCursorAdapter.GroupListI
void onDeleteButtonClicked(View view);
}
public class GroupListItemViewHolder extends RecyclerView.ViewHolder
public static class GroupListItemViewHolder extends RecyclerView.ViewHolder
{
public TextView mName, mCardCount;
public AppCompatImageButton mMoveUp, mMoveDown, mEdit, mDelete;

View File

@@ -12,14 +12,16 @@ import android.text.InputType;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.Toast;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
@@ -46,6 +48,7 @@ public class ImportExportActivity extends CatimaAppCompatActivity
private String importAlertTitle;
private String importAlertMessage;
private DataFormat importDataFormat;
private String exportPassword;
@Override
protected void onCreate(Bundle savedInstanceState)
@@ -87,7 +90,28 @@ public class ImportExportActivity extends CatimaAppCompatActivity
@Override
public void onClick(View v)
{
chooseFileWithIntent(intentCreateDocumentAction, CHOOSE_EXPORT_LOCATION);
AlertDialog.Builder builder = new AlertDialog.Builder(ImportExportActivity.this);
builder.setTitle(R.string.exportPassword);
FrameLayout container = new FrameLayout(ImportExportActivity.this);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.leftMargin = 50;
params.rightMargin = 50;
final EditText input = new EditText(ImportExportActivity.this);
input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
input.setLayoutParams(params);
input.setHint(R.string.exportPasswordHint);
container.addView(input);
builder.setView(container);
builder.setPositiveButton(R.string.ok, (dialogInterface, i) -> {
exportPassword = input.getText().toString();
chooseFileWithIntent(intentCreateDocumentAction, CHOOSE_EXPORT_LOCATION);
});
builder.setNegativeButton(R.string.cancel, (dialogInterface, i) -> dialogInterface.cancel());
builder.show();
}
});
@@ -187,7 +211,7 @@ public class ImportExportActivity extends CatimaAppCompatActivity
builder.show();
}
private void startImport(final InputStream target, final Uri targetUri, final DataFormat dataFormat, final char[] password)
private void startImport(final InputStream target, final Uri targetUri, final DataFormat dataFormat, final char[] password, final boolean closeWhenDone)
{
ImportExportTask.TaskCompleteListener listener = new ImportExportTask.TaskCompleteListener()
{
@@ -195,6 +219,13 @@ public class ImportExportActivity extends CatimaAppCompatActivity
public void onTaskComplete(ImportExportResult result, DataFormat dataFormat)
{
onImportComplete(result, targetUri, dataFormat);
if (closeWhenDone) {
try {
target.close();
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
}
};
@@ -203,19 +234,25 @@ public class ImportExportActivity extends CatimaAppCompatActivity
importExporter.execute();
}
private void startExport(final OutputStream target, final Uri targetUri)
private void startExport(final OutputStream target, final Uri targetUri,char[] password, final boolean closeWhenDone)
{
ImportExportTask.TaskCompleteListener listener = new ImportExportTask.TaskCompleteListener()
{
@Override
public void onTaskComplete(ImportExportResult result, DataFormat dataFormat)
{
public void onTaskComplete(ImportExportResult result, DataFormat dataFormat) {
onExportComplete(result, targetUri);
if (closeWhenDone) {
try {
target.close();
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
}
};
importExporter = new ImportExportTask(ImportExportActivity.this,
DataFormat.Catima, target, listener);
DataFormat.Catima, target,password, listener);
importExporter.execute();
}
@@ -393,6 +430,7 @@ public class ImportExportActivity extends CatimaAppCompatActivity
{
if (requestCode == CHOOSE_EXPORT_LOCATION)
{
OutputStream writer;
if (uri.getScheme() != null)
{
@@ -402,9 +440,8 @@ public class ImportExportActivity extends CatimaAppCompatActivity
{
writer = new FileOutputStream(new File(uri.toString()));
}
Log.e(TAG, "Starting file export with: " + uri.toString());
startExport(writer, uri);
startExport(writer, uri,exportPassword.toCharArray(),true);
}
else
{
@@ -420,10 +457,10 @@ public class ImportExportActivity extends CatimaAppCompatActivity
Log.e(TAG, "Starting file import with: " + uri.toString());
startImport(reader, uri, importDataFormat, password);
startImport(reader, uri, importDataFormat, password, true);
}
}
catch(FileNotFoundException e)
catch(IOException e)
{
Log.e(TAG, "Failed to import/export file: " + uri.toString(), e);
if (requestCode == CHOOSE_EXPORT_LOCATION)

View File

@@ -35,7 +35,7 @@ class ImportExportTask extends AsyncTask<Void, Void, ImportExportResult>
/**
* Constructor which will setup a task for exporting to the given file
*/
ImportExportTask(Activity activity, DataFormat format, OutputStream output,
ImportExportTask(Activity activity, DataFormat format, OutputStream output,char[] password,
TaskCompleteListener listener)
{
super();
@@ -43,6 +43,7 @@ class ImportExportTask extends AsyncTask<Void, Void, ImportExportResult>
this.doImport = false;
this.format = format;
this.outputStream = output;
this.password = password;
this.listener = listener;
}
@@ -70,14 +71,14 @@ class ImportExportTask extends AsyncTask<Void, Void, ImportExportResult>
return importResult;
}
private ImportExportResult performExport(Context context, OutputStream stream, DBHelper db)
private ImportExportResult performExport(Context context, OutputStream stream, DBHelper db,char[] password)
{
ImportExportResult result = ImportExportResult.GenericFailure;
try
{
OutputStreamWriter writer = new OutputStreamWriter(stream, StandardCharsets.UTF_8);
result = MultiFormatExporter.exportData(context, db, stream, format);
result = MultiFormatExporter.exportData(context, db, stream, format,password);
writer.close();
}
catch (IOException e)
@@ -118,7 +119,7 @@ class ImportExportTask extends AsyncTask<Void, Void, ImportExportResult>
}
else
{
result = performExport(activity.getApplicationContext(), outputStream, db);
result = performExport(activity.getApplicationContext(), outputStream, db,password);
}
return result;

View File

@@ -21,7 +21,6 @@ import java.math.BigDecimal;
import java.text.DateFormat;
import java.util.ArrayList;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;
import protect.card_locker.preferences.Settings;
@@ -62,7 +61,7 @@ public class LoyaltyCardCursorAdapter extends BaseCursorAdapter<LoyaltyCardCurso
public LoyaltyCardListItemViewHolder onCreateViewHolder(ViewGroup inputParent, int inputViewType)
{
View itemView = LayoutInflater.from(inputParent.getContext()).inflate(R.layout.loyalty_card_layout, inputParent, false);
return new LoyaltyCardListItemViewHolder(itemView);
return new LoyaltyCardListItemViewHolder(itemView, mListener);
}
public Cursor getCursor()
@@ -241,7 +240,7 @@ public class LoyaltyCardCursorAdapter extends BaseCursorAdapter<LoyaltyCardCurso
void onRowLongClicked(int inputPosition);
}
public class LoyaltyCardListItemViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener
public static class LoyaltyCardListItemViewHolder extends RecyclerView.ViewHolder
{
public TextView mStoreField, mNoteField, mBalanceField, mExpiryField;
@@ -251,7 +250,7 @@ public class LoyaltyCardCursorAdapter extends BaseCursorAdapter<LoyaltyCardCurso
public View mDivider;
public RelativeLayout mThumbnailFrontContainer, mThumbnailBackContainer;
public LoyaltyCardListItemViewHolder(View inputView)
public LoyaltyCardListItemViewHolder(View inputView, CardAdapterListener inputListener)
{
super(inputView);
mRow = inputView.findViewById(R.id.row);
@@ -265,15 +264,11 @@ public class LoyaltyCardCursorAdapter extends BaseCursorAdapter<LoyaltyCardCurso
mExpiryField = inputView.findViewById(R.id.expiry);
mCardIcon = inputView.findViewById(R.id.thumbnail);
mStarIcon = inputView.findViewById(R.id.star);
inputView.setOnLongClickListener(this);
}
@Override
public boolean onLongClick(View inputView)
{
mListener.onRowLongClicked(getAdapterPosition());
inputView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
return true;
inputView.setOnLongClickListener(view -> {
inputListener.onRowClicked(getAdapterPosition());
inputView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
return true;
});
}
}
}

View File

@@ -1,14 +1,18 @@
package protect.card_locker;
import android.app.Application;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.multidex.MultiDexApplication;
import protect.card_locker.preferences.Settings;
public class LoyaltyCardLockerApplication extends MultiDexApplication {
public class LoyaltyCardLockerApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Settings settings = new Settings(getApplicationContext());
Settings settings = new Settings(this);
AppCompatDelegate.setDefaultNightMode(settings.getTheme());
}
}

View File

@@ -268,7 +268,10 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
if (imageTypes.get(mainImageIndex) == ImageType.BARCODE) {
redrawBarcodeAfterResize();
}
centerGuideline.setGuidelinePercent(0.5f * scale);
if(loyaltyCard!=null && format!=null && format.isSquare())
centerGuideline.setGuidelinePercent(0.75f * scale);
else
centerGuideline.setGuidelinePercent(0.5f * scale);
}
@Override
@@ -417,6 +420,12 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
setupOrientation();
format = loyaltyCard.barcodeType;
if(format != null && format.isSquare()){
centerGuideline.setGuidelinePercent(0.75f);
}
else{
centerGuideline.setGuidelinePercent(0.5f);
}
cardIdString = loyaltyCard.cardId;
barcodeIdString = loyaltyCard.barcodeId;

View File

@@ -195,9 +195,9 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
@Override
public void onTabSelected(TabLayout.Tab tab) {
selectedTab = tab.getPosition();
Log.d("onTabSelected","Tab Position "+tab.getPosition());
mGroup = tab.getTag();
updateLoyaltyCardList();
// Store active tab in Shared Preference to restore next app launch
SharedPreferences activeTabPref = getApplicationContext().getSharedPreferences(
getString(R.string.sharedpreference_active_tab),
@@ -230,6 +230,7 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
mHelpText.setOnTouchListener(gestureTouchListener);
mNoMatchingCardsText.setOnTouchListener(gestureTouchListener);
mCardList.setOnTouchListener(gestureTouchListener);
mNoGroupCardsText.setOnTouchListener(gestureTouchListener);
mAdapter = new LoyaltyCardCursorAdapter(this, null, this);
mCardList.setAdapter(mAdapter);
@@ -633,6 +634,12 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
mGestureDetector.onTouchEvent(ev);
return super.dispatchTouchEvent(ev);
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
Log.d(TAG, "On fling");
@@ -648,9 +655,10 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
}
Integer currentTab = groupsTabLayout.getSelectedTabPosition();
Log.d("onFling","Current Tab "+currentTab);
// Swipe right
if (velocityX < -150) {
Log.d("onFling","Right Swipe detected "+velocityX);
Integer nextTab = currentTab + 1;
if (nextTab == groupsTabLayout.getTabCount()) {
@@ -664,6 +672,7 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
// Swipe left
if (velocityX > 150) {
Log.d("onFling","Left Swipe detected "+velocityX);
Integer nextTab = currentTab - 1;
if (nextTab < 0) {

View File

@@ -6,6 +6,7 @@ import android.graphics.Bitmap;
import net.lingala.zip4j.io.outputstream.ZipOutputStream;
import net.lingala.zip4j.model.ZipParameters;
import net.lingala.zip4j.model.enums.EncryptionMethod;
import net.lingala.zip4j.util.InternalZipConstants;
import org.apache.commons.csv.CSVFormat;
@@ -30,14 +31,21 @@ import protect.card_locker.Utils;
*/
public class CatimaExporter implements Exporter
{
public void exportData(Context context, DBHelper db, OutputStream output) throws IOException, InterruptedException
public void exportData(Context context, DBHelper db, OutputStream output,char[] password) throws IOException, InterruptedException
{
// Necessary vars
int readLen;
byte[] readBuffer = new byte[InternalZipConstants.BUFF_SIZE];
// Create zip output stream
ZipOutputStream zipOutputStream = new ZipOutputStream(output);
ZipOutputStream zipOutputStream;
if(password!=null && password.length>0){
zipOutputStream = new ZipOutputStream(output,password);
}
else{
zipOutputStream = new ZipOutputStream(output);
}
// Generate CSV
ByteArrayOutputStream catimaOutputStream = new ByteArrayOutputStream();
@@ -45,8 +53,7 @@ public class CatimaExporter implements Exporter
writeCSV(db, catimaOutputStreamWriter);
// Add CSV to zip file
ZipParameters csvZipParameters = new ZipParameters();
csvZipParameters.setFileNameInZip("catima.csv");
ZipParameters csvZipParameters = createZipParameters("catima.csv",password);
zipOutputStream.putNextEntry(csvZipParameters);
InputStream csvInputStream = new ByteArrayInputStream(catimaOutputStream.toByteArray());
while ((readLen = csvInputStream.read(readBuffer)) != -1) {
@@ -71,8 +78,7 @@ public class CatimaExporter implements Exporter
// If it exists, add to the .zip file
Bitmap image = Utils.retrieveCardImage(context, card.id, front);
if (image != null) {
ZipParameters imageZipParameters = new ZipParameters();
imageZipParameters.setFileNameInZip(Utils.getCardImageFileName(card.id, front));
ZipParameters imageZipParameters = createZipParameters(Utils.getCardImageFileName(card.id, front),password);
zipOutputStream.putNextEntry(imageZipParameters);
InputStream imageInputStream = new ByteArrayInputStream(Utils.bitmapToByteArray(image));
while ((readLen = imageInputStream.read(readBuffer)) != -1) {
@@ -86,6 +92,16 @@ public class CatimaExporter implements Exporter
zipOutputStream.close();
}
private ZipParameters createZipParameters(String fileName, char[] password){
ZipParameters zipParameters = new ZipParameters();
zipParameters.setFileNameInZip(fileName);
if(password!=null && password.length>0){
zipParameters.setEncryptFiles(true);
zipParameters.setEncryptionMethod(EncryptionMethod.AES);
}
return zipParameters;
}
private void writeCSV(DBHelper db, OutputStreamWriter output) throws IOException, InterruptedException {
CSVPrinter printer = new CSVPrinter(output, CSVFormat.RFC4180);

View File

@@ -48,7 +48,7 @@ public class CatimaImporter implements Importer
bufferedInputStream.mark(100);
// First, check if this is a zip file
ZipInputStream zipInputStream = new ZipInputStream(bufferedInputStream);
ZipInputStream zipInputStream = new ZipInputStream(bufferedInputStream,password);
boolean isZipFile = false;

View File

@@ -17,5 +17,5 @@ public interface Exporter
* Export the database to the output stream in a given format.
* @throws IOException
*/
void exportData(Context context, DBHelper db, OutputStream output) throws IOException, InterruptedException;
void exportData(Context context, DBHelper db, OutputStream output,char[] password) throws IOException, InterruptedException;
}

View File

@@ -22,7 +22,7 @@ public class MultiFormatExporter
* another ImportExportResult otherwise. If not Success, partial data may have been
* written to the output stream, and it should be discarded.
*/
public static ImportExportResult exportData(Context context, DBHelper db, OutputStream output, DataFormat format)
public static ImportExportResult exportData(Context context, DBHelper db, OutputStream output, DataFormat format,char[] password)
{
Exporter exporter = null;
@@ -40,7 +40,7 @@ public class MultiFormatExporter
{
try
{
exporter.exportData(context, db, output);
exporter.exportData(context, db, output,password);
return ImportExportResult.Success;
}
catch(IOException e)

View File

@@ -116,14 +116,14 @@ public class StocardImporter implements Importer
.substring("/loyalty-card-providers/".length())
);
try {
if (jsonObject.has("input_barcode_format")) {
loyaltyCardHashMap = appendToLoyaltyCardHashMap(
loyaltyCardHashMap,
cardName,
"barcodeType",
jsonObject.getString("input_barcode_format")
);
} catch (JSONException ignored) {}
}
}
} else if (fileName.endsWith("notes/default.json")) {
loyaltyCardHashMap = appendToLoyaltyCardHashMap(

View File

@@ -1,6 +1,7 @@
package protect.card_locker.preferences;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
@@ -41,7 +42,6 @@ public class SettingsActivity extends CatimaAppCompatActivity
// Display the fragment as the main content.
SettingsFragment fragment = new SettingsFragment();
fragment.setParentReference(this);
getSupportFragmentManager().beginTransaction()
.replace(R.id.settings_container, fragment)
.commit();
@@ -64,11 +64,6 @@ public class SettingsActivity extends CatimaAppCompatActivity
public static class SettingsFragment extends PreferenceFragmentCompat
{
private static final String DIALOG_FRAGMENT_TAG = "SettingsFragment";
private SettingsActivity parent;
public void setParentReference(SettingsActivity settingsActivity) {
parent = settingsActivity;
}
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
@@ -120,8 +115,9 @@ public class SettingsActivity extends CatimaAppCompatActivity
});
localePreference.setOnPreferenceChangeListener((preference, newValue) -> {
// Refresh the activity
parent.finish();
startActivity(parent.getIntent());
Intent intent = new Intent(getContext(), SettingsActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
getContext().startActivity(intent);
return true;
});