最後に見ていた位置のTL要素のIDを保存するようにした.現時点では使い道がない

This commit is contained in:
tateisu 2018-08-24 22:45:27 +09:00
parent 636614299c
commit 7bec1b814d
6 changed files with 65 additions and 12 deletions

View File

@ -430,7 +430,7 @@ class ActMain : AppCompatActivity()
})
for(column in app_state.column_list) {
column.onSaveInstanceState()
column.saveScrollPosition()
}
}
@ -522,6 +522,11 @@ class ActMain : AppCompatActivity()
app_state.stream_reader.stopAll()
for(column in app_state.column_list) {
column.saveScrollPosition()
}
app_state.saveColumnList(bEnableSpeech = false)
super.onStop()
}
@ -560,8 +565,15 @@ class ActMain : AppCompatActivity()
{ env -> env.pager.currentItem },
{ env -> env.tablet_layout_manager.findFirstVisibleItemPosition() })
pref.edit().put(Pref.ipLastColumnPos, last_pos).apply()
val e = pref.edit()
.put(Pref.ipLastColumnPos, last_pos)
e.apply()
for(column in app_state.column_list) {
column.saveScrollPosition()
}
app_state.saveColumnList(bEnableSpeech = false)
super.onPause()
}
@ -2629,9 +2641,7 @@ class ActMain : AppCompatActivity()
if(timeline_font_size_sp.isNaN()) {
tv.textSize = timeline_font_size_sp
}
if(timeline_font != null) {
tv.typeface = timeline_font
}
tv.typeface = timeline_font
tv.text = text
tv.measure(
View.MeasureSpec.makeMeasureSpec(nAutoCwCellWidth, View.MeasureSpec.EXACTLY),

View File

@ -252,10 +252,10 @@ class AppState(internal val context : Context, internal val pref : SharedPrefere
return array
}
internal fun saveColumnList() {
internal fun saveColumnList(bEnableSpeech :Boolean = true) {
val array = encodeColumnList()
saveColumnList(context, FILE_COLUMN_LIST, array)
enableSpeech()
if(bEnableSpeech) enableSpeech()
}
private fun loadColumnList() {

View File

@ -2,6 +2,7 @@ package jp.juggler.subwaytooter
import android.annotation.SuppressLint
import android.content.Context
import android.content.SharedPreferences
import android.net.Uri
import android.os.AsyncTask
import android.os.SystemClock
@ -127,6 +128,7 @@ class Column(
private const val KEY_INSTANCE_LOCAL = "instance_local"
private const val KEY_ENABLE_SPEECH = "enable_speech"
private const val KEY_LAST_VIEWING_ITEM = "lastViewingItem"
private const val KEY_REGEX_TEXT = "regex_text"
@ -427,6 +429,7 @@ class Column(
internal var instance_information : TootInstance? = null
internal var scroll_save : ScrollPosition? = null
internal var last_viewing_item_id :EntityId? = null
internal val is_dispose = AtomicBoolean()
@ -581,6 +584,7 @@ class Column(
instance_local = src.optBoolean(KEY_INSTANCE_LOCAL)
enable_speech = src.optBoolean(KEY_ENABLE_SPEECH)
last_viewing_item_id = EntityId.from(src,KEY_LAST_VIEWING_ITEM)
regex_text = src.parseString(KEY_REGEX_TEXT) ?: ""
@ -648,6 +652,7 @@ class Column(
dst.put(KEY_INSTANCE_LOCAL, instance_local)
dst.put(KEY_ENABLE_SPEECH, enable_speech)
last_viewing_item_id?.putTo(dst,KEY_LAST_VIEWING_ITEM)
dst.put(KEY_REGEX_TEXT, regex_text)
@ -5042,8 +5047,27 @@ class Column(
val isMisskey : Boolean = access_info.isMisskey
fun onSaveInstanceState() {
viewHolder?.saveScrollPosition()
fun saveScrollPosition() {
try {
if(viewHolder?.saveScrollPosition() == true) {
val ss = this.scroll_save
if( ss != null ) {
val item = list_data[toListIndex(ss.adapterIndex)]
this.last_viewing_item_id = item.getOrderId()
// とりあえず保存はするが
// TLデータそのものを永続化しないかぎり出番はないっぽい
}
}
}catch(ex:Throwable) {
log.e(ex,"can't get last_viewing_item_id.")
}
}
fun findListIndexByTimelineId(orderId : EntityId) : Int? {
list_data.forEachIndexed{ i,v->
if( v.getOrderId() == orderId ) return i
}
return null
}
}

View File

@ -356,6 +356,21 @@ class ColumnViewHolder(
//復元後にもここを通るがこれは正常である
val sp = column.scroll_save
if(sp==null) {
// val lvi = column.last_viewing_item_id
// if( lvi != null ){
// column.last_viewing_item_id = null
// val listIndex = column.findListIndexByTimelineId(lvi)
// if( listIndex != null){
// log.d(
// "restoreScrollPosition [$page_idx] %s , restore from last_viewing_item_id %d"
// , column.getColumnName( true )
// ,listIndex
// )
// ScrollPosition(column.toAdapterIndex(listIndex),0).restore(this@ColumnViewHolder)
// return
// }
// }
log.d(
"restoreScrollPosition [$page_idx] %s , column has no saved scroll position."
, column.getColumnName( true )
@ -1072,7 +1087,7 @@ class ColumnViewHolder(
showToast(activity, true, refreshError)
}
fun saveScrollPosition() {
fun saveScrollPosition() :Boolean{
val column = this.column
when {
column == null -> log.d("saveScrollPosition [%d] , column==null", page_idx)
@ -1092,6 +1107,7 @@ class ColumnViewHolder(
, scroll_save.adapterIndex
, scroll_save.offset
)
return true
}
else -> {
@ -1104,8 +1120,10 @@ class ColumnViewHolder(
, scroll_save.adapterIndex
, scroll_save.offset
)
return true
}
}
return false
}
fun setScrollPosition(sp : ScrollPosition, deltaDp : Float = 0f) {

View File

@ -238,4 +238,5 @@ internal class ItemListAdapter(
// diffを取る部分をワーカースレッドで実行したいが、直後にスクロール位置の処理があるので差支えがある…
}
}

View File

@ -47,7 +47,7 @@ abstract class EntityId : Comparable<EntityId> {
}
}
private fun encode():String{
fun encode():String{
val prefix = when(this){
is EntityIdLong ->'L'
is EntityIdString->'S'