diff --git a/app/src/main/java/com/etesync/syncadapter/ui/AccountActivity.java b/app/src/main/java/com/etesync/syncadapter/ui/AccountActivity.java index 697d27b0..f06459f4 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/AccountActivity.java +++ b/app/src/main/java/com/etesync/syncadapter/ui/AccountActivity.java @@ -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 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 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); } diff --git a/app/src/main/java/com/etesync/syncadapter/ui/CreateAddressBookActivity.java b/app/src/main/java/com/etesync/syncadapter/ui/CreateAddressBookActivity.java index e7c80af2..1280b88b 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/CreateAddressBookActivity.java +++ b/app/src/main/java/com/etesync/syncadapter/ui/CreateAddressBookActivity.java @@ -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(); diff --git a/app/src/main/java/com/etesync/syncadapter/ui/CreateCalendarActivity.java b/app/src/main/java/com/etesync/syncadapter/ui/CreateCalendarActivity.java index 45238c4e..ae04803c 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/CreateCalendarActivity.java +++ b/app/src/main/java/com/etesync/syncadapter/ui/CreateCalendarActivity.java @@ -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(); diff --git a/app/src/main/java/com/etesync/syncadapter/ui/DeleteCollectionFragment.java b/app/src/main/java/com/etesync/syncadapter/ui/DeleteCollectionFragment.java index fe5945a3..d574e008 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/DeleteCollectionFragment.java +++ b/app/src/main/java/com/etesync/syncadapter/ui/DeleteCollectionFragment.java @@ -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(); } } diff --git a/app/src/main/res/layout/activity_create_address_book.xml b/app/src/main/res/layout/activity_create_address_book.xml index fe2b6dc3..d8095dde 100644 --- a/app/src/main/res/layout/activity_create_address_book.xml +++ b/app/src/main/res/layout/activity_create_address_book.xml @@ -16,12 +16,6 @@ android:layout_height="wrap_content" android:padding="@dimen/activity_margin"> - - + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 36029f93..8d33a417 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -183,7 +183,7 @@ Display name (title) of this collection: Title is required Description (optional): - Create + Save Delete Are you sure? This collection (%s) and all its data will be removed from the server.