fixed detailed status position lost in interactions timeline

quick & dirty fix to #822
This commit is contained in:
Mariotaku Lee 2017-05-10 12:59:01 +08:00
parent 3cbef0b1bf
commit 99cda131e7
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
4 changed files with 29 additions and 65 deletions

View File

@ -6,8 +6,5 @@ import android.support.v7.widget.RecyclerView
* Created by mariotaku on 16/8/21.
*/
fun RecyclerView.Adapter<*>.findPositionByItemId(itemId: Long): Int {
for (i in 0 until itemCount) {
if (getItemId(i) == itemId) return i
}
return RecyclerView.NO_POSITION
return (0 until itemCount).firstOrNull { getItemId(it) == itemId } ?: RecyclerView.NO_POSITION
}

View File

@ -62,7 +62,10 @@ import kotlinx.android.synthetic.main.header_status.view.*
import kotlinx.android.synthetic.main.layout_content_fragment_common.*
import org.mariotaku.abstask.library.TaskStarter
import org.mariotaku.kpreferences.get
import org.mariotaku.ktextension.*
import org.mariotaku.ktextension.applyFontFamily
import org.mariotaku.ktextension.contains
import org.mariotaku.ktextension.findPositionByItemId
import org.mariotaku.ktextension.hideIfEmpty
import org.mariotaku.library.objectcursor.ObjectCursor
import org.mariotaku.microblog.library.MicroBlog
import org.mariotaku.microblog.library.MicroBlogException
@ -430,35 +433,6 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
override fun onLoaderReset(loader: Loader<SingleResponse<ParcelableStatus>>) {
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.menu_status, menu)
}
override fun onPrepareOptionsMenu(menu: Menu) {
menu.setItemAvailability(R.id.current_status, adapter.status != null)
super.onPrepareOptionsMenu(menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.current_status -> {
if (adapter.status != null) {
val position = adapter.getFirstPositionOfItem(StatusAdapter.ITEM_IDX_STATUS)
recyclerView.smoothScrollToPosition(position)
}
return true
}
}
return super.onOptionsItemSelected(item)
}
private fun setConversation(data: List<ParcelableStatus>?) {
val readPosition = saveReadPosition()
val changed = adapter.setData(data)
hasMoreConversation = data != null && changed
restoreReadPosition(readPosition)
}
override val refreshing: Boolean
get() = loaderManager.hasRunningLoadersSafe()
@ -546,6 +520,19 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
}
}
private fun setConversation(data: List<ParcelableStatus>?) {
val readPosition = saveReadPosition()
val changed = adapter.setData(data)
hasMoreConversation = data != null && changed
restoreReadPosition(readPosition)
}
private fun scrollToCurrent() {
if (adapter.status != null) {
val position = adapter.getFirstPositionOfItem(StatusAdapter.ITEM_IDX_STATUS)
recyclerView.smoothScrollToPosition(position)
}
}
private fun displayTranslation(translation: TranslationResult) {
adapter.translationResult = translation
@ -1782,10 +1769,13 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
val countIndex = getItemCountIndex(position)
when (countIndex) {
ITEM_IDX_CONVERSATION, ITEM_IDX_STATUS, ITEM_IDX_REPLY -> {
return (countIndex.toLong() shl 32) or getStatus(position).hashCode().toLong()
val status = getStatus(position)
val hashCode = ParcelableStatus.calculateHashCode(status.account_key, status.id)
return (countIndex.toLong() shl 32) or hashCode.toLong()
}
}
return (countIndex.toLong() shl 32) or getItemType(position).toLong()
val countPos = (position - getItemStartPosition(countIndex)).toLong()
return (countIndex.toLong() shl 32) or countPos
}
override fun getItemCount(): Int {

View File

@ -20,13 +20,13 @@
package org.mariotaku.twidere.util
import android.graphics.Typeface
import android.net.Uri
import android.text.Editable
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.StyleSpan
import android.text.style.URLSpan
import okhttp3.HttpUrl
import org.attoparser.ParseException
import org.attoparser.config.ParseConfiguration
import org.attoparser.simple.AbstractSimpleMarkupHandler
@ -76,7 +76,11 @@ object HtmlSpanBuilder {
private fun createSpan(info: TagInfo): Any? {
when (info.nameLower) {
"a" -> {
return URLSpan(info.getAttribute("href"))
var href = info.getAttribute("href") ?: return null
if (HttpUrl.parse(href)?.scheme() == null) {
href = "https://" + href
}
return URLSpan(href)
}
"b", "strong" -> {
return StyleSpan(Typeface.BOLD)

View File

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Twidere - Twitter client for Android
~
~ Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/current_status"
android:icon="@drawable/ic_action_twitter"
android:title="@string/current_status"
app:showAsAction="always" />
</menu>