Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/news-android.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Luhmer <david-dev@live.de>2020-01-16 08:24:21 +0300
committerGitHub <noreply@github.com>2020-01-16 08:24:21 +0300
commitb1d6993b3f143a61fa1387e27ef26e4022387589 (patch)
tree958733d03fdcd332a467da1323f617a39371f0f9 /News-Android-App/src/main/java/de/luhmer/owncloudnewsreader
parent58335e4f49343e6726fc7f01240eb25caadcf65d (diff)
parent5957360935c062aaaa15f7448caeb4ba88c2a49e (diff)
Merge pull request #811 from nextcloud/android-auto-voice
implement basic voice commands
Diffstat (limited to 'News-Android-App/src/main/java/de/luhmer/owncloudnewsreader')
-rw-r--r--News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/PodcastPlaybackService.java95
1 files changed, 86 insertions, 9 deletions
diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/PodcastPlaybackService.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/PodcastPlaybackService.java
index 2c758d51..acd2fe86 100644
--- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/PodcastPlaybackService.java
+++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/PodcastPlaybackService.java
@@ -10,21 +10,22 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.ResultReceiver;
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
import android.support.v4.media.MediaBrowserCompat;
-import androidx.media.MediaBrowserServiceCompat;
-
import android.support.v4.media.MediaDescriptionCompat;
import android.support.v4.media.MediaMetadataCompat;
-import androidx.media.session.MediaButtonReceiver;
import android.support.v4.media.session.MediaSessionCompat;
import android.support.v4.media.session.PlaybackStateCompat;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
+import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.media.MediaBrowserServiceCompat;
+import androidx.media.session.MediaButtonReceiver;
+
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -478,11 +479,13 @@ public class PodcastPlaybackService extends MediaBrowserServiceCompat {
}
else if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) {
// Pause playback
+ mSession.getController().getTransportControls().pause();
} else if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
// Lower the volume, keep playing
} else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
// Your app has been granted audio focus again
// Raise volume to normal, restart playback if necessary
+ mSession.getController().getTransportControls().play();
}
};
@@ -611,9 +614,7 @@ public class PodcastPlaybackService extends MediaBrowserServiceCompat {
RssItem rssItem = dbConn.getRssItemById(podcastId);
PodcastItem podcastItem = ParsePodcastItemFromRssItem(PodcastPlaybackService.this, rssItem);
- Intent intent = new Intent(PodcastPlaybackService.this, PodcastPlaybackService.class);
- intent.putExtra(PodcastPlaybackService.MEDIA_ITEM, podcastItem);
- startService(intent);
+ startPlayingPodcastItem(podcastItem);
}
super.onPlayFromMediaId(mediaId, extras);
@@ -634,7 +635,36 @@ public class PodcastPlaybackService extends MediaBrowserServiceCompat {
@Override
public void onPlayFromSearch(String query, Bundle extras) {
Log.d(TAG, "onPlayFromSearch() called with: query = [" + query + "], extras = [" + extras + "]");
- // TODO Implement this
+
+ // In case the user just says "Play music"
+ if(TextUtils.isEmpty(query)) {
+ List<PodcastItem> audioPodcasts = getAllPodcastItems();
+
+ // If there are any audio podcasts
+ if(audioPodcasts.size() > 0) {
+ PodcastItem podcastItem = audioPodcasts.get(0);
+ startPlayingPodcastItem(podcastItem);
+ }
+ } else {
+ // User is actually searching for something..
+ List<PodcastItem> audioPodcasts = getAllPodcastItems();
+ if(audioPodcasts.size() > 0) {
+ boolean foundMatching = false;
+ for(PodcastItem pi : audioPodcasts) {
+ if(pi.title.contains(query)) {
+ startPlayingPodcastItem(pi);
+ foundMatching = true;
+ break;
+ }
+ }
+
+ // in case we didn't find a matching podcast.. palay a random one
+ if(!foundMatching) {
+ PodcastItem podcastItem = audioPodcasts.get(0);
+ startPlayingPodcastItem(podcastItem);
+ }
+ }
+ }
super.onPlayFromSearch(query, extras);
}
@@ -666,12 +696,40 @@ public class PodcastPlaybackService extends MediaBrowserServiceCompat {
@Override
public void onSkipToNext() {
Log.d(TAG, "onSkipToNext() called");
+
+ MediaItem currentlyPlayingPodcast = getCurrentlyPlayingPodcast();
+ List<PodcastItem> podcastItems = getAllPodcastItems();
+
+ for(int i = 0; i < podcastItems.size(); i++) {
+ PodcastItem podcastItem = podcastItems.get(i);
+ if(podcastItem.itemId == currentlyPlayingPodcast.itemId) {
+ if(i+1 < podcastItems.size()) {
+ startPlayingPodcastItem(podcastItems.get(i+1));
+ }
+ break;
+ }
+ }
+
super.onSkipToNext();
}
@Override
public void onSkipToPrevious() {
Log.d(TAG, "onSkipToPrevious() called");
+
+ MediaItem currentlyPlayingPodcast = getCurrentlyPlayingPodcast();
+ List<PodcastItem> podcastItems = getAllPodcastItems();
+
+ for(int i = 0; i < podcastItems.size(); i++) {
+ PodcastItem podcastItem = podcastItems.get(i);
+ if(podcastItem.itemId == currentlyPlayingPodcast.itemId) {
+ if(i > 0) {
+ startPlayingPodcastItem(podcastItems.get(i-1));
+ }
+ break;
+ }
+ }
+
super.onSkipToPrevious();
}
@@ -700,6 +758,25 @@ public class PodcastPlaybackService extends MediaBrowserServiceCompat {
}
}
+ private void startPlayingPodcastItem(PodcastItem podcastItem) {
+ Intent intent = new Intent(PodcastPlaybackService.this, PodcastPlaybackService.class);
+ intent.putExtra(PodcastPlaybackService.MEDIA_ITEM, podcastItem);
+ startService(intent);
+ }
+
+ private List<PodcastItem> getAllPodcastItems() {
+ DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(PodcastPlaybackService.this);
+ List<PodcastItem> audioPodcasts= new ArrayList<>();
+ for(PodcastFeedItem podcastFeed : dbConn.getListOfFeedsWithAudioPodcasts()) {
+ long id = podcastFeed.mFeed.getId();
+ for(PodcastItem podcastItem : dbConn.getListOfAudioPodcastsForFeed(PodcastPlaybackService.this, id)) {
+
+ audioPodcasts.add(podcastItem);
+ }
+ }
+ return audioPodcasts;
+ }
+
private void initMediaSessions() {
//String packageName = PodcastNotificationToggle.class.getPackage().getName();