Experiment: show last selected folder

pull/194/merge
M66B 3 years ago
parent 982b156a20
commit 16d016df6e

@ -57,10 +57,12 @@ import androidx.constraintlayout.widget.Group;
import androidx.core.content.pm.ShortcutInfoCompat;
import androidx.core.content.pm.ShortcutManagerCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.OnLifecycleEvent;
import androidx.lifecycle.ViewModelProvider;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.DiffUtil;
@ -95,6 +97,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
private Context context;
private LifecycleOwner owner;
private LayoutInflater inflater;
private ViewModelSelected selectedModel;
private boolean subscriptions;
@ -105,6 +108,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
private int textColorSecondary;
private int colorUnread;
private int colorControlNormal;
private int colorSeparator;
private String search = null;
private List<Long> disabledIds = new ArrayList<>();
@ -226,6 +230,10 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
view.setEnabled(!disabled);
view.setAlpha(folder.hide || disabled ? Helper.LOW_LIGHT : 1.0f);
if (listener == null && selectedModel != null)
view.setBackgroundColor(selectedModel.isSelected(folder.id)
? colorSeparator : Color.TRANSPARENT);
if (textSize != 0)
tvName.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
@ -425,6 +433,9 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
return;
if (listener == null) {
if (selectedModel != null)
selectedModel.select(folder.id);
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_MESSAGES)
@ -1154,6 +1165,9 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
this.context = context;
this.owner = owner;
this.inflater = LayoutInflater.from(context);
if (context instanceof FragmentActivity)
this.selectedModel = new ViewModelProvider((FragmentActivity) context)
.get(ViewModelSelected.class);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean compact = prefs.getBoolean("compact", false);
@ -1176,6 +1190,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
int colorHighlight = prefs.getInt("highlight_color", Helper.resolveColor(context, R.attr.colorUnreadHighlight));
this.colorUnread = (highlight_unread ? colorHighlight : Helper.resolveColor(context, R.attr.colorUnread));
this.colorControlNormal = Helper.resolveColor(context, R.attr.colorControlNormal);
this.colorSeparator = Helper.resolveColor(context, R.attr.colorSeparator);
setHasStableIds(true);

@ -60,6 +60,7 @@ import androidx.core.view.MenuCompat;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
@ -408,6 +409,9 @@ public class FragmentFolders extends FragmentBase {
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (BuildConfig.DEBUG)
new ViewModelProvider(getActivity()).get(ViewModelSelected.class);
if (savedInstanceState != null)
searching = savedInstanceState.getString("fair:searching");
adapter.search(searching);

@ -0,0 +1,40 @@
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-2022 by Marcel Bokhorst (M66B)
*/
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
public class ViewModelSelected extends ViewModel {
private final MutableLiveData<Long> selectedItem = new MutableLiveData<>();
public void select(Long selected) {
selectedItem.setValue(selected);
}
public LiveData<Long> liveSelected() {
return selectedItem;
}
public boolean isSelected(long id) {
return Long.valueOf(id).equals(selectedItem.getValue());
}
}
Loading…
Cancel
Save