Skip to content

Commit

Permalink
Added logs and handle CompletableFutures exception
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Aug 19, 2019
1 parent b41a82c commit c1e5d2e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.mozilla.vrbrowser.search.suggestions;

import android.content.Context;
import android.util.Log;

import androidx.annotation.NonNull;

Expand All @@ -17,6 +18,8 @@

public class SuggestionsProvider {

private static final String LOGTAG = SuggestionsProvider.class.getSimpleName();

public class DefaultSuggestionsComparator implements Comparator {

public int compare(Object obj1, Object obj2) {
Expand Down Expand Up @@ -90,6 +93,11 @@ public CompletableFuture<List<SuggestionItem>> getBookmarkSuggestions(@NonNull L
items.sort(mComparator);
}
future.complete(items);

}).exceptionally(th -> {
Log.e(LOGTAG, "Error getting bookmarks suggestions: " + th.getLocalizedMessage());
future.complete(items);
return null;
});

return future;
Expand All @@ -111,6 +119,11 @@ public CompletableFuture<List<SuggestionItem>> getHistorySuggestions(@NonNull fi
items.sort(mComparator);
}
future.complete(items);

}).exceptionally(th -> {
Log.e(LOGTAG, "Error getting history suggestions: " + th.getLocalizedMessage());
future.complete(items);
return null;
});

return future;
Expand Down Expand Up @@ -152,6 +165,11 @@ public CompletableFuture<List<SuggestionItem>> getSearchEngineSuggestions(@NonNu
items.sort(mComparator);
}
future.complete(items);

}).exceptionally(th -> {
Log.e(LOGTAG, "Error getting search engine suggestions: " + th.getLocalizedMessage());
future.complete(items);
return null;
});

return future;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.text.TextWatcher;
import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.GestureDetector;
import android.view.MotionEvent;
Expand Down Expand Up @@ -52,6 +53,9 @@
import mozilla.components.ui.autocomplete.InlineAutocompleteEditText;

public class NavigationURLBar extends FrameLayout {

private static final String LOGTAG = NavigationURLBar.class.getSimpleName();

private InlineAutocompleteEditText mURL;
private UIButton mMicrophoneButton;
private UIButton mUAModeButton;
Expand Down Expand Up @@ -255,7 +259,10 @@ private void handleBookmarkClick() {
bookmarkStore.deleteBookmarkByURL(url);
setBookmarked(false);
}
}, mUIThreadExecutor);
}, mUIThreadExecutor).exceptionally(th -> {
Log.e(LOGTAG, "Error getting bookmarks: " + th.getLocalizedMessage());
return null;
});

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class NavigationBarWidget extends UIWidget implements GeckoSession.Naviga
SharedPreferences.OnSharedPreferenceChangeListener, SuggestionsWidget.URLBarPopupDelegate,
BookmarkListener, TrayListener {

private static final String LOGTAG = "VRB";
private static final String LOGTAG = NavigationBarWidget.class.getSimpleName();

private AudioEngine mAudio;
private UIButton mBackButton;
Expand Down Expand Up @@ -900,7 +900,10 @@ public void OnShowSearchPopup() {
mPopup.show(CLEAR_FOCUS);
}

}, new UIThreadExecutor());
}, new UIThreadExecutor()).exceptionally(th -> {
Log.e(LOGTAG, "Error getting suggestions: " + th.getLocalizedMessage());
return null;
});
}

@Override
Expand Down

0 comments on commit c1e5d2e

Please sign in to comment.