mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-01-24 14:58:07 -05:00
committed by
Sylvia van Os
parent
67328724fa
commit
45663065f9
@@ -21,7 +21,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
/**
|
||||
* The configuration screen for creating a shortcut.
|
||||
*/
|
||||
public class CardShortcutConfigure extends AppCompatActivity implements LoyaltyCardCursorAdapter.MessageAdapterListener
|
||||
public class CardShortcutConfigure extends AppCompatActivity implements LoyaltyCardCursorAdapter.CardAdapterListener
|
||||
{
|
||||
static final String TAG = "Catima";
|
||||
final DBHelper mDb = new DBHelper(this);
|
||||
@@ -92,7 +92,7 @@ public class CardShortcutConfigure extends AppCompatActivity implements LoyaltyC
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageRowClicked(int inputPosition) {
|
||||
public void onRowClicked(int inputPosition) {
|
||||
onClickAction(inputPosition);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,11 +14,9 @@ import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import androidx.cardview.widget.CardView;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
@@ -30,18 +28,20 @@ public class LoyaltyCardCursorAdapter extends BaseCursorAdapter<LoyaltyCardCurso
|
||||
Settings settings;
|
||||
|
||||
private static int mCurrentSelectedIndex = -1;
|
||||
private Cursor mCursor;
|
||||
Settings mSettings;
|
||||
boolean mDarkModeEnabled;
|
||||
private Context mContext;
|
||||
private MessageAdapterListener mListener;
|
||||
private CardAdapterListener mListener;
|
||||
private SparseBooleanArray mSelectedItems;
|
||||
private SparseBooleanArray mAnimationItemsIndex;
|
||||
private boolean mReverseAllAnimations = false;
|
||||
|
||||
public LoyaltyCardCursorAdapter(Context inputContext, Cursor inputCursor, MessageAdapterListener inputListener)
|
||||
public LoyaltyCardCursorAdapter(Context inputContext, Cursor inputCursor, CardAdapterListener inputListener)
|
||||
{
|
||||
super(inputCursor);
|
||||
settings = new Settings(inputContext);
|
||||
mCursor = inputCursor;
|
||||
this.mContext = inputContext;
|
||||
this.mListener = inputListener;
|
||||
mSelectedItems = new SparseBooleanArray();
|
||||
@@ -58,6 +58,11 @@ public class LoyaltyCardCursorAdapter extends BaseCursorAdapter<LoyaltyCardCurso
|
||||
return new LoyaltyCardListItemViewHolder(itemView);
|
||||
}
|
||||
|
||||
public Cursor getCursor()
|
||||
{
|
||||
return mCursor;
|
||||
}
|
||||
|
||||
public void onBindViewHolder(LoyaltyCardListItemViewHolder inputHolder, Cursor inputCursor) {
|
||||
if (mDarkModeEnabled) {
|
||||
inputHolder.mStarIcon.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
|
||||
@@ -128,7 +133,7 @@ public class LoyaltyCardCursorAdapter extends BaseCursorAdapter<LoyaltyCardCurso
|
||||
@Override
|
||||
public void onClick(View inputView)
|
||||
{
|
||||
mListener.onMessageRowClicked(inputPosition);
|
||||
mListener.onRowClicked(inputPosition);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -137,7 +142,7 @@ public class LoyaltyCardCursorAdapter extends BaseCursorAdapter<LoyaltyCardCurso
|
||||
@Override
|
||||
public void onClick(View inputView)
|
||||
{
|
||||
mListener.onMessageRowClicked(inputPosition);
|
||||
mListener.onRowClicked(inputPosition);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -234,15 +239,30 @@ public class LoyaltyCardCursorAdapter extends BaseCursorAdapter<LoyaltyCardCurso
|
||||
return mSelectedItems.size();
|
||||
}
|
||||
|
||||
public ArrayList<LoyaltyCard> getSelectedItems()
|
||||
{
|
||||
|
||||
ArrayList<LoyaltyCard> result = new ArrayList<>();
|
||||
|
||||
int i;
|
||||
for(i = 0; i < mSelectedItems.size(); i++)
|
||||
{
|
||||
mCursor.moveToPosition(mSelectedItems.keyAt(i));
|
||||
result.add(LoyaltyCard.toLoyaltyCard(mCursor));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void resetCurrentIndex()
|
||||
{
|
||||
mCurrentSelectedIndex = -1;
|
||||
}
|
||||
|
||||
public interface MessageAdapterListener
|
||||
public interface CardAdapterListener
|
||||
{
|
||||
void onIconClicked(int inputPosition);
|
||||
void onMessageRowClicked(int inputPosition);
|
||||
void onRowClicked(int inputPosition);
|
||||
void onRowLongClicked(int inputPosition);
|
||||
}
|
||||
|
||||
@@ -259,17 +279,17 @@ public class LoyaltyCardCursorAdapter extends BaseCursorAdapter<LoyaltyCardCurso
|
||||
public LoyaltyCardListItemViewHolder(View inputView)
|
||||
{
|
||||
super(inputView);
|
||||
mThumbnailContainer = (CardView) inputView.findViewById(R.id.thumbnail_container);
|
||||
mRow = (ConstraintLayout) inputView.findViewById(R.id.row);
|
||||
mThumbnailFrontContainer = (RelativeLayout) inputView.findViewById(R.id.thumbnail_front);
|
||||
mThumbnailBackContainer = (RelativeLayout) inputView.findViewById(R.id.thumbnail_back);
|
||||
mInformationContainer= (LinearLayout) inputView.findViewById(R.id.information_container);
|
||||
mStoreField = (TextView) inputView.findViewById(R.id.store);
|
||||
mNoteField = (TextView) inputView.findViewById(R.id.note);
|
||||
mBalanceField = (TextView) inputView.findViewById(R.id.balanceField);
|
||||
mExpiryField = (TextView) inputView.findViewById(R.id.expiryField);
|
||||
mCardIcon = (ImageView) inputView.findViewById(R.id.thumbnail);
|
||||
mStarIcon = (ImageView) inputView.findViewById(R.id.star);
|
||||
mThumbnailContainer = inputView.findViewById(R.id.thumbnail_container);
|
||||
mRow = inputView.findViewById(R.id.row);
|
||||
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.balanceField);
|
||||
mExpiryField = inputView.findViewById(R.id.expiryField);
|
||||
mCardIcon = inputView.findViewById(R.id.thumbnail);
|
||||
mStarIcon = inputView.findViewById(R.id.star);
|
||||
inputView.setOnLongClickListener(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,13 +37,12 @@ import java.util.List;
|
||||
|
||||
import protect.card_locker.preferences.SettingsActivity;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements LoyaltyCardCursorAdapter.MessageAdapterListener, GestureDetector.OnGestureListener
|
||||
public class MainActivity extends AppCompatActivity implements LoyaltyCardCursorAdapter.CardAdapterListener, GestureDetector.OnGestureListener
|
||||
{
|
||||
private static final String TAG = "Catima";
|
||||
|
||||
private final DBHelper mDB = new DBHelper(this);
|
||||
private LoyaltyCardCursorAdapter mAdapter;
|
||||
private LoyaltyCard mCard;
|
||||
private ActionMode mCurrentActionMode;
|
||||
private Menu mMenu;
|
||||
private GestureDetector mGestureDetector;
|
||||
@@ -71,29 +70,55 @@ public class MainActivity extends AppCompatActivity implements LoyaltyCardCursor
|
||||
{
|
||||
if (inputItem.getItemId() == R.id.action_copy_to_clipboard)
|
||||
{
|
||||
inputMode.finish();
|
||||
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||||
ClipData clip = ClipData.newPlainText(mCard.store, mCard.cardId);
|
||||
|
||||
String clipboardData;
|
||||
int cardCount = mAdapter.getSelectedItemCount();
|
||||
|
||||
if (cardCount == 1) {
|
||||
clipboardData = mAdapter.getSelectedItems().get(0).cardId;
|
||||
} else {
|
||||
StringBuilder cardIds = new StringBuilder();
|
||||
|
||||
|
||||
for (int i = 0; i < cardCount - 1; i++) {
|
||||
LoyaltyCard loyaltyCard = mAdapter.getSelectedItems().get(i);
|
||||
|
||||
cardIds.append(loyaltyCard.store + ": " + loyaltyCard.cardId);
|
||||
if (i != (cardCount - 1)) {
|
||||
cardIds.append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
clipboardData = cardIds.toString();
|
||||
}
|
||||
|
||||
ClipData clip = ClipData.newPlainText(getString(R.string.card_ids_copied), clipboardData);
|
||||
clipboard.setPrimaryClip(clip);
|
||||
Toast.makeText(MainActivity.this, R.string.copy_to_clipboard_toast, Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(MainActivity.this, cardCount > 1 ? R.string.copy_to_clipboard_multiple_toast : R.string.copy_to_clipboard_toast, Toast.LENGTH_LONG).show();
|
||||
inputMode.finish();
|
||||
return true;
|
||||
}
|
||||
else if (inputItem.getItemId() == R.id.action_share)
|
||||
{
|
||||
// final ImportURIHelper importURIHelper = new ImportURIHelper(MainActivity.this);
|
||||
// importURIHelper.startShareIntent(mCard);
|
||||
inputMode.finish();
|
||||
final ImportURIHelper importURIHelper = new ImportURIHelper(MainActivity.this);
|
||||
importURIHelper.startShareIntent(mCard);
|
||||
return true;
|
||||
}
|
||||
else if(inputItem.getItemId() == R.id.action_edit)
|
||||
{
|
||||
inputMode.finish();
|
||||
if (mAdapter.getSelectedItemCount() != 1) {
|
||||
throw new IllegalArgumentException("Cannot edit more than 1 card at a time");
|
||||
}
|
||||
|
||||
Intent intent = new Intent(getApplicationContext(), LoyaltyCardEditActivity.class);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt("id", mCard.id);
|
||||
bundle.putInt("id", mAdapter.getSelectedItems().get(0).id);
|
||||
bundle.putBoolean("update", true);
|
||||
intent.putExtras(bundle);
|
||||
startActivity(intent);
|
||||
inputMode.finish();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -327,10 +352,6 @@ public class MainActivity extends AppCompatActivity implements LoyaltyCardCursor
|
||||
mCardList.setLayoutManager(mLayoutManager);
|
||||
mCardList.setItemAnimator(new DefaultItemAnimator());
|
||||
|
||||
DividerItemDecoration itemDecorator= new DividerItemDecoration(this, LinearLayoutManager.VERTICAL);
|
||||
itemDecorator.setDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.list_divider));
|
||||
mCardList.addItemDecoration(itemDecorator);
|
||||
|
||||
final TextView helpText = findViewById(R.id.helpText);
|
||||
final TextView noMatchingCardsText = findViewById(R.id.noMatchingCardsText);
|
||||
|
||||
@@ -363,6 +384,10 @@ public class MainActivity extends AppCompatActivity implements LoyaltyCardCursor
|
||||
mCardList.setAdapter(mAdapter);
|
||||
|
||||
registerForContextMenu(mCardList);
|
||||
|
||||
if (mCurrentActionMode != null) {
|
||||
mCurrentActionMode.finish();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTabGroups(TabLayout groupsTabLayout)
|
||||
@@ -616,7 +641,7 @@ public class MainActivity extends AppCompatActivity implements LoyaltyCardCursor
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageRowClicked(int inputPosition)
|
||||
public void onRowClicked(int inputPosition)
|
||||
{
|
||||
|
||||
if (mAdapter.getSelectedItemCount() > 0)
|
||||
@@ -625,7 +650,7 @@ public class MainActivity extends AppCompatActivity implements LoyaltyCardCursor
|
||||
}
|
||||
else
|
||||
{
|
||||
Cursor selected = (Cursor) mDB.getLoyaltyCardCursor();
|
||||
Cursor selected = mAdapter.getCursor();
|
||||
selected.moveToPosition(inputPosition);
|
||||
LoyaltyCard loyaltyCard = LoyaltyCard.toLoyaltyCard(selected);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user