162 lines
5.7 KiB
Java
162 lines
5.7 KiB
Java
package com.yunbao.share.adapters;
|
|
|
|
import android.content.Context;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.ImageView;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.annotation.DrawableRes;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.StringRes;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import com.pdlive.shayu.R;
|
|
import com.yunbao.share.ICallback;
|
|
import com.yunbao.share.bean.ShareBean;
|
|
import com.yunbao.share.platform.FacebookShare;
|
|
import com.yunbao.share.platform.Instagram;
|
|
import com.yunbao.share.platform.Internal;
|
|
import com.yunbao.share.platform.Line;
|
|
import com.yunbao.share.platform.MessengerShare;
|
|
import com.yunbao.share.platform.TwitterShare;
|
|
import com.yunbao.share.platform.WhatsApp;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class ShareAppAdapter extends RecyclerView.Adapter<ShareAppAdapter.AppViewHolder> {
|
|
private Context mContext;
|
|
private List<ShareBean> list;
|
|
ShareCallback shareCallback;
|
|
|
|
private onShareListener onShareListener;
|
|
|
|
public ShareAppAdapter.onShareListener getOnShareListener() {
|
|
return onShareListener;
|
|
}
|
|
|
|
public void setOnShareListener(ShareAppAdapter.onShareListener onShareListener) {
|
|
this.onShareListener = onShareListener;
|
|
}
|
|
|
|
public ShareAppAdapter(Context mContext) {
|
|
list = new ArrayList<>();
|
|
this.mContext = mContext;
|
|
}
|
|
|
|
public void setList(List<ShareBean> list) {
|
|
this.list = list;
|
|
notifyDataSetChanged();
|
|
}
|
|
|
|
@NonNull
|
|
@Override
|
|
public AppViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
return new AppViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_share_app, parent, false));
|
|
}
|
|
|
|
@Override
|
|
public void onBindViewHolder(@NonNull AppViewHolder holder, int position) {
|
|
ShareBean builder = list.get(position);
|
|
System.out.println("------type------>" + builder.getType());
|
|
switch (builder.getType()) {
|
|
case ShareBean.APP_FACEBOOK:
|
|
holder.setData(builder, R.mipmap.icon_share_facebook, R.string.dialog_share_app_facebook);
|
|
break;
|
|
case ShareBean.APP_LINE:
|
|
holder.setData(builder, R.mipmap.icon_share_line, R.string.dialog_share_app_line);
|
|
break;
|
|
case ShareBean.APP_TWITTER:
|
|
holder.setData(builder, R.mipmap.icon_share_twitter, R.string.dialog_share_app_twitter);
|
|
break;
|
|
case ShareBean.APP_WHATSAPP:
|
|
holder.setData(builder, R.mipmap.icon_share_whatsapp, R.string.dialog_share_app_whatsapp);
|
|
break;
|
|
case ShareBean.APP_MESSENGER:
|
|
holder.setData(builder, R.mipmap.icon_share_messenger, R.string.dialog_share_app_messenger);
|
|
break;
|
|
case ShareBean.APP_INSTAGRAM:
|
|
holder.setData(builder, R.mipmap.icon_share_instagram, R.string.dialog_share_app_instagram);
|
|
break;
|
|
case ShareBean.APP_INTERNAL:
|
|
holder.setData(builder, R.mipmap.ic_share_friend, R.string.dialog_share_app_internal);
|
|
break;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public int getItemCount() {
|
|
return list.size();
|
|
}
|
|
|
|
public void setOnShareStatusListener(ShareCallback shareCallback) {
|
|
this.shareCallback = shareCallback;
|
|
if (this.shareCallback == null) {
|
|
this.shareCallback = new ShareCallback();
|
|
}
|
|
}
|
|
|
|
public class AppViewHolder extends RecyclerView.ViewHolder {
|
|
ImageView icon;
|
|
TextView title;
|
|
|
|
public AppViewHolder(@NonNull View itemView) {
|
|
super(itemView);
|
|
icon = itemView.findViewById(R.id.share_app_icon);
|
|
title = itemView.findViewById(R.id.share_app_name);
|
|
}
|
|
|
|
public void setData(ShareBean bean, @DrawableRes int iconId, @StringRes int appName) {
|
|
icon.setImageResource(iconId);
|
|
title.setText(appName);
|
|
itemView.setOnClickListener(v -> {
|
|
switch (bean.getType()) {
|
|
case ShareBean.APP_FACEBOOK:
|
|
new FacebookShare(itemView.getContext()).share(bean, new ShareCallback());
|
|
break;
|
|
case ShareBean.APP_LINE:
|
|
new Line(itemView.getContext()).share(bean, new ShareCallback());
|
|
break;
|
|
case ShareBean.APP_TWITTER:
|
|
new TwitterShare(itemView.getContext()).share(bean, new ShareCallback());
|
|
break;
|
|
case ShareBean.APP_WHATSAPP:
|
|
new WhatsApp(itemView.getContext()).share(bean, new ShareCallback());
|
|
break;
|
|
case ShareBean.APP_MESSENGER:
|
|
new MessengerShare(itemView.getContext()).share(bean, new ShareCallback());
|
|
break;
|
|
case ShareBean.APP_INSTAGRAM:
|
|
new Instagram(itemView.getContext()).share(bean, new ShareCallback());
|
|
break;
|
|
case ShareBean.APP_INTERNAL:
|
|
new Internal(itemView.getContext()).share(bean, shareCallback);
|
|
break;
|
|
}
|
|
if (onShareListener != null) {
|
|
onShareListener.onAddShareCount();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
public interface onShareListener {
|
|
void onAddShareCount();
|
|
}
|
|
|
|
public static class ShareCallback implements ICallback {
|
|
|
|
@Override
|
|
public void onSuccess() {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onFailure() {
|
|
|
|
}
|
|
}
|
|
}
|