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

Avoid removing history items when updating history #2180

Merged
merged 1 commit into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1236,11 +1234,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 @@ -277,6 +281,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 @@ -292,6 +302,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