Commit 3f929fbe authored by mengcuiguang's avatar mengcuiguang

首页添加接口、业务逻辑

parent 48c66288
package com.mints.wisdomclean.manager
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import com.mints.library.utils.json.JsonUtil
import com.mints.wisdomclean.common.Constant
import com.mints.wisdomclean.mvp.model.BannerBean
import com.mints.wisdomclean.mvp.model.VedioBean
import com.mints.wisdomclean.utils.AppPreferencesManager
import com.mints.wisdomclean.video.DramaApiDetailActivity
import com.mints.wisdomclean.video.VideoActivity
/**
* 本地视频缓存管理
*/
object LocalVedioManager {
var vedioCache: Any? = null
var vedioCache: VedioBean? = null
/**
* 提交当前视频数据
*/
fun commitVedio(data: Any) {
fun commitVedio(data: VedioBean) {
cacheVedio(data)
TrackManager.getInstance().commitVedio()
}
......@@ -24,7 +29,7 @@ object LocalVedioManager {
/**
* 内存、本地都缓存视频
*/
private fun cacheVedio(data: Any) {
private fun cacheVedio(data: VedioBean) {
vedioCache = data
AppPreferencesManager.get().put(Constant.LOCAL_VEDIO, JsonUtil.toJson(data))
}
......@@ -57,16 +62,38 @@ object LocalVedioManager {
/**
* 展示缓存视频
*/
fun getCacheVedio(): Any? {
fun getCacheVedio(): VedioBean? {
if (vedioCache != null) {
return vedioCache as Any
return vedioCache as VedioBean
}
val localVedio = AppPreferencesManager.get().getString(Constant.LOCAL_VEDIO, "")
if (!TextUtils.isEmpty(localVedio)) {
return JsonUtil.parseJson(localVedio, BannerBean::class.java)
return JsonUtil.parseJson(localVedio, VedioBean::class.java)
}
return null
}
/**
* 根据类型跳转对应视频详情页 [自有或穿山甲]
*/
fun startVedioDetailActivityForType(activity: Activity, data: VedioBean?) {
val bundle = Bundle()
if (data?.createType==1) {
//自有短剧
readyGo(activity, VideoActivity::class.java, bundle)
} else {
//穿山甲短剧
readyGo(activity, DramaApiDetailActivity::class.java, bundle)
}
}
fun readyGo(activity: Activity, clazz: Class<*>, bundle: Bundle) {
val intent = Intent(activity, clazz)
if (null != bundle) {
intent.putExtras(bundle)
}
activity.startActivity(intent)
}
}
\ No newline at end of file
package com.mints.wisdomclean.mvp.model;
import java.io.Serializable;
import java.util.List;
public class BannerList implements Serializable {
private List<VedioBean> list;
public List<VedioBean> getList() {
return list;
}
public void setList(List<VedioBean> list) {
this.list = list;
}
}
......@@ -35,10 +35,8 @@ data class HotStyleBean(
@SuppressLint("ParcelCreator")
@Parcelize
data class HotStyleTypesBean(
var isChecked: Boolean = false,
var title: String = "",
var id: Int = 0,
var imageCount: Int = -1,
var type: String = "",
var torder: Int = 0
) : Parcelable
@SuppressLint("ParcelCreator")
......
package com.mints.wisdomclean.mvp.model;
import java.io.Serializable;
public class VedioBean implements Serializable {
private String thirdId;//穿山甲id
private int createType;//类型,1,自有剧,2 穿山甲
private String title;
private String type;
private String topTabsReamrk;
private Object orderTags;
private int vedioTotal;//同穿山甲 total
private String vedioDesc;
private String coverImage;
private int completeStatus;//完结状态 同穿山接status 0-完结
private String scriptName;
private String scriptAuthor;
private int vedioId;// 视频id,服务器标识
public String getThirdId() {
return thirdId;
}
public void setThirdId(String thirdId) {
this.thirdId = thirdId;
}
public int getCreateType() {
return createType;
}
public void setCreateType(int createType) {
this.createType = createType;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getTopTabsReamrk() {
return topTabsReamrk;
}
public void setTopTabsReamrk(String topTabsReamrk) {
this.topTabsReamrk = topTabsReamrk;
}
public Object getOrderTags() {
return orderTags;
}
public void setOrderTags(Object orderTags) {
this.orderTags = orderTags;
}
public int getVedioTotal() {
return vedioTotal;
}
public void setVedioTotal(int vedioTotal) {
this.vedioTotal = vedioTotal;
}
public String getVedioDesc() {
return vedioDesc;
}
public void setVedioDesc(String vedioDesc) {
this.vedioDesc = vedioDesc;
}
public String getCoverImage() {
return coverImage;
}
public void setCoverImage(String coverImage) {
this.coverImage = coverImage;
}
public int getCompleteStatus() {
return completeStatus;
}
public void setCompleteStatus(int completeStatus) {
this.completeStatus = completeStatus;
}
public String getScriptName() {
return scriptName;
}
public void setScriptName(String scriptName) {
this.scriptName = scriptName;
}
public String getScriptAuthor() {
return scriptAuthor;
}
public void setScriptAuthor(String scriptAuthor) {
this.scriptAuthor = scriptAuthor;
}
public int getVedioId() {
return vedioId;
}
public void setVedioId(int vedioId) {
this.vedioId = vedioId;
}
}
......@@ -44,6 +44,66 @@ class HomePresenter : BasePresenter<HomeView>() {
})
}
fun topTabs() {
AppHttpManager.getInstance(loanApplication)
.call(loanService.topTabs(),
object : BaseSubscriber<BaseResponse<BannerList>>() {
override fun onCompleted() {
if (isLinkView) return
}
override fun onError(e: Throwable) {
if (isLinkView) return
}
override fun onNext(baseResponse: BaseResponse<BannerList>) {
if (isLinkView) return
val code = baseResponse.status
val message = baseResponse.message
when (code) {
200 -> {
view.topTabsSuc(baseResponse.data)
}
else -> {
view.showToast(message)
}
}
}
})
}
fun orders() {
AppHttpManager.getInstance(loanApplication)
.call(loanService.orders(),
object : BaseSubscriber<BaseResponse<BannerList>>() {
override fun onCompleted() {
if (isLinkView) return
}
override fun onError(e: Throwable) {
if (isLinkView) return
}
override fun onNext(baseResponse: BaseResponse<BannerList>) {
if (isLinkView) return
val code = baseResponse.status
val message = baseResponse.message
when (code) {
200 -> {
view.ordersSuc(baseResponse.data)
}
else -> {
view.showToast(message)
}
}
}
})
}
/**
* 游客登录
*/
......@@ -115,7 +175,11 @@ class HomePresenter : BasePresenter<HomeView>() {
if (isLinkView) return
val code = baseResponse.status
when (code) {
200 -> getHomeV1Types()
200 -> {
getHomeV1Types()
topTabs()
orders()
}
}
}
})
......
package com.mints.wisdomclean.mvp.views
import com.mints.wisdomclean.mvp.model.BannerList
import com.mints.wisdomclean.mvp.model.HotStyleTypesListBean
interface HomeView : BaseView {
fun getHomeV1MsgSuc(data: HotStyleTypesListBean)
fun topTabsSuc(data: BannerList)
fun ordersSuc(data: BannerList)
}
......@@ -5,9 +5,9 @@ import android.text.TextUtils;
import com.google.gson.JsonObject;
import com.mints.wisdomclean.BuildConfig;
import com.mints.wisdomclean.mvp.model.BannerList;
import com.mints.wisdomclean.mvp.model.BaseResponse;
import com.mints.wisdomclean.mvp.model.HotStyleListBean;
import com.mints.wisdomclean.mvp.model.HotStyleMsgBean;
import com.mints.wisdomclean.mvp.model.HotStyleTypesListBean;
import com.mints.wisdomclean.mvp.model.OrderRecordBean;
import com.mints.wisdomclean.mvp.model.UserBean;
......@@ -165,7 +165,7 @@ public interface LoanService {
*
* @return
*/
@POST("api/ai/homeV1Types")
@POST("api/vedio/types")
Observable<BaseResponse<HotStyleTypesListBean>> getHomeV1Types();
/**
......@@ -184,6 +184,22 @@ public interface LoanService {
@POST("api/feedback")
Observable<BaseResponse<Object>> feedback(@Body Map<String, Object> vo);
/**
* 轮播图
*
* @return
*/
@POST("api/vedio/topTabs")
Observable<BaseResponse<BannerList>> topTabs();
/**
* 排行榜
*
* @return
*/
@POST("api/vedio/orders")
Observable<BaseResponse<BannerList>> orders();
/**
* 默认http工厂
*/
......
......@@ -14,7 +14,7 @@ class HomeVideoPageAdapter(
private val fragments = mutableMapOf<Int, Fragment>()
override fun getItemId(position: Int): Long {
return data[position].id.toLong()
return data[position].torder.toLong()
}
override fun getItemCount() = data.size
......@@ -23,14 +23,14 @@ class HomeVideoPageAdapter(
val fragment = fragments[position]
if (fragment != null) return fragment
val newFragment = MovieFragment.newInstance(data[position].id,position)
val newFragment = MovieFragment.newInstance(data[position].torder,position)
fragments[position] = newFragment
return newFragment
}
override fun containsItem(itemId: Long): Boolean {
data.forEach {
if (it.id.toLong() == itemId) {
if (it.torder.toLong() == itemId) {
return true
}
}
......
......@@ -10,9 +10,9 @@ import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.mints.library.utils.GlideUtils
import com.mints.wisdomclean.R
import com.mints.wisdomclean.mvp.model.VipBean
import com.mints.wisdomclean.mvp.model.VedioBean
class TopAdapter(val vipList: MutableList<VipBean.ListBean>?) :
class TopAdapter(val topList: MutableList<VedioBean>?) :
RecyclerView.Adapter<TopAdapter.ViewHolder>() {
lateinit var context: Context
......@@ -36,9 +36,13 @@ class TopAdapter(val vipList: MutableList<VipBean.ListBean>?) :
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
// val vipBean = vipList[position]
// val topBean = topList[position]
holder.tvTopItemLable.text = "${position + 1}"
GlideUtils.loadImageViewGifForFitCenter(context,"https://mints-pkg.oss-cn-beijing.aliyuncs.com/pkg-bcurd/img/bg_vip_top1.png",holder.ivTopItem)
GlideUtils.loadImageViewGifForFitCenter(
context,
"https://mints-pkg.oss-cn-beijing.aliyuncs.com/pkg-bcurd/img/bg_vip_top1.png",
holder.ivTopItem
)
when (position) {
......@@ -64,8 +68,7 @@ class TopAdapter(val vipList: MutableList<VipBean.ListBean>?) :
holder.itemView.setTag(position)
}
// override fun getItemCount() = vipList?.size
override fun getItemCount() = 20
override fun getItemCount() = topList?.size ?: 0
interface OnItemClickListener {
fun onItemClick(position: Int)
......
......@@ -17,10 +17,7 @@ import com.mints.wisdomclean.common.AppConfig
import com.mints.wisdomclean.common.Constant
import com.mints.wisdomclean.manager.LocalVedioManager
import com.mints.wisdomclean.manager.UserManager
import com.mints.wisdomclean.mvp.model.BannerBean
import com.mints.wisdomclean.mvp.model.HotStyleTypesBean
import com.mints.wisdomclean.mvp.model.HotStyleTypesListBean
import com.mints.wisdomclean.mvp.model.UserBean
import com.mints.wisdomclean.mvp.model.*
import com.mints.wisdomclean.mvp.presenters.HomePresenter
import com.mints.wisdomclean.mvp.views.HomeView
import com.mints.wisdomclean.ui.adapter.HomeVideoPageAdapter
......@@ -46,15 +43,10 @@ import kotlin.concurrent.schedule
*/
class MainFragment : LazyLoadBaseFragment(), HomeView, View.OnClickListener, OnRefreshListener {
var imageUrls = listOf(
"http://static.mints-pkg.mints-id.com/pkg-bcurd/bg_main_banner23.png",
"http://static.mints-pkg.mints-id.com/pkg-bcurd/bg_main_banner21.png",
"http://static.mints-pkg.mints-id.com/pkg-bcurd/bg_main_banner24.png"
)
private var mSelectTabIndex = -1
private val tabsData = mutableListOf<HotStyleTypesBean>()
private val bannerList = mutableListOf<BannerBean>()
private val topList = mutableListOf<VedioBean>()
private var vpAdapter: HomeVideoPageAdapter? = null
private var topAdapter: TopAdapter? = null
......@@ -68,7 +60,6 @@ class MainFragment : LazyLoadBaseFragment(), HomeView, View.OnClickListener, OnR
}
override fun onFragmentFirstVisible() {
initView()
initVp()
initListener()
loadData()
......@@ -96,21 +87,6 @@ class MainFragment : LazyLoadBaseFragment(), HomeView, View.OnClickListener, OnR
banner?.stop()
}
private fun initView() {
for (i in 0 until imageUrls.size) {
val bean = BannerBean()
bean.title = "天师下山各显神勇" + i
bean.imageRes = imageUrls.get(i)
bannerList.add(bean)
}
banner.addBannerLifecycleObserver(this)
.setAdapter(ImageTitleAdapter(bannerList))
.setOnBannerListener { data, position ->
showToast(position.toString())
}
}
private fun initListener() {
srlMainPage.setOnRefreshListener(this)
iv_main_watching_close.setOnClickListener(this)
......@@ -121,9 +97,6 @@ class MainFragment : LazyLoadBaseFragment(), HomeView, View.OnClickListener, OnR
if (AntiShake.check(v?.id)) return
when (v?.id) {
// R.id.tv_test -> {
// readyGo(VideoActivity::class.java)
// }
R.id.iv_main_watching_close -> {
LocalVedioManager.closeCacheVedio()
ll_main_watching_root.visibility = View.GONE
......@@ -131,7 +104,7 @@ class MainFragment : LazyLoadBaseFragment(), HomeView, View.OnClickListener, OnR
R.id.tv_main_watching_goto -> {
val cacheVedio = LocalVedioManager.getCacheVedio()
if (cacheVedio != null) {
LocalVedioManager.startVedioDetailActivityForType(requireActivity(), null)
}
}
}
......@@ -148,20 +121,22 @@ class MainFragment : LazyLoadBaseFragment(), HomeView, View.OnClickListener, OnR
homePresenter.userLogin()
} else {
homePresenter.getHomeV1Types()
homePresenter.topTabs()
homePresenter.orders()
}
}
}
}
private fun initVp() {
topAdapter = TopAdapter(null)
topAdapter = TopAdapter(topList)
val ma = LinearLayoutManager(requireContext())
ma.orientation = LinearLayoutManager.HORIZONTAL
rv_main_list.layoutManager = ma
rv_main_list.adapter = topAdapter
topAdapter?.setOnItemClickListener(object : TopAdapter.OnItemClickListener {
override fun onItemClick(position: Int) {
showToast(position.toString())
LocalVedioManager.startVedioDetailActivityForType(requireActivity(), null)
}
})
......@@ -172,7 +147,7 @@ class MainFragment : LazyLoadBaseFragment(), HomeView, View.OnClickListener, OnR
// 初始化Tab
tab.id = position
if (tabsData.size > 0) {
tab.customView = getTabView(tabsData[position].title)
tab.customView = getTabView(tabsData[position].type)
}
}.attach()
tablayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
......@@ -221,24 +196,24 @@ class MainFragment : LazyLoadBaseFragment(), HomeView, View.OnClickListener, OnR
}
fun setWatchingStatus() {
if (LocalVedioManager.isCacheVedio()) {
ll_main_watching_root.visibility = View.VISIBLE
val cacheVedio = LocalVedioManager.getCacheVedio()
if (cacheVedio != null) {
// if (LocalVedioManager.isCacheVedio()) {
ll_main_watching_root.visibility = View.VISIBLE
val cacheVedio = LocalVedioManager.getCacheVedio()
if (cacheVedio != null) {
}
}
GlideUtils.loadImageViewGifForFitCenter(
requireContext(),
"https://mints-pkg.oss-cn-beijing.aliyuncs.com/pkg-bcurd/img/bg_vip_top1.png",
iv_main_watching_pic
)
GlideUtils.loadImageViewGifForFitCenter(
requireContext(),
"https://mints-pkg.oss-cn-beijing.aliyuncs.com/pkg-bcurd/img/bg_vip_top1.png",
iv_main_watching_pic
)
// tv_main_watching_name.text=""
// tv_main_watching_text1.text=""
// tv_main_watching_text2.text=""
} else {
ll_main_watching_root.visibility = View.GONE
}
// } else {
// ll_main_watching_root.visibility = View.GONE
// }
}
override fun getHomeV1MsgSuc(data: HotStyleTypesListBean) {
......@@ -249,4 +224,28 @@ class MainFragment : LazyLoadBaseFragment(), HomeView, View.OnClickListener, OnR
vpAdapter?.notifyDataSetChanged()
}
}
override fun topTabsSuc(data: BannerList) {
if (data != null && data.list != null && data.list.size > 0) {
bannerList.clear()
for (i in 0 until data.list.size) {
val bean = BannerBean()
bean.title = data.list.get(i).title
bean.imageRes = data.list.get(i).coverImage
bannerList.add(bean)
}
banner.addBannerLifecycleObserver(this)
.setAdapter(ImageTitleAdapter(bannerList))
.setOnBannerListener { data, position ->
LocalVedioManager.startVedioDetailActivityForType(requireActivity(), null)
}
}
}
override fun ordersSuc(data: BannerList) {
topList.clear()
topList.addAll(data.list)
topAdapter?.notifyDataSetChanged()
}
}
\ No newline at end of file
......@@ -6,6 +6,7 @@ import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.GridLayoutManager
import com.mints.wisdomclean.R
import com.mints.wisdomclean.common.Constant
import com.mints.wisdomclean.manager.LocalVedioManager
import com.mints.wisdomclean.mvp.model.*
import com.mints.wisdomclean.mvp.presenters.PicContentPresenter
import com.mints.wisdomclean.mvp.views.PicContentView
......@@ -123,7 +124,8 @@ class MovieFragment : LazyLoadBaseFragment(), PicContentView, OnLoadMoreListener
// if (hotList.size > 0) {
//
// }
showToast(position.toString())
LocalVedioManager.startVedioDetailActivityForType(requireActivity(),null)
// showToast(position.toString())
}
})
}
......
......@@ -74,7 +74,7 @@ class MyFragment : BaseFragment(), MyView, View.OnClickListener {
R.id.ll_my_setting -> {
readyGo(SettingsActivity::class.java)
}
R.id.tv_my_account -> {
R.id.tv_my_account ,R.id.ll_my_login-> {
if (!userManager.userIsLogin()) {
readyGo(MobileLoginActivity::class.java)
}
......@@ -132,6 +132,7 @@ class MyFragment : BaseFragment(), MyView, View.OnClickListener {
}
private fun initListener() {
ll_my_login.setOnClickListener(this)
tv_my_btn.setOnClickListener(this)
tv_my_account.setOnClickListener(this)
ll_my_record.setOnClickListener(this)
......
......@@ -205,12 +205,11 @@
<ImageView
android:id="@+id/iv_main_watching_close"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginTop="4dp"
android:layout_marginRight="4dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_alignParentRight="true"
android:src="@mipmap/ic_activity_quit"></ImageView>
android:src="@mipmap/ic_quit_white"></ImageView>
<TextView
android:id="@+id/tv_main_watching_goto"
......
......@@ -31,6 +31,7 @@
android:orientation="vertical">
<LinearLayout
android:id="@+id/ll_my_login"
android:layout_marginTop="56dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment