From 2ce574922696938b1b5569615ccfbaafda12ed47 Mon Sep 17 00:00:00 2001 From: jendib Date: Fri, 21 Nov 2014 03:18:20 +0100 Subject: [PATCH] Android: documents listing: tags and date --- .../sismics/docs/adapter/DocListAdapter.java | 60 ++++++++++++------ .../docs/resource/DocumentResource.java | 3 + .../ic_folder_open_grey600_48dp.png | Bin 0 -> 442 bytes .../drawable-hdpi/list_background_holo.9.png | Bin 970 -> 0 bytes .../ic_folder_open_grey600_48dp.png | Bin 0 -> 543 bytes .../drawable-xhdpi/list_background_holo.9.png | Bin 969 -> 0 bytes .../ic_folder_open_grey600_48dp.png | Bin 0 -> 751 bytes .../app/src/main/res/layout/doc_list_item.xml | 45 +++++++++++-- .../app/src/main/res/layout/main_activity.xml | 1 - 9 files changed, 85 insertions(+), 24 deletions(-) create mode 100644 docs-android/app/src/main/res/drawable-hdpi/ic_folder_open_grey600_48dp.png delete mode 100644 docs-android/app/src/main/res/drawable-hdpi/list_background_holo.9.png create mode 100644 docs-android/app/src/main/res/drawable-xhdpi/ic_folder_open_grey600_48dp.png delete mode 100644 docs-android/app/src/main/res/drawable-xhdpi/list_background_holo.9.png create mode 100644 docs-android/app/src/main/res/drawable-xxhdpi/ic_folder_open_grey600_48dp.png diff --git a/docs-android/app/src/main/java/com/sismics/docs/adapter/DocListAdapter.java b/docs-android/app/src/main/java/com/sismics/docs/adapter/DocListAdapter.java index 83ed1bf7..3f2101ae 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/adapter/DocListAdapter.java +++ b/docs-android/app/src/main/java/com/sismics/docs/adapter/DocListAdapter.java @@ -1,6 +1,12 @@ package com.sismics.docs.adapter; +import android.graphics.Color; 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.View; import android.view.ViewGroup; @@ -11,59 +17,68 @@ import com.sismics.docs.R; import org.json.JSONArray; import org.json.JSONObject; +import java.util.Date; + /** * Adapter of documents. * * @author bgamard */ public class DocListAdapter extends RecyclerView.Adapter { + /** + * Displayed 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 - // you provide access to all the views for a data item in a view holder + /** + * ViewHolder. + */ public static class ViewHolder extends RecyclerView.ViewHolder { - // each data item is just a string in this case public TextView titleTextView; public TextView subtitleTextView; + public TextView dateTextView; + public ViewHolder(View v) { super(v); titleTextView = (TextView) v.findViewById(R.id.titleTextView); 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 void setDocuments(JSONArray documents) { - this.documents = documents; - notifyDataSetChanged(); - } - - // Create new views (invoked by the layout manager) @Override public DocListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - // create a new view View v = LayoutInflater.from(parent.getContext()). inflate(R.layout.doc_list_item, parent, false); - // set the view's size, margins, paddings and layout parameters return new ViewHolder(v); } - // Replace the contents of a view (invoked by the layout manager) @Override 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); + 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 public int getItemCount() { if (documents == null) { @@ -71,4 +86,13 @@ public class DocListAdapter extends RecyclerView.AdapterI(3)EF2VS{N990fib~ zFff!FFfhDIU|_JC!N4G1FlSew4N!t9$=lt9;eUJonf*W>XMsm#F#`j)FbFd;%$g&? zz`$ta>EalYaqsOddoN~3k>elVyLfU`FsX`nxQIA*n`}F%ePd~7>!f2 zCwOD)I*fa&zc0AE^m%QZnh_cYqBuI%5zm-~7L z7jMaoZKXf7KUCC(UweMso=GwlWVw(>Zy=Zg5gHp#+x?xPH|OWkdpwVy@bH>Xnv!Vr zB2{_8^OOt9@%Jp}+o(1#Gm)rx7GvZcovM5;zopr0QZKgkpKVy literal 0 HcmV?d00001 diff --git a/docs-android/app/src/main/res/drawable-hdpi/list_background_holo.9.png b/docs-android/app/src/main/res/drawable-hdpi/list_background_holo.9.png deleted file mode 100644 index 694d6a4d002c1460e056c37bcca3f32505b775d4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 970 zcmaJ=J8aWH7A~j?ExHML4pRq642@@b8 zAu%u_20&~`6$6Y2fmjd&6ANPLfS4I!VBnl4X$OL(^Zj@FzVCnD{pQwsZsF1bMNv6@ zLu--!T)MJn$^XScyh65%xZcHW)WfkELaOQ@3j*CUcVP>f&hW-3Sf;2`!0mK#*Vt5S zFyZlEAe0AO;rPb$ylo`Q{xBTt}t1iw0)|HQ0AIMj>pEwmSA`&z2p! zat)Ldg$Q^Mn;`M_{YXhvdaSDuJH2LUFoxhgl|BlpYcxR(g%A`OE^l)s4wQI?7YmXk zT>%2eb1WyYypZQ5MHCc{1Cx&?-a@CRw6w;=7dfePALBq_**K1wSY%MR%kr`;ry7Eg zCy0DB^s$-b{b+frpuxxv-2l7D2dScIp#fHD66sM2UNDpOqe+=a!PvwMSf1h1l%_z# z_&?P1X6OjF;BmbF6plK>0J1F@p+RVq#`Ts{SAkLsp@~u0L1=$k#bzI26!lR6YV9J} zc6|rM(HLzQitb0)^lhkXDoyx|>pDtZtP2HREJ=dc;Q6{(ElF~f*m6}CRtu|ZQ?7>W zfd_p&I(3)EF2VS{N990fib~ zFff!FFfhDIU|_JC!N4G1FlSew4N!t9$=lt9;eUJonf*W>XMsm#F#`j)FbFd;%$g&? zz`!`&)5S5Q;?~>SySpZ_?SEMW&8%alwSV z*>Kj@c9mkjDi5#TWe&x+tztL1YmKjOxb76e;B5Ql?H8|#SPjc%pL3VjG9BF?zqG_# zvwlPg{Q>SYnIgJe5p@@g%v2&er#{hf4?j5{Q7A!mcV#p@O1TaS?83{ F1OR4>*S-J% literal 0 HcmV?d00001 diff --git a/docs-android/app/src/main/res/drawable-xhdpi/list_background_holo.9.png b/docs-android/app/src/main/res/drawable-xhdpi/list_background_holo.9.png deleted file mode 100644 index 9d4d5829da3c2475ff1679fd0bd797e10c0c126a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 969 zcmaJ=O^?z*814qM(KV|^FS?hVlo&74Pd@B~N`QipSb{*ZBzvK>12k+qwH=niCTcuv z^yGTe_#gZO9z1*Wx``+6dNONbqE1<0_aHWz&PSf-d7t;4cV5mWpHW-H4tX8xJ zov%dW;yV3rR}!D;bc>YQq=|cEZ1{-DTeyor)iL_0fedT%_!G)9ObpnqHfie*p@|*N zh%j8}c$CdB*<9!u<`5CkMSa^<+3z1dvcR@fb|<9^x>rO4yE64rb6RVe)1j$YZ0nEVjqDNCnQWEEr7JhiE=WN$=n5! zAPT%7@uHLvGfHI=1&&bBS6r6oBjD^f-l6;Uk7iY(tNX9{_-SW1`VWOBjPusL#& zOBP(~j4Q9?MvdTjG_r<#dmmY4A3I={Ftk^D5mxHWxz=hg;z}-0&G6B+p1bD75$&C5 zxoldxS++fLX|MaVsS8}~7kv=9s+Mns$KB4G$>G}NpRW!dt<|r_UpzVa_T}mN^=C&% z*J3wfZ#$jj?`>GSy&L~3oWx_v*MII@iv3_N+++?8w%#4@o4e8Ds+MZn`$FgWUsJLv AfdBvi diff --git a/docs-android/app/src/main/res/drawable-xxhdpi/ic_folder_open_grey600_48dp.png b/docs-android/app/src/main/res/drawable-xxhdpi/ic_folder_open_grey600_48dp.png new file mode 100644 index 0000000000000000000000000000000000000000..c9a13a9c3c507401b08111d6af7f5c84f0fb9c64 GIT binary patch literal 751 zcmeAS@N?(olHy`uVBq!ia0vp^6F``Q1xWh(YZ(J6g=CK)Uj~LMH3o);76yi2K%s^g z3=E|P3=FRl7#OT(FffQ0%-I!a1C(G&@^*J&_}|`tWO>_%)r1c48n{Iv*t(u zRit~mIEGZ*dVAN_UnEeX?P2wiewQfcB%PLPxoox{n-YG2skv{`x zMC_O(5iQJn|EAY4JL(; zci4*kI8?fcsjqf&&-+sLs$<#b#LK=&2^?*F_i@{VTPp zGkJwcpu`KK_g=GALuY9C7}PJ)Jn&=IzpT3rc~fmBbqTdLMlJ1MI>{w*f%kHQSzJP? z2mfo7&CGf7>a)J=w;RjO_FrtMiplw6wD)}av>z|u_I=Rbf10nKwJUYfcN=kyd8Trl zBImW2v3AYR$Ue-F$|-o(IGOdRzR7piu5`Zz6;Vt_jYV%w_&?A8uKvB|8on~a=~7@1 z`?756j&uYw%M7)Fq0!^Obo1yMNH8ReZ*Bqy(VHYDNpN88o*@bfD#^w-Nny|+gJ^?? zq{+0F`F9IX>{Q+_Z*u9OK|O2fB&{iabqn?`X(;>5oU6{dWvcuNUwg@UcC&vre)~Cv z=Yrbr!&`o;R(XCXsWiM}^FrKzGDFp&_aBb^s5UKoQMmh|P4^zjRJFYaneMX9kKw;5 zQM&SDqnNz(jf=mwWL~t(+x|iLs*Dz - + android:padding="12dp" + android:clickable="true" + android:focusable="true" + android:background="?android:attr/selectableItemBackground"> + + + android:text="Test" + android:textSize="16sp" + android:ellipsize="end" + android:maxLines="1"/> + android:text="test2" + android:textSize="16sp" + android:maxLines="1" + android:ellipsize="end"/> + + - \ No newline at end of file + \ No newline at end of file diff --git a/docs-android/app/src/main/res/layout/main_activity.xml b/docs-android/app/src/main/res/layout/main_activity.xml index 2600e19a..c38cd8af 100644 --- a/docs-android/app/src/main/res/layout/main_activity.xml +++ b/docs-android/app/src/main/res/layout/main_activity.xml @@ -17,7 +17,6 @@ android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" - android:background="@drawable/list_background_holo" android:gravity="center" android:orientation="vertical">