Commit 7ede3300 by 刘鹏

Merge branch 'fix/lp/lp_fix_trends' into 'd/v4.4.05'

feat: 我的动态列表 KotlinNullPointerException  问题修复

See merge request app_android_lib/YDL-Component!274
parents 448abcc2 be768178
......@@ -8,16 +8,16 @@ import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import androidx.interpolator.view.animation.FastOutLinearInInterpolator
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.interpolator.view.animation.FastOutLinearInInterpolator
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.ydl.webview.H5Params
import com.ydl.webview.NewH5Activity
import com.ydl.ydlcommon.utils.BuryPointUtils
......@@ -25,8 +25,8 @@ import com.ydl.ydlcommon.utils.SharedPreferencesEditor
import com.ydl.ydlcommon.view.WrapContentLinearLayoutManager
import com.yidianling.common.tools.LogUtil
import com.yidianling.common.tools.ToastUtil
import com.yidianling.dynamic.bean.DynamicConstants
import com.yidianling.dynamic.R
import com.yidianling.dynamic.bean.DynamicConstants
import com.yidianling.dynamic.common.net.DynamicApiUtils
import com.yidianling.dynamic.model.*
import com.yidianling.dynamic.publishTrend.PublishTrendActivity
......@@ -35,15 +35,12 @@ import com.yidianling.dynamic.topic.AllTopicActivity
import com.yidianling.dynamic.trendList.adapter.RecommendTopAdapter
import com.yidianling.dynamic.trendList.adapter.RecommendTopicListAdapter
import com.yidianling.dynamic.trendList.adapter.TrendsListAdapter
import com.yidianling.dynamic.trendList.adapter.TrendsListAdapter.FOOTER_STATE_NO_DATA
import com.yidianling.dynamic.trendList.adapter.TrendsListAdapter.FOOTRE_STATE_LOAD_MORE
import com.yidianling.dynamic.trendList.adapter.TrendsListAdapter.FOOTRE_STATE_INIT
import com.yidianling.dynamic.trendList.adapter.TrendsListAdapter.*
import com.yidianling.dynamic.trendsDetail.TrendsDetailActivity
import com.yidianling.dynamic.trendsHome.TrendsHomeFragment
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.dynamic_fragment_trends_list.*
import java.util.*
/**
......@@ -113,9 +110,9 @@ class TrendsListFragment : BaseLazyFragment(), ITrendsListView,
LinearLayoutManager(activity)
mRecommendTopAdapter = RecommendTopAdapter<TrendsListBean.ExtData>(activity)
mRecommendTopRcv = view.findViewById<View>(R.id.recy_top) as RecyclerView
mRecommendTopRcv!!.layoutManager = linearLayoutManager
mRecommendTopRcv!!.adapter = mRecommendTopAdapter
mRecommendTopRcv!!.visibility = View.GONE
mRecommendTopRcv?.layoutManager = linearLayoutManager
mRecommendTopRcv?.adapter = mRecommendTopAdapter
mRecommendTopRcv?.visibility = View.GONE
return view
}
......@@ -123,7 +120,7 @@ class TrendsListFragment : BaseLazyFragment(), ITrendsListView,
get() {
if (tab == 1 && trendType == TREND_TYPE_DEFAULT) {
headers = arrayOf(headerView, recommendTopHeaderView)
return headers!!.size
return headers?.size?:0
}
return 0
}
......@@ -151,15 +148,18 @@ class TrendsListFragment : BaseLazyFragment(), ITrendsListView,
private val lastId: Int
get() {
var id: String? = "0"
if (trendsDatas != null && trendsDatas!!.size > 0) {
LogUtil.i("TAG get last content: " + trendsDatas!![trendsDatas!!.size - 1].toString())
id = trendsDatas!![trendsDatas!!.size - 1].id
return if (id == null || id == "") {
0
} else {
Integer.valueOf(id)
trendsDatas?.let { trendsDatas ->
if (trendsDatas.size > 0) {
LogUtil.i("TAG get last content: " + trendsDatas[trendsDatas.size].toString())
id = trendsDatas[trendsDatas.size - 1].id
return if (id == null || id == "") {
0
} else {
Integer.valueOf(id)
}
}
}
return 0
}
......@@ -194,12 +194,12 @@ class TrendsListFragment : BaseLazyFragment(), ITrendsListView,
private fun initViews() {
if (trendType == TREND_TYPE_USER_TREND || trendType == TREND_TYPE_TOPIC_TREND) {
trends_lastr_swl!!.isEnabled = false
trends_rcv!!.isNestedScrollingEnabled = false
trends_lastr_swl?.isEnabled = false
trends_rcv?.isNestedScrollingEnabled = false
} else {
trends_lastr_swl!!.setViewGroup(trends_rcv)
trends_lastr_swl!!.setOnRefreshListener(this)
trends_lastr_swl!!.setColorSchemeResources(R.color.platform_main_theme)
trends_lastr_swl?.setViewGroup(trends_rcv)
trends_lastr_swl?.setOnRefreshListener(this)
trends_lastr_swl?.setColorSchemeResources(R.color.platform_main_theme)
}
initRecyclerView()
}
......@@ -225,7 +225,7 @@ class TrendsListFragment : BaseLazyFragment(), ITrendsListView,
private fun initRecyclerView() {
trendsDatas = ArrayList<TrendsListBean.Trend>()
mRcvAdapter = TrendsListAdapter(activity, trendsDatas)
mRcvAdapter!!.setOnItemClickListener(object : TrendsListAdapter.OnItemClickListener {
mRcvAdapter?.setOnItemClickListener(object : TrendsListAdapter.OnItemClickListener {
override fun onItemLikeClick(
view: View,
position: Int,
......@@ -235,11 +235,11 @@ class TrendsListFragment : BaseLazyFragment(), ITrendsListView,
}
override fun onItemClick(id: Int, commentCount: Int, position: Int) {
val trend = trendsDatas!![position - mRcvAdapter!!.headersCount]
if (trend.isAd == 1) {
val trend = trendsDatas?.get(position - (mRcvAdapter?.headersCount?:0))
if (trend?.isAd == 1) {
//广告跳转H5
NewH5Activity.start(context, H5Params(trend.url, null, trend.share))
DynamicApiUtils.adClickCount(Command.AdClickCount(trend.focId))
NewH5Activity.start(context, H5Params(trend?.url, null, trend?.share))
DynamicApiUtils.adClickCount(Command.AdClickCount(trend?.focId))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ objectBaseResponse ->
......@@ -250,9 +250,9 @@ class TrendsListFragment : BaseLazyFragment(), ITrendsListView,
return
}
BuryPointUtils.getInstance().createMap()
.put("dynamic_ID", trend.id)
.put("dynamic_name", trend.title)
.put("dynamic_type", trend.topicTitle)
.put("dynamic_ID", trend?.id)
.put("dynamic_name", trend?.title)
.put("dynamic_type", trend?.topicTitle)
.burryPoint("Dynamic_click")
TrendsDetailActivity.startForResult(
this@TrendsListFragment,
......@@ -266,11 +266,11 @@ class TrendsListFragment : BaseLazyFragment(), ITrendsListView,
override fun onItemCommentClick(id: Int, commentCount: Int, position: Int) {
BuryPointUtils.getInstance().createMap()
.put("dynamic_name", trendsDatas!![position - mRcvAdapter!!.headersCount].title)
.put("dynamic_ID", trendsDatas!![position - mRcvAdapter!!.headersCount].id)
.put("dynamic_name", trendsDatas?.get(position - (mRcvAdapter?.headersCount ?: 0))?.title)
.put("dynamic_ID", trendsDatas?.get(position - (mRcvAdapter?.headersCount ?: 0))?.id)
.put(
"dynamic_type",
trendsDatas!![position - mRcvAdapter!!.headersCount].topicTitle
trendsDatas?.get(position - (mRcvAdapter?.headersCount ?: 0))?.topicTitle
)
.burryPoint("Comment_dynamic")
TrendsDetailActivity.startForResult(
......@@ -286,9 +286,9 @@ class TrendsListFragment : BaseLazyFragment(), ITrendsListView,
val layoutManager =
WrapContentLinearLayoutManager(activity, WrapContentLinearLayoutManager.VERTICAL, false)
// LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
trends_rcv!!.adapter = mRcvAdapter
trends_rcv!!.layoutManager = layoutManager
trends_rcv!!.itemAnimator?.changeDuration = 0 //解决局部刷新闪屏
trends_rcv?.adapter = mRcvAdapter
trends_rcv?.layoutManager = layoutManager
trends_rcv?.itemAnimator?.changeDuration = 0 //解决局部刷新闪屏
mScrollListener = object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
......@@ -313,22 +313,22 @@ class TrendsListFragment : BaseLazyFragment(), ITrendsListView,
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
try {
if (!recyclerView!!.canScrollVertically(-1)) {
if (!recyclerView?.canScrollVertically(-1)) {
//滑到顶部,隐藏按钮
image_scroll_top!!.animate().cancel()
image_scroll_top!!.animate()
.scaleX(0f)
.scaleY(0f)
.alpha(0f)
.setDuration(200)
.setInterpolator(FastOutLinearInInterpolator())
.setListener(object : AnimatorListenerAdapter() {
image_scroll_top?.animate()?.cancel()
image_scroll_top?.animate()
?.scaleX(0f)
?.scaleY(0f)
?.alpha(0f)
?.setDuration(200)
?.setInterpolator(FastOutLinearInInterpolator())
?.setListener(object : AnimatorListenerAdapter() {
private var mCancelled: Boolean = false
@SuppressLint("RestrictedApi")
override fun onAnimationStart(animation: Animator) {
if (image_scroll_top != null) {
image_scroll_top!!.visibility = View.VISIBLE
image_scroll_top?.visibility = View.VISIBLE
}
mCancelled = false
}
......@@ -340,7 +340,7 @@ class TrendsListFragment : BaseLazyFragment(), ITrendsListView,
@SuppressLint("RestrictedApi")
override fun onAnimationEnd(animation: Animator) {
if (!mCancelled && image_scroll_top != null) {
image_scroll_top!!.visibility = View.INVISIBLE
image_scroll_top?.visibility = View.INVISIBLE
}
}
})
......@@ -360,21 +360,23 @@ class TrendsListFragment : BaseLazyFragment(), ITrendsListView,
}
}
trends_rcv!!.addOnScrollListener(mScrollListener!!)
mRcvAdapter!!.addFooterView(footerView)
mScrollListener?.let { listener ->
trends_rcv?.addOnScrollListener(listener)
}
mRcvAdapter?.addFooterView(footerView)
if (headerCount > 0) {
for (i in headers!!.indices) {
mRcvAdapter!!.addHeaderView(headers!![i])
for (i in headers?.indices!!) {
mRcvAdapter?.addHeaderView(headers?.get(i))
}
}
}
private fun doLikeAction(view: View, position: Int, mDatas: List<TrendsListBean.Trend>) {
if (DynamicIn.loginByOneKeyLogin(mActivity!!,true)) {
if (mActivity?.let { DynamicIn.loginByOneKeyLogin(it,true) } == true) {
if (!isDoLikeAction) {
isDoLikeAction = true
mPresenter!!.doLikeAction(
mPresenter?.doLikeAction(
view,
position,
Integer.valueOf(mDatas[position].id),
......@@ -388,21 +390,21 @@ class TrendsListFragment : BaseLazyFragment(), ITrendsListView,
LogUtil.i("TAG get param: tab: $tab page: $page topicId: $topic_id lastId: $last_id")
if (!isTrendsListLoading) {
isTrendsListLoading = true
mPresenter!!.fetchUserTrendsList(userid, page, tab)
mPresenter?.fetchUserTrendsList(userid, page, tab)
}
}
private fun fetchTrendsList() {
if (!isTrendsListLoading) {
isTrendsListLoading = true
mPresenter!!.fetchPhpTrendsInfo(tab, page, topic_id, last_id)
mPresenter?.fetchPhpTrendsInfo(tab, page, topic_id, last_id)
}
}
private fun fetchRecommendTopicList() {
if (tab == 1 && !isTopicLoading && trendType == TREND_TYPE_DEFAULT) {
isTopicLoading = true
mPresenter!!.fetchTopicListInfo(2, 0)
mPresenter?.fetchTopicListInfo(2, 0)
}
}
......@@ -426,17 +428,17 @@ class TrendsListFragment : BaseLazyFragment(), ITrendsListView,
}
private fun showLoadSuccessView() {
if (trend_list_no_datas_rel!!.visibility != View.GONE) {
trend_list_no_datas_rel!!.visibility = View.GONE
if (trend_list_no_datas_rel?.visibility != View.GONE) {
trend_list_no_datas_rel?.visibility = View.GONE
}
}
private fun showErrorView() {
if (page == 1) {
trend_list_no_datas_rel!!.visibility = View.VISIBLE
trend_list_no_datas_rel?.visibility = View.VISIBLE
} else {
trend_list_no_datas_rel!!.visibility = View.GONE
trend_list_no_datas_rel?.visibility = View.GONE
}
}
......@@ -446,7 +448,7 @@ class TrendsListFragment : BaseLazyFragment(), ITrendsListView,
Handler().postDelayed({
page = 1
last_id = 0
trends_lastr_swl!!.isRefreshing = true
trends_lastr_swl?.isRefreshing = true
switchDataToFetch()
}, 200)
}
......@@ -486,10 +488,10 @@ class TrendsListFragment : BaseLazyFragment(), ITrendsListView,
fun scrollToTop() {
if (firstVisibleItem > 10) {
trends_rcv!!.scrollToPosition(10)
trends_rcv!!.smoothScrollToPosition(0)
trends_rcv?.scrollToPosition(10)
trends_rcv?.smoothScrollToPosition(0)
} else {
trends_rcv!!.smoothScrollToPosition(0)
trends_rcv?.smoothScrollToPosition(0)
}
}
......@@ -497,10 +499,10 @@ class TrendsListFragment : BaseLazyFragment(), ITrendsListView,
super.onDestroyView()
LogUtil.d("fragmentlist onDestroy() $tab")
if (mPresenter != null) {
mPresenter!!.onDestroy()
mPresenter?.onDestroy()
}
if (image_scroll_top != null) {
image_scroll_top!!.animate().cancel()
image_scroll_top?.animate()?.cancel()
}
}
......@@ -528,21 +530,21 @@ class TrendsListFragment : BaseLazyFragment(), ITrendsListView,
if (str.size == 3) if (!TextUtils.isEmpty(str[2])) str[2] else "" else ""
comments.add(comment)
}
mRcvAdapter!!.datas[position - headerCount].comments = comments
mRcvAdapter!!.datas[position - headerCount].commentsCount = commentCount
mRcvAdapter!!.notifyItemChanged(position)
mRcvAdapter?.datas?.get(position - headerCount)?.comments = comments
mRcvAdapter?.datas?.get(position - headerCount)?.commentsCount = commentCount
mRcvAdapter?.notifyItemChanged(position)
} else {
mRcvAdapter!!.datas[position - headerCount].comments.clear()
mRcvAdapter!!.datas[position - headerCount].commentsCount = commentCount
mRcvAdapter!!.notifyItemChanged(position)
mRcvAdapter?.datas?.get(position - headerCount)?.comments?.clear()
mRcvAdapter?.datas?.get(position - headerCount)?.commentsCount = commentCount
mRcvAdapter?.notifyItemChanged(position)
}
}
LogUtil.d("resultcode: $resultCode position: $position likestate: $likestate")
if (likestate != 0) {
mRcvAdapter!!.datas[position - headerCount].zanCount =
mRcvAdapter!!.datas[position - headerCount].zanCount + (mRcvAdapter!!.datas[position - headerCount].isZan - likestate)
mRcvAdapter!!.datas[position - headerCount].isZan = likestate
mRcvAdapter!!.notifyItemChanged(position)
mRcvAdapter?.datas?.get(position - headerCount)?.zanCount =
mRcvAdapter?.datas?.get(position - headerCount)?.zanCount?:0 + (mRcvAdapter?.datas?.get(position - headerCount)?.isZan?:0 - likestate)
mRcvAdapter?.datas?.get(position - headerCount)?.isZan = likestate
mRcvAdapter?.notifyItemChanged(position)
}
}
}
......@@ -554,8 +556,8 @@ class TrendsListFragment : BaseLazyFragment(), ITrendsListView,
override fun hideLoadingView() {}
override fun hideRefreshProgress() {
if (trends_lastr_swl!!.isRefreshing && !isTopicLoading) {
trends_lastr_swl!!.isRefreshing = false
if (trends_lastr_swl?.isRefreshing == true && !isTopicLoading) {
trends_lastr_swl?.isRefreshing = false
}
}
......@@ -569,39 +571,39 @@ class TrendsListFragment : BaseLazyFragment(), ITrendsListView,
return
}
if (page == 1) {
trendsDatas!!.clear()
trendsDatas?.clear()
}
LogUtil.i("get datas $data")
showLoadSuccessView()
if (data.size >= eachPageDataNum) {
trendsDatas!!.addAll(data)
mRcvAdapter!!.setDatas(trendsDatas, FOOTRE_STATE_LOAD_MORE)
trendsDatas?.addAll(data)
mRcvAdapter?.setDatas(trendsDatas, FOOTRE_STATE_LOAD_MORE)
if (page == 1) {
mRcvAdapter!!.notifyDataSetChanged()
mRcvAdapter?.notifyDataSetChanged()
return
}
mRcvAdapter!!.notifyItemRangeInserted(
trendsDatas!!.size + headerCount - data.size,
mRcvAdapter?.notifyItemRangeInserted(
trendsDatas?.size?:0 + headerCount - data.size,
data.size
)
} else {
LogUtil.i("get datas no more data$data")
trendsDatas!!.addAll(data)
if (trendsDatas == null || trendsDatas!!.size == 0) {
mRcvAdapter!!.setDatas(trendsDatas, FOOTRE_STATE_INIT)
trendsDatas?.addAll(data)
if (trendsDatas == null || trendsDatas?.size == 0) {
mRcvAdapter?.setDatas(trendsDatas, FOOTRE_STATE_INIT)
if (page == 1) {
mRcvAdapter!!.notifyDataSetChanged()
mRcvAdapter?.notifyDataSetChanged()
}
trend_list_no_datas_rel!!.visibility = View.VISIBLE
trend_list_no_datas_rel?.visibility = View.VISIBLE
return
}
mRcvAdapter!!.setDatas(trendsDatas, FOOTER_STATE_NO_DATA)
mRcvAdapter?.setDatas(trendsDatas, FOOTER_STATE_NO_DATA)
if (page == 1) {
mRcvAdapter!!.notifyDataSetChanged()
mRcvAdapter?.notifyDataSetChanged()
return
}
mRcvAdapter!!.notifyItemRangeInserted(
trendsDatas!!.size + headerCount - data.size,
mRcvAdapter?.notifyItemRangeInserted(
trendsDatas?.size?:0 + headerCount - data.size,
data.size
)
}
......@@ -617,8 +619,8 @@ class TrendsListFragment : BaseLazyFragment(), ITrendsListView,
isTopicLoading = false
if (topicListDatas.list != null && topicListDatas.list.size > 0) {
recommendTopicDatas = topicListDatas.list
mRecommendTopicListAdapter!!.setDatas(recommendTopicDatas)
mRecommendTopicListAdapter!!.notifyDataSetChanged()
mRecommendTopicListAdapter?.setDatas(recommendTopicDatas)
mRecommendTopicListAdapter?.notifyDataSetChanged()
}
}
......@@ -672,9 +674,9 @@ class TrendsListFragment : BaseLazyFragment(), ITrendsListView,
override fun showTopTrendsView(extDatas: List<TrendsListBean.ExtData>?) {
if (extDatas != null && extDatas.size > 0) { //置顶信息
mRecommendTopRcv!!.visibility = View.VISIBLE
mRecommendTopAdapter!!.setExtData(extDatas)
mRecommendTopAdapter!!.notifyDataSetChanged()
mRecommendTopRcv?.visibility = View.VISIBLE
mRecommendTopAdapter?.setExtData(extDatas)
mRecommendTopAdapter?.notifyDataSetChanged()
}
}
......
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