fix: 修复一堆可能导致闪退的问题
This commit is contained in:
parent
a36a8315cb
commit
31202c9dc4
|
|
@ -6,6 +6,7 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.content.res.ColorStateList
|
||||
import android.os.Build
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.ColorRes
|
||||
|
|
@ -87,3 +88,7 @@ fun ViewGroup.enableChangingLayoutTransition() {
|
|||
this.layoutTransition = LayoutTransition()
|
||||
this.layoutTransition.enableTransitionType(LayoutTransition.CHANGING)
|
||||
}
|
||||
|
||||
fun View.getLocationInWindow(): IntArray {
|
||||
return IntArray(2).apply { getLocationInWindow(this) }
|
||||
}
|
||||
|
|
@ -158,6 +158,9 @@ class FloorActivity : BaseActivity() {
|
|||
}
|
||||
|
||||
private fun refresh() {
|
||||
if (tid == null) {
|
||||
return
|
||||
}
|
||||
refreshLayout.isRefreshing = true
|
||||
TiebaApi.getInstance()
|
||||
.floor(tid!!, pn, pid, spid)
|
||||
|
|
|
|||
|
|
@ -171,9 +171,6 @@ public class ReplyActivity extends BaseActivity implements View.OnClickListener
|
|||
.findFirst(Draft.class);
|
||||
if (draft != null) {
|
||||
content = draft.getContent();
|
||||
if (!TextUtils.isEmpty(content)) {
|
||||
sendItem.setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -399,10 +396,10 @@ public class ReplyActivity extends BaseActivity implements View.OnClickListener
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
public boolean onCreateOptionsMenu(@NotNull Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_reply_toolbar, menu);
|
||||
sendItem = menu.findItem(R.id.menu_send);
|
||||
sendItem.setEnabled(false);
|
||||
sendItem.setEnabled(!TextUtils.isEmpty(content));
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -92,6 +92,10 @@ class SearchPostActivity : BaseActivity() {
|
|||
}
|
||||
|
||||
fun refresh() {
|
||||
if (keyword == null || keyword == null) {
|
||||
refreshLayout.finishRefresh(false)
|
||||
return
|
||||
}
|
||||
page = 1
|
||||
getInstance().searchPost(keyword!!, forumName!!, false, page, 30).enqueue(object : Callback<SearchPostBean> {
|
||||
override fun onResponse(call: Call<SearchPostBean>, response: Response<SearchPostBean>) {
|
||||
|
|
@ -108,6 +112,10 @@ class SearchPostActivity : BaseActivity() {
|
|||
}
|
||||
|
||||
private fun loadMore() {
|
||||
if (keyword == null || keyword == null) {
|
||||
refreshLayout.finishLoadMore(false)
|
||||
return
|
||||
}
|
||||
getInstance().searchPost(keyword!!, forumName!!, false, page + 1, 30).enqueue(object : Callback<SearchPostBean> {
|
||||
override fun onResponse(call: Call<SearchPostBean>, response: Response<SearchPostBean>) {
|
||||
val data = response.body()
|
||||
|
|
|
|||
|
|
@ -554,12 +554,17 @@ class ThreadActivity : BaseActivity(), View.OnClickListener, IThreadMenuFragment
|
|||
get() {
|
||||
if (dataBean == null) return null
|
||||
val position = firstVisibleItemPosition
|
||||
return if (position < 0) {
|
||||
null
|
||||
} else if (position == 0) {
|
||||
threadMainPostAdapter.threadPostBean ?: replyAdapter.getItem(position)
|
||||
} else {
|
||||
replyAdapter.getItem(position - 1)
|
||||
return when {
|
||||
position < 0 -> {
|
||||
null
|
||||
}
|
||||
position == 0 -> {
|
||||
threadMainPostAdapter.threadPostBean ?: replyAdapter.getItem(position)
|
||||
}
|
||||
replyAdapter.itemCount > 0 -> {
|
||||
replyAdapter.getItem(position - 1)
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -567,12 +572,17 @@ class ThreadActivity : BaseActivity(), View.OnClickListener, IThreadMenuFragment
|
|||
get() {
|
||||
if (dataBean == null) return null
|
||||
val position = getItemPositionByAdapterPosition(virtualLayoutManager.findLastVisibleItemPosition())
|
||||
return if (position < 0) {
|
||||
null
|
||||
} else if (position == 0) {
|
||||
threadMainPostAdapter.threadPostBean ?: replyAdapter.getItem(position)
|
||||
} else {
|
||||
replyAdapter.getItem(position - 1)
|
||||
return when {
|
||||
position < 0 -> {
|
||||
null
|
||||
}
|
||||
position == 0 -> {
|
||||
threadMainPostAdapter.threadPostBean ?: replyAdapter.getItem(position)
|
||||
}
|
||||
replyAdapter.itemCount > 0 -> {
|
||||
replyAdapter.getItem(position - 1)
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -191,6 +191,9 @@ class UserActivity : BaseActivity() {
|
|||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.menu_block_black, R.id.menu_block_white -> {
|
||||
if (profileBean == null || profileBean!!.user == null) {
|
||||
return true
|
||||
}
|
||||
val category = if (item.itemId == R.id.menu_block_black) Block.CATEGORY_BLACK_LIST else Block.CATEGORY_WHITE_LIST
|
||||
Block()
|
||||
.setUid(profileBean!!.user!!.id)
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ class MessageListAdapter(
|
|||
}
|
||||
)
|
||||
textView.setOnClickListener {
|
||||
if ("1" == item.isFloor) {
|
||||
if ("1" == item.isFloor && item.quotePid != null) {
|
||||
FloorActivity.launch(context, item.threadId!!, postId = item.quotePid)
|
||||
} else {
|
||||
ThreadActivity.launch(context, item.threadId!!)
|
||||
|
|
|
|||
|
|
@ -44,10 +44,10 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
|
|||
lateinit var mRecyclerView: RecyclerView
|
||||
|
||||
@BindView(R.id.refresh)
|
||||
lateinit var mRefreshLayout: SmartRefreshLayout
|
||||
private var mRefreshLayout: SmartRefreshLayout? = null
|
||||
|
||||
private lateinit var delegateAdapter: DelegateAdapter
|
||||
private lateinit var virtualLayoutManager: VirtualLayoutManager
|
||||
private val virtualLayoutManager: VirtualLayoutManager by lazy { VirtualLayoutManager(attachContext) }
|
||||
private val delegateAdapter: DelegateAdapter by lazy { DelegateAdapter(virtualLayoutManager) }
|
||||
private lateinit var forumAdapter: NewForumAdapter
|
||||
private lateinit var forumTopsLayoutAdapter: ForumTopsLayoutAdapter
|
||||
private lateinit var goodClassifyLayoutAdapter: GoodClassifyLayoutAdapter
|
||||
|
|
@ -56,13 +56,13 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
|
|||
if (preload) {
|
||||
PreLoader.listenData<ForumPageBean>(preloadId, DataHolder())
|
||||
} else if (mDataBean == null) {
|
||||
mRefreshLayout.autoRefresh()
|
||||
mRefreshLayout?.autoRefresh()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFragmentVisibleChange(isVisible: Boolean) {
|
||||
if (isVisible && mDataBean == null) {
|
||||
mRefreshLayout.autoRefresh()
|
||||
mRefreshLayout?.autoRefresh()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -108,8 +108,6 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
|
|||
if (isGood) {
|
||||
classifyId = DEFAULT_CLASSIFY_ID
|
||||
}
|
||||
virtualLayoutManager = VirtualLayoutManager(attachContext)
|
||||
delegateAdapter = DelegateAdapter(virtualLayoutManager)
|
||||
forumAdapter = NewForumAdapter(attachContext).apply {
|
||||
setHasStableIds(true)
|
||||
}
|
||||
|
|
@ -143,8 +141,8 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
|
|||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
mRefreshLayout.setOnRefreshListener { refresh() }
|
||||
mRefreshLayout.setOnLoadMoreListener { loadMore() }
|
||||
mRefreshLayout!!.setOnRefreshListener { refresh() }
|
||||
mRefreshLayout!!.setOnLoadMoreListener { loadMore() }
|
||||
mRecyclerView.apply {
|
||||
layoutManager = virtualLayoutManager
|
||||
adapter = delegateAdapter
|
||||
|
|
@ -172,23 +170,23 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
|
|||
private fun loadMore() {
|
||||
TiebaApi.getInstance().forumPage(forumName!!, page + 1, sortType, classifyId).enqueue(object : Callback<ForumPageBean> {
|
||||
override fun onFailure(call: Call<ForumPageBean>, t: Throwable) {
|
||||
mRefreshLayout.finishLoadMore(false)
|
||||
mRefreshLayout?.finishLoadMore(false)
|
||||
}
|
||||
|
||||
override fun onResponse(call: Call<ForumPageBean>, response: Response<ForumPageBean>) {
|
||||
page += 1
|
||||
val forumPageBean = response.body()!!
|
||||
mRefreshLayout.finishLoadMore()
|
||||
mRefreshLayout?.finishLoadMore()
|
||||
mDataBean = forumPageBean
|
||||
pageSize = forumPageBean.page?.pageSize?.toInt()!!
|
||||
forumAdapter.addData(forumPageBean)
|
||||
mRefreshLayout.setNoMoreData(mDataBean!!.page?.hasMore == "0")
|
||||
mRefreshLayout?.setNoMoreData(mDataBean!!.page?.hasMore == "0")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun refresh() {
|
||||
mRecyclerView.scrollToPosition(0)
|
||||
scrollToTop()
|
||||
delegateAdapter.clear()
|
||||
delegateAdapter.notifyDataSetChanged()
|
||||
page = 1
|
||||
|
|
@ -203,10 +201,10 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
|
|||
(attachContext as OnRefreshedListener).onFailure(errorCode, t.message)
|
||||
}
|
||||
}
|
||||
mRefreshLayout.finishRefresh(false)
|
||||
mRefreshLayout?.finishRefresh(false)
|
||||
if (errorCode == -1) {
|
||||
Util.showNetworkErrorSnackbar(mRecyclerView) {
|
||||
mRefreshLayout.autoRefresh()
|
||||
mRefreshLayout?.autoRefresh()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -220,29 +218,29 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
|
|||
(attachContext as OnRefreshedListener).onSuccess(forumPageBean)
|
||||
}
|
||||
}
|
||||
mRefreshLayout.finishRefresh()
|
||||
mRefreshLayout?.finishRefresh()
|
||||
mDataBean = forumPageBean
|
||||
pageSize = forumPageBean.page?.pageSize?.toInt()!!
|
||||
forumAdapter.setData(forumPageBean)
|
||||
mRefreshLayout.setNoMoreData(mDataBean!!.page?.hasMore == "0")
|
||||
mRefreshLayout?.setNoMoreData(mDataBean!!.page?.hasMore == "0")
|
||||
reloadAdapters()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun onRefresh() {
|
||||
mRefreshLayout.autoRefresh()
|
||||
mRefreshLayout?.autoRefresh()
|
||||
}
|
||||
|
||||
override fun onSwitch(which: Int) {
|
||||
if (isGood && mDataBean != null) {
|
||||
classifyId = mDataBean!!.forum?.goodClassify?.get(which)?.classId!!
|
||||
mRefreshLayout.autoRefresh()
|
||||
mRefreshLayout?.autoRefresh()
|
||||
}
|
||||
}
|
||||
|
||||
override fun scrollToTop() {
|
||||
mRecyclerView.layoutManager!!.scrollToPosition(0)
|
||||
virtualLayoutManager.scrollToPosition(0)
|
||||
}
|
||||
|
||||
interface OnRefreshedListener {
|
||||
|
|
@ -253,7 +251,7 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
|
|||
internal inner class DataHolder : DataListener<ForumPageBean?> {
|
||||
override fun onDataArrived(forumPageBean: ForumPageBean?) {
|
||||
if (forumPageBean == null) {
|
||||
mRefreshLayout.autoRefresh()
|
||||
mRefreshLayout?.autoRefresh()
|
||||
return
|
||||
}
|
||||
if (!isGood) {
|
||||
|
|
@ -261,11 +259,11 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
|
|||
(attachContext as OnRefreshedListener).onSuccess(forumPageBean)
|
||||
}
|
||||
}
|
||||
mRefreshLayout.finishRefresh()
|
||||
mRefreshLayout?.finishRefresh()
|
||||
mDataBean = forumPageBean
|
||||
pageSize = forumPageBean.page?.pageSize?.toInt()!!
|
||||
forumAdapter.setData(forumPageBean)
|
||||
mRefreshLayout.setNoMoreData(mDataBean!!.page?.hasMore == "0")
|
||||
mRefreshLayout?.setNoMoreData(mDataBean!!.page?.hasMore == "0")
|
||||
reloadAdapters()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,23 +172,19 @@ class MessageFragment : BaseFragment(), Refreshable, OnTabSelectedListener, Tool
|
|||
val messageListBeanCallback: Callback<MessageListBean> = object : Callback<MessageListBean> {
|
||||
override fun onResponse(call: Call<MessageListBean?>, response: Response<MessageListBean?>) {
|
||||
dataBean = response.body()
|
||||
if (dataBean == null) {
|
||||
return
|
||||
}
|
||||
if (reload) {
|
||||
adapter.reset()
|
||||
dataBean?.let { adapter.setData(it) }
|
||||
recyclerView.scrollToPosition(0)
|
||||
} else {
|
||||
dataBean?.let { adapter.addData(it) }
|
||||
}
|
||||
if (reload) {
|
||||
mSmartRefreshLayout.finishRefresh(true)
|
||||
if (dataBean!!.page!!.hasMore != "1") {
|
||||
mSmartRefreshLayout.finishRefreshWithNoMoreData()
|
||||
}
|
||||
recyclerView.scrollToPosition(0)
|
||||
} else {
|
||||
mSmartRefreshLayout.finishLoadMore(true)
|
||||
if (dataBean!!.page!!.hasMore != "1") {
|
||||
mSmartRefreshLayout.finishLoadMoreWithNoMoreData()
|
||||
}
|
||||
mSmartRefreshLayout.finishRefresh(true)
|
||||
if (dataBean?.page?.hasMore != "1") {
|
||||
mSmartRefreshLayout.finishRefreshWithNoMoreData()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -159,14 +159,23 @@ class MyInfoFragment : BaseFragment(), View.OnClickListener, CompoundButton.OnCh
|
|||
}
|
||||
view.findViewById<ViewGroup>(R.id.my_info_user).enableChangingLayoutTransition()
|
||||
(followsTextView.parent as View).setOnClickListener {
|
||||
if (dataBean == null || dataBean!!.data == null) {
|
||||
return@setOnClickListener
|
||||
}
|
||||
WebViewActivity.launch(attachContext, attachContext.resources.getString(R.string.url_user_home, dataBean!!.data.getName(), 2))
|
||||
}
|
||||
(fansTextView.parent as View).setOnClickListener {
|
||||
if (dataBean == null || dataBean!!.data == null) {
|
||||
return@setOnClickListener
|
||||
}
|
||||
WebViewActivity.launch(attachContext, attachContext.resources.getString(R.string.url_user_home, dataBean!!.data.getName(), 3))
|
||||
}
|
||||
(threadsTextView.parent as View).setOnClickListener {
|
||||
if (dataBean == null || dataBean!!.data == null) {
|
||||
return@setOnClickListener
|
||||
}
|
||||
goToActivity<UserActivity> {
|
||||
putExtra(UserActivity.EXTRA_UID, dataBean!!.data.getUid().toString())
|
||||
putExtra(UserActivity.EXTRA_UID, "${dataBean!!.data.getUid()}")
|
||||
putExtra(UserActivity.EXTRA_TAB, UserActivity.TAB_THREAD)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import com.huanchengfly.tieba.post.api.SearchThreadOrder
|
|||
import com.huanchengfly.tieba.post.api.TiebaApi
|
||||
import com.huanchengfly.tieba.post.api.models.SearchThreadBean
|
||||
import com.huanchengfly.tieba.post.dpToPx
|
||||
import com.huanchengfly.tieba.post.getLocationInWindow
|
||||
import com.huanchengfly.tieba.post.interfaces.ISearchFragment
|
||||
import com.huanchengfly.tieba.post.utils.ThemeUtil
|
||||
import com.scwang.smart.refresh.layout.SmartRefreshLayout
|
||||
|
|
@ -196,9 +197,7 @@ class SearchThreadFragment : BaseFragment(), ISearchFragment, NewSearchActivity.
|
|||
}
|
||||
|
||||
override fun openFilter(context: Context, view: View, onClose: () -> Unit) {
|
||||
val tabLocationArray = IntArray(2).apply {
|
||||
view.getLocationInWindow(this)
|
||||
}
|
||||
val tabLocationArray = view.getLocationInWindow()
|
||||
FilterPopupWindow(context, order, filter).apply {
|
||||
onChangedListener = object : FilterPopupWindow.OnChangedListener {
|
||||
override fun onChanged(popup: FilterPopupWindow, order: SearchThreadOrder, filter: SearchThreadFilter) {
|
||||
|
|
|
|||
|
|
@ -171,8 +171,11 @@ public final class NavigationHelper {
|
|||
}
|
||||
|
||||
private boolean navigationByUrl(String url, @NonNull String oldUrl) {
|
||||
Uri uri = Uri.parse(url),
|
||||
oldUri = Uri.parse(oldUrl);
|
||||
if (url == null || oldUrl == null) {
|
||||
return false;
|
||||
}
|
||||
Uri uri = Uri.parse(url);
|
||||
Uri oldUri = Uri.parse(oldUrl);
|
||||
String host = uri.getHost(),
|
||||
path = uri.getPath(),
|
||||
oldHost = oldUri.getHost(),
|
||||
|
|
|
|||
Loading…
Reference in New Issue