mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-05-17 05:09:08 -04:00
Add tab to switch between multiple barcodes of same store
This commit is contained in:
@@ -7,6 +7,9 @@ import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DBHelper extends SQLiteOpenHelper
|
||||
{
|
||||
public static final String DATABASE_NAME = "LoyaltyCards.db";
|
||||
@@ -170,6 +173,34 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all loyalty cards of the given store.
|
||||
*
|
||||
* @param store
|
||||
* @return List<LoyaltyCard>
|
||||
*/
|
||||
public List<LoyaltyCard> getLoyaltyCardsForStore(String store) {
|
||||
List<LoyaltyCard> loyaltyCards = new ArrayList<>();
|
||||
|
||||
SQLiteDatabase db = getReadableDatabase();
|
||||
String[] selectionArgs = { store };
|
||||
|
||||
Cursor res = db.rawQuery("select * from " + LoyaltyCardDbIds.TABLE +
|
||||
" WHERE " + LoyaltyCardDbIds.STORE + " IS ? " +
|
||||
" ORDER BY " + LoyaltyCardDbIds.STORE + " COLLATE NOCASE ASC", selectionArgs, null);
|
||||
|
||||
try
|
||||
{
|
||||
while (res.moveToNext()) {
|
||||
loyaltyCards.add(LoyaltyCard.toLoyaltyCard(res));
|
||||
}
|
||||
} finally {
|
||||
res.close();
|
||||
}
|
||||
|
||||
return loyaltyCards;
|
||||
}
|
||||
|
||||
public int getLoyaltyCardCount()
|
||||
{
|
||||
// An empty string will match everything
|
||||
|
||||
@@ -26,8 +26,11 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import protect.card_locker.preferences.Settings;
|
||||
|
||||
|
||||
@@ -36,6 +39,8 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
private static final String TAG = "CardLocker";
|
||||
private static final double LUMINANCE_MIDPOINT = 0.5;
|
||||
|
||||
TabLayout tabLayout;
|
||||
TabLayout.OnTabSelectedListener onTabSelectedListener;
|
||||
TextView cardIdFieldView;
|
||||
TextView noteView;
|
||||
View noteViewDivider;
|
||||
@@ -44,6 +49,7 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
View collapsingToolbarLayout;
|
||||
int loyaltyCardId;
|
||||
LoyaltyCard loyaltyCard;
|
||||
List<LoyaltyCard> storeCards;
|
||||
boolean rotationEnabled;
|
||||
DBHelper db;
|
||||
ImportURIHelper importURIHelper;
|
||||
@@ -96,6 +102,20 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
db = new DBHelper(this);
|
||||
importURIHelper = new ImportURIHelper(this);
|
||||
|
||||
tabLayout = findViewById(R.id.tabLayout);
|
||||
onTabSelectedListener = new TabLayout.OnTabSelectedListener() {
|
||||
@Override
|
||||
public void onTabSelected(TabLayout.Tab tab) {
|
||||
loyaltyCardId = storeCards.get(tab.getPosition()).id;
|
||||
onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabUnselected(TabLayout.Tab tab) {}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(TabLayout.Tab tab) {}
|
||||
};
|
||||
cardIdFieldView = findViewById(R.id.cardIdView);
|
||||
noteView = findViewById(R.id.noteView);
|
||||
noteViewDivider = findViewById(R.id.noteViewDivider);
|
||||
@@ -142,6 +162,32 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
return;
|
||||
}
|
||||
|
||||
storeCards = db.getLoyaltyCardsForStore(loyaltyCard.store);
|
||||
tabLayout.removeOnTabSelectedListener(onTabSelectedListener);
|
||||
tabLayout.removeAllTabs();
|
||||
for(int i = 0; i < storeCards.size(); i++)
|
||||
{
|
||||
LoyaltyCard storeCard = storeCards.get(i);
|
||||
|
||||
String loyaltyCardText = storeCard.note;
|
||||
if(loyaltyCardText.isEmpty())
|
||||
{
|
||||
loyaltyCardText = String.valueOf(i + 1);
|
||||
}
|
||||
|
||||
tabLayout.addTab(tabLayout.newTab().setText(loyaltyCardText));
|
||||
|
||||
if(storeCard.id == loyaltyCardId)
|
||||
{
|
||||
tabLayout.getTabAt(i).select();
|
||||
}
|
||||
}
|
||||
tabLayout.addOnTabSelectedListener(onTabSelectedListener);
|
||||
if(tabLayout.getTabCount() > 1)
|
||||
{
|
||||
tabLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
String formatString = loyaltyCard.barcodeType;
|
||||
final BarcodeFormat format = !formatString.isEmpty() ? BarcodeFormat.valueOf(formatString) : null;
|
||||
final String cardIdString = loyaltyCard.cardId;
|
||||
|
||||
@@ -27,6 +27,18 @@
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintGuide_percent="0.5"/>
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:visibility="gone"
|
||||
android:id="@+id/tabLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toTopOf="@+id/barcode"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:tabGravity="fill"
|
||||
app:tabMode="scrollable"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/barcode"
|
||||
android:layout_width="0dp"
|
||||
@@ -35,10 +47,10 @@
|
||||
android:layout_marginBottom="10.0dip"
|
||||
android:layout_marginStart="15.0dip"
|
||||
android:layout_marginEnd="15.0dip"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tabLayout"
|
||||
app:layout_constraintBottom_toTopOf="@+id/centerGuideline"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:contentDescription="@string/barcodeImageDescription"/>
|
||||
|
||||
<TextView
|
||||
|
||||
Reference in New Issue
Block a user