Account/identity/folder delete menu instead of button

pull/146/head
M66B 6 years ago
parent d7df285eb2
commit a844d24ec1

@ -42,6 +42,9 @@ import android.text.TextUtils;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
@ -50,7 +53,6 @@ import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.ScrollView; import android.widget.ScrollView;
@ -117,7 +119,6 @@ public class FragmentAccount extends FragmentEx {
private EditText etInterval; private EditText etInterval;
private Button btnCheck; private Button btnCheck;
private ImageButton ibDelete;
private ProgressBar pbCheck; private ProgressBar pbCheck;
private TextView tvIdle; private TextView tvIdle;
@ -155,6 +156,7 @@ public class FragmentAccount extends FragmentEx {
@Nullable @Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.title_edit_account); setSubtitle(R.string.title_edit_account);
setHasOptionsMenu(true);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
final boolean insecure = prefs.getBoolean("insecure", false); final boolean insecure = prefs.getBoolean("insecure", false);
@ -190,7 +192,6 @@ public class FragmentAccount extends FragmentEx {
etInterval = view.findViewById(R.id.etInterval); etInterval = view.findViewById(R.id.etInterval);
btnCheck = view.findViewById(R.id.btnCheck); btnCheck = view.findViewById(R.id.btnCheck);
ibDelete = view.findViewById(R.id.ibDelete);
pbCheck = view.findViewById(R.id.pbCheck); pbCheck = view.findViewById(R.id.pbCheck);
tvIdle = view.findViewById(R.id.tvIdle); tvIdle = view.findViewById(R.id.tvIdle);
@ -229,7 +230,6 @@ public class FragmentAccount extends FragmentEx {
grpAdvanced.setVisibility(View.GONE); grpAdvanced.setVisibility(View.GONE);
btnCheck.setVisibility(position > 0 ? View.VISIBLE : View.GONE); btnCheck.setVisibility(position > 0 ? View.VISIBLE : View.GONE);
ibDelete.setVisibility(position > 0 && id > 0 ? View.VISIBLE : View.GONE);
tvIdle.setVisibility(View.GONE); tvIdle.setVisibility(View.GONE);
Object tag = adapterView.getTag(); Object tag = adapterView.getTag();
@ -417,7 +417,6 @@ public class FragmentAccount extends FragmentEx {
Helper.setViewsEnabled(view, false); Helper.setViewsEnabled(view, false);
btnAuthorize.setEnabled(false); btnAuthorize.setEnabled(false);
btnCheck.setEnabled(false); btnCheck.setEnabled(false);
ibDelete.setEnabled(false);
pbCheck.setVisibility(View.VISIBLE); pbCheck.setVisibility(View.VISIBLE);
tvIdle.setVisibility(View.GONE); tvIdle.setVisibility(View.GONE);
grpFolders.setVisibility(View.GONE); grpFolders.setVisibility(View.GONE);
@ -539,7 +538,6 @@ public class FragmentAccount extends FragmentEx {
Helper.setViewsEnabled(view, true); Helper.setViewsEnabled(view, true);
btnAuthorize.setEnabled(true); btnAuthorize.setEnabled(true);
btnCheck.setEnabled(true); btnCheck.setEnabled(true);
ibDelete.setEnabled(true);
pbCheck.setVisibility(View.GONE); pbCheck.setVisibility(View.GONE);
tvIdle.setVisibility(result.idle ? View.GONE : View.VISIBLE); tvIdle.setVisibility(result.idle ? View.GONE : View.VISIBLE);
@ -559,7 +557,6 @@ public class FragmentAccount extends FragmentEx {
Helper.setViewsEnabled(view, true); Helper.setViewsEnabled(view, true);
btnAuthorize.setEnabled(true); btnAuthorize.setEnabled(true);
btnCheck.setEnabled(true); btnCheck.setEnabled(true);
ibDelete.setEnabled(true);
pbCheck.setVisibility(View.GONE); pbCheck.setVisibility(View.GONE);
grpFolders.setVisibility(View.GONE); grpFolders.setVisibility(View.GONE);
btnSave.setVisibility(View.GONE); btnSave.setVisibility(View.GONE);
@ -580,7 +577,6 @@ public class FragmentAccount extends FragmentEx {
Helper.setViewsEnabled(view, false); Helper.setViewsEnabled(view, false);
btnAuthorize.setEnabled(false); btnAuthorize.setEnabled(false);
btnCheck.setEnabled(false); btnCheck.setEnabled(false);
ibDelete.setEnabled(false);
btnSave.setEnabled(false); btnSave.setEnabled(false);
pbSave.setVisibility(View.VISIBLE); pbSave.setVisibility(View.VISIBLE);
@ -828,7 +824,6 @@ public class FragmentAccount extends FragmentEx {
Helper.setViewsEnabled(view, true); Helper.setViewsEnabled(view, true);
btnAuthorize.setEnabled(true); btnAuthorize.setEnabled(true);
btnCheck.setEnabled(true); btnCheck.setEnabled(true);
ibDelete.setEnabled(true);
btnSave.setEnabled(true); btnSave.setEnabled(true);
pbSave.setVisibility(View.GONE); pbSave.setVisibility(View.GONE);
@ -842,53 +837,6 @@ public class FragmentAccount extends FragmentEx {
} }
}); });
ibDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setMessage(R.string.title_account_delete)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Helper.setViewsEnabled(view, false);
btnAuthorize.setEnabled(false);
btnCheck.setEnabled(false);
ibDelete.setEnabled(false);
btnSave.setEnabled(false);
pbWait.setVisibility(View.VISIBLE);
Bundle args = new Bundle();
args.putLong("id", id);
new SimpleTask<Void>() {
@Override
protected Void onLoad(Context context, Bundle args) {
long id = args.getLong("id");
DB db = DB.getInstance(context);
EntityAccount account = db.account().getAccount(id);
db.account().deleteAccount(id);
if (account.synchronize)
ServiceSynchronize.reload(getContext(), "delete account");
return null;
}
@Override
protected void onLoaded(Bundle args, Void data) {
getFragmentManager().popBackStack();
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
}
}.load(FragmentAccount.this, args);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
}
});
adapter = new ArrayAdapter<>(getContext(), R.layout.spinner_item1, android.R.id.text1, new ArrayList<EntityFolder>()); adapter = new ArrayAdapter<>(getContext(), R.layout.spinner_item1, android.R.id.text1, new ArrayList<EntityFolder>());
adapter.setDropDownViewResource(R.layout.spinner_item1_dropdown); adapter.setDropDownViewResource(R.layout.spinner_item1_dropdown);
@ -910,7 +858,6 @@ public class FragmentAccount extends FragmentEx {
tvIdle.setVisibility(View.GONE); tvIdle.setVisibility(View.GONE);
btnCheck.setVisibility(View.GONE); btnCheck.setVisibility(View.GONE);
ibDelete.setVisibility(View.GONE);
pbCheck.setVisibility(View.GONE); pbCheck.setVisibility(View.GONE);
btnSave.setVisibility(View.GONE); btnSave.setVisibility(View.GONE);
@ -1031,7 +978,6 @@ public class FragmentAccount extends FragmentEx {
cbPrimary.setEnabled(cbSynchronize.isChecked()); cbPrimary.setEnabled(cbSynchronize.isChecked());
// Consider previous check/save/delete as cancelled // Consider previous check/save/delete as cancelled
ibDelete.setVisibility(account == null ? View.GONE : View.VISIBLE);
pbWait.setVisibility(View.GONE); pbWait.setVisibility(View.GONE);
args.putLong("account", account == null ? -1 : account.id); args.putLong("account", account == null ? -1 : account.id);
@ -1064,18 +1010,70 @@ public class FragmentAccount extends FragmentEx {
}.load(this, args); }.load(this, args);
} }
private void selectAccount() { @Override
Log.i(Helper.TAG, "Select account"); public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
Provider provider = (Provider) spProvider.getSelectedItem(); inflater.inflate(R.menu.menu_account, menu);
if (provider.type != null) super.onCreateOptionsMenu(menu, inflater);
startActivityForResult(newChooseAccountIntent( }
null,
null, @Override
new String[]{provider.type}, public void onPrepareOptionsMenu(Menu menu) {
null, menu.findItem(R.id.menu_delete).setVisible(id > 0);
null, super.onPrepareOptionsMenu(menu);
null, }
null), ActivitySetup.REQUEST_CHOOSE_ACCOUNT);
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_delete:
onMenuDelete();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void onMenuDelete() {
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setMessage(R.string.title_account_delete)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Helper.setViewsEnabled(view, false);
btnAuthorize.setEnabled(false);
btnCheck.setEnabled(false);
btnSave.setEnabled(false);
pbWait.setVisibility(View.VISIBLE);
Bundle args = new Bundle();
args.putLong("id", id);
new SimpleTask<Void>() {
@Override
protected Void onLoad(Context context, Bundle args) {
long id = args.getLong("id");
DB db = DB.getInstance(context);
EntityAccount account = db.account().getAccount(id);
db.account().deleteAccount(id);
if (account.synchronize)
ServiceSynchronize.reload(getContext(), "delete account");
return null;
}
@Override
protected void onLoaded(Bundle args, Void data) {
getFragmentManager().popBackStack();
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
}
}.load(FragmentAccount.this, args);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
} }
@Override @Override
@ -1129,6 +1127,20 @@ public class FragmentAccount extends FragmentEx {
} }
} }
private void selectAccount() {
Log.i(Helper.TAG, "Select account");
Provider provider = (Provider) spProvider.getSelectedItem();
if (provider.type != null)
startActivityForResult(newChooseAccountIntent(
null,
null,
new String[]{provider.type},
null,
null,
null,
null), ActivitySetup.REQUEST_CHOOSE_ACCOUNT);
}
private void setColor(int color) { private void setColor(int color) {
FragmentAccount.this.color = color; FragmentAccount.this.color = color;

@ -25,13 +25,15 @@ import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
@ -58,7 +60,6 @@ public class FragmentFolder extends FragmentEx {
private EditText etSyncDays; private EditText etSyncDays;
private EditText etKeepDays; private EditText etKeepDays;
private Button btnSave; private Button btnSave;
private ImageButton ibDelete;
private ProgressBar pbSave; private ProgressBar pbSave;
private ProgressBar pbWait; private ProgressBar pbWait;
@ -79,6 +80,7 @@ public class FragmentFolder extends FragmentEx {
@Nullable @Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.title_edit_folder); setSubtitle(R.string.title_edit_folder);
setHasOptionsMenu(true);
view = (ViewGroup) inflater.inflate(R.layout.fragment_folder, container, false); view = (ViewGroup) inflater.inflate(R.layout.fragment_folder, container, false);
@ -92,7 +94,6 @@ public class FragmentFolder extends FragmentEx {
etSyncDays = view.findViewById(R.id.etSyncDays); etSyncDays = view.findViewById(R.id.etSyncDays);
etKeepDays = view.findViewById(R.id.etKeepDays); etKeepDays = view.findViewById(R.id.etKeepDays);
btnSave = view.findViewById(R.id.btnSave); btnSave = view.findViewById(R.id.btnSave);
ibDelete = view.findViewById(R.id.ibDelete);
pbSave = view.findViewById(R.id.pbSave); pbSave = view.findViewById(R.id.pbSave);
pbWait = view.findViewById(R.id.pbWait); pbWait = view.findViewById(R.id.pbWait);
@ -108,7 +109,6 @@ public class FragmentFolder extends FragmentEx {
public void onClick(View v) { public void onClick(View v) {
Helper.setViewsEnabled(view, false); Helper.setViewsEnabled(view, false);
btnSave.setEnabled(false); btnSave.setEnabled(false);
ibDelete.setEnabled(false);
pbSave.setVisibility(View.VISIBLE); pbSave.setVisibility(View.VISIBLE);
Bundle args = new Bundle(); Bundle args = new Bundle();
@ -250,7 +250,6 @@ public class FragmentFolder extends FragmentEx {
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Helper.setViewsEnabled(view, true); Helper.setViewsEnabled(view, true);
btnSave.setEnabled(true); btnSave.setEnabled(true);
ibDelete.setEnabled(true);
pbSave.setVisibility(View.GONE); pbSave.setVisibility(View.GONE);
if (ex instanceof IllegalArgumentException) if (ex instanceof IllegalArgumentException)
@ -262,94 +261,110 @@ public class FragmentFolder extends FragmentEx {
} }
}); });
ibDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setMessage(R.string.title_folder_delete)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Helper.setViewsEnabled(view, false);
btnSave.setEnabled(false);
ibDelete.setEnabled(false);
pbSave.setVisibility(View.VISIBLE);
Bundle args = new Bundle();
args.putLong("id", id);
new SimpleTask<Void>() {
@Override
protected Void onLoad(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
IMAPStore istore = null;
DB db = DB.getInstance(getContext());
try {
db.beginTransaction();
EntityFolder folder = db.folder().getFolder(id);
EntityAccount account = db.account().getAccount(folder.account);
Properties props = MessageHelper.getSessionProperties(account.auth_type, account.insecure);
Session isession = Session.getInstance(props, null);
istore = (IMAPStore) isession.getStore(account.starttls ? "imap" : "imaps");
Helper.connect(context, istore, account);
IMAPFolder ifolder = (IMAPFolder) istore.getFolder(folder.name);
ifolder.delete(false);
db.folder().deleteFolder(id);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
if (istore != null)
istore.close();
}
ServiceSynchronize.reload(getContext(), "delete folder");
return null;
}
@Override
protected void onLoaded(Bundle args, Void data) {
getFragmentManager().popBackStack();
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.setViewsEnabled(view, true);
btnSave.setEnabled(true);
ibDelete.setEnabled(true);
pbSave.setVisibility(View.GONE);
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
}
}.load(FragmentFolder.this, args);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
}
});
// Initialize // Initialize
Helper.setViewsEnabled(view, false); Helper.setViewsEnabled(view, false);
btnSave.setEnabled(false); btnSave.setEnabled(false);
ibDelete.setEnabled(false);
ibDelete.setVisibility(View.GONE);
pbSave.setVisibility(View.GONE); pbSave.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE); pbWait.setVisibility(View.VISIBLE);
return view; return view;
} }
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_folder, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public void onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_delete).setVisible(id > 0);
super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_delete:
onMenuDelete();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void onMenuDelete() {
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setMessage(R.string.title_folder_delete)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Helper.setViewsEnabled(view, false);
btnSave.setEnabled(false);
pbSave.setVisibility(View.VISIBLE);
Bundle args = new Bundle();
args.putLong("id", id);
new SimpleTask<Void>() {
@Override
protected Void onLoad(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
IMAPStore istore = null;
DB db = DB.getInstance(getContext());
try {
db.beginTransaction();
EntityFolder folder = db.folder().getFolder(id);
EntityAccount account = db.account().getAccount(folder.account);
Properties props = MessageHelper.getSessionProperties(account.auth_type, account.insecure);
Session isession = Session.getInstance(props, null);
istore = (IMAPStore) isession.getStore(account.starttls ? "imap" : "imaps");
Helper.connect(context, istore, account);
IMAPFolder ifolder = (IMAPFolder) istore.getFolder(folder.name);
ifolder.delete(false);
db.folder().deleteFolder(id);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
if (istore != null)
istore.close();
}
ServiceSynchronize.reload(getContext(), "delete folder");
return null;
}
@Override
protected void onLoaded(Bundle args, Void data) {
getFragmentManager().popBackStack();
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.setViewsEnabled(view, true);
btnSave.setEnabled(true);
pbSave.setVisibility(View.GONE);
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
}
}.load(FragmentFolder.this, args);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
}
@Override @Override
public void onActivityCreated(@Nullable final Bundle savedInstanceState) { public void onActivityCreated(@Nullable final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
@ -384,7 +399,6 @@ public class FragmentFolder extends FragmentEx {
etRename.setEnabled(folder == null || EntityFolder.USER.equals(folder.type)); etRename.setEnabled(folder == null || EntityFolder.USER.equals(folder.type));
cbPoll.setEnabled(cbSynchronize.isChecked()); cbPoll.setEnabled(cbSynchronize.isChecked());
btnSave.setEnabled(true); btnSave.setEnabled(true);
ibDelete.setVisibility(folder == null || !EntityFolder.USER.equals(folder.type) ? View.GONE : View.VISIBLE);
} }
@Override @Override

@ -31,6 +31,9 @@ import android.text.Html;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
@ -99,7 +102,6 @@ public class FragmentIdentity extends FragmentEx {
private Button btnSave; private Button btnSave;
private ProgressBar pbSave; private ProgressBar pbSave;
private ImageButton ibDelete;
private ProgressBar pbWait; private ProgressBar pbWait;
private Group grpAdvanced; private Group grpAdvanced;
@ -120,6 +122,7 @@ public class FragmentIdentity extends FragmentEx {
@Nullable @Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.title_edit_identity); setSubtitle(R.string.title_edit_identity);
setHasOptionsMenu(true);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
final boolean insecure = prefs.getBoolean("insecure", false); final boolean insecure = prefs.getBoolean("insecure", false);
@ -159,7 +162,6 @@ public class FragmentIdentity extends FragmentEx {
btnSave = view.findViewById(R.id.btnSave); btnSave = view.findViewById(R.id.btnSave);
pbSave = view.findViewById(R.id.pbSave); pbSave = view.findViewById(R.id.pbSave);
ibDelete = view.findViewById(R.id.ibDelete);
pbWait = view.findViewById(R.id.pbWait); pbWait = view.findViewById(R.id.pbWait);
grpAdvanced = view.findViewById(R.id.grpAdvanced); grpAdvanced = view.findViewById(R.id.grpAdvanced);
@ -528,50 +530,6 @@ public class FragmentIdentity extends FragmentEx {
} }
}); });
ibDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setMessage(R.string.title_identity_delete)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Helper.setViewsEnabled(view, false);
btnSave.setEnabled(false);
pbWait.setVisibility(View.VISIBLE);
Bundle args = new Bundle();
args.putLong("id", id);
new SimpleTask<Void>() {
@Override
protected Void onLoad(Context context, Bundle args) {
long id = args.getLong("id");
DB db = DB.getInstance(context);
EntityIdentity identity = db.identity().getIdentity(id);
db.identity().deleteIdentity(id);
if (identity.synchronize)
ServiceSynchronize.reload(getContext(), "delete identity");
return null;
}
@Override
protected void onLoaded(Bundle args, Void data) {
getFragmentManager().popBackStack();
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
}
}.load(FragmentIdentity.this, args);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
}
});
adapter = new ArrayAdapter<>(getContext(), R.layout.spinner_item1, android.R.id.text1, new ArrayList<EntityFolder>()); adapter = new ArrayAdapter<>(getContext(), R.layout.spinner_item1, android.R.id.text1, new ArrayList<EntityFolder>());
adapter.setDropDownViewResource(R.layout.spinner_item1_dropdown); adapter.setDropDownViewResource(R.layout.spinner_item1_dropdown);
spSent.setAdapter(adapter); spSent.setAdapter(adapter);
@ -584,7 +542,6 @@ public class FragmentIdentity extends FragmentEx {
btnAdvanced.setVisibility(View.GONE); btnAdvanced.setVisibility(View.GONE);
grpAdvanced.setVisibility(View.GONE); grpAdvanced.setVisibility(View.GONE);
pbSave.setVisibility(View.GONE); pbSave.setVisibility(View.GONE);
ibDelete.setVisibility(View.GONE);
return view; return view;
} }
@ -672,8 +629,6 @@ public class FragmentIdentity extends FragmentEx {
cbPrimary.setEnabled(cbSynchronize.isChecked()); cbPrimary.setEnabled(cbSynchronize.isChecked());
// Consider previous save/delete as cancelled
ibDelete.setVisibility(identity == null ? View.GONE : View.VISIBLE);
pbWait.setVisibility(View.GONE); pbWait.setVisibility(View.GONE);
new SimpleTask<List<EntityAccount>>() { new SimpleTask<List<EntityAccount>>() {
@ -757,6 +712,70 @@ public class FragmentIdentity extends FragmentEx {
}.load(this, args); }.load(this, args);
} }
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_identity, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public void onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_delete).setVisible(id > 0);
super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_delete:
onMenuDelete();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void onMenuDelete() {
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setMessage(R.string.title_identity_delete)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Helper.setViewsEnabled(view, false);
btnSave.setEnabled(false);
pbWait.setVisibility(View.VISIBLE);
Bundle args = new Bundle();
args.putLong("id", id);
new SimpleTask<Void>() {
@Override
protected Void onLoad(Context context, Bundle args) {
long id = args.getLong("id");
DB db = DB.getInstance(context);
EntityIdentity identity = db.identity().getIdentity(id);
db.identity().deleteIdentity(id);
if (identity.synchronize)
ServiceSynchronize.reload(getContext(), "delete identity");
return null;
}
@Override
protected void onLoaded(Bundle args, Void data) {
getFragmentManager().popBackStack();
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
}
}.load(FragmentIdentity.this, args);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
}
private void setColor(int color) { private void setColor(int color) {
FragmentIdentity.this.color = color; FragmentIdentity.this.color = color;

@ -360,15 +360,6 @@
app:layout_constraintStart_toEndOf="@id/btnCheck" app:layout_constraintStart_toEndOf="@id/btnCheck"
app:layout_constraintTop_toTopOf="@id/btnCheck" /> app:layout_constraintTop_toTopOf="@id/btnCheck" />
<ImageButton
android:id="@+id/ibDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:src="@drawable/baseline_delete_24"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/etInterval" />
<TextView <TextView
android:id="@+id/tvIdle" android:id="@+id/tvIdle"
android:layout_width="wrap_content" android:layout_width="wrap_content"

@ -140,15 +140,6 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etKeepDays" /> app:layout_constraintTop_toBottomOf="@id/etKeepDays" />
<ImageButton
android:id="@+id/ibDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:src="@drawable/baseline_delete_24"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/etKeepDays" />
<ProgressBar <ProgressBar
android:id="@+id/pbSave" android:id="@+id/pbSave"
style="@style/Base.Widget.AppCompat.ProgressBar" style="@style/Base.Widget.AppCompat.ProgressBar"

@ -420,15 +420,6 @@
app:layout_constraintStart_toEndOf="@id/btnSave" app:layout_constraintStart_toEndOf="@id/btnSave"
app:layout_constraintTop_toTopOf="@id/btnSave" /> app:layout_constraintTop_toTopOf="@id/btnSave" />
<ImageButton
android:id="@+id/ibDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:src="@drawable/baseline_delete_24"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/spSent" />
<ProgressBar <ProgressBar
android:id="@+id/pbWait" android:id="@+id/pbWait"
style="@style/Base.Widget.AppCompat.ProgressBar" style="@style/Base.Widget.AppCompat.ProgressBar"

@ -0,0 +1,8 @@
<?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:title="@string/title_delete"
app:showAsAction="never" />
</menu>

@ -0,0 +1,8 @@
<?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:title="@string/title_delete"
app:showAsAction="never" />
</menu>

@ -0,0 +1,8 @@
<?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:title="@string/title_delete"
app:showAsAction="never" />
</menu>
Loading…
Cancel
Save