2021-02-13 07:49:57 +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/>.
|
|
|
|
|
2022-01-01 08:46:36 +00:00
|
|
|
Copyright 2018-2022 by Marcel Bokhorst (M66B)
|
2021-02-13 07:49:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import android.app.Dialog;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
|
2022-03-21 15:33:08 +00:00
|
|
|
import java.util.ArrayList;
|
2021-02-13 08:34:38 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
2021-02-13 07:49:57 +00:00
|
|
|
public class FragmentDialogSync extends FragmentDialogBase {
|
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
2021-02-13 08:34:38 +00:00
|
|
|
Bundle args = getArguments();
|
|
|
|
long fid = args.getLong("folder");
|
|
|
|
String name = args.getString("name");
|
|
|
|
String type = args.getString("type");
|
2021-02-13 07:49:57 +00:00
|
|
|
|
|
|
|
View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_sync, null);
|
|
|
|
final TextView tvFolder = view.findViewById(R.id.tvFolder);
|
|
|
|
final EditText etMonths = view.findViewById(R.id.etMonths);
|
2021-08-12 11:29:46 +00:00
|
|
|
final TextView tvRemark = view.findViewById(R.id.tvRemark);
|
2021-02-13 07:49:57 +00:00
|
|
|
|
2021-02-13 08:34:38 +00:00
|
|
|
if (fid < 0) {
|
|
|
|
if (TextUtils.isEmpty(type))
|
|
|
|
tvFolder.setText(R.string.title_folder_unified);
|
|
|
|
else
|
|
|
|
tvFolder.setText(EntityFolder.localizeType(getContext(), type));
|
|
|
|
} else
|
|
|
|
tvFolder.setText(name);
|
|
|
|
|
2022-05-08 05:59:18 +00:00
|
|
|
etMonths.setText("12");
|
2021-02-13 07:49:57 +00:00
|
|
|
|
2021-08-12 11:29:46 +00:00
|
|
|
tvRemark.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
Helper.viewFAQ(view.getContext(), 39);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-02-13 07:49:57 +00:00
|
|
|
return new AlertDialog.Builder(getContext())
|
|
|
|
.setView(view)
|
|
|
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
String months = etMonths.getText().toString();
|
|
|
|
|
|
|
|
Bundle args = getArguments();
|
|
|
|
if (TextUtils.isEmpty(months))
|
|
|
|
args.putInt("months", 0);
|
|
|
|
else
|
|
|
|
try {
|
|
|
|
args.putInt("months", Integer.parseInt(months));
|
|
|
|
} catch (NumberFormatException ex) {
|
|
|
|
Log.e(ex);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void onExecute(Context context, Bundle args) {
|
|
|
|
long fid = args.getLong("folder");
|
2021-02-13 08:34:38 +00:00
|
|
|
String type = args.getString("type");
|
|
|
|
int months = args.getInt("months", -1);
|
2022-03-21 15:33:08 +00:00
|
|
|
boolean children = args.getBoolean("children");
|
2021-02-13 07:49:57 +00:00
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
try {
|
|
|
|
db.beginTransaction();
|
|
|
|
|
2021-02-13 08:34:38 +00:00
|
|
|
List<EntityFolder> folders;
|
|
|
|
if (fid < 0)
|
|
|
|
folders = db.folder().getFoldersUnified(type, false);
|
|
|
|
else {
|
|
|
|
EntityFolder folder = db.folder().getFolder(fid);
|
2021-02-13 13:52:09 +00:00
|
|
|
if (folder == null)
|
2021-02-13 08:34:38 +00:00
|
|
|
return null;
|
2022-03-21 15:33:08 +00:00
|
|
|
|
|
|
|
folders = new ArrayList<>();
|
|
|
|
folders.add(folder);
|
|
|
|
|
|
|
|
if (children) {
|
|
|
|
List<EntityFolder> sub = db.folder().getChildFolders(folder.id);
|
|
|
|
if (sub != null)
|
|
|
|
folders.addAll(sub);
|
|
|
|
}
|
2021-02-13 07:49:57 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 13:52:09 +00:00
|
|
|
for (EntityFolder folder : folders)
|
|
|
|
if (folder.selectable) {
|
|
|
|
if (months == 0) {
|
|
|
|
db.folder().setFolderInitialize(folder.id, Integer.MAX_VALUE);
|
|
|
|
db.folder().setFolderKeep(folder.id, Integer.MAX_VALUE);
|
|
|
|
} else if (months > 0) {
|
|
|
|
db.folder().setFolderInitialize(folder.id, months * 30);
|
|
|
|
db.folder().setFolderKeep(folder.id, Math.max(folder.keep_days, months * 30));
|
|
|
|
}
|
|
|
|
|
|
|
|
EntityOperation.sync(context, folder.id, true);
|
2021-02-13 08:34:38 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 07:49:57 +00:00
|
|
|
db.setTransactionSuccessful();
|
|
|
|
} finally {
|
|
|
|
db.endTransaction();
|
|
|
|
}
|
|
|
|
|
2021-03-27 14:50:39 +00:00
|
|
|
ServiceSynchronize.eval(context, "folder:months");
|
2021-02-13 07:49:57 +00:00
|
|
|
|
2021-03-27 14:50:39 +00:00
|
|
|
return null;
|
2021-03-25 08:36:45 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 07:49:57 +00:00
|
|
|
@Override
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
Log.unexpectedError(getParentFragmentManager(), ex);
|
|
|
|
}
|
|
|
|
}.execute(getContext(), getViewLifecycleOwner(), args, "folder:months");
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
.create();
|
|
|
|
}
|
|
|
|
}
|