2019-06-30 15:44:53 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
2019-06-30 20:27:49 +00:00
|
|
|
import androidx.appcompat.app.AlertDialog;
|
2019-06-30 15:44:53 +00:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import static android.app.Activity.RESULT_OK;
|
|
|
|
|
2019-07-01 14:27:22 +00:00
|
|
|
public class FragmentDialogFolder extends DialogFragmentEx {
|
2019-06-30 15:44:53 +00:00
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
|
|
|
String title = getArguments().getString("title");
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
rvFolder.setHasFixedSize(false);
|
|
|
|
LinearLayoutManager llm = new LinearLayoutManager(getContext());
|
|
|
|
rvFolder.setLayoutManager(llm);
|
|
|
|
|
|
|
|
rvFolder.setVisibility(View.GONE);
|
|
|
|
pbWait.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("account", getArguments().getLong("account"));
|
|
|
|
|
|
|
|
new SimpleTask<List<TupleFolderEx>>() {
|
|
|
|
@Override
|
|
|
|
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 = new ArrayList<>();
|
|
|
|
|
|
|
|
long account = args.getLong("account");
|
2019-07-01 14:27:22 +00:00
|
|
|
AdapterFolder adapter = new AdapterFolder(getContext(), getActivity(),
|
2019-06-30 18:47:30 +00:00
|
|
|
account, false, new AdapterFolder.IFolderSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void onFolderSelected(TupleFolderEx folder) {
|
|
|
|
dismiss();
|
2019-07-01 12:43:52 +00:00
|
|
|
|
|
|
|
Bundle args = getArguments();
|
|
|
|
args.putLong("folder", folder.id);
|
|
|
|
|
|
|
|
sendResult(RESULT_OK);
|
2019-06-30 18:47:30 +00:00
|
|
|
}
|
|
|
|
});
|
2019-06-30 15:44:53 +00:00
|
|
|
|
|
|
|
rvFolder.setAdapter(adapter);
|
|
|
|
|
|
|
|
adapter.setDisabled(Helper.fromLongArray(getArguments().getLongArray("disabled")));
|
|
|
|
adapter.set(folders);
|
|
|
|
|
|
|
|
pbWait.setVisibility(View.GONE);
|
|
|
|
rvFolder.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
2019-07-01 12:06:15 +00:00
|
|
|
Helper.unexpectedError(getFragmentManager(), ex);
|
2019-06-30 15:44:53 +00:00
|
|
|
}
|
2019-06-30 21:12:36 +00:00
|
|
|
}.execute(getContext(), getActivity(), args, "folder:select");
|
2019-06-30 15:44:53 +00:00
|
|
|
|
|
|
|
return new AlertDialog.Builder(getContext())
|
|
|
|
.setTitle(title)
|
|
|
|
.setView(dview)
|
|
|
|
.create();
|
|
|
|
}
|
|
|
|
}
|