diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 3e3b4b4944..7e693dccf0 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -3008,25 +3008,13 @@ public class AdapterMessage extends RecyclerView.Adapter>() { - @Override - protected List onExecute(Context context, Bundle args) { - long account = args.getLong("account"); - - DB db = DB.getInstance(context); - return db.folder().getFoldersEx(account); - } - - @Override - protected void onExecuted(final Bundle args, List folders) { - if (folders == null) - folders = new ArrayList<>(); - - adapter.setDisabled(Arrays.asList(data.message.folder)); - adapter.set(folders); - pbWait.setVisibility(View.GONE); - rvFolder.setVisibility(View.VISIBLE); - } - - @Override - protected void onException(Bundle args, Throwable ex) { - Helper.unexpectedError(context, owner, ex); - } - }.execute(context, owner, args, "message:move:list"); } private void onActionMoveOutbox(ActionData data) { diff --git a/app/src/main/java/eu/faircode/email/DialogFolder.java b/app/src/main/java/eu/faircode/email/DialogFolder.java new file mode 100644 index 0000000000..55518738c5 --- /dev/null +++ b/app/src/main/java/eu/faircode/email/DialogFolder.java @@ -0,0 +1,101 @@ +package eu.faircode.email; + +/* + This file is part of FairEmail. + + FairEmail is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + FairEmail is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FairEmail. If not, see . + + Copyright 2018-2019 by Marcel Bokhorst (M66B) +*/ + +import android.app.Dialog; +import android.content.Context; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; + +import androidx.lifecycle.LifecycleOwner; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import java.util.ArrayList; +import java.util.List; + +public class DialogFolder { + static void show( + final Context context, final LifecycleOwner owner, View parentView, int title, + long account, final List disabled, + final IDialogFolder intf) { + final View dview = LayoutInflater.from(context).inflate(R.layout.dialog_folder_select, null); + final RecyclerView rvFolder = dview.findViewById(R.id.rvFolder); + final ContentLoadingProgressBar pbWait = dview.findViewById(R.id.pbWait); + + final Dialog dialog = new DialogBuilderLifecycle(context, owner) + .setTitle(title) + .setView(dview) + .create(); + + rvFolder.setHasFixedSize(false); + LinearLayoutManager llm = new LinearLayoutManager(context); + rvFolder.setLayoutManager(llm); + + final AdapterFolder adapter = new AdapterFolder(context, owner, parentView, account, false, + new AdapterFolder.IFolderSelectedListener() { + @Override + public void onFolderSelected(TupleFolderEx folder) { + dialog.dismiss(); + intf.onFolderSelected(folder); + } + }); + + rvFolder.setAdapter(adapter); + + rvFolder.setVisibility(View.GONE); + pbWait.setVisibility(View.VISIBLE); + dialog.show(); + + Bundle args = new Bundle(); + args.putLong("account", account); + + new SimpleTask>() { + @Override + protected List onExecute(Context context, Bundle args) { + long account = args.getLong("account"); + + DB db = DB.getInstance(context); + return db.folder().getFoldersEx(account); + } + + @Override + protected void onExecuted(final Bundle args, List folders) { + if (folders == null) + folders = new ArrayList<>(); + + adapter.setDisabled(disabled); + adapter.set(folders); + pbWait.setVisibility(View.GONE); + rvFolder.setVisibility(View.VISIBLE); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Helper.unexpectedError(context, owner, ex); + } + }.execute(context, owner, args, "folder:select"); + } + + interface IDialogFolder { + void onFolderSelected(TupleFolderEx folder); + } +} diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index b6c9abb5fb..79d589e4f1 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -1981,36 +1981,16 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } private void onActionMoveSelectionAccount(long account, List folders, List disabled, final Long id) { - final View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_folder_select, null); - final RecyclerView rvFolder = dview.findViewById(R.id.rvFolder); - final ContentLoadingProgressBar pbWait = dview.findViewById(R.id.pbWait); - - final Dialog dialog = new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner()) - .setTitle(R.string.title_move_to_folder) - .setView(dview) - .create(); - - rvFolder.setHasFixedSize(false); - LinearLayoutManager llm = new LinearLayoutManager(getContext()); - rvFolder.setLayoutManager(llm); - - final AdapterFolder adapter = new AdapterFolder(getContext(), getViewLifecycleOwner(), view, account, false, - new AdapterFolder.IFolderSelectedListener() { + DialogFolder.show( + getContext(), getViewLifecycleOwner(), view, + R.string.title_move_to_folder, + account, disabled, + new DialogFolder.IDialogFolder() { @Override public void onFolderSelected(TupleFolderEx folder) { - dialog.dismiss(); onActionMoveSelection(folder.id, id); } }); - - adapter.setDisabled(disabled); - adapter.set(folders); - - rvFolder.setAdapter(adapter); - - rvFolder.setVisibility(View.VISIBLE); - pbWait.setVisibility(View.GONE); - dialog.show(); } private void onActionMoveSelection(long target, Long id) {