->
media = controller?.getMedia()
- if (media != null) {
- emitter.onSuccess(media!!)
- } else {
- emitter.onComplete()
- }
+ if (media != null) emitter.onSuccess(media!!)
+ else emitter.onComplete()
}.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ media: Playable ->
@@ -191,12 +188,41 @@ class PlayerDetailsFragment : Fragment() {
}, { error: Throwable? -> Log.e(TAG, Log.getStackTraceString(error)) })
}
+ fun buildHomeReaderText() {
+ showHomeText = !showHomeText
+ if (showHomeText) {
+ if (homeText == null && item?.link != null) {
+ runBlocking {
+ val url = item!!.link!!
+ val htmlSource = fetchHtmlSource(url)
+ val readability4J = Readability4J(item!!.link!!, htmlSource)
+ val article = readability4J.parse()
+ val readerhtml = article.contentWithDocumentsCharsetOrUtf8
+ if (readerhtml != null) {
+ val shownotesCleaner = ShownotesCleaner(requireContext(), readerhtml, 0)
+ homeText = shownotesCleaner.processShownotes()
+ }
+ }
+ }
+ if (homeText != null)
+ binding.webview.loadDataWithBaseURL("https://127.0.0.1", homeText!!, "text/html", "UTF-8", null)
+ } else {
+ val shownotesCleaner = ShownotesCleaner(requireContext(), item?.description ?: "", media?.getDuration()?:0)
+ cleanedNotes = shownotesCleaner.processShownotes()
+ if (cleanedNotes != null) binding.webview.loadDataWithBaseURL("https://127.0.0.1", cleanedNotes!!, "text/html", "UTF-8", null)
+ }
+ }
+
@UnstableApi private fun displayMediaInfo(media: Playable) {
val pubDateStr = DateFormatter.formatAbbrev(context, media.getPubDate())
binding.txtvPodcastTitle.text = StringUtils.stripToEmpty(media.getFeedTitle())
if (item == null || item!!.media?.getIdentifier() != media.getIdentifier()) {
if (media is FeedMedia) {
- item = media.item
+ if (item?.itemIdentifier != media.item?.itemIdentifier) {
+ item = media.item
+ showHomeText = false
+ homeText = null
+ }
if (item != null) {
val openFeed: Intent = MainActivity.getIntentToOpenFeed(requireContext(), item!!.feedId)
binding.txtvPodcastTitle.setOnClickListener { startActivity(openFeed) }
@@ -223,8 +249,7 @@ class PlayerDetailsFragment : Fragment() {
binding.txtvEpisodeTitle.scrollTo(0, 0)
}
})
- val fadeBackIn: ObjectAnimator = ObjectAnimator.ofFloat(
- binding.txtvEpisodeTitle, "alpha", 1f)
+ val fadeBackIn: ObjectAnimator = ObjectAnimator.ofFloat(binding.txtvEpisodeTitle, "alpha", 1f)
val set = AnimatorSet()
set.playSequentially(verticalMarquee, fadeOut, fadeBackIn)
set.start()
@@ -239,9 +264,7 @@ class PlayerDetailsFragment : Fragment() {
private fun updateChapterControlVisibility() {
var chapterControlVisible = false
when {
- media?.getChapters() != null -> {
- chapterControlVisible = media!!.getChapters().isNotEmpty()
- }
+ media?.getChapters() != null -> chapterControlVisible = media!!.getChapters().isNotEmpty()
media is FeedMedia -> {
val fm: FeedMedia? = (media as FeedMedia?)
// If an item has chapters but they are not loaded yet, still display the button.
@@ -310,23 +333,18 @@ class PlayerDetailsFragment : Fragment() {
if (controller == null || curr == null || displayedChapterIndex == -1) return
when {
- displayedChapterIndex < 1 -> {
- controller!!.seekTo(0)
- }
+ displayedChapterIndex < 1 -> controller!!.seekTo(0)
(controller!!.position - 10000 * controller!!.currentPlaybackSpeedMultiplier) < curr.start -> {
refreshChapterData(displayedChapterIndex - 1)
if (media != null) controller!!.seekTo(media!!.getChapters()[displayedChapterIndex].start.toInt())
}
- else -> {
- controller!!.seekTo(curr.start.toInt())
- }
+ else -> controller!!.seekTo(curr.start.toInt())
}
}
@UnstableApi private fun seekToNextChapter() {
- if (controller == null || media == null || media!!.getChapters().isEmpty() || displayedChapterIndex == -1 || displayedChapterIndex + 1 >= media!!.getChapters().size) {
- return
- }
+ if (controller == null || media == null || media!!.getChapters().isEmpty() || displayedChapterIndex == -1
+ || displayedChapterIndex + 1 >= media!!.getChapters().size) return
refreshChapterData(displayedChapterIndex + 1)
controller!!.seekTo(media!!.getChapters()[displayedChapterIndex].start.toInt())
@@ -393,7 +411,11 @@ class PlayerDetailsFragment : Fragment() {
fun setItem(item_: FeedItem) {
Log.d(TAG, "setItem ${item_.title}")
- item = item_
+ if (item?.itemIdentifier != item_.itemIdentifier) {
+ item = item_
+ showHomeText = false
+ homeText = null
+ }
}
// override fun onConfigurationChanged(newConfig: Configuration) {
diff --git a/app/src/main/java/ac/mdiq/podcini/ui/utils/ShownotesCleaner.kt b/app/src/main/java/ac/mdiq/podcini/ui/utils/ShownotesCleaner.kt
index ccc5c907..0383c5f4 100644
--- a/app/src/main/java/ac/mdiq/podcini/ui/utils/ShownotesCleaner.kt
+++ b/app/src/main/java/ac/mdiq/podcini/ui/utils/ShownotesCleaner.kt
@@ -64,9 +64,8 @@ class ShownotesCleaner(context: Context, private val rawShownotes: String, priva
}
// replace ASCII line breaks with HTML ones if shownotes don't contain HTML line breaks already
- if (!LINE_BREAK_REGEX.matcher(shownotes).find() && !shownotes.contains("")) {
+ if (!LINE_BREAK_REGEX.matcher(shownotes).find() && !shownotes.contains("
"))
shownotes = shownotes.replace("\n", "
")
- }
val document = Jsoup.parse(shownotes)
cleanCss(document)
@@ -79,10 +78,8 @@ class ShownotesCleaner(context: Context, private val rawShownotes: String, priva
val elementsWithTimeCodes = document.body().getElementsMatchingOwnText(TIMECODE_REGEX)
Log.d(TAG, "Recognized " + elementsWithTimeCodes.size + " timecodes")
- if (elementsWithTimeCodes.size == 0) {
- // No elements with timecodes
- return
- }
+ if (elementsWithTimeCodes.size == 0) return // No elements with timecodes
+
var useHourFormat = true
if (playableDuration != Int.MAX_VALUE) {
@@ -107,9 +104,7 @@ class ShownotesCleaner(context: Context, private val rawShownotes: String, priva
}
}
- if (!useHourFormat) {
- break
- }
+ if (!useHourFormat) break
}
}
diff --git a/app/src/main/java/ac/mdiq/podcini/ui/widget/WidgetUpdater.kt b/app/src/main/java/ac/mdiq/podcini/ui/widget/WidgetUpdater.kt
index be13e7e6..03a17608 100644
--- a/app/src/main/java/ac/mdiq/podcini/ui/widget/WidgetUpdater.kt
+++ b/app/src/main/java/ac/mdiq/podcini/ui/widget/WidgetUpdater.kt
@@ -136,10 +136,10 @@ object WidgetUpdater {
} else {
views.setViewVisibility(R.id.layout_center, View.VISIBLE)
}
- val showPlaybackSpeed = prefs.getBoolean(PlayerWidget.KEY_WIDGET_PLAYBACK_SPEED + id, false)
- val showRewind = prefs.getBoolean(PlayerWidget.KEY_WIDGET_REWIND + id, false)
- val showFastForward = prefs.getBoolean(PlayerWidget.KEY_WIDGET_FAST_FORWARD + id, false)
- val showSkip = prefs.getBoolean(PlayerWidget.KEY_WIDGET_SKIP + id, false)
+ val showPlaybackSpeed = prefs.getBoolean(PlayerWidget.KEY_WIDGET_PLAYBACK_SPEED + id, true)
+ val showRewind = prefs.getBoolean(PlayerWidget.KEY_WIDGET_REWIND + id, true)
+ val showFastForward = prefs.getBoolean(PlayerWidget.KEY_WIDGET_FAST_FORWARD + id, true)
+ val showSkip = prefs.getBoolean(PlayerWidget.KEY_WIDGET_SKIP + id, true)
if (showPlaybackSpeed || showRewind || showSkip || showFastForward) {
views.setInt(R.id.extendedButtonsContainer, "setVisibility", View.VISIBLE)
diff --git a/app/src/main/java/ac/mdiq/podcini/ui/widget/WidgetUpdaterWorker.kt b/app/src/main/java/ac/mdiq/podcini/ui/widget/WidgetUpdaterWorker.kt
index 1212d007..f3367266 100644
--- a/app/src/main/java/ac/mdiq/podcini/ui/widget/WidgetUpdaterWorker.kt
+++ b/app/src/main/java/ac/mdiq/podcini/ui/widget/WidgetUpdaterWorker.kt
@@ -8,9 +8,8 @@ import ac.mdiq.podcini.preferences.PlaybackPreferences.Companion.createInstanceF
import ac.mdiq.podcini.ui.widget.WidgetUpdater.WidgetState
import ac.mdiq.podcini.playback.base.PlayerStatus
-class WidgetUpdaterWorker(context: Context,
- workerParams: WorkerParameters
-) : Worker(context, workerParams) {
+class WidgetUpdaterWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) {
+
override fun doWork(): Result {
try {
updateWidget()
@@ -27,13 +26,9 @@ class WidgetUpdaterWorker(context: Context,
private fun updateWidget() {
val media = createInstanceFromPreferences(applicationContext)
if (media != null) {
- WidgetUpdater.updateWidget(applicationContext,
- WidgetState(media, PlayerStatus.STOPPED,
- media.getPosition(), media.getDuration(),
- getCurrentPlaybackSpeed(media)))
+ WidgetUpdater.updateWidget(applicationContext, WidgetState(media, PlayerStatus.STOPPED, media.getPosition(), media.getDuration(), getCurrentPlaybackSpeed(media)))
} else {
- WidgetUpdater.updateWidget(applicationContext,
- WidgetState(PlayerStatus.STOPPED))
+ WidgetUpdater.updateWidget(applicationContext, WidgetState(PlayerStatus.STOPPED))
}
}
diff --git a/app/src/main/res/layout/episode_home_fragment.xml b/app/src/main/res/layout/episode_home_fragment.xml
index 8400d222..5242f781 100644
--- a/app/src/main/res/layout/episode_home_fragment.xml
+++ b/app/src/main/res/layout/episode_home_fragment.xml
@@ -23,4 +23,10 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
+
+
\ No newline at end of file
diff --git a/app/src/main/res/menu/mediaplayer.xml b/app/src/main/res/menu/mediaplayer.xml
index 594888c8..82ce95c4 100644
--- a/app/src/main/res/menu/mediaplayer.xml
+++ b/app/src/main/res/menu/mediaplayer.xml
@@ -2,6 +2,13 @@