Search in sources :

Example 1 with DateSection

use of org.mozilla.focus.history.model.DateSection in project Rocket by mozilla-tw.

the class ScreenshotItemAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
    if (holder instanceof GirdItemViewHolder) {
        final GirdItemViewHolder gridVH = (GirdItemViewHolder) holder;
        gridVH.rootView.setOnClickListener(this);
        final Screenshot item = (Screenshot) mItems.get(position);
        GlideApp.with(mActivity).asBitmap().placeholder(R.drawable.placeholder).fitCenter().load(item.getImageUri()).into(gridVH.img);
    } else if (holder instanceof DateItemViewHolder) {
        final DateSection item = (DateSection) mItems.get(position);
        if (item != null) {
            final DateItemViewHolder dateVH = (DateItemViewHolder) holder;
            dateVH.textDate.setText(DateUtils.getRelativeTimeSpanString(item.getTimestamp(), System.currentTimeMillis(), DateUtils.DAY_IN_MILLIS));
        }
    }
}
Also used : DateSection(org.mozilla.focus.history.model.DateSection) Screenshot(org.mozilla.focus.screenshot.model.Screenshot)

Example 2 with DateSection

use of org.mozilla.focus.history.model.DateSection in project Rocket by mozilla-tw.

the class HistoryItemAdapter method add.

private void add(Object item) {
    if (mItems.size() > 0 && isSameDay(((Site) mItems.get(mItems.size() - 1)).getLastViewTimestamp(), ((Site) item).getLastViewTimestamp())) {
        mItems.add(item);
        notifyItemInserted(mItems.size());
    } else {
        mItems.add(new DateSection(((Site) item).getLastViewTimestamp()));
        mItems.add(item);
        notifyItemRangeInserted(mItems.size() - 2, 2);
    }
    ++mCurrentCount;
}
Also used : Site(org.mozilla.focus.history.model.Site) DateSection(org.mozilla.focus.history.model.DateSection)

Example 3 with DateSection

use of org.mozilla.focus.history.model.DateSection in project Rocket by mozilla-tw.

the class HistoryItemAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
    if (holder instanceof SiteItemViewHolder) {
        final Site item = (Site) mItems.get(position);
        if (item != null) {
            final SiteItemViewHolder siteVH = (SiteItemViewHolder) holder;
            siteVH.rootView.setOnClickListener(this);
            siteVH.textMain.setText(item.getTitle());
            siteVH.textSecondary.setText(item.getUrl());
            String favIconUri = item.getFavIconUri();
            if (favIconUri != null) {
                Glide.with(siteVH.imgFav.getContext()).asBitmap().load(favIconUri).into(new SimpleTarget<Bitmap>() {

                    @Override
                    public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
                        if (DimenUtils.iconTooBlurry(siteVH.imgFav.getResources(), resource.getWidth())) {
                            setImageViewWithDefaultBitmap(siteVH.imgFav, item.getUrl());
                        } else {
                            siteVH.imgFav.setImageBitmap(resource);
                        }
                    }
                });
            } else {
                setImageViewWithDefaultBitmap(siteVH.imgFav, item.getUrl());
            }
            final PopupMenu popupMenu = new PopupMenu(mContext, siteVH.btnMore);
            popupMenu.setOnMenuItemClickListener(menuItem -> {
                if (menuItem.getItemId() == R.id.browsing_history_menu_delete) {
                    BrowsingHistoryManager.getInstance().delete(item.getId(), HistoryItemAdapter.this);
                    TelemetryWrapper.historyRemoveLink();
                    // Delete favicon
                    String uriString = item.getFavIconUri();
                    if (uriString == null) {
                        return false;
                    }
                    final URI fileUri;
                    try {
                        fileUri = new URI(uriString);
                    } catch (URISyntaxException e) {
                        e.printStackTrace();
                        return false;
                    }
                    final Runnable runnable = new FileUtils.DeleteFileRunnable(new File(fileUri));
                    ThreadUtils.postToBackgroundThread(runnable);
                }
                return false;
            });
            popupMenu.inflate(R.menu.menu_browsing_history_option);
            siteVH.btnMore.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    popupMenu.show();
                    TelemetryWrapper.showHistoryContextMenu();
                }
            });
        }
    } else if (holder instanceof DateItemViewHolder) {
        final DateSection item = (DateSection) mItems.get(position);
        if (item != null) {
            final DateItemViewHolder dateVH = (DateItemViewHolder) holder;
            dateVH.textDate.setText(DateUtils.getRelativeTimeSpanString(item.getTimestamp(), System.currentTimeMillis(), DateUtils.DAY_IN_MILLIS));
        }
    }
}
Also used : Site(org.mozilla.focus.history.model.Site) DateSection(org.mozilla.focus.history.model.DateSection) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) SiteItemViewHolder(org.mozilla.focus.site.SiteItemViewHolder) Bitmap(android.graphics.Bitmap) File(java.io.File) PopupMenu(androidx.appcompat.widget.PopupMenu)

Example 4 with DateSection

use of org.mozilla.focus.history.model.DateSection in project Rocket by mozilla-tw.

the class ScreenshotItemAdapter method add.

private void add(Object item) {
    if (mItems.size() > 0 && isSameDay(((Screenshot) mItems.get(mItems.size() - 1)).getTimestamp(), ((Screenshot) item).getTimestamp())) {
        mItems.add(item);
        notifyItemInserted(mItems.size());
    } else {
        mItems.add(new DateSection(((Screenshot) item).getTimestamp()));
        mItems.add(item);
        notifyItemRangeInserted(mItems.size() - 2, 2);
    }
    ++mCurrentCount;
}
Also used : DateSection(org.mozilla.focus.history.model.DateSection) Screenshot(org.mozilla.focus.screenshot.model.Screenshot)

Aggregations

DateSection (org.mozilla.focus.history.model.DateSection)4 Site (org.mozilla.focus.history.model.Site)2 Screenshot (org.mozilla.focus.screenshot.model.Screenshot)2 Bitmap (android.graphics.Bitmap)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 PopupMenu (androidx.appcompat.widget.PopupMenu)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 File (java.io.File)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 SiteItemViewHolder (org.mozilla.focus.site.SiteItemViewHolder)1