Search in sources :

Example 1 with Site

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;
}
Also used : Site(org.mozilla.focus.history.model.Site)

Example 2 with 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;
    }
}
Also used : Site(org.mozilla.focus.history.model.Site) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException)

Example 3 with Site

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();
}
Also used : Site(org.mozilla.focus.history.model.Site) ArrayList(java.util.ArrayList)

Example 4 with Site

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);
        }
    }
}
Also used : Site(org.mozilla.focus.history.model.Site)

Example 5 with Site

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);
    }
}
Also used : Site(org.mozilla.focus.history.model.Site)

Aggregations

Site (org.mozilla.focus.history.model.Site)12 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 JSONException (org.json.JSONException)2 DateSection (org.mozilla.focus.history.model.DateSection)2 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 PopupMenu (android.support.v7.widget.PopupMenu)1 RecyclerView (android.support.v7.widget.RecyclerView)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1 SessionLoadedIdlingResource (org.mozilla.focus.helper.SessionLoadedIdlingResource)1