The default item list layout looks a bit better, and gained a date
This commit is contained in:
parent
fb9a1a706c
commit
bff0256243
@ -18,4 +18,10 @@ public final class DateUtils {
|
||||
|
||||
return new LocalDateTime(formatter.parse(value));
|
||||
}
|
||||
|
||||
public static String formatedDateByLocal(LocalDateTime dateTime) {
|
||||
DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault());
|
||||
|
||||
return df.format(dateTime.toDate());
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,10 @@ import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.RequestManager;
|
||||
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
|
||||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.readrops.app.database.entities.Item;
|
||||
|
||||
public class MainItemListAdapter extends ListAdapter<Item, MainItemListAdapter.ViewHolder> {
|
||||
@ -40,7 +42,7 @@ public class MainItemListAdapter extends ListAdapter<Item, MainItemListAdapter.V
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
|
||||
LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
|
||||
View view = inflater.inflate(R.layout.compact_list_element, viewGroup, false);
|
||||
View view = inflater.inflate(R.layout.image_list_item, viewGroup, false);
|
||||
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
@ -50,24 +52,31 @@ public class MainItemListAdapter extends ListAdapter<Item, MainItemListAdapter.V
|
||||
Item item = getItem(i);
|
||||
viewHolder.bind(item);
|
||||
|
||||
// displaying image with some round corners
|
||||
RequestOptions requestOptions = new RequestOptions();
|
||||
requestOptions = requestOptions.transforms(new CenterCrop(), new RoundedCorners(16));
|
||||
|
||||
if (item.getImageLink() != null)
|
||||
manager.load(item.getImageLink()).into(viewHolder.itemImage);
|
||||
manager.load(item.getImageLink()).apply(requestOptions).into(viewHolder.itemImage);
|
||||
}
|
||||
|
||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private TextView itemTitle;
|
||||
private ImageView itemImage;
|
||||
private TextView date;
|
||||
|
||||
ViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
||||
itemTitle = itemView.findViewById(R.id.item_title);
|
||||
itemImage = itemView.findViewById(R.id.item_image);
|
||||
date = itemView.findViewById(R.id.item_date);
|
||||
}
|
||||
|
||||
private void bind(Item item) {
|
||||
itemTitle.setText(item.getTitle());
|
||||
date.setText(DateUtils.formatedDateByLocal(item.getFormatedDate()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="vertical"
|
||||
tools:listitem="@layout/compact_list_element"/>
|
||||
tools:listitem="@layout/image_list_item"/>
|
||||
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
|
||||
|
@ -9,11 +9,11 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="test title for this textview which is 3 maximum lines"
|
||||
android:layout_marginLeft="15dp"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:minLines="1"
|
||||
android:maxLines="3"
|
||||
android:layout_alignParentLeft="true"
|
||||
@ -27,9 +27,9 @@
|
||||
android:id="@+id/item_image"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="70dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginRight="15dp"
|
||||
android:layout_marginEnd="15dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginRight="5dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginBottom="12dp"
|
||||
/>
|
||||
@ -40,12 +40,22 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_toLeftOf="@id/item_image"
|
||||
android:layout_marginTop="62dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_below="@id/item_image"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:layout_marginStart="5dp"
|
||||
android:ellipsize="end"
|
||||
android:text="Numerama"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_date"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="10 janvier 2019"
|
||||
android:layout_below="@id/item_image"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
Loading…
x
Reference in New Issue
Block a user