2018-10-24 09:09:07 +00:00
|
|
|
package eu.faircode.email;
|
|
|
|
|
|
2018-10-29 08:09:56 +00:00
|
|
|
/*
|
|
|
|
|
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.
|
|
|
|
|
|
2018-10-29 10:46:49 +00:00
|
|
|
FairEmail is distributed in the hope that it will be useful,
|
2018-10-29 08:09:56 +00:00
|
|
|
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
|
2018-10-29 10:46:49 +00:00
|
|
|
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
2018-10-29 08:09:56 +00:00
|
|
|
|
|
|
|
|
Copyright 2018 by Marcel Bokhorst (M66B)
|
|
|
|
|
*/
|
|
|
|
|
|
2018-10-24 09:09:07 +00:00
|
|
|
import androidx.annotation.NonNull;
|
2018-10-24 15:18:01 +00:00
|
|
|
import androidx.paging.PagedList;
|
2018-10-24 09:09:07 +00:00
|
|
|
import androidx.recyclerview.selection.SelectionTracker;
|
2018-10-24 15:18:01 +00:00
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
2018-10-24 09:09:07 +00:00
|
|
|
|
|
|
|
|
public class SelectionPredicateMessage extends SelectionTracker.SelectionPredicate<Long> {
|
2018-10-24 15:18:01 +00:00
|
|
|
private RecyclerView recyclerView;
|
2018-11-23 08:53:18 +01:00
|
|
|
private long account = -1;
|
2018-10-24 15:18:01 +00:00
|
|
|
|
|
|
|
|
SelectionPredicateMessage(RecyclerView recyclerView) {
|
|
|
|
|
this.recyclerView = recyclerView;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-23 08:53:18 +01:00
|
|
|
void clearAccount() {
|
|
|
|
|
account = -1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-24 09:09:07 +00:00
|
|
|
@Override
|
|
|
|
|
public boolean canSetStateForKey(@NonNull Long key, boolean nextState) {
|
2018-10-24 15:18:01 +00:00
|
|
|
AdapterMessage adapter = (AdapterMessage) recyclerView.getAdapter();
|
|
|
|
|
PagedList<TupleMessageEx> messages = adapter.getCurrentList();
|
|
|
|
|
if (messages != null)
|
|
|
|
|
for (int i = 0; i < messages.size(); i++) {
|
|
|
|
|
TupleMessageEx message = messages.get(i);
|
2018-11-23 08:53:18 +01:00
|
|
|
if (message != null && message.id.equals(key)) {
|
|
|
|
|
if (message.uid != null && (account < 0 || account == message.account)) {
|
|
|
|
|
account = message.account;
|
|
|
|
|
return true;
|
|
|
|
|
} else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-10-24 15:18:01 +00:00
|
|
|
}
|
|
|
|
|
return false;
|
2018-10-24 09:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canSetStateAtPosition(int position, boolean nextState) {
|
2018-10-24 15:18:01 +00:00
|
|
|
AdapterMessage adapter = (AdapterMessage) recyclerView.getAdapter();
|
2018-11-23 08:53:18 +01:00
|
|
|
PagedList<TupleMessageEx> messages = adapter.getCurrentList();
|
|
|
|
|
if (messages != null) {
|
|
|
|
|
TupleMessageEx message = messages.get(position);
|
2018-12-02 17:40:43 +01:00
|
|
|
if (message != null) {
|
|
|
|
|
if (message.uid != null && (account < 0 || account == message.account)) {
|
|
|
|
|
account = message.account;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-11-23 08:53:18 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2018-10-24 09:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canSelectMultiple() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|