Commit f961eb92 by 洪国微

stash

parent f6209eb8
......@@ -4,7 +4,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'trace-point'
//apply plugin: 'trace-point'
kapt {
arguments {
......@@ -175,20 +175,20 @@ dependencies {
kapt 'com.alibaba:arouter-compiler:1.2.2'
}
noTracePoint{
outputModifyFile = false
targetPackages = ['com.cxzapp.yidianling',
'com.yidianling.consultant',
'com.yidianling.course',
'com.yidianling.dynamic',
'com.ydl.home_module',
'com.yidianling.fm',
'com.yidianling.im',
'com.yidianling.avchatkit',
'com.yidianling.uikit',
'com.yidianling.phonecall',
'com.yidianling.tests',
'com.yidianling.user',
'com.yidianling.ydlcommon',
]
}
\ No newline at end of file
//noTracePoint{
// outputModifyFile = false
// targetPackages = ['com.cxzapp.yidianling',
// 'com.yidianling.consultant',
// 'com.yidianling.course',
// 'com.yidianling.dynamic',
// 'com.ydl.home_module',
// 'com.yidianling.fm',
// 'com.yidianling.im',
// 'com.yidianling.avchatkit',
// 'com.yidianling.uikit',
// 'com.yidianling.phonecall',
// 'com.yidianling.tests',
// 'com.yidianling.user',
// 'com.yidianling.ydlcommon',
// ]
//}
\ No newline at end of file
apply from: "config.gradle"
buildscript {
ext.kotlin_version = '1.3.21'
ext {
kotlin_version = '1.3.21'
support_version = '26.1.0'
......@@ -16,7 +15,7 @@ buildscript {
}
repositories {
google()
maven{
maven {
url 'http://nexus.yidianling.com/repository/AndroidReleases/'
}
jcenter()
......@@ -103,7 +102,7 @@ modular {
}
repositories {
maven{
maven {
url 'http://nexus.yidianling.com/repository/AndroidReleases/'
credentials {
username "admin"
......
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
kapt {
arguments {
arg("AROUTER_MODULE_NAME", project.getName())
}
}
android {
compileSdkVersion rootProject.ext.android["compileSdkVersion"]
buildToolsVersion rootProject.ext.android["buildToolsVersion"]
defaultConfig {
minSdkVersion rootProject.ext.android["minSdkVersion"]
targetSdkVersion rootProject.ext.android["targetSdkVersion"]
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
flavorDimensions "versionCode"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
buildConfigField "String", "AGORA_APPID", "3387e9b251f3491e9221a9877e8f7830"
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
buildConfigField "String", "AGORA_APPID", "13b1536698f64905a1e7e5bb978ba821"
}
}
publishNonDefault true
productFlavors {
ydl {}
xlzx {}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// 注意此处的依赖方式:kotlin中使用和java中使用方式有不同
kapt "com.alibaba:arouter-compiler:$arouter_compiler"
implementation project(":ydl-platform")
api "com.alibaba:arouter-api:$arouter_api"
implementation ('com.ydl:ydl-av:1.1.8@aar'){
transitive = true
}
implementation project(":ydl-webview")
}
modular {
packageName "com.ydl.audioim"
// 模块发布需要的参数
publish {
modules {
xlzx {
//发布信息 module/api 通用
groupId = "com.ydl"
artifactId = "m-audioim-module-xlzx"
// 上报的业务模块 aar 包的版本号
version = "0.0.1"
}
ydl{
//发布信息 module/api 通用
groupId = "com.ydl"
artifactId = "m-audioim-module-ydl"
// 上报的业务模块 aar 包的版本号
version = "0.0.1"
}
}
api {
//发布信息 module/api 通用
groupId = "com.ydl"
artifactId = "m-audioim-api"
// version = "0.0.1"
// API 层打包时需要引入的依赖
apiDependencies {
implementation "com.google.code.gson:gson:2.8.2"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.alibaba:arouter-api:1.4.1'
}
}
}
}
\ No newline at end of file
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
package com.ydl.audioim
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.m_audioim.test", appContext.packageName)
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ydl.audioim" >
<uses-permission android:name="android.permission.VIBRATE" />
<application>
<activity
android:name=".AudioHomeActivity"
android:screenOrientation="portrait" />
</application>
</manifest>
package com.ydl.audioim
import com.ydl.audioim.api.IAVRouter
class AVRouterImpl: IAVRouter {
override fun loginAgora(userId: String?) {
YDLavManager.instances.login(userId)
}
}
\ No newline at end of file
package com.ydl.audioim;
/**
* @author jiucheng
* @描述:页面参数传递常量
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/11/7
*/
public interface IntentConstants {
String INTENT_EXPERT_HEAD_URL = "intent_expert_head_url";
String INTENT_EXPERT_NAME = "intent_expert_name";
String INTENT_EXPERT_TIPS = "intent_expert_tips";
String INTENT_ROOM_ID = "intent_room_id";
String INTENT_REMAIN_TIME = "intent_remain_time";
String INTENT_RELATION_ID = "intent_relation_id";
String INTENT_CALL_ID = "INTENT_CALL_ID";
String INTENT_TOKEN = "intent_token";
String INTENT_SIGNAL_TOKEN= "intent_signal_token";
String INTENT_LISTENER_UID= "intent_listener_uid";
String INTENT_TOTAL_DURATION= "intent_total_duration";
String INTENT_LISTEN_ID= "intent_listen_id";
String INTENT_COMMENT_URL= "intent_comment_url";
}
package com.ydl.audioim
import android.content.Context
import com.ydl.ydl_av.messge_service.YDLRTMClient
import com.ydl.ydl_av.messge_service.bean.RTMMesssage
import com.ydl.ydl_av.messge_service.callback.InitListener
import com.ydl.ydl_av.messge_service.callback.LoginCallback
import com.ydl.ydl_av.messge_service.request.LoginParam
import com.ydl.audioim.http.AudioApiRequestUtil
import com.ydl.ydlcommon.utils.log.LogHelper
import com.yidianling.common.tools.LogUtil
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
/**
* @author harvie
* @date 2019/9/27
* 语音通话入口类
*/
class YDLavManager {
companion object{
val instances : YDLavManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED){
YDLavManager()
}
}
private constructor()
fun init(context: Context,appId:String){
YDLRTMClient.instances.init(context,appId,listener)
}
fun login(userId:String?){
//登录实时消息
//获取token
AudioApiRequestUtil.getAgoraToken(userId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
if ("200".equals(it.code)){
YDLRTMClient.instances.login(LoginParam(userId,it.data.token),object : LoginCallback {
override fun onSuccess() {
//登陆成功,发起呼叫
LogUtil.d("[agora]实时消息登录成功")
}
override fun onFailure(msg: String?) {
LogUtil.d("[agora]实时消息登录失败:$msg")
}
})
}else{
LogUtil.e("声网token获取失败uid:"+userId+" error:"+it.msg)
LogHelper.getInstance().writeLogSync("声网token获取失败uid:"+userId+" error:"+it.msg)
}
},{
LogUtil.e("声网token获取异常uid:"+userId+" error:"+it.message)
})
}
/**
* 退出登录
*/
fun logout(){
YDLRTMClient.instances.logout(object : LoginCallback {
override fun onSuccess() {
//退出登陆成功
LogUtil.d("[agora]实时消息退出成功")
}
override fun onFailure(msg: String?) {
LogUtil.d("[agora]实时消息退出失败:$msg")
}
})
}
/**
* 实时消息全局监听
*/
private val listener = object :InitListener{
override fun onTokenExpired() {
LogUtil.e("[agora]onTokenExpired")
}
override fun onMessageReceived(message: RTMMesssage, userId: Int) {
LogUtil.i("[agora]onMessageReceived:${message.text} -->uid:$userId")
}
override fun onConnectionStateChanged(state: Int, reason: Int) {
LogUtil.i("[agora]onConnectionStateChanged:state:${state} -->reason:$reason")
}
}
}
\ No newline at end of file
package com.ydl.audioim.bean;
/**
* 声网token获取结果
*/
public class AgoraTokenResponse {
private String token;
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
}
package com.ydl.audioim.bean
class ConnectBean{
var dialDetail : DialDetail? = null
var listenOrderId : Long? = 0 //订单ID
var callId : String? = null //
var payId : String?=null //支付ID
var payTitle : String? = null //支付标题
var listenOrderPrice : Double? = null //订单金额
var userBaseInfoRespDto : UserBaseInfoRespDto?=null
var coupon :CouponData? = null //优惠信息
}
class DialDetail{
var agoraExpertInfo: ExpertInfoBean? = null
var callConnectType :Int ? = null
var dialReason : String? = null //连接失败原因
var dialStatus : Int? = null //连接状态
var phoneNu : String ?= null //axb号码
}
class UserBaseInfoRespDto{
var availableMoney : Double ? = null
var companyMoney : Double ? = null
var doctorId : Long ? = null
var phone : Long ? = null
var userType : String?=null
}
class CouponData{
var couponMoney:Double? = 0.00
}
package com.ydl.audioim.bean;
/**
* @author jiucheng
* @描述:
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/11/10
*/
public class ExpertInfoBean {
public String expertHeadUrl;//专家头像地址
public String expertName;//专家姓名
public String expertTips;//专家文案
public String token;//token
public String signalToken;//信令
public String listenerUid;//聆听者UID
public int listenerStatus;//1 空闲 2 倾听中(只用这个字段判断老师状态,下面两个字段都不用)
public String listenerIsOpen;//1 开启 2 关闭
public String listenOrderStatus;//1未链接2连接中3连接失败4连接成功
public String channelId;//声网点对点聊天房间id
public String remainingTime;//倾诉剩余时长(时长单位s,eg:剩余2min15s,返回135)
public String totalDuration;//总时长
public String commentUrl;//评价页URL
}
package com.ydl.audioim.contract
import com.ydl.audioim.bean.ConnectBean
import com.ydl.audioim.http.command.ConnectCommand
import com.ydl.audioim.http.command.ConnectFinishCommand
import com.ydl.audioim.http.command.ConnectStartCommand
import com.ydl.audioim.http.command.NoticePushCommand
import com.ydl.ydlcommon.data.http.BaseAPIResponse
import com.ydl.ydlcommon.data.http.BaseResponse
import com.ydl.ydlcommon.mvp.base.BasePresenter
import com.ydl.ydlcommon.mvp.base.IModel
import com.ydl.ydlcommon.mvp.base.IPresenter
import com.ydl.ydlcommon.mvp.base.IView
import io.reactivex.Observable
/**
* @author jiucheng
* @描述:声网倾诉首页约束类
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/10/30
*/
interface IAudioHomeActivityContract {
interface View : IView {
/**
* 显示进度条
*/
fun showProgressView()
/**
* 关闭进度条
*/
fun dismissProgressView()
/**
* 关闭窗口
*/
fun finishActivity()
/**
*切换axb回调
*/
fun switchAXBResponse(axbPhone: String)
/**
* 跳转拨号页面
*/
fun dialPhone()
}
interface Presenter : IPresenter<View> {
/**
* 登录信令
*/
fun loginChatNet(signalingToken: String)
/**
* 获取axb电话
*/
fun getAXBPhone(cmd: ConnectCommand)
/**
* 通话开始(更新专家状态)
* @param param 请求参数
*/
fun connectStart(param: ConnectStartCommand)
/**
* 通话结束(更新专家状态)
* @param param 请求参数
*/
fun connectFinish(param: ConnectFinishCommand)
/**
* 通知服务端发送推送
*/
fun noticeServerPush(cmd: NoticePushCommand)
}
interface Model : IModel {
/**
* 获取axb电话
*/
fun getAXBPhone(cmd: ConnectCommand): Observable<BaseAPIResponse<ConnectBean>>
/**
* 通话开始回调(更新专家状态)
*/
fun connectStart(param: ConnectStartCommand): Observable<BaseAPIResponse<Any>>
/**
* 通话结束(更新专家状态)
*/
fun connectFinish(param: ConnectFinishCommand): Observable<BaseAPIResponse<Any>>
/**
* 通知服务端发送推送
*/
fun noticeServerPush(param: NoticePushCommand): Observable<BaseResponse<Any>>
}
}
\ No newline at end of file
package com.ydl.audioim.http
import com.google.gson.Gson
import com.ydl.audioim.bean.AgoraTokenResponse
import com.ydl.audioim.bean.ConnectBean
import com.ydl.audioim.http.command.ConnectCommand
import com.ydl.audioim.http.command.NoticePushCommand
import com.ydl.audioim.http.command.ConnectFinishCommand
import com.ydl.audioim.http.command.ConnectStartCommand
import com.ydl.ydlcommon.data.http.BaseAPIResponse
import com.ydl.ydlcommon.data.http.BaseResponse
import com.ydl.ydlcommon.data.http.RxUtils
import com.ydl.ydlnet.YDLHttpUtils
import io.reactivex.Observable
import okhttp3.MediaType
import okhttp3.RequestBody
/**
* @author jiucheng
* @描述:声网业务接口请求
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/11/9
*/
class AudioApiRequestUtil {
companion object {
/**
* 倾诉
*/
fun connectListen(cmd: ConnectCommand): Observable<BaseAPIResponse<ConnectBean>> {
return RxUtils.mapObservable(cmd)
.flatMap {
it->
YDLHttpUtils.obtainApi(AudioNetAPi::class.java).connectListen(it)
}
}
/**
* 通话开始回调
*
* @param param
* @return
*/
fun connectStart(param: ConnectStartCommand): Observable<BaseAPIResponse<Any>> {
// val list = YdlRetrofitUtils.getPostList(param)
var str = Gson().toJson(param)
val body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str) as RequestBody
return YDLHttpUtils.obtainApi(AudioNetAPi::class.java).connectStart(body)
}
/**
* 通话结束回调
*
* @param param
* @return
*/
fun connectFinish(param: ConnectFinishCommand): Observable<BaseAPIResponse<Any>> {
// val list = YdlRetrofitUtils.getPostList(param)
var str = Gson().toJson(param)
val body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str) as RequestBody
return YDLHttpUtils.obtainApi(AudioNetAPi::class.java).connectFinish(body)
}
/**
* 通知服务端发送推送
*/
fun noticeServerPush(param: NoticePushCommand): Observable<BaseResponse<Any>> {
var str = Gson().toJson(param)
val body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str) as RequestBody
return YDLHttpUtils.obtainApi(AudioNetAPi::class.java).noticeServerPush(body)
}
/**
* 获取声网登录token
*/
fun getAgoraToken(uid:String?): Observable<BaseAPIResponse<AgoraTokenResponse>>{
return YDLHttpUtils.obtainApi(AudioNetAPi::class.java).getAgoraToken(uid)
}
}
}
\ No newline at end of file
package com.ydl.audioim.http
import com.ydl.audioim.bean.AgoraTokenResponse
import com.ydl.audioim.bean.ConnectBean
import com.ydl.ydlcommon.base.config.YDL_DOMAIN
import com.ydl.ydlcommon.base.config.YDL_DOMAIN_JAVA
import com.ydl.ydlcommon.data.http.BaseAPIResponse
import com.ydl.ydlcommon.data.http.BaseResponse
import io.reactivex.Observable
import okhttp3.RequestBody
import retrofit2.http.*
/**
* @author jiucheng
* @描述:声网业务接口api
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/11/9
*/
interface AudioNetAPi {
/**
* 通话开始回调
*/
@Headers( YDL_DOMAIN+ YDL_DOMAIN_JAVA,"Content-Type:application/json")
@POST("auth/listen-order/callback/agora/start")
fun connectStart(@Body body:RequestBody): Observable<BaseAPIResponse<Any>>
/**
* 通话结束回调
*/
@Headers( YDL_DOMAIN + YDL_DOMAIN_JAVA,"Content-Type:application/json")
@POST("auth/listen-order/callback/agora/finish")
fun connectFinish(@Body body:RequestBody): Observable<BaseAPIResponse<Any>>
/**
* 链接 :获取axb手机号
*/
@Headers( YDL_DOMAIN+ YDL_DOMAIN_JAVA,"Content-Type:application/json")
@GET("auth/listen/dial")
fun connectListen(@QueryMap params: Map<String, String>): Observable<BaseAPIResponse<ConnectBean>>
/**
*通知服务端发送推送
*/
@POST("api/push/notify/doctor")
fun noticeServerPush(@Body body: RequestBody): Observable<BaseResponse<Any>>
/**
* 获取声网登录token
*/
@Headers( YDL_DOMAIN + YDL_DOMAIN_JAVA,"Content-Type:application/json")
@GET("im/getAgoraToken")
fun getAgoraToken(@Query("uid") uid: String?): Observable<BaseAPIResponse<AgoraTokenResponse>>
}
\ No newline at end of file
package com.ydl.audioim.http.command
import com.ydl.ydlcommon.data.http.BaseCommand
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/03/08
*/
class ConnectCommand : BaseCommand {
var id: String = "0" //倾诉id
var type: String = "1" //1 走AxB 2双呼 3声网
var isCheckStatus = "2"//1 检测专家状态 2 跳过检测专家状态
constructor() : super()
constructor(id: String, type: String) : super() {
this.id = id
this.type = type
}
}
package com.ydl.audioim.http.command
import com.ydl.ydlcommon.data.http.BaseCommand
/**
* @author jiucheng
* @描述:更新专家状态请求参数
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/11/9
*/
data class ConnectFinishCommand(
var listenerUid:String,//专家uid
// @JvmField
var relationId: String,//订单ID
var connectStatus:String,// 0开始 1 结束
// @JvmField
var callLongTime: Int,//本次通话时长
// @JvmField
var session: String,//调用connect接口时候,会返回这个值,直接给我好了
var calleePhone:String = "${0}",
var callerPhone:String = "${0}",
var callStartTime:String,//通话开始时间
var callEndTime:String,//通话结束时间
var status:Int //连接成功传递3
) : BaseCommand()
\ No newline at end of file
package com.ydl.audioim.http.command
import com.ydl.ydlcommon.data.http.BaseCommand
/**
* @author jiucheng
* @描述:通话开始请求参数
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/11/9
*/
data class ConnectStartCommand(
var listenerUid:String,//专家uid
// @JvmField
var relationId: String,//订单ID
var callId:String,//会话session 调用connect接口时候,会返回这个值,直接给我好了
var callTime:String,//通话开始时间
var callType:String,//声网默认3
var subId:String,
var telA:String,
var telB:String,
var telX:String
) : BaseCommand()
\ No newline at end of file
package com.ydl.audioim.http.command;
import com.ydl.ydlcommon.data.http.BaseCommand;
/**
* @author jiucheng
* @描述:
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/11/17
*/
public class NoticePushCommand extends BaseCommand {
public String data;//AudioMessageBean的字符串
public String pushId;//专家uid
public String status;//CALL 呼叫 CALL_OFF 取消呼叫
public String title = "您有一条倾诉消息";
public String sound = "专家响铃3.mp3";//用于ios设备接到通知响铃
}
package com.ydl.audioim.model
import com.ydl.audioim.bean.ConnectBean
import com.ydl.audioim.contract.IAudioHomeActivityContract
import com.ydl.audioim.http.AudioApiRequestUtil
import com.ydl.audioim.http.command.ConnectCommand
import com.ydl.audioim.http.command.NoticePushCommand
import com.ydl.audioim.http.command.ConnectFinishCommand
import com.ydl.audioim.http.command.ConnectStartCommand
import com.ydl.ydlcommon.data.http.BaseAPIResponse
import com.ydl.ydlcommon.data.http.BaseResponse
import io.reactivex.Observable
/**
* @author jiucheng
* @描述:model实现类
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/10/30
*/
class AudioHomeModelImpl : IAudioHomeActivityContract.Model {
override fun connectStart(param: ConnectStartCommand): Observable<BaseAPIResponse<Any>> {
return AudioApiRequestUtil.connectStart(param)
}
override fun connectFinish(param: ConnectFinishCommand): Observable<BaseAPIResponse<Any>> {
return AudioApiRequestUtil.connectFinish(param)
}
override fun noticeServerPush(param: NoticePushCommand): Observable<BaseResponse<Any>> {
return AudioApiRequestUtil.noticeServerPush(param)
}
override fun getAXBPhone(cmd: ConnectCommand): Observable<BaseAPIResponse<ConnectBean>> {
return AudioApiRequestUtil.connectListen(cmd)
}
}
\ No newline at end of file
package com.ydl.audioim.player
import android.content.Context
import android.media.AudioAttributes
import android.media.AudioManager
import android.media.MediaPlayer
import android.os.Build
/**
* @author jiucheng
* @描述:音频播放
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/11/9
*/
class AudioPlayer {
private var mPlayer: MediaPlayer? = null
private var mContext: Context? = null
private var audioManager: AudioManager? = null
constructor(mContext: Context?) {
this.mContext = mContext
mPlayer = MediaPlayer()
mPlayer?.setAudioStreamType(AudioManager.STREAM_VOICE_CALL)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
var attributes = AudioAttributes.Builder()
.setLegacyStreamType(AudioManager.STREAM_VOICE_CALL)
.build()
mPlayer?.setAudioAttributes(attributes)
} else {
mPlayer?.setAudioStreamType(AudioManager.STREAM_VOICE_CALL)
}
audioManager = mContext!!.getSystemService(Context.AUDIO_SERVICE) as AudioManager?
audioManager?.setStreamVolume(AudioManager.STREAM_VOICE_CALL,
audioManager!!.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL) / 2,
AudioManager.STREAM_VOICE_CALL)
//默认听筒模式
audioManager?.isSpeakerphoneOn = false
}
/**
* 设置音频文件
* @param id 文件id
*/
fun setDataSource(id: Int) {
val file = mContext?.resources?.openRawResourceFd(id)
if (null == file){
return
}
if (mPlayer != null) {
mPlayer?.reset()
mPlayer?.setDataSource(file.fileDescriptor, file.startOffset, file.length)
}
file.close()
}
/**
* 设置两个音乐文件,第一个播放一次,第二个循环播放
*/
fun setTwoDataAndStart(startMusicId: Int, loopMusicId: Int) {
requestFocus()
setDataSource(startMusicId)
mPlayer?.setOnPreparedListener {
it.start()
}
mPlayer?.setOnCompletionListener {
it.pause()
startNext(loopMusicId)
}
mPlayer?.prepare()
}
/**
* 播放下一首
*/
private fun startNext(loopMusicId: Int) {
setDataSource(loopMusicId)
start(true, false)
}
/**
* 播放
* @param isLooping 是否重复播放
* @param isSetOnCompletionListener 是否设置过播放完成监听
*/
fun start(isLooping: Boolean, isSetOnCompletionListener: Boolean) {
requestFocus()
mPlayer?.isLooping = isLooping
mPlayer?.setOnPreparedListener {
it.start()
}
if (!isLooping && !isSetOnCompletionListener) {
mPlayer?.setOnCompletionListener {
it.pause()
}
}
mPlayer?.prepare()
}
/**
* 设置播放完成回调
*/
fun setCompletionListener(listener: MediaPlayer.OnCompletionListener) {
if (listener == null) {
return
}
mPlayer?.setOnCompletionListener(listener)
}
/**
* 切换扬声器、听筒播放方式
* @param isSpeakerphoneOn true 扬声器 false 听筒模式
*/
fun switchPlayType(isSpeakerphoneOn: Boolean) {
audioManager?.isSpeakerphoneOn = isSpeakerphoneOn
audioManager?.mode = AudioManager.MODE_IN_CALL
}
/**
* 暂停
*/
fun pause() {
if (mPlayer != null) {
mPlayer?.pause()
}
}
/**
* 停止
*/
fun stop() {
if (mPlayer != null) {
mPlayer?.stop()
}
}
/**
* 获取焦点
*
*/
fun requestFocus() {
try {
val result = audioManager?.requestAudioFocus(afChangeListener,
// Use the music stream.
AudioManager.STREAM_VOICE_CALL,
// Request permanent focus.
AudioManager.AUDIOFOCUS_GAIN)
} catch (e: Exception) {
}
}
fun clear() {
if (audioManager != null) {
audioManager?.abandonAudioFocus(afChangeListener)
}
if (mPlayer != null) {
mPlayer?.stop()
mPlayer?.release()
mPlayer = null
}
}
var afChangeListener = AudioManager.OnAudioFocusChangeListener {
if (it == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) {
// Pause playback
// pause()
} else if (it == AudioManager.AUDIOFOCUS_GAIN) {
// Resume playback
} else if (it == AudioManager.AUDIOFOCUS_LOSS) {
// mAm.unregisterMediaButtonEventReceiver(RemoteControlReceiver);
// audioManager!!.abandonAudioFocus(afChangeListener)
// // Stop playback
// stop()
}
}
}
package com.ydl.audioim.presenter
import android.app.Activity
import com.ydl.audioim.BuildConfig
import com.ydl.ydl_av.chat.config.YDLChatParam
import com.ydl.audioim.R
import com.ydl.audioim.contract.IAudioHomeActivityContract
import com.ydl.audioim.http.command.ConnectCommand
import com.ydl.audioim.http.command.ConnectFinishCommand
import com.ydl.audioim.http.command.ConnectStartCommand
import com.ydl.audioim.http.command.NoticePushCommand
import com.ydl.audioim.model.AudioHomeModelImpl
import com.ydl.ydlcommon.mvp.base.BasePresenter
import com.ydl.ydlcommon.router.YdlCommonRouterManager
import com.ydl.ydlcommon.utils.remind.ToastHelper
import com.yidianling.common.tools.LogUtil
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
/**
* @author jiucheng
* @描述:
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/10/30
*/
class AudioHomePresenterImpl : BasePresenter<IAudioHomeActivityContract.View, IAudioHomeActivityContract.Model>(), IAudioHomeActivityContract.Presenter {
override fun connectStart(param: ConnectStartCommand) {
mModel.connectStart(param)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnSubscribe {
}
.doAfterTerminate {
// view.dismissProgressView()
}
.subscribe({
// if (isSwitchAxb) {
// //切换axb:跳到拨号界面
// view.dialPhone()
// }
}, { e ->
LogUtil.e(e.message)
})
}
override fun connectFinish(param: ConnectFinishCommand) {
mModel.connectFinish(param)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnSubscribe {
//通知服务端专家已经接通时,此时用户已在界面通话中,不需要弹进度条
mView.showProgressView()
}
.doAfterTerminate {
mView.dismissProgressView()
}
.subscribe({
// if (isSwitchAxb) {
// //切换axb:跳到拨号界面
// view.dialPhone()
// }
//挂断逻辑:不管接口调用成功与否,都关闭界面
mView.finishActivity()
}, { e ->
LogUtil.e(e.message)
//挂断逻辑:不管接口调用成功与否,都关闭界面
mView.finishActivity()
})
}
/**
* 登录声网
*/
override fun loginChatNet(signalingToken: String) {
mView.showProgressView()
// appId:应用id
// account:uid
// token :由 App ID 和 App Certificate 生成的 SignalingToken (如果不使用token可以设为字符串 _no_need_token)
// uid:固定填 0
// deviceID:暂时无用,设置为空
// retry_time_in_s:登录重试时间,默认为 30 秒
// retry_count:登录重试次数,默认为 3 次
val ydlChtat = YDLChatParam()
ydlChtat.appId = BuildConfig.AGORA_APPID
ydlChtat.account = YdlCommonRouterManager.getYdlCommonRoute().getUid().toString()
ydlChtat.token = signalingToken
ydlChtat.uid = 0
ydlChtat.deviceID = ""
ydlChtat.retry_time_in_s = 30
ydlChtat.retry_count = 3
// YDLChartManager.instance!!.getChatApi().login(ydlChtat)
}
/**
* 获取axb电话
*/
override fun getAXBPhone(cmd: ConnectCommand) {
mModel.getAXBPhone(cmd)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnSubscribe { mView.showProgressView() }
.doAfterTerminate { mView.dismissProgressView() }
.subscribe({
if ("200".equals(it.code)){
if(0==it.data?.dialDetail?.dialStatus?:-1){
//连接成功
if(it.data?.dialDetail?.callConnectType?:-1==1){
//axb
mView.switchAXBResponse(it.data?.dialDetail?.phoneNu?:"")
}else{
ToastHelper.show(it.data?.dialDetail?.dialReason?:"连接失败")
}
}else{
ToastHelper.show(it.data?.dialDetail?.dialReason?:"连接失败")
}
}else{
ToastHelper.show(it.data?.dialDetail?.dialReason?:"连接失败")
}
}, { e ->
LogUtil.d(e.message)
})
}
/**
* 通知服务端发送推送
*/
override fun noticeServerPush(param: NoticePushCommand) {
mModel.noticeServerPush(param)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
if (it.code == 200) {
//TODO
} else {
LogUtil.e(it.msg)
}
}, { e ->
LogUtil.e(e.message)
})
}
override fun createModel(): IAudioHomeActivityContract.Model {
return AudioHomeModelImpl()
}
}
\ No newline at end of file
# 声网module
\ No newline at end of file
package com.ydl.audioim.utils;
/**
* @author jiucheng
* @描述:
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/11/7
*/
public class DateUtils {
/**
* 将时间(单位:s )转化成00:00格式
*
* @param timeTemp
* @return
*/
public static String formatTime(Object timeTemp) {
int timeParam = 0;
if (timeTemp instanceof Integer) {
timeParam = (Integer) timeTemp;
}
if (timeTemp instanceof String) {
timeParam = Integer.valueOf((String) timeTemp);
}
int second = timeParam % 60;
int minuteTemp = timeParam / 60;
if (minuteTemp > 0) {
int minute = minuteTemp % 60;
int hour = minuteTemp / 60;
if (hour > 0) {
return (hour >= 10 ? (hour + "") : ("0" + hour)) + ":" + (minute >= 10 ? (minute + "") : ("0" + minute))
+ ":" + (second >= 10 ? (second + "") : ("0" + second));
} else {
return (minute >= 10 ? (minute + "") : ("0" + minute)) + ":"
+ (second >= 10 ? (second + "") : ("0" + second));
}
} else {
return "00:" + (second >= 10 ? (second + "") : ("0" + second));
}
}
}
package com.ydl.audioim.widget
import android.app.Activity
import android.app.Dialog
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import com.ydl.audioim.R
import kotlinx.android.synthetic.main.dialog_axb_confirm.*
/**
* @author jiucheng
* @描述:Axb呼叫确认弹窗
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/12/27
*/
class AxbConfirmDialog : Dialog {
private var activity: Activity? = null
private var listener: OnClickEnsureListener? = null
constructor(activity: Activity?, listener: OnClickEnsureListener?) : super(activity) {
this.activity = activity
this.listener = listener
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.dialog_axb_confirm)
setCanceledOnTouchOutside(false)
window.setBackgroundDrawable(ColorDrawable())
ic_close.setOnClickListener {
dismiss()
}
rl_ensure.setOnClickListener {
if (listener != null) {
listener!!.onClickEnsure()
}
dismiss()
}
}
interface OnClickEnsureListener {
fun onClickEnsure()
}
override fun show() {
if (null == activity || activity!!.isFinishing) {
return
}
super.show()
}
}
\ No newline at end of file
package com.ydl.audioim.api
/**
* Created by hgw on 2018/5/3.
*/
interface IAVRouter {
/**
* 登录agora
*/
fun loginAgora(userId:String?)
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="63dp" />
<solid android:color="@color/color_30FFFFFF" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="20dp" />
<solid android:color="@color/color_32D296" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="4dp" />
<solid android:color="@color/color_20FFFFFF" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_80353535">
<TextView
android:id="@+id/tv_change_route"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="25dp"
android:layout_marginRight="10dp"
android:background="?android:attr/selectableItemBackground"
android:drawableRight="@drawable/audio_home_img_choose_arrow_unuse"
android:drawablePadding="6dp"
android:padding="5dp"
android:text="切换至传统电话"
android:textColor="@color/color_50FFFFFF"
android:textSize="13sp"
android:visibility="visible" />
<RelativeLayout
android:id="@+id/rl_head"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="74dp">
<com.ydl.ydlcommon.view.WaveView
android:id="@+id/wave_view"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_centerInParent="true" />
<ImageView
android:layout_width="126dp"
android:layout_height="126dp"
android:layout_centerInParent="true"
android:background="@drawable/audio_home_head_background" />
<ImageView
android:id="@+id/iv_head"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_centerInParent="true"
android:scaleType="centerCrop"
android:src="@drawable/head_place_hold_pic" />
</RelativeLayout>
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/rl_head"
android:layout_centerHorizontal="true"
android:layout_marginTop="-20dp"
android:textColor="@color/white"
android:textSize="26sp"
tools:text="留意" />
<TextView
android:id="@+id/tv_tips"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_name"
android:layout_centerHorizontal="true"
android:layout_marginLeft="25dp"
android:layout_marginTop="6dp"
android:layout_marginRight="25dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="2"
android:textColor="@color/white"
android:textSize="15sp"
tools:text="你存在的本身就是值得被爱的你存在的本身就是值得被爱的" />
<!-- 倾诉剩余时间-->
<RelativeLayout
android:id="@+id/rl_remain_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/rl_hang_up"
android:layout_marginBottom="20dp"
android:visibility="gone">
<TextView
android:id="@+id/tv_notes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="您的倾诉时间还有"
android:textColor="@color/color_30FFFFFF"
android:textSize="12sp" />
<TextView
android:id="@+id/tv_remain_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_notes"
android:layout_centerHorizontal="true"
android:text="23:23"
android:textColor="@color/white"
android:textSize="20sp" />
</RelativeLayout>
<TextView
android:id="@+id/tv_change_doctor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/rl_hang_up"
android:layout_centerHorizontal="true"
android:layout_marginBottom="48dp"
android:gravity="center"
android:text="聆听者长时间未接听,\n您可以点击右上角切换线路,或者挂断换一位"
android:textColor="@color/white"
android:visibility="gone" />
<TextView
android:id="@+id/tv_waiting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/rl_hang_up"
android:layout_centerHorizontal="true"
android:layout_marginBottom="50dp"
android:text="正在等待聆听者接受邀请…"
android:textColor="@color/color_70FFFFFF"
android:textSize="12sp"
android:visibility="visible" />
<!--挂断按钮-->
<RelativeLayout
android:id="@+id/rl_hang_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="72dp"
android:layout_marginBottom="18dp">
<com.ydl.ydlcommon.view.ProgressView
android:id="@+id/progress_view"
android:layout_width="70dp"
android:layout_height="70dp"
app:progressWidth="2dp" />
<ImageView
android:id="@+id/iv_hang_up"
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="1dp"
android:src="@drawable/audio_home_img_hang_up_unuse"
android:visibility="visible" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/iv_hang_up"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:text="挂断"
android:textColor="@color/white"
android:textSize="12sp" />
</RelativeLayout>
<!-- 免提按钮-->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="72dp"
android:layout_marginBottom="18dp">
<ImageView
android:id="@+id/iv_hands_free"
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_marginTop="1dp"
android:src="@drawable/audio_home_img_hands_free_unuse" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/iv_hands_free"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:text="免提"
android:textColor="@color/white"
android:textSize="12sp" />
</RelativeLayout>
<!--自定义弹窗-->
<TextView
android:id="@+id/tv_toast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_tips"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp"
android:background="@drawable/audio_home_toast_view_background"
android:elevation="6dp"
android:paddingLeft="11dp"
android:paddingTop="4dp"
android:paddingRight="11dp"
android:paddingBottom="4dp"
android:textColor="@color/white"
android:visibility="gone"
tools:text="已接通" />
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
app:cardCornerRadius="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="@+id/ic_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="7dp"
android:layout_marginRight="10dp"
android:padding="5dp"
android:src="@drawable/ic_close_24dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:src="@drawable/audio_home_privacy_ico" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:text="号码隐私保护"
android:textColor="@color/color_333333"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:text="您的真实号码全程保密,请安心呼叫"
android:textColor="@color/color_333333"
android:visibility="visible"
android:textSize="13sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:layout_marginTop="15dp"
android:text="呼出号码与注册号码需为同一手机号"
android:textColor="@color/color_999999"
android:textSize="13sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="否则无法接通"
android:textColor="@color/color_999999"
android:textSize="13sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:gravity="bottom"
android:text="壹点灵全程保护您的隐私"
android:textColor="@color/color_999999"
android:textSize="10sp" />
<RelativeLayout
android:id="@+id/rl_ensure"
android:layout_width="210dp"
android:layout_height="40dp"
android:layout_marginTop="11dp"
android:layout_marginBottom="20dp"
android:background="@drawable/audio_home_privacy_background">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal"
android:drawableLeft="@drawable/audio_home_ic_phone"
android:gravity="center_horizontal"
android:text="呼叫"
android:textColor="@color/white"
android:textSize="17sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="color_40353535">#66353535</color>
<color name="color_80353535">#CC353535</color>
<color name="color_50ffffff">#B3ffffff</color>
<color name="color_30FFFFFF">#4DFFFFFF</color>
<color name="color_70FFFFFF">#B3FFFFFF</color>
</resources>
\ No newline at end of file
<resources>
<string name="app_name">av</string>
<string name="need_storage_permission_hint">App正常工作需要内部存储使用权限,请开启</string>
</resources>
package com.ydl.audioim
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
kapt {
arguments {
arg("AROUTER_MODULE_NAME", project.getName())
}
}
android {
compileSdkVersion rootProject.ext.android["compileSdkVersion"]
buildToolsVersion rootProject.ext.android["buildToolsVersion"]
defaultConfig {
minSdkVersion rootProject.ext.android["minSdkVersion"]
targetSdkVersion rootProject.ext.android["targetSdkVersion"]
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
flavorDimensions "versionCode"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
publishNonDefault true
productFlavors {
ydl {}
xlzx {}
}
sourceSets {
main {
res.srcDirs = [
'src/main/res/layouts/confidehome',
'src/main/res/layouts',
'src/main/res'
]
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.daimajia.androidanimations:library:2.3@aar'
api 'fr.tvbarthel.blurdialogfragment:lib:2.1.5'
api "com.alibaba:arouter-api:$arouter_api"
// 注意此处的依赖方式:kotlin中使用和java中使用方式有不同
kapt "com.alibaba:arouter-compiler:$arouter_compiler"
implementation project(":ydl-platform")
implementation 'com.alibaba:fastjson:1.2.38'
}
modular {
packageName "com.ydl.confide"
// 模块发布需要的参数
publish {
modules {
xlzx {
//发布信息 module/api 通用
groupId = "com.ydl"
artifactId = "m-confide-module-xlzx"
// 上报的业务模块 aar 包的版本号
version = "0.0.1"
}
ydl{
//发布信息 module/api 通用
groupId = "com.ydl"
artifactId = "m-confide-module-ydl"
// 上报的业务模块 aar 包的版本号
version = "0.0.1"
}
}
api {
//发布信息 module/api 通用
groupId = "com.ydl"
artifactId = "m-confide-api"
//version = "0.0.1"
// API 层打包时需要引入的依赖
apiDependencies {
implementation "com.google.code.gson:gson:2.8.2"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.alibaba:arouter-api:1.4.1'
}
}
}
}
\ No newline at end of file
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
package com.ydl.confide
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.m_confide.test", appContext.packageName)
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ydl.confide" >
<application>
<activity android:name=".PhoneCallActivity"
android:screenOrientation="portrait"/>
<activity android:name=".home.ConfideHomeActivity"
android:screenOrientation="portrait">
</activity>
<activity android:name="com.yidianling.phonecall.order.DownOrderActivity"
android:screenOrientation="portrait"/>
</application>
</manifest>
package com.ydl.confide.home.adapter
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import com.ydl.confide.R
import com.ydl.confide.home.bean.ConfideHomeDataBean
import com.ydl.confide.home.config.IConfideHomeConfig
import com.ydl.confide.home.contract.IConfideHomeContract
import com.ydl.confide.home.event.IConfideHomeEvent
import com.ydl.confide.home.widget.*
/**
* @author yuanwai
* @描述:倾诉首页列表适配器(因为section框架有问题,故先改为传统方式编写)
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/12/14
*/
class ConfideHomeAdapter(private val mContext: Context,
private var confideHomeEvent: IConfideHomeEvent,
private var confideHomeView: IConfideHomeContract.View) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private var mListData: List<ConfideHomeDataBean>? = null
private var mFilterViewHolder: FilterViewHolder? = null
fun getFilterViewHolder(): FilterViewHolder? {
return mFilterViewHolder
}
init {
if (null == mListData) {
mListData = ArrayList()
}
}
override fun getItemViewType(position: Int): Int {
if (null == mListData || mListData!!.isEmpty() || position >= mListData!!.size) {
//当没数据 返回一个不存在的类型
return 0
}
return mListData!![position].type!!
}
fun updataItems(list: List<ConfideHomeDataBean>) {
if (null == mListData || mListData!!.isEmpty()) {
mListData = ArrayList()
} else {
(mListData as ArrayList).clear()
}
(mListData as ArrayList).addAll(list)
}
fun addItems(list: List<ConfideHomeDataBean>) {
if (null == mListData || mListData!!.isEmpty()) {
mListData = ArrayList()
}
(mListData as ArrayList).addAll(list)
}
fun getList(): List<ConfideHomeDataBean>? {
return mListData
}
fun getCount(): Int {
if (null == mListData || mListData!!.isEmpty()) {
return 0
}
return mListData!!.size
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
when (viewType) {
//banner
IConfideHomeConfig.TYPE_BANNER -> {
return BannerViewHolder(ConfideHomeBannerView(parent.context, confideHomeEvent))
}
//最近倾诉
IConfideHomeConfig.TYPE_RECENTLY_CONFIDED -> {
return ConsultViewHolder(ConfideHomeRecentView(parent.context, confideHomeEvent))
}
//分类
IConfideHomeConfig.TYPE_CATEGORY -> {
return CategoryViewHolder(ConfideHomeCategoryView(parent.context, confideHomeEvent, confideHomeView))
}
//筛选模块
IConfideHomeConfig.TYPE_RECOMMEND_FILTER -> {
return FilterViewHolder(ConfideHomeFilterView(parent.context, confideHomeView))
}
//为你推荐
IConfideHomeConfig.TYPE_RECOMMEND -> {
return RecommendViewHolder(ConfideHomeRecommendView(confideHomeView, parent.context, confideHomeEvent))
}
//听声寻人
IConfideHomeConfig.TYPE_SOUND -> {
return ConfideHomeListenAndFoundViewHolder(ConfideHomeListenAndFoundView(parent.context, confideHomeEvent))
}
else -> {
return EmptyViewHolder(View.inflate(parent.context, R.layout.confidehome_empty, null))
}
}
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) =
if (holder is BannerViewHolder && null != holder.bannerView) {
//banner
holder.bannerView!!.initData(mListData!![position])
} else if (holder is CategoryViewHolder && null != holder.categoryView) {
//分类
holder.categoryView!!.initData(mListData!![position])
} else if (holder is FilterViewHolder && null != holder.filterView) {
mFilterViewHolder = holder
//筛选模块
holder.filterView.initData(mListData!![position])
} else if (holder is ConfideHomeListenAndFoundViewHolder) {
//听声寻人
holder.confideHomeListenAndFoundView!!.initData(mListData!![position])
} else if (holder is ConsultViewHolder && null != holder.consultView) {
//最近倾诉
holder.consultView!!.initData(mListData!![position])
} else if (holder is RecommendViewHolder && null != mListData!![position] && null != mListData!![position].body && !mListData!![position].body!!.isEmpty()) {
//为你推荐
holder.confideHomeRecommendView.initData(mListData!![position].body!![0], position, mListData!![position].recommendId)
} else if (holder is EmptyViewHolder) {
} else {
}
override fun getItemCount(): Int {
return mListData!!.size
}
/**
* banner viewHolder
*/
inner class BannerViewHolder(itemView: ConfideHomeBannerView) : RecyclerView.ViewHolder(itemView) {
var bannerView: ConfideHomeBannerView? = null
init {
bannerView = itemView
}
}
/**
* 分类测评 viewHolder
*/
inner class CategoryViewHolder(itemView: ConfideHomeCategoryView) : RecyclerView.ViewHolder(itemView) {
var categoryView: ConfideHomeCategoryView? = null
init {
categoryView = itemView
}
}
/**
* 筛选模块 viewHolder
*/
inner class FilterViewHolder(var filterView: ConfideHomeFilterView) : RecyclerView.ViewHolder(filterView)
/**
* 听声寻人 viewHolder
*/
inner class ConfideHomeListenAndFoundViewHolder(var confideHomeListenAndFoundView: ConfideHomeListenAndFoundView) : RecyclerView.ViewHolder(confideHomeListenAndFoundView)
/**
* 最近倾诉 viewHolder
*/
inner class ConsultViewHolder(var consultView: ConfideHomeRecentView) : RecyclerView.ViewHolder(consultView)
/**
* 为你推荐 viewHolder
*/
inner class RecommendViewHolder(var confideHomeRecommendView: ConfideHomeRecommendView) : RecyclerView.ViewHolder(confideHomeRecommendView)
/**
* 空ViewHolder
*/
inner class EmptyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
var view: View? = null
init {
view = itemView
}
}
}
\ No newline at end of file
package com.ydl.confide.home.bean
/**
* @author yuanwai
* @描述:倾诉首页--已选择的筛选参数bean(用于拼装为你推荐筛选请求参数)
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/9/22
*/
data class ConfideHomeAllFiltersBean(
var page : Int,
//选择的综合排序Id
var selectSort : ConfideHomeFiterItemBean?,
//选择的性别id
var selectSex : ConfideHomeFiterItemBean?,
//年龄筛选数据集
val selectAgeData : ArrayList<ConfideHomeFiterItemBean>?,
//擅长方向筛选数据集
val selectGoodData : ArrayList<ConfideHomeFiterItemBean>?,
//当前列表已存在专家uid列表
var notInUid : ArrayList<Int> = ArrayList()
)
\ No newline at end of file
package com.ydl.confide.home.bean
/**
* @author yuanwai
* @描述:倾诉首页数据--body bean
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/8/10
*/
data class ConfideHomeBodyBean(
/**
* 公共参数
*/
val linkUrl : String?,
//倾诉Id
val confidedId : String?,
//专家Id(专家编号)
val doctorId : String?,
//专家的uid
val uid : Int?,
//咨询师姓名
val confidedName : String?,
//咨询师性别 1.男 2.女
val confideSex : Int = 1,
//对你留言
val confideContent : String?,
//咨询师头像地址
val confidedIcon : String?,
//是否在线 //1在线 2离线 3通话中 4继续倾诉
val confideLine : Int?,
//已聆听文案
val confideHearNum : String?,
//历史倾听记录
val confideHistory : String?,
//是否为播放状态
var confideIsPlay : Boolean=false,
//音频播放地址
val confideVoice:String?,
//副标题(底部更多文案)
val subTitle : String?,
//咨询师标题
val confidedTitle:String?,
//副标题点击事件
val subLinkUrl : String?,
//咨询师背景图片
val confideBgUrl : String?,
//价格
val confideFee : String?,
//红包金额
val couponMoney : String?,
//新用户优惠文案
val couponText : String?,
/**
* banner数据
*/
//banner id
val bannerId : String?,
//banner 图片地址
val bannerImageUrl : String?,
//banner标题(用于数据埋点)
val bannerTitle : String?,
//跳转地址
val bannerLinkUrl : String?,
/**
* 最近倾诉数据说明(查看公共参数说明)
*/
//...
/**
* 分类参数
*/
//分类Id
val categoryId : String?,
//分类名称
val categoryName : String?,
//分类类型(1.倾诉指南,2.专业师资)
val categoryType : Int?,
//分类图片地址
val categoryIcon : String?,
//分类内容
val categoryContent : String?,
/**
* 为你推荐筛选模块数据
*/
//筛选标题
val filterName : String?,
//筛选类型(1.综合排序 2.性别年龄 3.擅长方向)
val filterType : Int?,
//筛选数据集
val group : ArrayList<ConfideHomeBodyGroupItemBean>?,
// //性别筛选标题
// val sexTitle : String?,
// //性别筛选数据集
// val sexData : ArrayList<ConfideHomeFiterItemBean>?,
// //年龄筛选标题
// val ageTitle : String?,
// //年龄筛选数据集
// val ageData : ArrayList<ConfideHomeFiterItemBean>?,
// //擅长方向标题
// val goodTitle : String?,
// //擅长方向筛选数据集
// val goodData : ArrayList<ConfideHomeFiterItemBean>?,
/**
* 为你推荐数据说明
*/
val confidedTag : List<String>?,
/**
* 听声寻人数据说明(请查看公共参数说明)
*/
//...
/**
* 最佳倾诉榜单数据说明
*/
//倾诉统计文案(8513人)
val confideNum : String?,
//接通率
val confideConnection : String?,
//
var bodyData : List<ConfideHomeBodyBean>?
)
\ No newline at end of file
package com.ydl.confide.home.bean
/**
* @author yuanwai
* @描述:
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/10/15
*/
data class ConfideHomeBodyGroupItemBean(val title : String?,
val data : ArrayList<ConfideHomeFiterItemBean>?)
\ No newline at end of file
package com.ydl.confide.home.bean
import com.ydl.ydlcommon.bean.YDLFooterBean
import com.ydl.ydlcommon.bean.YDLHeadBean
/**
* @author yuanwai
* @描述:倾诉首页数据bean
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/7/26
*/
data class ConfideHomeDataBean(
/**
* 数据分类 1.banner 2.最近倾诉 3.分类测评 4.实时倾诉数据 5.为你推荐 6.听声寻人 7.咨询师推荐
*/
val type: Int?,
/**
* 数据集合节点
*/
val body : MutableList<ConfideHomeBodyBean>?,
/**
* 头部数据节点
*/
val head : YDLHeadBean?,
/**
* 底部数据节点
*/
val footer : YDLFooterBean?,
/**
* 为你推荐Id 本地使用 用于区分音频播放区域
*/
var recommendId : Int,
/**
* 是否显示分割线 0.不显示 1.显示
*/
val diviLine : Int?)
\ No newline at end of file
package com.ydl.confide.home.bean
/**
* @author yuanwai
* @描述:倾诉首页筛选Item bean
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/9/22
*/
data class ConfideHomeFiterItemBean(
/**
* 筛选id
*/
var id : String?,
/**
* 筛选名称
*/
var name : String?)
\ No newline at end of file
package com.ydl.confide.home.config
/**
* @author yuanwai
* @描述:倾诉首页配置信息
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/8/10
*/
interface IConfideHomeConfig{
companion object {
/**
* 数据类型 1.banner 2.最近倾诉 3.分类 4.为你推荐筛选模块
* 5.为你推荐 6.听声寻人 7.最佳倾诉榜单 999.底部 更多情感恋爱专家view
*/
const val TYPE_BANNER = 1
const val TYPE_RECENTLY_CONFIDED = 2
const val TYPE_CATEGORY = 3
const val TYPE_RECOMMEND_FILTER = 4
const val TYPE_RECOMMEND = 5
const val TYPE_SOUND = 6
const val TYPE_CONSULTANT = 7
const val TYPE_FOOTER = 999
/**
* section id. 与上面相对应
*/
const val SECTION_BANNER = 10001
const val SECTION_RECENTLY_CONFIDED = 10002
const val SECTION_CATEGORY = 10003
const val SECTION_RECOMMEND_FILTER = 10004
const val SECTION_RECOMMEND = 10005
const val SECTION_SOUND = 10006
const val SECTION_CONSULTANT = 10007
const val SECTION_FOOTER = 19999
/**
* 筛选窗状态
* 0.默认筛选状态 1.非默认筛选状态 2.筛选窗打开状态
*/
const val FILTER_STATUS_NORMAL = 0
const val FILTER_STATUS_FILTERED = 1
const val FILTER_STATUS_OPEN = 2
}
}
\ No newline at end of file
package com.ydl.confide.home.contract
import android.content.Context
import com.ydl.confide.home.bean.ConfideHomeBodyBean
import com.ydl.confide.home.bean.ConfideHomeDataBean
import com.ydl.confide.home.http.ConfideRecommendParam
import com.ydl.ydlcommon.mvp.base.IModel
import com.ydl.ydlcommon.mvp.base.IPresenter
import com.ydl.ydlcommon.mvp.base.IView
import com.ydl.ydlcommon.view.DrawableRightTextView
import io.reactivex.Observable
/**
* @author yuanwai
* @描述:倾诉首页约束类
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/8/10
*/
interface IConfideHomeContract{
//View接口
interface View : IView {
/**
* 倾诉首页数据请求结果
* @param list 数据集合
*/
fun confideHomeResponse(list : MutableList<ConfideHomeDataBean>)
/**
* 倾诉首页数据请求失败
*/
fun confideHomeRequestFail()
/**
* 为你推荐--筛选 请求结果
*/
fun recommendListResponse(bean : ConfideHomeDataBean)
/**
* 为你推荐--翻页 请求结果
*/
fun recommendListMoreResponse(bean : ConfideHomeDataBean)
/**
* 更新section的播放状态
* 点击列表中的一个播放按钮 其他播放按钮要显示暂停状态
* @param type
* @param index 模块中点击播放的索引位置
* @param recommendId
*/
fun updataPlayStatu(type : Int?,index : Int,recommendId : Int,isPlaying : Boolean)
/**
* 为你推荐列表
*/
fun recommendList(page : Int)
/**
* 排序弹窗
*/
fun showSortPopupWindow(v_line_top: android.view.View, tvSort: DrawableRightTextView, bodyBean: ConfideHomeBodyBean?)
/**
* 性别年龄弹窗
*/
fun showSexAgePopupWindow(v_line_top: android.view.View, tvSexAge: DrawableRightTextView, bodyBean: ConfideHomeBodyBean?)
/**
* 擅长方向弹窗
*/
fun showGoodPopupWindow(v_line_top: android.view.View, tvGood: DrawableRightTextView, bodyBean: ConfideHomeBodyBean?)
/**
* 移动到为你推荐筛选模块 并置顶
*/
fun moveToFilter()
/**
* 显示错误信息
*/
fun showError(msg : String?)
fun getContext() : Context
fun showProgress()
}
interface Presenter : IPresenter<View> {
/**
* 加载本地缓存
*/
fun loadLocalData(context: Context)
/**
* 倾诉首页数据请求
*/
fun confideHomeRequest()
/**
* 为你推荐列表(筛选调用)
*/
fun recommendList(param : ConfideRecommendParam)
/**
* 为你推荐列表(翻页调用)
*/
fun recommendListMore(param : ConfideRecommendParam)
}
interface Model: IModel {
/**
* 倾诉首页数据请求
*/
fun confideHomeRequest() : Observable<MutableList<ConfideHomeDataBean>>
/**
* 为你推荐列表
*/
fun recommendList(param : ConfideRecommendParam) : Observable<ConfideHomeDataBean>
}
}
\ No newline at end of file
package com.ydl.confide.home.event
import android.view.View
import com.ydl.confide.home.adapter.ConfideHomeAdapter
import com.ydl.confide.home.bean.ConfideHomeAllFiltersBean
import com.ydl.confide.home.bean.ConfideHomeBodyBean
import com.ydl.confide.home.widget.ConfideHomeFilterView
/**
* @author yuanwai
* @描述:倾诉首页事件处理类接口
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/8/10
*/
interface IConfideHomeEvent {
/**
* 跳转我的
*/
fun jumpMine()
/**
* banner点击事件
* @param linkUrl 跳转地址
* @param position 点击索引
* @param title banner 标题
*/
fun bannerClick(linkUrl: String?, position: Int?, title: String?)
/**
* 最近倾诉--继续倾诉
* @param linkUrl 跳转地址
*/
fun latelyConfideClick(linkUrl: String?)
/**
* 最近倾诉--更多
* @param linkUrl 跳转地址
*/
fun latelyConfideMore(linkUrl: String?)
/**
* 分类测评点击事件
* @param linkUrl
*/
fun categoryClick(linkUrl: String?)
/**
* 为你推荐--向TA倾诉
* @param linkUrl 跳转地址
*/
fun recommendClick(linkUrl: String?)
/**
* 为你推荐--更多
* @param linkUrl 跳转地址
*/
fun recommendMoreClick(linkUrl: String?)
/**
* 听声寻人--向TA倾诉
* @param linkUrl 跳转地址
*/
fun soundClick(linkUrl: String?)
/**
* 听声寻人--更多
* @param linkUrl 跳转地址
*/
fun soundMoreClick(linkUrl: String?)
/**
* 咨询师推荐--点我倾诉
* @param linkUrl 跳转地址
*/
fun consultantClick(linkUrl: String?)
/**
* 咨询师推荐--更多情感恋爱专家
* @param linkUrl 跳转地址
*/
fun consultantMoreClick(linkUrl: String?)
/**
* 播放音频
* @param type 当前模块数据类型
* @param index 当前的模块里的数据索引位置
* @param playUrl 播放地址
*/
fun playVoice(type: Int?, index: Int?, playUrl: String?)
/**
* 播放音频
* @param type 当前模块数据类型
* @param index 当前的模块里的数据索引位置
* @param recommendId 为你推荐Id(用于区分播放区域)
* @param playUrl 播放地址
* @param name 咨询师姓名
*/
fun playVoice(type: Int?, index: Int?, recommendId: Int, playUrl: String?, name: String?)
/**
* 重播
*/
fun rePlayVoice()
/**
* 暂停播放
*/
fun pauseVoice()
/**
* 结束播放 释放资源
*/
fun destoryPlayer()
/**
* 私聊
*/
fun toChatForMsg(doctorId: String?)
/**
* 排序弹窗
*/
fun showSortPopupWindow(v_line_top: View, filterView: ConfideHomeFilterView, bodyBean: ConfideHomeBodyBean?, allFiltersBean: ConfideHomeAllFiltersBean, mConfideAdapter: ConfideHomeAdapter)
/**
* 性别年龄弹窗
*/
fun showSexAgePopupWindow(v_line_top: View, filterView: ConfideHomeFilterView, bodyBean: ConfideHomeBodyBean?, allFiltersBean: ConfideHomeAllFiltersBean, mConfideAdapter: ConfideHomeAdapter)
/**
* 擅长方向弹窗
*/
fun showGoodPopupWindow(v_line_top: View, filterView: ConfideHomeFilterView, bodyBean: ConfideHomeBodyBean?, allFiltersBean: ConfideHomeAllFiltersBean, mConfideAdapter: ConfideHomeAdapter)
}
\ No newline at end of file
package com.ydl.confide.home.http
import com.ydl.confide.home.bean.ConfideHomeDataBean
import com.ydl.ydlcommon.base.config.YDL_DOMAIN
import com.ydl.ydlcommon.base.config.YDL_DOMAIN_JAVA
import com.ydl.ydlcommon.data.http.BaseAPIResponse
import io.reactivex.Observable
import retrofit2.http.GET
import retrofit2.http.Headers
import retrofit2.http.Url
/**
* @author yuanwai
* @描述:倾诉首页Api
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/8/10
*/
interface ConfideHomeApi{
//倾诉首页
@Headers( YDL_DOMAIN + YDL_DOMAIN_JAVA,"Content-Type:application/json")
@GET
fun confideHome(@Url url: String): Observable<BaseAPIResponse<MutableList<ConfideHomeDataBean>>>
//每日精选 换一批
@Headers( YDL_DOMAIN+ YDL_DOMAIN_JAVA,"Content-Type:application/json")
@GET
fun recommedChange(@Url url: String): Observable<BaseAPIResponse<ConfideHomeDataBean>>
}
\ No newline at end of file
package com.ydl.confide.home.http
/**
* @author yuanwai
* @描述:倾诉首页接口实现模型
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/7/26
*/
object ConfideHomeDataManager{
fun getHttp(): IConfideHomeHttp = ConfideHomeHttpImpl.getInstance()
}
\ No newline at end of file
package com.ydl.confide.home.http
import com.ydl.confide.home.bean.ConfideHomeDataBean
import com.ydl.ydlcommon.base.config.HttpConfig
import com.ydl.ydlcommon.data.http.BaseAPIResponse
import com.ydl.ydlcommon.data.http.RxUtils
import com.ydl.ydlnet.YDLHttpUtils
import io.reactivex.Observable
/**
* @author yuanwai
* @描述:倾诉首页接口实现类
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/7/26
*/
class ConfideHomeHttpImpl private constructor(): IConfideHomeHttp{
companion object {
fun getInstance(): ConfideHomeHttpImpl {
return Holder.INSTANCE
}
}
object Holder {
val INSTANCE = ConfideHomeHttpImpl()
}
private val confideHomeApi: ConfideHomeApi by lazy {
YDLHttpUtils.obtainApi(ConfideHomeApi::class.java)
}
override fun confideHomeRequest(): Observable<BaseAPIResponse<MutableList<ConfideHomeDataBean>>> {
return RxUtils.mapObservable(ConfideHomeParam(0))
.flatMap {
confideHomeApi.confideHome(HttpConfig.SERVER_API_JAVA_URL+"auth/listen/home")
}
}
override fun recommendList(param : ConfideRecommendParam): Observable<BaseAPIResponse<ConfideHomeDataBean>> {
var inuid = StringBuffer()
if (param != null && param.notInUid != null){
for (i in param.notInUid.indices) {
inuid.append(param.notInUid[i])
if(i<param.notInUid.size-1){
inuid.append(",")
}
}
}
val sb = StringBuffer()
sb.append("page").append("=").append(param.page).append("&")
.append("sortType").append("=").append(param.getSortType()).append("&")
.append("sexType").append("=").append(param.getSexType()).append("&")
.append("ageType").append("=").append(param.getAgeType()).append("&")
.append("goodType").append("=").append(param.getGoodType()).append("&")
.append("notInUid").append("=").append(inuid.toString()).append("&")
val confideParam = sb.toString()
return RxUtils.mapObservable(param)
.flatMap {
confideHomeApi.recommedChange(HttpConfig.SERVER_API_JAVA_URL + "auth/listen/search?"+confideParam)
}
}
}
\ No newline at end of file
package com.ydl.confide.home.http
/**
* @author yuanwai
* @描述:倾诉首页请求参数bean
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/8/10
*/
data class ConfideHomeParam(val type : Int)
\ No newline at end of file
package com.ydl.confide.home.http
/**
* @author yuanwai
* @描述:倾诉首页为你推荐请求参数bean
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/9/11
*/
class ConfideRecommendParam private constructor(builder: Builder){
/**
* 页码
*/
internal var page : Int = 1
/**
* 综合排序(传对应排序的ID)
*/
private var sortType : String = ""
/**
* 性别(传对应性别的ID)
*/
private var sexType : String = ""
/**
* 年龄(传对应年龄ID拼接成的字符串) 例如:选中60后、70后、80后,传参为:“6-7-8”
*/
private var ageType : String = ""
/**
* 年龄(传对应年龄ID拼接成的字符串) 例如:选中60后、70后、80后,传参为:“6-7-8”
*/
private var goodType : String = ""
//当前列表已存在专家uid列表
var notInUid : ArrayList<Int> = ArrayList()
fun getSortType() : String{
return sortType
}
fun getSexType() : String{
return sexType
}
fun getAgeType() : String{
return ageType
}
fun getGoodType() : String{
return goodType
}
init {
this.page = builder.page
this.sortType = builder.sortType
this.sexType = builder.sexType
this.ageType = builder.ageType
this.goodType = builder.goodType
this.notInUid = builder.notInUid
}
class Builder {
internal var page : Int = 1
internal var sortType : String = ""
internal var sexType : String = ""
internal var ageType : String = ""
internal var goodType : String = ""
internal var notInUid : ArrayList<Int> = ArrayList()
fun page(page: Int): Builder {
this.page = page
return this
}
fun sortType(sortType: String): Builder {
this.sortType = sortType
return this
}
fun sexType(sexType: String): Builder {
this.sexType = sexType
return this
}
fun ageType(ageType: String): Builder {
this.ageType = ageType
return this
}
fun goodType(goodType: String): Builder {
this.goodType = goodType
return this
}
fun build() : ConfideRecommendParam{
return ConfideRecommendParam(this)
}
}
}
package com.ydl.confide.home.http
import com.ydl.confide.home.bean.ConfideHomeDataBean
import com.ydl.ydlcommon.data.http.BaseAPIResponse
import io.reactivex.Observable
/**
* @author yuanwai
* @描述:倾诉首页请求接口
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/7/26
*/
interface IConfideHomeHttp{
/**
* 倾诉首页请求
*/
fun confideHomeRequest(): Observable<BaseAPIResponse<MutableList<ConfideHomeDataBean>>>
/**
* 为你推荐列表
*/
fun recommendList(param : ConfideRecommendParam): Observable<BaseAPIResponse<ConfideHomeDataBean>>
}
\ No newline at end of file
package com.ydl.confide.home.listener
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import com.yidianling.common.tools.LogUtil
import com.yidianling.common.tools.RxImageTool
/**
* @author yuanwai
* @描述:
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/9/25
*/
class ConfideHomeRecycleViewListener : RecyclerView.OnScrollListener() {
/**
* 筛选模块位置
*/
private var mIndex: Int = 0
/**
* rv是否需要第二次滚动
*/
private var move = false
override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
//在这里进行第二次滚动(最后的距离)
if (move && recyclerView != null) {
move = false
//获取要置顶的项在当前屏幕的位置,mIndex是记录的要置顶项在RecyclerView中的位置
var n = mIndex - (recyclerView!!.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
if (0 <= n && n < recyclerView.childCount) {
//获取要置顶的项顶部离RecyclerView顶部的距离
var top = recyclerView.getChildAt(n).top
//最后的移动
recyclerView.scrollBy(0, top)
}
}
}
/**
* 设置筛选模块的位置
*/
fun setFilterIndex(index : Int){
this.mIndex = index
}
/**
* 移动筛选模块置顶
*/
fun moveToPosition(mRecyclerView: RecyclerView){
mRecyclerView.scrollBy(0, 1)
var top = mRecyclerView.getChildAt(mIndex).top
if(top==0 || top==1){
//已滚动到顶部
}else{
// top-=mRecyclerView.getChildAt(mIndex).height
mRecyclerView.scrollBy(0, top)
}
//获取当前recycleView屏幕可见的第一项和最后一项的Position
// var firstItem = (recyclerview.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
// var lastItem = (recyclerview.layoutManager as LinearLayoutManager).findLastVisibleItemPosition()
// //然后区分情况
// if (mIndex <= firstItem) {
// //当要置顶的项在当前显示的第一个项的前面时
// recyclerview.scrollToPosition(mIndex)
// } else if (mIndex <= lastItem) {
// //当要置顶的项已经在屏幕上显示时,计算它离屏幕原点的距离
// var top = recyclerview.getChildAt(mIndex - firstItem).top - RxImageTool.dip2px(48f)
// recyclerview.scrollBy(0, top)
// } else {
// //当要置顶的项在当前显示的最后一项的后面时
// recyclerview.scrollToPosition(mIndex)
// //记录当前需要在RecyclerView滚动监听里面继续第二次滚动
// move = true
// }
}
}
\ No newline at end of file
package com.ydl.confide.home.listener
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.View
import com.yidianling.common.tools.LogUtil
import com.yidianling.common.tools.RxImageTool
import com.ydl.confide.home.adapter.ConfideHomeAdapter
import com.ydl.confide.home.config.IConfideHomeConfig
import com.ydl.confide.home.widget.ConfideHomeFilterView
/**
* @author yuanwai
* @描述:悬浮按钮监听事件
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/9/25
*/
class ConfideHomeRecyleSuspendListener : RecyclerView.OnScrollListener() {
private var mCurrentPosition = 0
private var mSuspensionHeight: Int = RxImageTool.dip2px(48f)
private var filterView: ConfideHomeFilterView? = null
private var adapter: ConfideHomeAdapter? = null
fun setFilterView(filterView: ConfideHomeFilterView) {
this.filterView = filterView
}
fun setSectionAdapter(adapter: ConfideHomeAdapter) {
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) == IConfideHomeConfig.TYPE_RECOMMEND) {
var view = manager.findViewByPosition(mCurrentPosition + 1)
if (view != null) {
if (view.top <= mSuspensionHeight) {
filterView!!.visibility = View.VISIBLE
} else {
// filterView!!.visibility = View.INVISIBLE
}
}
}else if (adapter!!.getItemViewType(mCurrentPosition) == IConfideHomeConfig.TYPE_RECOMMEND || adapter!!.getItemViewType(mCurrentPosition) == IConfideHomeConfig.TYPE_SOUND){
filterView!!.visibility = View.VISIBLE
}else {
filterView!!.visibility = View.INVISIBLE
}
}
}
\ No newline at end of file
package com.ydl.confide.home.model
import com.ydl.confide.home.bean.ConfideHomeDataBean
import com.ydl.confide.home.contract.IConfideHomeContract
import com.ydl.confide.home.http.ConfideHomeDataManager
import com.ydl.confide.home.http.ConfideRecommendParam
import com.ydl.ydlcommon.data.http.RxUtils
import io.reactivex.Observable
/**
* @author yuanwai
* @描述:倾诉首页数据模型实现类
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/8/10
*/
class ConfideHomeModelImpl : IConfideHomeContract.Model{
override fun confideHomeRequest(): Observable<MutableList<ConfideHomeDataBean>> {
return ConfideHomeDataManager.getHttp().confideHomeRequest()
.compose(RxUtils.resultJavaData())
}
override fun recommendList(param : ConfideRecommendParam): Observable<ConfideHomeDataBean> {
return ConfideHomeDataManager.getHttp().recommendList(param)
.compose(RxUtils.resultJavaData())
}
}
\ No newline at end of file
package com.ydl.confide.home.popwindow
import android.content.Context
import android.graphics.Typeface
import android.graphics.drawable.BitmapDrawable
import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.PopupWindow
import com.yidianling.common.tools.RxImageTool
import com.ydl.confide.R
import com.ydl.confide.home.bean.ConfideHomeFiterItemBean
import com.ydl.confide.home.popwindow.adapter.ConfideHomeGoodAdapter
import com.ydl.ydlcommon.view.SpaceItemDecorator
import kotlinx.android.synthetic.main.confidehome_good_popup_window.view.*
/**
* @author yuanwai
* @描述:倾诉首页--擅长方向popWindow
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/9/22
*/
class ConfideHomeGoodPopupWindow(context: Context, goodsList: ArrayList<ConfideHomeFiterItemBean>, selectedGoodsList: ArrayList<ConfideHomeFiterItemBean>)
: PopupWindow(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) {
var onGoodSelectedListener: OnGoodSelectedListener? = null
//擅长方向列表数据
private var goodsList: ArrayList<ConfideHomeFiterItemBean>? = null
//已选择的擅长方向数据
private var selectedGoodsList: ArrayList<ConfideHomeFiterItemBean>? = null
init {
val view = LayoutInflater.from(context).inflate(R.layout.confidehome_good_popup_window, null)
this.contentView = view
this.isFocusable = true
@Suppress("DEPRECATION")
this.setBackgroundDrawable(BitmapDrawable())
this.isOutsideTouchable = true
val rvGood = view.rvGood
val tvTitle = view.tv_title
tvTitle.text = "擅长方向"
if (null == this.goodsList){
this.goodsList = ArrayList()
}else{
(this.goodsList as ArrayList).clear()
}
this.goodsList!!.addAll(goodsList)
if (null == this.selectedGoodsList){
this.selectedGoodsList = ArrayList()
}else{
(this.selectedGoodsList as ArrayList).clear()
}
this.selectedGoodsList!!.addAll(selectedGoodsList)
var goodAdapter: ConfideHomeGoodAdapter? = null
if (null == rvGood.adapter){
goodAdapter = ConfideHomeGoodAdapter(context, this.goodsList!!, this.selectedGoodsList!!)
rvGood.adapter = goodAdapter
rvGood.layoutManager = GridLayoutManager(context, 3, LinearLayoutManager.VERTICAL, false)
rvGood.addItemDecoration(SpaceItemDecorator(RxImageTool.dp2px(8f), 3))
}
inputMethodMode = PopupWindow.INPUT_METHOD_NEEDED
view.btnConfirm.setOnClickListener {
onGoodSelectedListener?.onGoodSelected(this.selectedGoodsList!!)
dismiss()
}
view.btnReset.setOnClickListener {
goodAdapter?.cleanSelectedGoods()
}
view.v_zhezhao.setOnClickListener {
dismiss()
}
}
interface OnGoodSelectedListener {
fun onGoodSelected(selectedGoodsList: ArrayList<ConfideHomeFiterItemBean>)
}
}
\ No newline at end of file
package com.ydl.confide.home.popwindow
import android.content.Context
import android.graphics.Typeface
import android.graphics.drawable.BitmapDrawable
import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.PopupWindow
import android.widget.TextView
import com.yidianling.common.tools.RxImageTool
import com.ydl.confide.R
import com.ydl.confide.home.bean.ConfideHomeAllFiltersBean
import com.ydl.confide.home.bean.ConfideHomeFiterItemBean
import com.ydl.confide.home.popwindow.adapter.ConfideHomeGoodAdapter
import com.ydl.ydlcommon.view.SpaceItemDecorator
import kotlinx.android.synthetic.main.confidehome_sexage_popup_window.view.*
/**
* @author yuanwai
* @描述:倾诉首页--性别年龄popWindow
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/9/22
*/
class ConfideHomeSexAgePopupWindow(context: Context, sexData: ArrayList<ConfideHomeFiterItemBean>,ageData : ArrayList<ConfideHomeFiterItemBean>, allFiltersBean: ConfideHomeAllFiltersBean)
: PopupWindow(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) {
var onGoodSelectedListener: OnSexAgeSelectedListener? = null
//性别数据集
private var sexData: ArrayList<ConfideHomeFiterItemBean>? = null
//年龄数据集
private var ageData: ArrayList<ConfideHomeFiterItemBean>? = null
//已选择的性别数据
private var selectSex : ConfideHomeFiterItemBean? = null
//已选择的年龄数据集
private var selectedAge: ArrayList<ConfideHomeFiterItemBean>? = null
private var sexAgeAdapter : ConfideHomeGoodAdapter? = null
private var mAllFiltersBean : ConfideHomeAllFiltersBean? = null
init {
val view = LayoutInflater.from(context).inflate(R.layout.confidehome_sexage_popup_window, null)
this.contentView = view
this.isFocusable = true
@Suppress("DEPRECATION")
this.setBackgroundDrawable(BitmapDrawable())
this.isOutsideTouchable = true
val rvAge = view.rvAge
val tvSexTitle = view.tv_sexTitle
val tvAgeTitle = view.tv_ageTitle
tvSexTitle.text = "性别筛选"
tvAgeTitle.text = "年龄筛选"
if (null == mAllFiltersBean){
mAllFiltersBean = ConfideHomeAllFiltersBean(allFiltersBean.page,allFiltersBean.selectSort,allFiltersBean.selectSex,allFiltersBean.selectAgeData,allFiltersBean.selectGoodData)
}
initData(sexData,ageData,mAllFiltersBean!!)
initSexData(view,mAllFiltersBean!!)
initAdapter(context,rvAge)
inputMethodMode = PopupWindow.INPUT_METHOD_NEEDED
view.btnConfirm.setOnClickListener {
onGoodSelectedListener?.onSexAgeSelected(this.selectSex!!,this.selectedAge!!)
dismiss()
}
view.btnReset.setOnClickListener {
selectSex = ConfideHomeFiterItemBean("-1","")
mAllFiltersBean!!.selectSex = selectSex
initSexData(view,mAllFiltersBean!!)
sexAgeAdapter?.cleanSelectedGoods()
}
view.v_zhezhao.setOnClickListener {
dismiss()
}
}
/**
* 初始化数据
*/
private fun initData(sexData: ArrayList<ConfideHomeFiterItemBean>,ageData : ArrayList<ConfideHomeFiterItemBean>,allFiltersBean: ConfideHomeAllFiltersBean){
//初始化已选择性别数据
if (null == selectSex){
selectSex = ConfideHomeFiterItemBean("-1","")
}
if (null != allFiltersBean.selectSex){
selectSex!!.id = allFiltersBean.selectSex!!.id
selectSex!!.name = allFiltersBean.selectSex!!.name
}
//初始化性别数据集
if (null == this.sexData){
this.sexData = ArrayList()
}else{
(this.sexData as ArrayList).clear()
}
this.sexData!!.addAll(sexData)
//初始化年龄数据集
if (null == this.ageData){
this.ageData = ArrayList()
}else{
(this.ageData as ArrayList).clear()
}
this.ageData!!.addAll(ageData)
//初始化已选择年龄数据集
if (null == this.selectedAge){
this.selectedAge = ArrayList()
}else{
(this.selectedAge as ArrayList).clear()
}
this.selectedAge!!.addAll(allFiltersBean.selectAgeData!!)
}
/**
* 初始化性别数据
*/
private fun initSexData(view : View,allFiltersBean: ConfideHomeAllFiltersBean){
var tvSex1 = view.findViewById<TextView>(R.id.tvSex1)
var tvSex2 = view.findViewById<TextView>(R.id.tvSex2)
if (null != sexData && sexData!!.size > 0){
tvSex1.text = sexData!![0].name
tvSex1.setOnClickListener {
if (selectSex!!.id == sexData!![0].id){
selectSex!!.id = "-1"
selectSex!!.name = ""
setSelect(tvSex1,false)
}else{
selectSex!!.id = sexData!![0].id
selectSex!!.name = sexData!![0].name
setSelect(tvSex1,true)
setSelect(tvSex2,false)
}
}
}
if (null != sexData && sexData!!.size > 1) {
tvSex2.text = sexData!![1].name
tvSex2.setOnClickListener {
if (selectSex!!.id == sexData!![1].id){
selectSex!!.id = "-1"
selectSex!!.name = ""
setSelect(tvSex2,false)
}else{
selectSex!!.id = sexData!![1].id
selectSex!!.name = sexData!![1].name
setSelect(tvSex1,false)
setSelect(tvSex2,true)
}
}
}
if (null == sexData || null == allFiltersBean.selectSex){
return
}
if (sexData!!.size > 0 && allFiltersBean.selectSex!!.id == sexData!![0].id){
setSelect(tvSex1,true)
}else if (sexData!!.size > 1 && allFiltersBean.selectSex!!.id == sexData!![1].id){
setSelect(tvSex2,true)
}else{
setSelect(tvSex1,false)
setSelect(tvSex2,false)
}
}
/**
* 设置性别选中样式
*/
private fun setSelect(tvSex1: TextView,boolean: Boolean){
if (boolean){
tvSex1.setBackgroundResource(R.drawable.confidehome_filter_select_sel)
tvSex1.setTextColor(tvSex1.context.resources.getColor(R.color.baby_blue))
}else{
tvSex1.setBackgroundResource(R.drawable.confidehome_filter_select_nor)
tvSex1.setTextColor(tvSex1.context.resources.getColor(R.color._6))
}
}
private fun initAdapter(context: Context,rvAge : RecyclerView){
//初始化年龄适配器
if (null == rvAge.adapter){
sexAgeAdapter = ConfideHomeGoodAdapter(context, this.ageData!!, this.selectedAge!!)
rvAge.adapter = sexAgeAdapter
rvAge.layoutManager = GridLayoutManager(context, 3, LinearLayoutManager.VERTICAL, false)
rvAge.addItemDecoration(SpaceItemDecorator(RxImageTool.dp2px(8f), 3))
}
}
interface OnSexAgeSelectedListener {
fun onSexAgeSelected(sexData : ConfideHomeFiterItemBean,ageData: ArrayList<ConfideHomeFiterItemBean>)
}
}
\ No newline at end of file
package com.ydl.confide.home.popwindow
import android.content.Context
import android.graphics.drawable.BitmapDrawable
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.PopupWindow
import com.ydl.confide.R
import com.ydl.confide.home.bean.ConfideHomeFiterItemBean
import com.ydl.confide.home.popwindow.adapter.ConfideHomeSortAdapter
import kotlinx.android.synthetic.main.confidehome_sort_popup_window.view.*
/**
* @author yuanwai
* @描述:综合排序popupWindow
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/9/22
*/
class ConfideHomeSortPopupWindow(val context: Context, private val sortItems: ArrayList<ConfideHomeFiterItemBean>, var selectedSort: ConfideHomeFiterItemBean, private val onSortItemSelectedListener: OnSortItemSelectedListener)
: PopupWindow(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) {
private var adapter: ConfideHomeSortAdapter? = null
init {
val view = LayoutInflater.from(context).inflate(R.layout.confidehome_sort_popup_window, null)
this.contentView = view
this.isFocusable = true
@Suppress("DEPRECATION")
this.setBackgroundDrawable(BitmapDrawable())
this.isOutsideTouchable = true
val rvSortItem = view.rvSortItem
if (null == adapter){
adapter = ConfideHomeSortAdapter(context, sortItems, selectedSort, onSortItemSelectedListener)
rvSortItem.adapter = adapter
rvSortItem.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
}
view.v_zhezhao.setOnClickListener {
dismiss()
}
}
fun notifyDataSetChanged() {
adapter?.notifyDataSetChanged()
}
interface OnSortItemSelectedListener {
fun onSortItemSelected(sortItem: ConfideHomeFiterItemBean)
}
}
\ No newline at end of file
package com.ydl.confide.home.popwindow.adapter
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.ydl.confide.R
import com.ydl.confide.home.bean.ConfideHomeFiterItemBean
import kotlinx.android.synthetic.main.confidehome_good_item.view.*
/**
* @author yuanwai
* @描述:倾诉首页--筛选模块--擅长方式popwindow适配器
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/9/22
*/
class ConfideHomeGoodAdapter(private val context: Context, private val goods: ArrayList<ConfideHomeFiterItemBean>, private val selectedGood: ArrayList<ConfideHomeFiterItemBean>) : RecyclerView.Adapter<ConfideHomeGoodAdapter.ViewHolder>() {
override fun onBindViewHolder(holder: ViewHolder?, position: Int) {
if (holder != null) {
val category = goods[position]
holder.tvGoodName.text = goods[position].name
holder.tvGoodName.isSelected = selectedGood.contains(category)
if (holder.tvGoodName.isSelected) {
holder.tvGoodName.setBackgroundResource(R.drawable.confidehome_filter_select_sel)
} else {
holder.tvGoodName.setBackgroundResource(R.drawable.confidehome_filter_select_nor)
}
}
}
fun cleanSelectedGoods(){
selectedGood?.clear()
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
val itemView = LayoutInflater.from(context).inflate(R.layout.confidehome_good_item, parent, false)
return ViewHolder(itemView)
}
override fun getItemCount(): Int = goods.size
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val tvGoodName: TextView = itemView.tvGoodName
init {
itemView.setOnClickListener {
if (adapterPosition != RecyclerView.NO_POSITION) {
val subject = goods[adapterPosition]
when {
//如果 点击已选中的 那就移除 然后更新
selectedGood.contains(subject) -> {
selectedGood.remove(subject)
notifyItemChanged(adapterPosition)
}
else -> {
//如果点击没选中的 则添加
selectedGood.add(subject)
notifyDataSetChanged()
}
}
}
}
}
}
}
\ No newline at end of file
package com.ydl.confide.home.popwindow.adapter
import android.content.Context
import android.graphics.Color
import android.support.v4.content.ContextCompat
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.ydl.confide.R
import com.ydl.confide.home.bean.ConfideHomeFiterItemBean
import com.ydl.confide.home.popwindow.ConfideHomeSortPopupWindow
import kotlinx.android.synthetic.main.confidehome_sort_item.view.*
/**
* @author yuanwai
* @描述:倾诉首页--综合排序适配器
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/9/22
*/
class ConfideHomeSortAdapter(private val context: Context,
private val sortItems: ArrayList<ConfideHomeFiterItemBean>,
private val selectedSort: ConfideHomeFiterItemBean,
private val onItemSelectedListener: ConfideHomeSortPopupWindow.OnSortItemSelectedListener) : RecyclerView.Adapter<ConfideHomeSortAdapter.ViewHolder>() {
override fun getItemCount(): Int = sortItems.size
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
val itemView = LayoutInflater.from(context).inflate(R.layout.confidehome_sort_item, parent, false)
return ViewHolder(itemView)
}
override fun onBindViewHolder(holder: ViewHolder?, position: Int) {
val item = sortItems[position]
if (holder != null) {
holder.tvSort.text = item.name
if (item.id == selectedSort.id) {
holder.tvSort.setTextColor(Color.parseColor("#1DA1F2"))
}else{
holder.tvSort.setTextColor(ContextCompat.getColor(context, R.color._6))
}
}
}
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val tvSort = itemView.tvSort!!
init {
itemView.setOnClickListener {
if (adapterPosition != RecyclerView.NO_POSITION){
onItemSelectedListener.onSortItemSelected(sortItems[adapterPosition])
}
}
}
}
}
\ No newline at end of file
倾诉首页界面
\ No newline at end of file
package com.ydl.confide.home.section
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import com.ydl.confide.R
import com.ydl.confide.home.bean.ConfideHomeDataBean
import com.ydl.confide.home.config.IConfideHomeConfig
import com.ydl.confide.home.event.IConfideHomeEvent
import com.ydl.confide.home.widget.ConfideHomeBannerView
import com.ydl.ydlcommon.adapter.section.Section
/**
* @author yuanwai
* @描述:banner 适配器
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/8/10 0010
*/
class ConfideHomeBannerSection(var context: Context, private var confideHomeEvent : IConfideHomeEvent) : Section<RecyclerView.ViewHolder>(0) {
override fun getSectionId(): Int {
return IConfideHomeConfig.SECTION_BANNER
}
private var data : ConfideHomeDataBean? = null
override fun getTotalDataNum(): Int {
return 1
}
override fun getItemViewType(position: Int): Int {
return IConfideHomeConfig.SECTION_BANNER
}
fun setData(data : ConfideHomeDataBean){
this.data = data
}
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): RecyclerView.ViewHolder {
return when(viewType){
//banner
IConfideHomeConfig.SECTION_BANNER -> {
BannerViewHolder(ConfideHomeBannerView(context,confideHomeEvent))
}
else -> {
EmptyViewHolder(View.inflate(context,R.layout.view_empty,null))
}
}
}
override fun bindViewHolder(holder: RecyclerView.ViewHolder?, position: Int) {
if (holder is BannerViewHolder){
holder.bannerView!!.initData(this.data!!)
}
}
override fun isBelongTo(viewType: Int): Boolean {
return viewType.toString().startsWith(IConfideHomeConfig.SECTION_BANNER.toString())
}
override fun isHeadType(position: Int): Boolean {
return false
}
override fun isFooterType(position: Int): Boolean {
return false
}
/**
* banner viewHolder
*/
inner class BannerViewHolder(itemView: ConfideHomeBannerView) : RecyclerView.ViewHolder(itemView) {
var bannerView: ConfideHomeBannerView? = null
init {
bannerView = itemView
}
}
/**
* 空View
*/
inner class EmptyViewHolder(itemViews: View) : RecyclerView.ViewHolder(itemViews) {
private var itemViews: View? = null
init {
this.itemViews = itemViews
}
}
}
\ No newline at end of file
package com.ydl.confide.home.section
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import com.ydl.confide.R
import com.ydl.confide.home.bean.ConfideHomeDataBean
import com.ydl.confide.home.config.IConfideHomeConfig
import com.ydl.confide.home.contract.IConfideHomeContract
import com.ydl.confide.home.event.IConfideHomeEvent
import com.ydl.confide.home.widget.ConfideHomeCategoryView
import com.ydl.ydlcommon.adapter.section.Section
/**
* @author yuanwai
* @描述:倾诉首页 分类 适配器
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/8/10 0010
*/
class ConfideHomeCategorySection(var context: Context, var confideHomeEvent : IConfideHomeEvent,var homeView : IConfideHomeContract.View) : Section<RecyclerView.ViewHolder>(0) {
override fun getSectionId(): Int {
return IConfideHomeConfig.SECTION_CATEGORY
}
private var data : ConfideHomeDataBean? = null
override fun getTotalDataNum(): Int {
return 1
}
override fun getItemViewType(position: Int): Int {
return IConfideHomeConfig.SECTION_CATEGORY
}
fun setData(data : ConfideHomeDataBean){
this.data = data
}
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): RecyclerView.ViewHolder {
return when(viewType){
//banner
IConfideHomeConfig.SECTION_CATEGORY -> {
CategoryViewHolder(ConfideHomeCategoryView(context,confideHomeEvent,homeView))
}
else -> {
EmptyViewHolder(View.inflate(context,R.layout.view_empty,null))
}
}
}
override fun bindViewHolder(holder: RecyclerView.ViewHolder?, position: Int) {
if (holder is CategoryViewHolder){
holder.categoryView!!.initData(this.data!!)
}
}
override fun isBelongTo(viewType: Int): Boolean {
return viewType.toString().startsWith(IConfideHomeConfig.SECTION_CATEGORY.toString())
}
override fun isHeadType(position: Int): Boolean {
return false
}
override fun isFooterType(position: Int): Boolean {
return false
}
/**
* 分类测评 viewHolder
*/
inner class CategoryViewHolder(itemView: ConfideHomeCategoryView) : RecyclerView.ViewHolder(itemView) {
var categoryView: ConfideHomeCategoryView? = null
init {
categoryView = itemView
}
}
/**
* 空View
*/
inner class EmptyViewHolder(itemViews: View) : RecyclerView.ViewHolder(itemViews) {
private var itemViews: View? = null
init {
this.itemViews = itemViews
}
}
}
\ No newline at end of file
package com.ydl.confide.home.section
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import com.yidianling.common.tools.RxImageTool
import com.ydl.confide.R
import com.ydl.confide.home.bean.ConfideHomeDataBean
import com.ydl.confide.home.config.IConfideHomeConfig
import com.ydl.confide.home.contract.IConfideHomeContract
import com.ydl.confide.home.event.IConfideHomeEvent
import com.ydl.confide.home.widget.ConfideHomeFilterView
import com.ydl.ydlcommon.adapter.section.Section
/**
* @author yuanwai
* @描述:为你推荐筛选模块section
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/9/21 0010
*/
class ConfideHomeFilterSection(var context: Context,var view : IConfideHomeContract.View) : Section<RecyclerView.ViewHolder>(0) {
private val FOOTER = 200
private var mFilterViewHolder : FilterViewHolder? = null
override fun getSectionId(): Int {
return IConfideHomeConfig.SECTION_RECOMMEND_FILTER
}
private var data: ConfideHomeDataBean? = null
override fun getItemViewType(position: Int): Int {
if (isFooterType(position)) {
return combineType(IConfideHomeConfig.SECTION_RECOMMEND_FILTER, this.FOOTER)
} else {
return IConfideHomeConfig.SECTION_RECOMMEND_FILTER
}
}
fun setData(data: ConfideHomeDataBean) {
this.data = data
}
override fun bindViewHolder(holder: RecyclerView.ViewHolder?, position: Int) {
if (holder is FilterViewHolder) {
holder.filterView.initData(data!!)
}else if (holder is FooterViewHolder){
}
}
override fun getTotalDataNum(): Int {
return 2
}
fun getFilterViewHolder() : FilterViewHolder? {
return mFilterViewHolder
}
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): RecyclerView.ViewHolder {
if (viewType == combineType(IConfideHomeConfig.SECTION_RECOMMEND_FILTER, FOOTER)) {
var param = RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,RxImageTool.dip2px(0.5f))
var dp15 = RxImageTool.dip2px(15f)
param.setMargins(dp15,0,dp15,0)
var footerView = View(context)
footerView.setBackgroundColor(context.resources.getColor(R.color.confidehome_filters_line))
footerView.layoutParams = param
return FooterViewHolder(footerView)
}else{
mFilterViewHolder = FilterViewHolder(ConfideHomeFilterView(context,view))
return mFilterViewHolder as FilterViewHolder
}
}
override fun isBelongTo(viewType: Int): Boolean {
return viewType.toString().startsWith(IConfideHomeConfig.SECTION_RECOMMEND_FILTER.toString())
}
override fun isHeadType(position: Int): Boolean {
return false
}
override fun isFooterType(position: Int): Boolean {
if (position == 1){
return true
}
return false
}
inner class FilterViewHolder(var filterView: ConfideHomeFilterView) : RecyclerView.ViewHolder(filterView)
inner class FooterViewHolder(var footerView : View) : RecyclerView.ViewHolder(footerView)
}
\ No newline at end of file
package com.ydl.confide.home.section
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import com.ydl.confide.R
import com.ydl.confide.home.config.IConfideHomeConfig
import com.ydl.confide.home.event.IConfideHomeEvent
import com.ydl.confide.home.widget.ConfideHomeFooterView
import com.ydl.ydlcommon.adapter.section.Section
/**
* @author yuanwai
* @描述:倾诉首页 底部 更多情感恋爱专家View 适配器
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/8/10 0010
*/
class ConfideHomeFooterSection(var context: Context, private var confideHomeEvent : IConfideHomeEvent) : Section<RecyclerView.ViewHolder>(0) {
override fun getSectionId(): Int {
return IConfideHomeConfig.SECTION_FOOTER
}
override fun getTotalDataNum(): Int {
return 1
}
override fun getItemViewType(position: Int): Int {
return IConfideHomeConfig.SECTION_FOOTER
}
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): RecyclerView.ViewHolder {
return when(viewType){
//banner
IConfideHomeConfig.SECTION_FOOTER -> {
FooterViewHolder(ConfideHomeFooterView(context,confideHomeEvent))
}
else -> {
EmptyViewHolder(View.inflate(context,R.layout.view_empty,null))
}
}
}
override fun bindViewHolder(holder: RecyclerView.ViewHolder?, position: Int) {
}
override fun isBelongTo(viewType: Int): Boolean {
return viewType.toString().startsWith(IConfideHomeConfig.SECTION_FOOTER.toString())
}
override fun isHeadType(position: Int): Boolean {
return false
}
override fun isFooterType(position: Int): Boolean {
return false
}
/**
* 底部 更多情感恋爱专家 viewHolder
*/
inner class FooterViewHolder(itemView: ConfideHomeFooterView) : RecyclerView.ViewHolder(itemView) {
var footerView: ConfideHomeFooterView? = null
init {
footerView = itemView
}
}
/**
* 空View
*/
inner class EmptyViewHolder(itemViews: View) : RecyclerView.ViewHolder(itemViews) {
private var itemViews: View? = null
init {
this.itemViews = itemViews
}
}
}
\ No newline at end of file
package com.ydl.confide.home.section
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.ViewGroup
import com.ydl.confide.home.bean.ConfideHomeDataBean
import com.ydl.confide.home.config.IConfideHomeConfig
import com.ydl.confide.home.contract.IConfideHomeContract
import com.ydl.confide.home.event.IConfideHomeEvent
import com.ydl.confide.home.widget.ConfideHomeHeadView
import com.ydl.confide.home.widget.ConfideHomeListenAndFoundView
import com.ydl.ydlcommon.adapter.section.Section
/**
* @author Jim
* @描述:听声寻人section
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/8/11 0011
*/
class ConfideHomeListenAndFoundSection(var context: Context, var view: IConfideHomeContract.View, var confideHomeEvent: IConfideHomeEvent) : Section<RecyclerView.ViewHolder>(0) {
override fun getSectionId(): Int {
return IConfideHomeConfig.SECTION_RECENTLY_CONFIDED
}
private var data: ConfideHomeDataBean? = null
private val HEADER = 200
private var confideHomeListenAndFoundView: ConfideHomeListenAndFoundView? = null
fun setData(data: ConfideHomeDataBean) {
this.data = data
}
override fun bindViewHolder(holder: RecyclerView.ViewHolder?, position: Int) {
if (holder is HeadViewHolder) {
holder.confideHeadView.initData(this.data!!)
} else if (holder is ConfideHomeListenAndFoundViewHolder) {
holder.confideHomeListenAndFoundView.initData(this.data!!)
}
}
override fun getTotalDataNum(): Int {
var count = 1
if (data?.head != null) {
count++
} else if (data?.footer != null) {
count++
}
return count
}
override fun getItemViewType(position: Int): Int {
if (isHeadType(position)) {
return combineType(IConfideHomeConfig.SECTION_SOUND, this.HEADER)
} else {
return IConfideHomeConfig.SECTION_SOUND
}
}
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): RecyclerView.ViewHolder {
if (viewType == combineType(IConfideHomeConfig.SECTION_SOUND, HEADER)) {
return HeadViewHolder(ConfideHomeHeadView(context, confideHomeEvent))
} else {
confideHomeListenAndFoundView = ConfideHomeListenAndFoundView(context, confideHomeEvent)
return ConfideHomeListenAndFoundViewHolder(confideHomeListenAndFoundView!!)
}
}
override fun isBelongTo(viewType: Int): Boolean {
return viewType.toString().startsWith(IConfideHomeConfig.SECTION_SOUND.toString())
}
override fun isHeadType(position: Int): Boolean {
if (data?.head == null) {
return false
} else if (position == 0) {
return true
}
return false
}
override fun isFooterType(position: Int): Boolean {
return false
}
inner class HeadViewHolder(var confideHeadView: ConfideHomeHeadView) : RecyclerView.ViewHolder(confideHeadView)
inner class ConfideHomeListenAndFoundViewHolder(var confideHomeListenAndFoundView: ConfideHomeListenAndFoundView) : RecyclerView.ViewHolder(confideHomeListenAndFoundView)
}
\ No newline at end of file
package com.ydl.confide.home.section
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.ViewGroup
import com.ydl.confide.home.bean.ConfideHomeDataBean
import com.ydl.confide.home.config.IConfideHomeConfig
import com.ydl.confide.home.event.IConfideHomeEvent
import com.ydl.confide.home.widget.ConfideHomeRecentView
import com.ydl.ydlcommon.adapter.section.Section
/**
* @author Jim
* @描述:最近倾诉
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/8/10 0010
*/
class ConfideHomeRecentConfideSection(var context: Context, var confideHomeEvent: IConfideHomeEvent) : Section<RecyclerView.ViewHolder>(0) {
override fun getSectionId(): Int {
return IConfideHomeConfig.SECTION_RECENTLY_CONFIDED
}
private var data: ConfideHomeDataBean? = null
fun setData(data: ConfideHomeDataBean) {
this.data = data
}
override fun bindViewHolder(holder: RecyclerView.ViewHolder?, position: Int) {
if (holder is ConsultViewHolder) {
holder.consultView.initData(data!!)
}
}
override fun getTotalDataNum(): Int {
return 1
}
override fun getItemViewType(position: Int): Int {
return IConfideHomeConfig.SECTION_RECENTLY_CONFIDED
}
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): RecyclerView.ViewHolder {
return ConsultViewHolder(ConfideHomeRecentView(context, confideHomeEvent))
}
override fun isBelongTo(viewType: Int): Boolean {
return viewType.toString().startsWith(IConfideHomeConfig.SECTION_RECENTLY_CONFIDED.toString())
}
override fun isHeadType(position: Int): Boolean {
return false
}
override fun isFooterType(position: Int): Boolean {
return false
}
inner class ConsultViewHolder(var consultView: ConfideHomeRecentView) : RecyclerView.ViewHolder(consultView)
}
\ No newline at end of file
package com.ydl.confide.home.section
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.ydl.confide.R
import com.ydl.confide.home.bean.ConfideHomeDataBean
import com.ydl.confide.home.config.IConfideHomeConfig
import com.ydl.confide.home.event.IConfideHomeEvent
import com.ydl.confide.home.widget.ConfideHomeRecommendExpertView
import com.ydl.ydlcommon.adapter.section.Section
/**
* @author Jim
* @描述:最佳倾诉榜单section
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/8/11 0011
*/
class ConfideHomeRecommendExpertSection(var context: Context, var confideHomeEvent: IConfideHomeEvent) : Section<RecyclerView.ViewHolder>(0){
private var data: ConfideHomeDataBean? = null
private val HEADER = 200
fun setData(data: ConfideHomeDataBean) {
this.data = data
}
override fun bindViewHolder(holder: RecyclerView.ViewHolder?, position: Int) {
if (holder is HeadViewHolder && null != data && null != data!!.head && !TextUtils.isEmpty(this.data?.head!!.title)) {
holder.confideHeadView.findViewById<TextView>(R.id.tv_title).text = this.data?.head!!.title
} else if (holder is ConfideHomeRecommendExpertViewHolder) {
holder.confideHomeRecommendExpertView.initData(this.data!!)
}
}
override fun getTotalDataNum(): Int {
var count = 0
if (data?.head != null && !TextUtils.isEmpty(data?.head!!.title)) {
count++
} else if (data?.footer != null) {
count++
}
return count+1
}
override fun getItemViewType(position: Int): Int {
if (isHeadType(position)) {
return combineType(IConfideHomeConfig.SECTION_CONSULTANT, this.HEADER)
} else {
return IConfideHomeConfig.SECTION_CONSULTANT
}
}
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): RecyclerView.ViewHolder {
if (viewType == combineType(IConfideHomeConfig.SECTION_CONSULTANT, HEADER)) {
return HeadViewHolder(LayoutInflater.from(context).inflate(R.layout.confidehome_recommend_expert_head, parent, false))
} else {
return ConfideHomeRecommendExpertViewHolder(ConfideHomeRecommendExpertView(context, confideHomeEvent))
}
}
override fun isBelongTo(viewType: Int): Boolean {
return viewType.toString().startsWith(IConfideHomeConfig.SECTION_CONSULTANT.toString())
}
override fun isHeadType(position: Int): Boolean {
if (data?.head==null || TextUtils.isEmpty(data?.head!!.title)) {
return false
} else if (position == 0) {
return true
}
return false
}
override fun isFooterType(position: Int): Boolean {
if (data?.footer == null) {
return false
} else if (position == totalDataNum - 1) {
return true
}
return false
}
inner class HeadViewHolder(var confideHeadView: View) : RecyclerView.ViewHolder(confideHeadView)
inner class ConfideHomeRecommendExpertViewHolder(var confideHomeRecommendExpertView: ConfideHomeRecommendExpertView) : RecyclerView.ViewHolder(confideHomeRecommendExpertView)
}
\ No newline at end of file
package com.ydl.confide.home.section
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.ViewGroup
import com.ydl.confide.home.bean.ConfideHomeDataBean
import com.ydl.confide.home.config.IConfideHomeConfig
import com.ydl.confide.home.contract.IConfideHomeContract
import com.ydl.confide.home.event.IConfideHomeEvent
import com.ydl.confide.home.widget.ConfideHomeRecommendView
import com.ydl.ydlcommon.adapter.section.Section
/**
* @author Jim
* @描述:为你推荐section
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/8/11 0011
*/
class ConfideRecommendSection(var context: Context,var view: IConfideHomeContract.View, var confideHomeEvent: IConfideHomeEvent) : Section<RecyclerView.ViewHolder>(0) {
override fun getSectionId(): Int {
return IConfideHomeConfig.SECTION_RECOMMEND
}
private var data: ConfideHomeDataBean? = null
fun setData(data: ConfideHomeDataBean) {
this.data = data
}
fun addData(data: ConfideHomeDataBean){
if (null == data || null == data.body){
return
}
(this.data!!.body as ArrayList).addAll(data.body)
}
override fun bindViewHolder(holder: RecyclerView.ViewHolder?, position: Int) {
if (holder is RecommendViewHolder) {
holder.confideHomeRecommendView.initData(this.data!!.body!![position],position,data!!.recommendId)
}
}
override fun getTotalDataNum(): Int {
return data!!.body!!.size
}
override fun getItemViewType(position: Int): Int {
return IConfideHomeConfig.SECTION_RECOMMEND
}
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): RecyclerView.ViewHolder {
return RecommendViewHolder(ConfideHomeRecommendView(view,context, confideHomeEvent))
}
override fun isBelongTo(viewType: Int): Boolean {
return viewType.toString().startsWith(IConfideHomeConfig.SECTION_RECOMMEND.toString())
}
override fun isHeadType(position: Int): Boolean {
return false
}
override fun isFooterType(position: Int): Boolean {
return false
}
inner class RecommendViewHolder(var confideHomeRecommendView: ConfideHomeRecommendView) : RecyclerView.ViewHolder(confideHomeRecommendView)
}
\ No newline at end of file
package com.ydl.confide.home.widget
import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import com.yidianling.common.tools.RxImageTool
import com.ydl.confide.R
import com.ydl.confide.home.bean.ConfideHomeBodyBean
import com.ydl.confide.home.bean.ConfideHomeDataBean
import com.ydl.confide.home.event.IConfideHomeEvent
import com.ydl.ydlcommon.view.banner.GlideImageLoader
import kotlinx.android.synthetic.main.confidehome_banner_view.view.*
/**
* @author yuanwai
* @描述:倾诉首页banner
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/8/10
*/
class ConfideHomeBannerView(context: Context,
//
private var confideHomeEvent: IConfideHomeEvent) : FrameLayout(context) {
/**
* banner数据缓存
*/
private var mDataList: List<ConfideHomeBodyBean>? = null
/**
* 数据缓存
*/
private var mDataBean: ConfideHomeDataBean? = null
private var margin = 0
init {
initView()
}
private fun initView() {
val params = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
View.inflate(context, R.layout.confidehome_banner_view, this)
layoutParams = params
margin = RxImageTool.dip2px(2.5f)
}
fun initData(dataBean: ConfideHomeDataBean?) {
if (null == dataBean ||
dataBean.body == null ||
dataBean.body!!.isEmpty()) {
visibility = View.GONE
return
}
mDataBean = dataBean
visibility = View.VISIBLE
if (null == mDataList) {
mDataList = ArrayList()
} else {
(mDataList as ArrayList).clear()
}
(mDataList as ArrayList<ConfideHomeBodyBean>).addAll(mDataBean!!.body!!)
var urlLists = ArrayList<String>()
var count = (mDataList as ArrayList<ConfideHomeBodyBean>).size - 1
for (index in 0..count) {
urlLists.add((mDataList as ArrayList<ConfideHomeBodyBean>)[index].bannerImageUrl!!)
}
banner.setImageLoader(GlideImageLoader(R.color.new_divide_color,6)).setImages(urlLists).start()
banner.setOnBannerListener {
confideHomeEvent!!.bannerClick((mDataList as ArrayList<ConfideHomeBodyBean>)[it].bannerLinkUrl, it, (mDataList as ArrayList<ConfideHomeBodyBean>)[it].bannerTitle)
}
}
}
\ No newline at end of file
package com.ydl.confide.home.widget
import android.content.Context
import android.support.annotation.Nullable
import android.support.v7.widget.CardView
import android.text.TextUtils
import android.util.AttributeSet
import android.view.View
import com.ydl.ydl_image.module.GlideApp
import com.yidianling.common.tools.RxImageTool
import com.ydl.confide.R
import com.ydl.confide.home.bean.ConfideHomeBodyBean
import com.ydl.confide.home.contract.IConfideHomeContract
import com.ydl.confide.home.event.IConfideHomeEvent
import com.ydl.ydlcommon.utils.UMEventUtils
import kotlinx.android.synthetic.main.confidehome_item_category.view.*
/**
* @author yuanwai
* @描述:倾诉首页--分类子View
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/9/21
*/
class ConfideHomeCategoryItemView(mContext: Context, @Nullable attrs: AttributeSet) : CardView(mContext, attrs) {
private var confideHomeEvent: IConfideHomeEvent? = null
private var dp35: Int = 0
init {
initView()
}
private fun initView() {
View.inflate(context, R.layout.confidehome_item_category, this)
dp35 = RxImageTool.dip2px(35f)
}
fun initData(bodyBean: ConfideHomeBodyBean?, confideHomeEvent: IConfideHomeEvent, homeView: IConfideHomeContract.View) {
this.confideHomeEvent = confideHomeEvent
if (null == bodyBean) {
return
}
//这样处理 是防止 滑动过程中 反复去加载图片
if (!TextUtils.isEmpty(bodyBean.categoryIcon) && img_icon.getTag(R.id.img_icon) != bodyBean.categoryIcon) {
GlideApp.with(context)
.load(bodyBean.categoryIcon)
.override(dp35, dp35)
.into(img_icon)
img_icon.setTag(R.id.img_icon, bodyBean.categoryIcon)
}
tv_title.text = bodyBean.categoryName
tv_content.text = bodyBean.categoryContent
setOnClickListener {
//加载H5页面
if (bodyBean.categoryType == 1) {
//加载H5页面,跳转统一路由
confideHomeEvent.categoryClick(bodyBean.linkUrl)
} else if (bodyBean.categoryType == 2) {
//锚点到筛选位置
homeView.moveToFilter()
//埋点
UMEventUtils.umEvent("专业师资点击", "专业师资", "专业师资")
}
}
}
}
\ No newline at end of file
package com.ydl.confide.home.widget
import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.yidianling.common.tools.RxImageTool
import com.ydl.confide.R
import com.ydl.confide.home.bean.ConfideHomeBodyBean
import com.ydl.confide.home.bean.ConfideHomeDataBean
import com.ydl.confide.home.contract.IConfideHomeContract
import com.ydl.confide.home.event.IConfideHomeEvent
import kotlinx.android.synthetic.main.confidehome_category_view.view.*
/**
* @author yuanwai
* @描述:倾诉首页--分类View
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/9/21
*/
class ConfideHomeCategoryView(mContext: Context,
//倾诉首页事件类
private var confideHomeEvent: IConfideHomeEvent,
//倾诉首页View接口
private var homeView : IConfideHomeContract.View) : LinearLayout(mContext) {
init {
initView()
}
private fun initView(){
var params = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,RxImageTool.dip2px(106f))
View.inflate(context, R.layout.confidehome_category_view,this)
layoutParams = params
orientation = HORIZONTAL
setBackgroundResource(R.color.confidehome_category_bg)
}
fun initData(bean: ConfideHomeDataBean?){
if (null == bean || null == bean.body || bean.body.isEmpty()){
visibility = View.GONE
return
}
visibility = View.VISIBLE
initItem1Data(bean.body[0])
if (bean.body.size > 1){
initItem2Data(bean.body[1])
}
}
private fun initItem1Data(bodyBean: ConfideHomeBodyBean?){
v_item1.initData(bodyBean,confideHomeEvent,homeView)
}
private fun initItem2Data(bodyBean: ConfideHomeBodyBean?){
v_item2.initData(bodyBean,confideHomeEvent,homeView)
}
}
\ 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