mirror of
https://github.com/etesync/android
synced 2025-01-11 08:10:58 +00:00
ViewCollection: only allow owner to edit collections.
This commit is contained in:
parent
656dad3615
commit
9fb9db9327
@ -10,11 +10,13 @@ package com.etesync.syncadapter.ui;
|
|||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.CalendarContract;
|
import android.provider.CalendarContract;
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@ -52,7 +54,9 @@ public class ViewCollectionActivity extends AppCompatActivity implements Refresh
|
|||||||
EXTRA_COLLECTION_INFO = "collectionInfo";
|
EXTRA_COLLECTION_INFO = "collectionInfo";
|
||||||
|
|
||||||
private Account account;
|
private Account account;
|
||||||
|
private JournalEntity journalEntity;
|
||||||
protected CollectionInfo info;
|
protected CollectionInfo info;
|
||||||
|
private boolean isOwner;
|
||||||
|
|
||||||
public static Intent newIntent(Context context, Account account, CollectionInfo info) {
|
public static Intent newIntent(Context context, Account account, CollectionInfo info) {
|
||||||
Intent intent = new Intent(context, ViewCollectionActivity.class);
|
Intent intent = new Intent(context, ViewCollectionActivity.class);
|
||||||
@ -65,13 +69,14 @@ public class ViewCollectionActivity extends AppCompatActivity implements Refresh
|
|||||||
public void refresh() {
|
public void refresh() {
|
||||||
EntityDataStore<Persistable> data = ((App) getApplicationContext()).getData();
|
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()) {
|
if ((journalEntity == null) || journalEntity.isDeleted()) {
|
||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
info = journalEntity.getInfo();
|
info = journalEntity.getInfo();
|
||||||
|
isOwner = account.name.equals(journalEntity.getOwner());
|
||||||
|
|
||||||
final View colorSquare = findViewById(R.id.color);
|
final View colorSquare = findViewById(R.id.color);
|
||||||
if (info.type == CollectionInfo.Type.CALENDAR) {
|
if (info.type == CollectionInfo.Type.CALENDAR) {
|
||||||
@ -161,7 +166,21 @@ public class ViewCollectionActivity extends AppCompatActivity implements Refresh
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onEditCollection(MenuItem item) {
|
public void onEditCollection(MenuItem item) {
|
||||||
|
if (isOwner) {
|
||||||
startActivity(EditCollectionActivity.newIntent(this, account, info));
|
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) {
|
public void onImport(MenuItem item) {
|
||||||
|
@ -104,6 +104,8 @@
|
|||||||
<string name="change_journal_title">Change Journal</string>
|
<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="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="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 -->
|
<!-- CollectionMembers -->
|
||||||
<string name="collection_members_title">Members</string>
|
<string name="collection_members_title">Members</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user