Added apply to all user folders

pull/163/head
M66B 5 years ago
parent c6ff0f3149
commit 4ce024991a

@ -263,6 +263,13 @@ public interface DaoFolder {
boolean synchronize, boolean poll, boolean download,
int sync_days, int keep_days, boolean auto_delete);
@Query("UPDATE folder" +
" SET `sync_days` = :sync_days" +
", `keep_days` = :keep_days" +
" WHERE account = :account" +
" AND type = '" + EntityFolder.USER + "'")
int setFolderProperties(long account, int sync_days, int keep_days);
@Query("UPDATE folder SET keywords = :keywords WHERE id = :id")
int setFolderKeywords(long id, String keywords);

@ -19,7 +19,9 @@ package eu.faircode.email;
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
@ -32,11 +34,15 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.constraintlayout.widget.Group;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentTransaction;
@ -401,6 +407,8 @@ public class FragmentFolders extends FragmentBase {
public void onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_compact).setChecked(compact);
menu.findItem(R.id.menu_show_hidden).setChecked(show_hidden);
menu.findItem(R.id.menu_apply_all).setVisible(account >= 0);
super.onPrepareOptionsMenu(menu);
}
@ -413,6 +421,9 @@ public class FragmentFolders extends FragmentBase {
case R.id.menu_show_hidden:
onMenuShowHidden();
return true;
case R.id.menu_apply_all:
onMenuApplyToAll();
return true;
default:
return super.onOptionsItemSelected(item);
}
@ -434,6 +445,15 @@ public class FragmentFolders extends FragmentBase {
adapter.setShowHidden(show_hidden);
}
private void onMenuApplyToAll() {
Bundle args = new Bundle();
args.putLong("account", account);
FragmentDialogApply fragment = new FragmentDialogApply();
fragment.setArguments(args);
fragment.show(getParentFragmentManager(), "folders:apply");
}
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
@ -596,4 +616,62 @@ public class FragmentFolders extends FragmentBase {
}
}.execute(this, args, "folder:delete");
}
public static class FragmentDialogApply extends FragmentDialogBase {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_folder_all, null);
final EditText etSyncDays = view.findViewById(R.id.etSyncDays);
final EditText etKeepDays = view.findViewById(R.id.etKeepDays);
final CheckBox cbKeepAll = view.findViewById(R.id.cbKeepAll);
cbKeepAll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
etKeepDays.setEnabled(!isChecked);
}
});
return new AlertDialog.Builder(getContext())
.setView(view)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Bundle args = getArguments();
args.putString("sync", etSyncDays.getText().toString());
args.putString("keep", cbKeepAll.isChecked()
? Integer.toString(Integer.MAX_VALUE)
: etKeepDays.getText().toString());
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) throws Throwable {
long account = args.getLong("account");
String sync = args.getString("sync");
String keep = args.getString("keep");
if (TextUtils.isEmpty(sync))
sync = "7";
if (TextUtils.isEmpty(keep))
keep = "30";
DB db = DB.getInstance(context);
db.folder().setFolderProperties(
account, Integer.parseInt(sync), Integer.parseInt(keep));
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(FragmentDialogApply.this, args, "folders:all");
}
})
.setNegativeButton(android.R.string.cancel, null)
.create();
}
}
}

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="24dp">
<TextView
android:id="@+id/tvCaption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:labelFor="@+id/etLink"
android:text="@string/title_apply_to_all"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_folder_user"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvCaption" />
<TextView
android:id="@+id/tvSyncDays"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_sync_days"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvUser" />
<EditText
android:id="@+id/etSyncDays"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="7"
android:inputType="number"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSyncDays" />
<TextView
android:id="@+id/tvKeepDays"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_keep_days"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etSyncDays" />
<EditText
android:id="@+id/etKeepDays"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="30"
android:inputType="number"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvKeepDays" />
<CheckBox
android:id="@+id/cbKeepAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_keep_all"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etKeepDays" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -20,4 +20,9 @@
android:checkable="true"
android:title="@string/title_show_folders"
app:showAsAction="never" />
<item
android:id="@+id/menu_apply_all"
android:title="@string/title_apply_to_all"
app:showAsAction="never" />
</menu>

@ -475,6 +475,7 @@
<string name="title_folder_name">Folder name</string>
<string name="title_display_name">Display name</string>
<string name="title_show_folders">Show hidden folders</string>
<string name="title_apply_to_all">Apply to all &#8230;</string>
<string name="title_hide_folder">Hide folder</string>
<string name="title_unified_folder">Show in unified inbox</string>
<string name="title_navigation_folder">Show in navigation menu</string>

Loading…
Cancel
Save