mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-02 19:10:11 +01:00
Folder favorite improvements
This commit is contained in:
@@ -211,8 +211,9 @@ public interface DaoFolder {
|
||||
int increaseSelectedCount(long id, long last);
|
||||
|
||||
@Query("UPDATE folder" +
|
||||
" SET selected_last = 0, selected_count = 0")
|
||||
int resetSelectedCount();
|
||||
" SET selected_last = 0, selected_count = 0" +
|
||||
" WHERE account = :account")
|
||||
int resetSelectedCount(long account);
|
||||
|
||||
@Query("SELECT * FROM folder WHERE id = :id")
|
||||
EntityFolder getFolder(Long id);
|
||||
|
||||
@@ -239,10 +239,6 @@ public class EntityOperation {
|
||||
EntityMessage.snooze(context, message.id, null);
|
||||
}
|
||||
|
||||
if (source.account.equals(target.account) &&
|
||||
EntityFolder.USER.equals(target.type))
|
||||
db.folder().increaseSelectedCount(target.id, new Date().getTime());
|
||||
|
||||
if (EntityFolder.JUNK.equals(source.type) && EntityFolder.INBOX.equals(target.type)) {
|
||||
List<EntityRule> rules = db.rule().getRules(target.id);
|
||||
for (EntityRule rule : rules)
|
||||
|
||||
@@ -22,7 +22,6 @@ package eu.faircode.email;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
@@ -47,7 +46,9 @@ import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
|
||||
@@ -56,6 +57,9 @@ public class FragmentDialogFolder extends FragmentDialogBase {
|
||||
|
||||
private static final int MAX_SELECTED_FOLDERS = 5;
|
||||
|
||||
private static final ExecutorService executor =
|
||||
Helper.getBackgroundExecutor(1, "folder");
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
@@ -84,6 +88,7 @@ public class FragmentDialogFolder extends FragmentDialogBase {
|
||||
final TextView tvFavorite1 = dview.findViewById(R.id.tvFavorite1);
|
||||
final TextView tvFavorite2 = dview.findViewById(R.id.tvFavorite2);
|
||||
final TextView tvFavorite3 = dview.findViewById(R.id.tvFavorite3);
|
||||
final ImageButton ibResetFavorites = dview.findViewById(R.id.ibResetFavorites);
|
||||
final RecyclerView rvFolder = dview.findViewById(R.id.rvFolder);
|
||||
final ContentLoadingProgressBar pbWait = dview.findViewById(R.id.pbWait);
|
||||
final Group grpReady = dview.findViewById(R.id.grpReady);
|
||||
@@ -136,6 +141,8 @@ public class FragmentDialogFolder extends FragmentDialogBase {
|
||||
JSONArray jarray = new JSONArray(selected_folders);
|
||||
prefs.edit().putString("selected_folders", jarray.toString()).apply();
|
||||
|
||||
increaseSelectedCount(folder.id, context);
|
||||
|
||||
Bundle args = getArguments();
|
||||
args.putLong("folder", folder.id);
|
||||
|
||||
@@ -147,10 +154,7 @@ public class FragmentDialogFolder extends FragmentDialogBase {
|
||||
tvFavorite1.setVisibility(View.GONE);
|
||||
tvFavorite2.setVisibility(View.GONE);
|
||||
tvFavorite3.setVisibility(View.GONE);
|
||||
|
||||
tvFavorite1.setPaintFlags(tvFavorite1.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
||||
tvFavorite2.setPaintFlags(tvFavorite2.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
||||
tvFavorite3.setPaintFlags(tvFavorite3.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
||||
ibResetFavorites.setVisibility(View.GONE);
|
||||
|
||||
View.OnClickListener listener = new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -159,6 +163,8 @@ public class FragmentDialogFolder extends FragmentDialogBase {
|
||||
if (id == null)
|
||||
return;
|
||||
|
||||
increaseSelectedCount(id, context);
|
||||
|
||||
Bundle args = getArguments();
|
||||
args.putLong("folder", id);
|
||||
|
||||
@@ -170,6 +176,29 @@ public class FragmentDialogFolder extends FragmentDialogBase {
|
||||
tvFavorite2.setOnClickListener(listener);
|
||||
tvFavorite3.setOnClickListener(listener);
|
||||
|
||||
ibResetFavorites.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
tvFavorite1.setVisibility(View.GONE);
|
||||
tvFavorite2.setVisibility(View.GONE);
|
||||
tvFavorite3.setVisibility(View.GONE);
|
||||
ibResetFavorites.setVisibility(View.GONE);
|
||||
|
||||
final DB db = DB.getInstance(context);
|
||||
|
||||
executor.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
db.folder().resetSelectedCount(account);
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
rvFolder.setAdapter(adapter);
|
||||
|
||||
etSearch.addTextChangedListener(new TextWatcher() {
|
||||
@@ -264,9 +293,7 @@ public class FragmentDialogFolder extends FragmentDialogBase {
|
||||
if (data.folders == null || data.folders.size() == 0)
|
||||
tvNoFolder.setVisibility(View.VISIBLE);
|
||||
else {
|
||||
adapter.setDisabled(Helper.fromLongArray(disabled));
|
||||
adapter.set(data.folders);
|
||||
if (data.favorites != null) {
|
||||
if (data.favorites != null && data.favorites.size() > 0) {
|
||||
TextView[] tv = new TextView[]{tvFavorite1, tvFavorite2, tvFavorite3};
|
||||
for (int i = 0; i < data.favorites.size(); i++) {
|
||||
EntityFolder favorite = data.favorites.get(i);
|
||||
@@ -274,7 +301,13 @@ public class FragmentDialogFolder extends FragmentDialogBase {
|
||||
tv[i].setText(favorite.getDisplayName(context));
|
||||
tv[i].setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
ibResetFavorites.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
adapter.setDisabled(Helper.fromLongArray(disabled));
|
||||
adapter.set(data.folders);
|
||||
|
||||
grpReady.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
@@ -293,6 +326,23 @@ public class FragmentDialogFolder extends FragmentDialogBase {
|
||||
.create();
|
||||
}
|
||||
|
||||
private static void increaseSelectedCount(Long id, Context context) {
|
||||
final DB db = DB.getInstance(context);
|
||||
|
||||
executor.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
EntityFolder folder = db.folder().getFolder(id);
|
||||
if (folder != null && EntityFolder.USER.equals(folder.type))
|
||||
db.folder().increaseSelectedCount(folder.id, new Date().getTime());
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static class Data {
|
||||
private List<TupleFolderEx> folders;
|
||||
private List<EntityFolder> favorites;
|
||||
|
||||
@@ -350,6 +350,7 @@ public class FragmentOptions extends FragmentBase {
|
||||
for (String option : options)
|
||||
editor.remove(option);
|
||||
editor.apply();
|
||||
|
||||
ToastEx.makeText(context, R.string.title_setup_done, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
})
|
||||
|
||||
@@ -835,20 +835,6 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
editor.remove(key);
|
||||
editor.apply();
|
||||
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) {
|
||||
DB db = DB.getInstance(context);
|
||||
db.folder().resetSelectedCount();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Log.unexpectedError(getParentFragmentManager(), ex);
|
||||
}
|
||||
}.execute(this, new Bundle(), "reset:questions");
|
||||
|
||||
ToastEx.makeText(getContext(), R.string.title_setup_done, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
android:singleLine="true"
|
||||
android:text="favorite1"
|
||||
android:textAlignment="center"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textColor="?android:attr/textColorLink"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toStartOf="@+id/tvFavorite2"
|
||||
@@ -67,7 +67,7 @@
|
||||
android:singleLine="true"
|
||||
android:text="favorite2"
|
||||
android:textAlignment="center"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textColor="?android:attr/textColorLink"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toStartOf="@+id/tvFavorite3"
|
||||
@@ -84,14 +84,24 @@
|
||||
android:singleLine="true"
|
||||
android:text="favorite3"
|
||||
android:textAlignment="center"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textColor="?android:attr/textColorLink"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/ibResetFavorites"
|
||||
app:layout_constraintHorizontal_chainStyle="spread"
|
||||
app:layout_constraintStart_toEndOf="@id/tvFavorite2"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvNoFolder" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/ibResetFavorites"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:padding="3dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvNoFolder"
|
||||
app:srcCompat="@drawable/twotone_cancel_24" />
|
||||
|
||||
<eu.faircode.email.FixedRecyclerView
|
||||
android:id="@+id/rvFolder"
|
||||
android:layout_width="0dp"
|
||||
|
||||
Reference in New Issue
Block a user