1
0
mirror of https://github.com/etesync/android synced 2024-12-23 15:18:14 +00:00

ViewCollection: only allow owner to edit collections.

This commit is contained in:
Tom Hacohen 2017-04-13 21:29:11 +01:00
parent 656dad3615
commit 9fb9db9327
2 changed files with 23 additions and 2 deletions

View File

@ -10,11 +10,13 @@ package com.etesync.syncadapter.ui;
import android.accounts.Account;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.CalendarContract;
import android.provider.ContactsContract;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.Menu;
@ -52,7 +54,9 @@ public class ViewCollectionActivity extends AppCompatActivity implements Refresh
EXTRA_COLLECTION_INFO = "collectionInfo";
private Account account;
private JournalEntity journalEntity;
protected CollectionInfo info;
private boolean isOwner;
public static Intent newIntent(Context context, Account account, CollectionInfo info) {
Intent intent = new Intent(context, ViewCollectionActivity.class);
@ -65,13 +69,14 @@ public class ViewCollectionActivity extends AppCompatActivity implements Refresh
public void refresh() {
EntityDataStore<Persistable> data = ((App) getApplicationContext()).getData();
final JournalEntity journalEntity = JournalEntity.fetch(data, info.getServiceEntity(data), info.uid);
journalEntity = JournalEntity.fetch(data, info.getServiceEntity(data), info.uid);
if ((journalEntity == null) || journalEntity.isDeleted()) {
finish();
return;
}
info = journalEntity.getInfo();
isOwner = account.name.equals(journalEntity.getOwner());
final View colorSquare = findViewById(R.id.color);
if (info.type == CollectionInfo.Type.CALENDAR) {
@ -161,7 +166,21 @@ public class ViewCollectionActivity extends AppCompatActivity implements Refresh
}
public void onEditCollection(MenuItem item) {
startActivity(EditCollectionActivity.newIntent(this, account, info));
if (isOwner) {
startActivity(EditCollectionActivity.newIntent(this, account, info));
} else {
AlertDialog dialog = new AlertDialog.Builder(this)
.setIcon(R.drawable.ic_info_dark)
.setTitle(R.string.not_allowed_title)
.setMessage(getString(R.string.edit_owner_only, journalEntity.getOwner()))
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).create();
dialog.show();
}
}
public void onImport(MenuItem item) {

View File

@ -104,6 +104,8 @@
<string name="change_journal_title">Change Journal</string>
<string name="account_showcase_import">In order to import contacts and calendars into EteSync, you need to click on the menu, and choose \"Import\".</string>
<string name="members_owner_only">Only the owner of this collection (%s) is allowed to view its members.</string>
<string name="not_allowed_title">Not Allowed</string>
<string name="edit_owner_only">Only the owner of this collection (%s) is allowed to edit it.</string>
<!-- CollectionMembers -->
<string name="collection_members_title">Members</string>