Search in sources :

Example 1 with UILImageGetter

use of in.testpress.testpress.util.UILImageGetter in project android by testpress.

the class CommentsListAdapter method onBindViewHolder.

@SuppressLint({ "SetTextI18n", "DefaultLocale" })
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
    if (viewHolder instanceof CommentsViewHolder) {
        final CommentsViewHolder holder = (CommentsViewHolder) viewHolder;
        Comment comment = comments.get(position);
        imageLoader.displayImage(comment.getUser().getMediumImage(), holder.userImage, options);
        if (comment.getUser().getMediumImage().isEmpty()) {
            holder.userImage.setColorFilter(Color.parseColor("#888888"));
        } else {
            holder.userImage.clearColorFilter();
        }
        holder.userName.setText(comment.getUser().getDisplayName());
        Spanned htmlSpan = Html.fromHtml(comment.getComment(), new UILImageGetter(holder.comment, activity), null);
        ZoomableImageString zoomableImageQuestion = new ZoomableImageString(activity);
        holder.comment.setText(zoomableImageQuestion.convertString(htmlSpan));
        holder.comment.setMovementMethod(LinkMovementMethod.getInstance());
        updateTimeSpan(comment, holder);
        holder.userName.setTypeface(TestpressSdk.getRubikMediumFont(activity));
        ViewUtils.setTypeface(new TextView[] { holder.submitDate, holder.comment }, TestpressSdk.getRubikRegularFont(activity));
    }
}
Also used : Comment(in.testpress.testpress.models.Comment) UILImageGetter(in.testpress.testpress.util.UILImageGetter) ZoomableImageString(in.testpress.testpress.util.ZoomableImageString) Spanned(android.text.Spanned) SuppressLint(android.annotation.SuppressLint)

Example 2 with UILImageGetter

use of in.testpress.testpress.util.UILImageGetter in project android by testpress.

the class ProductDetailsActivity method onLoadFinished.

public void onLoadFinished(final Loader<ProductDetails> loader, final ProductDetails productDetails) {
    if (productDetails == null) {
        // noinspection ThrowableResultOfMethodCallIgnored
        Exception exception = ((ThrowableLoader<ProductDetails>) loader).clearException();
        exception.printStackTrace();
        if (exception.getMessage() != null && exception.getMessage().equals("404 NOT FOUND")) {
            gotoMainActivity();
        } else if (exception.getCause() instanceof IOException) {
            setEmptyText(R.string.network_error, R.string.no_internet_try_again, R.drawable.ic_error_outline_black_18dp);
        } else {
            setEmptyText(R.string.error_loading_products, R.string.try_after_sometime, R.drawable.ic_error_outline_black_18dp);
        }
        progressBar.setVisibility(View.GONE);
        return;
    }
    progressBar.setVisibility(View.GONE);
    productDetailsView.setVisibility(View.VISIBLE);
    FormatDate date = new FormatDate();
    ImageLoader imageLoader = ImageLoader.getInstance();
    DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisc(true).resetViewBeforeLoading(true).showImageForEmptyUri(R.drawable.icon).showImageOnFail(R.drawable.icon).showImageOnLoading(R.drawable.icon).build();
    // download and display image from url
    imageLoader.displayImage(productDetails.getImages()[0].getOriginal(), image, options);
    titleText.setText(productDetails.getTitle());
    try {
        if (Float.parseFloat(productDetails.getPrice()) == 0) {
            buyButton.setText("Start Now - Free");
        }
    } catch (Exception e) {
    }
    if (productDetails.getExams().size() != 0) {
        totalExams.setText(productDetails.getExams().size() + " Exams");
        totalExamsContainer.setVisibility(View.VISIBLE);
    } else {
        totalExamsContainer.setVisibility(View.GONE);
    }
    if (productDetails.getNotes().size() != 0) {
        totalNotes.setText(productDetails.getNotes().size() + " Documents");
        totalNotesContainer.setVisibility(View.VISIBLE);
    } else {
        totalNotesContainer.setVisibility(View.GONE);
    }
    if (date.getDate(productDetails.getStartDate(), productDetails.getEndDate()) != null) {
        dateText.setVisibility(View.VISIBLE);
        dateText.setText(date.getDate(productDetails.getStartDate(), productDetails.getEndDate()));
    }
    // Price & Categories
    String categories = Arrays.toString(productDetails.getCategories().toArray());
    categoriesText.setText(categories.substring(1, categories.length() - 1));
    priceText.setText(productDetails.getPrice());
    // Update product description
    if (productDetails.getDescription().isEmpty()) {
        descriptionContainer.setVisibility(View.GONE);
    } else {
        descriptionContainer.setVisibility(View.VISIBLE);
        Spanned html = Html.fromHtml(productDetails.getDescription(), new UILImageGetter(descriptionText, this), null);
        ZoomableImageString zoomableImageHtml = new ZoomableImageString(this);
        descriptionText.setText(zoomableImageHtml.convertString(html), TextView.BufferType.SPANNABLE);
        descriptionText.setMovementMethod(LinkMovementMethod.getInstance());
        descriptionText.setVisibility(View.VISIBLE);
    }
    // Update exams list
    if (productDetails.getExams().isEmpty()) {
        examsListContainer.setVisibility(View.GONE);
    } else {
        examsListContainer.setVisibility(View.VISIBLE);
        examsListView.setFocusable(false);
        examsListView.setAdapter(new ProductExamsAdapter(this.getApplicationContext(), productDetails.getExams()));
        setListViewHeightBasedOnChildren(examsListView);
    }
    // Update notes list
    if (productDetails.getNotes().isEmpty()) {
        notesListContainer.setVisibility(View.GONE);
    } else {
        notesListContainer.setVisibility(View.VISIBLE);
        notesListView.setFocusable(false);
        notesListView.setAdapter(new NotesListAdapter(this.getLayoutInflater(), productDetails.getNotes(), R.layout.product_notes_list_item));
        setListViewHeightBasedOnChildren(notesListView);
    }
    this.productDetails = productDetails;
}
Also used : UILImageGetter(in.testpress.testpress.util.UILImageGetter) IOException(java.io.IOException) ZoomableImageString(in.testpress.testpress.util.ZoomableImageString) Spanned(android.text.Spanned) IOException(java.io.IOException) FormatDate(in.testpress.testpress.util.FormatDate) ZoomableImageString(in.testpress.testpress.util.ZoomableImageString) ImageLoader(com.nostra13.universalimageloader.core.ImageLoader) DisplayImageOptions(com.nostra13.universalimageloader.core.DisplayImageOptions)

Aggregations

Spanned (android.text.Spanned)2 UILImageGetter (in.testpress.testpress.util.UILImageGetter)2 ZoomableImageString (in.testpress.testpress.util.ZoomableImageString)2 SuppressLint (android.annotation.SuppressLint)1 DisplayImageOptions (com.nostra13.universalimageloader.core.DisplayImageOptions)1 ImageLoader (com.nostra13.universalimageloader.core.ImageLoader)1 Comment (in.testpress.testpress.models.Comment)1 FormatDate (in.testpress.testpress.util.FormatDate)1 IOException (java.io.IOException)1