use of org.mozilla.focus.history.model.Site in project Rocket by mozilla-tw.
the class QueryHandler method cursorToSite.
private static Site cursorToSite(Cursor cursor) {
Site site = new Site();
site.setId(cursor.getLong(cursor.getColumnIndex(HistoryContract.BrowsingHistory._ID)));
site.setTitle(cursor.getString(cursor.getColumnIndex(HistoryContract.BrowsingHistory.TITLE)));
site.setUrl(cursor.getString(cursor.getColumnIndex(HistoryContract.BrowsingHistory.URL)));
site.setViewCount(cursor.getLong(cursor.getColumnIndex(HistoryContract.BrowsingHistory.VIEW_COUNT)));
site.setLastViewTimestamp(cursor.getLong(cursor.getColumnIndex(HistoryContract.BrowsingHistory.LAST_VIEW_TIMESTAMP)));
site.setFavIcon(bytesToBitmap(cursor.getBlob(cursor.getColumnIndex(HistoryContract.BrowsingHistory.FAV_ICON))));
return site;
}
use of org.mozilla.focus.history.model.Site in project Rocket by mozilla-tw.
the class TopSitesUtils method paresJsonToList.
public static List<Site> paresJsonToList(Context context, JSONArray jsonArray) {
List<Site> defaultSites = new ArrayList<>();
try {
if (jsonArray != null) {
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject json_site = (JSONObject) jsonArray.get(i);
final Site site = new Site();
site.setId(json_site.getLong("id"));
site.setUrl(json_site.getString("url"));
site.setTitle(json_site.getString("title"));
site.setViewCount(json_site.getLong("viewCount"));
site.setLastViewTimestamp(json_site.getLong("lastViewTimestamp"));
String icon_name = json_site.getString("favicon");
site.setFavIcon(TopSitesUtils.getIconFromAssets(context, icon_name));
defaultSites.add(site);
}
}
} catch (JSONException e) {
e.printStackTrace();
} finally {
return defaultSites;
}
}
use of org.mozilla.focus.history.model.Site in project Rocket by mozilla-tw.
the class HomeFragment method mergeQueryAndDefaultSites.
private void mergeQueryAndDefaultSites(List<Site> querySites) {
// if query data are equal to the default data, merge them
initDefaultSitesFromJSONArray(this.orginalDefaultSites);
List<Site> topSites = new ArrayList<>(this.presenter.getSites());
for (Site topSite : topSites) {
Iterator<Site> querySitesIterator = querySites.iterator();
while (querySitesIterator.hasNext()) {
Site temp = querySitesIterator.next();
if (UrlUtils.urlsMatchExceptForTrailingSlash(topSite.getUrl(), temp.getUrl())) {
topSite.setViewCount(topSite.getViewCount() + temp.getViewCount());
querySitesIterator.remove();
}
}
}
topSites.addAll(querySites);
TopSideComparator topSideComparator = new TopSideComparator();
Collections.sort(topSites, topSideComparator);
if (topSites.size() > TOP_SITES_QUERY_LIMIT) {
List<Site> removeSites = topSites.subList(TOP_SITES_QUERY_LIMIT, topSites.size());
removeDefaultSites(removeSites);
topSites = topSites.subList(0, TOP_SITES_QUERY_LIMIT);
}
this.presenter.setSites(topSites);
this.presenter.populateSites();
}
use of org.mozilla.focus.history.model.Site in project Rocket by mozilla-tw.
the class TopSiteAdapter method removeSite.
public void removeSite(@NonNull Site toRemove) {
for (int i = 0; i < this.sites.size(); i++) {
final Site site = this.sites.get(i);
if (site.getId() == toRemove.getId()) {
this.sites.remove(i);
notifyDataSetChanged();
// notifyItemRemoved(i);
}
}
}
use of org.mozilla.focus.history.model.Site in project Rocket by mozilla-tw.
the class TopSiteAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(SiteViewHolder holder, int position) {
final Site site = sites.get(position);
holder.text.setText(site.getTitle());
holder.img.setImageBitmap(site.getFavIcon());
int dominantColor = FavIconUtils.getDominantColor(site.getFavIcon());
int alpha = (dominantColor & 0xFF000000);
// Add 25% white to dominant Color
int red = addWhiteToColorCode((dominantColor & 0x00FF0000) >> 16, 0.25f) << 16;
int green = addWhiteToColorCode((dominantColor & 0x0000FF00) >> 8, 0.25f) << 8;
int blue = addWhiteToColorCode((dominantColor & 0x000000FF), 0.25f);
ViewCompat.setBackgroundTintList(holder.img, ColorStateList.valueOf(alpha + red + green + blue));
// let click listener knows which site is clicked
holder.itemView.setTag(site);
if (clickListener != null) {
holder.itemView.setOnClickListener(clickListener);
}
if (longClickListener != null) {
holder.itemView.setOnLongClickListener(longClickListener);
}
}
Aggregations