1
0
mirror of https://github.com/sismics/docs.git synced 2025-12-13 09:46:17 +00:00

Refactor, TODO

This commit is contained in:
jendib
2015-05-09 23:34:43 +02:00
parent 52387d93ac
commit 25136bc146
2 changed files with 45 additions and 22 deletions

View File

@@ -71,17 +71,22 @@ public class DocumentViewActivity extends AppCompatActivity {
/**
* File view pager.
*/
ViewPager fileViewPager;
private ViewPager fileViewPager;
/**
* File pager adapter.
*/
FilePagerAdapter filePagerAdapter;
private FilePagerAdapter filePagerAdapter;
/**
* Document displayed.
*/
JSONObject document;
private JSONObject document;
/**
* Menu.
*/
private Menu menu;
@Override
protected void onCreate(final Bundle args) {
@@ -181,29 +186,16 @@ public class DocumentViewActivity extends AppCompatActivity {
// Grab the attached files
updateFiles();
// Grab the full document (used for ACLs and writable status)
updateDocument();
}
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.document_view_activity, menu);
// Silently get the document to know if it is writable by the current user
// If this call fails or is slow and the document is read-only,
// write actions will be allowed and will fail
DocumentResource.get(this, document.optString("id"), new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
boolean writable = response.optBoolean("writable");
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);
}
});
this.menu = menu;
return super.onCreateOptionsMenu(menu);
}
@@ -510,6 +502,33 @@ public class DocumentViewActivity extends AppCompatActivity {
}
}
/**
* Update the document model.
*/
private void updateDocument() {
if (document == null) return;
// Silently get the document to know if it is writable by the current user
// If this call fails or is slow and the document is read-only,
// write actions will be allowed and will fail
DocumentResource.get(this, document.optString("id"), new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
boolean writable = response.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
}
});
}
/**
* Refresh files list.
*/