Get rid of headingStoreTextColorValue

This commit is contained in:
Sylvia van Os
2020-11-10 19:11:57 +01:00
parent 91c2efbdfc
commit 1641631bdc
8 changed files with 29 additions and 61 deletions

View File

@@ -274,13 +274,10 @@ public class CsvDatabaseImporter implements DatabaseImporter
String barcodeType = extractString(DBHelper.LoyaltyCardDbIds.BARCODE_TYPE, record, "");
Integer headerColor = null;
Integer headerTextColor = null;
if(record.isMapped(DBHelper.LoyaltyCardDbIds.HEADER_COLOR) &&
record.isMapped(DBHelper.LoyaltyCardDbIds.HEADER_TEXT_COLOR))
if(record.isMapped(DBHelper.LoyaltyCardDbIds.HEADER_COLOR))
{
headerColor = extractInt(DBHelper.LoyaltyCardDbIds.HEADER_COLOR, record, true);
headerTextColor = extractInt(DBHelper.LoyaltyCardDbIds.HEADER_TEXT_COLOR, record, true);
}
int starStatus = 0;
@@ -291,7 +288,7 @@ public class CsvDatabaseImporter implements DatabaseImporter
// We catch this exception so we can still import old backups
}
if (starStatus != 1) starStatus = 0;
helper.insertLoyaltyCard(database, id, store, note, cardId, barcodeType, headerColor, headerTextColor, starStatus);
helper.insertLoyaltyCard(database, id, store, note, cardId, barcodeType, headerColor, starStatus);
}
/**

View File

@@ -5,6 +5,7 @@ import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.graphics.Color;
import java.util.ArrayList;
import java.util.List;
@@ -112,7 +113,7 @@ public class DBHelper extends SQLiteOpenHelper
public long insertLoyaltyCard(final String store, final String note, final String cardId,
final String barcodeType, final Integer headerColor,
final Integer headerTextColor, final int starStatus)
final int starStatus)
{
SQLiteDatabase db = getWritableDatabase();
ContentValues contentValues = new ContentValues();
@@ -121,7 +122,7 @@ public class DBHelper extends SQLiteOpenHelper
contentValues.put(LoyaltyCardDbIds.CARD_ID, cardId);
contentValues.put(LoyaltyCardDbIds.BARCODE_TYPE, barcodeType);
contentValues.put(LoyaltyCardDbIds.HEADER_COLOR, headerColor);
contentValues.put(LoyaltyCardDbIds.HEADER_TEXT_COLOR, headerTextColor);
contentValues.put(LoyaltyCardDbIds.HEADER_TEXT_COLOR, Color.WHITE);
contentValues.put(LoyaltyCardDbIds.STAR_STATUS, starStatus);
final long newId = db.insert(LoyaltyCardDbIds.TABLE, null, contentValues);
return newId;
@@ -130,7 +131,7 @@ public class DBHelper extends SQLiteOpenHelper
public boolean insertLoyaltyCard(final SQLiteDatabase db, final int id, final String store,
final String note, final String cardId,
final String barcodeType, final Integer headerColor,
final Integer headerTextColor, final int starStatus)
final int starStatus)
{
ContentValues contentValues = new ContentValues();
contentValues.put(LoyaltyCardDbIds.ID, id);
@@ -139,7 +140,7 @@ public class DBHelper extends SQLiteOpenHelper
contentValues.put(LoyaltyCardDbIds.CARD_ID, cardId);
contentValues.put(LoyaltyCardDbIds.BARCODE_TYPE, barcodeType);
contentValues.put(LoyaltyCardDbIds.HEADER_COLOR, headerColor);
contentValues.put(LoyaltyCardDbIds.HEADER_TEXT_COLOR, headerTextColor);
contentValues.put(LoyaltyCardDbIds.HEADER_TEXT_COLOR, Color.WHITE);
contentValues.put(LoyaltyCardDbIds.STAR_STATUS,starStatus);
final long newId = db.insert(LoyaltyCardDbIds.TABLE, null, contentValues);
return (newId != -1);
@@ -147,7 +148,7 @@ public class DBHelper extends SQLiteOpenHelper
public boolean updateLoyaltyCard(final int id, final String store, final String note,
final String cardId, final String barcodeType,
final Integer headerColor, final Integer headerTextColor)
final Integer headerColor)
{
SQLiteDatabase db = getWritableDatabase();
ContentValues contentValues = new ContentValues();
@@ -156,7 +157,7 @@ public class DBHelper extends SQLiteOpenHelper
contentValues.put(LoyaltyCardDbIds.CARD_ID, cardId);
contentValues.put(LoyaltyCardDbIds.BARCODE_TYPE, barcodeType);
contentValues.put(LoyaltyCardDbIds.HEADER_COLOR, headerColor);
contentValues.put(LoyaltyCardDbIds.HEADER_TEXT_COLOR, headerTextColor);
contentValues.put(LoyaltyCardDbIds.HEADER_TEXT_COLOR, Color.WHITE);
int rowsUpdated = db.update(LoyaltyCardDbIds.TABLE, contentValues,
LoyaltyCardDbIds.ID + "=?",
new String[]{Integer.toString(id)});

View File

@@ -12,9 +12,6 @@ public class ImportURIHelper {
private static final String BARCODE_TYPE = DBHelper.LoyaltyCardDbIds.BARCODE_TYPE;
private static final String HEADER_COLOR = DBHelper.LoyaltyCardDbIds.HEADER_COLOR;
private static final String HEADER_TEXT_COLOR = DBHelper.LoyaltyCardDbIds.HEADER_TEXT_COLOR;
private final Context context;
private final String host;
@@ -57,11 +54,6 @@ public class ImportURIHelper {
{
headerColor = Integer.parseInt(unparsedHeaderColor);
}
String unparsedHeaderTextColor = uri.getQueryParameter(HEADER_TEXT_COLOR);
if(unparsedHeaderTextColor != null)
{
headerTextColor = Integer.parseInt(unparsedHeaderTextColor);
}
return new LoyaltyCard(-1, store, note, cardId, barcodeType, headerColor, headerTextColor, 0);
} catch (NullPointerException | NumberFormatException ex) {
@@ -83,10 +75,6 @@ public class ImportURIHelper {
{
uriBuilder.appendQueryParameter(HEADER_COLOR, loyaltyCard.headerColor.toString());
}
if(loyaltyCard.headerTextColor != null)
{
uriBuilder.appendQueryParameter(HEADER_TEXT_COLOR, loyaltyCard.headerTextColor.toString());
}
//StarStatus will not be exported
return uriBuilder.build();
}

View File

@@ -71,6 +71,6 @@ class LoyaltyCardCursorAdapter extends CursorAdapter
if (loyaltyCard.starStatus!=0) star.setVisibility(View.VISIBLE);
else star.setVisibility(View.GONE);
thumbnail.setImageBitmap(Utils.generateIcon(context, loyaltyCard.store, loyaltyCard.headerColor, loyaltyCard.headerTextColor).getLetterTile());
thumbnail.setImageBitmap(Utils.generateIcon(context, loyaltyCard.store, loyaltyCard.headerColor).getLetterTile());
}
}

View File

@@ -67,7 +67,6 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
boolean updateLoyaltyCard;
Uri importLoyaltyCardUri = null;
Integer headingColorValue = null;
Integer headingStoreTextColorValue = null;
DBHelper db;
ImportURIHelper importUriHelper;
@@ -192,15 +191,6 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
}
}
if(headingStoreTextColorValue == null)
{
headingStoreTextColorValue = loyaltyCard.headerTextColor;
if(headingStoreTextColorValue == null)
{
headingStoreTextColorValue = Color.WHITE;
}
}
setTitle(R.string.editCardTitle);
}
else if(importLoyaltyCardUri != null)
@@ -220,7 +210,6 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
cardIdFieldView.setText(importCard.cardId);
barcodeTypeField.setText(importCard.barcodeType);
headingColorValue = importCard.headerColor;
headingStoreTextColorValue = importCard.headerTextColor;
}
else
{
@@ -266,11 +255,7 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
colors.recycle();
}
if(headingStoreTextColorValue == null) {
headingStoreTextColorValue = Color.WHITE;
}
thumbnail.setOnClickListener(new ColorSelectListener(headingColorValue, true));
thumbnail.setOnClickListener(new ColorSelectListener(headingColorValue));
if(cardIdFieldView.getText().length() > 0 && barcodeTypeField.getText().length() > 0)
{
@@ -380,12 +365,10 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
class ColorSelectListener implements View.OnClickListener
{
final int defaultColor;
final boolean isBackgroundColor;
ColorSelectListener(int defaultColor, boolean isBackgroundColor)
ColorSelectListener(int defaultColor)
{
this.defaultColor = defaultColor;
this.isBackgroundColor = isBackgroundColor;
}
@Override
@@ -397,14 +380,7 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
@Override
public void onColorSelected(int dialogId, int color)
{
if(isBackgroundColor)
{
headingColorValue = color;
}
else
{
headingStoreTextColorValue = color;
}
headingColorValue = color;
generateIcon(storeFieldEdit.getText().toString());
}
@@ -454,12 +430,12 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
if(updateLoyaltyCard)
{ //update of "starStatus" not necessary, since it cannot be changed in this activity (only in ViewActivity)
db.updateLoyaltyCard(loyaltyCardId, store, note, cardId, barcodeType, headingColorValue, headingStoreTextColorValue);
db.updateLoyaltyCard(loyaltyCardId, store, note, cardId, barcodeType, headingColorValue);
Log.i(TAG, "Updated " + loyaltyCardId + " to " + cardId);
}
else
{
loyaltyCardId = (int)db.insertLoyaltyCard(store, note, cardId, barcodeType, headingColorValue, headingStoreTextColorValue, 0);
loyaltyCardId = (int)db.insertLoyaltyCard(store, note, cardId, barcodeType, headingColorValue, 0);
}
db.setLoyaltyCardGroups(loyaltyCardId, selectedGroups);
@@ -579,13 +555,13 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
}
private void generateIcon(String store) {
if (headingColorValue == null && headingStoreTextColorValue == null) {
if (headingColorValue == null) {
return;
}
thumbnail.setBackgroundColor(headingColorValue);
LetterBitmap letterBitmap = Utils.generateIcon(this, store, headingColorValue, headingStoreTextColorValue);
LetterBitmap letterBitmap = Utils.generateIcon(this, store, headingColorValue);
if (letterBitmap != null) {
thumbnail.setImageBitmap(letterBitmap.getLetterTile());

View File

@@ -8,7 +8,6 @@ import android.os.Build;
import android.os.Bundle;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.graphics.ColorUtils;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.core.widget.TextViewCompat;
import androidx.appcompat.app.ActionBar;
@@ -36,7 +35,6 @@ import protect.card_locker.preferences.Settings;
public class LoyaltyCardViewActivity extends AppCompatActivity
{
private static final String TAG = "Catima";
private static final double LUMINANCE_MIDPOINT = 0.5;
TextView cardIdFieldView;
TextView noteView;
@@ -223,7 +221,7 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
collapsingToolbarLayout.setBackgroundColor(backgroundHeaderColor);
// If the background is very bright, we should use dark icons
backgroundNeedsDarkIcons = (ColorUtils.calculateLuminance(backgroundHeaderColor) > LUMINANCE_MIDPOINT);
backgroundNeedsDarkIcons = Utils.needsDarkForeground(backgroundHeaderColor);
ActionBar actionBar = getSupportActionBar();
if(actionBar != null)
{

View File

@@ -486,5 +486,4 @@ public class MainActivity extends AppCompatActivity
int currentNightMode = config.uiMode & Configuration.UI_MODE_NIGHT_MASK;
return (currentNightMode == Configuration.UI_MODE_NIGHT_YES);
}
}

View File

@@ -1,9 +1,14 @@
package protect.card_locker;
import android.content.Context;
import android.graphics.Color;
import androidx.core.graphics.ColorUtils;
public class Utils {
static public LetterBitmap generateIcon(Context context, String store, Integer backgroundColor, Integer textColor) {
static final double LUMINANCE_MIDPOINT = 0.5;
static public LetterBitmap generateIcon(Context context, String store, Integer backgroundColor) {
if (store.length() == 0) {
return null;
}
@@ -12,6 +17,10 @@ public class Utils {
int pixelSize = context.getResources().getDimensionPixelSize(R.dimen.cardThumbnailSize);
return new LetterBitmap(context, store, store,
tileLetterFontSize, pixelSize, pixelSize, backgroundColor, textColor);
tileLetterFontSize, pixelSize, pixelSize, backgroundColor, needsDarkForeground(backgroundColor) ? Color.BLACK : Color.WHITE);
}
static public boolean needsDarkForeground(Integer backgroundColor) {
return ColorUtils.calculateLuminance(backgroundColor) > LUMINANCE_MIDPOINT;
}
}