diff --git a/app/src/main/java/com/a494studios/koreanconjugator/display/DisplayObserver.java b/app/src/main/java/com/a494studios/koreanconjugator/display/DisplayObserver.java index 7a783193..97b64f45 100644 --- a/app/src/main/java/com/a494studios/koreanconjugator/display/DisplayObserver.java +++ b/app/src/main/java/com/a494studios/koreanconjugator/display/DisplayObserver.java @@ -53,11 +53,12 @@ public void setEntry(EntryQuery.Entry entry) { @Override public void onNext(FavoritesQuery.Data favData) { // Favorites, hide the card and skip if there are none - if (favData.favConjugations().isEmpty()) { + String pos = entry.pos(); + if (!pos.equals("Adjective") && !pos.equals("Verb")) { conjugations.setVisibility(View.GONE); } else { List conjugations = favData.favConjugations(); - boolean isAdj = entry.pos().equals("Adjective"); + boolean isAdj = pos.equals("Adjective"); Boolean regular = entry.regular(); List favorites = Utils.getFavorites(displayCardView.getContext()); diff --git a/app/src/main/java/com/a494studios/koreanconjugator/display/cards/FavoritesCard.java b/app/src/main/java/com/a494studios/koreanconjugator/display/cards/FavoritesCard.java index adc72bc2..0429c526 100644 --- a/app/src/main/java/com/a494studios/koreanconjugator/display/cards/FavoritesCard.java +++ b/app/src/main/java/com/a494studios/koreanconjugator/display/cards/FavoritesCard.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.view.View; import android.view.ViewGroup; +import android.widget.TextView; import com.a494studios.koreanconjugator.conjugations.ConjugationActivity; import com.a494studios.koreanconjugator.R; @@ -21,6 +22,8 @@ public class FavoritesCard implements DisplayCardBody { private View view; + private TextView emptyView; + private LinearListView listView; private String stem; private boolean honorific; @@ -38,24 +41,29 @@ public FavoritesCard(ArrayList> entries, @Override public View addBodyView(Context context, ViewGroup parentView, DisplayCardView cardView) { - if(view == null) { + if (view == null) { view = View.inflate(context, R.layout.dcard_list, parentView); } - LinearListView listView = view.findViewById(R.id.listCard_list); + + emptyView = view.findViewById(R.id.listCard_empty); + listView = view.findViewById(R.id.listCard_list); + emptyView.setText(R.string.empty_favorites); + toggleEmptyState(adapter.isEmpty()); + listView.setAdapter(adapter); listView.setOnItemClickListener((parent, view, position, id) -> { String favName = adapter.getItem(position).getKey(); - ConjugationFragment conjugation = adapter.getItem(position).getValue(); + ConjugationFragment conjugation = adapter.getItem(position).getValue(); // Log select favorite event Logger.getInstance().logSelectFavorite(favName, conjugation.name(), conjugation.conjugation()); Intent i = new Intent(view.getContext(), ConjInfoActivity.class); i.putExtra(ConjInfoActivity.EXTRA_NAME, conjugation.name()); - i.putExtra(ConjInfoActivity.EXTRA_CONJ,conjugation.conjugation()); - i.putExtra(ConjInfoActivity.EXTRA_PRON,conjugation.pronunciation()); - i.putExtra(ConjInfoActivity.EXTRA_ROME,conjugation.romanization()); - i.putExtra(ConjInfoActivity.EXTRA_EXPL,new ArrayList<>(conjugation.reasons())); + i.putExtra(ConjInfoActivity.EXTRA_CONJ, conjugation.conjugation()); + i.putExtra(ConjInfoActivity.EXTRA_PRON, conjugation.pronunciation()); + i.putExtra(ConjInfoActivity.EXTRA_ROME, conjugation.romanization()); + i.putExtra(ConjInfoActivity.EXTRA_EXPL, new ArrayList<>(conjugation.reasons())); i.putExtra(ConjInfoActivity.EXTRA_HONO, conjugation.honorific()); view.getContext().startActivity(i); }); @@ -89,6 +97,17 @@ public String getHeading() { public void addConjugation(Map.Entry conjugation, int index) { adapter.addConjugation(conjugation, index); adapter.notifyDataSetChanged(); + toggleEmptyState(false); + } + + private void toggleEmptyState(boolean isEmpty) { + if(isEmpty) { + emptyView.setVisibility(View.VISIBLE); + listView.setVisibility(View.GONE); + } else { + emptyView.setVisibility(View.GONE); + listView.setVisibility(View.VISIBLE); + } } } diff --git a/app/src/main/res/layout/dcard_list.xml b/app/src/main/res/layout/dcard_list.xml index ff113205..dc9029c4 100644 --- a/app/src/main/res/layout/dcard_list.xml +++ b/app/src/main/res/layout/dcard_list.xml @@ -7,4 +7,11 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" /> + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fa5ad7ae..de48e417 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -58,6 +58,7 @@ Regular Forms Remove Ads : + You don\'t have any favorites. Click on favorites in settings to make some. Submit Add suggestion diff --git a/app/src/test/java/com/a494studios/koreanconjugator/display/cards/FavoritesCardUnitTest.java b/app/src/test/java/com/a494studios/koreanconjugator/display/cards/FavoritesCardUnitTest.java index 9d15ac24..af209e5b 100644 --- a/app/src/test/java/com/a494studios/koreanconjugator/display/cards/FavoritesCardUnitTest.java +++ b/app/src/test/java/com/a494studios/koreanconjugator/display/cards/FavoritesCardUnitTest.java @@ -3,9 +3,11 @@ import android.app.Activity; import android.content.ComponentName; import android.content.Intent; +import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.LinearLayout; +import android.widget.TextView; import com.a494studios.koreanconjugator.R; import com.a494studios.koreanconjugator.conjugations.ConjugationActivity; @@ -111,6 +113,16 @@ public void test_addConjugation() { Map.Entry entry = new AbstractMap.SimpleEntry<>("new", conjugation); card.addConjugation(entry,0); - assertEquals(1,card.getCount()); + assertEquals(1, card.getCount()); + + TextView emptyView = viewGroup.findViewById(R.id.listCard_empty); + assertEquals(emptyView.getVisibility(), View.GONE); + } + + @Test + public void test_emptyState() { + TextView emptyView = viewGroup.findViewById(R.id.listCard_empty); + assertEquals(emptyView.getVisibility(), View.VISIBLE); + assertEquals(emptyView.getText().toString(), activity.getString(R.string.empty_favorites)); } }