仿探探cardview(api在此)




api

package com.example.com.api;

import com.example.com.bean.CommentBean;
import com.example.com.bean.DetailsBean;
import com.example.com.bean.MessageBean;
import com.example.com.bean.SearchBean;
import com.example.com.bean.VideoAllBean;
import com.example.com.bean.WelfareBean;

import io.reactivex.Flowable;
import retrofit2.http.GET;
import retrofit2.http.Path;
import retrofit2.http.Query;

/**
 * Created by linmeihui on 2018/5/16.
 */

public interface ApiService {
    @GET("front/homePageApi/homePage.do")
    Flowable<MessageBean>  getImg();

    //全部视频分类接口
    //"http://api.svipmovie.com/front/columns/getVideoList.do?catalogId=402834815584e463015584e538140009&information=null
    @GET("front/columns/getVideoList.do")
    Flowable<VideoAllBean> getVideoAll(@Query("catalogId")String catalogId);

    @GET("front/videoDetailApi/videoDetail.do")
    Flowable<DetailsBean> getDetails(@Query("mediaId")String mediaId);

    //评论接口
    @GET("front/Commentary/getCommentList.do")
    Flowable<CommentBean> getEvaluate(@Query("mediaId")String mediaId);

    //福利接口
    @GET("api/data/{type}/{num}/1")
    Flowable<WelfareBean> getFuli(@Path("type")String type, @Path("num")int num);

    //搜索电影接口
    @GET("front/searchKeyWordApi/getVideoListByKeyWord.do")
    Flowable<SearchBean> getSearch(@Query("keyword")String keyword);

}


布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">


    <android.support.v7.widget.RecyclerView
        android:id="@+id/fra3_recy"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</android.support.design.widget.CoordinatorLayout>


activity

package com.example.com.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.com.adapter.Fra3RecyAdapter;
import com.example.com.bean.MessageBean;
import com.example.com.bean.VideoAllBean;
import com.example.com.camera.OverLayCardLayoutManager;
import com.example.com.camera.R;
import com.example.com.camera.RenRenCallback;
import com.example.com.presenter.MyVedioPresenter;
import com.example.com.view.VedioView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by linmeihui on 2018/5/15.
 */

public class FindFra extends Fragment implements VedioView {

    private List<MessageBean.RetBean.ListBean> listBeans;
    private RecyclerView fra3_recy;
    private MyVedioPresenter myVedioPresenter;
    private Fra3RecyAdapter fra3RecyAdapter;
    private List<VideoAllBean.RetBean.ListBean> list;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        EventBus.getDefault().register(this);
        View v=inflater.inflate( R.layout.fra03,container,false);

        fra3_recy = v.findViewById(R.id.fra3_recy);

        init();

        return v;
    }

    private void init() {

        myVedioPresenter = new MyVedioPresenter(this);

        fra3_recy.setLayoutManager(new OverLayCardLayoutManager(getActivity()));
        
    }



    //订阅者
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getListNet(List<MessageBean.RetBean.ListBean> listBeans) {
/*
        this.listBeans=listBeans;
*/

        toUrl(listBeans);
    }


    private void toUrl(List<MessageBean.RetBean.ListBean> listBeans) {

        List<String> urlList = new ArrayList<>();


        for (int i = 0; i <listBeans.size() ; i++) {
            urlList.add(listBeans.get(i).getMoreURL());
        }

        String s = urlList.get(2);

        int i = s.indexOf("=");
        int i1 = s.indexOf("&i");
        //
        String substring = s.substring(i+1, i1);
        //
        myVedioPresenter.toGetUrl(s,substring);

    }



    @Override
    public void onSuccess(VideoAllBean videoAllBean) {

        Log.d("--", "onSuccess: "+videoAllBean.getMsg());

        list = videoAllBean.getRet().getList();
        fra3RecyAdapter = new Fra3RecyAdapter(videoAllBean.getRet().getList(), getActivity());
        fra3_recy.setAdapter(fra3RecyAdapter);

        final RenRenCallback callback = new RenRenCallback();


        callback.setSwipeListener(new RenRenCallback.OnSwipeListener() {
            @Override
            public void onSwiped(int adapterPosition, int direction) {
                if (direction == ItemTouchHelper.DOWN || direction == ItemTouchHelper.UP) {
                    list.add(0, list.remove(adapterPosition));
                    fra3_recy.getAdapter().notifyDataSetChanged();
                } else {
                    list.remove(adapterPosition);
                }
                fra3_recy.getAdapter().notifyDataSetChanged();
            }

            @Override
            public void onSwipeTo(RecyclerView.ViewHolder viewHolder, float offset) {

            }
        });
        new ItemTouchHelper(callback).attachToRecyclerView(fra3_recy);

    }




    @Override
    public void onFailed(String message) {

        Toast.makeText(getActivity(),message,Toast.LENGTH_SHORT).show();
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();

        EventBus.getDefault().unregister(this);

    }
}



vedioview

package com.example.com.view;

import com.example.com.bean.VideoAllBean;

/**
 * Created by linmeihui on 2018/5/18.
 */

public interface VedioView {
    void onSuccess(VideoAllBean videoAllBean);
    void onFailed(String message);
}


myvediomodel

package com.example.com.model;

import com.example.com.api.ApiService;
import com.example.com.bean.VideoAllBean;
import com.example.com.presenter.MyVedioPresenter;
import com.example.com.presenter.VedioPresenter;
import com.example.com.utils.RetrofitUtils;

import io.reactivex.Flowable;

/**
 * Created by linmeihui on 2018/5/18.
 */

public class MyVedioModel {

    public void toData(String catalogId,VedioPresenter vedioPresenter) {

        Flowable<VideoAllBean> videoAll = RetrofitUtils.getInstance().getService().getVideoAll(catalogId);

        vedioPresenter.success(videoAll);

    }
}


adapter

package com.example.com.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.com.bean.VideoAllBean;
import com.example.com.camera.R;

import java.util.List;

/**
 * Created by linmeihui on 2018/5/20.
 */

public class Fra3RecyAdapter extends RecyclerView.Adapter {

    List<VideoAllBean.RetBean.ListBean> list;
    Context context;

    public Fra3RecyAdapter(List<VideoAllBean.RetBean.ListBean> list, Context context) {

        this.context=context;
        this.list=list;

    }

    public int dp(int dp) {
        final float density = context.getResources().getDisplayMetrics().density;
        return (int) (dp * density);
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        View view= LayoutInflater.from(context).inflate(R.layout.fra3_item,parent,false);

        ViewHolder viewHolder=new ViewHolder(view);

        return viewHolder;


    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {

        ViewHolder viewHolder= (ViewHolder) holder;

        viewHolder.title.setText(list.get(position).getTitle());
        viewHolder.synopsis.setText(list.get(position).getDescription());
        Glide.with(context).load(list.get(position).getPic()).into(viewHolder.img);

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private final ImageView img;
        private final TextView synopsis;
        private final TextView title;

        public ViewHolder(View itemView) {
            super(itemView);
            img = itemView.findViewById(R.id.fi_img);
            synopsis = itemView.findViewById(R.id.fi_synopsis);
            title = itemView.findViewById(R.id.fi_title);
        }
    }

}


adapter子条目

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="360dp"
    android:layout_height="480dp"
    app:cardBackgroundColor="#b3bc76"
    app:cardCornerRadius="6dp"
    app:cardElevation="6dp"
    app:contentPadding="0dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">


        <TextView
            android:id="@+id/fi_title"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:gravity="center"
            android:text="太阳之门"
            android:textSize="20dp" />

        <ImageView
            android:id="@+id/fi_img"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

        <TextView
            android:maxLines="8"
            android:ellipsize="end"
            android:id="@+id/fi_synopsis"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:gravity="center" />

    </LinearLayout>


</android.support.v7.widget.CardView>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值