From b4b544e342e988d7baddc5baeda9cc63a6c6e381 Mon Sep 17 00:00:00 2001 From: Katharine Date: Sat, 30 Oct 2021 11:04:21 +0800 Subject: [PATCH] remove modularity --- .../main/java/protect/card_locker/Group.java | 20 + .../card_locker/LoyaltyCardCursorAdapter.java | 4 +- .../card_locker/ManageGroupActivity.java | 25 +- .../card_locker/ManageGroupCursorAdapter.java | 361 +++--------------- .../card_locker/ManageGroupLoyaltyCard.java | 168 -------- .../card_locker/ManageGroupsActivity.java | 3 +- .../main/res/layout/activity_manage_group.xml | 2 +- .../main/res/layout/content_manage_group.xml | 49 --- .../manage_group_loyalty_card_layout.xml | 147 ------- 9 files changed, 97 insertions(+), 682 deletions(-) delete mode 100644 app/src/main/java/protect/card_locker/ManageGroupLoyaltyCard.java delete mode 100644 app/src/main/res/layout/content_manage_group.xml delete mode 100644 app/src/main/res/layout/manage_group_loyalty_card_layout.xml diff --git a/app/src/main/java/protect/card_locker/Group.java b/app/src/main/java/protect/card_locker/Group.java index 0120dd229..fab064cda 100644 --- a/app/src/main/java/protect/card_locker/Group.java +++ b/app/src/main/java/protect/card_locker/Group.java @@ -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(); + } } diff --git a/app/src/main/java/protect/card_locker/LoyaltyCardCursorAdapter.java b/app/src/main/java/protect/card_locker/LoyaltyCardCursorAdapter.java index 8572fe152..f259768c1 100644 --- a/app/src/main/java/protect/card_locker/LoyaltyCardCursorAdapter.java +++ b/app/src/main/java/protect/card_locker/LoyaltyCardCursorAdapter.java @@ -35,8 +35,8 @@ public class LoyaltyCardCursorAdapter extends BaseCursorAdapter 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); + } } diff --git a/app/src/main/java/protect/card_locker/ManageGroupCursorAdapter.java b/app/src/main/java/protect/card_locker/ManageGroupCursorAdapter.java index c1a10d6d0..a88083474 100644 --- a/app/src/main/java/protect/card_locker/ManageGroupCursorAdapter.java +++ b/app/src/main/java/protect/card_locker/ManageGroupCursorAdapter.java @@ -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 { - 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 mIndexCardMap; +public class ManageGroupCursorAdapter extends LoyaltyCardCursorAdapter { + private HashMap mIndexCardMap; private HashMap 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(); - swapCursor(mCursor); + mDb = new DBHelper(inputContext); } @Override public void swapCursor(Cursor inputCursor) { - mIndexCardMap = new HashMap(); - super.swapCursor(inputCursor); - mCursor = inputCursor; - + mIndexCardMap = new HashMap(); } @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 fetchWholeQuery (){ - HashMap res = new HashMap(); - 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 cache = fetchWholeQuery(); - for(Map.Entry 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 cache = fetchWholeQuery(); - for(Map.Entry entry : mInGroupOverlay.entrySet()){ - ManageGroupLoyaltyCard cardEntry = cache.get(entry.getKey()); - if(cardEntry.is_in_group != entry.getValue()){ + private boolean isLoyaltyCardInGroup(int cardId){ + List groups = mDb.getLoyaltyCardGroups(cardId); + Iterator groupItr = groups.listIterator(); + while(groupItr.hasNext()){ + if (groupItr.next().equals(mGroup)){ return true; } } return false; } - public int getCountFromCursor(){ - return mCursor.getCount(); - } - - public HashMap exportInGroupState(){ - return (HashMap)mInGroupOverlay.clone(); - } - - public void importInGroupState(HashMap cardIdInGroupMap){ - mInGroupOverlay = (HashMap)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 entry: mInGroupOverlay.entrySet()){ + int cardId = entry.getKey(); + List groups = mDb.getLoyaltyCardGroups(cardId); + if(entry.getValue()){ + groups.add(mGroup); + }else{ + groups.remove(mGroup); + } + mDb.setLoyaltyCardGroups(cardId, groups); + } + } + + public void importInGroupState(HashMap cardIdInGroupMap) { + mInGroupOverlay = (HashMap) cardIdInGroupMap.clone(); + } + + public HashMap exportInGroupState(){ + return (HashMap)mInGroupOverlay.clone(); + } + + public int getCountFromCursor() { + return super.getCursor().getCount(); } } diff --git a/app/src/main/java/protect/card_locker/ManageGroupLoyaltyCard.java b/app/src/main/java/protect/card_locker/ManageGroupLoyaltyCard.java deleted file mode 100644 index 0010d1f19..000000000 --- a/app/src/main/java/protect/card_locker/ManageGroupLoyaltyCard.java +++ /dev/null @@ -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 CREATOR = new Creator() { - @Override - public LoyaltyCard createFromParcel(Parcel in) { - return new LoyaltyCard(in); - } - - @Override - public LoyaltyCard[] newArray(int size) { - return new LoyaltyCard[size]; - } - }; -} diff --git a/app/src/main/java/protect/card_locker/ManageGroupsActivity.java b/app/src/main/java/protect/card_locker/ManageGroupsActivity.java index 9140ef7de..60127bd24 100644 --- a/app/src/main/java/protect/card_locker/ManageGroupsActivity.java +++ b/app/src/main/java/protect/card_locker/ManageGroupsActivity.java @@ -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; diff --git a/app/src/main/res/layout/activity_manage_group.xml b/app/src/main/res/layout/activity_manage_group.xml index 32f696a4c..75031e891 100644 --- a/app/src/main/res/layout/activity_manage_group.xml +++ b/app/src/main/res/layout/activity_manage_group.xml @@ -49,7 +49,7 @@ + layout="@layout/content_main" /> diff --git a/app/src/main/res/layout/content_manage_group.xml b/app/src/main/res/layout/content_manage_group.xml deleted file mode 100644 index 71a305bcb..000000000 --- a/app/src/main/res/layout/content_manage_group.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - diff --git a/app/src/main/res/layout/manage_group_loyalty_card_layout.xml b/app/src/main/res/layout/manage_group_loyalty_card_layout.xml deleted file mode 100644 index 4c3af71d5..000000000 --- a/app/src/main/res/layout/manage_group_loyalty_card_layout.xml +++ /dev/null @@ -1,147 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file