forked from LawnchairLauncher/lawnchair
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'LawnchairLauncher:15-dev' into trunk
- Loading branch information
Showing
22 changed files
with
869 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package app.lawnchair.api.gh | ||
|
||
import app.lawnchair.util.kotlinxJson | ||
import kotlinx.serialization.Serializable | ||
import okhttp3.MediaType.Companion.toMediaType | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.kotlinx.serialization.asConverterFactory | ||
import retrofit2.http.GET | ||
import retrofit2.http.Path | ||
|
||
interface GitHubApi { | ||
@GET("repos/LawnchairLauncher/lawnchair/releases") | ||
suspend fun getReleases(): List<GitHubRelease> | ||
|
||
@GET("repos/{owner}/{repo}/events") | ||
suspend fun getRepositoryEvents( | ||
@Path("owner") owner: String, | ||
@Path("repo") repo: String, | ||
): List<GitHubEvent> | ||
} | ||
|
||
const val BASE_URL = "https://api.github.com/" | ||
|
||
val retrofit: Retrofit by lazy { | ||
Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.addConverterFactory(kotlinxJson.asConverterFactory("application/json".toMediaType())) | ||
.build() | ||
} | ||
|
||
val api: GitHubApi by lazy { | ||
retrofit.create(GitHubApi::class.java) | ||
} | ||
|
||
@Serializable | ||
data class GitHubRelease( | ||
val tag_name: String, | ||
val assets: List<GitHubAsset>, | ||
) | ||
|
||
@Serializable | ||
data class GitHubAsset( | ||
val name: String, | ||
val browser_download_url: String, | ||
) | ||
|
||
@Serializable | ||
data class GitHubEvent( | ||
val type: String, | ||
val actor: Actor, | ||
val created_at: String, | ||
) | ||
|
||
@Serializable | ||
data class Actor( | ||
val login: String, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
lawnchair/src/app/lawnchair/gestures/IconGestureListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package app.lawnchair.gestures | ||
|
||
import android.content.Context | ||
import android.util.Log | ||
import androidx.lifecycle.lifecycleScope | ||
import app.lawnchair.gestures.config.GestureHandlerConfig | ||
import app.lawnchair.gestures.type.GestureType | ||
import app.lawnchair.launcher | ||
import app.lawnchair.preferences2.PreferenceManager2 | ||
import com.android.launcher3.model.data.ItemInfo | ||
import com.android.launcher3.util.VibratorWrapper | ||
import kotlinx.coroutines.flow.firstOrNull | ||
import kotlinx.coroutines.launch | ||
|
||
class IconGestureListener( | ||
private val context: Context, | ||
private val prefs: PreferenceManager2, | ||
private val cmp: ItemInfo?, | ||
) : DirectionalGestureListener(context) { | ||
|
||
override fun onSwipeRight() = handleGesture(GestureType.SWIPE_RIGHT) | ||
override fun onSwipeLeft() = handleGesture(GestureType.SWIPE_LEFT) | ||
override fun onSwipeTop() = handleGesture(GestureType.SWIPE_UP) | ||
override fun onSwipeDown() = handleGesture(GestureType.SWIPE_DOWN) | ||
|
||
private fun handleGesture(gestureType: GestureType) { | ||
Log.d("GESTURE_HANDLER", "Handling gesture: ${gestureType.name}") | ||
|
||
cmp?.componentKey?.let { | ||
context.launcher.lifecycleScope.launch { | ||
val gesture = prefs.getGestureForApp(it, gestureType).firstOrNull() | ||
if (gesture !is GestureHandlerConfig.NoOp) { | ||
Log.d("GESTURE_HANDLER", "Triggering gesture: ${gestureType.name}") | ||
VibratorWrapper.INSTANCE.get(context.launcher).vibrate(VibratorWrapper.OVERVIEW_HAPTIC) | ||
gesture?.createHandler(context)?.onTrigger(context.launcher) | ||
} else { | ||
Log.d("GESTURE_HANDLER", "NoOp gesture, ignoring") | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.