Skip to content

Commit

Permalink
null safety tuning and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
XilinJia committed Feb 17, 2024
1 parent 0e36e6f commit 45abbd3
Show file tree
Hide file tree
Showing 92 changed files with 2,062 additions and 2,101 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PodVinci is an open source podcast manager/player project.

This is based on a fork from the popular project AntennaPod (https://github.com/AntennaPod/AntennaPod) as of Feb 5 2024.

This project is purely Kotlin based, relies on the most recent dependencies, and most importantly has migrated the media player to androidx.media3, and added mechanism of AudioOffloadMode which is supposed to be kind to device battery. App build is also upgraded to target Android 14.
Differing from the forked project, this project is purely Kotlin based, relies on the most recent dependencies, and most importantly has migrated the media player to androidx.media3, and added mechanism of AudioOffloadMode which is supposed to be kind to device battery. Efficiencies are also sought on running the app. App build is also upgraded to target Android 14.

## Privacy Policy

Expand Down
8 changes: 7 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

<supports-screens
Expand Down Expand Up @@ -43,6 +42,13 @@
android:allowAudioPlaybackCapture="true"
android:networkSecurityConfig="@xml/network_security_config">

<!-- <service-->
<!-- android:name=".core.service.playback.PlaybackService"-->
<!-- android:foregroundServiceType="mediaPlayback"-->
<!-- android:exported="false"-->
<!-- tools:replace="android:exported">-->
<!-- </service>-->

<activity
android:name=".activity.PlaybackSpeedDialogActivity"
android:noHistory="true"
Expand Down
112 changes: 54 additions & 58 deletions app/src/main/java/ac/mdiq/podvinci/activity/OnlineFeedViewActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,20 @@ class OnlineFeedViewActivity : AppCompatActivity() {
private var parser: Disposable? = null
private var updater: Disposable? = null

private var headerBinding: OnlinefeedviewHeaderBinding? = null
private var viewBinding: OnlinefeedviewActivityBinding? = null
private lateinit var headerBinding: OnlinefeedviewHeaderBinding
private lateinit var viewBinding: OnlinefeedviewActivityBinding

override fun onCreate(savedInstanceState: Bundle?) {
setTheme(getTranslucentTheme(this))
super.onCreate(savedInstanceState)

viewBinding = OnlinefeedviewActivityBinding.inflate(layoutInflater)
setContentView(viewBinding!!.root)
setContentView(viewBinding.root)

viewBinding!!.transparentBackground.setOnClickListener { v: View? -> finish() }
viewBinding!!.closeButton.setOnClickListener { view: View? -> finish() }
viewBinding!!.card.setOnClickListener(null)
viewBinding!!.card.setCardBackgroundColor(getColorFromAttr(this, R.attr.colorSurface))
viewBinding.transparentBackground.setOnClickListener { v: View? -> finish() }
viewBinding.closeButton.setOnClickListener { view: View? -> finish() }
viewBinding.card.setOnClickListener(null)
viewBinding.card.setCardBackgroundColor(getColorFromAttr(this, R.attr.colorSurface))
headerBinding = OnlinefeedviewHeaderBinding.inflate(layoutInflater)

var feedUrl: String? = null
Expand Down Expand Up @@ -165,8 +165,8 @@ class OnlineFeedViewActivity : AppCompatActivity() {
* Displays a progress indicator.
*/
private fun setLoadingLayout() {
viewBinding!!.progressBar.visibility = View.VISIBLE
viewBinding!!.feedDisplayContainer.visibility = View.GONE
viewBinding.progressBar.visibility = View.VISIBLE
viewBinding.feedDisplayContainer.visibility = View.GONE
}

override fun onStart() {
Expand All @@ -189,15 +189,9 @@ class OnlineFeedViewActivity : AppCompatActivity() {

public override fun onDestroy() {
super.onDestroy()
if (updater != null) {
updater!!.dispose()
}
if (download != null) {
download!!.dispose()
}
if (parser != null) {
parser!!.dispose()
}
updater?.dispose()
download?.dispose()
parser?.dispose()
}

override fun onSaveInstanceState(outState: Bundle) {
Expand Down Expand Up @@ -264,8 +258,9 @@ class OnlineFeedViewActivity : AppCompatActivity() {
val results = searcher.search(query)?.blockingGet()
if (results.isNullOrEmpty()) return null
for (result in results) {
if (result?.feedUrl != null && result.author != null && result.author.equals(artistName,
ignoreCase = true) && result.title.equals(trackName, ignoreCase = true)) {
if (result?.feedUrl != null && result.author != null &&
result.author.equals(artistName, ignoreCase = true) &&
result.title.equals(trackName, ignoreCase = true)) {
return result.feedUrl
}
}
Expand Down Expand Up @@ -301,7 +296,7 @@ class OnlineFeedViewActivity : AppCompatActivity() {
if (username != null && password != null) {
Toast.makeText(this, R.string.download_error_unauthorized, Toast.LENGTH_LONG).show()
}
if (downloader!!.downloadRequest.source != null) {
if (downloader?.downloadRequest?.source != null) {
dialog = FeedViewAuthenticationDialog(this@OnlineFeedViewActivity,
R.string.authentication_notification_title, downloader!!.downloadRequest.source!!).create()
dialog?.show()
Expand Down Expand Up @@ -376,8 +371,7 @@ class OnlineFeedViewActivity : AppCompatActivity() {
} else {
throw UnsupportedFeedtypeException(getString(R.string.download_error_unsupported_type_html))
}
}
else null
} else null
} else {
throw e
}
Expand All @@ -395,18 +389,18 @@ class OnlineFeedViewActivity : AppCompatActivity() {
* This method is executed on the GUI thread.
*/
@UnstableApi private fun showFeedInformation(feed: Feed, alternateFeedUrls: Map<String, String>) {
viewBinding!!.progressBar.visibility = View.GONE
viewBinding!!.feedDisplayContainer.visibility = View.VISIBLE
viewBinding.progressBar.visibility = View.GONE
viewBinding.feedDisplayContainer.visibility = View.VISIBLE
if (isFeedFoundBySearch) {
val resId = R.string.no_feed_url_podcast_found_by_search
Snackbar.make(findViewById(android.R.id.content), resId, Snackbar.LENGTH_LONG).show()
}

viewBinding!!.backgroundImage.colorFilter = LightingColorFilter(-0x7d7d7e, 0x000000)
viewBinding.backgroundImage.colorFilter = LightingColorFilter(-0x7d7d7e, 0x000000)

viewBinding!!.listView.addHeaderView(headerBinding!!.root)
viewBinding!!.listView.setSelector(android.R.color.transparent)
viewBinding!!.listView.adapter = FeedItemlistDescriptionAdapter(this, 0, feed.items)
viewBinding.listView.addHeaderView(headerBinding.root)
viewBinding.listView.setSelector(android.R.color.transparent)
viewBinding.listView.adapter = FeedItemlistDescriptionAdapter(this, 0, feed.items)

if (StringUtils.isNotBlank(feed.imageUrl)) {
Glide.with(this)
Expand All @@ -416,22 +410,22 @@ class OnlineFeedViewActivity : AppCompatActivity() {
.error(R.color.light_gray)
.fitCenter()
.dontAnimate())
.into(viewBinding!!.coverImage)
.into(viewBinding.coverImage)
Glide.with(this)
.load(feed.imageUrl)
.apply(RequestOptions()
.placeholder(R.color.image_readability_tint)
.error(R.color.image_readability_tint)
.transform(FastBlurTransformation())
.dontAnimate())
.into(viewBinding!!.backgroundImage)
.into(viewBinding.backgroundImage)
}

viewBinding!!.titleLabel.text = feed.title
viewBinding!!.authorLabel.text = feed.author
headerBinding!!.txtvDescription.text = HtmlToPlainText.getPlainText(feed.description)
viewBinding.titleLabel.text = feed.title
viewBinding.authorLabel.text = feed.author
headerBinding.txtvDescription.text = HtmlToPlainText.getPlainText(feed.description)

viewBinding!!.subscribeButton.setOnClickListener { v: View? ->
viewBinding.subscribeButton.setOnClickListener { v: View? ->
if (feedInFeedlist()) {
openFeed()
} else {
Expand All @@ -441,29 +435,29 @@ class OnlineFeedViewActivity : AppCompatActivity() {
}
}

viewBinding!!.stopPreviewButton.setOnClickListener { v: View? ->
viewBinding.stopPreviewButton.setOnClickListener { v: View? ->
writeNoMediaPlaying()
sendLocalBroadcast(this, PlaybackServiceInterface.ACTION_SHUTDOWN_PLAYBACK_SERVICE)
}

if (isEnableAutodownload) {
val preferences = getSharedPreferences(PREFS, MODE_PRIVATE)
viewBinding!!.autoDownloadCheckBox.isChecked = preferences.getBoolean(PREF_LAST_AUTO_DOWNLOAD, true)
viewBinding.autoDownloadCheckBox.isChecked = preferences.getBoolean(PREF_LAST_AUTO_DOWNLOAD, true)
}

headerBinding!!.txtvDescription.maxLines = DESCRIPTION_MAX_LINES_COLLAPSED
headerBinding!!.txtvDescription.setOnClickListener { v: View? ->
if (headerBinding!!.txtvDescription.maxLines > DESCRIPTION_MAX_LINES_COLLAPSED) {
headerBinding!!.txtvDescription.maxLines = DESCRIPTION_MAX_LINES_COLLAPSED
headerBinding.txtvDescription.maxLines = DESCRIPTION_MAX_LINES_COLLAPSED
headerBinding.txtvDescription.setOnClickListener { v: View? ->
if (headerBinding.txtvDescription.maxLines > DESCRIPTION_MAX_LINES_COLLAPSED) {
headerBinding.txtvDescription.maxLines = DESCRIPTION_MAX_LINES_COLLAPSED
} else {
headerBinding!!.txtvDescription.maxLines = 2000
headerBinding.txtvDescription.maxLines = 2000
}
}

if (alternateFeedUrls.isEmpty()) {
viewBinding!!.alternateUrlsSpinner.visibility = View.GONE
viewBinding.alternateUrlsSpinner.visibility = View.GONE
} else {
viewBinding!!.alternateUrlsSpinner.visibility = View.VISIBLE
viewBinding.alternateUrlsSpinner.visibility = View.VISIBLE

val alternateUrlsList: MutableList<String> = ArrayList()
val alternateUrlsTitleList: MutableList<String?> = ArrayList()
Expand All @@ -486,8 +480,8 @@ class OnlineFeedViewActivity : AppCompatActivity() {
}

adapter.setDropDownViewResource(R.layout.alternate_urls_dropdown_item)
viewBinding!!.alternateUrlsSpinner.adapter = adapter
viewBinding!!.alternateUrlsSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
viewBinding.alternateUrlsSpinner.adapter = adapter
viewBinding.alternateUrlsSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View, position: Int, id: Long) {
selectedDownloadUrl = alternateUrlsList[position]
}
Expand All @@ -510,21 +504,23 @@ class OnlineFeedViewActivity : AppCompatActivity() {
}

@UnstableApi private fun handleUpdatedFeedStatus() {
if (DownloadServiceInterface.get() == null || selectedDownloadUrl == null) return
if (DownloadServiceInterface.get()!!.isDownloadingEpisode(selectedDownloadUrl!!)) {
viewBinding!!.subscribeButton.isEnabled = false
viewBinding!!.subscribeButton.setText(R.string.subscribing_label)
val dli = DownloadServiceInterface.get()
if (dli == null || selectedDownloadUrl == null) return

if (dli.isDownloadingEpisode(selectedDownloadUrl!!)) {
viewBinding.subscribeButton.isEnabled = false
viewBinding.subscribeButton.setText(R.string.subscribing_label)
} else if (feedInFeedlist()) {
viewBinding!!.subscribeButton.isEnabled = true
viewBinding!!.subscribeButton.setText(R.string.open_podcast)
viewBinding.subscribeButton.isEnabled = true
viewBinding.subscribeButton.setText(R.string.open_podcast)
if (didPressSubscribe) {
didPressSubscribe = false

val feed1 = DBReader.getFeed(feedId)?: return
val feedPreferences = feed1.preferences
if (feedPreferences != null) {
if (isEnableAutodownload) {
val autoDownload = viewBinding!!.autoDownloadCheckBox.isChecked
val autoDownload = viewBinding.autoDownloadCheckBox.isChecked
feedPreferences.autoDownload = autoDownload

val preferences = getSharedPreferences(PREFS, MODE_PRIVATE)
Expand All @@ -541,10 +537,10 @@ class OnlineFeedViewActivity : AppCompatActivity() {
openFeed()
}
} else {
viewBinding!!.subscribeButton.isEnabled = true
viewBinding!!.subscribeButton.setText(R.string.subscribe_label)
viewBinding.subscribeButton.isEnabled = true
viewBinding.subscribeButton.setText(R.string.subscribe_label)
if (isEnableAutodownload) {
viewBinding!!.autoDownloadCheckBox.visibility = View.VISIBLE
viewBinding.autoDownloadCheckBox.visibility = View.VISIBLE
}
}
}
Expand Down Expand Up @@ -622,7 +618,7 @@ class OnlineFeedViewActivity : AppCompatActivity() {
@Subscribe(threadMode = ThreadMode.MAIN)
fun playbackStateChanged(event: PlayerStatusEvent?) {
val isPlayingPreview = currentlyPlayingMediaType == RemoteMedia.PLAYABLE_TYPE_REMOTE_MEDIA.toLong()
viewBinding!!.stopPreviewButton.visibility = if (isPlayingPreview) View.VISIBLE else View.GONE
viewBinding.stopPreviewButton.visibility = if (isPlayingPreview) View.VISIBLE else View.GONE
}

/**
Expand All @@ -631,7 +627,7 @@ class OnlineFeedViewActivity : AppCompatActivity() {
*/
private fun showFeedDiscoveryDialog(feedFile: File, baseUrl: String): Boolean {
val fd = FeedDiscoverer()
val urlsMap: Map<String, String>?
val urlsMap: Map<String, String>
try {
urlsMap = fd.findLinks(feedFile, baseUrl)
if (urlsMap.isEmpty()) {
Expand Down
Loading

0 comments on commit 45abbd3

Please sign in to comment.