FairEmail/app/src/main/java/eu/faircode/email/FragmentDialogFolder.java

118 lines
4.2 KiB
Java
Raw Normal View History

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 <http://www.gnu.org/licenses/>.
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;
2019-07-27 16:37:29 +00:00
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
2019-06-30 20:27:49 +00:00
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import static android.app.Activity.RESULT_OK;
2019-09-11 19:43:27 +00:00
public class FragmentDialogFolder extends FragmentDialogBase {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
2019-07-30 17:22:28 +00:00
final String title = getArguments().getString("title");
final long account = getArguments().getLong("account");
final long[] disabled = getArguments().getLongArray("disabled");
final View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_folder_select, null);
2019-07-27 16:37:29 +00:00
final TextView tvNoFolder = dview.findViewById(R.id.tvNoFolder);
final RecyclerView rvFolder = dview.findViewById(R.id.rvFolder);
final ContentLoadingProgressBar pbWait = dview.findViewById(R.id.pbWait);
rvFolder.setHasFixedSize(false);
LinearLayoutManager llm = new LinearLayoutManager(getContext());
rvFolder.setLayoutManager(llm);
2019-09-11 12:03:59 +00:00
final AdapterFolder adapter = new AdapterFolder(getContext(), getViewLifecycleOwner(),
2019-10-03 13:57:21 +00:00
account, false, false, new AdapterFolder.IFolderSelectedListener() {
2019-07-30 17:22:28 +00:00
@Override
public void onFolderSelected(TupleFolderEx folder) {
Bundle args = getArguments();
args.putLong("folder", folder.id);
sendResult(RESULT_OK);
dismiss();
}
});
rvFolder.setAdapter(adapter);
Bundle args = new Bundle();
2019-07-30 17:22:28 +00:00
args.putLong("account", account);
new SimpleTask<List<TupleFolderEx>>() {
@Override
2019-07-27 16:37:29 +00:00
protected void onPreExecute(Bundle args) {
tvNoFolder.setVisibility(View.GONE);
rvFolder.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE);
}
@Override
protected void onPostExecute(Bundle args) {
pbWait.setVisibility(View.GONE);
}
@Override
2019-07-31 06:51:18 +00:00
protected List<TupleFolderEx> 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<TupleFolderEx> folders) {
if (folders == null || folders.size() == 0)
2019-07-27 16:37:29 +00:00
tvNoFolder.setVisibility(View.VISIBLE);
else {
2019-07-30 17:22:28 +00:00
adapter.setDisabled(Helper.fromLongArray(disabled));
adapter.set(folders);
2019-07-30 20:23:53 +00:00
rvFolder.setVisibility(View.VISIBLE);
2019-07-27 16:37:29 +00:00
}
}
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(getParentFragmentManager(), ex);
}
2019-09-11 12:03:59 +00:00
}.execute(this, args, "folder:select");
return new AlertDialog.Builder(getContext())
.setTitle(title)
.setView(dview)
2019-09-12 11:23:32 +00:00
.setNegativeButton(android.R.string.cancel, null)
.create();
}
}