Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Avoid removing history items when updating history (#2180)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo authored and bluemarvin committed Nov 6, 2019
1 parent 700cadc commit 8c76cb1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Surface;
Expand Down Expand Up @@ -47,7 +46,6 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.LinkedList;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

Expand Down Expand Up @@ -1239,11 +1237,9 @@ public void onHistoryStateChange(@NonNull GeckoSession aSession, @NonNull GeckoS

} else {
mQueuedCalls.add(() -> {
new Handler(mContext.getMainLooper()).postDelayed(() -> {
if (mHistoryDelegate != null) {
mHistoryDelegate.onHistoryStateChange(aSession, historyList);
}
}, 100);
if (mHistoryDelegate != null) {
mHistoryDelegate.onHistoryStateChange(aSession, historyList);
}
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@
import java.util.Comparator;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import mozilla.components.concept.storage.VisitInfo;
Expand Down Expand Up @@ -286,6 +290,12 @@ public void onAuthenticationProblems() {
}
};

@NotNull
public static <T> Predicate<T> distinctByUrl(Function<? super T, ?> keyExtractor) {
Set<Object> seen = ConcurrentHashMap.newKeySet();
return t -> seen.add(keyExtractor.apply(t));
}

private void updateHistory() {
Calendar date = new GregorianCalendar();
date.set(Calendar.HOUR_OF_DAY, 0);
Expand All @@ -301,6 +311,7 @@ private void updateHistory() {
List<VisitInfo> orderedItems = items.stream()
.sorted(Comparator.comparing(VisitInfo::getVisitTime)
.reversed())
.filter(distinctByUrl(VisitInfo::getUrl))
.collect(Collectors.toList());

addSection(orderedItems, getResources().getString(R.string.history_section_today), Long.MAX_VALUE, todayLimit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1575,15 +1575,9 @@ public GeckoResult<Boolean> onVisited(@NonNull GeckoSession geckoSession, @NonNu
}
}

SessionStore.get().getHistoryStore().deleteVisitsFor(url).thenAcceptAsync(result -> {
SessionStore.get().getHistoryStore().recordVisit(url, pageVisit);
SessionStore.get().getHistoryStore().recordObservation(url, new PageObservation(url));
SessionStore.get().getHistoryStore().recordVisit(url, pageVisit);
SessionStore.get().getHistoryStore().recordObservation(url, new PageObservation(url));

}, mUIThreadExecutor).exceptionally(throwable -> {
Log.d(LOGTAG, "Error deleting history: " + throwable.getLocalizedMessage());
throwable.printStackTrace();
return null;
});
return GeckoResult.fromValue(true);
}

Expand Down

0 comments on commit 8c76cb1

Please sign in to comment.