mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 05:57:57 +01:00
Android: tags in drawer
This commit is contained in:
parent
1773998ca0
commit
6a9a166670
@ -16,14 +16,16 @@ import org.json.JSONObject;
|
||||
public class MainApplication extends Application {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
// Fetching /user/info from cache
|
||||
// Fetching GET /user from cache
|
||||
JSONObject json = PreferenceUtil.getCachedJson(getApplicationContext(), PreferenceUtil.PREF_CACHED_USER_INFO_JSON);
|
||||
ApplicationContext.getInstance().setUserInfo(getApplicationContext(), json);
|
||||
|
||||
// TODO Fullscreen preview
|
||||
// TODO Tags in drawer & search on select
|
||||
// TODO Sharing
|
||||
// TODO Error feedback
|
||||
// TODO Printing
|
||||
// TODO Fullscreen preview
|
||||
// TODO Caching preferences
|
||||
|
||||
super.onCreate();
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import android.widget.TextView;
|
||||
import com.loopj.android.http.JsonHttpResponseHandler;
|
||||
import com.sismics.docs.R;
|
||||
import com.sismics.docs.adapter.FilePagerAdapter;
|
||||
import com.sismics.docs.event.DocumentFullscreenEvent;
|
||||
import com.sismics.docs.model.application.ApplicationContext;
|
||||
import com.sismics.docs.resource.FileResource;
|
||||
import com.sismics.docs.util.PreferenceUtil;
|
||||
@ -31,6 +32,8 @@ import org.json.JSONObject;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Document activity.
|
||||
*
|
||||
@ -92,6 +95,8 @@ public class DocumentActivity extends ActionBarActivity {
|
||||
|
||||
// Grab the document
|
||||
refreshDocument(document);
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -223,4 +228,14 @@ public class DocumentActivity extends ActionBarActivity {
|
||||
request.setDescription(description);
|
||||
downloadManager.enqueue(request);
|
||||
}
|
||||
|
||||
public void onEvent(DocumentFullscreenEvent event) {
|
||||
findViewById(R.id.detailLayout).setVisibility(event.isFullscreen() ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
EventBus.getDefault().unregister(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
@ -13,13 +13,20 @@ import android.support.v7.widget.SearchView;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.loopj.android.http.JsonHttpResponseHandler;
|
||||
import com.sismics.docs.R;
|
||||
import com.sismics.docs.adapter.TagListAdapter;
|
||||
import com.sismics.docs.event.SearchEvent;
|
||||
import com.sismics.docs.model.application.ApplicationContext;
|
||||
import com.sismics.docs.provider.RecentSuggestionsProvider;
|
||||
import com.sismics.docs.resource.TagResource;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
@ -49,7 +56,7 @@ public class MainActivity extends ActionBarActivity {
|
||||
setContentView(R.layout.main_activity);
|
||||
|
||||
// Enable ActionBar app icon to behave as action to toggle nav drawer
|
||||
DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
final DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
if (getSupportActionBar() != null) {
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setHomeButtonEnabled(true);
|
||||
@ -68,6 +75,31 @@ public class MainActivity extends ActionBarActivity {
|
||||
TextView emailTextView = (TextView) findViewById(R.id.emailTextView);
|
||||
emailTextView.setText(userInfo.optString("email"));
|
||||
|
||||
// Get tag list to fill the drawer
|
||||
final ListView tagListView = (ListView) findViewById(R.id.tagListView);
|
||||
TagResource.stats(this, new JsonHttpResponseHandler() {
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
|
||||
tagListView.setAdapter(new TagListAdapter(response.optJSONArray("stats")));
|
||||
}
|
||||
});
|
||||
|
||||
// Click on a tag
|
||||
tagListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
TagListAdapter adapter = (TagListAdapter) tagListView.getAdapter();
|
||||
if (adapter == null) return;
|
||||
JSONObject tag = adapter.getItem(position);
|
||||
if (tag == null) return;
|
||||
SearchView searchView = (SearchView) searchItem.getActionView();
|
||||
searchView.setQuery("tag:" + tag.optString("name"), true);
|
||||
searchView.setIconified(false);
|
||||
searchView.clearFocus();
|
||||
drawerLayout.closeDrawers();
|
||||
}
|
||||
});
|
||||
|
||||
handleIntent(getIntent());
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,77 @@
|
||||
package com.sismics.docs.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.sismics.docs.R;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Tag list adapter.
|
||||
*
|
||||
* @author bgamard.
|
||||
*/
|
||||
public class TagListAdapter extends BaseAdapter {
|
||||
/**
|
||||
* Tags.
|
||||
*/
|
||||
private JSONArray tags;
|
||||
|
||||
/**
|
||||
* Tag list adapter.
|
||||
*
|
||||
* @param tags Tags
|
||||
*/
|
||||
public TagListAdapter(JSONArray tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return tags.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getItem(int position) {
|
||||
return tags.optJSONObject(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return getItem(position).optString("id").hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View view, ViewGroup parent) {
|
||||
if (view == null) {
|
||||
LayoutInflater vi = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
view = vi.inflate(R.layout.tag_list_item, parent, false);
|
||||
}
|
||||
|
||||
// Fill the view
|
||||
JSONObject tag = getItem(position);
|
||||
TextView tagTextView = (TextView) view.findViewById(R.id.tagTextView);
|
||||
tagTextView.setText(tag.optString("name"));
|
||||
TextView tagCountTextView = (TextView) view.findViewById(R.id.tagCountTextView);
|
||||
tagCountTextView.setText(tag.optString("count"));
|
||||
|
||||
// Label color filtering
|
||||
ImageView labelImageView = (ImageView) view.findViewById(R.id.labelImageView);
|
||||
Drawable labelDrawable = labelImageView.getDrawable().mutate();
|
||||
labelDrawable.setColorFilter(Color.parseColor(tag.optString("color")), PorterDuff.Mode.MULTIPLY);
|
||||
labelImageView.setImageDrawable(labelDrawable);
|
||||
labelImageView.invalidate();
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.sismics.docs.event;
|
||||
|
||||
/**
|
||||
* @author bgamard.
|
||||
*/
|
||||
public class DocumentFullscreenEvent {
|
||||
|
||||
private boolean fullscreen;
|
||||
|
||||
public DocumentFullscreenEvent(boolean fullscreen) {
|
||||
this.fullscreen = fullscreen;
|
||||
}
|
||||
|
||||
public boolean isFullscreen() {
|
||||
return fullscreen;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.sismics.docs.resource;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.loopj.android.http.JsonHttpResponseHandler;
|
||||
|
||||
/**
|
||||
* Access to /tag API.
|
||||
*
|
||||
* @author bgamard
|
||||
*/
|
||||
public class TagResource extends BaseResource {
|
||||
/**
|
||||
* GET /tag/stats.
|
||||
*
|
||||
* @param context Context
|
||||
* @param responseHandler Callback
|
||||
*/
|
||||
public static void stats(Context context, JsonHttpResponseHandler responseHandler) {
|
||||
init(context);
|
||||
|
||||
client.get(getApiUrl(context) + "/tag/stats", responseHandler);
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 374 B |
Binary file not shown.
After Width: | Height: | Size: 479 B |
@ -3,7 +3,6 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="12dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
|
@ -6,6 +6,7 @@
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/detailLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="12dp"
|
||||
@ -81,7 +82,7 @@
|
||||
<com.sismics.docs.ui.view.FileViewPager
|
||||
android:id="@+id/fileViewPager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
@ -89,7 +90,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:indeterminate="true" />
|
||||
android:indeterminate="true"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
@ -10,13 +10,13 @@
|
||||
android:layout_height="15dip"
|
||||
android:id="@+id/fileProgressBar"
|
||||
android:indeterminate="false"
|
||||
android:layout_centerInParent="true" />
|
||||
android:layout_centerInParent="true"/>
|
||||
|
||||
<it.sephiroth.android.library.imagezoom.ImageViewTouch
|
||||
android:id="@+id/fileImageView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="matrix"
|
||||
android:src="@drawable/ic_launcher" />
|
||||
android:src="@drawable/ic_launcher"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
44
docs-android/app/src/main/res/layout/tag_list_item.xml
Normal file
44
docs-android/app/src/main/res/layout/tag_list_item.xml
Normal file
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="12dp"
|
||||
android:background="?android:attr/selectableItemBackground">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/labelImageView"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_marginRight="12dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_label_white_24dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tagTextView"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toRightOf="@+id/labelImageView"
|
||||
android:layout_toEndOf="@+id/labelImageView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="sans-serif"
|
||||
android:textColor="#212121"
|
||||
android:text="Appartement"
|
||||
android:textSize="14sp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tagCountTextView"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="sans-serif"
|
||||
android:textColor="#888"
|
||||
android:text="5"
|
||||
android:textSize="14sp"/>
|
||||
|
||||
</RelativeLayout>
|
Loading…
Reference in New Issue
Block a user