properly calculate scrollbar height
This commit is contained in:
parent
6aba53c387
commit
8462d76aa7
|
@ -43,5 +43,5 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:8b339d6e4b'
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:01841778a4'
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
<activity
|
||||
android:name=".activities.MainActivity"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||
android:exported="true"
|
||||
android:theme="@style/LauncherTheme" />
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.content.pm.LauncherApps
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Bundle
|
||||
|
@ -17,6 +18,7 @@ import com.simplemobiletools.commons.views.MyGridLayoutManager
|
|||
import com.simplemobiletools.launcher.BuildConfig
|
||||
import com.simplemobiletools.launcher.R
|
||||
import com.simplemobiletools.launcher.adapters.LaunchersAdapter
|
||||
import com.simplemobiletools.launcher.extensions.getColumnCount
|
||||
import com.simplemobiletools.launcher.models.AppLauncher
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
|
||||
|
@ -40,6 +42,18 @@ class MainActivity : SimpleActivity() {
|
|||
setupNavigationBar()
|
||||
}
|
||||
|
||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||
super.onConfigurationChanged(newConfig)
|
||||
launchers_grid.scrollToPosition(0)
|
||||
launchers_fastscroller.resetManualScrolling()
|
||||
setupNavigationBar()
|
||||
|
||||
val layoutManager = launchers_grid.layoutManager as MyGridLayoutManager
|
||||
layoutManager.spanCount = getColumnCount()
|
||||
val launchers = (launchers_grid.adapter as LaunchersAdapter).launchers
|
||||
setupAdapter(launchers)
|
||||
}
|
||||
|
||||
@SuppressLint("WrongConstant")
|
||||
private fun getLaunchers() {
|
||||
val allApps = ArrayList<AppLauncher>()
|
||||
|
@ -79,17 +93,12 @@ class MainActivity : SimpleActivity() {
|
|||
launchers.sortBy { it.title.toLowerCase() }
|
||||
|
||||
val layoutManager = launchers_grid.layoutManager as MyGridLayoutManager
|
||||
layoutManager.spanCount = if (portrait) {
|
||||
resources.getInteger(R.integer.portrait_column_count)
|
||||
} else {
|
||||
resources.getInteger(R.integer.landscape_column_count)
|
||||
}
|
||||
|
||||
layoutManager.spanCount = getColumnCount()
|
||||
setupAdapter(launchers)
|
||||
}
|
||||
|
||||
private fun setupAdapter(launchers: ArrayList<AppLauncher>) {
|
||||
LaunchersAdapter(this, launchers) {
|
||||
LaunchersAdapter(this, launchers, launchers_fastscroller) {
|
||||
|
||||
}.apply {
|
||||
launchers_grid.adapter = this
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.simplemobiletools.launcher.adapters
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewTreeObserver
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
|
||||
import com.simplemobiletools.commons.extensions.getProperTextColor
|
||||
|
@ -10,16 +11,20 @@ import com.simplemobiletools.commons.extensions.portrait
|
|||
import com.simplemobiletools.commons.extensions.realScreenSize
|
||||
import com.simplemobiletools.launcher.R
|
||||
import com.simplemobiletools.launcher.activities.SimpleActivity
|
||||
import com.simplemobiletools.launcher.extensions.getColumnCount
|
||||
import com.simplemobiletools.launcher.models.AppLauncher
|
||||
import kotlinx.android.synthetic.main.item_launcher_label.view.*
|
||||
|
||||
class LaunchersAdapter(
|
||||
val activity: SimpleActivity,
|
||||
val launchers: ArrayList<AppLauncher>,
|
||||
val fastScroller: RecyclerViewFastScroller,
|
||||
val itemClick: (Any) -> Unit
|
||||
) : RecyclerView.Adapter<LaunchersAdapter.ViewHolder>(), RecyclerViewFastScroller.OnPopupTextUpdate {
|
||||
|
||||
private var textColor = activity.getProperTextColor()
|
||||
private var iconPadding = 0
|
||||
private var wasManualScrollPositionSet = false
|
||||
|
||||
init {
|
||||
calculateIconWidth()
|
||||
|
@ -57,6 +62,19 @@ class LaunchersAdapter(
|
|||
setOnClickListener { itemClick(launcher) }
|
||||
}
|
||||
|
||||
if (!wasManualScrollPositionSet) {
|
||||
itemView.launcher_holder.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||
override fun onGlobalLayout() {
|
||||
itemView.launcher_holder.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
||||
if (!wasManualScrollPositionSet) {
|
||||
val rowCount = Math.ceil(launchers.size / activity.getColumnCount().toDouble()).toInt()
|
||||
fastScroller.fullContentHeight = rowCount * itemView.height
|
||||
fastScroller.calculateScrollPositionManually = true
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return itemView
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,16 @@
|
|||
package com.simplemobiletools.launcher.extensions
|
||||
|
||||
import android.content.Context
|
||||
import com.simplemobiletools.commons.extensions.portrait
|
||||
import com.simplemobiletools.launcher.R
|
||||
import com.simplemobiletools.launcher.helpers.Config
|
||||
|
||||
val Context.config: Config get() = Config.newInstance(applicationContext)
|
||||
|
||||
fun Context.getColumnCount(): Int {
|
||||
return if (portrait) {
|
||||
resources.getInteger(R.integer.portrait_column_count)
|
||||
} else {
|
||||
resources.getInteger(R.integer.landscape_column_count)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue