Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninjaman494 committed May 11, 2021
2 parents d4d1878 + 9fb7c3b commit 3e0c190
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<FavoritesQuery.FavConjugation> conjugations = favData.favConjugations();
boolean isAdj = entry.pos().equals("Adjective");
boolean isAdj = pos.equals("Adjective");
Boolean regular = entry.regular();
List<Favorite> favorites = Utils.getFavorites(displayCardView.getContext());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,6 +22,8 @@
public class FavoritesCard implements DisplayCardBody {

private View view;
private TextView emptyView;
private LinearListView listView;

private String stem;
private boolean honorific;
Expand All @@ -38,24 +41,29 @@ public FavoritesCard(ArrayList<Map.Entry<String, ConjugationFragment>> 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);
});
Expand Down Expand Up @@ -89,6 +97,17 @@ public String getHeading() {
public void addConjugation(Map.Entry<String, ConjugationFragment> 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);
}
}

}
7 changes: 7 additions & 0 deletions app/src/main/res/layout/dcard_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />

<TextView
android:id="@+id/listCard_empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="22sp"
android:visibility="gone"/>
</RelativeLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<string name="regular_forms">Regular Forms</string>
<string name="menu_ad_free">Remove Ads</string>
<string name="conj_seperator">:</string>
<string name="empty_favorites">You don\'t have any favorites. Click on favorites in settings to make some.</string>
<!-- Suggestions -->
<string name="suggestion_submit">Submit</string>
<string name="menu_add">Add suggestion</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -111,6 +113,16 @@ public void test_addConjugation() {

Map.Entry<String, ConjugationFragment> 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));
}
}

0 comments on commit 3e0c190

Please sign in to comment.