|
|
|
@ -61,6 +61,7 @@ public class FragmentFolder extends FragmentBase {
|
|
|
|
|
|
|
|
|
|
private long id = -1;
|
|
|
|
|
private long account = -1;
|
|
|
|
|
private Boolean subscribed = null;
|
|
|
|
|
private boolean saving = false;
|
|
|
|
|
private boolean deletable = false;
|
|
|
|
|
|
|
|
|
@ -289,6 +290,8 @@ public class FragmentFolder extends FragmentBase {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onPrepareOptionsMenu(Menu menu) {
|
|
|
|
|
menu.findItem(R.id.menu_subscribe).setChecked(subscribed != null && subscribed);
|
|
|
|
|
menu.findItem(R.id.menu_subscribe).setVisible(id > 0 && subscribed != null);
|
|
|
|
|
menu.findItem(R.id.menu_delete).setVisible(id > 0 && !saving && deletable);
|
|
|
|
|
super.onPrepareOptionsMenu(menu);
|
|
|
|
|
}
|
|
|
|
@ -296,6 +299,11 @@ public class FragmentFolder extends FragmentBase {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
|
case R.id.menu_subscribe:
|
|
|
|
|
subscribed = !item.isChecked();
|
|
|
|
|
item.setChecked(subscribed);
|
|
|
|
|
onMenuSubscribe();
|
|
|
|
|
return true;
|
|
|
|
|
case R.id.menu_delete:
|
|
|
|
|
onMenuDelete();
|
|
|
|
|
return true;
|
|
|
|
@ -304,6 +312,29 @@ public class FragmentFolder extends FragmentBase {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onMenuSubscribe() {
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
|
args.putLong("id", id);
|
|
|
|
|
args.putBoolean("subscribed", subscribed);
|
|
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
|
@Override
|
|
|
|
|
protected Void onExecute(Context context, Bundle args) {
|
|
|
|
|
long id = args.getLong("id");
|
|
|
|
|
boolean subscribed = args.getBoolean("subscribed");
|
|
|
|
|
|
|
|
|
|
EntityOperation.subscribe(context, id, subscribed);
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
|
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
|
|
|
|
|
}
|
|
|
|
|
}.execute(getContext(), getViewLifecycleOwner(), args, "folder:subscribe");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onMenuDelete() {
|
|
|
|
|
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
|
|
|
|
|
.setMessage(R.string.title_folder_delete)
|
|
|
|
@ -399,6 +430,7 @@ public class FragmentFolder extends FragmentBase {
|
|
|
|
|
cbDownload.setEnabled(cbSynchronize.isChecked());
|
|
|
|
|
btnSave.setEnabled(true);
|
|
|
|
|
|
|
|
|
|
subscribed = (folder == null ? null : folder.subscribed != null && folder.subscribed);
|
|
|
|
|
deletable = (folder != null && EntityFolder.USER.equals(folder.type));
|
|
|
|
|
getActivity().invalidateOptionsMenu();
|
|
|
|
|
}
|
|
|
|
|