remove modularity

This commit is contained in:
Katharine
2021-10-30 11:04:21 +08:00
parent f667fcbebe
commit b4b544e342
9 changed files with 97 additions and 682 deletions

View File

@@ -4,6 +4,8 @@ import android.database.Cursor;
import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.Nullable;
public class Group implements Parcelable
{
public final String _id;
@@ -52,4 +54,22 @@ public class Group implements Parcelable
return new Group[size];
}
};
@Override
public boolean equals(@Nullable Object obj) {
if (obj == null){
return false;
}
if (!(obj instanceof Group)){
return false;
}
Group anotherGroup = (Group)obj;
return _id.equals(anotherGroup._id) && order == anotherGroup.order;
}
@Override
public int hashCode(){
String combined = _id + "_" + order;
return combined.hashCode();
}
}

View File

@@ -35,8 +35,8 @@ public class LoyaltyCardCursorAdapter extends BaseCursorAdapter<LoyaltyCardCurso
boolean mDarkModeEnabled;
private Context mContext;
private CardAdapterListener mListener;
private SparseBooleanArray mSelectedItems;
private SparseBooleanArray mAnimationItemsIndex;
protected SparseBooleanArray mSelectedItems;
protected SparseBooleanArray mAnimationItemsIndex;
private boolean mReverseAllAnimations = false;
public LoyaltyCardCursorAdapter(Context inputContext, Cursor inputCursor, CardAdapterListener inputListener) {

View File

@@ -95,12 +95,20 @@ public class ManageGroupActivity extends CatimaAppCompatActivity implements Mana
mGroupNameText = findViewById(R.id.editTextGroupName);
mGroupNameLabel = findViewById(R.id.textViewEditGroupName);
mAdapter = new ManageGroupCursorAdapter(this, null, this);
Intent intent = getIntent();
String groupId = intent.getStringExtra("group");
if (groupId == null){
throw(new IllegalArgumentException("this activity expects a group loaded into it's intent"));
}
Log.d("groupId", "gropuId: " + groupId);
mGroup = mDB.getGroup(groupId);
if (mGroup == null){
throw(new IllegalArgumentException("cannot load group " + groupId + " from database"));
}
mAdapter = new ManageGroupCursorAdapter(this, null, this, mGroup);
mCardList.setAdapter(mAdapter);
registerForContextMenu(mCardList);
mGroup = null;
mDarkMode = Utils.isDarkModeEnabled(getApplicationContext());
if (inputSavedInstanceState != null) {
@@ -146,12 +154,6 @@ public class ManageGroupActivity extends CatimaAppCompatActivity implements Mana
{
super.onResume();
Intent intent = getIntent();
mGroup = intent.getParcelableExtra("group");
if (mGroup == null){
throw(new IllegalArgumentException("this activity expects a group loaded into it's intent"));
}
setTitle(getString(R.string.edit) + ": " + mGroup._id);
if (mCurrentGroupName == null){
@@ -207,7 +209,7 @@ public class ManageGroupActivity extends CatimaAppCompatActivity implements Mana
}
private void updateLoyaltyCardList() {
mAdapter.swapCursor(mDB.getIfLoyaltyCardsAreInGroupCursor(mFilter, mGroup, mOrder, mOrderDirection));
mAdapter.swapCursor(mDB.getLoyaltyCardCursor(mFilter, null, mOrder, mOrderDirection));
if(mAdapter.getCountFromCursor() > 0)
{
@@ -294,7 +296,7 @@ public class ManageGroupActivity extends CatimaAppCompatActivity implements Mana
}
}
mAdapter.commitToDatabase(getApplicationContext(), mGroup._id);
mAdapter.commitToDatabase(getApplicationContext());
Toast toast = Toast.makeText(getApplicationContext(), R.string.group_updated, Toast.LENGTH_SHORT);
if(!currentGroupName.trim().equals(mGroup._id)){
mDB.updateGroup(mGroup._id, currentGroupName.trim());
@@ -351,5 +353,6 @@ public class ManageGroupActivity extends CatimaAppCompatActivity implements Mana
public void onRowClicked(int inputPosition)
{
mAdapter.toggleSelection(inputPosition);
}
}

View File

@@ -24,6 +24,8 @@ import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -35,331 +37,86 @@ import androidx.recyclerview.widget.RecyclerView;
import protect.card_locker.preferences.Settings;
public class ManageGroupCursorAdapter extends BaseCursorAdapter<ManageGroupCursorAdapter.ManageGroupListItemViewHolder> {
private int mCurrentSelectedIndex = -1;
private Cursor mCursor;
Settings mSettings;
boolean mDarkModeEnabled;
private Context mContext;
private CardAdapterListener mListener;
private SparseBooleanArray mSelectedItems;
private SparseBooleanArray mAnimationItemsIndex;
private boolean mReverseAllAnimations = false;
private HashMap<Integer, ManageGroupLoyaltyCard> mIndexCardMap;
public class ManageGroupCursorAdapter extends LoyaltyCardCursorAdapter {
private HashMap<Integer, Integer> mIndexCardMap;
private HashMap<Integer, Boolean> mInGroupOverlay;
public ManageGroupCursorAdapter(Context inputContext, Cursor inputCursor, CardAdapterListener inputListener) {
super(inputCursor);
setHasStableIds(true);
mSettings = new Settings(inputContext);
mContext = inputContext;
mListener = inputListener;
mSelectedItems = new SparseBooleanArray();
mAnimationItemsIndex = new SparseBooleanArray();
mDarkModeEnabled = Utils.isDarkModeEnabled(inputContext);
private Group mGroup;
private DBHelper mDb;
public ManageGroupCursorAdapter(Context inputContext, Cursor inputCursor, CardAdapterListener inputListener, Group group){
super(inputContext, inputCursor, inputListener);
mGroup = new Group(group._id, group.order);
mInGroupOverlay = new HashMap<Integer, Boolean>();
swapCursor(mCursor);
mDb = new DBHelper(inputContext);
}
@Override
public void swapCursor(Cursor inputCursor) {
mIndexCardMap = new HashMap<Integer, ManageGroupLoyaltyCard>();
super.swapCursor(inputCursor);
mCursor = inputCursor;
mIndexCardMap = new HashMap<Integer, Integer>();
}
@Override
public ManageGroupListItemViewHolder onCreateViewHolder(ViewGroup inputParent, int inputViewType) {
View itemView = LayoutInflater.from(inputParent.getContext()).inflate(R.layout.manage_group_loyalty_card_layout, inputParent, false);
return new ManageGroupListItemViewHolder(itemView, mListener);
}
public Cursor getCursor() {
return mCursor;
}
public void onBindViewHolder(ManageGroupListItemViewHolder inputHolder, Cursor inputCursor) {
// Invisible until we want to show something more
inputHolder.mDivider.setVisibility(View.GONE);
int size = mSettings.getFontSizeMax(mSettings.getSmallFont());
if (mDarkModeEnabled) {
inputHolder.mStarIcon.setColorFilter(BlendModeColorFilterCompat.createBlendModeColorFilterCompat(Color.WHITE, BlendModeCompat.SRC_ATOP));
}
ManageGroupLoyaltyCard cardEntry = ManageGroupLoyaltyCard.toCard(inputCursor);
inputHolder.mStoreField.setText(cardEntry.store);
inputHolder.mStoreField.setTextSize(mSettings.getFontSizeMax(mSettings.getMediumFont()));
if (!cardEntry.note.isEmpty()) {
inputHolder.mNoteField.setVisibility(View.VISIBLE);
inputHolder.mNoteField.setText(cardEntry.note);
inputHolder.mNoteField.setTextSize(size);
} else {
inputHolder.mNoteField.setVisibility(View.GONE);
}
if (!cardEntry.balance.equals(new BigDecimal("0"))) {
int drawableSize = dpToPx((size*24)/14, mContext);
inputHolder.mDivider.setVisibility(View.VISIBLE);
inputHolder.mBalanceField.setVisibility(View.VISIBLE);
Drawable balanceIcon = inputHolder.mBalanceField.getCompoundDrawables()[0];
balanceIcon.setBounds(0,0,drawableSize,drawableSize);
inputHolder.mBalanceField.setCompoundDrawablesRelative(balanceIcon, null, null, null);
if (mDarkModeEnabled) {
balanceIcon.setColorFilter(BlendModeColorFilterCompat.createBlendModeColorFilterCompat(Color.WHITE, BlendModeCompat.SRC_ATOP));
}
inputHolder.mBalanceField.setText(Utils.formatBalance(mContext, cardEntry.balance, cardEntry.balanceType));
inputHolder.mBalanceField.setTextSize(size);
} else {
inputHolder.mBalanceField.setVisibility(View.GONE);
}
if (cardEntry.expiry != null) {
int drawableSize = dpToPx((size*24)/14, mContext);
inputHolder.mDivider.setVisibility(View.VISIBLE);
inputHolder.mExpiryField.setVisibility(View.VISIBLE);
Drawable expiryIcon = inputHolder.mExpiryField.getCompoundDrawables()[0];
expiryIcon.setBounds(0,0, drawableSize, drawableSize);
inputHolder.mExpiryField.setCompoundDrawablesRelative(expiryIcon, null, null, null);
if (Utils.hasExpired(cardEntry.expiry)) {
expiryIcon.setColorFilter(BlendModeColorFilterCompat.createBlendModeColorFilterCompat(Color.RED, BlendModeCompat.SRC_ATOP));
inputHolder.mExpiryField.setTextColor(Color.RED);
} else if (mDarkModeEnabled) {
expiryIcon.setColorFilter(BlendModeColorFilterCompat.createBlendModeColorFilterCompat(Color.WHITE, BlendModeCompat.SRC_ATOP));
}
inputHolder.mExpiryField.setText(DateFormat.getDateInstance(DateFormat.LONG).format(cardEntry.expiry));
inputHolder.mExpiryField.setTextSize(size);
} else {
inputHolder.mExpiryField.setVisibility(View.GONE);
}
// inputHolder.mStarIcon.setVisibility(cardEntry.starStatus != 0 ? View.VISIBLE : View.GONE);
inputHolder.mCardIcon.setImageBitmap(Utils.generateIcon(mContext, cardEntry.store, cardEntry.headerColor).getLetterTile());
int imageSize = dpToPx( (size*46)/14, mContext);
inputHolder.mCardIcon.getLayoutParams().height = imageSize;
inputHolder.mCardIcon.getLayoutParams().width = imageSize;
inputHolder.mStarIcon.getLayoutParams().height = imageSize;
inputHolder.mStarIcon.getLayoutParams().width = imageSize;
inputHolder.mTickIcon.getLayoutParams().height = imageSize;
inputHolder.mTickIcon.getLayoutParams().width = imageSize;
/* Changing Padding and Margin of different views according to font size
* Views Included:
* a) InformationContainer padding
* b) Store left padding
* c) Divider Margin
* d) note top margin
* e) row margin
* */
int marginPaddingSize = dpToPx((size*16)/14, mContext );
inputHolder.mInformationContainer.setPadding(marginPaddingSize, marginPaddingSize, marginPaddingSize, marginPaddingSize);
inputHolder.mStoreField.setPadding(marginPaddingSize, 0, 0, 0);
LinearLayout.LayoutParams lpDivider = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT );
lpDivider.setMargins(0, marginPaddingSize, 0, marginPaddingSize);
inputHolder.mDivider.setLayoutParams(lpDivider);
LinearLayout.LayoutParams lpNoteField = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT );
lpNoteField.setMargins(0, marginPaddingSize/2, 0, 0);
inputHolder.mNoteField.setLayoutParams(lpNoteField);
LinearLayout.LayoutParams lpRow = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT );
lpRow.setMargins(marginPaddingSize/2, marginPaddingSize/2, marginPaddingSize/2, marginPaddingSize/2);
inputHolder.mRow.setLayoutParams(lpRow);
inputHolder.itemView.setActivated(mSelectedItems.get(inputCursor.getPosition(), false));
Boolean overlayValue = mInGroupOverlay.get(cardEntry.id);
if((overlayValue != null? overlayValue: cardEntry.is_in_group)) {
public void onBindViewHolder(LoyaltyCardListItemViewHolder inputHolder, Cursor inputCursor){
LoyaltyCard loyaltyCard = LoyaltyCard.toLoyaltyCard(inputCursor);
Boolean overlayValue = mInGroupOverlay.get(loyaltyCard.id);
if((overlayValue != null? overlayValue: isLoyaltyCardInGroup(loyaltyCard.id))) {
mAnimationItemsIndex.put(inputCursor.getPosition(), true);
mSelectedItems.put(inputCursor.getPosition(), true);
}
applyIconAnimation(inputHolder, inputCursor.getPosition());
applyClickEvents(inputHolder, inputCursor.getPosition());
mIndexCardMap.put(inputCursor.getPosition(), cardEntry);
mIndexCardMap.put(inputCursor.getPosition(), loyaltyCard.id);
super.onBindViewHolder(inputHolder, inputCursor);
}
private void applyClickEvents(ManageGroupListItemViewHolder inputHolder, final int inputPosition) {
inputHolder.mRow.setOnClickListener(inputView -> mListener.onRowClicked(inputPosition));
inputHolder.mInformationContainer.setOnClickListener(inputView -> mListener.onRowClicked(inputPosition));
inputHolder.mRow.setOnLongClickListener(inputView -> {
mListener.onRowLongClicked(inputPosition);
inputView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
return true;
});
inputHolder.mInformationContainer.setOnLongClickListener(inputView -> {
mListener.onRowLongClicked(inputPosition);
inputView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
return true;
});
}
private void applyIconAnimation(ManageGroupListItemViewHolder inputHolder, int inputPosition) {
if (mSelectedItems.get(inputPosition, false)) {
inputHolder.mThumbnailFrontContainer.setVisibility(View.GONE);
resetIconYAxis(inputHolder.mThumbnailBackContainer);
inputHolder.mThumbnailBackContainer.setVisibility(View.VISIBLE);
inputHolder.mThumbnailBackContainer.setAlpha(1);
if (mCurrentSelectedIndex == inputPosition) {
LoyaltyCardAnimator.flipView(mContext, inputHolder.mThumbnailBackContainer, inputHolder.mThumbnailFrontContainer, true);
resetCurrentIndex();
}
} else {
inputHolder.mThumbnailBackContainer.setVisibility(View.GONE);
resetIconYAxis(inputHolder.mThumbnailFrontContainer);
inputHolder.mThumbnailFrontContainer.setVisibility(View.VISIBLE);
inputHolder.mThumbnailFrontContainer.setAlpha(1);
if ((mReverseAllAnimations && mAnimationItemsIndex.get(inputPosition, false)) || mCurrentSelectedIndex == inputPosition) {
LoyaltyCardAnimator.flipView(mContext, inputHolder.mThumbnailBackContainer, inputHolder.mThumbnailFrontContainer, false);
resetCurrentIndex();
}
}
}
private void resetIconYAxis(View inputView) {
if (inputView.getRotationY() != 0) {
inputView.setRotationY(0);
}
}
public void resetAnimationIndex() {
mReverseAllAnimations = false;
mAnimationItemsIndex.clear();
}
public void toggleSelection(int inputPosition) {
mCurrentSelectedIndex = inputPosition;
if (mSelectedItems.get(inputPosition, false)) {
mSelectedItems.delete(inputPosition);
mAnimationItemsIndex.delete(inputPosition);
} else {
mSelectedItems.put(inputPosition, true);
mAnimationItemsIndex.put(inputPosition, true);
}
ManageGroupLoyaltyCard cardEntry = mIndexCardMap.get(inputPosition);
Boolean overlayValue = mInGroupOverlay.get(cardEntry.id);
if (overlayValue == null){
mInGroupOverlay.put(cardEntry.id, !cardEntry.is_in_group);
}else{
mInGroupOverlay.put(cardEntry.id, !overlayValue);
}
notifyDataSetChanged();
}
private void resetCurrentIndex() {
mCurrentSelectedIndex = -1;
}
public interface CardAdapterListener {
void onRowClicked(int inputPosition);
void onRowLongClicked(int inputPosition);
}
private HashMap<Integer, ManageGroupLoyaltyCard> fetchWholeQuery (){
HashMap<Integer, ManageGroupLoyaltyCard> res = new HashMap<Integer, ManageGroupLoyaltyCard>();
int oldPosition = mCursor.getPosition();
mCursor.moveToFirst();
while(!mCursor.isAfterLast()){
ManageGroupLoyaltyCard cardEntry = ManageGroupLoyaltyCard.toCard(mCursor);
res.put(cardEntry.id, cardEntry);
mCursor.moveToNext();
}
mCursor.moveToPosition(oldPosition);
return res;
}
public void commitToDatabase(Context context, String groupId){
DBHelper dbHelper = new DBHelper(context);
HashMap<Integer, ManageGroupLoyaltyCard> cache = fetchWholeQuery();
for(Map.Entry<Integer, Boolean> entry : mInGroupOverlay.entrySet()){
ManageGroupLoyaltyCard cardEntry = cache.get(entry.getKey());
if (cardEntry == null){
Log.d("commitToDatabase", "card with id " + entry.getKey() + " was removed from database unexpectedly");
continue;
}
if (entry.getValue() != cardEntry.is_in_group) {
if (entry.getValue()) {
dbHelper.addLoyaltyCardToGroup(entry.getKey(), groupId);
} else {
dbHelper.removeLoyaltyCardFromGroup(entry.getKey(), groupId);
}
}
}
}
public boolean hasChanged(){
HashMap<Integer, ManageGroupLoyaltyCard> cache = fetchWholeQuery();
for(Map.Entry<Integer, Boolean> entry : mInGroupOverlay.entrySet()){
ManageGroupLoyaltyCard cardEntry = cache.get(entry.getKey());
if(cardEntry.is_in_group != entry.getValue()){
private boolean isLoyaltyCardInGroup(int cardId){
List<Group> groups = mDb.getLoyaltyCardGroups(cardId);
Iterator<Group> groupItr = groups.listIterator();
while(groupItr.hasNext()){
if (groupItr.next().equals(mGroup)){
return true;
}
}
return false;
}
public int getCountFromCursor(){
return mCursor.getCount();
}
public HashMap<Integer, Boolean> exportInGroupState(){
return (HashMap<Integer, Boolean>)mInGroupOverlay.clone();
}
public void importInGroupState(HashMap<Integer, Boolean> cardIdInGroupMap){
mInGroupOverlay = (HashMap<Integer, Boolean>)cardIdInGroupMap.clone();
}
public static class ManageGroupListItemViewHolder extends RecyclerView.ViewHolder {
public TextView mStoreField, mNoteField, mBalanceField, mExpiryField;
public LinearLayout mInformationContainer;
public ImageView mCardIcon, mStarIcon, mTickIcon;
public MaterialCardView mRow;
public View mDivider;
public RelativeLayout mThumbnailFrontContainer, mThumbnailBackContainer;
public ManageGroupListItemViewHolder(View inputView, CardAdapterListener inputListener) {
super(inputView);
mRow = inputView.findViewById(R.id.row);
mDivider = inputView.findViewById(R.id.info_divider);
mThumbnailFrontContainer = inputView.findViewById(R.id.thumbnail_front);
mThumbnailBackContainer = inputView.findViewById(R.id.thumbnail_back);
mInformationContainer = inputView.findViewById(R.id.information_container);
mStoreField = inputView.findViewById(R.id.store);
mNoteField = inputView.findViewById(R.id.note);
mBalanceField = inputView.findViewById(R.id.balance);
mExpiryField = inputView.findViewById(R.id.expiry);
mCardIcon = inputView.findViewById(R.id.thumbnail);
mStarIcon = inputView.findViewById(R.id.star);
mTickIcon = inputView.findViewById(R.id.selected_thumbnail);
inputView.setOnLongClickListener(view -> {
inputListener.onRowClicked(getAdapterPosition());
inputView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
return true;
});
@Override
public void toggleSelection(int inputPosition){
super.toggleSelection(inputPosition);
int cardId = mIndexCardMap.get(inputPosition);
Boolean overlayValue = mInGroupOverlay.get(cardId);
if (overlayValue == null){
mInGroupOverlay.put(cardId, !isLoyaltyCardInGroup(cardId));
}else{
mInGroupOverlay.remove(cardId);
}
}
public int dpToPx(int dp, Context mContext){
Resources r = mContext.getResources();
int px = (int)TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics());
return px;
public boolean hasChanged() {
return mInGroupOverlay.size() > 0;
}
public void commitToDatabase(Context context){
// this is very inefficient but done to keep the size of DBHelper low
for(Map.Entry<Integer, Boolean> entry: mInGroupOverlay.entrySet()){
int cardId = entry.getKey();
List<Group> groups = mDb.getLoyaltyCardGroups(cardId);
if(entry.getValue()){
groups.add(mGroup);
}else{
groups.remove(mGroup);
}
mDb.setLoyaltyCardGroups(cardId, groups);
}
}
public void importInGroupState(HashMap<Integer, Boolean> cardIdInGroupMap) {
mInGroupOverlay = (HashMap<Integer, Boolean>) cardIdInGroupMap.clone();
}
public HashMap<Integer, Boolean> exportInGroupState(){
return (HashMap<Integer, Boolean>)mInGroupOverlay.clone();
}
public int getCountFromCursor() {
return super.getCursor().getCount();
}
}

View File

@@ -1,168 +0,0 @@
package protect.card_locker;
// Was thinking about extending LoyaltyCard but this makes things more modular..?
import android.database.Cursor;
import android.os.Parcel;
import android.os.Parcelable;
import java.math.BigDecimal;
import java.util.Currency;
import java.util.Date;
import androidx.annotation.Nullable;
public class ManageGroupLoyaltyCard implements Parcelable {
public final int id;
public final String store;
public final String note;
public final Date expiry;
public final BigDecimal balance;
public final Currency balanceType;
public final String cardId;
@Nullable
public final String barcodeId;
@Nullable
public final CatimaBarcode barcodeType;
@Nullable
public final Integer headerColor;
public final int starStatus;
public final long lastUsed;
public int zoomLevel;
public final boolean is_in_group;
public ManageGroupLoyaltyCard(final int id, final String store, final String note, final Date expiry,
final BigDecimal balance, final Currency balanceType, final String cardId,
@Nullable final String barcodeId, @Nullable final CatimaBarcode barcodeType,
@Nullable final Integer headerColor, final int starStatus, final long lastUsed,final int zoomLevel,
final boolean is_in_group)
{
this.id = id;
this.store = store;
this.note = note;
this.expiry = expiry;
this.balance = balance;
this.balanceType = balanceType;
this.cardId = cardId;
this.barcodeId = barcodeId;
this.barcodeType = barcodeType;
this.headerColor = headerColor;
this.starStatus = starStatus;
this.lastUsed = lastUsed;
this.zoomLevel = zoomLevel;
this.is_in_group = is_in_group;
}
protected ManageGroupLoyaltyCard(Parcel in) {
id = in.readInt();
store = in.readString();
note = in.readString();
long tmpExpiry = in.readLong();
expiry = tmpExpiry != -1 ? new Date(tmpExpiry) : null;
balance = (BigDecimal) in.readValue(BigDecimal.class.getClassLoader());
balanceType = (Currency) in.readValue(Currency.class.getClassLoader());
cardId = in.readString();
barcodeId = in.readString();
String tmpBarcodeType = in.readString();
barcodeType = !tmpBarcodeType.isEmpty() ? CatimaBarcode.fromName(tmpBarcodeType) : null;
int tmpHeaderColor = in.readInt();
headerColor = tmpHeaderColor != -1 ? tmpHeaderColor : null;
starStatus = in.readInt();
lastUsed = in.readLong();
zoomLevel = in.readInt();
if (in.readInt() == 1) {
is_in_group = true;
}else{
is_in_group = false;
}
}
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeInt(id);
parcel.writeString(store);
parcel.writeString(note);
parcel.writeLong(expiry != null ? expiry.getTime() : -1);
parcel.writeValue(balance);
parcel.writeValue(balanceType);
parcel.writeString(cardId);
parcel.writeString(barcodeId);
parcel.writeString(barcodeType != null ? barcodeType.name() : "");
parcel.writeInt(headerColor != null ? headerColor : -1);
parcel.writeInt(starStatus);
parcel.writeLong(lastUsed);
parcel.writeInt(zoomLevel);
if (is_in_group) {
parcel.writeInt(1);
}else{
parcel.writeInt(0);
}
}
public static ManageGroupLoyaltyCard toCard(Cursor cursor)
{
int id = cursor.getInt(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.ID));
String store = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.STORE));
String note = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.NOTE));
long expiryLong = cursor.getLong(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.EXPIRY));
BigDecimal balance = new BigDecimal(cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.BALANCE)));
String cardId = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.CARD_ID));
String barcodeId = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.BARCODE_ID));
int starred = cursor.getInt(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.STAR_STATUS));
long lastUsed = cursor.getLong(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.LAST_USED));
int zoomLevel = cursor.getInt(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.ZOOM_LEVEL));
int barcodeTypeColumn = cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.BARCODE_TYPE);
int balanceTypeColumn = cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.BALANCE_TYPE);
int headerColorColumn = cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.HEADER_COLOR);
boolean was_in_group = !cursor.isNull(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIdsGroups.groupID));
CatimaBarcode barcodeType = null;
Currency balanceType = null;
Date expiry = null;
Integer headerColor = null;
if (cursor.isNull(barcodeTypeColumn) == false)
{
barcodeType = CatimaBarcode.fromName(cursor.getString(barcodeTypeColumn));
}
if (cursor.isNull(balanceTypeColumn) == false)
{
balanceType = Currency.getInstance(cursor.getString(balanceTypeColumn));
}
if(expiryLong > 0)
{
expiry = new Date(expiryLong);
}
if(cursor.isNull(headerColorColumn) == false)
{
headerColor = cursor.getInt(headerColorColumn);
}
return new ManageGroupLoyaltyCard(id, store, note, expiry, balance, balanceType, cardId, barcodeId, barcodeType, headerColor, starred, lastUsed,zoomLevel,was_in_group);
}
@Override
public int describeContents() {
return id;
}
public static final Creator<LoyaltyCard> CREATOR = new Creator<LoyaltyCard>() {
@Override
public LoyaltyCard createFromParcel(Parcel in) {
return new LoyaltyCard(in);
}
@Override
public LoyaltyCard[] newArray(int size) {
return new LoyaltyCard[size];
}
};
}

View File

@@ -177,9 +177,8 @@ public class ManageGroupsActivity extends CatimaAppCompatActivity implements Gro
@Override
public void onEditButtonClicked(View view) {
Group group = mDb.getGroup(getGroupName(view));
Intent intent = new Intent(this, ManageGroupActivity.class);
intent.putExtra("group", group);
intent.putExtra("group", getGroupName(view));
startActivity(intent);
/*
final String groupName = c;