mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-03-31 13:51:52 -04:00
Show warning when no matches
This commit is contained in:
@@ -175,5 +175,29 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
|
||||
return numItems;
|
||||
}
|
||||
|
||||
public int getFilteredLoyaltyCardCount(String filter)
|
||||
{
|
||||
String actualFilter = String.format("%%%s%%", filter);
|
||||
String[] selectionArgs = { actualFilter, actualFilter };
|
||||
|
||||
SQLiteDatabase db = getReadableDatabase();
|
||||
Cursor data = db.rawQuery("SELECT Count(*) FROM " + LoyaltyCardDbIds.TABLE +
|
||||
" WHERE " + LoyaltyCardDbIds.STORE + " LIKE ? " +
|
||||
" OR " + LoyaltyCardDbIds.NOTE + " LIKE ? "
|
||||
, selectionArgs, null);
|
||||
|
||||
int numItems = 0;
|
||||
|
||||
if(data.getCount() == 1)
|
||||
{
|
||||
data.moveToFirst();
|
||||
numItems = data.getInt(0);
|
||||
}
|
||||
|
||||
data.close();
|
||||
|
||||
return numItems;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +87,7 @@ public class MainActivity extends AppCompatActivity
|
||||
final EditText filter = findViewById(R.id.menu_filter);
|
||||
final ListView cardList = findViewById(R.id.list);
|
||||
final TextView helpText = findViewById(R.id.helpText);
|
||||
final TextView noMatchingCardsText = findViewById(R.id.noMatchingCardsText);
|
||||
final DBHelper db = new DBHelper(this);
|
||||
|
||||
if(db.getLoyaltyCardCount() > 0)
|
||||
@@ -94,12 +95,21 @@ public class MainActivity extends AppCompatActivity
|
||||
filter.setVisibility(View.VISIBLE);
|
||||
cardList.setVisibility(View.VISIBLE);
|
||||
helpText.setVisibility(View.GONE);
|
||||
if(db.getFilteredLoyaltyCardCount(filterText) > 0)
|
||||
{
|
||||
noMatchingCardsText.setVisibility(View.GONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
noMatchingCardsText.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
filter.setVisibility(View.GONE);
|
||||
cardList.setVisibility(View.GONE);
|
||||
helpText.setVisibility(View.VISIBLE);
|
||||
noMatchingCardsText.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
Cursor cardCursor = db.getLoyaltyCardCursor(filterText);
|
||||
|
||||
@@ -17,6 +17,14 @@
|
||||
android:text="@string/noGiftCards"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<TextView
|
||||
style="@style/AppTheme.TextView.NoData"
|
||||
android:id="@+id/noMatchingCardsText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/noMatchingGiftCards"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<ListView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
<string name="typeToSearch">Type to search</string>
|
||||
<string name="noGiftCards">You don\'t have any loyalty cards at the moment. Click the "+" (plus) button up top to get started.\n\nLoyalty Card Locker lets you carry your loyalty cards on your phone, so they are always within reach.</string>
|
||||
<string name="noMatchingGiftCards">No loyalty cards match the search filter. Please try some different terms.</string>
|
||||
|
||||
<string name="storeName">Store</string>
|
||||
<string name="note">Note</string>
|
||||
|
||||
Reference in New Issue
Block a user