Commit 86f23be6 by konghaorui

Merge branch 'feature/v3' of…

Merge branch 'feature/v3' of ssh://gitlab.yidianling.com:2224/app_android_lib/YDL-Component into feature/v3
parents 600d1acd 5ea2e0ca
......@@ -11,7 +11,4 @@
android:name="com.yidianling.home.ui.fragment.YdlHomeFragment"
/>
</LinearLayout>
\ No newline at end of file
......@@ -48,6 +48,17 @@ android {
targetCompatibility 1.8
}
sourceSets {
main {
res.srcDirs = [
'src/main/res',
'src/main/res/layouts',
'src/main/res/layouts/ydlhome', //壹点零用户版首页fragment所在xml
'src/main/res/layouts/ydlhome/holder', //壹点零用户版首页fragment中列表ViewHolder所在xml
]
}
}
}
dependencies {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
package com.yidianling.home.constants
import android.content.Context
import com.ydl.ydlcommon.data.http.BaseAPIResponse
import com.ydl.ydlcommon.mvp.base.IModel
import com.ydl.ydlcommon.mvp.base.IPresenter
import com.ydl.ydlcommon.mvp.base.IView
import com.yidianling.home.model.bean.*
import io.reactivex.Observable
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 壹点灵首页约束类
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/13
*/
class IHomeBaseContract {
interface View : IView {
/**
* 首页数据回调接口
*/
fun homeDataResponse(list: MutableList<HomePagerDataBean>)
/**
* 头部数据回调
*/
fun homeHeadResponse(homeHeaderBean: HomeHeaderBean)
/**
* 首页数据请求失败接口
*/
fun homeDataFail(msg: String)
/**
* 获取倾述数据回调
*/
fun confideDataResponse(data: HomeConfideBean, selectPosition: Int)
/**
* 获取咨询数据回调
*/
fun consultDataResponse(data: HomeConsultBean, selectPosition: Int)
/**
* 问答模块数据回调
*/
fun askDataResponse(data: HomeAskBean, position: Int)
/**
* 首页问答 - 点赞
*/
fun askZan(position: Int, index: Int, id: String)
/**
* 首页问答 - 关注
*/
fun askFocus(position: Int, id: String)
/**
* 获取倾述列表数据
* @param type 倾述类型
* @param selectPosition 选中的position
*/
fun getConfideData(type: String, selectPosition: Int)
/**
* 获取咨询列表数据
*/
fun getConsultData(type: String, selectPosition: Int)
fun showHomeProgress()
fun showRefreshLayout()
fun dismissHomeProgress()
fun resetModuleTabPosition()
}
interface Presenter<V : IView> : IPresenter<V> {
/**
* 获取首页本地缓存
*/
fun localHomeData(context: Context, fileName: String)
/**
* 刷新首页数据请求
*/
fun refreshHomeData()
/**
* 获取首页数据请求
*/
fun loadHomeData()
/**
*获取倾述列表
*/
fun getConfideData(type: String, selectPosition: Int)
/**
*获取咨询列表
*/
fun getConsultData(type: String, selectPosition: Int)
/**
* 首页问答 - 点赞
*/
fun askZan(position: Int, index: Int, id: String)
/**
* 首页问答 - 关注
*/
fun askFocus(position: Int, id: String)
/**
* 保存临时数据
*/
fun saveTempData(list: MutableList<HomePagerDataBean>)
/**
* 获取临时数据
*/
fun getHomeItemFromTempData(dataBean: HomeItemBaseBean, type: Int): Any
}
interface Model : IModel {
/**
* 首页头部 分类&Banner请求
*/
fun headerRequest(): Observable<HomeHeaderBean>
/**
* 首页电台请求
*/
fun fmRequest(): Observable<HomeFMBean>
/**
* 首页课程请求
*/
fun courseRequest(): Observable<HomeCourseBean>
/**
* 首页测试题请求
*/
fun testRequest(): Observable<BaseAPIResponse<MutableList<HomeTestItemBean>>>
/**
* 首页咨询请求
*/
fun consultRequest(category: String): Observable<HomeConsultBean>
/**
* 首页倾听请求
*/
fun confideRequest(goodType: String): Observable<HomeConfideBean>
/**
* 首页问答请求
*/
fun askRequest(): Observable<HomeAskBean>
/**
* 首页文章请求
*/
fun articleRequest(): Observable<HomeArticleBean>
/**
* 首页问答 - 点赞
*/
fun askZan(id: String): Observable<AskResultBean>
/**
* 首页问答 - 关注
*/
fun askFocus(id: String): Observable<AskResultBean>
}
}
\ No newline at end of file
package com.yidianling.home.event
import android.support.v7.widget.RecyclerView
import android.view.View
import android.widget.ImageView
import com.yidianling.home.model.bean.*
import com.yidianling.home.ui.view.CouponDialog
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 首页点击事件接口类
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/13
*/
interface IHomeBaseEvent {
/**
* 服务电话点击事件
*/
fun serviceCallClick()
/**
* 动态编辑按钮点击
*/
fun publishTrendClick()
/**
* 咨询条目点击事件
*/
fun consultItemClick(linkUrl: String?, doctorId: String)
/**
* 咨询私聊点击事件
*/
fun consultChatClick(doctorId: String?)
/**
* 测试条目点击事件
*/
fun testItemClick(linkUrl: String?)
/**
* 测试更多点击事件
*/
fun testMoreClick()
/**
* 咨询更多点击事件
*/
fun consultMoreClick()
/**
* 搜索框点击事件
*/
fun searchTvClick(text:String)
/**
* 列表滚动事件
*/
fun onPageScroll(view_rl_top_bg: View): RecyclerView.OnScrollListener?
/**
* 跳转链接点击
* Banner & 首页分类 & 首页条目 使用
*/
fun linkTo(linkUrl: String)
/**
* banner点击跳转
*/
fun bannerClick(banner:HomeHeaderBean.FocusListBean)
/**
* 首页分类跳转
*/
fun categoryClick(category: HomeHeaderBean.AskCategoryDataBean)
/**
* 预约专家点击事件
*/
fun reservationExpertsClick()
/**
* 即可倾诉点击事件
*/
fun nowConfideClick()
/**
* 心理课堂点击事件
*/
fun psychologyClassClick()
/**
* 心理测试点击事件
*/
fun psychologyTestClick()
/**
* 倾诉更多点击事件
*/
fun confideMoreClick()
/**
* 倾述咨询师点击
* @param linkUrl 跳转地址
*/
fun confideClick(linkUrl: String?, doctorId: Int)
/**
* 私聊
*/
fun toChatForMsg(doctorId: String?)
/**
* 课程item点击事件
*/
fun courseItemClick(bean: HomeCourseBean.ListBean)
/**
* 课程更多点击事件
*/
fun courseMreClick()
/**
* 问答条目关注点击事件
* @param id : 用户uid
*/
fun askItemFocusClick(position:Int,id: String)
/**
* 问答条目点赞事件
* @param id : 动态id
*/
fun askItemZanClick(position:Int,index:Int,id: String)
/**
* 问答更多点击事件
*/
fun askMoreClick()
/**
* 问答条目点击事件
*/
fun askItemClick(bean:HomeAskBean.DataBean)
/**
* 电台条目点击播放事件
*/
fun fmPlayClick(bean: HomeFMBean.ListBean)
/**
* 电台条目点击进入详情
*/
fun fmItemClick(bean: HomeFMBean.ListBean)
/**
* 电台更多点击事件
*/
fun fmMoreClick()
/**
* 文章更多点击事件
*/
fun articleMoreClick()
/**
* 文章item点击事件
*/
fun articleItemClick(bean: HomeArticleBean.Bean?)
/**
* 获取倾述列表数据
* 最终调用
* @see com.yidianling.home.ui.fragment.YdlHomeFragment.getConfideData
*
* @param type 倾述类型
* @param selectPosition 选中的position
*/
fun getConfideData(type: HomeHeaderBean.ListenCategoryDateBean, selectPosition: Int)
/**
* 获取咨询列表数据
* 最终调用
* @see com.yidianling.home.ui.fragment.YdlHomeFragment.getConsultData
*
* @param type 类型
* @param selectPosition 选中的position
*/
fun getConsultData(type: HomeHeaderBean.ConsultCategoryDateBean, selectPosition: Int)
}
\ No newline at end of file
package com.yidianling.home.http
import com.ydl.ydlcommon.data.http.BaseAPIResponse
import com.ydl.ydlcommon.data.http.BaseResponse
import com.ydl.ydlcommon.data.http.RxUtils
import com.ydl.ydlcommon.modular.ModularServiceManager
import com.ydl.ydlnet.YDLHttpUtils
import com.yidianling.home.model.bean.*
import com.yidianling.user.api.service.IUserService
import io.reactivex.Observable
class HomeBaseHttp {
companion object {
fun getInstance(): HomeBaseHttp {
return Holder.INSTANCE
}
}
object Holder {
val INSTANCE = HomeBaseHttp()
}
private var homeApi: HomeBasePagerApi? = null
fun getHomePagerApi(): HomeBasePagerApi {
if (homeApi == null) {
homeApi = YDLHttpUtils.obtainApi(HomeBasePagerApi::class.java)
}
return homeApi!!
}
//首页头部 分类&Banner 请求
fun newHomeHeaderRequest(): Observable<BaseAPIResponse<HomeHeaderBean>> {
return getHomePagerApi().getHomeHeaderData()
}
//首页倾述请求
fun getConfideData(goodType: String): Observable<BaseAPIResponse<HomeConfideBean>> {
val loginBean = ModularServiceManager.provide(IUserService::class.java).getUserInfo()
var userId = loginBean?.uid ?: "";
return getHomePagerApi().getConfideData(goodType, uid = userId);
}
//首页课程请求
fun getCourseData(listType: String = "10"): Observable<BaseAPIResponse<HomeCourseBean>> {
val loginBean = ModularServiceManager.provide(IUserService::class.java).getUserInfo()
var userId = loginBean?.uid ?: "";
return getHomePagerApi().getCourseData(listType, uid = userId);
}
//首页测试请求
fun getTestData(): Observable<BaseAPIResponse<MutableList<HomeTestItemBean>>> {
val loginBean = ModularServiceManager.provide(IUserService::class.java).getUserInfo()
var userId = loginBean?.uid ?: "";
return getHomePagerApi().getTestData(uid = userId)
}
//首页问答请求
fun getAskData(): Observable<BaseAPIResponse<HomeAskBean>> {
val loginBean = ModularServiceManager.provide(IUserService::class.java).getUserInfo()
var userId = loginBean?.uid ?: "";
var token = loginBean?.accessToken ?: "";
return getHomePagerApi().getAskData(accessToken = token, uid = userId);
}
//首页电台请求
fun getFMData(): Observable<BaseAPIResponse<HomeFMBean>> {
return getHomePagerApi().getFMData();
}
//首页文章请求
fun getArticleData(perPageRows: String = "4"): Observable<BaseAPIResponse<HomeArticleBean>> {
return getHomePagerApi().getArticleData()
}
//首页咨询请求
fun getConsultData(goodType: String): Observable<BaseAPIResponse<HomeConsultBean>> {
val loginBean = ModularServiceManager.provide(IUserService::class.java).getUserInfo()
var userId = loginBean?.uid ?: ""
return getHomePagerApi().getConsultData(category = goodType, uid = userId)
}
//首页问答 - 点赞
fun askZan(id: String): Observable<BaseResponse<AskResultBean>> {
val cmd = AskRequestParamBean.ZanAction("2", id)
return RxUtils.mapObservable(cmd).flatMap { getHomePagerApi().askZan(it) }
}
//首页问答 - 关注
fun askFocus(id: String): Observable<BaseResponse<AskResultBean>> {
val cmd = AskRequestParamBean.FocusCmd(id, "1")
return RxUtils.mapObservable(cmd).flatMap { getHomePagerApi().askFocus(it) }
}
}
\ No newline at end of file
package com.yidianling.home.http
import com.ydl.ydlcommon.base.BaseApp
import com.ydl.ydlcommon.base.config.YDL_DOMAIN
import com.ydl.ydlcommon.base.config.YDL_DOMAIN_JAVA
import com.ydl.ydlcommon.data.PlatformDataManager
import com.ydl.ydlcommon.data.http.BaseAPIResponse
import com.ydl.ydlcommon.data.http.BaseResponse
import com.yidianling.common.tools.RxDeviceTool
import com.yidianling.home.model.bean.*
import io.reactivex.Observable
import retrofit2.http.*
/**
* @author jiucheng
* @描述:首页接口api
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/8/22
*/
interface HomeBasePagerApi {
/**
* 首页头部数据 Banner&分类
*/
@GET("home/index")
@Headers(YDL_DOMAIN + YDL_DOMAIN_JAVA)
fun getHomeHeaderData(): Observable<BaseAPIResponse<HomeHeaderBean>>
/**
* 首页咨询请求
* goodType 为空或不传 则获取默认类型数据
*/
@GET("doctor/list")
@Headers(YDL_DOMAIN + YDL_DOMAIN_JAVA)
fun getConsultData(
@Query("categories") category: String,
@Query("limit") limit: String = "3",
@Query("page") page: String = "1",
@Query("uid") uid: String,
@Query("searchWord") searchWord: String = "",
@Query("showType") showType: String = "0",
@Query("ffrom") ffrom: String = PlatformDataManager.getRam().getChannelName(),
@Query("version") version: String = RxDeviceTool.getAppVersionName(BaseApp.getApp())
): Observable<BaseAPIResponse<HomeConsultBean>>
/**
* 首页倾述请求
* goodType 为空或不传 则获取默认类型数据
*/
@GET("auth/listen/search")
@Headers(YDL_DOMAIN + YDL_DOMAIN_JAVA)
fun getConfideData(
@Query("goodType") goodType: String,
@Query("limit") limit: String = "3",
@Query("page") page: String = "1",
// 1: 查询第一个类型列表,较goodType比,低优先级
@Query("isDefaultType") isDefaultType: String = "1",
@Query("uid") uid: String,
@Query("ffrom") ffrom: String = PlatformDataManager.getRam().getChannelName(),
@Query("version") version: String = RxDeviceTool.getAppVersionName(BaseApp.getApp())
): Observable<BaseAPIResponse<HomeConfideBean>>
//首页课程请求
@GET("auth/course/getList")
@Headers(YDL_DOMAIN + YDL_DOMAIN_JAVA)
fun getCourseData(
@Query("listType") listType: String = "10",
@Query("limit") limit: String = "3",
@Query("uid") uid: String,
@Query("ffrom") ffrom: String = PlatformDataManager.getRam().getChannelName(),
@Query("version") version: String = RxDeviceTool.getAppVersionName(BaseApp.getApp())
): Observable<BaseAPIResponse<HomeCourseBean>>
//首页测试请求
@GET("test-item/home-recommend")
@Headers(YDL_DOMAIN + YDL_DOMAIN_JAVA)
fun getTestData(
@Query("uid") uid: String,
@Query("ffrom") ffrom: String = PlatformDataManager.getRam().getChannelName(),
@Query("version") version: String = RxDeviceTool.getAppVersionName(BaseApp.getApp())
): Observable<BaseAPIResponse<MutableList<HomeTestItemBean>>>
//首页问答请求
@GET("ask/list-old")
@Headers(YDL_DOMAIN + YDL_DOMAIN_JAVA)
fun getAskData(
@Query("perPageRows") perPageRows: String = "6",
@Query("tab") tab: String = "2",
@Query("accessToken") accessToken: String,
@Query("uid") uid: String
): Observable<BaseAPIResponse<HomeAskBean>>
//首页电台请求
@GET("fm/list/all")
@Headers(YDL_DOMAIN + YDL_DOMAIN_JAVA)
fun getFMData(@Query("perPageRows") perPageRows: String = "4"): Observable<BaseAPIResponse<HomeFMBean>>
//首页文章请求
@GET("article/list/all")
@Headers(YDL_DOMAIN + YDL_DOMAIN_JAVA)
fun getArticleData(@Query("perPageRows") perPageRows: String = "4"): Observable<BaseAPIResponse<HomeArticleBean>>
//首页问答 - 点赞
@FormUrlEncoded
@POST("sq-active/zan")
fun askZan(@FieldMap params: Map<String, String>): Observable<BaseResponse<AskResultBean>>
//首页问答 - 关注
@FormUrlEncoded
@POST("sq-active/focus")
fun askFocus(@FieldMap params: Map<String, String>): Observable<BaseResponse<AskResultBean>>
}
\ No newline at end of file
package com.yidianling.home.model
import com.ydl.ydlcommon.data.http.BaseAPIResponse
import com.ydl.ydlcommon.data.http.RxUtils
import com.yidianling.home.constants.IHomeBaseContract
import com.yidianling.home.http.HomeBaseHttp
import com.yidianling.home.model.bean.*
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
open class BaseHomeModelImpl : IHomeBaseContract.Model {
/**
* 首页咨询请求
*/
override fun consultRequest(category: String): Observable<HomeConsultBean> {
return HomeBaseHttp.getInstance().getConsultData(category).compose(RxUtils.resultJavaData())
.subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread())
.onErrorReturn { HomeConsultBean(true) }
}
/**
* 首页问答 - 点赞
*/
override fun askZan(id: String): Observable<AskResultBean> {
return HomeBaseHttp.getInstance().askZan(id).compose(RxUtils.resultData())
}
/**
* 首页问答 - 关注
*/
override fun askFocus(id: String): Observable<AskResultBean> {
return HomeBaseHttp.getInstance().askFocus(id).compose(RxUtils.resultData())
}
/**
* 首页电台请求
*/
override fun fmRequest(): Observable<HomeFMBean> {
return HomeBaseHttp.getInstance().getFMData().compose(RxUtils.resultJavaData())
.onErrorReturn { HomeFMBean(true) }
}
/**
* 首页课程请求
*/
override fun courseRequest(): Observable<HomeCourseBean> {
return HomeBaseHttp.getInstance().getCourseData().compose(RxUtils.resultJavaData())
.subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread())
.onErrorReturn { HomeCourseBean(true) }
}
/**
* 首页测试题请求
*/
override fun testRequest(): Observable<BaseAPIResponse<MutableList<HomeTestItemBean>>> {
return HomeBaseHttp.getInstance().getTestData()
}
/**
* 首页倾听请求
*/
override fun confideRequest(goodType: String): Observable<HomeConfideBean> {
return HomeBaseHttp.getInstance().getConfideData(goodType).compose(RxUtils.resultJavaData())
.subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread())
.onErrorReturn { HomeConfideBean(true) }
}
/**
* 首页问答请求
*/
override fun askRequest(): Observable<HomeAskBean> {
return HomeBaseHttp.getInstance().getAskData().compose(RxUtils.resultJavaData())
.subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread())
.onErrorReturn { HomeAskBean(true) }
}
/**
* 首页文章请求
*/
override fun articleRequest(): Observable<HomeArticleBean> {
return HomeBaseHttp.getInstance().getArticleData().compose(RxUtils.resultJavaData())
.subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread())
.onErrorReturn { HomeArticleBean(true) }
}
/**
* 首页头部 分类&Banner请求
*/
override fun headerRequest(): Observable<HomeHeaderBean> {
return HomeBaseHttp.getInstance().newHomeHeaderRequest().compose(RxUtils.resultJavaData())
.subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread())
.onErrorReturn { HomeHeaderBean(true) }
}
}
\ No newline at end of file
package com.yidianling.home.model.bean;
import com.ydl.ydlcommon.data.http.BaseCommand;
/**
......@@ -32,3 +33,4 @@ public class AskRequestParamBean {
}
}
......@@ -41,7 +41,7 @@ class HomeConfideBean : HomeItemBaseBean {
/**
* 实际费用
*/
var confideFee: String? =null
var confideFee: String = "0"
/**
* 接通率
*/
......@@ -57,7 +57,7 @@ class HomeConfideBean : HomeItemBaseBean {
/**
* 红包金额
*/
var couponMoney: String? = null
var couponMoney: String = "0"
var confidedTag: List<String>? = null
/**
* 红包展示文本
......
......@@ -80,6 +80,9 @@ class HomeConsultBean: HomeItemBaseBean {
var isHiddenXcx: String? = null
var tags: String? = null
//私聊文案
var chatBtnText: String? = null
class ShareBean {
/**
* title : 姜建萍咨询工作室
......
package com.yidianling.home.presenter
import android.annotation.SuppressLint
import android.content.Context
import android.text.TextUtils
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.ydl.ydlcommon.base.BaseApp
import com.ydl.ydlcommon.data.http.RxUtils
import com.ydl.ydlcommon.data.http.ThrowableConsumer
import com.ydl.ydlcommon.mvp.base.BasePresenter
import com.ydl.ydlcommon.mvp.base.IModel
import com.ydl.ydlcommon.mvp.base.IView
import com.ydl.ydlcommon.utils.SharedPreferencesEditor
import com.ydl.ydlcommon.utils.YDLAsyncUtils
import com.yidianling.common.tools.RxAppTool
import com.yidianling.home.constants.IHomeBaseContract
import com.yidianling.home.model.bean.HomeAskBean
import com.yidianling.home.model.bean.HomeItemBaseBean
import com.yidianling.home.model.bean.HomePagerDataBean
import com.yidianling.home.utils.HomeFileUtils
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.functions.Consumer
import io.reactivex.schedulers.Schedulers
abstract class BaseHomePresenterImpl< V : IHomeBaseContract.View,M : IHomeBaseContract.Model>:
BasePresenter< V, M>(), IHomeBaseContract.Presenter<V> {
abstract override fun createModel(): M
/**
* 获取首页数据请求
*/
abstract override fun loadHomeData()
/**
* 保存临时数据
*/
abstract override fun saveTempData(list: MutableList<HomePagerDataBean>)
/**
* 获取临时数据
*/
abstract override fun getHomeItemFromTempData(dataBean: HomeItemBaseBean, type: Int): Any
/**
* 刷新首页数据请求
*/
abstract override fun refreshHomeData()
var CACHE_HOME_PAGER_DATA = "cache_home_pager_data"
//首页json文件和缓存数据结构不一致时临时使用
var IS_NEW_CACHE_HOME_PAGER_DATA = "IS_NEW_CACHE_HOME_PAGER_DATA"
//首页缓存版本号
var HOME_PAGER_DATA_CACHE_VERISON = "HOME_PAGER_DATA_CACHE_VERISON"
private var mConsultDisposable: Disposable? = null
private var mConfideDisposable: Disposable? = null
private var mHomeDisposable: Disposable? = null
var mConfideType: String = ""
var mConsultType: String = ""
@Volatile
var mHomeAskBean: HomeAskBean? = null
//首页数据缓存
var homeTempData: HomePagerDataBean = HomePagerDataBean()
/**
* 加载本地缓存
*/
override fun localHomeData(context: Context, fileName: String) {
YDLAsyncUtils.asyncAsResult(object : YDLAsyncUtils.AsyncObjecyerResult {
override fun doAsyncAction(): Any {
//首页缓存数据
var cacheHomeData: String
//是否为新的数据结构
val isNewPageData = SharedPreferencesEditor.getString(IS_NEW_CACHE_HOME_PAGER_DATA)
val homeCacheVersion =
SharedPreferencesEditor.getString(HOME_PAGER_DATA_CACHE_VERISON)
val appVersionCode = RxAppTool.getAppVersionCode(BaseApp.getApp())
//版本更新后不使用上个版本的首页缓存
cacheHomeData = if (isNewPageData.isEmpty() || (!TextUtils.isEmpty(homeCacheVersion) && appVersionCode > homeCacheVersion.toInt())) {
""
} else {
//上次首页缓存数据
SharedPreferencesEditor.getString(CACHE_HOME_PAGER_DATA)
}
if (cacheHomeData.isEmpty()) {
//第一次安装使用本地临时数据
cacheHomeData =
String(HomeFileUtils.getAssertsFile(context, fileName)!!)
}
return cacheHomeData
}
override fun asyncResult(`object`: Any?) {
//如果没 有缓存数据,显示加载框
if (`object` !is String || TextUtils.isEmpty(`object`)) {
mView.showRefreshLayout()
}
if (`object` is String) {
val list = Gson().fromJson<MutableList<HomePagerDataBean>>(
`object`,
object : TypeToken<MutableList<HomePagerDataBean>>() {
}.type
)
if (null != list && !list.isEmpty()) {
mView.homeDataResponse(list)
saveTempData(list)
}
}
}
})
}
/**
*获取倾述列表
*/
@SuppressLint("CheckResult")
override fun getConfideData(type: String, selectPosition: Int) {
disposeConfide()
disposeHome()
mConfideType = type
mConfideDisposable = mModel.confideRequest(type)
.map { it }
.filter { true }
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Consumer {
mView.confideDataResponse(it, selectPosition)
}, object : ThrowableConsumer() {
override fun accept(msg: String) {
mView.homeDataFail(msg)
}
})
}
/**
*获取咨询列表
*/
override fun getConsultData(type: String, selectPosition: Int) {
disposeConsult()
disposeHome()
mConsultType = type
mConsultDisposable = mModel.consultRequest(type)
.map { it }
.filter { true }
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Consumer {
mView.consultDataResponse(it, selectPosition)
}, object : ThrowableConsumer() {
override fun accept(msg: String) {
mView.homeDataFail(msg)
}
})
}
fun disposeConfide() {
if (mConfideDisposable != null && !mConfideDisposable!!.isDisposed) {
mConfideDisposable?.dispose()
}
}
fun disposeConsult() {
if (mConsultDisposable != null && !mConsultDisposable!!.isDisposed) {
mConsultDisposable?.dispose()
}
}
fun disposeHome() {
if (mHomeDisposable != null && !mHomeDisposable!!.isDisposed) {
mHomeDisposable?.dispose()
}
}
/**
* 首页问答 - 点赞
*/
@SuppressLint("CheckResult")
override fun askZan(position: Int, index: Int, id: String) {
mModel.askZan(id)
.compose(RxUtils.netCheck())
.subscribeOn(Schedulers.io())
.map {}
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Consumer {
}, object : ThrowableConsumer() {
override fun accept(msg: String) {
mView.homeDataFail(msg)
}
})
}
/**
* 首页问答 - 关注
*/
@SuppressLint("CheckResult")
override fun askFocus(position: Int, id: String) {
mModel.askFocus(id)
.compose(RxUtils.netCheck())
.subscribeOn(Schedulers.io())
.map {}
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Consumer {
// view.askDataResponse(it!!, position)
}, object : ThrowableConsumer() {
override fun accept(msg: String) {
mView.homeDataFail(msg)
}
})
}
}
\ No newline at end of file
<resources>
<string name="app_name">m-home</string>
<string name="search_hint">搜索话题、咨询师姓名</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="NoTitleTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:windowActionBar">false</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorPrimary">@color/platform_main_theme_blue</item>
<item name="colorPrimaryDark">@color/platform_main_theme_blue</item>
<item name="colorAccent">@color/platform_main_theme_blue</item>
</style>
</resources>
\ No newline at end of file
package com.yidianling.home.adapter
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.yidianling.home.R
import com.yidianling.home.constract.YdlHomeViewHolderConstract
import com.yidianling.home.event.HomeImpl
import com.yidianling.home.event.IHomeEvent
import com.yidianling.home.model.bean.HomeAskBean
import com.yidianling.home.model.bean.HomeConfideBean
import com.yidianling.home.model.bean.HomeConsultBean
import com.yidianling.home.model.bean.HomePagerDataBean
import com.yidianling.home.ui.view.*
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 壹点零首页适配器
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/13
*/
class YdlHomeAdapter(private val mContext: Context,
private var homeEvent: HomeImpl,
private var list: ArrayList<HomePagerDataBean>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private val mInflater: LayoutInflater = LayoutInflater.from(mContext)
/**
* 倾述item的position
*
*/
private var confidePosition = -1
/**
* 咨询条目 position
*/
private var consultPosition = -1
/**
* 倾述模块中tab上次选中的下标
*/
var confideSelectPosition = 0
/**
* 咨询模块中tab上次选中的下标
*/
var consultSelectPosition = 0
fun updateItems(list: MutableList<HomePagerDataBean>) {
if (null == this.list || this.list!!.isEmpty()) {
this.list = ArrayList()
} else {
this.list.clear()
}
this.list.addAll(list)
//重置标记位
confidePosition = -1
consultPosition = -1
notifyDataSetChanged()
}
/**
* 更新倾诉模块数据
*/
fun updateConfideData(data: HomeConfideBean, selectPosition: Int) {
if (confidePosition == -1) {
return
}
list[confidePosition].confideBean = data
this.confideSelectPosition = selectPosition
notifyItemChanged(confidePosition)
}
/**
* 更新咨询模块数据
*/
fun updateConsultData(data: HomeConsultBean, selectPosition: Int) {
if (consultPosition == -1) {
return
}
list[consultPosition].consultBean = data
this.consultSelectPosition = selectPosition
notifyItemChanged(consultPosition)
}
/**
* 更新问答模块数据
*/
fun updateAskData(data: HomeAskBean, position: Int) {
list[position].askBean = data
notifyItemChanged(position)
}
override fun getItemViewType(position: Int): Int {
if (position < list.size) {
return list[position].type!!
} else {
return YdlHomeViewHolderConstract.FOOTER_VIEW
}
}
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): RecyclerView.ViewHolder {
when (viewType) {
//顶部预约专家,即时倾诉,心理测试按钮模块
YdlHomeViewHolderConstract.BUTTON_BANNER_VIEW -> {
return HomeButtonBannerViewHolder(HomeButtonBannerView(mContext, homeEvent))
}
//倾诉*排解模块
YdlHomeViewHolderConstract.CONFIDE_VIEW -> {
return HomeConfideViewHolder(HomeConfideView(mContext, homeEvent))
}
//课程*成长模块
YdlHomeViewHolderConstract.COURSE_VIEW -> {
return HomeCourseViewHolder(HomeCourseView(mContext, homeEvent))
}
//解忧*问答模块
YdlHomeViewHolderConstract.ASSUAGE_GRIEF_VIEW -> {
return HomeAssuageGriefViewHolder(HomeAssuageGriefView(mContext, homeEvent))
}
//文章*阅读模块
YdlHomeViewHolderConstract.ARTICLE_VIEW -> {
return HomeArticleViewHolder(HomeArticleView(mContext, homeEvent))
}
//咨询模块
YdlHomeViewHolderConstract.CONSULT_VIEW -> {
return HomeConsultViewHolder(HomeConsultView(mContext, homeEvent))
}
//测试模块
YdlHomeViewHolderConstract.TEST_VIEW -> {
return HomeTestViewHolder(HomeTestView(mContext, homeEvent))
}
//底部提示语模块
else -> {
val view = mInflater.inflate(R.layout.home_module_footer_view, parent, false)
return FooterViewViewHolder(view)
}
}
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
when (holder) {
//顶部预约专家,即时倾诉,心理课堂,心理测试按钮模块
is HomeButtonBannerViewHolder -> {
holder.buttonBannerView.initData(list[position].headerBean?.homeSaleData,list[position].headerBean?.askCategoryData)
}
//倾诉*排解模块
is HomeConfideViewHolder -> {
holder.confideViewView.setTitle(list[position].headerBean?.listenCategoryDate, confideSelectPosition)
holder.confideViewView.setConfideExpertInfoView(list[position].confideBean?.body)
confidePosition = position
}
//课程*成长模块
is HomeCourseViewHolder -> {
holder.courseViewView.initData(list[position].courseBean?.list)
}
//解忧*问答模块
is HomeAssuageGriefViewHolder -> {
holder.assuageGriefViewView.initData(position, list[position].askBean?.data)
}
//文章*阅读模块
is HomeArticleViewHolder -> {
holder.articleViewView.initData(list[position].articleBean?.list)
}
//咨询模块
is HomeConsultViewHolder -> {
holder.consultView.setTitle(list[position].headerBean?.consultCategoryData, consultSelectPosition)
holder.consultView.setConsultInfoView(list[position].consultBean?.list,list[position].headerBean?.consultCategoryData?.get(consultSelectPosition))
consultPosition = position
}
//测试模块
is HomeTestViewHolder -> {
holder.testView.initData(list[position].testListBean)
}
}
}
override fun getItemCount(): Int {
return list.size
}
/**
* 顶部预约专家,即时倾诉,心理测试按钮模块 ViewHolder
*/
inner class HomeButtonBannerViewHolder(val buttonBannerView: HomeButtonBannerView) : RecyclerView.ViewHolder(buttonBannerView)
/**
* 咨询模块 ViewHolder
*/
inner class HomeConsultViewHolder(val consultView: HomeConsultView) : RecyclerView.ViewHolder(consultView)
/**
* 倾诉*排解模块 ViewHolder
*/
inner class HomeConfideViewHolder(val confideViewView: HomeConfideView) : RecyclerView.ViewHolder(confideViewView)
/**
* 课程*成长模块 ViewHolder
*/
inner class HomeCourseViewHolder(val courseViewView: HomeCourseView) : RecyclerView.ViewHolder(courseViewView)
/**
* 测试模块 ViewHolder
*/
inner class HomeTestViewHolder(val testView: HomeTestView) : RecyclerView.ViewHolder(testView)
/**
* 解忧*问答模块 ViewHolder
*/
inner class HomeAssuageGriefViewHolder(val assuageGriefViewView: HomeAssuageGriefView) : RecyclerView.ViewHolder(assuageGriefViewView)
/**
* 文章*阅读模块 ViewHolder
*/
inner class HomeArticleViewHolder(val articleViewView: HomeArticleView) : RecyclerView.ViewHolder(articleViewView)
/**
* 底部提示语模块 ViewHolder
*/
inner class FooterViewViewHolder(val footerView: View) : RecyclerView.ViewHolder(footerView)
}
\ No newline at end of file
package com.yidianling.home.constract
import android.app.Activity
import android.content.Context
import com.ydl.ydlcommon.data.http.BaseResponse
import com.ydl.ydlcommon.mvp.base.IModel
import com.ydl.ydlcommon.mvp.base.IPresenter
import com.ydl.ydlcommon.mvp.base.IView
import com.yidianling.home.constants.IHomeBaseContract
import com.yidianling.home.model.bean.*
import io.reactivex.Observable
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 心理咨询首页约束类
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/13
*/
class IHomeContract {
interface View : IHomeBaseContract.View {
/**
* 获取优惠券数据回调
*/
fun couponDataResponse(data: List<CouponBean>)
/**
* 领取优惠券回调
*/
fun receiveCouponResponse(data: BaseResponse<Any>)
/**
* 领取优惠券
*/
fun receiveCoupon(data: List<CouponBean>)
}
interface Presenter : IHomeBaseContract.Presenter<View> {
/**
* 获取优惠券信息
*/
fun prepareCoupon(activity: Activity)
/**
* 领取优惠券
*/
fun receiveCoupon(list:List<CouponBean>)
}
interface Model: IHomeBaseContract.Model {
/**
* 领取优惠券
*/
fun receiveCoupon(uid: String, couponIds: String): Observable<BaseResponse<Any>>
/**
* 获取优惠券
*/
fun getCoupons(uid: String): Observable<BaseResponse<List<CouponBean>>>
}
}
\ No newline at end of file
package com.yidianling.home.constract
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述:壹点零首页ViewHolder约束类
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/13
*/
class YdlHomeViewHolderConstract {
companion object {
/**
* 顶部ViewPager与分类模块
*/
val PAGER_BANNER_VIEW = 10001
/**
* 顶部预约专家,即时倾诉,心理测试按钮模块
*/
val BUTTON_BANNER_VIEW = 10002
/**
* 咨询模块
*/
val CONSULT_VIEW = 10003
/**
* 倾诉*排解模块
*/
val CONFIDE_VIEW = 10004
/**
* 课程*成长模块
*/
val COURSE_VIEW = 10005
/**
* 测试模块
*/
val TEST_VIEW = 10006
/**
* 解忧*问答模块
*/
val ASSUAGE_GRIEF_VIEW = 10007
/**
* 文章*阅读模块
*/
val ARTICLE_VIEW = 10008
/**
* 底部提示语模块
*/
val FOOTER_VIEW = 10009
}
}
\ No newline at end of file
package com.yidianling.home.dialog
import android.app.Activity
import android.app.Dialog
import android.os.Bundle
import com.ydl.webview.H5Params
import com.ydl.webview.NewH5Activity
import com.yidianling.home.R
import com.ydl.ydl_image.module.GlideApp
import com.ydl.ydl_router.manager.YDLRouterManager
import kotlinx.android.synthetic.xlzx.dialog_activity.*
import java.lang.ref.WeakReference
/**
* 活动弹窗
*/
class ActivityDialog : Dialog{
private var imgUrl :String?= null
private var linkUrl:String? = null
private var title: String? = null
private var mActivity: WeakReference<Activity>?= null
constructor(activit: Activity,imgUrl: String?,linkUrl: String?,title:String?):super(activit,R.style.activityDialog){
this.imgUrl = imgUrl
this.linkUrl = linkUrl
this.title = title
this.mActivity = WeakReference<Activity>(activit)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window.setBackgroundDrawableResource(android.R.color.transparent)
setContentView(R.layout.dialog_activity)
initView()
}
private fun initView(){
img_close.setOnClickListener{
this.dismiss()
}
img_activity.setOnClickListener{
//跳转
if (this.linkUrl!=null && this.linkUrl!!.startsWith("http")){
NewH5Activity.start(context, H5Params(this.linkUrl!!,null))
}else{
YDLRouterManager.router(this.linkUrl)
}
}
GlideApp.with(context).load(imgUrl).into(img_activity)
setCanceledOnTouchOutside(false)
setCancelable(false)
}
}
package com.yidianling.home.dialog
import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.Window
import com.ydl.ydl_image.module.GlideApp
import com.ydl.ydlcommon.utils.DisplayUtils
import com.yidianling.home.R
import kotlinx.android.synthetic.xlzx.dialog_guide_activity.*
import java.util.*
/**
* 首页活动引导弹窗
*/
class ActivityGuideDialog : Dialog{
private var imgUrl :String?= null
private var title:String? = null
private var marginTop: Int? = null
private var marginLeft: Int? = null
constructor(context: Context,imgUrl: String?,title: String?,marginTop : Int,marginLeft:Int):super(context,R.style.activityDialog){
this.imgUrl = imgUrl
this.title = title
this.marginTop = marginTop
this.marginLeft = marginLeft
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestWindowFeature(Window.FEATURE_NO_TITLE)
window.setBackgroundDrawableResource(android.R.color.transparent)
setContentView(R.layout.dialog_guide_activity)
initView()
}
private fun initView(){
if (marginTop==null){
marginTop = DisplayUtils.dp2px(context,135)
}
if (marginLeft==null){
marginLeft = DisplayUtils.dp2px(context,35)
}
c_body.setPadding(marginLeft!!,marginTop!!,0,0)
c_body.setOnClickListener {
dismiss()
}
tv_content.text = this.title
GlideApp.with(context).load(imgUrl).into(img_activity)
//3秒自动消失
Timer().schedule(object : TimerTask() {
override fun run() {
dismiss()
}
},3000)
}
}
\ No newline at end of file
package com.yidianling.home.event
import android.content.Context
import android.content.Intent
import android.graphics.drawable.AnimationDrawable
import android.net.Uri
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.RecyclerView
import android.text.TextUtils
import android.view.View
import android.widget.ImageView
import android.widget.RelativeLayout
import com.alibaba.android.arouter.launcher.ARouter
import com.ydl.media.audio.AudioPlayer
import com.ydl.media.audio.model.Music
import com.ydl.media.view.PlayTypeEnum
import com.ydl.media.view.PlayerFloatHelper
import com.ydl.media.view.PlayerFloatView
import com.ydl.webview.H5Params
import com.ydl.webview.NewH5Activity
import com.yidianling.home.R
import com.yidianling.home.constract.IHomeContract
import com.yidianling.home.model.bean.*
import com.yidianling.home.ui.view.CouponDialog
import com.ydl.ydl_router.manager.YDLRouterManager
import com.ydl.ydl_router.manager.YDLRouterParams
import com.ydl.ydl_router.util.YDLRouterParamsUrls
import com.ydl.ydlcommon.base.BaseActivity
import com.ydl.ydlcommon.base.config.HttpConfig
import com.ydl.ydlcommon.bean.ShareData
import com.ydl.ydlcommon.data.PlatformRamImpl
import com.ydl.ydlcommon.modular.ModularServiceManager
import com.ydl.ydlcommon.router.IYDLRouterConstant
import com.ydl.ydlcommon.utils.remind.ToastHelper
import com.ydl.ydlcommon.view.dialog.CommonDialog
import com.yidianling.router.RouterManager
import com.yidianling.router.im.IMRequestCallback
import com.yidianling.tests.api.service.ITestsApiService
import com.yidianling.user.api.service.IUserService
import org.json.JSONObject
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 首页点击事件实现类
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/13
*/
class HomeImpl(context: Context, homeView: IHomeContract.View) : HomeBaseImpl(context, homeView), IHomeEvent {
private var lastVoiceView: ImageView? = null
private var floatViewClickListener: PlayerFloatView.FloatViewPlayListener? = null
override fun clickEnsure(list: List<CouponBean>): CouponDialog.OnClickEnsureListener {
return object : CouponDialog.OnClickEnsureListener {
override fun clickEnsure(status: Int) {
//立即领取
if (status == CouponDialog.STATUS_RECEIVER) {
mHomeView?.receiveCoupon(list)
}
//查看我的卡券
if (status == CouponDialog.STATUS_GET) {
ARouter.getInstance().build(IYDLRouterConstant.ROUTER_MINE_REDPACKET)
.withString("is_from_main", "1")
.navigation()
}
}
}
}
override fun confidePlayClick(voiceView: ImageView, bean: HomeConfideBean.BodyBean) {
val music = Music()
music.title = bean.confidedName
music.coverPath = bean.confidedIcon
AudioPlayer.get().singlePlay(music, false)
PlayerFloatHelper.playingType = PlayTypeEnum.PLAY_TYPE_CONFIDE
if (PlayerFloatHelper.isShow(mContext!!)) {
if (PlayerFloatHelper.playingType == PlayTypeEnum.PLAY_TYPE_CONFIDE) {
PlayerFloatHelper.removeView(mContext!!)
PlayerFloatHelper.show(mContext!!)
} else {
PlayerFloatHelper.setPlayingState(mContext!!)
}
} else {
mContext?.let { PlayerFloatHelper.show(it) }
}
stopPlayAnim()
var animationDrawable = voiceView?.getDrawable() as AnimationDrawable
animationDrawable.start()
lastVoiceView = voiceView
if (floatViewClickListener == null) {
floatViewClickListener = object : PlayerFloatView.FloatViewPlayListener {
override fun onStartClick() {
startPlayAnim()
}
override fun onPlayFinish() {
stopPlayAnim()
if (PlayerFloatHelper.isShow(mContext!!)) {
PlayerFloatHelper.removeView(mContext!!)
AudioPlayer.get().stopPlayer()
}
}
override fun onPauseClick() {
stopPlayAnim()
}
}
PlayerFloatHelper.addClickListener(floatViewClickListener as PlayerFloatView.FloatViewPlayListener)
}
}
private fun stopPlayAnim() {
if (lastVoiceView != null) {
var animationDrawable = lastVoiceView?.getDrawable() as AnimationDrawable
animationDrawable.stop()
animationDrawable.selectDrawable(3);
}
}
private fun startPlayAnim() {
if (lastVoiceView != null) {
var animationDrawable = lastVoiceView?.getDrawable() as AnimationDrawable
animationDrawable.start()
}
}
}
package com.yidianling.home.event
import android.support.v7.widget.RecyclerView
import android.widget.ImageView
import android.widget.RelativeLayout
import com.yidianling.home.model.bean.*
import com.yidianling.home.ui.view.CouponDialog
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 首页点击事件接口类
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/13
*/
interface IHomeEvent {
/**
* 点击优惠券确定事件
*/
fun clickEnsure(list: List<CouponBean>): CouponDialog.OnClickEnsureListener
/**
* 咨询师音频点击播放
*/
fun confidePlayClick(voiceView:ImageView,bean: HomeConfideBean.BodyBean)
}
\ No newline at end of file
package com.cxzapp.yidianling_atk8.ui.homepager.http
import com.ydl.ydlcommon.data.http.BaseAPIResponse
import com.ydl.ydlcommon.data.http.BaseCommand
import com.ydl.ydlcommon.data.http.BaseResponse
import com.ydl.ydlcommon.data.http.RxUtils
import com.ydl.ydlcommon.modular.ModularServiceManager
import com.ydl.ydlnet.YDLHttpUtils
import com.yidianling.home.model.bean.*
import com.yidianling.user.api.service.IUserService
import io.reactivex.Observable
import okhttp3.MediaType
import okhttp3.RequestBody
/**
* @author jiucheng
* @描述:首页接口实现类
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/8/22
*/
class HomeHttp private constructor() {
companion object {
fun getInstance(): HomeHttp {
return Holder.INSTANCE
}
}
object Holder {
val INSTANCE = HomeHttp()
}
private var homePagerApi: HomePagerApi? = null
private fun getHomePagerApi(): HomePagerApi {
if (homePagerApi == null) {
homePagerApi = YDLHttpUtils.obtainApi(HomePagerApi::class.java)
}
return homePagerApi!!
}
//领取优惠券
fun receiveCoupon(uid: String, couponIds: String): Observable<BaseResponse<Any>> {
val body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), couponIds)
return getHomePagerApi().receiveCoupon(uid, body)
}
//获取优惠券
// applyUsers 用户
// applyEnds 用户版
fun getCoupons(uid: String): Observable<BaseResponse<List<CouponBean>>> {
return getHomePagerApi().getCoupons(uid, "1", "3")
}
}
\ No newline at end of file
package com.cxzapp.yidianling_atk8.ui.homepager.http
import com.ydl.ydlcommon.base.BaseApp
import com.ydl.ydlcommon.base.config.YDL_DOMAIN
import com.ydl.ydlcommon.base.config.YDL_DOMAIN_JAVA
import com.ydl.ydlcommon.base.config.YDL_DOMAIN_JAVA_URL
import com.ydl.ydlcommon.data.PlatformDataManager
import com.ydl.ydlcommon.data.http.BaseAPIResponse
import com.ydl.ydlcommon.data.http.BaseResponse
import com.yidianling.home.model.bean.*
import com.yidianling.common.tools.RxDeviceTool
import io.reactivex.Observable
import okhttp3.RequestBody
import retrofit2.http.*
/**
* @author jiucheng
* @描述:首页接口api
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/8/22
*/
interface HomePagerApi {
//领取优惠券
@POST("marketing/coupon/{uid}/receive")
@Headers(YDL_DOMAIN + YDL_DOMAIN_JAVA_URL)
fun receiveCoupon(@Path("uid") uid: String, @Body body: RequestBody): Observable<BaseResponse<Any>>
//获取优惠券
@GET("marketing/coupon/{uid}/obtain")
@Headers(YDL_DOMAIN + YDL_DOMAIN_JAVA_URL)
fun getCoupons(
@Path("uid") uid: String, @Query("applyUsers") applyUsers: String, @Query(
"applyEnds"
) applyEnds: String
): Observable<BaseResponse<List<CouponBean>>>
}
\ No newline at end of file
package com.yidianling.home.listener
import android.support.design.widget.TabLayout
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.yidianling.home.adapter.YdlHomeAdapter
import com.yidianling.home.constract.YdlHomeViewHolderConstract
import com.yidianling.common.tools.RxImageTool
/**
* @author yuanwai
* @描述:悬浮按钮监听事件
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/9/25
*/
class HomeConfideRecyleSuspendListener : RecyclerView.OnScrollListener() {
private var mCurrentPosition = 0
private var mSuspensionHeight: Int = RxImageTool.dip2px(51f)
private var filterView: LinearLayout? = null
private var adapter: YdlHomeAdapter? = null
fun setFilterView(filterView: LinearLayout) {
this.filterView = filterView
}
fun setSectionAdapter(adapter: YdlHomeAdapter) {
this.adapter = adapter
}
override fun onScrollStateChanged(recyclerView: RecyclerView?, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (null != filterView) {
mSuspensionHeight = filterView!!.height
}
}
override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
if (null == adapter) {
return
}
val manager = recyclerView!!.layoutManager as LinearLayoutManager
if (mCurrentPosition != manager.findFirstVisibleItemPosition()) {
mCurrentPosition = manager.findFirstVisibleItemPosition()
}
// LogUtil.e("http----------------type=" + adapter!!.getItemViewType(mCurrentPosition))
if (adapter!!.getItemViewType(mCurrentPosition) == YdlHomeViewHolderConstract.CONFIDE_VIEW) {
var view = manager.findViewByPosition(mCurrentPosition)
if (view != null) {
if (view is ViewGroup) {
if (view.getChildAt(1) is TabLayout) {
var tablayout = view.getChildAt(1)
var location = IntArray(2)
tablayout.getLocationOnScreen(location)
if (location[1] - RxImageTool.dip2px(40f) <= mSuspensionHeight) {
filterView!!.visibility = View.VISIBLE
} else {
filterView!!.visibility = View.INVISIBLE
}
}
}
}
var nextView = manager.findViewByPosition(mCurrentPosition + 1)
if (nextView != null) {
if (nextView.top <= (mSuspensionHeight + RxImageTool.dip2px(41f))) {
filterView!!.visibility = View.INVISIBLE
}
}
} else {
filterView!!.visibility = View.INVISIBLE
}
}
}
\ No newline at end of file
package com.yidianling.home.model
import com.cxzapp.yidianling_atk8.ui.homepager.http.HomeHttp
import com.ydl.ydlcommon.base.config.HttpConfig
import com.ydl.ydlcommon.data.http.BaseResponse
import com.ydl.ydlcommon.data.http.RxUtils
import com.ydl.ydlcommon.mvp.base.BaseModel
import com.yidianling.home.constract.IHomeContract
import com.yidianling.home.model.bean.*
import io.reactivex.Observable
import okhttp3.MediaType
import okhttp3.RequestBody
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述:
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/13
*/
class HomeModelImpl: BaseHomeModelImpl(), IHomeContract.Model {
//领取优惠券
override fun receiveCoupon(uid: String, couponIds: String): Observable<BaseResponse<Any>> {
return HomeHttp.getInstance().receiveCoupon(uid, couponIds)
}
//获取优惠券
override fun getCoupons(uid: String): Observable<BaseResponse<List<CouponBean>>> {
return HomeHttp.getInstance().getCoupons(uid)
}
}
\ No newline at end of file
package com.yidianling.home.ui.behavior;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.OverScroller;
import android.widget.RelativeLayout;
import com.ydl.ydlcommon.utils.ColorCalculateUtils;
import com.ydl.ydlcommon.utils.DisplayUtils;
import com.yidianling.home.ui.scrollView.DisInterceptNestedScrollView;
/**
* Created by haorui on 2019/3/2.
* Des:
*/
public class HomeAppBarLayoutBehavior extends AppBarLayout.Behavior {
private static final String TAG = "overScroll";
private static final String TAG_TOOLBAR = "toolbar";
private static final String TAG_TOOLBAR_BG = "toolbar_bg";
private static final String TAG_MIDDLE_BUT = "middle_but_layout";
private static final String TAG_SEARCH_INPUT = "tag_search_input";
private static final String TAG_SEARCH_INPUT_BG = "tag_search_input_bg";
private static final String TAG_SEARCH_INPUT_EDIT = "tag_search_input_edit";
private static final String TAG_SEARCH_INPUT_IMG = "tag_search_input_img";
private View mTargetView;
private View mToolBarBg;
private ViewGroup middleLayout;//咨询按钮布局
private RelativeLayout inputLayout;//输入框布局
private boolean isRecovering = false;//是否正在自动回弹中
private float INPUT_LEFT_OFFSET ;//52dp - 15dp
private float INPUT_RIGHT_OFFSET ;//38dp - 15dp
private float INPUT_HEIGHT_OFFSET ;//44dp - 32dp
private float INPUT_SEARCH_IMAGE_OFFSET ;//15dp - 10dp
private float INPUT_SEARCH_IMAGE_ORIGIN_OFFSET;//15dp
private float INPUT_ORIGIN_HEIGHT;
private int inputOriginMargin;
private View inputLayoutBg;
private GradientDrawable inputBgDrawable;
private EditText inputLayoutEdit;
private ImageView inputLayoutImg;
private OverScroller mScroller1;
private float mInputLastScale ;
private CoordinatorLayout.LayoutParams mLayoutParams;
private RelativeLayout.LayoutParams mLayoutImageParams;
public HomeAppBarLayoutBehavior() {
}
public HomeAppBarLayoutBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
INPUT_LEFT_OFFSET = DisplayUtils.dp2px(context,23);
INPUT_RIGHT_OFFSET = DisplayUtils.dp2px(context,37);
INPUT_HEIGHT_OFFSET = DisplayUtils.dp2px(context,11);
INPUT_ORIGIN_HEIGHT = DisplayUtils.dp2px(context,44);
INPUT_SEARCH_IMAGE_OFFSET = DisplayUtils.dp2px(context,4);
INPUT_SEARCH_IMAGE_ORIGIN_OFFSET = DisplayUtils.dp2px(context,10);
}
@Override
public boolean onLayoutChild(CoordinatorLayout parent, AppBarLayout abl, int layoutDirection) {
boolean handled = super.onLayoutChild(parent, abl, layoutDirection);
if (mToolBarBg == null) {
mToolBarBg = (View) parent.findViewWithTag(TAG_TOOLBAR_BG);
}
if (middleLayout == null) {
middleLayout = (ViewGroup) parent.findViewWithTag(TAG_MIDDLE_BUT);
}
if (inputLayout == null) {
inputLayout = (RelativeLayout) parent.findViewWithTag(TAG_SEARCH_INPUT);
inputLayoutBg = parent.findViewWithTag(TAG_SEARCH_INPUT_BG);
inputLayoutEdit = (EditText) parent.findViewWithTag(TAG_SEARCH_INPUT_EDIT);
inputLayoutImg = (ImageView) parent.findViewWithTag(TAG_SEARCH_INPUT_IMG);
inputBgDrawable = (GradientDrawable) inputLayoutBg.getBackground();
mLayoutParams = (CoordinatorLayout.LayoutParams) inputLayout.getLayoutParams();
inputOriginMargin = mLayoutParams.leftMargin;
mLayoutImageParams = (RelativeLayout.LayoutParams) inputLayoutImg.getLayoutParams();
}
if (mTargetView == null) {
mTargetView = parent.findViewWithTag(TAG);
if (mTargetView != null) {
initial(abl);
}
}
abl.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public final void onOffsetChanged(AppBarLayout appBarLayout, int i) {
float scale = Float.valueOf(Math.abs(i)) / Float.valueOf(appBarLayout.getTotalScrollRange());
mToolBarBg.setAlpha( scale);
float leftMargin = inputOriginMargin + (INPUT_LEFT_OFFSET*scale);
float rightMargin = inputOriginMargin + (INPUT_RIGHT_OFFSET*scale);
mLayoutParams.setMargins((int)leftMargin,0,(int) rightMargin,0);
mLayoutParams.height = (int) (INPUT_ORIGIN_HEIGHT - (scale*INPUT_HEIGHT_OFFSET));
inputLayout.setLayoutParams(mLayoutParams);
float imageRightMargin = INPUT_SEARCH_IMAGE_ORIGIN_OFFSET - (INPUT_SEARCH_IMAGE_OFFSET*scale);
mLayoutImageParams.setMargins((int)INPUT_SEARCH_IMAGE_ORIGIN_OFFSET,0,(int) imageRightMargin,0);
inputLayoutImg.setLayoutParams(mLayoutImageParams);
//设置圆角
inputBgDrawable.setCornerRadius(12+(40*scale));
if(Math.abs(scale-mInputLastScale)>0.25) {
//设置字体/图标颜色 4次
inputLayoutEdit.setHintTextColor(Color.parseColor(ColorCalculateUtils.calculateColor("#FFB3B3B3","#A4999999",scale)));
inputLayoutImg.setColorFilter(Color.parseColor(ColorCalculateUtils.calculateColor("#FF999999","#FFB3B3B3",scale)));
// inputLayoutEdit.setTextColor(Color.parseColor(ColorCalculateUtils.calculateColor("#FF444444","#A4FFFFFF",scale)));
mInputLastScale = scale;
}
// inputLayoutImg.setAlpha((float) (1- (0.4*scale)));
}
});
return handled;
}
@Override
public boolean onStartNestedScroll(CoordinatorLayout parent, AppBarLayout child, View directTargetChild, View target, int nestedScrollAxes, int type) {
if (target instanceof DisInterceptNestedScrollView)
return true;//middleLayout
return super.onStartNestedScroll(parent, child, directTargetChild, target, nestedScrollAxes,type);
}
private void initial(AppBarLayout abl) {
abl.setClipChildren(false);
}
}
\ No newline at end of file
package com.yidianling.home.ui.scrollView;
import android.content.Context;
import android.support.v4.widget.NestedScrollView;
import android.util.AttributeSet;
import android.view.MotionEvent;
/**
* 用于子类防止父类拦截子类的事件
*/
public class DisInterceptNestedScrollView extends NestedScrollView {
public DisInterceptNestedScrollView(Context context) {
super(context);
requestDisallowInterceptTouchEvent(true);
}
public DisInterceptNestedScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
requestDisallowInterceptTouchEvent(true);
}
public DisInterceptNestedScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
requestDisallowInterceptTouchEvent(true);
}
public boolean dispatchTouchEvent(MotionEvent ev) {
getParent().requestDisallowInterceptTouchEvent(true);
return super.dispatchTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
requestDisallowInterceptTouchEvent(false);
break;
}
return super.onTouchEvent(event);
}
}
package com.yidianling.home.ui.view
import android.app.Activity
import android.app.Dialog
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.text.TextUtils
import com.yidianling.home.R
import com.yidianling.home.model.bean.CouponBean
import kotlinx.android.synthetic.xlzx.dialog_coupon.*
/**
* @author jiucheng
* @描述:首页优惠券弹窗
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/8/6
*/
class CouponDialog : Dialog {
private var activity: Activity? = null
var status: Int = STATUS_RECEIVER
var couponBean: CouponBean? = null
var list: List<CouponBean>? = null
var listener: OnClickEnsureListener? = null
companion object {
var STATUS_RECEIVER = 0 //立即领取
var STATUS_GET = 1 //查看我的卡券
}
constructor(activity: Activity?, list: List<CouponBean>, listener: OnClickEnsureListener?) : super(activity) {
this.activity = activity
this.couponBean = list[0]
this.list = list
this.listener = listener
}
fun updateStatus(status: Int) {
this.status = status
updateUiByStatus()
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.dialog_coupon)
setCanceledOnTouchOutside(false)
window.setBackgroundDrawable(ColorDrawable())
if (couponBean != null) {
if (!TextUtils.isEmpty(couponBean!!.title)) {
tv_title.text = couponBean!!.title
}
tv_duration.text = couponBean!!.validity
if (TextUtils.equals("1", couponBean!!.type)) {
tv_money.text = couponBean!!.amount
tv_unit.text = "元"
} else {
tv_money.text = (couponBean!!.discount?:"0".toFloat() * 10).toString()
tv_unit.text = "折"
}
tv_limit.text = couponBean!!.condition
}
updateUiByStatus()
tv_ensure.setOnClickListener {
if (listener != null) {
listener!!.clickEnsure(status)
}
if (status == STATUS_GET) {
dismiss()
}
}
iv_close.setOnClickListener {
dismiss()
}
}
private fun updateUiByStatus() {
var title = ""
var ensureText = ""
var iamge = 0
when (status) {
STATUS_RECEIVER -> {
if (list!!.size > 1) {
title = "获得${list!!.size}张新的优惠券"
} else {
title = "获得新优惠券"
}
ensureText = "立即领取"
iamge = R.drawable.coupon_receiver
}
STATUS_GET -> {
if (list!!.size > 1) {
title = "获得${list!!.size}张新的优惠券"
} else {
title = "恭喜您,领取成功"
}
ensureText = "查看我的卡券"
iamge = R.drawable.coupon_success
}
}
iv_title.setImageResource(iamge)
tv_status.text = title
tv_ensure.text = ensureText
}
interface OnClickEnsureListener {
fun clickEnsure(status: Int)
}
override fun show() {
if (null == activity || activity!!.isFinishing) {
return
}
super.show()
}
}
\ No newline at end of file
package com.yidianling.home.ui.view
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.ydl.ydl_image.manager.YDLImageCacheManager
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.model.bean.HomeArticleBean
import kotlinx.android.synthetic.xlzx.home_module_article_item_view.view.*
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 文章*阅读模块item
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/14
*/
class HomeArticleItemView(private val mContext: Context, private var homeEvent: IHomeBaseEvent?) :
LinearLayout(mContext) {
init {
initView()
}
private fun initView() {
val params = RecyclerView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
layoutParams = params
View.inflate(mContext, R.layout.home_module_article_item_view, this)
}
fun updateData(bean: HomeArticleBean.Bean?) {
homeModuleArticleItemViewTitle.text = bean?.title
homeModuleArticleItemViewContent.text = bean?.desc
homeModuleArticleItemViewAuthor.text = bean?.name
homeModuleArticleItemViewGreatNum.text = bean?.countOfFavorite.toString()
homeModuleArticleItemViewLookNum.text = bean?.readNum.toString()
YDLImageCacheManager.showImage(mContext, bean?.imgUrl, homeModuleArticleItemViewImg)
setOnClickListener {
bean?.let {
homeEvent?.articleItemClick(bean)
}
}
}
/**
* 最后一个item需要隐藏item的下划线
*/
fun hideBottomLine() {
homeModuleArticleItemViewBottomLine.visibility = View.GONE
}
}
\ No newline at end of file
package com.yidianling.home.ui.view
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.model.bean.HomeArticleBean
import kotlinx.android.synthetic.xlzx.home_module_article_view.view.*
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 文章*阅读模块
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/13
*/
class HomeArticleView(private val mContext: Context, private var homeEvent: IHomeBaseEvent?) :
LinearLayout(mContext) {
private var cacheList: ArrayList<HomeArticleBean.Bean> = ArrayList()
init {
initView()
}
private fun initView() {
orientation = VERTICAL
val params = RecyclerView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
layoutParams = params
View.inflate(mContext, R.layout.home_module_article_view, this)
homeModuleArticleViewHomeCommonTitleView.setTitle("文章·阅读")
homeModuleArticleViewHomeCommonTitleView.setOnClickListener {
homeEvent?.articleMoreClick()
}
}
fun initData(list: List<HomeArticleBean.Bean>?) {
//添加View
if (list == null) {
return
}
if (cacheList.size != list?.size) {
cacheList.clear()
cacheList.addAll(list!!)
updateHomeArticleItemViewNumber()
}
//刷新数据
for (index in 0 until childCount) {
val itemView = getChildAt(index)
if (itemView is HomeArticleItemView) {
itemView.updateData(list[index - 1])
// 最后一个隐藏底部横线
if (index == childCount - 1) {
itemView.hideBottomLine()
}
}
}
}
/**
* 更新itemView的数量以适应新的数据集
*/
private fun updateHomeArticleItemViewNumber() {
var childCountRecord = childCount - 1 //减1是因为第一个子View是标题View
while (cacheList.size > childCountRecord) {
addView(HomeArticleItemView(mContext, homeEvent))
childCountRecord++
}
while (cacheList.size < childCountRecord && getChildAt(childCountRecord - 1) is HomeArticleItemView) {
removeViewAt(childCountRecord - 1)
childCountRecord--
}
}
}
\ No newline at end of file
package com.yidianling.home.ui.view
import android.content.Context
import android.support.v7.widget.CardView
import android.view.View
import android.widget.LinearLayout
import com.ydl.ydl_image.manager.YDLImageCacheManager
import com.yidianling.common.tools.RxDeviceTool
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import kotlinx.android.synthetic.xlzx.home_module_assuage_grief_image_more_five_item_view.view.*
import kotlinx.android.synthetic.xlzx.home_module_assuage_grief_image_under_four_item_view.view.*
import kotlinx.android.synthetic.xlzx.home_module_assuage_grief_image_under_two_item_view.view.*
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 解忧*问答模块内部图片模块
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/15
*/
class HomeAssuageGriefImageItemView(
private val mContext: Context,
private val urlList: List<String>,
private var homeEvent: IHomeBaseEvent?
) : CardView(mContext) {
init {
initView()
}
private fun initView() {
radius = 4f
cardElevation = 0f
var screenWidth = RxDeviceTool.getScreenWidth(mContext)
var viewWidth = (screenWidth - 2 * 30 * RxDeviceTool.getScreenDensity(mContext)).toInt()
var params: LinearLayout.LayoutParams?
//根据图片的数量,加载不同的图片布局
if (urlList.size <= 2) {
var viewHeight = viewWidth * 178 / 315
params = LinearLayout.LayoutParams(viewWidth, viewHeight)
params.bottomMargin = (20 * RxDeviceTool.getScreenDensity(mContext)).toInt()
layoutParams = params
View.inflate(
mContext,
R.layout.home_module_assuage_grief_image_under_two_item_view,
this
)
YDLImageCacheManager.showImage(
mContext,
urlList[0],
homeModuleAssuageGriefUnderTwoItemViewImg
)
} else if (urlList.size <= 4) {
var viewHeight = viewWidth * 178 / 315
params = LinearLayout.LayoutParams(viewWidth, viewHeight)
params.bottomMargin = (20 * RxDeviceTool.getScreenDensity(mContext)).toInt()
layoutParams = params
View.inflate(
mContext,
R.layout.home_module_assuage_grief_image_under_four_item_view,
this
)
YDLImageCacheManager.showImage(
mContext,
urlList[0],
homeModuleAssuageGriefUnderFourItemViewFirstImg
)
YDLImageCacheManager.showImage(
mContext,
urlList[1],
homeModuleAssuageGriefUnderFourItemViewSecondImg
)
YDLImageCacheManager.showImage(
mContext,
urlList[2],
homeModuleAssuageGriefUnderFourItemViewThirdImg
)
homeModuleAssuageGriefUnderFourthItemViewTag.text = urlList.size.toString() + "图"
} else if (urlList.size >= 5) {
var viewHeight = viewWidth * 180 / 315
params = LinearLayout.LayoutParams(viewWidth, viewHeight)
params.bottomMargin = (20 * RxDeviceTool.getScreenDensity(mContext)).toInt()
layoutParams = params
View.inflate(
mContext,
R.layout.home_module_assuage_grief_image_more_five_item_view,
this
)
YDLImageCacheManager.showImage(
mContext,
urlList[0],
homeModuleAssuageGriefUnderFiveItemViewFirstImg
)
YDLImageCacheManager.showImage(
mContext,
urlList[1],
homeModuleAssuageGriefUnderFiveItemViewSecondImg
)
YDLImageCacheManager.showImage(
mContext,
urlList[2],
homeModuleAssuageGriefUnderFiveItemViewThirdImg
)
YDLImageCacheManager.showImage(
mContext,
urlList[3],
homeModuleAssuageGriefUnderFiveItemViewFourthImg
)
YDLImageCacheManager.showImage(
mContext,
urlList[4],
homeModuleAssuageGriefUnderFiveItemViewFiveImg
)
homeModuleAssuageGriefUnderFiveItemViewTag.text = urlList.size.toString() + "图"
}
}
fun updateData() {
}
}
\ No newline at end of file
package com.yidianling.home.ui.view
import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.model.bean.HomeAskBean
import kotlinx.android.synthetic.xlzx.home_module_assuage_grief_view.view.*
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 解忧*问答模块
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/13
*/
class HomeAssuageGriefView(private val mContext: Context, private var homeEvent: IHomeBaseEvent?) :
LinearLayout(mContext) {
private var cacheList: ArrayList<HomeAskBean.DataBean> = ArrayList()
init {
initView()
}
private fun initView() {
orientation = VERTICAL
val params = LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
layoutParams = params
View.inflate(mContext, R.layout.home_module_assuage_grief_view, this)
homeModuleAssuageGriefViewHomeCommonTitleView.setTitle("解忧·问答")
homeModuleAssuageGriefViewHomeCommonTitleView.setOnClickListener {
homeEvent?.askMoreClick()
}
}
fun initData(position: Int, list: List<HomeAskBean.DataBean>?) {
//添加View
if (list == null) {
return
}
if (cacheList.size != list?.size) {
cacheList.clear()
cacheList.addAll(list!!)
updateHomeAssuageGriefItemViewNumber()
}
//刷新数据
for (index in 0..childCount) {
val itemView = getChildAt(index)
if (itemView is HomeAssuageGriefItemView) {
itemView.updateData(list[index - 1], position, index - 1)
}
}
}
/**
* 更新itemView的数量以适应新的数据集
*/
private fun updateHomeAssuageGriefItemViewNumber() {
var childCountRecord = childCount - 1 //减1是因为第一个子View是标题View
while (cacheList.size > childCountRecord) {
addView(HomeAssuageGriefItemView(mContext, homeEvent))
childCountRecord++
}
while (cacheList.size < childCountRecord && getChildAt(childCountRecord - 1) is HomeAssuageGriefItemView) {
removeViewAt(childCountRecord - 1)
childCountRecord--
}
}
}
\ No newline at end of file
package com.yidianling.home.ui.view
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.LinearLayout
import com.yidianling.common.tools.RxImageTool
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.model.bean.HomeHeaderBean
import kotlinx.android.synthetic.xlzx.home_module_button_banner_view.view.*
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 顶部预约专家,即时倾诉,心理课堂,心理测试按钮模块
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/13
*/
class HomeButtonBannerView(private val mContext: Context, private var homeEvent: IHomeBaseEvent?) :
LinearLayout(mContext) {
/**
* 数据缓存
*/
var mDataList: ArrayList<HomeHeaderBean.AskCategoryDataBean>? = null
/**
* 间隔
*/
var margin: Int = 0
/**
* 是否添加了实时测试状态View
*/
var hasRealTestView: Boolean = false
private var realTestView: HomePagerBannerRealView? = null
/**
* 线
*/
private var lineView: View? = null
private var buttonParams: LinearLayout.LayoutParams? = null
init {
initView()
}
private fun initView() {
val params = RecyclerView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
layoutParams = params
View.inflate(mContext, R.layout.home_module_button_banner_view, this)
// initButtonView()
homeModuleButtonBannerFirst.setOnClickListener {
homeEvent?.reservationExpertsClick()
}
homeModuleButtonBannerSecond.setOnClickListener {
homeEvent?.nowConfideClick()
}
homeModuleButtonBannerThird.setOnClickListener {
homeEvent?.psychologyClassClick()
}
homeModuleButtonBannerFourth.setOnClickListener {
homeEvent?.psychologyTestClick()
}
}
fun initData(
homeSaleData: List<HomeHeaderBean.HomeSaleDataBean>?,
homeCategory: List<HomeHeaderBean.AskCategoryDataBean>?
) {
setRealTextView(homeSaleData)
homeEvent?.let { home_category_view.setEvent(it) };
home_category_view.initData(homeCategory)
}
/**
* 初始化实时测评状态View
*/
private fun initRealTextView() {
if (null == realTestView) {
var realTestParam = FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
realTestView = HomePagerBannerRealView(context, homeEvent!!)
realTestView!!.layoutParams = realTestParam
}
}
private fun initLineView() {
var lineParam =
FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, RxImageTool.dip2px(0.5f))
var dp15 = RxImageTool.dip2px(15f)
lineParam.leftMargin = dp15
lineParam.rightMargin = dp15
lineView = View(context)
lineView!!.setBackgroundColor(resources.getColor(R.color.home_module_category_view_test_line))
lineView!!.layoutParams = lineParam
}
/**
* 实时测评状态赋值
*/
private fun setRealTextView(list: List<HomeHeaderBean.HomeSaleDataBean>?) {
if (!hasRealTestView) {
initLineView()
ll_home_module_button.addView(lineView)
initRealTextView()
ll_home_module_button.addView(realTestView)
val cutOffParams = FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
RxImageTool.dip2px(0.5f)
)
cutOffParams.height = RxImageTool.dip2px(10f)
val cutOffView = View(context)
cutOffView.setBackgroundColor(resources.getColor(R.color.colorBg))
cutOffView.layoutParams = cutOffParams
ll_home_module_button.addView(cutOffView)
hasRealTestView = true
}
realTestView!!.initData(list)
}
}
\ No newline at end of file
package com.yidianling.home.ui.view
import android.content.Context
import android.support.constraint.ConstraintLayout
import android.util.AttributeSet
import android.view.View
import com.yidianling.home.R
import kotlinx.android.synthetic.xlzx.home_module_common_title_view.view.*
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 首页通用标题
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/14
*/
class HomeCommonTitleView(private val mContext: Context, private val attributeSet: AttributeSet) : ConstraintLayout(mContext, attributeSet) {
init {
initView()
}
private fun initView() {
View.inflate(mContext, R.layout.home_module_common_title_view, this)
}
fun setTitle(title: String) {
homeModuleCommonTitleViewTitle.text = title
}
}
\ No newline at end of file
package com.yidianling.home.ui.view
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Paint
import android.text.TextUtils
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import com.ydl.ydl_image.config.SimpleImageOpConfiger
import com.ydl.ydl_image.manager.YDLImageCacheManager
import com.yidianling.common.tools.RxImageTool
import com.yidianling.home.R
import com.yidianling.home.event.HomeImpl
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.event.IHomeEvent
import com.yidianling.home.model.bean.HomeConfideBean
import kotlinx.android.synthetic.xlzx.home_module_confide_expert_info_view.view.*
/**
* @author jiucheng
* @描述:首页倾诉模块--专家个人信息view
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2019/2/16
*/
class HomeConfideExpertInfoView(
private var mContext: Context,
private var homeEvent: HomeImpl?
) : FrameLayout(mContext) {
private var dp70 = 0
init {
initView()
dp70 = RxImageTool.dip2px(70f)
}
private fun initView() {
var params = FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
layoutParams = params
View.inflate(context, R.layout.home_module_confide_expert_info_view, this)
}
fun setData(bean: HomeConfideBean.BodyBean?, position: Int, isLast: Boolean) {
if (bean == null) {
visibility = View.GONE
return
}
//设置头像
setHead(bean)
//设置名称
tv_name.text = bean.confidedName
//设置倾诉标签View的最大宽度
tag_view.setConfideWidth()
//咨询师标签
tag_view.initData(bean.confidedTag as MutableList<String>)
//设置向TA倾诉人数
setConfideNum(bean)
//设置接通率文案
setConnection(bean)
//设置向TA倾诉按钮状态
setConfideButton(bean)
//设置红包、原价
setCoupon(bean)
//最后一项显示分割线
if (isLast) {
view_line.visibility = View.GONE
} else {
view_line.visibility = View.VISIBLE
}
this.setOnClickListener {
homeEvent!!.confideClick(bean.linkUrl, bean.doctorId)
}
iv_confide_voice.setOnClickListener {
homeEvent!!.confidePlayClick(iv_confide_voice, bean)
}
}
/**
* 设置头像
*/
private fun setHead(bean: HomeConfideBean.BodyBean) {
val op = SimpleImageOpConfiger()
op.errorPic = R.drawable.platform_head_place_hold_pic
op.loadingPic = R.drawable.platform_head_place_hold_pic
op.transform = 0
YDLImageCacheManager.showImage(mContext, bean.confidedIcon, img_head, op)
}
/**
* 设置向TA倾诉人数
*/
private fun setConfideNum(bodyBean: HomeConfideBean.BodyBean) {
if (TextUtils.isEmpty(bodyBean.confideNum)) {
tv_confideNum.visibility = View.GONE
tv_tv_confideNumContent.visibility = View.GONE
} else {
tv_confideNum.visibility = View.VISIBLE
tv_tv_confideNumContent.visibility = View.VISIBLE
if (bodyBean.confideNum?.indexOf("人") != -1) {
bodyBean.confideNum =
bodyBean.confideNum?.substring(0, bodyBean.confideNum?.length!! - 1)
}
tv_confideNum.text = bodyBean.confideNum
}
}
/**
* 设置接通率文案
*/
private fun setConnection(bodyBean: HomeConfideBean.BodyBean) {
if (TextUtils.isEmpty(bodyBean.confideConnection)) {
tv_Connection.visibility = View.INVISIBLE
tv_ConnectionContent.visibility = View.INVISIBLE
} else {
tv_Connection.visibility = View.VISIBLE
tv_ConnectionContent.visibility = View.VISIBLE
tv_Connection.text = bodyBean.confideConnection
}
}
/**
* 设置向TA倾诉按钮状态
*/
private fun setConfideButton(bodyBean: HomeConfideBean.BodyBean) {
when (bodyBean.confideLine) {//1在线 2离线 3通话中 4继续倾诉
1 -> {
tv_confide.setBackgroundResource(R.drawable.home_module_confide_line_1)
}
2 -> {
tv_confide.setBackgroundResource(R.drawable.home_module_confide_line_2)
}
3 -> {
tv_confide.setBackgroundResource(R.drawable.home_module_confide_line_3)
}
4 -> {
tv_confide.setBackgroundResource(R.drawable.home_module_confide_line_4)
}
}
tv_confide.setOnClickListener {
if (bodyBean.confideLine == 2) {//喊他上线 私聊
homeEvent!!.toChatForMsg(bodyBean.uid.toString())
} else {
homeEvent!!.confideClick(bodyBean.linkUrl,bodyBean.doctorId)
}
}
}
/**
* 设置红包、原价
*/
@SuppressLint("SetTextI18n")
private fun setCoupon(bodyBean: HomeConfideBean.BodyBean) {
if (bodyBean.couponMoney.toFloat().toInt() <= 0) {//优惠金额
tvCoupon.visibility = View.GONE
tvOriginalPrice.visibility = View.GONE
tv_price.text = "¥${bodyBean.confideFee}"
} else {
val couponMoney = bodyBean.couponMoney.toFloat().toInt()
val confideFee = bodyBean.confideFee.toFloat().toInt()
val sb = StringBuilder()
sb.append("立减").append(couponMoney).append("元")
tvCoupon.text = sb.toString()
tvCoupon.visibility = View.VISIBLE
tvOriginalPrice.visibility = View.VISIBLE
val originalBuffer = StringBuilder()
originalBuffer.append("原价¥").append(bodyBean.confideFee)
tvOriginalPrice.text = originalBuffer.toString()
//添加删除线
tvOriginalPrice.paint.flags = Paint.STRIKE_THRU_TEXT_FLAG
if (couponMoney >= confideFee) {
tv_price.text = "¥0"
} else {
val price = confideFee - couponMoney
tv_price.text = "¥$price"
}
}
}
}
package com.yidianling.home.ui.view
import android.content.Context
import android.graphics.Typeface
import android.os.Build
import android.support.design.widget.TabLayout
import android.support.v4.content.ContextCompat
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import com.yidianling.common.tools.LogUtil
import com.yidianling.home.R
import com.yidianling.home.event.HomeImpl
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.model.bean.HomeConfideBean
import com.yidianling.home.model.bean.HomeHeaderBean
import kotlinx.android.synthetic.xlzx.home_module_confide_view.view.*
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 倾诉*排解模块
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/13
*/
class HomeConfideView(private val mContext: Context, private var homeEvent: HomeImpl?) :
LinearLayout(mContext) {
private var mLastPosition: Int = 0
/**
* 专家信息view缓存list
*/
private var cacheInfoViewList: ArrayList<HomeConfideExpertInfoView>? = null
/**
* TabLayout.OnTabSelectedListener
*/
private var listener: ConfideExpertTabSelectedListener? = null
init {
initView()
}
private fun initView() {
val params = RecyclerView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
layoutParams = params
orientation = VERTICAL
View.inflate(mContext, R.layout.home_module_confide_view, this)
homeModuleConfideViewHomeCommonTitleView.setTitle("倾诉·排解")
homeModuleConfideViewHomeCommonTitleView.setOnClickListener {
homeEvent?.confideMoreClick()
}
}
/**
* 创建tab栏
* @param lastPosition 上次选中的下标
*/
fun setTitle(list: List<HomeHeaderBean.ListenCategoryDateBean>?, lastPosition: Int) {
if (list == null || list.isEmpty()) {
visibility = View.GONE
return
}
if (listener != null) {
tab_layout.removeOnTabSelectedListener(listener!!)
}
mLastPosition = lastPosition
tab_layout.removeAllTabs()
for ((index, bean) in list.withIndex()) {
tab_layout.addTab(tab_layout.newTab().setText(bean.name), index == lastPosition)
}
listener = ConfideExpertTabSelectedListener(list, tab_layout)
tab_layout.addOnTabSelectedListener(listener!!)
var textView =
((tab_layout!!.getChildAt(0) as LinearLayout).getChildAt(lastPosition) as LinearLayout).getChildAt(
1
)
if (textView != null && textView is TextView) {
textView.textSize = 21f
textView.setTextColor(ContextCompat.getColor(mContext, R.color.platform_color_242424))
textView.typeface = Typeface.defaultFromStyle(Typeface.BOLD)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
tab_layout.setOnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
LogUtil.e("scrollX=$scrollX")
LogUtil.e("oldScrollX=$oldScrollX")
}
}
}
/**
* 设置数据
*/
fun setConfideExpertInfoView(list: List<HomeConfideBean.BodyBean>?) {
if (list == null || list.isEmpty()) {
ll_content.visibility = View.GONE
return
}
ll_content.visibility = View.VISIBLE
ll_content.removeAllViews()
if (cacheInfoViewList == null) {
cacheInfoViewList = ArrayList()
}
//创建HomeConfideExpertInfoView:每个tab最多显示三个专家
if (cacheInfoViewList!!.size >= list.size) {
for (index in 0 until list!!.size) {
//设置数据
cacheInfoViewList!![index].setData(list[index]!!, index, index == list!!.size - 1)
//添加到布局
ll_content.addView(cacheInfoViewList!![index])
}
} else {
for (index in 0 until list!!.size) {
if (index > 2) {
//只取前三条数据
break
}
//数据大于缓存view数量,创建view
if (index > cacheInfoViewList!!.size - 1) {
var homeConfideExpertInfoView = createExpertInfoView()
cacheInfoViewList!!.add(homeConfideExpertInfoView)
}
//设置数据
cacheInfoViewList!![index].setData(list[index]!!, index, index == list!!.size - 1)
//添加到布局
ll_content.addView(cacheInfoViewList!![index])
}
}
}
/**
* 创建专家信息view
*/
private fun createExpertInfoView(): HomeConfideExpertInfoView {
return HomeConfideExpertInfoView(mContext, homeEvent)
}
inner class ConfideExpertTabSelectedListener : TabLayout.OnTabSelectedListener {
private var list: List<HomeHeaderBean.ListenCategoryDateBean>? = null
private var tabLayout: TabLayout? = null
constructor(list: List<HomeHeaderBean.ListenCategoryDateBean>, tabLayout: TabLayout) {
this.list = list
this.tabLayout = tabLayout
}
override fun onTabReselected(tab: TabLayout.Tab?) {
}
override fun onTabUnselected(tab: TabLayout.Tab?) {
var textView =
((tabLayout!!.getChildAt(0) as LinearLayout).getChildAt(tab!!.position) as LinearLayout).getChildAt(
1
)
if (textView != null && textView is TextView) {
textView.textSize = 14f
textView.setTextColor(
ContextCompat.getColor(
mContext,
R.color.platform_color_333333
)
)
}
}
override fun onTabSelected(tab: TabLayout.Tab?) {
if (mLastPosition == tab!!.position) {
return
}
var textView =
((tabLayout!!.getChildAt(0) as LinearLayout).getChildAt(tab!!.position) as LinearLayout).getChildAt(
1
)
if (textView != null && textView is TextView) {
textView.textSize = 21f
textView.setTextColor(
ContextCompat.getColor(
mContext,
R.color.platform_color_242424
)
)
textView.typeface = Typeface.defaultFromStyle(Typeface.BOLD)
}
homeEvent!!.getConfideData(list!![tab!!.position], tab!!.position)
}
}
}
package com.yidianling.home.ui.view
import android.content.Context
import android.support.v4.content.ContextCompat
import android.text.TextUtils
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import com.ydl.ydl_image.manager.YDLImageCacheManager
import com.ydl.ydlcommon.utils.StringUtils
import com.ydl.ydlcommon.utils.URLUtils
import com.yidianling.common.tools.RxImageTool
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.model.bean.HomeConsultBean
import kotlinx.android.synthetic.xlzx.home_module_consult_item_view.view.*
/**
* @author jiucheng
* @描述:首页咨询理解模块--专家个人信息view
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2019/2/16
*/
class HomeConsultItemView(private var mContext: Context, private var homeEvent: IHomeBaseEvent?) :
FrameLayout(mContext) {
private var dp70 = 0
init {
initView()
dp70 = RxImageTool.dip2px(70f)
}
private fun initView() {
var params = FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
layoutParams = params
View.inflate(context, R.layout.home_module_consult_item_view, this)
}
fun setData(bean: HomeConsultBean.ListBean?, position: Int, isLast: Boolean, cateId: String?) {
if (bean == null) {
visibility = View.GONE
return
}
//设置头像
setHead(bean)
//设置名称
tv_consult_name.text = bean.doctorName
//咨询师标签
tag_view.initData(StringUtils.strToList(bean.tags))
//设置向TA倾诉人数
setConfideNum(bean)
//设置接通率文案
setConnection(bean)
//设置向TA倾诉按钮状态
setConfideButton(bean)
//设置红包、原价
setPrice(bean)
this.setOnClickListener {
val url = URLUtils.appendParmas(bean.hUrl, "cateId", cateId)
homeEvent!!.consultItemClick(url, bean.doctorId)
}
}
/**
* 设置头像
*/
private fun setHead(bean: HomeConsultBean.ListBean) {
YDLImageCacheManager.showImage(mContext, bean?.doctorHead, img_consult_head)
}
/**
* 设置向TA倾诉人数
*/
private fun setConfideNum(bodyBean: HomeConsultBean.ListBean) {
if (TextUtils.isEmpty(bodyBean.zixunOrderNum.toString())) {
tv_consult_num.visibility = View.GONE
tv_tv_consult_num_content.visibility = View.GONE
} else {
tv_consult_num.visibility = View.VISIBLE
tv_tv_consult_num_content.visibility = View.VISIBLE
tv_consult_num.text = bodyBean.zixunOrderNum.toString()
}
}
/**
* 设置接通率文案
*/
private fun setConnection(bodyBean: HomeConsultBean.ListBean) {
if (TextUtils.isEmpty(bodyBean.feedbackRate.toString())) {
tv_feedback_rate.visibility = View.INVISIBLE
tv_feedback_rate_content.visibility = View.INVISIBLE
} else {
tv_feedback_rate.visibility = View.VISIBLE
tv_feedback_rate_content.visibility = View.VISIBLE
try {
val dd = bodyBean.feedbackRate / 5.00f
val str = String.format("%.2f", dd * 100f) + "%"
tv_feedback_rate.text = str
} catch (e: Exception) {
e.printStackTrace()
}
}
}
/**
* 设置向TA倾诉按钮状态
*/
private fun setConfideButton(bodyBean: HomeConsultBean.ListBean) {
//私聊文案
if (TextUtils.isEmpty(bodyBean.chatBtnText)) {
tv_consult_chat.text = "私聊"
tv_consult_chat.setTextColor(
ContextCompat.getColor(
context,
R.color.platform_color_222222
)
)
tv_consult_chat.background =
ContextCompat.getDrawable(context, R.drawable.home_module_consult_chat_bg)
} else {
tv_consult_chat.text = bodyBean.chatBtnText
tv_consult_chat.setTextColor(
ContextCompat.getColor(
context,
R.color.platform_color_999999
)
)
tv_consult_chat.background =
ContextCompat.getDrawable(context, R.drawable.home_module_consult_chat_rest_bg)
}
tv_consult_chat.setOnClickListener {
homeEvent!!.consultChatClick(bodyBean.doctorUid.toString())
}
}
private fun setPrice(bodyBean: HomeConsultBean.ListBean) {
val confideFee = bodyBean.serviceFee
tv_consult_price.text = "¥$confideFee"
}
}
package com.yidianling.home.ui.view
import android.content.Context
import android.graphics.Typeface
import android.os.Build
import android.support.design.widget.TabLayout
import android.support.v4.content.ContextCompat
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import com.yidianling.common.tools.LogUtil
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.model.bean.HomeConsultBean
import com.yidianling.home.model.bean.HomeHeaderBean
import kotlinx.android.synthetic.xlzx.home_module_confide_view.view.*
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 咨询理解模块
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/13
*/
class HomeConsultView(private val mContext: Context, private var homeEvent: IHomeBaseEvent?) :
LinearLayout(mContext) {
private var mLastPosition: Int = 0
/**
* 专家信息view缓存list
*/
private var cacheInfoViewList: ArrayList<HomeConsultItemView>? = null
/**
* TabLayout.OnTabSelectedListener
*/
private var listener: ConsultTabSelectedListener? = null
init {
initView()
}
private fun initView() {
val params = RecyclerView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
layoutParams = params
orientation = VERTICAL
View.inflate(mContext, R.layout.home_module_confide_view, this)
homeModuleConfideViewHomeCommonTitleView.setTitle("咨询·理解")
homeModuleConfideViewHomeCommonTitleView.setOnClickListener {
homeEvent?.consultMoreClick()
}
}
/**
* 创建tab栏
* @param lastPosition 上次选中的下标
*/
fun setTitle(list: List<HomeHeaderBean.ConsultCategoryDateBean>?, lastPosition: Int) {
if (list == null || list.isEmpty()) {
visibility = View.GONE
return
}
if (listener != null) {
tab_layout.removeOnTabSelectedListener(listener!!)
}
mLastPosition = lastPosition
tab_layout.removeAllTabs()
for ((index, bean) in list.withIndex()) {
tab_layout.addTab(tab_layout.newTab().setText(bean.name), index == lastPosition)
}
listener = ConsultTabSelectedListener(list, tab_layout)
tab_layout.addOnTabSelectedListener(listener!!)
var textView =
((tab_layout!!.getChildAt(0) as LinearLayout).getChildAt(lastPosition) as LinearLayout).getChildAt(
1
)
if (textView != null && textView is TextView) {
textView.textSize = 26f
textView.setTextColor(ContextCompat.getColor(mContext, R.color.platform_color_242424))
textView.typeface = Typeface.defaultFromStyle(Typeface.BOLD)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
tab_layout.setOnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
LogUtil.e("scrollX=$scrollX")
LogUtil.e("oldScrollX=$oldScrollX")
}
}
}
/**
* 设置数据
*/
fun setConsultInfoView(
list: List<HomeConsultBean.ListBean>?,
category: HomeHeaderBean.ConsultCategoryDateBean?
) {
if (list == null || list.isEmpty()) {
ll_content.visibility = View.GONE
return
}
ll_content.visibility = View.VISIBLE
ll_content.removeAllViews()
if (cacheInfoViewList == null) {
cacheInfoViewList = ArrayList()
}
//创建HomeConsultItemView:每个tab最多显示三个专家
if (cacheInfoViewList!!.size >= list.size) {
for (index in 0 until list!!.size) {
//设置数据
cacheInfoViewList!![index].setData(
list[index]!!,
index,
index == list!!.size - 1,
"${category?.id}"
)
//添加到布局
ll_content.addView(cacheInfoViewList!![index])
}
} else {
for (index in 0 until list!!.size) {
if (index > 2) {
//只取前三条数据
break
}
//数据大于缓存view数量,创建view
if (index > cacheInfoViewList!!.size - 1) {
var HomeConsultItemView = createConsultInfoView()
cacheInfoViewList!!.add(HomeConsultItemView)
}
//设置数据
cacheInfoViewList!![index].setData(
list[index]!!,
index,
index == list!!.size - 1,
"${category?.id}"
)
//添加到布局
ll_content.addView(cacheInfoViewList!![index])
}
}
}
/**
* 创建专家信息view
*/
private fun createConsultInfoView(): HomeConsultItemView {
return HomeConsultItemView(mContext, homeEvent)
}
inner class ConsultTabSelectedListener : TabLayout.OnTabSelectedListener {
private var list: List<HomeHeaderBean.ConsultCategoryDateBean>? = null
private var tabLayout: TabLayout? = null
constructor(list: List<HomeHeaderBean.ConsultCategoryDateBean>, tabLayout: TabLayout) {
this.list = list
this.tabLayout = tabLayout
}
override fun onTabReselected(tab: TabLayout.Tab?) {
}
override fun onTabUnselected(tab: TabLayout.Tab?) {
var textView =
((tabLayout!!.getChildAt(0) as LinearLayout).getChildAt(tab!!.position) as LinearLayout).getChildAt(
1
)
if (textView != null && textView is TextView) {
textView.textSize = 14f
textView.setTextColor(
ContextCompat.getColor(
mContext,
R.color.platform_color_333333
)
)
}
}
override fun onTabSelected(tab: TabLayout.Tab?) {
if (mLastPosition == tab!!.position) {
return
}
var textView =
((tabLayout!!.getChildAt(0) as LinearLayout).getChildAt(tab!!.position) as LinearLayout).getChildAt(
1
)
if (textView != null && textView is TextView) {
textView.textSize = 26f
textView.setTextColor(
ContextCompat.getColor(
mContext,
R.color.platform_color_242424
)
)
textView.typeface = Typeface.defaultFromStyle(Typeface.BOLD)
}
homeEvent!!.getConsultData(list!![tab!!.position], tab!!.position)
}
}
}
package com.yidianling.home.ui.view
import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.RelativeLayout
import com.ydl.ydl_image.manager.YDLImageCacheManager
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.model.bean.HomeCourseBean
import kotlinx.android.synthetic.xlzx.home_module_course_item_view.view.*
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 课程成长模块item
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/14
*/
class HomeCourseItemView(private val mContext: Context, private var homeEvent: IHomeBaseEvent?) :
RelativeLayout(mContext) {
init {
initView()
}
private fun initView() {
val params = RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
layoutParams = params
View.inflate(mContext, R.layout.home_module_course_item_view, this)
}
/**
* 刷新数据
*/
fun updateData(bean: HomeCourseBean.ListBean?) {
YDLImageCacheManager.showImage(mContext, bean?.pic, homeModuleCourseItemViewImg)
homeModuleCourseItemViewTitle.text = bean?.title
homeModuleCourseItemViewPersonNum.text = bean?.readNums.toString()
if (bean?.applyFee == 0f) {
homeModuleCourseItemViewFreePrice.visibility = View.VISIBLE
homeModuleCourseItemViewExpensePriceHideView.visibility = View.GONE
} else {
if (bean?.isPromotion == 1) {
homeModuleCourseItemViewExpensePrice.text =
"¥" + String.format("%.2f", bean?.promotionApplyFee!!)
} else {
homeModuleCourseItemViewExpensePrice.text =
"¥" + String.format("%.2f", bean?.applyFee!!)
}
}
setOnClickListener {
homeEvent?.courseItemClick(bean)
}
}
}
\ No newline at end of file
package com.yidianling.home.ui.view
import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.model.bean.HomeCourseBean
import kotlinx.android.synthetic.xlzx.home_module_course_view.view.*
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 课程*成长模块
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/13
*/
class HomeCourseView(private val mContext: Context, private var homeEvent: IHomeBaseEvent?) :
LinearLayout(mContext) {
private var cacheList: ArrayList<HomeCourseBean.ListBean> = ArrayList()
init {
initView()
}
private fun initView() {
orientation = VERTICAL
val params = LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
layoutParams = params
View.inflate(mContext, R.layout.home_module_course_view, this)
homeModuleCourseViewHomeCommonTitleView.setTitle("课程·成长")
homeModuleCourseViewHomeCommonTitleView.setOnClickListener {
homeEvent?.courseMreClick()
}
}
fun initData(list: List<HomeCourseBean.ListBean>?) {
//添加View
if (list == null) {
return
}
if (cacheList.size != list?.size) {
cacheList.clear()
cacheList.addAll(list!!)
updateHomeCourseItemViewNumber()
}
//刷新数据
for (index in 0 until childCount) {
val itemView = getChildAt(index)
if (itemView is HomeCourseItemView) {
itemView.updateData(list[index - 1])
}
}
}
/**
* 更新itemView的数量以适应新的数据集
*/
private fun updateHomeCourseItemViewNumber() {
var childCountRecord = childCount - 1 //减1是因为第一个子View是标题View
while (cacheList.size > childCountRecord) {
addView(HomeCourseItemView(mContext, homeEvent))
childCountRecord++
}
while (cacheList.size < childCountRecord && getChildAt(childCountRecord - 1) is HomeCourseItemView) {
removeViewAt(childCountRecord - 1)
childCountRecord--
}
}
}
\ No newline at end of file
package com.yidianling.home.ui.view
import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.yidianling.common.tools.RxImageTool
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.model.bean.HomeFMBean
import kotlinx.android.synthetic.xlzx.home_module_intelligent_item_view.view.*
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 心灵电台模块item
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/14
*/
class HomeIntelligentItemView(
private val mContext: Context,
private var homeEvent: IHomeBaseEvent?
) : LinearLayout(mContext) {
private var params: LinearLayout.LayoutParams? = null
init {
initView()
}
private fun initView() {
orientation = VERTICAL
params = LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
layoutParams = params
View.inflate(mContext, R.layout.home_module_intelligent_item_view, this)
}
/**
* 刷新数据
*/
fun updateData(bean: HomeFMBean.ListBean) {
homeModuleIntelligentItemViewTitle.text = bean.name
homeModuleIntelligentItemViewHits.text = bean.hits.toString()
this.setOnClickListener { homeEvent?.fmItemClick(bean) }
iv_fm_play.setOnClickListener { homeEvent?.fmPlayClick(bean) }
}
/**
* 电台第二个item会有一个marginTop值
*/
fun setTopMargin() {
params?.topMargin = RxImageTool.dp2px(16f)
layoutParams = params
}
/**
* 电台最后一个item会有一个marginBottom值
*/
fun setBottomMargin() {
params?.bottomMargin = RxImageTool.dp2px(16f)
layoutParams = params
}
}
\ No newline at end of file
package com.yidianling.home.ui.view
import android.content.Context
import android.view.View
import android.widget.LinearLayout
import com.ydl.ydl_image.manager.YDLImageCacheManager
import com.yidianling.common.tools.RxDeviceTool
import com.yidianling.common.tools.RxImageTool
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.model.bean.HomeFMBean
import kotlinx.android.synthetic.xlzx.home_module_intelligent_top_item_view.view.*
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 心灵电台模块item--顶部item
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/15
*/
class HomeIntelligentTopItemView(
private val mContext: Context,
private var homeEvent: IHomeBaseEvent?
) : LinearLayout(mContext) {
init {
initView()
}
private fun initView() {
orientation = VERTICAL
var screenWidth = RxDeviceTool.getScreenWidth(mContext)
var viewWidth = (screenWidth - 2 * 15 * RxDeviceTool.getScreenDensity(mContext)).toInt()
var viewHeight = viewWidth * 143 / 345
val params = LinearLayout.LayoutParams(viewWidth, viewHeight)
layoutParams = params
View.inflate(mContext, R.layout.home_module_intelligent_top_item_view, this)
}
/**
* 刷新数据
*/
fun updateData(bean: HomeFMBean.ListBean) {
var screenWidth = RxDeviceTool.getScreenWidth(mContext)
var viewWidth = (screenWidth - RxImageTool.dip2px(30f))
var viewHeight = viewWidth * 143 / 345
YDLImageCacheManager.showImage(
mContext,
bean?.imageUrl,
homeModuleIntelligentTopViewImage,
viewWidth,
viewHeight
)
homeModuleIntelligentTopViewTitle.text = bean.name
homeModuleIntelligentTopViewAuthor.text = bean.author
homeModuleIntelligentTopViewHits.text = bean.hits.toString()
this.setOnClickListener { homeEvent?.fmItemClick(bean) }
iv_play_fm.setOnClickListener { homeEvent?.fmPlayClick(bean) }
}
}
\ No newline at end of file
package com.yidianling.home.ui.view
import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.model.bean.HomeFMBean
import kotlinx.android.synthetic.xlzx.home_module_intelligent_view.view.*
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 心灵*电台模块
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/13
*/
class HomeIntelligentView(private val mContext: Context, private var homeEvent: IHomeBaseEvent?) :
LinearLayout(mContext) {
private var cacheList: ArrayList<HomeFMBean.ListBean> = ArrayList()
init {
initView()
}
private fun initView() {
orientation = VERTICAL
val params = LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
layoutParams = params
View.inflate(mContext, R.layout.home_module_intelligent_view, this)
homeModuleIntelligentViewHomeCommonTitleView.setTitle("心灵·电台")
homeModuleIntelligentViewHomeCommonTitleView.setOnClickListener {
homeEvent?.fmMoreClick()
}
}
fun initData(list: List<HomeFMBean.ListBean>?) {
//添加View
if (list == null) {
return
}
if (cacheList.size != list?.size) {
cacheList.clear()
cacheList.addAll(list)
updateHomeIntelligentItemViewNumber()
}
//刷新数据
for (index in 0 until homeModuleIntelligentViewAddLayout.childCount) {
val itemView = homeModuleIntelligentViewAddLayout.getChildAt(index)
if (itemView is HomeIntelligentItemView) {
//第一个这种类型item,需要设置marginTop = 16dp,最后一个item需要设置marginBototm = 16dp
if (index == 1) {
itemView.setTopMargin()
} else if (index == homeModuleIntelligentViewAddLayout.childCount - 1) {
itemView.setBottomMargin()
}
itemView.updateData(list[index])
} else if (itemView is HomeIntelligentTopItemView) {
itemView.updateData(list[index])
}
}
}
/**
* 更新itemView的数量以适应新的数据集
*/
private fun updateHomeIntelligentItemViewNumber() {
var childCountRecord = homeModuleIntelligentViewAddLayout.childCount
while (cacheList.size > childCountRecord) {
if (childCountRecord == 0) {
homeModuleIntelligentViewAddLayout.addView(
HomeIntelligentTopItemView(
mContext,
homeEvent
)
)
} else {
homeModuleIntelligentViewAddLayout.addView(
HomeIntelligentItemView(
mContext,
homeEvent
)
)
}
childCountRecord++
}
while (cacheList.size < childCountRecord &&
(homeModuleIntelligentViewAddLayout.getChildAt(childCountRecord - 1) is HomeIntelligentItemView
|| homeModuleIntelligentViewAddLayout.getChildAt(childCountRecord - 1) is HomeIntelligentTopItemView)
) {
homeModuleIntelligentViewAddLayout.removeViewAt(childCountRecord - 1)
childCountRecord--
}
}
}
\ No newline at end of file
package com.yidianling.home.ui.view
import android.content.Context
import android.graphics.Color
import android.util.TypedValue
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import com.ydl.ydl_image.module.GlideApp
import com.ydl.ydlcommon.utils.ScreenUtil
import com.yidianling.common.tools.RxImageTool
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.event.IHomeEvent
import com.yidianling.home.model.bean.HomeHeaderBean
import kotlinx.android.synthetic.xlzx.home_module_pager_banner_category_view.view.*
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 首页顶部模块-分类模块
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/16
*/
class HomePagerBannerCategoryView(mContext: Context, homeEvent: IHomeBaseEvent) :
FrameLayout(mContext) {
/**
* 数据缓存
*/
var mDataList: ArrayList<HomeHeaderBean.AskCategoryDataBean>? = null
/**
* 分类view宽度
*/
var categoryWidth: Int = 0
/**
* 图片宽高
*/
var imageViewWidth: Int = 0
/**
* 文本宽度
*/
var textViewWidth: Int = 0
/**
* 文本高度
*/
var textViewHeight: Int = 0
/**
* 间隔
*/
var margin: Int = 0
var dp8: Int = 0
/**
* 是否添加了实时测试状态View
*/
var hasRealTestView: Boolean = false
private var realTestView: HomePagerBannerRealView? = null
/**
* 线
*/
private var lineView: View? = null
/**
* 图片View缓存
*/
private var imageViewCache: List<ImageView>? = null
/**
* 文本View缓存
*/
private var textViewCache: List<TextView>? = null
/**
* 倍数
*/
private var multiple: Int = 0
/**
* 测评首页事件处理类
*/
private var homeEvent: IHomeBaseEvent? = null
init {
initView()
this.homeEvent = homeEvent
}
/**
* 界面初始化
*/
private fun initView() {
View.inflate(context, R.layout.home_module_pager_banner_category_view, this)
val params = FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT
)
// params.topMargin = ScreenUtil.screenHeight * (356f / 750f).toInt()
layoutParams = params
initArgs()
}
/**
* 初始化变量
*/
private fun initArgs() {
categoryWidth = ScreenUtil.screenWidth - RxImageTool.dp2px(30f)
textViewWidth = categoryWidth / 4
imageViewWidth = RxImageTool.dip2px(38f)
margin = (categoryWidth - 4 * imageViewWidth) / 8
dp8 = RxImageTool.dip2px(8f)
//高度=文字12dp+16dp间距
textViewHeight = RxImageTool.dip2px(28f)
}
fun initData(
askCategoryDataBean: List<HomeHeaderBean.AskCategoryDataBean>?,
homeSaleData: List<HomeHeaderBean.HomeSaleDataBean>?
) {
if (null == askCategoryDataBean || askCategoryDataBean.isEmpty()) {
visibility = View.GONE
return
}
visibility = View.VISIBLE
if (null == mDataList) {
mDataList = ArrayList()
}
if (getChange(askCategoryDataBean, mDataList)) {
mDataList!!.clear()
mDataList!!.addAll(askCategoryDataBean)
}
refreshView()
setRealTextView(homeSaleData)
}
/**
* 判断数据是否变化
*/
private fun getChange(
bean: List<HomeHeaderBean.AskCategoryDataBean>?,
cacheBean: List<HomeHeaderBean.AskCategoryDataBean>?
): Boolean {
if (bean?.size != cacheBean?.size) {
return true
}
for (index in 0 until bean?.size!!) {
if (!bean[index].url.equals(cacheBean!![index].url)
|| !bean[index].coverUrl.equals(cacheBean!![index].coverUrl)
|| !bean[index].cateTitle.equals(cacheBean!![index].cateTitle)
|| bean[index].cateId != cacheBean!![index].cateId
) {
return true
}
}
return false
}
/**
* 刷新View
*/
private fun refreshView() {
var i = 0
if (null == imageViewCache) {
imageViewCache = ArrayList()
}
if (null == textViewCache) {
textViewCache = ArrayList()
}
var imageCount = imageViewCache!!.size
for (item in mDataList!!) {
if (i > 7) {
break
}
if (i >= imageCount) {
val imageView = createIcon(i)
val textView = createText(i)
(imageViewCache as ArrayList).add(imageView)
(textViewCache as ArrayList).add(textView)
homeModulePagerBannerFlRoot.addView(imageView)
homeModulePagerBannerFlRoot.addView(textView)
imageView.setOnClickListener {
homeEvent!!.categoryClick(item)
}
textView.setOnClickListener {
homeEvent!!.categoryClick(item)
}
}
bindIconData(imageViewCache!![i], item)
bindTextData(textViewCache!![i], item)
i++
}
}
/**
* 创建图标
*/
private fun createIcon(i: Int): ImageView {
val imageParams = FrameLayout.LayoutParams(imageViewWidth, imageViewWidth)
val imageView = ImageView(context)
imageView.scaleType = ImageView.ScaleType.CENTER_CROP
if (i > 3) {
multiple = 2
imageParams.topMargin = imageViewWidth + dp8 + textViewHeight
imageParams.leftMargin = margin * (i - 3) + (i - 4) * (imageViewWidth + margin)
} else {
multiple = 1
imageParams.leftMargin = margin * (i + 1) + i * (imageViewWidth + margin)
}
imageView.layoutParams = imageParams
return imageView
}
/**
* 加载图片
*/
private fun bindIconData(
imageView: ImageView,
categoryBean: HomeHeaderBean.AskCategoryDataBean
) {
GlideApp.with(context).load(categoryBean.coverUrl)
.centerCrop().into(imageView)
}
/**
* 创建文本
*/
private fun createText(index: Int): TextView {
val textParams = FrameLayout.LayoutParams(textViewWidth, textViewHeight)
val textView = TextView(context)
textView.setTextColor(Color.parseColor("#242424"))
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12f)
textView.gravity = Gravity.CENTER_HORIZONTAL
if (index > 3) {
textParams.topMargin = 2 * (imageViewWidth + dp8) + textViewHeight
textParams.leftMargin = textViewWidth * (index - 4)
} else {
textParams.topMargin = imageViewWidth + dp8
textParams.leftMargin = textViewWidth * (index)
}
textView.layoutParams = textParams
return textView
}
/**
* 设置文本
*/
private fun bindTextData(textView: TextView, categoryBean: HomeHeaderBean.AskCategoryDataBean) {
textView.text = categoryBean.cateTitle
}
/**
* 初始化实时测评状态View
*/
private fun initRealTextView() {
if (null == realTestView) {
var realTestParam = FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
realTestParam.topMargin =
multiple * (imageViewWidth + dp8 + textViewHeight) + dp8 + RxImageTool.dip2px(10f)
realTestView = HomePagerBannerRealView(context, homeEvent!!)
realTestView!!.layoutParams = realTestParam
}
}
private fun initLineView() {
var lineParam =
FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, RxImageTool.dip2px(0.5f))
var dp15 = RxImageTool.dip2px(15f)
lineParam.leftMargin = dp15
lineParam.rightMargin = dp15
lineParam.topMargin = multiple * (imageViewWidth + dp8 + textViewHeight) + dp8
lineView = View(context)
lineView!!.setBackgroundColor(resources.getColor(R.color.home_module_category_view_test_line))
lineView!!.layoutParams = lineParam
}
/**
* 实时测评状态赋值
*/
private fun setRealTextView(list: List<HomeHeaderBean.HomeSaleDataBean>?) {
if (!hasRealTestView) {
initLineView()
homeModulePagerBannerFlRoot.addView(lineView)
initRealTextView()
homeModulePagerBannerFlRoot.addView(realTestView)
hasRealTestView = true
}
realTestView!!.initData(list)
}
fun onDestory() {
if (null == realTestView) {
return
}
realTestView!!.onDestory()
}
}
\ No newline at end of file
package com.yidianling.home.ui.view
import android.content.Context
import android.os.Handler
import android.os.Looper
import android.os.Message
import android.view.View
import android.view.ViewGroup
import android.view.animation.Animation
import android.view.animation.DecelerateInterpolator
import android.view.animation.TranslateAnimation
import android.widget.LinearLayout
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.model.bean.HomeHeaderBean
import kotlinx.android.synthetic.xlzx.home_module_real_view_in.view.*
import kotlinx.android.synthetic.xlzx.home_module_real_view_left.view.*
import kotlinx.android.synthetic.xlzx.home_module_real_view_out.view.*
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 首页顶部模块-动态标签模块
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/16
*/
class HomePagerBannerRealView(mContext: Context, homeEvent: IHomeBaseEvent) :
LinearLayout(mContext) {
private val STATUS_IN = 0
private val STATUS_OUT = 1
private var curTipIndex = 0
private var lastTimeMillis: Long = 0
private val ANIM_DELAYED_MILLIONS = 2 * 1000
/**
* 动画持续时长
*/
private val ANIM_DURATION = 500
/**
* 进、出 两个view (主要用于做动画,其实是两个相同的布局文件)
*/
private var view_out: View? = null
private var view_in: View? = null
/**
* 进、出 两个View 的动画
*/
private var anim_out: Animation? = null
private var anim_in: Animation? = null
/**
* 数据缓存
*/
private var mDataList: List<HomeHeaderBean.HomeSaleDataBean>? = null
private var homeEvent: IHomeBaseEvent? = null
private val mHandler: Handler = object : Handler(Looper.getMainLooper()) {
override fun handleMessage(msg: Message?) {
super.handleMessage(msg)
updateTipAndPlayAnimation()
sendMessageDelayed(Message(), ANIM_DELAYED_MILLIONS.toLong())
}
}
init {
this.homeEvent = homeEvent
initView()
initAnimation()
}
/**
* 界面初始化
*/
private fun initView() {
orientation = HORIZONTAL
var params = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
View.inflate(context, R.layout.home_module_real_view_left, this)
view_out = View.inflate(context, R.layout.home_module_real_view_out, null)
view_in = View.inflate(context, R.layout.home_module_real_view_in, null)
homeModuleRealViewLeftFrameLayout.addView(view_out)
homeModuleRealViewLeftFrameLayout.addView(view_in)
layoutParams = params
}
private fun initAnimation() {
anim_out = newAnimation(0f, -1f)
anim_in = newAnimation(1f, 0f)
anim_in!!.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation) {
}
override fun onAnimationRepeat(animation: Animation) {
}
override fun onAnimationEnd(animation: Animation) {
updateViewVisibility()
}
})
}
/**
* 设置数据
*/
fun initData(list: List<HomeHeaderBean.HomeSaleDataBean>?) {
mHandler.removeCallbacksAndMessages(null)
if (null == list || list.isEmpty()) {
visibility = View.GONE
return
}
visibility = View.VISIBLE
if (null == mDataList) {
mDataList = ArrayList()
} else {
(mDataList as ArrayList).clear()
}
(mDataList as ArrayList).addAll(list)
curTipIndex = 0
updateTip(STATUS_OUT)
updateTipAndPlayAnimation()
mHandler.sendMessageDelayed(Message(), ANIM_DELAYED_MILLIONS.toLong())
}
private fun updateViewVisibility() {
if (curTipIndex % 2 == 0) {
view_out!!.visibility = View.INVISIBLE
} else {
view_in!!.visibility = View.INVISIBLE
}
}
private fun newAnimation(fromYValue: Float, toYValue: Float): Animation {
val anim = TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f,
Animation.RELATIVE_TO_SELF, fromYValue, Animation.RELATIVE_TO_SELF, toYValue
)
anim.duration = ANIM_DURATION.toLong()
anim.interpolator = DecelerateInterpolator()
return anim
}
private fun updateTipAndPlayAnimation() {
view_in!!.visibility = View.VISIBLE
view_out!!.visibility = View.VISIBLE
if (curTipIndex % 2 == 0) {
updateTip(STATUS_OUT)
view_in!!.startAnimation(anim_out)
view_out!!.startAnimation(anim_in)
this.bringChildToFront(view_in)
} else {
updateTip(STATUS_IN)
view_out!!.startAnimation(anim_out)
view_in!!.startAnimation(anim_in)
this.bringChildToFront(view_out)
}
}
private fun updateTip(status: Int) {
val bodyBean = getNextTip() ?: return
when (status) {
STATUS_IN -> {
tv_in_doctor_name.text = bodyBean.doctorName
tv_in_content_before.text = getName(bodyBean)
tv_in_content_after.text = String.format("老师%s", bodyBean.contentAfter)
view_in!!.setOnClickListener {
homeEvent!!.linkTo(bodyBean.url!!)
}
}
STATUS_OUT -> {
tv_out_doctor_name.text = bodyBean.doctorName
tv_out_content_before.text = getName(bodyBean)
tv_out_content_after.text = String.format("老师%s", bodyBean.contentAfter)
view_out!!.setOnClickListener {
homeEvent!!.linkTo(bodyBean.url!!)
}
}
}
}
private fun getName(bean: HomeHeaderBean.HomeSaleDataBean?): String {
var nameBuffer = StringBuffer()
nameBuffer.append(bean?.contentBefore)
nameBuffer.append(" ")
nameBuffer.append(bean?.nickName)
nameBuffer.append(resources.getString(R.string.home_module_real_appoint))
return nameBuffer.toString()
}
private fun getNextTip(): HomeHeaderBean.HomeSaleDataBean? {
if (null == mDataList || mDataList!!.isEmpty()) {
return null
}
return mDataList!![curTipIndex++ % mDataList!!.size]
}
fun onDestory() {
mHandler.removeCallbacksAndMessages(null)
}
}
\ No newline at end of file
package com.yidianling.home.ui.view
import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.RelativeLayout
import com.ydl.ydlcommon.view.banner.GlideImageLoader
import com.yidianling.common.tools.RxDeviceTool
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.model.bean.HomeHeaderBean
import kotlinx.android.synthetic.xlzx.home_module_pager_banner_view.view.*
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述:顶部ViewPager与分类模块
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/13
*/
class HomePagerBannerView(private val mContext: Context, private var homeEvent: IHomeBaseEvent?) :
RelativeLayout(mContext) {
private val mImageViews = ArrayList<String>()
private var homePagerBannerCategoryView: HomePagerBannerCategoryView? = null
init {
initView()
}
private fun initView() {
var screenWidth = RxDeviceTool.getScreenWidth(mContext)
val params = RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
layoutParams = params
View.inflate(mContext, R.layout.home_module_pager_banner_view, this)
initBannerLayout()
// val addLayoutParams = RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
// addLayoutParams.setMargins(0, (ScreenUtil.screenWidth * (356f / 750f)).toInt(),0,0)
// homeModulePagerBannerViewAddLayout.layoutParams = addLayoutParams
// if (null == homePagerBannerCategoryView) {
// homePagerBannerCategoryView = HomePagerBannerCategoryView(mContext, homeEvent!!)
// homeModulePagerBannerViewAddLayout.addView(homePagerBannerCategoryView)
// }
}
private fun initBannerLayout() {
// var screenWidth = RxDeviceTool.getScreenWidth(mContext)
// var viewHeight = screenWidth * 508 / 750
// val params = RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, viewHeight)
// homeModulePagerBannerViewBanner.layoutParams = params
homeModulePagerBannerViewBanner.setIndicatorBottomPadding(50)
}
/**
* 填充数据
*/
fun initData(bean: HomeHeaderBean?) {
initCategory(bean?.askCategoryData, bean?.homeSaleData)
initBanner(bean?.focusList)
}
/**
* 更新分类细目
*/
private fun initCategory(
categoryBean: List<HomeHeaderBean.AskCategoryDataBean>?,
homeSaleData: List<HomeHeaderBean.HomeSaleDataBean>?
) {
homePagerBannerCategoryView!!.initData(categoryBean, homeSaleData)
}
/**
* 更新banner
*/
private fun initBanner(focusListBean: List<HomeHeaderBean.FocusListBean>?) {
//临时缓存集合
val cacheList = ArrayList<HomeHeaderBean.FocusListBean>()
if (null != focusListBean && focusListBean.isNotEmpty()) {
mImageViews.clear()
//产品说取前8个
if (focusListBean.size > 8) {
cacheList.addAll(focusListBean.subList(0, 8))
} else {
cacheList.addAll(focusListBean)
}
for (item in cacheList) {
mImageViews.add(item.imageUrl!!)
}
}
homeModulePagerBannerViewBanner.setImageLoader(GlideImageLoader(R.drawable.home_module_image_default_back))
.setImages(mImageViews).start()
homeModulePagerBannerViewBanner.setOnBannerListener {
homeEvent?.bannerClick(cacheList!![it])
}
}
fun startBanner() {
if (homeModulePagerBannerViewBanner != null) {
homeModulePagerBannerViewBanner.startAutoPlay()
}
}
fun stopBanner() {
if (homeModulePagerBannerViewBanner != null) {
homeModulePagerBannerViewBanner.stopAutoPlay()
}
}
}
\ No newline at end of file
package com.yidianling.home.ui.view
import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.ydl.ydl_image.manager.YDLImageCacheManager
import com.yidianling.common.tools.RxImageTool
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.model.bean.HomeTestItemBean
import kotlinx.android.synthetic.xlzx.home_module_test_item_view.view.*
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 心灵电台模块item
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/14
*/
class HomeTestItemView(private val mContext: Context, private var homeEvent: IHomeBaseEvent?) :
LinearLayout(mContext) {
private var params: LinearLayout.LayoutParams? = null
init {
initView()
}
private fun initView() {
orientation = VERTICAL
params = LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
layoutParams = params
View.inflate(mContext, R.layout.home_module_test_item_view, this)
}
/**
* 刷新数据
*/
fun updateData(bean: HomeTestItemBean, isLast: Boolean) {
tv_test_item_name.text = bean.name
tv_test_item_hit.text = bean.hits.toString()
tv_tested_count.text = bean.testNum.toString()
YDLImageCacheManager.showImage(mContext, bean?.shareImage, iv_test_item)
if (isLast) {
view_test_line.visibility = View.GONE
} else {
view_test_line.visibility = View.VISIBLE
}
this.setOnClickListener {
homeEvent?.testItemClick(bean.recommendLinkUrl)
}
}
/**
* 电台第二个item会有一个marginTop值
*/
fun setTopMargin() {
params?.topMargin = RxImageTool.dp2px(16f)
layoutParams = params
}
/**
* 电台最后一个item会有一个marginBottom值
*/
fun setBottomMargin() {
params?.bottomMargin = RxImageTool.dp2px(16f)
layoutParams = params
}
}
\ No newline at end of file
package com.yidianling.home.ui.view
import android.content.Context
import android.view.View
import android.widget.LinearLayout
import com.ydl.ydl_image.config.ISimpleImageOpConfig
import com.ydl.ydl_image.config.SimpleImageOpConfiger
import com.ydl.ydl_image.manager.YDLImageCacheManager
import com.yidianling.common.tools.RxDeviceTool
import com.yidianling.common.tools.RxImageTool
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.model.bean.HomeTestItemBean
import kotlinx.android.synthetic.xlzx.home_module_test_top_item_view.view.*
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 心灵电台模块item--顶部item
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/15
*/
class HomeTestTopItemView(private val mContext: Context, private var homeEvent: IHomeBaseEvent?) :
LinearLayout(mContext) {
init {
initView()
}
private fun initView() {
orientation = VERTICAL
var screenWidth = RxDeviceTool.getScreenWidth(mContext)
var viewWidth = (screenWidth - 2 * 15 * RxDeviceTool.getScreenDensity(mContext)).toInt()
var viewHeight = viewWidth * 143 / 345
val params = LinearLayout.LayoutParams(viewWidth, viewHeight)
layoutParams = params
View.inflate(mContext, R.layout.home_module_test_top_item_view, this)
}
/**
* 刷新数据
*/
fun updateData(bean: HomeTestItemBean) {
var screenWidth = RxDeviceTool.getScreenWidth(mContext)
var viewWidth = (screenWidth - RxImageTool.dip2px(30f))
var viewHeight = viewWidth * 143 / 345
val sp = SimpleImageOpConfiger()
sp.loadingPic = R.drawable.platform_default_img
sp.errorPic = R.drawable.platform_default_img
sp.scaleType = ISimpleImageOpConfig.CENTER_CROP
sp.isCacheOnDisk = true
YDLImageCacheManager.showImage(
mContext,
bean?.shareImage,
homeModuleIntelligentTopViewImage,
viewWidth,
viewHeight,
sp
)
homeModuleIntelligentTopViewTitle.text = bean.name
homeModuleIntelligentTopViewAuthor.text = bean.hits.toString()
homeModuleIntelligentTopViewHits.text = bean.testNum.toString()
this.setOnClickListener {
homeEvent?.testItemClick(bean.recommendLinkUrl)
}
}
}
\ No newline at end of file
package com.yidianling.home.ui.view
import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.yidianling.home.R
import com.yidianling.home.event.HomeImpl
import com.yidianling.home.event.IHomeEvent
import com.yidianling.home.model.bean.HomeTestItemBean
import kotlinx.android.synthetic.xlzx.home_module_test_view.view.*
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 心灵*电台模块
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/13
*/
class HomeTestView(private val mContext: Context, private var homeEvent: HomeImpl?) : LinearLayout(mContext) {
private var cacheList : ArrayList<HomeTestItemBean> = ArrayList()
init {
initView()
}
private fun initView() {
orientation = VERTICAL
val params = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
layoutParams = params
View.inflate(mContext, R.layout.home_module_test_view, this)
homeModuleIntelligentViewHomeCommonTitleView.setTitle("测试·分析")
homeModuleIntelligentViewHomeCommonTitleView.setOnClickListener {
homeEvent?.testMoreClick()
}
}
fun initData(list: List<HomeTestItemBean>?) {
//添加View
if(list==null){
return
}
if (cacheList.size != list?.size){
cacheList.clear()
cacheList.addAll(list!!)
updateHomeTestItemViewNumber()
}
for (index in 0 until homeModuleIntelligentViewAddLayout.childCount){
val itemView = homeModuleIntelligentViewAddLayout.getChildAt(index)
if (itemView is HomeTestItemView){
//第一个这种类型item,需要设置marginTop = 16dp,最后一个item需要设置marginBototm = 16dp
if (index == 1) {
itemView.setTopMargin()
}
// else if (index == homeModuleIntelligentViewAddLayout.childCount -1) {
// itemView.setBottomMargin()
// }
itemView.updateData(list[index],index == list.size - 1)
}else if (itemView is HomeTestTopItemView) {
itemView.updateData(list[index])
}
}
}
/**
* 更新itemView的数量以适应新的数据集
*/
private fun updateHomeTestItemViewNumber() {
var childCountRecord = homeModuleIntelligentViewAddLayout.childCount
while (cacheList.size > childCountRecord) {
if (childCountRecord == 0) {
homeModuleIntelligentViewAddLayout.addView(HomeTestTopItemView(mContext, homeEvent))
}else {
homeModuleIntelligentViewAddLayout.addView(HomeTestItemView(mContext, homeEvent))
}
childCountRecord++
}
while (cacheList.size < childCountRecord &&
(homeModuleIntelligentViewAddLayout.getChildAt(childCountRecord -1 ) is HomeTestItemView
|| homeModuleIntelligentViewAddLayout.getChildAt(childCountRecord -1 ) is HomeTestTopItemView)) {
homeModuleIntelligentViewAddLayout.removeViewAt(childCountRecord -1 )
childCountRecord--
}
}
}
\ No newline at end of file
package com.yidianling.home.ui.widget
import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.util.TypedValue
import android.view.Gravity
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import com.ydl.ydl_image.module.GlideApp
import com.ydl.ydlcommon.utils.ScreenUtil
import com.yidianling.common.tools.RxImageTool
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.model.bean.HomeHeaderBean
import com.yidianling.home.ui.view.HomePagerBannerRealView
import kotlinx.android.synthetic.xlzx.home_module_pager_banner_category_view.view.*
/**
* @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
* @描述: 首页顶部模块-分类模块
* @Copyright Copyright (c) 2019
* @Company 壹点灵
* @date 2019/02/16
*/
class HomeModuleCategoryView : FrameLayout {
/**
* 数据缓存
*/
var mDataList: ArrayList<HomeHeaderBean.AskCategoryDataBean>? = null
/**
* 分类view宽度
*/
var categoryWidth: Int = 0
/**
* 图片宽高
*/
var imageViewWidth: Int = 0
/**
* 文本宽度
*/
var textViewWidth: Int = 0
/**
* 文本高度
*/
var textViewHeight: Int = 0
/**
* 间隔
*/
var margin: Int = 0
var dp8: Int = 0
private var realTestView: HomePagerBannerRealView? = null
/**
* 倍数
*/
private var multiple: Int = 0
/**
* 测评首页事件处理类
*/
private var homeEvent: IHomeBaseEvent? = null
constructor(context: Context?) : super(context) {
HomeModuleCategoryView(context, null)
}
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
initView();
}
fun setEvent(homeEvent: IHomeBaseEvent) {
this.homeEvent = homeEvent
}
/**
* 界面初始化
*/
private fun initView() {
View.inflate(context, R.layout.home_module_pager_banner_category_view, this)
val params = FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT
)
// params.topMargin = ScreenUtil.screenHeight * (356f / 750f).toInt()
layoutParams = params
initArgs()
}
/**
* 初始化变量
*/
private fun initArgs() {
categoryWidth = ScreenUtil.screenWidth - RxImageTool.dp2px(30f)
textViewWidth = categoryWidth / 4
imageViewWidth = RxImageTool.dip2px(38f)
margin = (categoryWidth - 4 * imageViewWidth) / 8
dp8 = RxImageTool.dip2px(8f)
//高度=文字12dp+16dp间距
textViewHeight = RxImageTool.dip2px(28f)
}
fun initData(askCategoryDataBean: List<HomeHeaderBean.AskCategoryDataBean>?) {
if (null == askCategoryDataBean || askCategoryDataBean.isEmpty()) {
visibility = View.GONE
return
}
visibility = View.VISIBLE
if (null == mDataList) {
mDataList = ArrayList()
}
if (getChange(askCategoryDataBean, mDataList)) {
mDataList!!.clear()
mDataList!!.addAll(askCategoryDataBean)
}
refreshView()
}
/**
* 判断数据是否变化
*/
private fun getChange(
bean: List<HomeHeaderBean.AskCategoryDataBean>?,
cacheBean: List<HomeHeaderBean.AskCategoryDataBean>?
): Boolean {
if (bean?.size != cacheBean?.size) {
return true
}
for (index in 0 until bean?.size!!) {
if (!bean[index].url.equals(cacheBean!![index].url)
|| !bean[index].coverUrl.equals(cacheBean!![index].coverUrl)
|| !bean[index].cateTitle.equals(cacheBean!![index].cateTitle)
|| bean[index].cateId != cacheBean!![index].cateId
) {
return true
}
}
return false
}
/**
* 刷新View
*/
private fun refreshView() {
homeModulePagerBannerFlRoot.removeAllViews()
var i = 0
for (item in mDataList!!) {
if (i > 7) {
break
}
val imageView = createIcon(i)
val textView = createText(i)
homeModulePagerBannerFlRoot.addView(imageView)
homeModulePagerBannerFlRoot.addView(textView)
imageView.setOnClickListener {
homeEvent!!.categoryClick(item)
}
textView.setOnClickListener {
homeEvent!!.categoryClick(item)
}
bindIconData(imageView, item)
bindTextData(textView, item)
i++
}
}
/**
* 创建图标
*/
private fun createIcon(i: Int): ImageView {
val imageParams = FrameLayout.LayoutParams(imageViewWidth, imageViewWidth)
val imageView = ImageView(context)
imageView.scaleType = ImageView.ScaleType.CENTER_CROP
if (i > 3) {
multiple = 2
imageParams.topMargin =
imageViewWidth + dp8 + textViewHeight + dp8 + RxImageTool.dip2px(1f)
imageParams.leftMargin = margin * (i - 3) + (i - 4) * (imageViewWidth + margin)
} else {
multiple = 1
imageParams.leftMargin = margin * (i + 1) + i * (imageViewWidth + margin)
}
imageView.layoutParams = imageParams
return imageView
}
/**
* 加载图片
*/
private fun bindIconData(
imageView: ImageView,
categoryBean: HomeHeaderBean.AskCategoryDataBean
) {
GlideApp.with(context).load(categoryBean.coverUrl)
.centerCrop().into(imageView)
}
/**
* 创建文本
*/
private fun createText(index: Int): TextView {
val textParams = FrameLayout.LayoutParams(textViewWidth, textViewHeight)
val textView = TextView(context)
textView.setTextColor(Color.parseColor("#444444"))
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12f)
textView.gravity = Gravity.CENTER_HORIZONTAL
if (index > 3) {
textParams.topMargin = 2 * (imageViewWidth + dp8) + textViewHeight + dp8
textParams.leftMargin = textViewWidth * (index - 4)
} else {
textParams.topMargin = imageViewWidth + dp8
textParams.leftMargin = textViewWidth * (index)
}
textView.layoutParams = textParams
return textView
}
/**
* 设置文本
*/
private fun bindTextData(textView: TextView, categoryBean: HomeHeaderBean.AskCategoryDataBean) {
textView.text = categoryBean.cateTitle
}
fun onDestory() {
if (null == realTestView) {
return
}
realTestView!!.onDestory()
}
}
\ No newline at end of file
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