mirror of
				https://github.com/SimpleMobileTools/Simple-Launcher.git
				synced 2025-06-05 21:59:15 +02:00 
			
		
		
		
	properly calculate scrollbar height
This commit is contained in:
		| @@ -43,5 +43,5 @@ android { | |||||||
| } | } | ||||||
|  |  | ||||||
| dependencies { | dependencies { | ||||||
|     implementation 'com.github.SimpleMobileTools:Simple-Commons:8b339d6e4b' |     implementation 'com.github.SimpleMobileTools:Simple-Commons:01841778a4' | ||||||
| } | } | ||||||
|   | |||||||
| @@ -32,6 +32,7 @@ | |||||||
|  |  | ||||||
|         <activity |         <activity | ||||||
|             android:name=".activities.MainActivity" |             android:name=".activities.MainActivity" | ||||||
|  |             android:configChanges="orientation|keyboardHidden|screenSize" | ||||||
|             android:exported="true" |             android:exported="true" | ||||||
|             android:theme="@style/LauncherTheme" /> |             android:theme="@style/LauncherTheme" /> | ||||||
|  |  | ||||||
|   | |||||||
| @@ -5,6 +5,7 @@ import android.content.Context | |||||||
| import android.content.Intent | import android.content.Intent | ||||||
| import android.content.pm.LauncherApps | import android.content.pm.LauncherApps | ||||||
| import android.content.pm.PackageManager | import android.content.pm.PackageManager | ||||||
|  | import android.content.res.Configuration | ||||||
| import android.graphics.Color | import android.graphics.Color | ||||||
| import android.graphics.drawable.Drawable | import android.graphics.drawable.Drawable | ||||||
| import android.os.Bundle | import android.os.Bundle | ||||||
| @@ -17,6 +18,7 @@ import com.simplemobiletools.commons.views.MyGridLayoutManager | |||||||
| import com.simplemobiletools.launcher.BuildConfig | import com.simplemobiletools.launcher.BuildConfig | ||||||
| import com.simplemobiletools.launcher.R | import com.simplemobiletools.launcher.R | ||||||
| import com.simplemobiletools.launcher.adapters.LaunchersAdapter | import com.simplemobiletools.launcher.adapters.LaunchersAdapter | ||||||
|  | import com.simplemobiletools.launcher.extensions.getColumnCount | ||||||
| import com.simplemobiletools.launcher.models.AppLauncher | import com.simplemobiletools.launcher.models.AppLauncher | ||||||
| import kotlinx.android.synthetic.main.activity_main.* | import kotlinx.android.synthetic.main.activity_main.* | ||||||
|  |  | ||||||
| @@ -40,6 +42,18 @@ class MainActivity : SimpleActivity() { | |||||||
|         setupNavigationBar() |         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") |     @SuppressLint("WrongConstant") | ||||||
|     private fun getLaunchers() { |     private fun getLaunchers() { | ||||||
|         val allApps = ArrayList<AppLauncher>() |         val allApps = ArrayList<AppLauncher>() | ||||||
| @@ -79,17 +93,12 @@ class MainActivity : SimpleActivity() { | |||||||
|         launchers.sortBy { it.title.toLowerCase() } |         launchers.sortBy { it.title.toLowerCase() } | ||||||
|  |  | ||||||
|         val layoutManager = launchers_grid.layoutManager as MyGridLayoutManager |         val layoutManager = launchers_grid.layoutManager as MyGridLayoutManager | ||||||
|         layoutManager.spanCount = if (portrait) { |         layoutManager.spanCount = getColumnCount() | ||||||
|             resources.getInteger(R.integer.portrait_column_count) |  | ||||||
|         } else { |  | ||||||
|             resources.getInteger(R.integer.landscape_column_count) |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         setupAdapter(launchers) |         setupAdapter(launchers) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private fun setupAdapter(launchers: ArrayList<AppLauncher>) { |     private fun setupAdapter(launchers: ArrayList<AppLauncher>) { | ||||||
|         LaunchersAdapter(this, launchers) { |         LaunchersAdapter(this, launchers, launchers_fastscroller) { | ||||||
|  |  | ||||||
|         }.apply { |         }.apply { | ||||||
|             launchers_grid.adapter = this |             launchers_grid.adapter = this | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ package com.simplemobiletools.launcher.adapters | |||||||
| import android.view.LayoutInflater | import android.view.LayoutInflater | ||||||
| import android.view.View | import android.view.View | ||||||
| import android.view.ViewGroup | import android.view.ViewGroup | ||||||
|  | import android.view.ViewTreeObserver | ||||||
| import androidx.recyclerview.widget.RecyclerView | import androidx.recyclerview.widget.RecyclerView | ||||||
| import com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller | import com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller | ||||||
| import com.simplemobiletools.commons.extensions.getProperTextColor | 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.commons.extensions.realScreenSize | ||||||
| import com.simplemobiletools.launcher.R | import com.simplemobiletools.launcher.R | ||||||
| import com.simplemobiletools.launcher.activities.SimpleActivity | import com.simplemobiletools.launcher.activities.SimpleActivity | ||||||
|  | import com.simplemobiletools.launcher.extensions.getColumnCount | ||||||
| import com.simplemobiletools.launcher.models.AppLauncher | import com.simplemobiletools.launcher.models.AppLauncher | ||||||
| import kotlinx.android.synthetic.main.item_launcher_label.view.* | import kotlinx.android.synthetic.main.item_launcher_label.view.* | ||||||
|  |  | ||||||
| class LaunchersAdapter( | class LaunchersAdapter( | ||||||
|     val activity: SimpleActivity, |     val activity: SimpleActivity, | ||||||
|     val launchers: ArrayList<AppLauncher>, |     val launchers: ArrayList<AppLauncher>, | ||||||
|  |     val fastScroller: RecyclerViewFastScroller, | ||||||
|     val itemClick: (Any) -> Unit |     val itemClick: (Any) -> Unit | ||||||
| ) : RecyclerView.Adapter<LaunchersAdapter.ViewHolder>(), RecyclerViewFastScroller.OnPopupTextUpdate { | ) : RecyclerView.Adapter<LaunchersAdapter.ViewHolder>(), RecyclerViewFastScroller.OnPopupTextUpdate { | ||||||
|  |  | ||||||
|     private var textColor = activity.getProperTextColor() |     private var textColor = activity.getProperTextColor() | ||||||
|     private var iconPadding = 0 |     private var iconPadding = 0 | ||||||
|  |     private var wasManualScrollPositionSet = false | ||||||
|  |  | ||||||
|     init { |     init { | ||||||
|         calculateIconWidth() |         calculateIconWidth() | ||||||
| @@ -57,6 +62,19 @@ class LaunchersAdapter( | |||||||
|                 setOnClickListener { itemClick(launcher) } |                 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 |             return itemView | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -1,6 +1,16 @@ | |||||||
| package com.simplemobiletools.launcher.extensions | package com.simplemobiletools.launcher.extensions | ||||||
|  |  | ||||||
| import android.content.Context | import android.content.Context | ||||||
|  | import com.simplemobiletools.commons.extensions.portrait | ||||||
|  | import com.simplemobiletools.launcher.R | ||||||
| import com.simplemobiletools.launcher.helpers.Config | import com.simplemobiletools.launcher.helpers.Config | ||||||
|  |  | ||||||
| val Context.config: Config get() = Config.newInstance(applicationContext) | 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) | ||||||
|  |     } | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user