X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Futils%2FObservableList.java;h=9e44faef76d1578a05d1f8409854ab58ed1575b2;hp=9893c5d1250644fe9899e0c3721ae8a8c8376f19;hb=83cac114e375728080194fb09758b49c50a8119b;hpb=0700200b6627f97ac37083fc2c7131bcaa39b635 diff --git a/app/src/main/java/net/ktnx/mobileledger/utils/ObservableList.java b/app/src/main/java/net/ktnx/mobileledger/utils/ObservableList.java index 9893c5d1..9e44faef 100644 --- a/app/src/main/java/net/ktnx/mobileledger/utils/ObservableList.java +++ b/app/src/main/java/net/ktnx/mobileledger/utils/ObservableList.java @@ -1,26 +1,24 @@ /* * Copyright © 2019 Damyan Ivanov. - * This file is part of Mobile-Ledger. - * Mobile-Ledger is free software: you can distribute it and/or modify it + * This file is part of MoLe. + * MoLe is free software: you can distribute it and/or modify it * under the term of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your opinion), any later version. * - * Mobile-Ledger is distributed in the hope that it will be useful, + * MoLe 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 terms for details. * * You should have received a copy of the GNU General Public License - * along with Mobile-Ledger. If not, see . + * along with MoLe. If not, see . */ package net.ktnx.mobileledger.utils; import android.os.Build; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.annotation.RequiresApi; +import android.util.Log; import java.util.Collection; import java.util.Comparator; @@ -34,7 +32,11 @@ import java.util.function.Predicate; import java.util.function.UnaryOperator; import java.util.stream.Stream; -public class ObservableList extends Observable { +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.RequiresApi; + +public class ObservableList extends Observable implements List { private List list; public ObservableList(List list) { this.list = list; @@ -43,9 +45,9 @@ public class ObservableList extends Observable { setChanged(); notifyObservers(); } - private void forceNotify(Object arg) { + private void forceNotify(int index) { setChanged(); - notifyObservers(arg); + notifyObservers(index); } public int size() { return list.size(); @@ -56,6 +58,7 @@ public class ObservableList extends Observable { public boolean contains(@Nullable Object o) { return list.contains(o); } + @NonNull public Iterator iterator() { return list.iterator(); } @@ -75,6 +78,9 @@ public class ObservableList extends Observable { if (result) forceNotify(); return result; } + public T removeQuietly(int index) { + return list.remove(index); + } public boolean containsAll(@NonNull Collection c) { return list.containsAll(c); } @@ -88,6 +94,9 @@ public class ObservableList extends Observable { if (result) forceNotify(); return result; } + public boolean addAllQuietly(int index, Collection c) { + return list.addAll(index, c); + } public boolean removeAll(@NonNull Collection c) { boolean result = list.removeAll(c); if (result) forceNotify(); @@ -167,11 +176,23 @@ public class ObservableList extends Observable { public void forEach(Consumer action) { list.forEach(action); } + public List getList() { + return list; + } public void setList(List aList) { list = aList; forceNotify(); } - public Iterable getList() { - return list; + public void triggerItemChangedNotification(T item) { + int index = list.indexOf(item); + if (index == -1) { + Log.d("ObList", "??? not sending notifications for item not found in the list"); + return; + } + Log.d("ObList", "Notifying item change observers"); + triggerItemChangedNotification(index); + } + public void triggerItemChangedNotification(int index) { + forceNotify(index); } } \ No newline at end of file