mirror of https://github.com/M66B/FairEmail.git
Remember selected folders
This commit is contained in:
parent
eeef13af3f
commit
2336b264dc
|
@ -21,12 +21,15 @@ package eu.faircode.email;
|
|||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
@ -34,9 +37,14 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
|
@ -44,6 +52,8 @@ import static android.app.Activity.RESULT_OK;
|
|||
public class FragmentDialogFolder extends FragmentDialogBase {
|
||||
private int result = 0;
|
||||
|
||||
private static final int MAX_SELECTED_FOLDERS = 5;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
|
@ -51,22 +61,57 @@ public class FragmentDialogFolder extends FragmentDialogBase {
|
|||
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);
|
||||
List<String> selected_folders = new ArrayList<>();
|
||||
|
||||
final Context context = getContext();
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String json = prefs.getString("selected_folders", "[]");
|
||||
|
||||
try {
|
||||
JSONArray jarray = new JSONArray(json);
|
||||
for (int i = 0; i < jarray.length(); i++)
|
||||
selected_folders.add((String) jarray.get(i));
|
||||
} catch (JSONException ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
|
||||
final View dview = LayoutInflater.from(context).inflate(R.layout.dialog_folder_select, null);
|
||||
final TextView tvNoFolder = dview.findViewById(R.id.tvNoFolder);
|
||||
final EditText etSearch = dview.findViewById(R.id.etSearch);
|
||||
final AutoCompleteTextView etSearch = dview.findViewById(R.id.etSearch);
|
||||
final ImageButton ibNext = dview.findViewById(R.id.ibNext);
|
||||
final RecyclerView rvFolder = dview.findViewById(R.id.rvFolder);
|
||||
final ContentLoadingProgressBar pbWait = dview.findViewById(R.id.pbWait);
|
||||
final Group grpReady = dview.findViewById(R.id.grpReady);
|
||||
|
||||
etSearch.setThreshold(1);
|
||||
etSearch.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
public void onFocusChange(View v, boolean hasFocus) {
|
||||
if (hasFocus)
|
||||
etSearch.showDropDown();
|
||||
}
|
||||
});
|
||||
|
||||
ArrayAdapter<String> frequent =
|
||||
new ArrayAdapter<>(context, R.layout.spinner_item1_dropdown, android.R.id.text1, selected_folders);
|
||||
etSearch.setAdapter(frequent);
|
||||
|
||||
rvFolder.setHasFixedSize(false);
|
||||
final LinearLayoutManager llm = new LinearLayoutManager(getContext());
|
||||
final LinearLayoutManager llm = new LinearLayoutManager(context);
|
||||
rvFolder.setLayoutManager(llm);
|
||||
|
||||
final AdapterFolder adapter = new AdapterFolder(getContext(), getViewLifecycleOwner(),
|
||||
final AdapterFolder adapter = new AdapterFolder(context, getViewLifecycleOwner(),
|
||||
account, false, false, new AdapterFolder.IFolderSelectedListener() {
|
||||
@Override
|
||||
public void onFolderSelected(TupleFolderEx folder) {
|
||||
String name = folder.getDisplayName(context, folder.parent_ref);
|
||||
selected_folders.remove(name);
|
||||
selected_folders.add(0, name);
|
||||
while (selected_folders.size() > MAX_SELECTED_FOLDERS)
|
||||
selected_folders.remove(MAX_SELECTED_FOLDERS);
|
||||
JSONArray jarray = new JSONArray(selected_folders);
|
||||
prefs.edit().putString("selected_folders", jarray.toString()).apply();
|
||||
|
||||
Bundle args = getArguments();
|
||||
args.putLong("folder", folder.id);
|
||||
|
||||
|
@ -126,6 +171,13 @@ public class FragmentDialogFolder extends FragmentDialogBase {
|
|||
}
|
||||
});
|
||||
|
||||
new Handler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
etSearch.clearFocus();
|
||||
}
|
||||
});
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("account", account);
|
||||
|
||||
|
@ -167,7 +219,7 @@ public class FragmentDialogFolder extends FragmentDialogBase {
|
|||
}
|
||||
}.execute(this, args, "folder:select");
|
||||
|
||||
return new AlertDialog.Builder(getContext())
|
||||
return new AlertDialog.Builder(context)
|
||||
.setTitle(title)
|
||||
.setView(dview)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
|
|
|
@ -84,7 +84,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
private final static String[] RESET_QUESTIONS = new String[]{
|
||||
"welcome", "first", "app_support", "notify_archive", "message_swipe", "message_select", "folder_actions", "folder_sync",
|
||||
"crash_reports_asked", "review_asked", "review_later", "why",
|
||||
"reply_hint", "html_always_images", "print_html_confirmed", "move_1_confirmed", "move_n_confirmed",
|
||||
"reply_hint", "html_always_images", "print_html_confirmed",
|
||||
"selected_folders", "move_1_confirmed", "move_n_confirmed",
|
||||
"identities_asked", "cc_bcc", "inline_image_hint", "compose_reference", "send_dialog",
|
||||
"setup_advanced"
|
||||
};
|
||||
|
|
|
@ -17,12 +17,13 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<eu.faircode.email.EditTextPlain
|
||||
<AutoCompleteTextView
|
||||
android:id="@+id/etSearch"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:hint="@string/title_search"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintEnd_toStartOf="@+id/ibNext"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
|
Loading…
Reference in New Issue