mirror of
https://github.com/etesync/android
synced 2025-02-02 19:01:06 +00:00
Merge contacts/calendars collection handling
This also removes the "stats" from the edit collection screen.
This commit is contained in:
parent
3530821ddd
commit
838cc2a79d
@ -183,10 +183,8 @@
|
|||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".ui.JournalViewerActivity"/>
|
<activity android:name=".ui.JournalViewerActivity"/>
|
||||||
<activity android:name=".ui.AccountSettingsActivity"/>
|
<activity android:name=".ui.AccountSettingsActivity"/>
|
||||||
<activity android:name=".ui.CreateAddressBookActivity"
|
<activity android:name=".ui.CreateCollectionActivity"/>
|
||||||
android:label="@string/create_addressbook"/>
|
<activity android:name=".ui.EditCollectionActivity"/>
|
||||||
<activity android:name=".ui.CreateCalendarActivity"
|
|
||||||
android:label="@string/create_calendar"/>
|
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.DebugInfoActivity"
|
android:name=".ui.DebugInfoActivity"
|
||||||
|
@ -61,7 +61,6 @@ import com.etesync.syncadapter.model.ServiceDB.Services;
|
|||||||
import com.etesync.syncadapter.resource.LocalCalendar;
|
import com.etesync.syncadapter.resource.LocalCalendar;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
@ -164,45 +163,24 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
Intent intent;
|
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.create_calendar:
|
case R.id.create_calendar:
|
||||||
intent = new Intent(this, CreateCalendarActivity.class);
|
CollectionInfo info = new CollectionInfo();
|
||||||
intent.putExtra(CreateCalendarActivity.EXTRA_ACCOUNT, account);
|
info.type = CollectionInfo.Type.CALENDAR;
|
||||||
startActivity(intent);
|
startActivity(CreateCollectionActivity.newIntent(AccountActivity.this, account, info));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AdapterView.OnItemClickListener onContactItemClickListener = new AdapterView.OnItemClickListener() {
|
private AdapterView.OnItemClickListener onItemClickListener = new AdapterView.OnItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
final ListView list = (ListView)parent;
|
final ListView list = (ListView)parent;
|
||||||
final ArrayAdapter<CollectionInfo> adapter = (ArrayAdapter)list.getAdapter();
|
final ArrayAdapter<CollectionInfo> adapter = (ArrayAdapter)list.getAdapter();
|
||||||
final CollectionInfo info = adapter.getItem(position);
|
final CollectionInfo info = adapter.getItem(position);
|
||||||
|
|
||||||
Intent intent = new Intent(AccountActivity.this, CreateAddressBookActivity.class);
|
startActivity(EditCollectionActivity.newIntent(AccountActivity.this, account, info, (adapter.getCount() > 1)));
|
||||||
intent.putExtra(CreateAddressBookActivity.EXTRA_ACCOUNT, account);
|
|
||||||
intent.putExtra(CreateAddressBookActivity.EXTRA_COLLECTION_INFO, info);
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private AdapterView.OnItemClickListener onCalendarItemClickListener = new AdapterView.OnItemClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
||||||
final ListView list = (ListView)parent;
|
|
||||||
final ArrayAdapter<CollectionInfo> adapter = (ArrayAdapter)list.getAdapter();
|
|
||||||
final CollectionInfo info = adapter.getItem(position);
|
|
||||||
|
|
||||||
Intent intent = new Intent(AccountActivity.this, CreateCalendarActivity.class);
|
|
||||||
intent.putExtra(CreateCalendarActivity.EXTRA_ACCOUNT, account);
|
|
||||||
intent.putExtra(CreateCalendarActivity.EXTRA_COLLECTION_INFO, info);
|
|
||||||
if (adapter.getCount() > 1) {
|
|
||||||
intent.putExtra(CreateCalendarActivity.EXTRA_ALLOW_DELETE, true);
|
|
||||||
}
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -250,7 +228,7 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu
|
|||||||
AddressBookAdapter adapter = new AddressBookAdapter(this);
|
AddressBookAdapter adapter = new AddressBookAdapter(this);
|
||||||
adapter.addAll(info.carddav.collections);
|
adapter.addAll(info.carddav.collections);
|
||||||
listCardDAV.setAdapter(adapter);
|
listCardDAV.setAdapter(adapter);
|
||||||
listCardDAV.setOnItemClickListener(onContactItemClickListener);
|
listCardDAV.setOnItemClickListener(onItemClickListener);
|
||||||
} else
|
} else
|
||||||
card.setVisibility(View.GONE);
|
card.setVisibility(View.GONE);
|
||||||
|
|
||||||
@ -266,7 +244,7 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu
|
|||||||
final CalendarAdapter adapter = new CalendarAdapter(this);
|
final CalendarAdapter adapter = new CalendarAdapter(this);
|
||||||
adapter.addAll(info.caldav.collections);
|
adapter.addAll(info.caldav.collections);
|
||||||
listCalDAV.setAdapter(adapter);
|
listCalDAV.setAdapter(adapter);
|
||||||
listCalDAV.setOnItemClickListener(onCalendarItemClickListener);
|
listCalDAV.setOnItemClickListener(onItemClickListener);
|
||||||
} else
|
} else
|
||||||
card.setVisibility(View.GONE);
|
card.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
@ -1,174 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright © 2013 – 2016 Ricki Hirner (bitfire web engineering).
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the GNU Public License v3.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
* http://www.gnu.org/licenses/gpl.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.etesync.syncadapter.ui;
|
|
||||||
|
|
||||||
import android.accounts.Account;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.graphics.drawable.ColorDrawable;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.provider.CalendarContract;
|
|
||||||
import android.support.v4.app.NavUtils;
|
|
||||||
import android.support.v7.app.AlertDialog;
|
|
||||||
import android.support.v7.app.AppCompatActivity;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import com.etesync.syncadapter.App;
|
|
||||||
import com.etesync.syncadapter.R;
|
|
||||||
import com.etesync.syncadapter.model.CollectionInfo;
|
|
||||||
import com.etesync.syncadapter.model.EntryEntity;
|
|
||||||
import com.etesync.syncadapter.model.JournalEntity;
|
|
||||||
import com.etesync.syncadapter.resource.LocalCalendar;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import at.bitfire.ical4android.CalendarStorageException;
|
|
||||||
import io.requery.Persistable;
|
|
||||||
import io.requery.sql.EntityDataStore;
|
|
||||||
import yuku.ambilwarna.AmbilWarnaDialog;
|
|
||||||
|
|
||||||
public class CreateCalendarActivity extends AppCompatActivity {
|
|
||||||
public static final String EXTRA_ACCOUNT = "account",
|
|
||||||
EXTRA_COLLECTION_INFO = "collectionInfo",
|
|
||||||
EXTRA_ALLOW_DELETE = "allowDelete";
|
|
||||||
|
|
||||||
protected Account account;
|
|
||||||
protected CollectionInfo info;
|
|
||||||
protected Boolean allowDelete;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
account = getIntent().getExtras().getParcelable(EXTRA_ACCOUNT);
|
|
||||||
info = (CollectionInfo) getIntent().getExtras().getSerializable(EXTRA_COLLECTION_INFO);
|
|
||||||
allowDelete = (Boolean) getIntent().getExtras().get(EXTRA_ALLOW_DELETE);
|
|
||||||
allowDelete = (allowDelete == null) ? false : allowDelete;
|
|
||||||
|
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
||||||
|
|
||||||
setContentView(R.layout.activity_create_calendar);
|
|
||||||
final View colorSquare = findViewById(R.id.color);
|
|
||||||
colorSquare.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
new AmbilWarnaDialog(CreateCalendarActivity.this, ((ColorDrawable) colorSquare.getBackground()).getColor(), true, new AmbilWarnaDialog.OnAmbilWarnaListener() {
|
|
||||||
@Override
|
|
||||||
public void onCancel(AmbilWarnaDialog dialog) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onOk(AmbilWarnaDialog dialog, int color) {
|
|
||||||
colorSquare.setBackgroundColor(color);
|
|
||||||
}
|
|
||||||
}).show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (info != null) {
|
|
||||||
final EditText edit = (EditText) findViewById(R.id.display_name);
|
|
||||||
edit.setText(info.displayName);
|
|
||||||
|
|
||||||
final EditText desc = (EditText) findViewById(R.id.description);
|
|
||||||
desc.setText(info.description);
|
|
||||||
|
|
||||||
if (info.color != null) {
|
|
||||||
colorSquare.setBackgroundColor(info.color);
|
|
||||||
} else {
|
|
||||||
colorSquare.setBackgroundColor(LocalCalendar.defaultColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
final TextView stats = (TextView) findViewById(R.id.stats);
|
|
||||||
final View statsGroup = findViewById(R.id.stats_group);
|
|
||||||
try {
|
|
||||||
LocalCalendar resource = (LocalCalendar) LocalCalendar.find(account, this.getContentResolver().acquireContentProviderClient(CalendarContract.CONTENT_URI),
|
|
||||||
LocalCalendar.Factory.INSTANCE, CalendarContract.Calendars.NAME + "=?", new String[]{info.url})[0];
|
|
||||||
long count = resource.count();
|
|
||||||
EntityDataStore<Persistable> data = ((App) getApplication()).getData();
|
|
||||||
int entryCount = -1;
|
|
||||||
final JournalEntity journalEntity = data.select(JournalEntity.class).where(JournalEntity.UID.eq(info.url)).limit(1).get().firstOrNull();
|
|
||||||
if (journalEntity != null) {
|
|
||||||
entryCount = data.count(EntryEntity.class).where(EntryEntity.JOURNAL.eq(journalEntity)).get().value();
|
|
||||||
}
|
|
||||||
stats.setText(String.format(Locale.getDefault(), "Events: %d, Journal entries: %d", count, entryCount));
|
|
||||||
statsGroup.setVisibility(View.VISIBLE);
|
|
||||||
} catch (CalendarStorageException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
|
||||||
if (info == null) {
|
|
||||||
getMenuInflater().inflate(R.menu.activity_create_collection, menu);
|
|
||||||
} else {
|
|
||||||
getMenuInflater().inflate(R.menu.activity_edit_collection, menu);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
if (item.getItemId() == android.R.id.home) {
|
|
||||||
Intent intent = new Intent(this, AccountActivity.class);
|
|
||||||
intent.putExtra(AccountActivity.EXTRA_ACCOUNT, account);
|
|
||||||
NavUtils.navigateUpTo(this, intent);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onDeleteCollection(MenuItem item) {
|
|
||||||
if (!allowDelete) {
|
|
||||||
new AlertDialog.Builder(this)
|
|
||||||
.setIcon(R.drawable.ic_error_dark)
|
|
||||||
.setTitle(R.string.account_delete_collection_last_title)
|
|
||||||
.setMessage(R.string.account_delete_collection_last_text)
|
|
||||||
.setPositiveButton(android.R.string.ok, null)
|
|
||||||
.show();
|
|
||||||
} else {
|
|
||||||
DeleteCollectionFragment.ConfirmDeleteCollectionFragment.newInstance(account, info).show(getSupportFragmentManager(), null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onCreateCollection(MenuItem item) {
|
|
||||||
boolean ok = true;
|
|
||||||
if (info == null) {
|
|
||||||
info = new CollectionInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
EditText edit = (EditText) findViewById(R.id.display_name);
|
|
||||||
info.displayName = edit.getText().toString();
|
|
||||||
if (TextUtils.isEmpty(info.displayName)) {
|
|
||||||
edit.setError(getString(R.string.create_collection_display_name_required));
|
|
||||||
ok = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
edit = (EditText) findViewById(R.id.description);
|
|
||||||
info.description = StringUtils.trimToNull(edit.getText().toString());
|
|
||||||
|
|
||||||
View view = findViewById(R.id.color);
|
|
||||||
info.color = ((ColorDrawable) view.getBackground()).getColor();
|
|
||||||
|
|
||||||
if (ok) {
|
|
||||||
info.type = CollectionInfo.Type.CALENDAR;
|
|
||||||
info.supportsVEVENT = true;
|
|
||||||
info.selected = true;
|
|
||||||
|
|
||||||
CreateCollectionFragment.newInstance(account, info).show(getSupportFragmentManager(), null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -9,9 +9,10 @@
|
|||||||
package com.etesync.syncadapter.ui;
|
package com.etesync.syncadapter.ui;
|
||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.ContactsContract;
|
|
||||||
import android.support.v4.app.NavUtils;
|
import android.support.v4.app.NavUtils;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@ -19,65 +20,63 @@ import android.view.Menu;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.etesync.syncadapter.App;
|
|
||||||
import com.etesync.syncadapter.R;
|
import com.etesync.syncadapter.R;
|
||||||
import com.etesync.syncadapter.model.CollectionInfo;
|
import com.etesync.syncadapter.model.CollectionInfo;
|
||||||
import com.etesync.syncadapter.model.EntryEntity;
|
|
||||||
import com.etesync.syncadapter.model.JournalEntity;
|
|
||||||
import com.etesync.syncadapter.resource.LocalAddressBook;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.w3c.dom.Text;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
import yuku.ambilwarna.AmbilWarnaDialog;
|
||||||
|
|
||||||
import at.bitfire.vcard4android.ContactsStorageException;
|
public class CreateCollectionActivity extends AppCompatActivity {
|
||||||
import io.requery.Persistable;
|
static final String EXTRA_ACCOUNT = "account",
|
||||||
import io.requery.sql.EntityDataStore;
|
|
||||||
|
|
||||||
public class CreateAddressBookActivity extends AppCompatActivity {
|
|
||||||
public static final String EXTRA_ACCOUNT = "account",
|
|
||||||
EXTRA_COLLECTION_INFO = "collectionInfo";
|
EXTRA_COLLECTION_INFO = "collectionInfo";
|
||||||
|
|
||||||
protected Account account;
|
protected Account account;
|
||||||
protected CollectionInfo info;
|
protected CollectionInfo info;
|
||||||
|
|
||||||
|
public static Intent newIntent(Context context, Account account, CollectionInfo info) {
|
||||||
|
Intent intent = new Intent(context, CreateCollectionActivity.class);
|
||||||
|
intent.putExtra(CreateCollectionActivity.EXTRA_ACCOUNT, account);
|
||||||
|
intent.putExtra(CreateCollectionActivity.EXTRA_COLLECTION_INFO, info);
|
||||||
|
return intent;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
account = getIntent().getParcelableExtra(EXTRA_ACCOUNT);
|
account = getIntent().getExtras().getParcelable(EXTRA_ACCOUNT);
|
||||||
info = (CollectionInfo) getIntent().getExtras().getSerializable(EXTRA_COLLECTION_INFO);
|
info = (CollectionInfo) getIntent().getExtras().getSerializable(EXTRA_COLLECTION_INFO);
|
||||||
|
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
setContentView(R.layout.activity_create_address_book);
|
|
||||||
|
|
||||||
if (info != null) {
|
setContentView(R.layout.activity_create_collection);
|
||||||
final EditText edit = (EditText) findViewById(R.id.display_name);
|
|
||||||
edit.setText(info.displayName);
|
|
||||||
|
|
||||||
final EditText desc = (EditText) findViewById(R.id.description);
|
if (info.type == CollectionInfo.Type.CALENDAR) {
|
||||||
desc.setText(info.description);
|
setTitle(R.string.create_calendar);
|
||||||
|
|
||||||
final TextView stats = (TextView) findViewById(R.id.stats);
|
final View colorSquare = findViewById(R.id.color);
|
||||||
final View statsGroup = findViewById(R.id.stats_group);
|
colorSquare.setOnClickListener(new View.OnClickListener() {
|
||||||
try {
|
@Override
|
||||||
LocalAddressBook resource = new LocalAddressBook(account, this.getContentResolver().acquireContentProviderClient(ContactsContract.Contacts.CONTENT_URI));
|
public void onClick(View v) {
|
||||||
long count = resource.count();
|
new AmbilWarnaDialog(CreateCollectionActivity.this, ((ColorDrawable) colorSquare.getBackground()).getColor(), true, new AmbilWarnaDialog.OnAmbilWarnaListener() {
|
||||||
EntityDataStore<Persistable> data = ((App) getApplication()).getData();
|
@Override
|
||||||
int entryCount = -1;
|
public void onCancel(AmbilWarnaDialog dialog) {
|
||||||
final JournalEntity journalEntity = data.select(JournalEntity.class).where(JournalEntity.UID.eq(info.url)).limit(1).get().firstOrNull();
|
|
||||||
if (journalEntity != null) {
|
|
||||||
entryCount = data.count(EntryEntity.class).where(EntryEntity.JOURNAL.eq(journalEntity)).get().value();
|
|
||||||
};
|
|
||||||
stats.setText(String.format(Locale.getDefault(), "Contacts: %d, Journal Entries: %d", count, entryCount));
|
|
||||||
statsGroup.setVisibility(View.VISIBLE);
|
|
||||||
} catch (ContactsStorageException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onOk(AmbilWarnaDialog dialog, int color) {
|
||||||
|
colorSquare.setBackgroundColor(color);
|
||||||
|
}
|
||||||
|
}).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
setTitle(R.string.create_addressbook);
|
||||||
|
|
||||||
|
final View colorGroup = findViewById(R.id.color_group);
|
||||||
|
colorGroup.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,18 +103,25 @@ public class CreateAddressBookActivity extends AppCompatActivity {
|
|||||||
info = new CollectionInfo();
|
info = new CollectionInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
EditText edit = (EditText)findViewById(R.id.display_name);
|
EditText edit = (EditText) findViewById(R.id.display_name);
|
||||||
info.displayName = edit.getText().toString();
|
info.displayName = edit.getText().toString();
|
||||||
if (TextUtils.isEmpty(info.displayName)) {
|
if (TextUtils.isEmpty(info.displayName)) {
|
||||||
edit.setError(getString(R.string.create_collection_display_name_required));
|
edit.setError(getString(R.string.create_collection_display_name_required));
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
edit = (EditText)findViewById(R.id.description);
|
edit = (EditText) findViewById(R.id.description);
|
||||||
info.description = StringUtils.trimToNull(edit.getText().toString());
|
info.description = StringUtils.trimToNull(edit.getText().toString());
|
||||||
|
|
||||||
if (ok) {
|
if (ok) {
|
||||||
info.type = CollectionInfo.Type.ADDRESS_BOOK;
|
if (info.type == CollectionInfo.Type.CALENDAR) {
|
||||||
|
View view = findViewById(R.id.color);
|
||||||
|
info.color = ((ColorDrawable) view.getBackground()).getColor();
|
||||||
|
|
||||||
|
info.supportsVEVENT = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
info.selected = true;
|
||||||
|
|
||||||
CreateCollectionFragment.newInstance(account, info).show(getSupportFragmentManager(), null);
|
CreateCollectionFragment.newInstance(account, info).show(getSupportFragmentManager(), null);
|
||||||
}
|
}
|
@ -84,7 +84,7 @@ public class DeleteCollectionFragment extends DialogFragment implements LoaderMa
|
|||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (activity instanceof AccountActivity)
|
if (activity instanceof AccountActivity)
|
||||||
((AccountActivity) activity).reload();
|
((AccountActivity) activity).reload();
|
||||||
else if (activity instanceof CreateCalendarActivity)
|
else if (activity instanceof CreateCollectionActivity)
|
||||||
activity.finish();
|
activity.finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2013 – 2016 Ricki Hirner (bitfire web engineering).
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the GNU Public License v3.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.gnu.org/licenses/gpl.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.etesync.syncadapter.ui;
|
||||||
|
|
||||||
|
import android.accounts.Account;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
import com.etesync.syncadapter.R;
|
||||||
|
import com.etesync.syncadapter.model.CollectionInfo;
|
||||||
|
import com.etesync.syncadapter.resource.LocalCalendar;
|
||||||
|
|
||||||
|
public class EditCollectionActivity extends CreateCollectionActivity {
|
||||||
|
private final static String EXTRA_ALLOW_DELETE = "allowDelete";
|
||||||
|
|
||||||
|
protected boolean allowDelete;
|
||||||
|
|
||||||
|
public static Intent newIntent(Context context, Account account, CollectionInfo info, boolean allowDelete) {
|
||||||
|
Intent intent = new Intent(context, EditCollectionActivity.class);
|
||||||
|
intent.putExtra(CreateCollectionActivity.EXTRA_ACCOUNT, account);
|
||||||
|
intent.putExtra(CreateCollectionActivity.EXTRA_COLLECTION_INFO, info);
|
||||||
|
intent.putExtra(EXTRA_ALLOW_DELETE, allowDelete);
|
||||||
|
return intent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
allowDelete = getIntent().getExtras().getBoolean(EXTRA_ALLOW_DELETE, false);
|
||||||
|
|
||||||
|
setTitle(R.string.edit_collection);
|
||||||
|
|
||||||
|
if (info.type == CollectionInfo.Type.CALENDAR) {
|
||||||
|
final View colorSquare = findViewById(R.id.color);
|
||||||
|
if (info.color != null) {
|
||||||
|
colorSquare.setBackgroundColor(info.color);
|
||||||
|
} else {
|
||||||
|
colorSquare.setBackgroundColor(LocalCalendar.defaultColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final EditText edit = (EditText) findViewById(R.id.display_name);
|
||||||
|
edit.setText(info.displayName);
|
||||||
|
|
||||||
|
final EditText desc = (EditText) findViewById(R.id.description);
|
||||||
|
desc.setText(info.description);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
if (info.type == CollectionInfo.Type.ADDRESS_BOOK) {
|
||||||
|
getMenuInflater().inflate(R.menu.activity_create_collection, menu);
|
||||||
|
} else {
|
||||||
|
getMenuInflater().inflate(R.menu.activity_edit_collection, menu);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDeleteCollection(MenuItem item) {
|
||||||
|
if (!allowDelete) {
|
||||||
|
new AlertDialog.Builder(this)
|
||||||
|
.setIcon(R.drawable.ic_error_dark)
|
||||||
|
.setTitle(R.string.account_delete_collection_last_title)
|
||||||
|
.setMessage(R.string.account_delete_collection_last_text)
|
||||||
|
.setPositiveButton(android.R.string.ok, null)
|
||||||
|
.show();
|
||||||
|
} else {
|
||||||
|
DeleteCollectionFragment.ConfirmDeleteCollectionFragment.newInstance(account, info).show(getSupportFragmentManager(), null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,64 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
~ Copyright © 2013 – 2016 Ricki Hirner (bitfire web engineering).
|
|
||||||
~ All rights reserved. This program and the accompanying materials
|
|
||||||
~ are made available under the terms of the GNU Public License v3.0
|
|
||||||
~ which accompanies this distribution, and is available at
|
|
||||||
~ http://www.gnu.org/licenses/gpl.html
|
|
||||||
-->
|
|
||||||
|
|
||||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_width="match_parent">
|
|
||||||
|
|
||||||
<LinearLayout android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:padding="@dimen/activity_margin">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/create_collection_display_name"/>
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/display_name"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="16dp"
|
|
||||||
android:hint="@string/create_addressbook_display_name_hint"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/create_collection_description"/>
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/description"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="16dp"
|
|
||||||
android:inputType="textAutoCorrect"/>
|
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/stats_group"
|
|
||||||
android:visibility="gone"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="16dp"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="4dp"
|
|
||||||
android:text="@string/collection_stats_title"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/stats"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginLeft="6dp" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
</ScrollView>
|
|
@ -39,6 +39,7 @@
|
|||||||
android:inputType="textAutoCorrect"/>
|
android:inputType="textAutoCorrect"/>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/color_group"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
@ -59,27 +60,5 @@
|
|||||||
android:text="@string/create_collection_color"/>
|
android:text="@string/create_collection_color"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/stats_group"
|
|
||||||
android:visibility="gone"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="16dp"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="4dp"
|
|
||||||
android:text="@string/collection_stats_title"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/stats"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginLeft="6dp" />
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</ScrollView>
|
</ScrollView>
|
@ -181,6 +181,7 @@
|
|||||||
<string name="create_addressbook_display_name_hint">My Address Book</string>
|
<string name="create_addressbook_display_name_hint">My Address Book</string>
|
||||||
<string name="create_calendar">Create calendar</string>
|
<string name="create_calendar">Create calendar</string>
|
||||||
<string name="create_calendar_display_name_hint">My Calendar</string>
|
<string name="create_calendar_display_name_hint">My Calendar</string>
|
||||||
|
<string name="edit_collection">Edit collection</string>
|
||||||
<string name="create_collection_color">Set the calendar\'s color</string>
|
<string name="create_collection_color">Set the calendar\'s color</string>
|
||||||
<string name="create_collection_creating">Creating collection</string>
|
<string name="create_collection_creating">Creating collection</string>
|
||||||
<string name="create_collection_display_name">Display name (title) of this collection:</string>
|
<string name="create_collection_display_name">Display name (title) of this collection:</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user