diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt index 00aae38..f70c42e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt @@ -15,6 +15,7 @@ import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.launcher.BuildConfig import com.simplemobiletools.launcher.R import com.simplemobiletools.launcher.fragments.AllAppsFragment +import com.simplemobiletools.launcher.fragments.MyFragment import com.simplemobiletools.launcher.interfaces.FlingListener import kotlinx.android.synthetic.main.activity_main.* @@ -35,11 +36,14 @@ class MainActivity : SimpleActivity(), FlingListener { mDetector = GestureDetectorCompat(this, MyGestureListener(this)) window.setDecorFitsSystemWindows(false) - (all_apps_fragment as AllAppsFragment).setupFragment(this) mScreenHeight = realScreenSize.y 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() { @@ -75,9 +79,9 @@ class MainActivity : SimpleActivity(), FlingListener { mTouchDownY = -1 if (!mIgnoreUpEvent) { if (all_apps_fragment.y < mScreenHeight * 0.7) { - showAllAppsFragment() + showAllAppsFragment(all_apps_fragment as MyFragment) } else { - hideAllAppsFragment() + hideAllAppsFragment(all_apps_fragment as MyFragment) } } } @@ -92,15 +96,15 @@ class MainActivity : SimpleActivity(), FlingListener { mIgnoreUpEvent = false } - private fun showAllAppsFragment() { - ObjectAnimator.ofFloat(all_apps_fragment, "y", 0f).apply { + private fun showAllAppsFragment(fragment: MyFragment) { + ObjectAnimator.ofFloat(fragment, "y", 0f).apply { interpolator = DecelerateInterpolator() start() } } - private fun hideAllAppsFragment() { - ObjectAnimator.ofFloat(all_apps_fragment, "y", mScreenHeight.toFloat()).apply { + private fun hideAllAppsFragment(fragment: MyFragment) { + ObjectAnimator.ofFloat(fragment, "y", mScreenHeight.toFloat()).apply { interpolator = DecelerateInterpolator() start() } @@ -147,11 +151,11 @@ class MainActivity : SimpleActivity(), FlingListener { override fun onFlingUp() { mIgnoreUpEvent = true - showAllAppsFragment() + showAllAppsFragment(all_apps_fragment as MyFragment) } override fun onFlingDown() { mIgnoreUpEvent = true - hideAllAppsFragment() + hideAllAppsFragment(all_apps_fragment as MyFragment) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/AllAppsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/AllAppsFragment.kt index c88125d..f849b13 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/AllAppsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/AllAppsFragment.kt @@ -11,7 +11,6 @@ import android.util.AttributeSet import android.view.MotionEvent import android.view.Surface import android.view.WindowManager -import android.widget.RelativeLayout import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.isRPlus @@ -23,12 +22,11 @@ import com.simplemobiletools.launcher.extensions.getColumnCount import com.simplemobiletools.launcher.models.AppLauncher 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 activity: MainActivity? = null @SuppressLint("ClickableViewAccessibility") - fun setupFragment(activity: MainActivity) { + override fun setupFragment(activity: MainActivity) { this.activity = activity background.applyColorFilter(activity.getProperBackgroundColor()) setPadding(0, activity.statusBarHeight, 0, 0) diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/MyFragment.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/MyFragment.kt new file mode 100644 index 0000000..cf46471 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/MyFragment.kt @@ -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) +} diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/WidgetsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/WidgetsFragment.kt index 983625c..bb9e4d2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/WidgetsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/WidgetsFragment.kt @@ -3,7 +3,6 @@ package com.simplemobiletools.launcher.fragments import android.appwidget.AppWidgetManager import android.content.Context import android.util.AttributeSet -import android.widget.RelativeLayout import com.simplemobiletools.commons.extensions.applyColorFilter import com.simplemobiletools.commons.extensions.getProperBackgroundColor 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.models.AppWidget -class WidgetsFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) { - private var activity: MainActivity? = null - - fun setupFragment(activity: MainActivity) { +class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment(context, attributeSet) { + override fun setupFragment(activity: MainActivity) { this.activity = activity background.applyColorFilter(activity.getProperBackgroundColor()) setPadding(0, activity.statusBarHeight, 0, 0) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 08c9e1b..4162f63 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -9,6 +9,11 @@ layout="@layout/all_apps_fragment" android:visibility="gone" /> + + - - +