Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustResize"/>
<activity
android:name=".LoyaltyCardViewActivity"
android:name=".cardview.LoyaltyCardViewActivity"
android:exported="true"
android:theme="@style/AppTheme.NoActionBar" />
<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class BarcodeImageWriterTask implements CompatCallable<Bitmap> {
private final boolean showFallback;
private final BarcodeImageWriterResultCallback callback;

BarcodeImageWriterTask(
public BarcodeImageWriterTask(
Context context, ImageView imageView, String cardIdString,
CatimaBarcode barcodeFormat, @NonNull Charset barcodeEncoding, TextView textView,
boolean showFallback, BarcodeImageWriterResultCallback callback, boolean roundCornerPadding, boolean isFullscreen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.concurrent.Flow;
import java.util.function.Consumer;

import protect.card_locker.cardview.LoyaltyCardViewActivity;

Comment on lines +25 to +26
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import seems unnecessary, right?

Copy link
Copy Markdown
Author

@NightShiftNexus NightShiftNexus Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is used for example in line

 Intent openIntent = new Intent(this, LoyaltyCardViewActivity.class)
                        .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                        .putExtra(LoyaltyCardViewActivity.BUNDLE_ID, card.id);

@RequiresApi(Build.VERSION_CODES.R)
public class CardsOnPowerScreenService extends ControlsProviderService {

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/protect/card_locker/ListWidget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.view.View
import android.widget.RemoteViews
import androidx.core.widget.RemoteViewsCompat
import protect.card_locker.DBHelper.LoyaltyCardArchiveFilter
import protect.card_locker.cardview.LoyaltyCardViewActivity
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import seems unnecessary, right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is used for example in line

  val templateIntent = Intent(context, LoyaltyCardViewActivity::class.java).apply {
                   flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
               }


class ListWidget : AppWidgetProvider() {
fun updateAll(context: Context) {
Expand Down Expand Up @@ -129,4 +130,4 @@ class ListWidget : AppWidgetProvider() {

return remoteViews
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,14 @@ public void handleOnBackPressed() {
});
}

@Override
protected void onDestroy() {
if (mDatabase != null && mDatabase.isOpen()) {
mDatabase.close();
}
super.onDestroy();
}

private void selectTab(int index) {
binding.tabs.selectTab(binding.tabs.getTabAt(index));
viewModel.setTabIndex(index);
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/protect/card_locker/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.google.android.material.tabs.TabLayout.OnTabSelectedListener
import protect.card_locker.DBHelper.LoyaltyCardOrder
import protect.card_locker.DBHelper.LoyaltyCardOrderDirection
import protect.card_locker.LoyaltyCardCursorAdapter.CardAdapterListener
import protect.card_locker.cardview.LoyaltyCardViewActivity
import protect.card_locker.databinding.ContentMainBinding
import protect.card_locker.databinding.MainActivityBinding
import protect.card_locker.databinding.SortingOptionBinding
Expand Down
45 changes: 24 additions & 21 deletions app/src/main/java/protect/card_locker/ShortcutHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
import androidx.core.graphics.drawable.IconCompat;

import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.LinkedList;

class ShortcutHelper {
import protect.card_locker.cardview.LoyaltyCardViewActivity;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import seems unnecessary, right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently is used for example in
Intent intent = new Intent(context, LoyaltyCardViewActivity.class);

I removed import java.util.Collections; because it was unnecessary


public class ShortcutHelper {
/**
* This variable controls the maximum number of shortcuts available.
* It is made public only to make testing easier and should not be
Expand All @@ -43,33 +43,36 @@ class ShortcutHelper {
* based on the lastUsed field. Archived cards are excluded from the shortcuts
* list. The list keeps at most maxShortcuts number of elements.
*/
static void updateShortcuts(Context context) {
public static void updateShortcuts(Context context) {
if (maxShortcuts == -1) {
maxShortcuts = ShortcutManagerCompat.getMaxShortcutCountPerActivity(context);
}
LinkedList<ShortcutInfoCompat> finalList = new LinkedList<>();
SQLiteDatabase database = new DBHelper(context).getReadableDatabase();
Cursor loyaltyCardCursor = DBHelper.getLoyaltyCardCursor(
DBHelper dbHelper = new DBHelper(context);
SQLiteDatabase database = dbHelper.getReadableDatabase();
try (Cursor loyaltyCardCursor = DBHelper.getLoyaltyCardCursor(
database,
"",
null,
DBHelper.LoyaltyCardOrder.LastUsed,
DBHelper.LoyaltyCardOrderDirection.Ascending,
DBHelper.LoyaltyCardArchiveFilter.Unarchived
);

int rank = 0;

while (rank < maxShortcuts && loyaltyCardCursor.moveToNext()) {
int id = loyaltyCardCursor.getInt(loyaltyCardCursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.ID));
LoyaltyCard loyaltyCard = DBHelper.getLoyaltyCard(context, database, id);

ShortcutInfoCompat updatedShortcut = createShortcutBuilder(context, loyaltyCard)
.setRank(rank)
.build();

finalList.addLast(updatedShortcut);
rank++;
)) {
int rank = 0;

while (rank < maxShortcuts && loyaltyCardCursor.moveToNext()) {
int id = loyaltyCardCursor.getInt(loyaltyCardCursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.ID));
LoyaltyCard loyaltyCard = DBHelper.getLoyaltyCard(context, database, id);

ShortcutInfoCompat updatedShortcut = createShortcutBuilder(context, loyaltyCard)
.setRank(rank)
.build();

finalList.addLast(updatedShortcut);
rank++;
}
} finally {
dbHelper.close();
}

ShortcutManagerCompat.setDynamicShortcuts(context, finalList);
Expand Down Expand Up @@ -110,4 +113,4 @@ static ShortcutInfoCompat.Builder createShortcutBuilder(Context context, Loyalty
.setIntent(intent)
.setIcon(icon);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package protect.card_locker.cardview;

import java.util.ArrayList;
import java.util.List;

final class LoyaltyCardImageNavigator {
private final List<LoyaltyCardImageType> imageTypes;
private int currentIndex;

LoyaltyCardImageNavigator(List<LoyaltyCardImageType> imageTypes, int currentIndex) {
this.imageTypes = new ArrayList<>(imageTypes);
this.currentIndex = clampIndex(currentIndex);
}

LoyaltyCardImageType getCurrent() {
if (isEmpty()) {
return LoyaltyCardImageType.NONE;
}
return imageTypes.get(currentIndex);
}

boolean isEmpty() {
return imageTypes.isEmpty();
}

int size() {
return imageTypes.size();
}

boolean remove(LoyaltyCardImageType type) {
int removedIndex = imageTypes.indexOf(type);
if (removedIndex == -1) {
return false;
}

imageTypes.remove(removedIndex);
currentIndex = clampIndex(currentIndex);
return true;
}

boolean canGoPrevious() {
return currentIndex > 0;
}

boolean canGoNext() {
return currentIndex < imageTypes.size() - 1;
}

boolean movePrevious() {
if (!canGoPrevious()) {
return false;
}
currentIndex--;
return true;
}

boolean moveNext(boolean overflow) {
if (isEmpty()) {
return false;
}
if (canGoNext()) {
currentIndex++;
return true;
}
if (overflow) {
currentIndex = 0;
return true;
}
return false;
}

int getCurrentIndex() {
return currentIndex;
}

LoyaltyCardImageType peekNext(boolean overflow) {
if (isEmpty()) {
return LoyaltyCardImageType.NONE;
}

if (canGoNext()) {
return imageTypes.get(currentIndex + 1);
}

return overflow ? imageTypes.get(0) : getCurrent();
}

private int clampIndex(int index) {
if (imageTypes.isEmpty()) {
return 0;
}

return Math.max(0, Math.min(index, imageTypes.size() - 1));
}
}

enum LoyaltyCardImageType {
NONE,
ICON,
BARCODE,
IMAGE_FRONT,
IMAGE_BACK
}
Loading