-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f27a53
commit 5f65bff
Showing
10 changed files
with
134 additions
and
78 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
37 changes: 37 additions & 0 deletions
37
shared/src/androidMain/kotlin/com/toasterofbread/spmp/widget/WidgetActionCallback.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,37 @@ | ||
package com.toasterofbread.spmp.widget | ||
|
||
import android.content.Context | ||
import androidx.glance.GlanceId | ||
import androidx.glance.action.Action | ||
import androidx.glance.action.ActionParameters | ||
import androidx.glance.action.actionParametersOf | ||
import androidx.glance.appwidget.action.ActionCallback | ||
import androidx.glance.appwidget.action.actionRunCallback | ||
import com.toasterofbread.spmp.widget.action.TypeWidgetClickAction | ||
import com.toasterofbread.spmp.widget.configuration.SpMpWidgetConfiguration | ||
import kotlinx.serialization.encodeToString | ||
|
||
internal class WidgetActionCallback: ActionCallback { | ||
override suspend fun onAction( | ||
context: Context, | ||
glanceId: GlanceId, | ||
parameters: ActionParameters | ||
) { | ||
val serialisedAction: String = parameters[keyAction] ?: return | ||
val configuration: SpMpWidgetConfiguration<TypeWidgetClickAction> = SpMpWidgetConfiguration.json.decodeFromString(serialisedAction) | ||
SpMpWidget.runActionOnWidget(configuration.type_configuration.click_action, glanceId) | ||
} | ||
|
||
companion object { | ||
val keyAction: ActionParameters.Key<String> = ActionParameters.Key("action") | ||
|
||
operator fun invoke(configuration: SpMpWidgetConfiguration<out TypeWidgetClickAction>): Action = | ||
actionRunCallback<WidgetActionCallback>( | ||
actionParametersOf( | ||
keyAction to SpMpWidgetConfiguration.json.encodeToString( | ||
configuration | ||
) | ||
) | ||
) | ||
} | ||
} |
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
Oops, something went wrong.