Android: ACLs in right drawer

This commit is contained in:
jendib 2015-05-10 21:44:39 +02:00
parent 566c563786
commit 060e5e8e24
16 changed files with 319 additions and 70 deletions

View File

@ -23,11 +23,14 @@ import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.sismics.docs.R; import com.sismics.docs.R;
import com.sismics.docs.adapter.AclListAdapter;
import com.sismics.docs.adapter.FilePagerAdapter; import com.sismics.docs.adapter.FilePagerAdapter;
import com.sismics.docs.event.DocumentDeleteEvent; import com.sismics.docs.event.DocumentDeleteEvent;
import com.sismics.docs.event.DocumentEditEvent; import com.sismics.docs.event.DocumentEditEvent;
@ -186,6 +189,58 @@ public class DocumentViewActivity extends AppCompatActivity {
ImageView sharedImageView = (ImageView) findViewById(R.id.sharedImageView); ImageView sharedImageView = (ImageView) findViewById(R.id.sharedImageView);
sharedImageView.setVisibility(shared ? View.VISIBLE : View.GONE); 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 // Grab the attached files
updateFiles(); updateFiles();
@ -217,37 +272,10 @@ public class DocumentViewActivity extends AppCompatActivity {
downloadCurrentFile(); downloadCurrentFile();
return true; 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: case R.id.delete_file:
deleteCurrentFile(); deleteCurrentFile();
return true; return true;
case R.id.delete_document:
deleteDocument();
return true;
case android.R.id.home: case android.R.id.home:
finish(); finish();
return true; return true;
@ -525,17 +553,21 @@ public class DocumentViewActivity extends AppCompatActivity {
DocumentResource.get(this, document.optString("id"), new JsonHttpResponseHandler() { DocumentResource.get(this, document.optString("id"), new JsonHttpResponseHandler() {
@Override @Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) { public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
boolean writable = response.optBoolean("writable"); document = response;
boolean writable = document.optBoolean("writable");
if (menu != null) { 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_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")));
} }
}); });
} }

View File

@ -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<JSONObject> 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;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 379 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 378 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 283 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 275 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 476 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 493 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 490 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 339 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 623 B

View File

@ -0,0 +1,65 @@
<?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="0dp"
android:background="?android:attr/selectableItemBackground">
<ImageView
android:id="@+id/peopleImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginRight="12dp"
android:layout_marginEnd="12dp"
android:layout_marginLeft="18dp"
android:layout_marginStart="18dp"
android:src="@drawable/ic_people_grey600_24dp"/>
<TextView
android:id="@+id/typeTextView"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/peopleImageView"
android:layout_toEndOf="@id/peopleImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:textColor="@color/primary_text_disabled_material_light"
android:text="USER"
android:layout_marginTop="12dp"
android:textSize="16sp"/>
<TextView
android:id="@+id/nameTextView"
android:layout_below="@id/typeTextView"
android:layout_toRightOf="@id/peopleImageView"
android:layout_toEndOf="@id/peopleImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:textColor="@color/primary_text_default_material_light"
android:text="admin"
android:layout_marginBottom="12dp"
android:ellipsize="end"
android:textSize="16sp"/>
<TextView
android:id="@+id/permTextView"
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="@color/primary_text_default_material_light"
android:text="WRITE"
android:layout_marginStart="12dp"
android:layout_marginLeft="12dp"
android:layout_marginEnd="18dp"
android:layout_marginRight="18dp"
android:textSize="16sp"/>
</RelativeLayout>

View File

@ -49,6 +49,94 @@
android:background="#fff" android:background="#fff"
android:elevation="5dp"> android:elevation="5dp">
<!-- Actions -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
style="?android:buttonBarStyle">
<Button
android:id="@+id/actionEditDocument"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/ic_create_grey600_24dp"
style="?android:buttonBarButtonStyle"
android:text="@string/edit_document"
android:textColor="@color/button_material_dark"
android:textAllCaps="false"
android:layout_margin="8dp"/>
<Button
android:id="@+id/actionUploadFile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/ic_file_upload_grey600_24dp"
style="?android:buttonBarButtonStyle"
android:text="@string/upload_file"
android:textColor="@color/button_material_dark"
android:textAllCaps="false"
android:layout_margin="8dp"/>
<Button
android:id="@+id/actionDownload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/ic_file_download_grey600_24dp"
style="?android:buttonBarButtonStyle"
android:text="@string/download_document"
android:textColor="@color/button_material_dark"
android:textAllCaps="false"
android:layout_margin="8dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
style="?android:buttonBarStyle">
<Button
android:id="@+id/actionSharing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/ic_share_grey600_24dp"
style="?android:buttonBarButtonStyle"
android:text="@string/share"
android:textColor="@color/button_material_dark"
android:textAllCaps="false"
android:layout_margin="8dp"/>
<Button
android:id="@+id/actionDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/ic_delete_grey600_24dp"
style="?android:buttonBarButtonStyle"
android:text="@string/delete_document"
android:textColor="@color/button_material_dark"
android:textAllCaps="false"
android:layout_margin="8dp"/>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginRight="12dp"
android:layout_marginLeft="12dp"
android:background="#eee"/>
<!-- Document metadata --> <!-- Document metadata -->
<RelativeLayout <RelativeLayout
@ -122,9 +210,27 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="1dp"
android:layout_marginRight="12dp" android:layout_marginRight="12dp"
android:layout_marginEnd="12dp" android:layout_marginLeft="12dp"
android:background="#eee"/> android:background="#eee"/>
<!-- ACLs -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textColor="@color/primary_text_default_material_light"
android:text="@string/who_can_access"
android:layout_margin="12dp"/>
<ListView
android:id="@+id/aclListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"/>
</LinearLayout> </LinearLayout>
</android.support.v4.widget.DrawerLayout> </android.support.v4.widget.DrawerLayout>

View File

@ -9,48 +9,16 @@
android:title="@string/toggle_informations"> android:title="@string/toggle_informations">
</item> </item>
<item
android:id="@+id/edit"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_create_white_24dp"
android:title="@string/edit_document">
</item>
<item
android:id="@+id/upload_file"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_file_upload_white_24dp"
android:title="@string/upload_file">
</item>
<item
android:id="@+id/share"
app:showAsAction="collapseActionView"
android:title="@string/share">
</item>
<item <item
android:id="@+id/download_file" android:id="@+id/download_file"
app:showAsAction="collapseActionView" app:showAsAction="collapseActionView"
android:title="@string/download_file"> android:title="@string/download_file">
</item> </item>
<item
android:id="@+id/download_document"
app:showAsAction="collapseActionView"
android:title="@string/download_document">
</item>
<item <item
android:id="@+id/delete_file" android:id="@+id/delete_file"
app:showAsAction="collapseActionView" app:showAsAction="collapseActionView"
android:title="@string/delete_file"> android:title="@string/delete_file">
</item> </item>
<item
android:id="@+id/delete_document"
app:showAsAction="collapseActionView"
android:title="@string/delete_document">
</item>
</menu> </menu>

View File

@ -29,7 +29,7 @@
<string name="created_date">Created date</string> <string name="created_date">Created date</string>
<string name="download_file">Download current file</string> <string name="download_file">Download current file</string>
<string name="downloading_file">Downloading file number %1s</string> <string name="downloading_file">Downloading file number %1s</string>
<string name="download_document">Download all files</string> <string name="download_document">Download</string>
<string name="downloading_document">Downloading document</string> <string name="downloading_document">Downloading document</string>
<string name="action_search">Search documents</string> <string name="action_search">Search documents</string>
<string name="all_documents">All documents</string> <string name="all_documents">All documents</string>
@ -54,7 +54,7 @@
<string name="share_default_name">Share link</string> <string name="share_default_name">Share link</string>
<string name="error_deleting_share">Error deleting the share</string> <string name="error_deleting_share">Error deleting the share</string>
<string name="send_share_to">Send share link to</string> <string name="send_share_to">Send share link to</string>
<string name="upload_file">Upload a file</string> <string name="upload_file">Add file</string>
<string name="upload_from">Upload a file from</string> <string name="upload_from">Upload a file from</string>
<string name="settings">Settings</string> <string name="settings">Settings</string>
<string name="logout">Sign Out</string> <string name="logout">Sign Out</string>
@ -75,11 +75,11 @@
<string name="language_english">English</string> <string name="language_english">English</string>
<string name="language_japanese">Japanese</string> <string name="language_japanese">Japanese</string>
<string name="save">Save</string> <string name="save">Save</string>
<string name="edit_document">Edit document</string> <string name="edit_document">Edit</string>
<string name="error_editing_document">Network error, please try again</string> <string name="error_editing_document">Network error, please try again</string>
<string name="please_wait">Please wait</string> <string name="please_wait">Please wait</string>
<string name="document_editing_message">Sending your data</string> <string name="document_editing_message">Sending your data</string>
<string name="delete_document">Delete document</string> <string name="delete_document">Delete</string>
<string name="delete_document_title">Delete document</string> <string name="delete_document_title">Delete document</string>
<string name="delete_document_message">Really delete this document and all associated files?</string> <string name="delete_document_message">Really delete this document and all associated files?</string>
<string name="document_delete_failure">Network error while deleting this document</string> <string name="document_delete_failure">Network error while deleting this document</string>
@ -106,6 +106,7 @@
<string name="search_tags">Search tags</string> <string name="search_tags">Search tags</string>
<string name="all_languages">All languages</string> <string name="all_languages">All languages</string>
<string name="toggle_informations">Toggle informations</string> <string name="toggle_informations">Toggle informations</string>
<string name="who_can_access">Who can access</string>
</resources> </resources>