Option to delete contacts
This commit is contained in:
@@ -8,4 +8,9 @@
|
||||
android:title="@string/save_contact"
|
||||
i2pandroid:showAsAction="ifRoom"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_delete_contact"
|
||||
android:title="@string/action_delete"
|
||||
i2pandroid:showAsAction="never"/>
|
||||
|
||||
</menu>
|
||||
@@ -57,6 +57,7 @@
|
||||
<string name="email_destination">Email destination</string>
|
||||
<string name="label_browse">Browse</string>
|
||||
<string name="save_contact">Save contact</string>
|
||||
<string name="delete_contact">Delete contact?</string>
|
||||
|
||||
<string name="network_info_unavailable">Network information is not available because Bote hasn\'t started connecting to the network yet.</string>
|
||||
<string name="local_destination">Local Destination:</string>
|
||||
|
||||
@@ -9,6 +9,8 @@ import android.support.v7.app.ActionBarActivity;
|
||||
|
||||
public class AddressBookActivity extends ActionBarActivity implements
|
||||
AddressBookFragment.OnContactSelectedListener {
|
||||
static final int ALTER_CONTACT_LIST = 1;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -34,7 +36,19 @@ public class AddressBookActivity extends ActionBarActivity implements
|
||||
} else {
|
||||
Intent i = new Intent(this, EditContactActivity.class);
|
||||
i.putExtra(EditContactFragment.CONTACT_DESTINATION, contact.getBase64Dest());
|
||||
startActivity(i);
|
||||
startActivityForResult(i, ALTER_CONTACT_LIST);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == ALTER_CONTACT_LIST) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
AddressBookFragment f = (AddressBookFragment) getSupportFragmentManager().findFragmentById(android.R.id.content);
|
||||
f.updateContactList();
|
||||
}
|
||||
} else {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class AddressBookFragment extends ListFragment implements
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_new_contact:
|
||||
Intent nci = new Intent(getActivity(), EditContactActivity.class);
|
||||
startActivity(nci);
|
||||
getActivity().startActivityForResult(nci, AddressBookActivity.ALTER_CONTACT_LIST);
|
||||
return true;
|
||||
|
||||
default:
|
||||
@@ -87,6 +87,11 @@ public class AddressBookFragment extends ListFragment implements
|
||||
mCallback.onContactSelected(mAdapter.getItem(pos));
|
||||
}
|
||||
|
||||
protected void updateContactList() {
|
||||
setListShown(false);
|
||||
getLoaderManager().restartLoader(0, null, this);
|
||||
}
|
||||
|
||||
// LoaderManager.LoaderCallbacks<SortedSet<Contact>>
|
||||
|
||||
public Loader<SortedSet<Contact>> onCreateLoader(int id, Bundle args) {
|
||||
|
||||
@@ -7,15 +7,20 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.security.GeneralSecurityException;
|
||||
|
||||
import i2p.bote.android.R;
|
||||
import i2p.bote.android.util.BoteHelper;
|
||||
import i2p.bote.android.util.EditPictureFragment;
|
||||
import i2p.bote.fileencryption.PasswordException;
|
||||
import i2p.bote.packet.dht.Contact;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@@ -123,9 +128,11 @@ public class EditContactFragment extends EditPictureFragment {
|
||||
|
||||
try {
|
||||
String err = BoteHelper.saveContact(destination, name, picture, text);
|
||||
if (err == null)
|
||||
if (err == null) {
|
||||
if (mDestination == null) // Only set if adding new contact
|
||||
getActivity().setResult(Activity.RESULT_OK);
|
||||
getActivity().finish();
|
||||
else
|
||||
} else
|
||||
mError.setText(err);
|
||||
} catch (PasswordException e) {
|
||||
// TODO Auto-generated catch block
|
||||
@@ -138,6 +145,41 @@ public class EditContactFragment extends EditPictureFragment {
|
||||
}
|
||||
return true;
|
||||
|
||||
case R.id.action_delete_contact:
|
||||
DialogFragment df = new DialogFragment() {
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setMessage(R.string.delete_contact)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
try {
|
||||
String err = BoteHelper.deleteContact(mDestination);
|
||||
if (err == null) {
|
||||
getActivity().setResult(Activity.RESULT_OK);
|
||||
getActivity().finish();
|
||||
} else
|
||||
mError.setText(err);
|
||||
} catch (PasswordException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (GeneralSecurityException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
};
|
||||
df.show(getActivity().getSupportFragmentManager(), "deletecontact");
|
||||
return true;
|
||||
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user