Option to delete identities
This commit is contained in:
@@ -8,4 +8,9 @@
|
|||||||
android:title="@string/edit_identity"
|
android:title="@string/edit_identity"
|
||||||
i2pandroid:showAsAction="ifRoom"/>
|
i2pandroid:showAsAction="ifRoom"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_delete_identity"
|
||||||
|
android:title="@string/action_delete"
|
||||||
|
i2pandroid:showAsAction="never"/>
|
||||||
|
|
||||||
</menu>
|
</menu>
|
||||||
@@ -101,5 +101,6 @@
|
|||||||
<string name="description">Description</string>
|
<string name="description">Description</string>
|
||||||
<string name="default_identity">Default identity</string>
|
<string name="default_identity">Default identity</string>
|
||||||
<string name="save_identity">Save identity</string>
|
<string name="save_identity">Save identity</string>
|
||||||
|
<string name="delete_identity">Delete identity?</string>
|
||||||
<string name="identity_saved">Identity saved</string>
|
<string name="identity_saved">Identity saved</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import i2p.bote.I2PBote;
|
|||||||
import i2p.bote.android.R;
|
import i2p.bote.android.R;
|
||||||
import i2p.bote.email.EmailIdentity;
|
import i2p.bote.email.EmailIdentity;
|
||||||
import i2p.bote.fileencryption.PasswordException;
|
import i2p.bote.fileencryption.PasswordException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -13,6 +14,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
@@ -35,6 +37,8 @@ public class SettingsActivity extends PreferenceActivity {
|
|||||||
// Actions for legacy settings
|
// Actions for legacy settings
|
||||||
private static final String ACTION_PREFS_GENERAL = "i2p.bote.PREFS_GENERAL";
|
private static final String ACTION_PREFS_GENERAL = "i2p.bote.PREFS_GENERAL";
|
||||||
|
|
||||||
|
static final int ALTER_IDENTITY_LIST = 1;
|
||||||
|
|
||||||
// Preference Header vars
|
// Preference Header vars
|
||||||
private Header[] mIdentityListHeaders;
|
private Header[] mIdentityListHeaders;
|
||||||
private List<Header> mGeneratedHeaders;
|
private List<Header> mGeneratedHeaders;
|
||||||
@@ -116,7 +120,7 @@ public class SettingsActivity extends PreferenceActivity {
|
|||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_new_identity:
|
case R.id.action_new_identity:
|
||||||
Intent ni = new Intent(this, EditIdentityActivity.class);
|
Intent ni = new Intent(this, EditIdentityActivity.class);
|
||||||
startActivity(ni);
|
startActivityForResult(ni, ALTER_IDENTITY_LIST);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -124,6 +128,15 @@ public class SettingsActivity extends PreferenceActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
if (requestCode == ALTER_IDENTITY_LIST) {
|
||||||
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
|
updateIdentities();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isValidFragment(String fragmentName) {
|
protected boolean isValidFragment(String fragmentName) {
|
||||||
return SettingsFragment.class.getName().equals(fragmentName);
|
return SettingsFragment.class.getName().equals(fragmentName);
|
||||||
@@ -369,7 +382,12 @@ public class SettingsActivity extends PreferenceActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled(int position) {
|
public boolean isEnabled(int position) {
|
||||||
return getItemViewType(position) != HEADER_TYPE_CATEGORY;
|
try {
|
||||||
|
return getItemViewType(position) != HEADER_TYPE_CATEGORY;
|
||||||
|
} catch (IndexOutOfBoundsException e) {
|
||||||
|
// Happens when deleting an identity
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -7,9 +7,14 @@ import i2p.bote.android.R;
|
|||||||
import i2p.bote.android.util.BoteHelper;
|
import i2p.bote.android.util.BoteHelper;
|
||||||
import i2p.bote.email.EmailIdentity;
|
import i2p.bote.email.EmailIdentity;
|
||||||
import i2p.bote.fileencryption.PasswordException;
|
import i2p.bote.fileencryption.PasswordException;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@@ -109,6 +114,41 @@ public class ViewIdentityFragment extends Fragment {
|
|||||||
startActivity(ei);
|
startActivity(ei);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
case R.id.action_delete_identity:
|
||||||
|
DialogFragment df = new DialogFragment() {
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
|
builder.setMessage(R.string.delete_identity)
|
||||||
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
dialog.dismiss();
|
||||||
|
try {
|
||||||
|
BoteHelper.deleteIdentity(mKey);
|
||||||
|
getActivity().setResult(Activity.RESULT_OK);
|
||||||
|
getActivity().finish();
|
||||||
|
} catch (PasswordException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException 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:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user