mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 22:07:56 +01:00
Android: documents listing: tags and date
This commit is contained in:
parent
76d195a344
commit
2ce5749226
@ -1,6 +1,12 @@
|
|||||||
package com.sismics.docs.adapter;
|
package com.sismics.docs.adapter;
|
||||||
|
|
||||||
|
import android.graphics.Color;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.text.SpannableStringBuilder;
|
||||||
|
import android.text.Spanned;
|
||||||
|
import android.text.format.DateFormat;
|
||||||
|
import android.text.style.BackgroundColorSpan;
|
||||||
|
import android.text.style.ForegroundColorSpan;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -11,59 +17,68 @@ import com.sismics.docs.R;
|
|||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapter of documents.
|
* Adapter of documents.
|
||||||
*
|
*
|
||||||
* @author bgamard
|
* @author bgamard
|
||||||
*/
|
*/
|
||||||
public class DocListAdapter extends RecyclerView.Adapter<DocListAdapter.ViewHolder> {
|
public class DocListAdapter extends RecyclerView.Adapter<DocListAdapter.ViewHolder> {
|
||||||
|
/**
|
||||||
|
* Displayed documents.
|
||||||
|
*/
|
||||||
private JSONArray documents;
|
private JSONArray documents;
|
||||||
|
|
||||||
// Provide a reference to the views for each data item
|
/**
|
||||||
// Complex data items may need more than one view per item, and
|
* ViewHolder.
|
||||||
// you provide access to all the views for a data item in a view holder
|
*/
|
||||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
// each data item is just a string in this case
|
|
||||||
public TextView titleTextView;
|
public TextView titleTextView;
|
||||||
public TextView subtitleTextView;
|
public TextView subtitleTextView;
|
||||||
|
public TextView dateTextView;
|
||||||
|
|
||||||
public ViewHolder(View v) {
|
public ViewHolder(View v) {
|
||||||
super(v);
|
super(v);
|
||||||
titleTextView = (TextView) v.findViewById(R.id.titleTextView);
|
titleTextView = (TextView) v.findViewById(R.id.titleTextView);
|
||||||
subtitleTextView = (TextView) v.findViewById(R.id.subtitleTextView);
|
subtitleTextView = (TextView) v.findViewById(R.id.subtitleTextView);
|
||||||
|
dateTextView = (TextView) v.findViewById(R.id.dateTextView);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provide a suitable constructor (depends on the kind of dataset)
|
|
||||||
public DocListAdapter() {
|
public DocListAdapter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDocuments(JSONArray documents) {
|
|
||||||
this.documents = documents;
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create new views (invoked by the layout manager)
|
|
||||||
@Override
|
@Override
|
||||||
public DocListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public DocListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
// create a new view
|
|
||||||
View v = LayoutInflater.from(parent.getContext()).
|
View v = LayoutInflater.from(parent.getContext()).
|
||||||
inflate(R.layout.doc_list_item, parent, false);
|
inflate(R.layout.doc_list_item, parent, false);
|
||||||
|
|
||||||
// set the view's size, margins, paddings and layout parameters
|
|
||||||
return new ViewHolder(v);
|
return new ViewHolder(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace the contents of a view (invoked by the layout manager)
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||||
// - get element from your dataset at this position
|
|
||||||
// - replace the contents of the view with that element
|
|
||||||
JSONObject document = documents.optJSONObject(position);
|
JSONObject document = documents.optJSONObject(position);
|
||||||
|
|
||||||
holder.titleTextView.setText(document.optString("title"));
|
holder.titleTextView.setText(document.optString("title"));
|
||||||
holder.subtitleTextView.setText(document.optString("description"));
|
|
||||||
|
JSONArray tags = document.optJSONArray("tags");
|
||||||
|
SpannableStringBuilder builder = new SpannableStringBuilder();
|
||||||
|
for (int i = 0; i < tags.length(); i++) {
|
||||||
|
JSONObject tag = tags.optJSONObject(i);
|
||||||
|
int start = builder.length();
|
||||||
|
builder.append(" ").append(tag.optString("name")).append(" ");
|
||||||
|
builder.setSpan(new ForegroundColorSpan(Color.WHITE), start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
builder.setSpan(new BackgroundColorSpan(Color.parseColor(tag.optString("color"))), start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
builder.append(" ");
|
||||||
|
}
|
||||||
|
holder.subtitleTextView.setText(builder);
|
||||||
|
|
||||||
|
String date = DateFormat.getDateFormat(holder.dateTextView.getContext()).format(new Date(document.optLong("create_date")));
|
||||||
|
holder.dateTextView.setText(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the size of your dataset (invoked by the layout manager)
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
if (documents == null) {
|
if (documents == null) {
|
||||||
@ -71,4 +86,13 @@ public class DocListAdapter extends RecyclerView.Adapter<DocListAdapter.ViewHold
|
|||||||
}
|
}
|
||||||
return documents.length();
|
return documents.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the displayed documents
|
||||||
|
* @param documents Documents
|
||||||
|
*/
|
||||||
|
public void setDocuments(JSONArray documents) {
|
||||||
|
this.documents = documents;
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
}
|
}
|
@ -22,6 +22,9 @@ public class DocumentResource extends BaseResource {
|
|||||||
init(context);
|
init(context);
|
||||||
|
|
||||||
RequestParams params = new RequestParams();
|
RequestParams params = new RequestParams();
|
||||||
|
params.put("limit", 50);
|
||||||
|
params.put("sort_column", 3);
|
||||||
|
params.put("asc", false);
|
||||||
client.get(getApiUrl(context) + "/document/list", params, responseHandler);
|
client.get(getApiUrl(context) + "/document/list", params, responseHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
After Width: | Height: | Size: 442 B |
Binary file not shown.
Before Width: | Height: | Size: 970 B |
Binary file not shown.
After Width: | Height: | Size: 543 B |
Binary file not shown.
Before Width: | Height: | Size: 969 B |
Binary file not shown.
After Width: | Height: | Size: 751 B |
@ -1,26 +1,61 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout
|
<RelativeLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="12dp">
|
android:padding="12dp"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:background="?android:attr/selectableItemBackground">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_marginRight="12dp"
|
||||||
|
android:id="@+id/folderImageView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:src="@drawable/ic_folder_open_grey600_48dp"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/titleTextView"
|
android:id="@+id/titleTextView"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:layout_toRightOf="@+id/folderImageView"
|
||||||
|
android:layout_toLeftOf="@+id/dateTextView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:fontFamily="sans-serif-light"
|
android:fontFamily="sans-serif-light"
|
||||||
android:textColor="#212121"
|
android:textColor="#212121"
|
||||||
android:textSize="16sp"/>
|
android:text="Test"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/subtitleTextView"
|
android:id="@+id/subtitleTextView"
|
||||||
|
android:layout_below="@+id/titleTextView"
|
||||||
|
android:layout_toRightOf="@+id/folderImageView"
|
||||||
android:layout_marginTop="4dp"
|
android:layout_marginTop="4dp"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:fontFamily="sans-serif-light"
|
android:fontFamily="sans-serif-light"
|
||||||
android:textColor="#777777"
|
android:textColor="#777777"
|
||||||
android:textSize="16sp"/>
|
android:text="test2"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:ellipsize="end"/>
|
||||||
|
|
||||||
</LinearLayout>
|
<TextView
|
||||||
|
android:id="@+id/dateTextView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="2014-12-02"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:textColor="#777777"
|
||||||
|
android:fontFamily="sans-serif-light"/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
@ -17,7 +17,6 @@
|
|||||||
android:layout_width="240dp"
|
android:layout_width="240dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="start"
|
android:layout_gravity="start"
|
||||||
android:background="@drawable/list_background_holo"
|
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user