布局
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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:background="#ea32ea" tools:context="com.example.com.activity.XiangqingActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <ImageView android:layout_width="50dp" android:id="@+id/houtui" android:layout_height="wrap_content" android:src="@drawable/back"/> <TextView android:layout_width="200dp" android:layout_height="wrap_content" android:layout_marginLeft="50dp" android:layout_gravity="center" android:id="@+id/tv_title" /> <CheckBox android:layout_width="60dp" android:layout_height="wrap_content" android:layout_marginLeft="50dp" android:id="@+id/shoucang" android:button="@null" android:background="@drawable/collection"/> </LinearLayout> <fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard android:id="@+id/jiecao_Player" android:layout_marginTop="40dp" android:layout_width="match_parent" android:layout_height="200dp"> </fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard> <android.support.design.widget.TabLayout android:layout_width="200dp" android:layout_height="wrap_content" android:layout_below="@id/jiecao_Player" android:layout_centerHorizontal="true" android:id="@+id/tablayout" app:tabIndicatorColor="#fff" app:tabSelectedTextColor="#349c15" app:tabMode="scrollable"> </android.support.design.widget.TabLayout> <android.support.v4.view.ViewPager android:layout_below="@id/tablayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/viewpager" > </android.support.v4.view.ViewPager> </RelativeLayout>
activity
package com.example.com.activity; import android.database.sqlite.SQLiteDatabase; import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.CheckBox; import android.widget.ImageView; import android.widget.Toast; import com.bumptech.glide.Glide; import com.example.com.bean.DaoMaster; import com.example.com.bean.DaoSession; import com.example.com.bean.DetailsBean; import com.example.com.bean.GreenBean; import com.example.com.bean.GreenBeanDao; import com.example.com.camera.R; import com.example.com.fragment.IntroduceTabFra1; import com.example.com.fragment.CommentTabFra2; import com.example.com.presenter.MyDetailsPresenter; import com.example.com.view.LInMeiHeiDataView; import org.greenrobot.eventbus.EventBus; import java.util.ArrayList; import java.util.List; import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard; public class XiangqingActivity extends AppCompatActivity implements LInMeiHeiDataView<DetailsBean> { private JCVideoPlayerStandard jiecao_player; private String url = "http://api.svipmovie.com/"; private TabLayout tablayout; private ViewPager viewpager; private List<Fragment> fraList=new ArrayList<>(); private List<String> titleList=new ArrayList<>(); private DetailsBean.RetBean ret; private ImageView houtui; private CheckBox shoucang; private GreenBeanDao greenBeanDao; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_xiangqing); jiecao_player = findViewById(R.id.jiecao_Player); tablayout = findViewById(R.id.tablayout); viewpager = findViewById(R.id.viewpager); houtui = findViewById(R.id.houtui); shoucang = findViewById(R.id.shoucang); //建立并保存数值 DaoMaster.DevOpenHelper mHelper = new DaoMaster.DevOpenHelper (this, "sport-db", null); SQLiteDatabase db = mHelper.getWritableDatabase(); // 注意:该数据库连接属于 DaoMaster,所以多个 Session 指的是相同的数据库连接。 DaoMaster mDaoMaster = new DaoMaster(db); DaoSession daoSession = mDaoMaster.newSession(); greenBeanDao = daoSession.getGreenBeanDao(); tablayout.setTabMode(TabLayout.MODE_FIXED); tablayout.setupWithViewPager(viewpager); houtui.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); shoucang.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (shoucang.isChecked()){ shoucang.setBackgroundResource(R.drawable.collection_select); greenBeanDao.insertOrReplace(new GreenBean(null,ret.getTitle(),ret.getPic(),ret.getDataID())); }else{ shoucang.setBackgroundResource(R.drawable.collection); List<GreenBean> greenBeans = greenBeanDao.loadAll(); for (int i = 0; i < greenBeans.size(); i++) { if(greenBeans.get(i).getName().equals(ret.getTitle())){ Long id = greenBeans.get(i).getId(); greenBeanDao.deleteByKey(id); } } } List<GreenBean> greenBeans = greenBeanDao.loadAll(); Log.d("--", "onClick: "+greenBeans.size()); } }); init(); } private void init() { String data = getIntent().getStringExtra("data"); MyDetailsPresenter myDetailsPresenter = new MyDetailsPresenter(this); myDetailsPresenter.toUrl(data); fraList.add(new IntroduceTabFra1()); fraList.add(new CommentTabFra2()); titleList.add("简介"); titleList.add("评论"); } @Override public void onSuccess(DetailsBean detailsBean) { ret = detailsBean.getRet(); String smoothURL = ret.getSmoothURL(); Toast.makeText(this,detailsBean.getRet().getList().size()+"",Toast.LENGTH_SHORT).show(); jiecao_player.setUp(smoothURL, jiecao_player.SCREEN_LAYOUT_NORMAL, "视频标题"); //jiecao_player.thumbImageView.setImageURI(Uri.parse(detailsBean.getRet().getPic())); Glide.with(this).load(detailsBean.getRet().getPic()).into(jiecao_player.thumbImageView); jiecao_player.thumbImageView.setScaleType(ImageView.ScaleType.FIT_XY); //jiecao_player.thumbImageView.setImageURI(Uri.parse(htmlURL)); viewpager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) { @Override public Fragment getItem(int position) { EventBus.getDefault().postSticky(ret); return fraList.get(position); } @Override public CharSequence getPageTitle(int position) { return titleList.get(position); } @Override public int getCount() { return titleList.size(); } }); } @Override public void onBackPressed() { if (jiecao_player.backPress()) { return; } super.onBackPressed(); } @Override protected void onPause() { super.onPause(); jiecao_player.releaseAllVideos(); } }
linmeihuidataview
package com.example.com.view; /** * Created by linmeihui on 2018/5/19. */ public interface LInMeiHeiDataView<T> { void onSuccess(T t); }
mydetailspresenter
package com.example.com.presenter; import com.example.com.bean.DetailsBean; import com.example.com.bean.MessageBean; import com.example.com.model.MyDetailsModel; import com.example.com.view.LInMeiHeiDataView; import io.reactivex.Flowable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.DefaultSubscriber; /** * Created by linmeihui on 2018/5/19. */ public class MyDetailsPresenter implements DataPresenter<DetailsBean>{ private MyDetailsModel model; private LInMeiHeiDataView dataView; public MyDetailsPresenter(LInMeiHeiDataView dataView) { this.dataView = dataView; model = new MyDetailsModel(); } public void toUrl(String mediaId){ model.toDataUrl(mediaId,this); } @Override public void success(Flowable<DetailsBean> t) { t.subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new DefaultSubscriber<DetailsBean>() { @Override public void onNext(DetailsBean detailsBean) { dataView.onSuccess(detailsBean); } @Override public void onError(Throwable t) { } @Override public void onComplete() { } }); } }
简介布局
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:fresco="http://schemas.android.com/apk/res-auto"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:id="@+id/introduce_daoyan" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:textColor="#CAB9C3" /> <TextView android:id="@+id/introduce_all" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:textColor="#CAB9C3" /> <com.ms.square.android.expandabletextview.ExpandableTextView android:id="@+id/expand_text_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/details_relative" android:layout_marginLeft="5dp" android:layout_marginTop="10dp" fresco:animDuration="1000" fresco:collapseDrawable="@drawable/icon_green_arrow_up" fresco:expandDrawable="@drawable/icon_green_arrow_down" fresco:maxCollapsedLines="4"> <TextView android:id="@id/expandable_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="8dp" android:textColor="#CAB9C3" android:textSize="16sp" /> <ImageButton android:id="@id/expand_collapse" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right|bottom" android:background="@android:color/transparent" android:padding="16dp" /> </com.ms.square.android.expandabletextview.ExpandableTextView> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:descendantFocusability="blocksDescendants" > <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/intro_recy"> </android.support.v7.widget.RecyclerView> </RelativeLayout> </LinearLayout> </ScrollView>
activity
package com.example.com.fragment; import android.content.Intent; 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.StaggeredGridLayoutManager; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.example.com.activity.Fra2ItemActivity; import com.example.com.activity.XiangqingActivity; import com.example.com.adapter.TabAdapter1; import com.example.com.bean.DetailsBean; import com.example.com.camera.R; import com.example.com.view.LInMeiHeiDataView; import com.ms.square.android.expandabletextview.ExpandableTextView; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import java.util.List; /** * Created by linmeihui on 2018/5/21. */ public class IntroduceTabFra1 extends Fragment implements TabAdapter1.OnItemClick{ private DetailsBean.RetBean retBean; private RecyclerView intro_recy; private List<DetailsBean.RetBean.ListBean> list; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view=inflater.inflate(R.layout.tab_item1,container,false); EventBus.getDefault().register(this); ExpandableTextView expandTextView=view.findViewById(R.id.expand_text_view); intro_recy = view.findViewById(R.id.intro_recy); expandTextView.setEnabled(false); // 设置显示内容 expandTextView.setText("\u3000\u3000" + retBean.getDescription()); // 设置状态监听 expandTextView.setOnExpandStateChangeListener(new ExpandableTextView.OnExpandStateChangeListener() { @Override public void onExpandStateChanged(TextView textView, boolean isExpanded) { } }); StaggeredGridLayoutManager manger=new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL); intro_recy.setLayoutManager(manger); intro_recy.setNestedScrollingEnabled(false); list = retBean.getList(); Log.i("********", ""+ list.size()); TabAdapter1 tabAdapter1 = new TabAdapter1(list.get(0).getChildList(), getActivity()); intro_recy.setAdapter(tabAdapter1); tabAdapter1.setClick(this); return view; } @Subscribe(threadMode = ThreadMode.MAIN,sticky = true) public void getUrl(DetailsBean.RetBean ret){ this.retBean = ret; } @Override public void onDestroyView() { super.onDestroyView(); EventBus.getDefault().unregister(this); } @Override public void itemClick(int position) { String dataId = list.get(0).getChildList().get(position).getDataId(); Intent intent = new Intent(getActivity(), XiangqingActivity.class); intent.putExtra("data",dataId); startActivity(intent); } }
adapter
package com.example.com.adapter; import android.content.Context; import android.support.annotation.NonNull; import android.support.v4.app.FragmentActivity; import android.support.v7.widget.RecyclerView; 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.DetailsBean; import com.example.com.camera.R; import java.util.List; /** * Created by linmeihui on 2018/5/22. */ public class TabAdapter1 extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ List<DetailsBean.RetBean.ListBean.ChildListBean> list; Context context; OnItemClick click; public TabAdapter1(List<DetailsBean.RetBean.ListBean.ChildListBean> list, Context context) { this.context=context; this.list=list; } public void setClick(OnItemClick click){ this.click=click; } public interface OnItemClick{ void itemClick(int position); } @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View view=View.inflate(context,R.layout.fra2_recy_item,null); ViewHolder viewHolder=new ViewHolder(view); return viewHolder; } @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) { ViewHolder viewHolder= (ViewHolder) holder; viewHolder.special_tv.setText(list.get(position).getTitle()); Glide.with(context).load(list.get(position).getPic()).into(viewHolder.img); viewHolder.img.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { click.itemClick(position); } }); } @Override public int getItemCount() { return list.size(); } class ViewHolder extends RecyclerView.ViewHolder{ private final ImageView img; private final TextView special_tv; public ViewHolder(View itemView) { super(itemView); special_tv = itemView.findViewById(R.id.special_tv); img = itemView.findViewById(R.id.img); } } }
adapter子布局
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_width="220dp" android:layout_height="120dp" android:scaleType="center" android:layout_margin="10dp" android:id="@+id/img"/> <TextView android:id="@+id/special_tv" android:layout_width="220dp" android:layout_height="20dp" android:layout_marginLeft="10dp" android:layout_alignBottom="@+id/img" android:background="@drawable/textview_shape" android:gravity="center_horizontal" android:textColor="#fff" /> </RelativeLayout>
评论布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/introdeuce_recy" android:layout_below="@id/expand_text_view"> </android.support.v7.widget.RecyclerView> </LinearLayout>
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.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.example.com.adapter.Tab2RecyAdapter; import com.example.com.bean.CommentBean; import com.example.com.bean.DetailsBean; import com.example.com.camera.R; import com.example.com.presenter.MyCommentPresenter; import com.example.com.view.LInMeiHeiDataView; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import java.util.List; /** * Created by linmeihui on 2018/5/21. */ public class CommentTabFra2 extends Fragment implements LInMeiHeiDataView<CommentBean>{ private RecyclerView introdeuce_recy; private MyCommentPresenter myCommentPresenter; String dataurl; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view=inflater.inflate( R.layout.tab_item2,container,false); EventBus.getDefault().register(this); introdeuce_recy = view.findViewById(R.id.introdeuce_recy); init(); return view; } private void init() { myCommentPresenter = new MyCommentPresenter(this); myCommentPresenter.toUrl(dataurl); introdeuce_recy.setLayoutManager(new LinearLayoutManager(getActivity())); introdeuce_recy.setNestedScrollingEnabled(false); } @Subscribe(threadMode = ThreadMode.MAIN,sticky = true) public void getUrl(DetailsBean.RetBean ret){ this.dataurl = ret.getDataID(); } @Override public void onDestroyView() { super.onDestroyView(); EventBus.getDefault().unregister(this); } @Override public void onSuccess(CommentBean commentBean) { List<CommentBean.RetBean.ListBean> list = commentBean.getRet().getList(); Tab2RecyAdapter tab2RecyAdapter = new Tab2RecyAdapter(list, getActivity()); // Log.i("***********", "onSuccess: "+list.size()); introdeuce_recy.setAdapter(tab2RecyAdapter); } }
mycommentdatapresenter
package com.example.com.presenter; import com.example.com.bean.CommentBean; import com.example.com.model.MyCommentModel; import com.example.com.view.DataView; import com.example.com.view.LInMeiHeiDataView; import io.reactivex.Flowable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.DefaultSubscriber; /** * Created by linmeihui on 2018/5/23. */ public class MyCommentPresenter implements DataPresenter<CommentBean>{ private MyCommentModel myCommentModel; LInMeiHeiDataView lInMeiHeiDataView; public MyCommentPresenter(LInMeiHeiDataView lInMeiHeiDataView) { myCommentModel =new MyCommentModel(); this.lInMeiHeiDataView=lInMeiHeiDataView; } @Override public void success(Flowable<CommentBean> t) { t.subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new DefaultSubscriber<CommentBean>() { @Override public void onNext(CommentBean commentBean) { lInMeiHeiDataView.onSuccess(commentBean); } @Override public void onError(Throwable t) { } @Override public void onComplete() { } }); } public void toUrl(String mediaId){ myCommentModel.toGet(mediaId,this); } }
adapter
package com.example.com.adapter; import android.content.Context; import android.support.annotation.NonNull; import android.support.v4.app.FragmentActivity; import android.support.v7.widget.RecyclerView; 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.CommentBean; import com.example.com.camera.R; import com.example.com.camera.XCRoundImageView; import java.util.List; /** * Created by linmeihui on 2018/5/23. */ public class Tab2RecyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ List<CommentBean.RetBean.ListBean> list; Context context; public Tab2RecyAdapter(List<CommentBean.RetBean.ListBean> list, Context context) { this.context=context; this.list=list; } @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View view=View.inflate(context,R.layout.tab2_recy_item,null); ViewHolder viewHolder=new ViewHolder(view); return viewHolder; } @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { ViewHolder viewHolder= (ViewHolder) holder; Glide.with(context).load(list.get(position).getUserPic()).into(viewHolder.tab2_img); viewHolder.tv2.setText(list.get(position).getTime()); viewHolder.tv3.setText(list.get(position).getMsg()); } @Override public int getItemCount() { return list.size(); } class ViewHolder extends RecyclerView.ViewHolder{ private final ImageView tab2_img; private final TextView tv2; private final TextView tv3; public ViewHolder(View itemView) { super(itemView); tab2_img = itemView.findViewById(R.id.tab2_img); tv2 = itemView.findViewById(R.id.tv2); tv3 = itemView.findViewById(R.id.tv3); } } }
adapter子布局
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_width="60dp" android:layout_height="60dp" android:id="@+id/tab2_img"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:layout_toRightOf="@id/tab2_img" android:id="@+id/tv2"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="35dp" android:layout_toRightOf="@id/tab2_img" android:id="@+id/tv3"/> </RelativeLayout>