Experiment: quick switch unified folders

pull/214/head
M66B 1 year ago
parent 5cdec1c39f
commit 7f71b21c2c

@ -100,7 +100,7 @@ public interface DaoFolder {
" GROUP BY folder.id")
LiveData<List<TupleFolderEx>> liveFolders(Long account, boolean primary);
@Query("SELECT folder.*" +
final String queryUnified = "SELECT folder.*" +
", account.id AS accountId, account.pop AS accountProtocol, account.`order` AS accountOrder" +
", account.name AS accountName, account.category AS accountCategory, account.color AS accountColor" +
", account.state AS accountState, account.error AS accountError" +
@ -117,9 +117,14 @@ public interface DaoFolder {
" LEFT JOIN operation ON operation.folder = folder.id" +
" WHERE account.`synchronize`" +
" AND ((:type IS NULL AND folder.unified) OR folder.type = :type)" +
" GROUP BY folder.id")
" GROUP BY folder.id";
@Query(queryUnified)
LiveData<List<TupleFolderEx>> liveUnified(String type);
@Query(queryUnified)
List<TupleFolderEx> getUnified(String type);
@Query("SELECT folder.account, folder.id AS folder, unified, sync_state" +
" FROM folder" +
" JOIN account ON account.id = folder.account" +

@ -62,6 +62,7 @@ import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentResultListener;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.OnLifecycleEvent;
import androidx.preference.PreferenceManager;
@ -137,6 +138,33 @@ public class FragmentBase extends Fragment {
updateSubtitle();
}
protected void setActionBarListener(final LifecycleOwner owner, final View.OnClickListener listener) {
final AppCompatActivity activity = (AppCompatActivity) getActivity();
if (activity == null)
return;
final ActionBar actionbar = activity.getSupportActionBar();
if (actionbar == null)
return;
if ((actionbar.getDisplayOptions() & DISPLAY_SHOW_CUSTOM) == 0)
return;
final View custom = actionbar.getCustomView();
if (custom == null)
return;
owner.getLifecycle().addObserver(new LifecycleObserver() {
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
public void onAny() {
Lifecycle.State state = owner.getLifecycle().getCurrentState();
custom.setOnClickListener(state.isAtLeast(Lifecycle.State.STARTED) ? listener : null);
if (Lifecycle.State.DESTROYED.equals(state))
owner.getLifecycle().removeObserver(this);
}
});
}
@Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);

@ -555,6 +555,59 @@ public class FragmentMessages extends FragmentBase
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setHasOptionsMenu(true);
setActionBarListener(getViewLifecycleOwner(), new View.OnClickListener() {
@Override
public void onClick(View v) {
new SimpleTask<List<TupleFolderEx>>() {
@Override
protected List<TupleFolderEx> onExecute(Context context, Bundle args) {
DB db = DB.getInstance(context);
return db.folder().getUnified(null);
}
@Override
protected void onExecuted(Bundle args, final List<TupleFolderEx> folders) {
if (folders == null)
return;
final Context context = getContext();
if (context == null)
return;
Collections.sort(folders, folders.get(0).getComparator(context));
List<CharSequence> items = new ArrayList<>();
for (TupleFolderEx folder : folders)
items.add(folder.accountName + "/" + folder.getDisplayName(context));
new AlertDialog.Builder(context)
.setIcon(R.drawable.twotone_folder_open_24)
.setTitle(R.string.title_folders_unified)
.setItems(items.toArray(new CharSequence[0]), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
TupleFolderEx folder = folders.get(which);
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_MESSAGES)
.putExtra("account", folder.account)
.putExtra("folder", folder.id)
.putExtra("type", folder.type));
}
})
.setPositiveButton(android.R.string.cancel, null)
.show();
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragment(), ex);
}
}.execute(FragmentMessages.this, new Bundle(), "unified");
}
});
view = (ViewGroup) inflater.inflate(R.layout.fragment_messages, container, false);
// Get controls

Loading…
Cancel
Save