Skip to content

Commit

Permalink
Add refocusing after reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyBoyFeng committed Aug 19, 2021
1 parent 35947f0 commit eb8ddff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.os.Bundle
import android.os.Handler
import android.os.Looper
import androidx.leanback.app.BrowseSupportFragment
import androidx.leanback.widget.ListRowPresenter
import androidx.lifecycle.ViewModelProvider
import com.github.crazyboyfeng.justTvLauncher.model.Shortcut
import java.text.DateFormat
Expand Down Expand Up @@ -39,6 +40,7 @@ class BrowseFragment : BrowseSupportFragment() {
is Shortcut -> {
launch(item.id)
viewModel.incrementOpenCount(item)
select(item)
}
}
}
Expand All @@ -56,6 +58,14 @@ class BrowseFragment : BrowseSupportFragment() {
startActivity(intent)
}


private fun select(shortcut: Shortcut) = handler.post {
val position = viewModel.findPosition(shortcut)
val task = ListRowPresenter.SelectItemViewHolderTask(position.second)
task.isSmoothScroll = false
rowsSupportFragment.setSelectedPosition(position.first, false, task)
}

override fun onResume() {
super.onResume()
startTick()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ class BrowseViewModel(application: Application) : AndroidViewModel(application)
loadShortcutGroupList()
}

fun findPosition(shortcut: Shortcut): Pair<Int, Int> {
val shortcutGroupList = browseContent.value!!
val x = shortcutGroupList.indexOfFirst { it.category == shortcut.category }
val y = shortcutGroupList[x].shortcutList.indexOf(shortcut)
Log.v(TAG, "${shortcut.id}: ($x, $y)")
return Pair(x, y)
}

fun removePackage(packageName: String) {
shortcutRepository.deleteById(packageName)
loadShortcutGroupList()
Expand Down

0 comments on commit eb8ddff

Please sign in to comment.