1
0
mirror of https://github.com/etesync/android synced 2024-11-16 04:49:06 +00:00

Add an edit collection page.

This commit is contained in:
Tom Hacohen 2017-03-08 14:13:23 +00:00
parent ce3483cee2
commit 7bb57c15a9
7 changed files with 108 additions and 78 deletions

View File

@ -46,7 +46,6 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
@ -176,81 +175,34 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu
return false;
}
private AdapterView.OnItemClickListener onItemClickListener = new AdapterView.OnItemClickListener() {
private AdapterView.OnItemClickListener onContactItemClickListener = 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);
boolean nowChecked = !info.selected;
if (list.getChoiceMode() == AbsListView.CHOICE_MODE_SINGLE)
// clear all other checked items
for (int i = adapter.getCount()-1; i >= 0; i--)
adapter.getItem(i).selected = false;
OpenHelper dbHelper = new OpenHelper(AccountActivity.this);
try {
SQLiteDatabase db = dbHelper.getWritableDatabase();
db.beginTransactionNonExclusive();
if (list.getChoiceMode() == AbsListView.CHOICE_MODE_SINGLE) {
// disable all other collections
ContentValues values = new ContentValues(1);
values.put(Collections.SYNC, 0);
db.update(Collections._TABLE, values, Collections.SERVICE_ID + "=?", new String[] { String.valueOf(info.serviceID) });
}
ContentValues values = new ContentValues(1);
values.put(Collections.SYNC, nowChecked ? 1 : 0);
db.update(Collections._TABLE, values, Collections.ID + "=?", new String[] { String.valueOf(info.id) });
db.setTransactionSuccessful();
db.endTransaction();
info.selected = nowChecked;
adapter.notifyDataSetChanged();
} finally {
dbHelper.close();
}
Intent intent = new Intent(AccountActivity.this, CreateAddressBookActivity.class);
intent.putExtra(CreateAddressBookActivity.EXTRA_ACCOUNT, account);
intent.putExtra(CreateAddressBookActivity.EXTRA_COLLECTION_INFO, info);
startActivity(intent);
}
};
private AdapterView.OnItemLongClickListener onItemLongClickListener = new AdapterView.OnItemLongClickListener() {
private AdapterView.OnItemClickListener onCalendarItemClickListener = new AdapterView.OnItemClickListener() {
@Override
public boolean onItemLongClick(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 ArrayAdapter<CollectionInfo> adapter = (ArrayAdapter)list.getAdapter();
final CollectionInfo info = adapter.getItem(position);
PopupMenu popup = new PopupMenu(AccountActivity.this, view);
popup.inflate(R.menu.account_collection_operations);
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.delete_collection:
if (adapter.getCount() == 1) {
new AlertDialog.Builder(AccountActivity.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);
}
break;
}
return true;
}
});
popup.show();
// long click was handled
return true;
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);
}
};
@ -293,6 +245,7 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu
AddressBookAdapter adapter = new AddressBookAdapter(this);
adapter.addAll(info.carddav.collections);
listCardDAV.setAdapter(adapter);
listCardDAV.setOnItemClickListener(onContactItemClickListener);
} else
card.setVisibility(View.GONE);
@ -308,8 +261,7 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu
final CalendarAdapter adapter = new CalendarAdapter(this);
adapter.addAll(info.caldav.collections);
listCalDAV.setAdapter(adapter);
listCalDAV.setOnItemClickListener(onItemClickListener);
listCalDAV.setOnItemLongClickListener(onItemLongClickListener);
listCalDAV.setOnItemClickListener(onCalendarItemClickListener);
} else
card.setVisibility(View.GONE);
}

View File

@ -18,24 +18,37 @@ import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import org.apache.commons.lang3.StringUtils;
import com.etesync.syncadapter.R;
import com.etesync.syncadapter.model.CollectionInfo;
import org.apache.commons.lang3.StringUtils;
public class CreateAddressBookActivity extends AppCompatActivity {
public static final String EXTRA_ACCOUNT = "account";
public static final String EXTRA_ACCOUNT = "account",
EXTRA_COLLECTION_INFO = "collectionInfo";
protected Account account;
protected CollectionInfo info;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
account = getIntent().getParcelableExtra(EXTRA_ACCOUNT);
info = (CollectionInfo) getIntent().getExtras().getSerializable(EXTRA_COLLECTION_INFO);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.activity_create_address_book);
if (info != null) {
final EditText edit = (EditText) findViewById(R.id.display_name);
edit.setText(info.displayName);
edit.setEnabled(false);
final EditText desc = (EditText) findViewById(R.id.description);
desc.setText(info.description);
}
}
@Override
@ -57,7 +70,9 @@ public class CreateAddressBookActivity extends AppCompatActivity {
public void onCreateCollection(MenuItem item) {
boolean ok = true;
CollectionInfo info = new CollectionInfo();
if (info == null) {
info = new CollectionInfo();
}
EditText edit = (EditText)findViewById(R.id.display_name);
info.displayName = edit.getText().toString();

View File

@ -13,6 +13,7 @@ import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
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;
@ -22,20 +23,30 @@ import android.widget.EditText;
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.resource.LocalCalendar;
import yuku.ambilwarna.AmbilWarnaDialog;
public class CreateCalendarActivity extends AppCompatActivity {
public static final String EXTRA_ACCOUNT = "account";
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);
@ -56,11 +67,30 @@ public class CreateCalendarActivity extends AppCompatActivity {
}).show();
}
});
if (info != null) {
final EditText edit = (EditText) findViewById(R.id.display_name);
edit.setText(info.displayName);
edit.setEnabled(false);
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);
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_create_collection, menu);
if (info == null) {
getMenuInflater().inflate(R.menu.activity_create_collection, menu);
} else {
getMenuInflater().inflate(R.menu.activity_edit_collection, menu);
}
return true;
}
@ -75,9 +105,24 @@ public class CreateCalendarActivity extends AppCompatActivity {
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;
CollectionInfo info = new CollectionInfo();
if (info == null) {
info = new CollectionInfo();
}
EditText edit = (EditText) findViewById(R.id.display_name);
info.displayName = edit.getText().toString();

View File

@ -81,6 +81,8 @@ public class DeleteCollectionFragment extends DialogFragment implements LoaderMa
Activity activity = getActivity();
if (activity instanceof AccountActivity)
((AccountActivity) activity).reload();
else if (activity instanceof CreateCalendarActivity)
activity.finish();
}
}

View File

@ -16,12 +16,6 @@
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_addressbook"
android:textAppearance="@style/TextView.Heading"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View File

@ -0,0 +1,22 @@
<?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
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:title="@string/delete_collection"
android:onClick="onDeleteCollection"
app:showAsAction="always"/>
<item android:title="@string/create_collection_create"
android:onClick="onCreateCollection"
app:showAsAction="always"/>
</menu>

View File

@ -183,7 +183,7 @@
<string name="create_collection_display_name">Display name (title) of this collection:</string>
<string name="create_collection_display_name_required">Title is required</string>
<string name="create_collection_description">Description (optional):</string>
<string name="create_collection_create">Create</string>
<string name="create_collection_create">Save</string>
<string name="delete_collection">Delete</string>
<string name="delete_collection_confirm_title">Are you sure?</string>
<string name="delete_collection_confirm_warning">This collection (%s) and all its data will be removed from the server.</string>