Android Open Source - feeligo_android_sdk Feeligo Sticker Store Adapter






From Project

Back to project page feeligo_android_sdk.

License

The source code is released under:

MIT License

If you think the Android project feeligo_android_sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package fr.baloomba.feeligo.store;
/* www  . java  2  s.co  m*/
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.VolleyError;
import fr.baloomba.feeligo.Feeligo;
import fr.baloomba.feeligo.R;
import fr.baloomba.feeligo.helper.ViewHelper;
import fr.baloomba.feeligo.model.StickerPack;
import fr.baloomba.feeligo.widget.FeeligoStickerImageView;
import fr.baloomba.wsvolley.WSStringResponseListener;

import java.util.ArrayList;

public class FeeligoStickerStoreAdapter extends BaseAdapter {

    // <editor-fold desc="VARIABLES">

    private static final String TAG = FeeligoStickerStoreAdapter.class.getSimpleName();

    private static LayoutInflater sInflater;

    private Context mContext;
    private ArrayList<StickerPack> mData;

    // </editor-fold>

    // <editor-fold desc="CONSTRUCTORS">

    public FeeligoStickerStoreAdapter(Context context) {
        sInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mContext = context;
    }

    // </editor-fold>

    // <editor-fold desc="SETTERS">

    public void setData(ArrayList<StickerPack> data) {
        mData = data;
    }

    // </editor-fold>

    // <editor-fold desc="BASE ADAPTER OVERRIDDEN METHODS">

    @Override
    public int getCount() {
        return mData != null ? mData.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return mData.get(position).getId();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = sInflater.inflate(R.layout.cell_sticker_store, parent, false);
            holder = new ViewHolder();
            if (convertView != null) {
                holder.imageView = (FeeligoStickerImageView)convertView
                        .findViewById(R.id.cell_sticker_store_sticker_image_view);
                holder.nameTextView = (TextView)convertView
                        .findViewById(R.id.cell_sticker_store_name_text_view);
                holder.authorTextView = (TextView)convertView
                        .findViewById(R.id.cell_sticker_store_author_text_view);
//                holder.priceTextView = (TextView)convertView
//                        .findViewById(R.id.cell_sticker_store_price_text_view);
                holder.layout = (LinearLayout)convertView
                        .findViewById(R.id.cell_sticker_store_layout);
                holder.button = (RelativeLayout)convertView
                        .findViewById(R.id.cell_sticker_store_button_layout);
                holder.buttonImage = (ImageView)convertView
                        .findViewById(R.id.cell_sticker_store_action_button);
                holder.progressBar = (ProgressBar)convertView
                        .findViewById(R.id.cell_sticker_store_action_progress_bar);
                convertView.setTag(holder);
            }
        } else
            holder = (ViewHolder)convertView.getTag();
        setContent(holder, mData.get(position));
        return convertView;
    }

    // </editor-fold>

    // <editor-fold desc="METHODS">

    private void setContent(final ViewHolder holder, final StickerPack stickerPack) {
        if (stickerPack.getIsLoading()) {
            holder.progressBar.setVisibility(View.VISIBLE);
        } else {
            ViewHelper.setEnabledViewWithAlpha(holder.button, true);
            holder.imageView.setImageUrl(stickerPack.getLogo(mContext));
            holder.nameTextView.setText(stickerPack.getName());
            holder.authorTextView.setText(stickerPack.getAuthor());
            holder.layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (!stickerPack.getIsLoading())
                        goToDetailsActivity(stickerPack);
                }
            });
            holder.progressBar.setVisibility(View.GONE);
            holder.buttonImage.setVisibility(View.VISIBLE);
            if (Feeligo.getInstance().isStickerPackPresent(stickerPack.getId())) {
                holder.buttonImage.setImageResource(R.drawable.ic_remove_pack);
                holder.button.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        stickerPack.setIsLoading(true);
                        holder.buttonImage.setVisibility(View.GONE);
                        holder.progressBar.setVisibility(View.VISIBLE);
                        Feeligo.getInstance().removeStickerPack(stickerPack,
                                new WSStringResponseListener() {
                                    @Override
                                    public void onResponse(String response) {
                                        stickerPack.setIsLoading(false);
                                        notifyDataSetChanged();
                                    }

                                    @Override
                                    public void onErrorResponse(VolleyError error) {
                                        stickerPack.setIsLoading(false);
                                        notifyDataSetChanged();
                                    }
                                }
                        );
                    }
                });
            } else {
                holder.buttonImage.setImageResource(R.drawable.ic_add_pack);
                holder.button.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        stickerPack.setIsLoading(true);
                        holder.buttonImage.setVisibility(View.GONE);
                        holder.progressBar.setVisibility(View.VISIBLE);
                        Feeligo.getInstance().addStickerPack(stickerPack,
                                new WSStringResponseListener() {
                                    @Override
                                    public void onResponse(String response) {
                                        stickerPack.setIsLoading(false);
                                        notifyDataSetChanged();
                                    }

                                    @Override
                                    public void onErrorResponse(VolleyError error) {
                                        stickerPack.setIsLoading(false);
                                        notifyDataSetChanged();
                                    }
                                }
                        );
                    }
                });
            }
        }
    }

    private void goToDetailsActivity(StickerPack stickerPack) {
        Intent intent = new Intent(mContext, FeeligoStickerStoreDetailActivity.class);
        intent.putExtra("sticker_pack", stickerPack);
        mContext.startActivity(intent);
    }

    // </editor-fold>

    // <editor-fold desc="VIEW HOLDER CLASS">

    static class ViewHolder {
        LinearLayout layout;
        FeeligoStickerImageView imageView;
        TextView nameTextView;
        TextView authorTextView;
        ImageView buttonImage;
        RelativeLayout button;
        ProgressBar progressBar;
//        TextView priceTextView;
    }

    // </editor-fold>

}




Java Source Code List

fr.baloomba.feeligo.FeeligoKeyboard.java
fr.baloomba.feeligo.FeeligoLog.java
fr.baloomba.feeligo.Feeligo.java
fr.baloomba.feeligo.helper.ActionBarHelper.java
fr.baloomba.feeligo.helper.DisplayHelper.java
fr.baloomba.feeligo.helper.FeeligoHelper.java
fr.baloomba.feeligo.helper.FeeligoLog.java
fr.baloomba.feeligo.helper.FeeligoSettings.java
fr.baloomba.feeligo.helper.JSONHelper.java
fr.baloomba.feeligo.helper.ViewHelper.java
fr.baloomba.feeligo.keyboard.FeeligoKeyboardGridAdapter.java
fr.baloomba.feeligo.keyboard.FeeligoKeyboardListener.java
fr.baloomba.feeligo.keyboard.FeeligoKeyboardPageAdapter.java
fr.baloomba.feeligo.keyboard.FeeligoKeyboardStickerPackPage.java
fr.baloomba.feeligo.model.StickerImage.java
fr.baloomba.feeligo.model.StickerPack.java
fr.baloomba.feeligo.model.Sticker.java
fr.baloomba.feeligo.model.UserStickerPack.java
fr.baloomba.feeligo.network.RequestBuilder.java
fr.baloomba.feeligo.network.URLBuilder.java
fr.baloomba.feeligo.store.FeeligoStickerStoreActivity.java
fr.baloomba.feeligo.store.FeeligoStickerStoreAdapter.java
fr.baloomba.feeligo.store.FeeligoStickerStoreDetailActivity.java
fr.baloomba.feeligo.store.FeeligoStoreDetailAdapter.java
fr.baloomba.feeligo.widget.FeeligoStickerImageView.java
fr.baloomba.feeligo.widget.FeeligoStickerPackTextView.java