create a MyFragment parent class

This commit is contained in:
tibbi 2022-09-01 16:15:06 +02:00
parent f154b444cc
commit 5322ad8803
6 changed files with 38 additions and 22 deletions

View file

@ -15,6 +15,7 @@ import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.launcher.BuildConfig import com.simplemobiletools.launcher.BuildConfig
import com.simplemobiletools.launcher.R import com.simplemobiletools.launcher.R
import com.simplemobiletools.launcher.fragments.AllAppsFragment import com.simplemobiletools.launcher.fragments.AllAppsFragment
import com.simplemobiletools.launcher.fragments.MyFragment
import com.simplemobiletools.launcher.interfaces.FlingListener import com.simplemobiletools.launcher.interfaces.FlingListener
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
@ -35,11 +36,14 @@ class MainActivity : SimpleActivity(), FlingListener {
mDetector = GestureDetectorCompat(this, MyGestureListener(this)) mDetector = GestureDetectorCompat(this, MyGestureListener(this))
window.setDecorFitsSystemWindows(false) window.setDecorFitsSystemWindows(false)
(all_apps_fragment as AllAppsFragment).setupFragment(this)
mScreenHeight = realScreenSize.y mScreenHeight = realScreenSize.y
mCurrentFragmentY = mScreenHeight mCurrentFragmentY = mScreenHeight
all_apps_fragment.y = mScreenHeight.toFloat()
all_apps_fragment.beVisible() arrayOf(all_apps_fragment as MyFragment, widgets_fragment as MyFragment).forEach { fragment ->
fragment.setupFragment(this)
fragment.y = mScreenHeight.toFloat()
fragment.beVisible()
}
} }
override fun onResume() { override fun onResume() {
@ -75,9 +79,9 @@ class MainActivity : SimpleActivity(), FlingListener {
mTouchDownY = -1 mTouchDownY = -1
if (!mIgnoreUpEvent) { if (!mIgnoreUpEvent) {
if (all_apps_fragment.y < mScreenHeight * 0.7) { if (all_apps_fragment.y < mScreenHeight * 0.7) {
showAllAppsFragment() showAllAppsFragment(all_apps_fragment as MyFragment)
} else { } else {
hideAllAppsFragment() hideAllAppsFragment(all_apps_fragment as MyFragment)
} }
} }
} }
@ -92,15 +96,15 @@ class MainActivity : SimpleActivity(), FlingListener {
mIgnoreUpEvent = false mIgnoreUpEvent = false
} }
private fun showAllAppsFragment() { private fun showAllAppsFragment(fragment: MyFragment) {
ObjectAnimator.ofFloat(all_apps_fragment, "y", 0f).apply { ObjectAnimator.ofFloat(fragment, "y", 0f).apply {
interpolator = DecelerateInterpolator() interpolator = DecelerateInterpolator()
start() start()
} }
} }
private fun hideAllAppsFragment() { private fun hideAllAppsFragment(fragment: MyFragment) {
ObjectAnimator.ofFloat(all_apps_fragment, "y", mScreenHeight.toFloat()).apply { ObjectAnimator.ofFloat(fragment, "y", mScreenHeight.toFloat()).apply {
interpolator = DecelerateInterpolator() interpolator = DecelerateInterpolator()
start() start()
} }
@ -147,11 +151,11 @@ class MainActivity : SimpleActivity(), FlingListener {
override fun onFlingUp() { override fun onFlingUp() {
mIgnoreUpEvent = true mIgnoreUpEvent = true
showAllAppsFragment() showAllAppsFragment(all_apps_fragment as MyFragment)
} }
override fun onFlingDown() { override fun onFlingDown() {
mIgnoreUpEvent = true mIgnoreUpEvent = true
hideAllAppsFragment() hideAllAppsFragment(all_apps_fragment as MyFragment)
} }
} }

View file

@ -11,7 +11,6 @@ import android.util.AttributeSet
import android.view.MotionEvent import android.view.MotionEvent
import android.view.Surface import android.view.Surface
import android.view.WindowManager import android.view.WindowManager
import android.widget.RelativeLayout
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.helpers.isRPlus import com.simplemobiletools.commons.helpers.isRPlus
@ -23,12 +22,11 @@ import com.simplemobiletools.launcher.extensions.getColumnCount
import com.simplemobiletools.launcher.models.AppLauncher import com.simplemobiletools.launcher.models.AppLauncher
import kotlinx.android.synthetic.main.all_apps_fragment.view.* import kotlinx.android.synthetic.main.all_apps_fragment.view.*
class AllAppsFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) { class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment(context, attributeSet) {
private var touchDownY = -1 private var touchDownY = -1
private var activity: MainActivity? = null
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
fun setupFragment(activity: MainActivity) { override fun setupFragment(activity: MainActivity) {
this.activity = activity this.activity = activity
background.applyColorFilter(activity.getProperBackgroundColor()) background.applyColorFilter(activity.getProperBackgroundColor())
setPadding(0, activity.statusBarHeight, 0, 0) setPadding(0, activity.statusBarHeight, 0, 0)

View file

@ -0,0 +1,12 @@
package com.simplemobiletools.launcher.fragments
import android.content.Context
import android.util.AttributeSet
import android.widget.RelativeLayout
import com.simplemobiletools.launcher.activities.MainActivity
abstract class MyFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) {
protected var activity: MainActivity? = null
abstract fun setupFragment(activity: MainActivity)
}

View file

@ -3,7 +3,6 @@ package com.simplemobiletools.launcher.fragments
import android.appwidget.AppWidgetManager import android.appwidget.AppWidgetManager
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.widget.RelativeLayout
import com.simplemobiletools.commons.extensions.applyColorFilter import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.getProperBackgroundColor import com.simplemobiletools.commons.extensions.getProperBackgroundColor
import com.simplemobiletools.commons.extensions.statusBarHeight import com.simplemobiletools.commons.extensions.statusBarHeight
@ -11,10 +10,8 @@ import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.launcher.activities.MainActivity import com.simplemobiletools.launcher.activities.MainActivity
import com.simplemobiletools.launcher.models.AppWidget import com.simplemobiletools.launcher.models.AppWidget
class WidgetsFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) { class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment(context, attributeSet) {
private var activity: MainActivity? = null override fun setupFragment(activity: MainActivity) {
fun setupFragment(activity: MainActivity) {
this.activity = activity this.activity = activity
background.applyColorFilter(activity.getProperBackgroundColor()) background.applyColorFilter(activity.getProperBackgroundColor())
setPadding(0, activity.statusBarHeight, 0, 0) setPadding(0, activity.statusBarHeight, 0, 0)

View file

@ -9,6 +9,11 @@
layout="@layout/all_apps_fragment" layout="@layout/all_apps_fragment"
android:visibility="gone" /> android:visibility="gone" />
<include
android:id="@+id/widgets_fragment"
layout="@layout/widgets_fragment"
android:visibility="gone" />
<View <View
android:id="@+id/popup_menu_anchor" android:id="@+id/popup_menu_anchor"
android:layout_width="1dp" android:layout_width="1dp"

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<com.simplemobiletools.launcher.fragments.AllAppsFragment xmlns:android="http://schemas.android.com/apk/res/android" <com.simplemobiletools.launcher.fragments.WidgetsFragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/widgets_holder" android:id="@+id/widgets_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -20,4 +20,4 @@
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" /> app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
</com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller> </com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller>
</com.simplemobiletools.launcher.fragments.AllAppsFragment> </com.simplemobiletools.launcher.fragments.WidgetsFragment>