Moved delete contacts

pull/153/head
M66B 6 years ago
parent 08d7d51e57
commit 83e4197bf9

@ -179,34 +179,6 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On
}
});
drawerList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
DrawerItem item = drawerArray.getItem(position);
if (item == null)
return false;
if (item.getMenuId() == R.string.menu_privacy) {
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
int count = DB.getInstance(context).contact().clearContacts();
Log.i("Cleared contacts=" + count);
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(ActivitySetup.this, ActivitySetup.this, ex);
}
}.execute(ActivitySetup.this, new Bundle(), "setup:privacy");
return true;
}
return false;
}
});
List<DrawerItem> items = new ArrayList<>();
PackageManager pm = getPackageManager();

@ -19,10 +19,16 @@ package eu.faircode.email;
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
@ -45,6 +51,7 @@ public class FragmentContacts extends FragmentBase {
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.menu_contacts);
setHasOptionsMenu(true);
View view = inflater.inflate(R.layout.fragment_contacts, container, false);
@ -87,4 +94,52 @@ public class FragmentContacts extends FragmentBase {
}
});
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_contacts, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_delete:
onDelete();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void onDelete() {
final View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_message, null);
final TextView tvMessage = dview.findViewById(R.id.tvMessage);
tvMessage.setText(getText(R.string.title_delete_contacts));
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setView(dview)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
int count = DB.getInstance(context).contact().clearContacts();
Log.i("Cleared contacts=" + count);
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
}
}.execute(getContext(), getViewLifecycleOwner(), new Bundle(), "setup:privacy");
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
}
}

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_delete"
android:icon="@drawable/baseline_delete_24"
android:title="@string/title_delete"
app:showAsAction="always" />
</menu>

@ -283,6 +283,7 @@
<string name="title_empty_trash_ask">Delete all trashed messages permanently?</string>
<string name="title_delete_operation">Delete operations with an error message?</string>
<string name="title_delete_contacts">Delete all local contacts?</string>
<string name="title_no_operations">No pending operations</string>
<string name="title_folder_name">Folder name</string>

Loading…
Cancel
Save