diff --git a/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java b/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java index 82c17698..5ecc3dee 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java +++ b/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java @@ -23,11 +23,14 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import android.widget.Button; import android.widget.ImageView; +import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import com.sismics.docs.R; +import com.sismics.docs.adapter.AclListAdapter; import com.sismics.docs.adapter.FilePagerAdapter; import com.sismics.docs.event.DocumentDeleteEvent; import com.sismics.docs.event.DocumentEditEvent; @@ -186,6 +189,58 @@ public class DocumentViewActivity extends AppCompatActivity { ImageView sharedImageView = (ImageView) findViewById(R.id.sharedImageView); sharedImageView.setVisibility(shared ? View.VISIBLE : View.GONE); + // Action edit document + Button button = (Button) findViewById(R.id.actionEditDocument); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(DocumentViewActivity.this, DocumentEditActivity.class); + intent.putExtra("document", DocumentViewActivity.this.document.toString()); + startActivityForResult(intent, REQUEST_CODE_EDIT_DOCUMENT); + } + }); + + // Action upload file + button = (Button) findViewById(R.id.actionUploadFile); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(Intent.ACTION_GET_CONTENT) + .setType("*/*") + .putExtra("android.intent.extra.ALLOW_MULTIPLE", true) + .addCategory(Intent.CATEGORY_OPENABLE); + startActivityForResult(Intent.createChooser(intent, getText(R.string.upload_from)), REQUEST_CODE_ADD_FILE); + } + }); + + // Action download document + button = (Button) findViewById(R.id.actionDownload); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + downloadZip(); + } + }); + + // Action delete document + button = (Button) findViewById(R.id.actionDelete); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + deleteDocument(); + } + }); + + // Action share + button = (Button) findViewById(R.id.actionSharing); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + DialogFragment dialog = DocShareFragment.newInstance(DocumentViewActivity.this.document.optString("id")); + dialog.show(getSupportFragmentManager(), "DocShareFragment"); + } + }); + // Grab the attached files updateFiles(); @@ -217,37 +272,10 @@ public class DocumentViewActivity extends AppCompatActivity { downloadCurrentFile(); return true; - case R.id.download_document: - downloadZip(); - return true; - - case R.id.share: - DialogFragment dialog = DocShareFragment.newInstance(document.optString("id")); - dialog.show(getSupportFragmentManager(), "DocShareFragment"); - return true; - - case R.id.upload_file: - Intent intent = new Intent(Intent.ACTION_GET_CONTENT) - .setType("*/*") - .putExtra("android.intent.extra.ALLOW_MULTIPLE", true) - .addCategory(Intent.CATEGORY_OPENABLE); - startActivityForResult(Intent.createChooser(intent, getText(R.string.upload_from)), REQUEST_CODE_ADD_FILE); - return true; - - case R.id.edit: - intent = new Intent(this, DocumentEditActivity.class); - intent.putExtra("document", document.toString()); - startActivityForResult(intent, REQUEST_CODE_EDIT_DOCUMENT); - return true; - case R.id.delete_file: deleteCurrentFile(); return true; - case R.id.delete_document: - deleteDocument(); - return true; - case android.R.id.home: finish(); return true; @@ -525,17 +553,21 @@ public class DocumentViewActivity extends AppCompatActivity { DocumentResource.get(this, document.optString("id"), new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { - boolean writable = response.optBoolean("writable"); + document = response; + boolean writable = document.optBoolean("writable"); if (menu != null) { - menu.findItem(R.id.share).setVisible(writable); - menu.findItem(R.id.upload_file).setVisible(writable); - menu.findItem(R.id.edit).setVisible(writable); menu.findItem(R.id.delete_file).setVisible(writable); - menu.findItem(R.id.delete_document).setVisible(writable); } - // TODO Show the ACLs in a sliding panel from the right + findViewById(R.id.actionEditDocument).setVisibility(writable ? View.VISIBLE : View.INVISIBLE); + findViewById(R.id.actionUploadFile).setVisibility(writable ? View.VISIBLE : View.INVISIBLE); + findViewById(R.id.actionSharing).setVisibility(writable ? View.VISIBLE : View.INVISIBLE); + findViewById(R.id.actionDelete).setVisibility(writable ? View.VISIBLE : View.INVISIBLE); + + // ACLs + ListView aclListView = (ListView) findViewById(R.id.aclListView); + aclListView.setAdapter(new AclListAdapter(document.optJSONArray("acls"))); } }); } diff --git a/docs-android/app/src/main/java/com/sismics/docs/adapter/AclListAdapter.java b/docs-android/app/src/main/java/com/sismics/docs/adapter/AclListAdapter.java new file mode 100644 index 00000000..f7aabce7 --- /dev/null +++ b/docs-android/app/src/main/java/com/sismics/docs/adapter/AclListAdapter.java @@ -0,0 +1,77 @@ +package com.sismics.docs.adapter; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.TextView; + +import com.sismics.docs.R; + +import org.json.JSONArray; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +/** + * ACL list adapter. + * + * @author bgamard. + */ +public class AclListAdapter extends BaseAdapter { + /** + * Shares. + */ + private List acls; + + /** + * ACL list adapter. + * + * @param acls ACLs + */ + public AclListAdapter(JSONArray acls) { + this.acls = new ArrayList<>(); + + // Extract only share ACLs + for (int i = 0; i < acls.length(); i++) { + JSONObject acl = acls.optJSONObject(i); + this.acls.add(acl); + } + } + + @Override + public int getCount() { + return acls.size(); + } + + @Override + public JSONObject getItem(int position) { + return acls.get(position); + } + + @Override + public long getItemId(int position) { + return getItem(position).optString("id").hashCode(); + } + + @Override + public View getView(int position, View view, final ViewGroup parent) { + if (view == null) { + LayoutInflater vi = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); + view = vi.inflate(R.layout.acl_list_item, parent, false); + } + + // Fill the view + final JSONObject acl = getItem(position); + TextView typeTextView = (TextView) view.findViewById(R.id.typeTextView); + typeTextView.setText(acl.optString("type")); + TextView nameTextView = (TextView) view.findViewById(R.id.nameTextView); + nameTextView.setText(acl.optString("name")); + TextView permTextView = (TextView) view.findViewById(R.id.permTextView); + permTextView.setText(acl.optString("perm")); + + return view; + } +} diff --git a/docs-android/app/src/main/res/drawable-xhdpi/ic_create_grey600_24dp.png b/docs-android/app/src/main/res/drawable-xhdpi/ic_create_grey600_24dp.png new file mode 100644 index 00000000..4c95bd57 Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xhdpi/ic_create_grey600_24dp.png differ diff --git a/docs-android/app/src/main/res/drawable-xhdpi/ic_create_white_24dp.png b/docs-android/app/src/main/res/drawable-xhdpi/ic_create_white_24dp.png deleted file mode 100644 index 7f0ea51b..00000000 Binary files a/docs-android/app/src/main/res/drawable-xhdpi/ic_create_white_24dp.png and /dev/null differ diff --git a/docs-android/app/src/main/res/drawable-xhdpi/ic_file_download_grey600_24dp.png b/docs-android/app/src/main/res/drawable-xhdpi/ic_file_download_grey600_24dp.png new file mode 100644 index 00000000..aa89d497 Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xhdpi/ic_file_download_grey600_24dp.png differ diff --git a/docs-android/app/src/main/res/drawable-xhdpi/ic_file_upload_grey600_24dp.png b/docs-android/app/src/main/res/drawable-xhdpi/ic_file_upload_grey600_24dp.png new file mode 100644 index 00000000..908b1567 Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xhdpi/ic_file_upload_grey600_24dp.png differ diff --git a/docs-android/app/src/main/res/drawable-xhdpi/ic_people_grey600_24dp.png b/docs-android/app/src/main/res/drawable-xhdpi/ic_people_grey600_24dp.png new file mode 100644 index 00000000..8fabd783 Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xhdpi/ic_people_grey600_24dp.png differ diff --git a/docs-android/app/src/main/res/drawable-xxhdpi/ic_create_grey600_24dp.png b/docs-android/app/src/main/res/drawable-xxhdpi/ic_create_grey600_24dp.png new file mode 100644 index 00000000..6ed4351c Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xxhdpi/ic_create_grey600_24dp.png differ diff --git a/docs-android/app/src/main/res/drawable-xxhdpi/ic_create_white_24dp.png b/docs-android/app/src/main/res/drawable-xxhdpi/ic_create_white_24dp.png deleted file mode 100644 index 34ec7092..00000000 Binary files a/docs-android/app/src/main/res/drawable-xxhdpi/ic_create_white_24dp.png and /dev/null differ diff --git a/docs-android/app/src/main/res/drawable-xxhdpi/ic_file_download_grey600_24dp.png b/docs-android/app/src/main/res/drawable-xxhdpi/ic_file_download_grey600_24dp.png new file mode 100644 index 00000000..e61a48a4 Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xxhdpi/ic_file_download_grey600_24dp.png differ diff --git a/docs-android/app/src/main/res/drawable-xxhdpi/ic_file_upload_grey600_24dp.png b/docs-android/app/src/main/res/drawable-xxhdpi/ic_file_upload_grey600_24dp.png new file mode 100644 index 00000000..77d80081 Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xxhdpi/ic_file_upload_grey600_24dp.png differ diff --git a/docs-android/app/src/main/res/drawable-xxhdpi/ic_people_grey600_24dp.png b/docs-android/app/src/main/res/drawable-xxhdpi/ic_people_grey600_24dp.png new file mode 100644 index 00000000..198a5795 Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xxhdpi/ic_people_grey600_24dp.png differ diff --git a/docs-android/app/src/main/res/layout/acl_list_item.xml b/docs-android/app/src/main/res/layout/acl_list_item.xml new file mode 100644 index 00000000..40384f83 --- /dev/null +++ b/docs-android/app/src/main/res/layout/acl_list_item.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/docs-android/app/src/main/res/layout/document_view_activity.xml b/docs-android/app/src/main/res/layout/document_view_activity.xml index b0e67d1d..19744f59 100644 --- a/docs-android/app/src/main/res/layout/document_view_activity.xml +++ b/docs-android/app/src/main/res/layout/document_view_activity.xml @@ -49,6 +49,94 @@ android:background="#fff" android:elevation="5dp"> + + + + + + +