Improve feed gestures
This commit is contained in:
@@ -2,7 +2,6 @@ package de.mm20.launcher2.ui.launcher.scaffold
|
|||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.Log
|
|
||||||
import androidx.activity.compose.LocalActivity
|
import androidx.activity.compose.LocalActivity
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
@@ -19,6 +18,7 @@ import androidx.compose.runtime.LaunchedEffect
|
|||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableFloatStateOf
|
import androidx.compose.runtime.mutableFloatStateOf
|
||||||
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
@@ -34,7 +34,6 @@ import de.mm20.launcher2.feed.FeedService
|
|||||||
import de.mm20.launcher2.preferences.feed.FeedSettings
|
import de.mm20.launcher2.preferences.feed.FeedSettings
|
||||||
import de.mm20.launcher2.ui.R
|
import de.mm20.launcher2.ui.R
|
||||||
import de.mm20.launcher2.ui.ktx.toIntOffset
|
import de.mm20.launcher2.ui.ktx.toIntOffset
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import org.koin.core.component.KoinComponent
|
import org.koin.core.component.KoinComponent
|
||||||
import org.koin.core.component.inject
|
import org.koin.core.component.inject
|
||||||
|
|
||||||
@@ -47,6 +46,8 @@ internal class FeedComponent(
|
|||||||
|
|
||||||
override val permanent: Boolean = true
|
override val permanent: Boolean = true
|
||||||
|
|
||||||
|
private var state = mutableIntStateOf(0)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
override fun Component(
|
override fun Component(
|
||||||
modifier: Modifier,
|
modifier: Modifier,
|
||||||
@@ -79,18 +80,30 @@ internal class FeedComponent(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val enableScroll = state.currentComponent == this && progress > 0f && progress < 1f
|
val componentState = this.state.intValue
|
||||||
|
|
||||||
LaunchedEffect(enableScroll) {
|
LaunchedEffect(state.currentComponent == this && componentState < 2) {
|
||||||
if (enableScroll) {
|
if (state.currentComponent == this@FeedComponent && componentState < 2) {
|
||||||
feedConnection?.startScroll()
|
feedConnection?.startScroll()
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(componentState == 2 && progress > 0.5f) {
|
||||||
|
if (componentState == 2 && progress > 0.5f) {
|
||||||
feedConnection?.endScroll()
|
feedConnection?.endScroll()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(progress) {
|
LaunchedEffect(componentState == 0) {
|
||||||
feedConnection?.onScroll(progress)
|
if (componentState == 0) {
|
||||||
|
feedConnection?.closeFeed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(state.currentComponent == this, progress) {
|
||||||
|
if (state.currentComponent == this@FeedComponent) {
|
||||||
|
feedConnection?.onScroll(progress)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(feedProgress.floatValue) {
|
LaunchedEffect(feedProgress.floatValue) {
|
||||||
@@ -142,4 +155,25 @@ internal class FeedComponent(
|
|||||||
.alpha(1f - state.currentProgress)
|
.alpha(1f - state.currentProgress)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun onPreActivate(state: LauncherScaffoldState) {
|
||||||
|
super.onPreActivate(state)
|
||||||
|
this.state.intValue = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun onActivate(state: LauncherScaffoldState) {
|
||||||
|
super.onActivate(state)
|
||||||
|
this.state.intValue = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun onDismiss(state: LauncherScaffoldState) {
|
||||||
|
super.onDismiss(state)
|
||||||
|
this.state.intValue = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun onPreDismiss(state: LauncherScaffoldState) {
|
||||||
|
super.onPreDismiss(state)
|
||||||
|
this.state.intValue = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# Feed
|
# Feed
|
||||||
|
|
||||||
The feed is a personalized content page that lives to the left of your home screen, that can be
|
The feed is a personalized content page that lives to the left of your home screen, which can be
|
||||||
opened without leaving the launcher. Traditionally, launchers show the Google Discover feed here,
|
opened without leaving the launcher. Traditionally, launchers show the Google Discover feed here,
|
||||||
but there are other alternatives.
|
but there are other alternatives.
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,10 @@ export const UserGuideSidebar: DefaultTheme.SidebarItem[] = [
|
|||||||
text: 'Weather',
|
text: 'Weather',
|
||||||
link: '/docs/user-guide/integrations/weather',
|
link: '/docs/user-guide/integrations/weather',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
text: 'Feed',
|
||||||
|
link: '/docs/user-guide/integrations/feed',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ interface FeedConnection {
|
|||||||
fun startScroll()
|
fun startScroll()
|
||||||
fun endScroll()
|
fun endScroll()
|
||||||
fun onScroll(progress: Float)
|
fun onScroll(progress: Float)
|
||||||
|
|
||||||
|
fun openFeed()
|
||||||
|
fun closeFeed()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class FeedConnectionImpl(
|
internal class FeedConnectionImpl(
|
||||||
@@ -77,6 +80,22 @@ internal class FeedConnectionImpl(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun openFeed() {
|
||||||
|
try {
|
||||||
|
overlay?.openOverlay(Flags)
|
||||||
|
} catch (e: RemoteException) {
|
||||||
|
CrashReporter.logException(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun closeFeed() {
|
||||||
|
try {
|
||||||
|
overlay?.closeOverlay(Flags)
|
||||||
|
} catch (e: RemoteException) {
|
||||||
|
CrashReporter.logException(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun start() {
|
fun start() {
|
||||||
activity.lifecycle.addObserver(this)
|
activity.lifecycle.addObserver(this)
|
||||||
val service = activity.packageManager.resolveService(serviceIntent, 0)
|
val service = activity.packageManager.resolveService(serviceIntent, 0)
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
package de.mm20.launcher2.feed
|
|
||||||
|
|
||||||
import amirz.aidlbridge.IBridgeCallback
|
|
||||||
import android.content.ComponentName
|
|
||||||
import android.content.ServiceConnection
|
|
||||||
import android.os.IBinder
|
|
||||||
|
|
||||||
class ServiceConnection: IBridgeCallback.Stub(), ServiceConnection {
|
|
||||||
override fun onServiceConnected(
|
|
||||||
name: ComponentName?,
|
|
||||||
service: IBinder?
|
|
||||||
) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onServiceDisconnected(name: ComponentName?) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user