多个接口的案例

///
package com.example.yue.service;
import com.example.yue.bean.Pinglun;
import com.example.yue.bean.ShouyBean;
import com.example.yue.bean.XqBean;
import java.util.Map;
import io.reactivex.Flowable;
import retrofit2.http.GET;
import retrofit2.http.QueryMap;

/**
 * Created by  
 */

public interface ApiService {
    @GET("homePageApi/homePage.do")
    Flowable<ShouyBean> getShouy(@QueryMap Map<String,String> map);

    @GET("videoDetailApi/videoDetail.do")
    Flowable<XqBean> getXiang(@QueryMap Map<String,String> map);

    @GET("Commentary/getCommentList.do")
    Flowable<Pinglun> getPingLun(@QueryMap Map<String,String> map);
}
 
package com.example.yue.presenter;
import java.util.Map;

/**
 * Created by 
 */

public interface BasePersenter {
    void getData(Map<String,String> map,String tag);
}
/
package com.example.yue.presenter;
import com.example.yue.bean.Pinglun;
import com.example.yue.bean.ShouyBean;
import com.example.yue.bean.XqBean;
import com.example.yue.iview.Iview;
import com.example.yue.model.NewsModel;
import java.util.Map;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subscribers.DisposableSubscriber;

/**
 * Created by 
 */

public class NewsPersenter implements BasePersenter {
    private Iview iv;
    private DisposableSubscriber subscriber;
    public void attach(Iview iv){
        this.iv=iv;
    }

    public void detachView(){
        if (iv!=null){
            iv=null;
        }
        if (subscriber!=null) {//rxjava的防止内存泄漏
            if (!subscriber.isDisposed()) {
                subscriber.isDisposed();
            }
        }
        }


    @Override
    public void getData(Map<String, String> map,String tag) {
        NewsModel newsModel = new NewsModel(this);//多态  this是当前的p层、
        newsModel.getData(map,tag);
    }

    public void getShouy(Flowable<ShouyBean> news, final String tag){
          news.subscribeOn(Schedulers.io())
                  .observeOn(AndroidSchedulers.mainThread())
                  .subscribeWith(new DisposableSubscriber<ShouyBean>() {
                      @Override
                      public void onNext(ShouyBean shouyBean) {
                            iv.onSuccess(shouyBean,tag);
                      }

                      @Override
                      public void onError(Throwable t) {

                      }

                      @Override
                      public void onComplete() {

                      }
                  });
    }

    public void getXiangQing(Flowable<XqBean> flowable, final String tag){
        flowable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new DisposableSubscriber<XqBean>() {
                    @Override
                    public void onNext(XqBean xqBean) {
                        iv.onSuccess(xqBean,tag);
                    }

                    @Override
                    public void onError(Throwable t) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void getPinglun(final Flowable<Pinglun> pingLun, final String tag){
        pingLun.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new DisposableSubscriber<Pinglun>() {
                    @Override
                    public void onNext(Pinglun pinglun) {;
                        iv.onSuccess(pinglun,tag);
                    }

                    @Override
                    public void onError(Throwable t) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}

//
package com.example.yue.model;
import java.util.Map;

/**
 * Created by
 */

public interface Imodel {
    void getData(Map<String,String> map,String tag);
}
package com.example.yue.model;
import com.example.yue.bean.Pinglun;
import com.example.yue.bean.ShouyBean;
import com.example.yue.bean.XqBean;
import com.example.yue.http.RetrofitUtils;
import com.example.yue.presenter.NewsPersenter;
import java.util.Map;
import io.reactivex.Flowable;

/**
 * Created by 
 */

public class NewsModel implements Imodel {

    private NewsPersenter presenter;
    public NewsModel(NewsPersenter presenter){
        this.presenter=presenter;
    }

    @Override
    public void getData(Map<String, String> map,String tag) {
        //判断
        if (tag.equals("首页")){
            Flowable<ShouyBean> news = RetrofitUtils.getInstance().getApiService().getShouy(map);
            presenter.getShouy(news,tag);
        }else if(tag.equals("详情")){
            Flowable<XqBean> xiang = RetrofitUtils.getInstance().getApiService().getXiang(map);
            presenter.getXiangQing(xiang,tag);
        }else if(tag.equals("评论")){
            Flowable<Pinglun> pingLun = RetrofitUtils.getInstance().getApiService().getPingLun(map);
            presenter.getPinglun(pingLun,tag);
        }
    }
}
package com.example.yue.iview;

/**
 * Created 
 */

public interface Iview {
    void onSuccess(Object o,String tag);
    void onFailed(Exception e);
}
//
package com.example.yue.http;
import com.example.yue.service.ApiService;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by 
 */

public class RetrofitUtils {
    private  static  volatile RetrofitUtils instance;
    private final ApiService apiService;

    private RetrofitUtils(){
        Retrofit retrofit=new Retrofit.Builder()
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .baseUrl("http://api.svipmovie.com/front/")
                .client(new OkHttpClient.Builder().build())
                .build();
        apiService = retrofit.create(ApiService.class);
    }
    public static  RetrofitUtils getInstance(){
        if (instance==null){
            synchronized (RetrofitUtils.class){
                if (null==instance){
                    instance=new RetrofitUtils();
                }
            }
        }
        return  instance;
    }

    public ApiService getApiService(){
        return  apiService;
    }
}

package com.example.yue.fragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.yue.R;
import com.example.yue.activity.ImgApp;
import com.example.yue.activity.Xiangqing;
import com.example.yue.adapter.RecycleViewAdapter;
import com.example.yue.bean.Img;
import com.example.yue.bean.ShouyBean;
import com.example.yue.iview.Iview;
import com.example.yue.presenter.NewsPersenter;
import com.youth.banner.Banner;
import com.youth.banner.listener.OnBannerListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by .
 */

public class One extends Fragment implements Iview{

    private Banner ban;
    private NewsPersenter presenter;
    List<String> lists=new ArrayList<>();
    List<Img> lists1=new ArrayList<>();
    private RecycleViewAdapter recycleViewAdapter;
    private RecyclerView rv;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.one, container, false);
        ban = view.findViewById(R.id.ban);
        rv =view.findViewById(R.id.rv);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        HashMap<String,String> map=new HashMap<>();
        presenter = new NewsPersenter();
        presenter.attach(this);
        presenter.getData(map,"首页");
    }

    @Override
    public void onSuccess(Object o,String tag) {
        if (tag.equals("首页")) {
            ShouyBean bean = (ShouyBean) o;
            ShouyBean.RetBean ret = bean.getRet();
            List<ShouyBean.RetBean.ListBean> list = ret.getList();
            final List<ShouyBean.RetBean.ListBean.ChildListBean> childList = list.get(0).getChildList();


            for (int i = 0; i < childList.size(); i++) {
                String angleIcon = childList.get(i).getPic();
                lists.add(angleIcon);
            }
            ban.setImageLoader(new ImgApp());//引用ImgApp,加载里面的东西
            ban.setImages(lists);
            ban.isAutoPlay(true);
            ban.setDelayTime(2000);
            ban.setOnBannerListener(new OnBannerListener() {
                @Override
                public void OnBannerClick(int position) {
                    Intent intent = new Intent(getActivity(), Xiangqing.class);
                    String dataId = childList.get(position).getDataId();
                    intent.putExtra("id",dataId);
                    startActivity(intent);
               }
           });
           ban.start();

            List<ShouyBean.RetBean.ListBean.ChildListBean> childList1 = bean.getRet().getList().get(4).getChildList();
            for (int j = 0; j < childList1.size(); j++) {
                String title = childList1.get(j).getTitle();
                String pic = childList1.get(j).getPic();
                lists1.add(new Img(title, pic));
            }

            LinearLayoutManager manager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
            rv.setLayoutManager(manager);
            recycleViewAdapter = new RecycleViewAdapter(getActivity(), lists1);
            rv.setAdapter(recycleViewAdapter);
        }
    }

    @Override
    public void onFailed(Exception e) {

    }
}
package com.example.yue.fragments;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.example.yue.R;
import com.example.yue.adapter.ListMovieAdapter;
import com.example.yue.bean.BusBean;
import com.example.yue.bean.XqBean;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import java.util.List;

/**
 * Created by 
 */

public class Fragment1 extends Fragment  {

    private XqBean.RetBean ret;
    private TextView daoyan;
    private TextView yanyuan;
    private RecyclerView jianjiemovie;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.f1,container,false);
        daoyan =view.findViewById(R.id.tv1);
        yanyuan =view.findViewById(R.id.tv2);
        jianjiemovie =view.findViewById(R.id.jianjiemovie);
        //注册EventBus
        EventBus.getDefault().register(this);

        GridLayoutManager manager = new GridLayoutManager(getActivity(), 3);
        jianjiemovie.setLayoutManager(manager);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    //接收
    @Subscribe
    public void onEventMainThread( BusBean busbean) {
        if (busbean != null) {
            String id = busbean.getId();
            if(id.equals("0")) {
                XqBean movieBean = (XqBean) busbean.getO();
                ret = movieBean.getRet();
                daoyan.setText("导演  :  " + ret.getDirector());
                yanyuan.setText("主演  :  " + ret.getActors());

                List<XqBean.RetBean.ListBean> list = ret.getList();
                List<XqBean.RetBean.ListBean.ChildListBean> childList = list.get(0).getChildList();
                ListMovieAdapter listMovieAdapter = new ListMovieAdapter(getActivity(), childList);
                jianjiemovie.setAdapter(listMovieAdapter);
            }
        }
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        EventBus.getDefault().unregister(this);//反注册EventBus
    }
}

//
package com.example.yue.fragments;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.yue.R;
import com.example.yue.adapter.PingLunAdapter;
import com.example.yue.bean.Pinglun;
import com.example.yue.iview.Iview;
import com.example.yue.presenter.NewsPersenter;
import java.util.HashMap;
import java.util.List;

/**
 * Created b
 */

public class Fragment2 extends Fragment implements Iview{
    private String uid;
    private NewsPersenter presenter;
    private RecyclerView rev;

    public Fragment2(String uid) {
        this.uid = uid;
    }
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.f2,container,false);

        rev =view.findViewById(R.id.rev);
        if (uid != null) {
            presenter = new NewsPersenter();
            presenter.attach(this);
            HashMap<String, String> map = new HashMap<>();
            map.put("mediaId", uid);
            presenter.getData(map, "评论");
        }
        LinearLayoutManager manager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
        rev.setLayoutManager(manager);
        return view;
    }


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

    }

    @Override
    public void onSuccess(Object o, String tag) {
        if (tag.equals("评论")) {
            Pinglun pingLunBean = (Pinglun) o;
            List<Pinglun.RetBean.ListBean> list = pingLunBean.getRet().getList();
            PingLunAdapter pingLunAdapter = new PingLunAdapter(list, getActivity());
            rev.setAdapter(pingLunAdapter);
        }
    }

    @Override
    public void onFailed(Exception e) {

    }
}
///
package com.example.yue.activity;
import android.content.Context;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.youth.banner.loader.ImageLoader;

/**
 * Created by 
 */

public class ImgApp extends ImageLoader {
    @Override
    public void displayImage(Context context, Object path, ImageView imageView) {
        Glide.with(context).load(path).into(imageView);
    }
}
动画跳转
package com.example.yue.activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;
import com.example.yue.MainActivity;
import com.example.yue.R;

public class Main2Activity extends AppCompatActivity {

    private ImageView a;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        a =(ImageView)findViewById(R.id.a);

        AnimationSet animationSet = new AnimationSet(false);
        Animation animation = new ScaleAnimation(1f, 1.1f, 1f, 1.1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        animation.setDuration(3000);
        animationSet.addAnimation(animation);
        a.setAnimation(animationSet);
        animationSet.start();//开始

        //设置动画的监听事件
        animationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {//结束的时候跳转
                Intent intent = new Intent(Main2Activity.this, MainActivity.class);
                startActivity(intent);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }
}


、、、、、、、、、、、、、、、、、、、、、、、、、
package com.example.yue.activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import android.widget.VideoView;
import com.example.yue.R;
import com.example.yue.adapter.FAdapter;
import com.example.yue.bean.BusBean;
import com.example.yue.bean.XqBean;
import com.example.yue.fragments.Fragment1;
import com.example.yue.fragments.Fragment2;
import com.example.yue.iview.Iview;
import com.example.yue.presenter.NewsPersenter;
import org.greenrobot.eventbus.EventBus;
import java.util.ArrayList;
import java.util.HashMap;

public class Xiangqing extends AppCompatActivity  implements Iview{

    private ViewPager vp;
    private ArrayList<Fragment> fragments;
    private NewsPersenter presenter;
    private TextView text1;
    private VideoView video_view;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xiangqing);
   //     EventBus.getDefault().register(this);
        vp = (ViewPager) findViewById(R.id.vp);
        text1 =(TextView)findViewById(R.id.text1);
        video_view =(VideoView)findViewById(R.id.video_view);



        Intent intent = getIntent();
        String id = intent.getStringExtra("id");
        HashMap<String,String> map=new HashMap<>();
        map.put("mediaId",id);
        presenter = new NewsPersenter();
        presenter.attach(this);
        presenter.getData(map,"详情");

        fragments = new ArrayList<>();
        fragments.add(new Fragment1());
        fragments.add(new Fragment2(id));

        FAdapter fAdapter = new FAdapter(getSupportFragmentManager(), fragments);
        vp.setAdapter(fAdapter);
    }

    @Override
    public void onSuccess(Object o, String tag) {
         if (tag.equals("详情")){
             XqBean bean=(XqBean)o;
             text1.setText(bean.getRet().getTitle());
             //EventBus发送
             BusBean busBean = new BusBean("0", bean);
             EventBus.getDefault().post(busBean);
   //          String hdurl = bean.getRet().getHDURL();
             //初始化配置
  //           Uri uri = Uri.parse(hdurl);
             //设置视频路径
//             videoView.setVideoURI(uri);
//             MediaController controller = new MediaController(this);
//             videoView.setMediaController(controller);
//             controller.setAnchorView(videoView);
//             //开始播放视频
//             videoView.start();
//             //播放完成回调
//             videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
//                 @Override
//                 public void onCompletion(MediaPlayer mediaPlayer) {
//                     Toast.makeText(SuccessActivity.this,"播放完成",Toast.LENGTH_SHORT).show();
//                 }
//             });
         }
    }


  /*  //接收到pager发送的消息
    @Subscribe
        public void onEventMainThread( BusBean busBean) {
            if(busBean!=null){
                String id = busBean.getId();
                if(id.equals("1")){
                    HashMap<String, String> map = new HashMap<>();
                    Log.e("---------",busBean.getO().toString());
                    map.put("mediaId", busBean.getO().toString());
                    presenter.getData(map, "详情");
                }
            }
    }*/


  /*  @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);//反注册EventBus
    }*/

    @Override
    public void onFailed(Exception e) {

    }
}
///
package com.example.yue;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.example.yue.fragment.Four;
import com.example.yue.fragment.One;
import com.example.yue.fragment.Three;
import com.example.yue.fragment.Two;
import com.hjm.bottomtabbar.BottomTabBar;

public class MainActivity extends AppCompatActivity {

    private BottomTabBar mb;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mb =(BottomTabBar)findViewById(R.id.bottom_tab_bar);

        mb.init(getSupportFragmentManager())
                .setTabBarBackgroundResource(R.drawable.bottom_bg)
                .setImgSize(60,60)
                .setFontSize(20)
                .setTabPadding(4,6,10)
                .setChangeColor(Color.RED,Color.DKGRAY)
                .addTabItem("精选",R.drawable.found, One.class)
                .addTabItem("发现",R.drawable.special_select, Two.class)
                .addTabItem("专题",R.drawable.fancy, Three.class)
                .addTabItem("我的",R.drawable.my, Four.class)
                .isShowDivider(false)
                .setOnTabChangeListener(new BottomTabBar.OnTabChangeListener() {
                    @Override
                    public void onTabChange(int position, String name) {
                    }
                })
                .setBackgroundResource(R.drawable.bg_blue);
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值