Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] show tags in list item view #594

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
35 changes: 35 additions & 0 deletions app/src/main/java/fr/gaulupeau/apps/Poche/data/ListAdapter.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
package fr.gaulupeau.apps.Poche.data;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

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

import fr.gaulupeau.apps.InThePoche.R;
import fr.gaulupeau.apps.Poche.data.dao.entities.Article;
import fr.gaulupeau.apps.Poche.data.dao.entities.Tag;

import static fr.gaulupeau.apps.Poche.data.ListTypes.*;

Expand Down Expand Up @@ -53,15 +61,19 @@ public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickL
OnItemClickListener listener;
TextView title;
TextView url;
LinearLayout tagContainer;
ImageView favourite;
ImageView read;
TextView readingTime;
boolean areTagsAdded;

public ViewHolder(View itemView, OnItemClickListener listener) {
super(itemView);
this.listener = listener;
title = (TextView) itemView.findViewById(R.id.title);
url = (TextView) itemView.findViewById(R.id.url);
tagContainer = (LinearLayout) itemView.findViewById(R.id.tagContainer);
areTagsAdded = false;
favourite = (ImageView) itemView.findViewById(R.id.favourite);
read = (ImageView) itemView.findViewById(R.id.read);
readingTime = (TextView) itemView.findViewById(R.id.estimatedReadingTime);
Expand All @@ -71,6 +83,29 @@ public ViewHolder(View itemView, OnItemClickListener listener) {
public void bind(Article article) {
title.setText(article.getTitle());
url.setText(article.getDomain());
if (areTagsAdded){
tagContainer.removeAllViews();
areTagsAdded = false;
}
List<String> tagsAdded = new ArrayList<>(); // do not add duplicate labels
for (Iterator<Tag> tags = article.getTags().iterator(); tags.hasNext();) {
Tag t = tags.next();
if(!areTagsAdded && !tagsAdded.contains(t.getLabel())) {
// TODO apply current theme
TextView tagText = new TextView(context);
tagText.setText(t.getLabel());
tagText.setBackground(context.getResources().getDrawable(R.drawable.tag_shape));
tagText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
tagText.setTextColor(Color.WHITE);
tagText.setPadding(5, 2, 5, 2); // (left, top, right, bottom);
LinearLayout.LayoutParams lllp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lllp.setMargins(0, 0, 5, 0);
tagText.setLayoutParams(lllp);
tagContainer.addView(tagText);
tagsAdded.add(t.getLabel());
}
}
areTagsAdded = true;

boolean showFavourite = false;
boolean showRead = false;
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/tag_shape.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1px"
android:color="#ffffff" />
<corners android:radius="10px"/>
</shape>
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/tag_shape_dark.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1px"
android:color="#000000" />
<corners android:radius="10px"/>
<padding android:left="2dp" android:top="2dp" android:right="2dp" android:bottom="2dp" />
</shape>
7 changes: 7 additions & 0 deletions app/src/main/res/layout/list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
android:src="?attr/listItem_icon_read"/>
</LinearLayout>

<LinearLayout
android:id="@+id/tagContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down