Android: Display tags, language and shared status on document

This commit is contained in:
jendib 2014-11-22 14:06:08 +01:00
parent 8c5c54125f
commit 92b2219bed
13 changed files with 83 additions and 36 deletions

View File

@ -23,8 +23,6 @@ public class MainApplication extends Application {
// TODO Fullscreen preview
// TODO Downloading
// TODO Sharing
// TODO Shared status
// TODO Tags on document
// TODO Error feedback
// TODO Infinite scrolling on documents
// TODO Searching

View File

@ -7,6 +7,7 @@ import android.support.v7.app.ActionBarActivity;
import android.text.format.DateFormat;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.loopj.android.http.JsonHttpResponseHandler;
@ -14,8 +15,10 @@ import com.sismics.docs.R;
import com.sismics.docs.adapter.FilePagerAdapter;
import com.sismics.docs.model.application.ApplicationContext;
import com.sismics.docs.resource.FileResource;
import com.sismics.docs.util.TagUtil;
import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@ -81,13 +84,15 @@ public class DocumentActivity extends ActionBarActivity {
String title = document.optString("title");
String date = DateFormat.getDateFormat(this).format(new Date(document.optLong("create_date")));
String description = document.optString("description");
boolean shared = document.optBoolean("shared");
String language = document.optString("language");
JSONArray tags = document.optJSONArray("tags");
// Fill the layout
setTitle(title);
TextView createdDateTextView = (TextView) findViewById(R.id.createdDateTextView);
createdDateTextView.setText(date);
TextView languageTextView = (TextView) findViewById(R.id.languageTextView);
languageTextView.setText(document.optString("language"));
TextView descriptionTextView = (TextView) findViewById(R.id.descriptionTextView);
if (description == null || description.isEmpty()) {
descriptionTextView.setVisibility(View.GONE);
@ -95,6 +100,19 @@ public class DocumentActivity extends ActionBarActivity {
descriptionTextView.setText(description);
}
TextView tagTextView = (TextView) findViewById(R.id.tagTextView);
if (tags.length() == 0) {
tagTextView.setVisibility(View.GONE);
} else {
tagTextView.setText(TagUtil.buildSpannable(tags));
}
ImageView languageImageView = (ImageView) findViewById(R.id.languageImageView);
languageImageView.setImageResource(getResources().getIdentifier(language, "drawable", getPackageName()));
ImageView sharedImageView = (ImageView) findViewById(R.id.sharedImageView);
sharedImageView.setVisibility(shared ? View.VISIBLE : View.GONE);
// Grab the attached files
FileResource.list(this, id, new JsonHttpResponseHandler() {
@Override

View File

@ -1,18 +1,14 @@
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;
import android.widget.TextView;
import com.sismics.docs.R;
import com.sismics.docs.util.TagUtil;
import org.json.JSONArray;
import org.json.JSONObject;
@ -64,16 +60,7 @@ public class DocListAdapter extends RecyclerView.Adapter<DocListAdapter.ViewHold
holder.titleTextView.setText(document.optString("title"));
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);
holder.subtitleTextView.setText(TagUtil.buildSpannable(tags));
String date = DateFormat.getDateFormat(holder.dateTextView.getContext()).format(new Date(document.optLong("create_date")));
holder.dateTextView.setText(date);

View File

@ -0,0 +1,39 @@
package com.sismics.docs.util;
import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.BackgroundColorSpan;
import android.text.style.ForegroundColorSpan;
import org.json.JSONArray;
import org.json.JSONObject;
/**
* Utility class for tags.
*
* @author bgamard.
*/
public class TagUtil {
/**
* Create a colored spannable from tags.
*
* @param tags Tags
* @return Colored spannable
*/
public static Spannable buildSpannable(JSONArray 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(" ");
}
return builder;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 442 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 599 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 545 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 410 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 542 B

View File

@ -33,36 +33,42 @@
android:text="01/12/2014"/>
<TextView
android:id="@+id/languageLabel"
android:id="@+id/tagTextView"
android:layout_marginTop="8dp"
android:layout_width="100dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/createdDateLabel"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp"
android:fontFamily="sans-serif"
android:text="@string/language"/>
<TextView
android:id="@+id/languageTextView"
android:layout_marginTop="8dp"
android:layout_toRightOf="@id/languageLabel"
android:layout_toEndOf="@id/languageLabel"
android:layout_below="@id/createdDateTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="fr"/>
android:maxLines="1"
android:fontFamily="sans-serif-light"/>
<TextView
android:id="@+id/descriptionTextView"
android:layout_marginTop="12dp"
android:layout_below="@id/languageLabel"
android:layout_below="@id/tagTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="Lorem ipsum dolor sit amen lorem ipsum dolor sit amen lorem ipsum dolor sit amen lorem ipsum dolor sit amen lorem ipsum dolor sit amen."/>
<ImageView
android:id="@+id/sharedImageView"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_folder_shared_grey600_24dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/languageImageView"
android:layout_toStartOf="@+id/languageImageView"/>
<ImageView
android:id="@+id/languageImageView"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"/>
</RelativeLayout>
<RelativeLayout

View File

@ -19,7 +19,6 @@
<string name="invalid_url">Please check the server URL and try again</string>
<string name="crash_toast_text">A crash occurred, a report has been sent to resolve this problem</string>
<string name="created_date">Created date</string>
<string name="language">Language</string>
<!-- Validation -->
<string name="validate_error_email">Invalid email</string>