Skip to content

Commit

Permalink
Google Assistant App Actions for AntennaPod (#4417)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgborowiec committed Jan 24, 2021
1 parent c32239b commit cd23ecc
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 2 deletions.
26 changes: 26 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,28 @@
android:windowSoftInputMode="stateAlwaysHidden"
android:launchMode="singleTask"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="antennapod.org"
android:pathPrefix="/deeplink/main"
android:scheme="https" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="antennapod.org"
android:pathPrefix="/deeplink/search"
android:scheme="https" />
</intent-filter>
</activity>

<activity
Expand Down Expand Up @@ -312,6 +334,10 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>

<meta-data
android:name="com.google.android.actions"
android:resource="@xml/actions" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
Expand Down Expand Up @@ -51,6 +52,7 @@
import de.danoeh.antennapod.fragment.NavDrawerFragment;
import de.danoeh.antennapod.fragment.PlaybackHistoryFragment;
import de.danoeh.antennapod.fragment.QueueFragment;
import de.danoeh.antennapod.fragment.SearchFragment;
import de.danoeh.antennapod.fragment.SubscriptionFragment;
import de.danoeh.antennapod.fragment.TransitionEffect;
import de.danoeh.antennapod.preferences.PreferenceUpgrader;
Expand Down Expand Up @@ -511,6 +513,8 @@ private void handleNavIntent() {
} else if (intent.getBooleanExtra(EXTRA_OPEN_PLAYER, false)) {
sheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
bottomSheetCallback.onSlide(null, 1.0f);
} else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
handleDeeplink(intent.getData());
}
// to avoid handling the intent twice when the configuration changes
setIntent(new Intent(MainActivity.this, MainActivity.class));
Expand All @@ -520,6 +524,7 @@ private void handleNavIntent() {
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
handleNavIntent();
}

public Snackbar showSnackbarAbovePlayer(CharSequence text, int duration) {
Expand All @@ -540,6 +545,59 @@ public Snackbar showSnackbarAbovePlayer(int text, int duration) {
return showSnackbarAbovePlayer(getResources().getText(text), duration);
}

/**
* Handles the deep link incoming via App Actions.
* Performs an in-app search or opens the relevant feature of the app
* depending on the query.
*
* @param uri incoming deep link
*/
private void handleDeeplink(Uri uri) {
if (uri == null || uri.getPath() == null) {
return;
}
Log.d(TAG, "Handling deeplink: " + uri.toString());
switch (uri.getPath()) {
case "/deeplink/search":
String query = uri.getQueryParameter("query");
if (query == null) {
return;
}

this.loadChildFragment(SearchFragment.newInstance(query));
break;
case "/deeplink/main":
String feature = uri.getQueryParameter("page");
if (feature == null) {
return;
}
switch (feature) {
case "DOWNLOADS":
loadFragment(DownloadsFragment.TAG, null);
break;
case "HISTORY":
loadFragment(PlaybackHistoryFragment.TAG, null);
break;
case "EPISODES":
loadFragment(EpisodesFragment.TAG, null);
break;
case "QUEUE":
loadFragment(QueueFragment.TAG, null);
break;
case "SUBSCRIPTIONS":
loadFragment(SubscriptionFragment.TAG, null);
break;
default:
showSnackbarAbovePlayer(getString(R.string.app_action_not_found, feature),
Snackbar.LENGTH_LONG);
return;
}
break;
default:
break;
}
}

//Hardware keyboard support
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
Expand Down Expand Up @@ -592,5 +650,4 @@ public boolean onKeyUp(int keyCode, KeyEvent event) {
}
return super.onKeyUp(keyCode, event);
}

}
25 changes: 25 additions & 0 deletions app/src/main/res/xml/actions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version ="1.0" encoding ="utf-8"?>
<actions>
<action intentName="actions.intent.OPEN_APP_FEATURE">
<fulfillment urlTemplate="https://antennapod.org/deeplink/main{?page}">
<parameter-mapping intentParameter="feature" urlParameter="page" />
</fulfillment>
<parameter name="feature">
<entity-set-reference entitySetId="featureEntitySet" />
</parameter>
</action>

<action intentName="actions.intent.GET_THING">
<fulfillment urlTemplate="https://antennapod.org/deeplink/search{?query}">
<parameter-mapping intentParameter="thing.name" urlParameter="query"/>
</fulfillment>
</action>

<entity-set entitySetId="featureEntitySet">
<entity identifier="QUEUE" name="@string/queue_label" />
<entity identifier="EPISODES" name="@string/episodes_label" />
<entity identifier="DOWNLOADS" name="@string/downloads_label" />
<entity identifier="SUBSCRIPTIONS" name="@string/subscriptions_label" />
<entity identifier="HISTORY" name="@string/playback_history_label" />
</entity-set>
</actions>
5 changes: 4 additions & 1 deletion core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<string name="statistics_label">Statistics</string>
<string name="add_feed_label">Add Podcast</string>
<string name="episodes_label">Episodes</string>
<string name="queue_label">Queue</string>
<string name="all_episodes_short_label">All</string>
<string name="new_episodes_label">New</string>
<string name="favorite_episodes_label">Favorites</string>
Expand All @@ -32,6 +33,9 @@
<string name="download_statistics_label">Downloads</string>
<string name="notification_pref_fragment">Notifications</string>

<!-- Google Assistant -->
<string name="app_action_not_found">\"%1$s\" not found</string>

<!-- Statistics fragment -->
<string name="total_time_listened_to_podcasts">Total time of episodes played:</string>
<string name="statistics_details_dialog">%1$d out of %2$d episodes started.\n\nPlayed %3$s out of %4$s.</string>
Expand Down Expand Up @@ -367,7 +371,6 @@
<string name="storage_pref">Storage</string>
<string name="storage_sum">Episode auto delete, Import, Export</string>
<string name="project_pref">Project</string>
<string name="queue_label">Queue</string>
<string name="synchronization_pref">Synchronization</string>
<string name="synchronization_sum">Synchronize with other devices using gpodder.net</string>
<string name="automation">Automation</string>
Expand Down

0 comments on commit cd23ecc

Please sign in to comment.