Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External player support #1130

Merged
merged 2 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ private void share(int currentPosition) {
*/
private void startTTS(int currentPosition) {
RssItem rssItem = rssItems.get(currentPosition);
String text = rssItem.getTitle() + "\n\n " + Html.fromHtml(rssItem.getBody()).toString();
String text = rssItem.getTitle() + ". " + Html.fromHtml(rssItem.getBody()).toString();
// Log.d(TAG, text);
TTSItem ttsItem = new TTSItem(rssItem.getId(), rssItem.getAuthor(), rssItem.getTitle(), text, rssItem.getFeed().getFaviconUrl());
openMediaItem(ttsItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.FileProvider;

import com.nextcloud.android.sso.helper.VersionCheckHelper;
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
Expand Down Expand Up @@ -258,19 +259,28 @@ private float dipToPx(@SuppressWarnings("SameParameterValue") float dip) {

@VisibleForTesting
public void openMediaItem(final MediaItem mediaItem) {
Intent intent = new Intent(this, PodcastPlaybackService.class);
intent.putExtra(PodcastPlaybackService.MEDIA_ITEM, mediaItem);
startService(intent);

/*
if(!mMediaBrowser.isConnected()) {
mMediaBrowser.connect();
}
*/

if (mPrefs.getBoolean(SettingsActivity.CB_EXTERNAL_PLAYER, false) && mediaItem instanceof PodcastItem) {
// PodcastItems can be audio or video
Uri uri = ((PodcastItem) mediaItem).offlineCached // in case it's locally cached (offline)
? FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider", new File(mediaItem.link))
: Uri.parse(mediaItem.link);

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, ((PodcastItem) mediaItem).mimeType);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
} else {
// in case the user wants to use the internal player or we have a TTS item (text to speech)
Intent intent = new Intent(this, PodcastPlaybackService.class);
intent.putExtra(PodcastPlaybackService.MEDIA_ITEM, mediaItem);
startService(intent);

//bindService(intent, mConnection, Context.BIND_AUTO_CREATE);

// if(!mMediaBrowser.isConnected()) {
// mMediaBrowser.connect();
// }
// bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public class SettingsActivity extends AppCompatActivity {
public static final String SP_APP_THEME = "sp_app_theme";
public static final String CB_OLED_MODE = "cb_oled_mode";

public static final String CB_EXTERNAL_PLAYER = "cb_external_player";

public static final String SP_FEED_LIST_LAYOUT = "sp_feed_list_layout"; // used for shared prefs
public static final String RI_FEED_LIST_LAYOUT = "ai_feed_list_layout"; // used for result intents
public static final String SP_FONT_SIZE = "sp_font_size";
Expand Down
3 changes: 3 additions & 0 deletions News-Android-App/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@
<string name="pref_oled_mode">Schwarzer Hintergrund</string>
<string name="pref_oled_mode_summary">Für dunkles Design auf OLED-Bildschirmen</string>

<string name="pref_external_player">Externes Wiedergabeprogramm</string>
<string name="pref_external_player_summary">Spiele Podcasts in der standard-Applikation</string>

<string name="pref_display_browser_cct">Integrierte angepasste Chrome-Tabs</string>
<string name="pref_display_browser_built_in">Integrierter Browser</string>
<string name="pref_display_browser_external">Externer Browser</string>
Expand Down
3 changes: 3 additions & 0 deletions News-Android-App/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@
<string name="pref_oled_mode">Black background</string>
<string name="pref_oled_mode_summary">For dark theme on OLED screens</string>

<string name="pref_external_player">External Player</string>
<string name="pref_external_player_summary">Play podcasts in your default media app</string>

<string-array name="pref_title_lines_count" translatable="false">
<item>1</item>
<item>2</item>
Expand Down
7 changes: 7 additions & 0 deletions News-Android-App/src/main/res/xml/pref_display.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@
android:title="@string/pref_display_browser"
app:iconSpaceReserved="false"/>

<SwitchPreference
android:key="cb_external_player"
android:title="@string/pref_external_player"
android:summary="@string/pref_external_player_summary"
android:defaultValue="false"
app:iconSpaceReserved="false"/>

<MultiSelectListPreference
android:entries="@array/pref_display_news_detail_actionbar_icons"
android:entryValues="@array/pref_display_news_detail_actionbar_icons_values"
Expand Down