Skip to content

Commit

Permalink
minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
XilinJia committed Feb 21, 2024
1 parent 824893c commit 31624b7
Show file tree
Hide file tree
Showing 84 changed files with 710 additions and 672 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ object EspressoTestUtils {
init(InstrumentationRegistry.getInstrumentation().targetContext)
deleteDatabase()
val adapter = getInstance()
adapter!!.open()
adapter.open()
adapter.close()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ class PlaybackServiceMediaPlayerTest {
f.preferences = prefs
f.items = mutableListOf()
val i = FeedItem(0, "t", "i", "l", Date(), FeedItem.UNPLAYED, f)
f.items!!.add(i)
f.items.add(i)
val media = FeedMedia(0, i, 0, 0, 0, "audio/wav", fileUrl, downloadUrl, fileUrl != null, null, 0, 0)
i.setMedia(media)
val adapter = getInstance()
adapter!!.open()
adapter.open()
adapter.setCompleteFeed(f)
Assert.assertTrue(media.id != 0L)
adapter.close()
Expand All @@ -130,14 +130,18 @@ class PlaybackServiceMediaPlayerTest {
try {
checkPSMPInfo(newInfo)
check(newInfo!!.playerStatus != PlayerStatus.ERROR) { "MediaPlayer error" }
if (countDownLatch.count == 0L) {
Assert.fail()
} else if (countDownLatch.count == 2L) {
Assert.assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus)
countDownLatch.countDown()
} else {
Assert.assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus)
countDownLatch.countDown()
when (countDownLatch.count) {
0L -> {
Assert.fail()
}
2L -> {
Assert.assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus)
countDownLatch.countDown()
}
else -> {
Assert.assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus)
countDownLatch.countDown()
}
}
} catch (e: AssertionFailedError) {
if (assertionError == null) assertionError = e
Expand Down Expand Up @@ -168,14 +172,18 @@ class PlaybackServiceMediaPlayerTest {
try {
checkPSMPInfo(newInfo)
check(newInfo!!.playerStatus != PlayerStatus.ERROR) { "MediaPlayer error" }
if (countDownLatch.count == 0L) {
Assert.fail()
} else if (countDownLatch.count == 2L) {
Assert.assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus)
countDownLatch.countDown()
} else {
Assert.assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus)
countDownLatch.countDown()
when (countDownLatch.count) {
0L -> {
Assert.fail()
}
2L -> {
Assert.assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus)
countDownLatch.countDown()
}
else -> {
Assert.assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus)
countDownLatch.countDown()
}
}
} catch (e: AssertionFailedError) {
if (assertionError == null) assertionError = e
Expand Down Expand Up @@ -207,16 +215,22 @@ class PlaybackServiceMediaPlayerTest {
try {
checkPSMPInfo(newInfo)
check(newInfo!!.playerStatus != PlayerStatus.ERROR) { "MediaPlayer error" }
if (countDownLatch.count == 0L) {
Assert.fail()
} else if (countDownLatch.count == 4L) {
Assert.assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus)
} else if (countDownLatch.count == 3L) {
Assert.assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus)
} else if (countDownLatch.count == 2L) {
Assert.assertEquals(PlayerStatus.PREPARING, newInfo.playerStatus)
} else if (countDownLatch.count == 1L) {
Assert.assertEquals(PlayerStatus.PREPARED, newInfo.playerStatus)
when (countDownLatch.count) {
0L -> {
Assert.fail()
}
4L -> {
Assert.assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus)
}
3L -> {
Assert.assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus)
}
2L -> {
Assert.assertEquals(PlayerStatus.PREPARING, newInfo.playerStatus)
}
1L -> {
Assert.assertEquals(PlayerStatus.PREPARED, newInfo.playerStatus)
}
}
countDownLatch.countDown()
} catch (e: AssertionFailedError) {
Expand Down Expand Up @@ -247,18 +261,25 @@ class PlaybackServiceMediaPlayerTest {
try {
checkPSMPInfo(newInfo)
check(newInfo!!.playerStatus != PlayerStatus.ERROR) { "MediaPlayer error" }
if (countDownLatch.count == 0L) {
Assert.fail()
} else if (countDownLatch.count == 5L) {
Assert.assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus)
} else if (countDownLatch.count == 4L) {
Assert.assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus)
} else if (countDownLatch.count == 3L) {
Assert.assertEquals(PlayerStatus.PREPARING, newInfo.playerStatus)
} else if (countDownLatch.count == 2L) {
Assert.assertEquals(PlayerStatus.PREPARED, newInfo.playerStatus)
} else if (countDownLatch.count == 1L) {
Assert.assertEquals(PlayerStatus.PLAYING, newInfo.playerStatus)
when (countDownLatch.count) {
0L -> {
Assert.fail()
}
5L -> {
Assert.assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus)
}
4L -> {
Assert.assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus)
}
3L -> {
Assert.assertEquals(PlayerStatus.PREPARING, newInfo.playerStatus)
}
2L -> {
Assert.assertEquals(PlayerStatus.PREPARED, newInfo.playerStatus)
}
1L -> {
Assert.assertEquals(PlayerStatus.PLAYING, newInfo.playerStatus)
}
}
countDownLatch.countDown()
} catch (e: AssertionFailedError) {
Expand Down Expand Up @@ -288,14 +309,18 @@ class PlaybackServiceMediaPlayerTest {
try {
checkPSMPInfo(newInfo)
check(newInfo!!.playerStatus != PlayerStatus.ERROR) { "MediaPlayer error" }
if (countDownLatch.count == 0L) {
Assert.fail()
} else if (countDownLatch.count == 2L) {
Assert.assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus)
countDownLatch.countDown()
} else {
Assert.assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus)
countDownLatch.countDown()
when (countDownLatch.count) {
0L -> {
Assert.fail()
}
2L -> {
Assert.assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus)
countDownLatch.countDown()
}
else -> {
Assert.assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus)
countDownLatch.countDown()
}
}
} catch (e: AssertionFailedError) {
if (assertionError == null) assertionError = e
Expand Down Expand Up @@ -325,14 +350,18 @@ class PlaybackServiceMediaPlayerTest {
try {
checkPSMPInfo(newInfo)
check(newInfo!!.playerStatus != PlayerStatus.ERROR) { "MediaPlayer error" }
if (countDownLatch.count == 0L) {
Assert.fail()
} else if (countDownLatch.count == 2L) {
Assert.assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus)
countDownLatch.countDown()
} else {
Assert.assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus)
countDownLatch.countDown()
when (countDownLatch.count) {
0L -> {
Assert.fail()
}
2L -> {
Assert.assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus)
countDownLatch.countDown()
}
else -> {
Assert.assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus)
countDownLatch.countDown()
}
}
} catch (e: AssertionFailedError) {
if (assertionError == null) assertionError = e
Expand Down Expand Up @@ -362,16 +391,22 @@ class PlaybackServiceMediaPlayerTest {
try {
checkPSMPInfo(newInfo)
check(newInfo!!.playerStatus != PlayerStatus.ERROR) { "MediaPlayer error" }
if (countDownLatch.count == 0L) {
Assert.fail()
} else if (countDownLatch.count == 4L) {
Assert.assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus)
} else if (countDownLatch.count == 3L) {
Assert.assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus)
} else if (countDownLatch.count == 2L) {
Assert.assertEquals(PlayerStatus.PREPARING, newInfo.playerStatus)
} else if (countDownLatch.count == 1L) {
Assert.assertEquals(PlayerStatus.PREPARED, newInfo.playerStatus)
when (countDownLatch.count) {
0L -> {
Assert.fail()
}
4L -> {
Assert.assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus)
}
3L -> {
Assert.assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus)
}
2L -> {
Assert.assertEquals(PlayerStatus.PREPARING, newInfo.playerStatus)
}
1L -> {
Assert.assertEquals(PlayerStatus.PREPARED, newInfo.playerStatus)
}
}
countDownLatch.countDown()
} catch (e: AssertionFailedError) {
Expand Down Expand Up @@ -401,18 +436,25 @@ class PlaybackServiceMediaPlayerTest {
try {
checkPSMPInfo(newInfo)
check(newInfo!!.playerStatus != PlayerStatus.ERROR) { "MediaPlayer error" }
if (countDownLatch.count == 0L) {
Assert.fail()
} else if (countDownLatch.count == 5L) {
Assert.assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus)
} else if (countDownLatch.count == 4L) {
Assert.assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus)
} else if (countDownLatch.count == 3L) {
Assert.assertEquals(PlayerStatus.PREPARING, newInfo.playerStatus)
} else if (countDownLatch.count == 2L) {
Assert.assertEquals(PlayerStatus.PREPARED, newInfo.playerStatus)
} else if (countDownLatch.count == 1L) {
Assert.assertEquals(PlayerStatus.PLAYING, newInfo.playerStatus)
when (countDownLatch.count) {
0L -> {
Assert.fail()
}
5L -> {
Assert.assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus)
}
4L -> {
Assert.assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus)
}
3L -> {
Assert.assertEquals(PlayerStatus.PREPARING, newInfo.playerStatus)
}
2L -> {
Assert.assertEquals(PlayerStatus.PREPARED, newInfo.playerStatus)
}
1L -> {
Assert.assertEquals(PlayerStatus.PLAYING, newInfo.playerStatus)
}
}
} catch (e: AssertionFailedError) {
if (assertionError == null) assertionError = e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class PlaybackServiceTaskManagerTest {
init(context)
deleteDatabase()
val adapter = getInstance()
adapter!!.open()
adapter.open()
adapter.close()
setShakeToReset(false)
setVibrate(false)
Expand All @@ -61,15 +61,15 @@ class PlaybackServiceTaskManagerTest {
val f = Feed(0, null, "title", "link", "d", null, null, null, null, "id", null, "null", "url", false)
f.items = mutableListOf()
for (i in 0 until NUM_ITEMS) {
f.items!!.add(FeedItem(0, pref + i, pref + i, "link", Date(), FeedItem.PLAYED, f))
f.items.add(FeedItem(0, pref + i, pref + i, "link", Date(), FeedItem.PLAYED, f))
}
val adapter = getInstance()
adapter!!.open()
adapter.open()
adapter.setCompleteFeed(f)
adapter.setQueue(f.items!!)
adapter.setQueue(f.items)
adapter.close()

for (item in f.items!!) {
for (item in f.items) {
Assert.assertTrue(item.id != 0L)
}
return f.items
Expand Down
2 changes: 1 addition & 1 deletion app/src/androidTest/java/ac/test/podcini/ui/UITestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class UITestUtils(private val context: Context) {
localFeedDataAdded = true

val adapter = getInstance()
adapter!!.open()
adapter.open()
adapter.setCompleteFeed(*hostedFeeds.toTypedArray<Feed>())
adapter.setQueue(queue)
adapter.close()
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/ac/mdiq/podcini/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.google.android.material.snackbar.Snackbar
import ac.mdiq.podcini.R
import ac.mdiq.podcini.core.preferences.ThemeSwitcher.getNoTitleTheme
import ac.mdiq.podcini.core.receiver.MediaButtonReceiver.Companion.createIntent
import ac.mdiq.podcini.core.storage.DBReader
import ac.mdiq.podcini.core.sync.queue.SynchronizationQueueSink
import ac.mdiq.podcini.core.util.download.FeedUpdateManager
import ac.mdiq.podcini.core.util.download.FeedUpdateManager.restartUpdateAlarm
Expand Down Expand Up @@ -103,6 +104,8 @@ class MainActivity : CastEnabledActivity() {
.build()
}

DBReader.updateFeedList()

val fm = supportFragmentManager
if (fm.findFragmentByTag(MAIN_FRAGMENT_TAG) == null) {
if (UserPreferences.DEFAULT_PAGE_REMEMBER != defaultPage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ class OnlineFeedViewActivity : AppCompatActivity() {

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

viewBinding.subscribeButton.setOnClickListener { v: View? ->
if (feedInFeedlist()) {
Expand Down
44 changes: 22 additions & 22 deletions app/src/main/java/ac/mdiq/podcini/activity/VideoplayerActivity.kt
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
package ac.mdiq.podcini.activity

import ac.mdiq.podcini.activity.MainActivity
import android.content.DialogInterface
import android.content.Intent
import android.graphics.PixelFormat
import android.graphics.drawable.ColorDrawable
import android.media.AudioManager
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.view.*
import android.view.View.OnTouchListener
import android.view.animation.*
import android.widget.EditText
import android.widget.FrameLayout
import android.widget.SeekBar
import android.widget.SeekBar.OnSeekBarChangeListener
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
import androidx.media3.common.util.UnstableApi
import com.bumptech.glide.Glide
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import ac.mdiq.podcini.R
import ac.mdiq.podcini.activity.MainActivity
import ac.mdiq.podcini.core.service.playback.PlaybackService.Companion.getPlayerActivityIntent
import ac.mdiq.podcini.core.service.playback.PlaybackService.Companion.isCasting
import ac.mdiq.podcini.core.storage.DBReader
Expand Down Expand Up @@ -53,6 +32,27 @@ import ac.mdiq.podcini.storage.preferences.UserPreferences.rewindSecs
import ac.mdiq.podcini.storage.preferences.UserPreferences.setShowRemainTimeSetting
import ac.mdiq.podcini.storage.preferences.UserPreferences.shouldShowRemainingTime
import ac.mdiq.podcini.ui.appstartintent.MainActivityStarter
import android.content.DialogInterface
import android.content.Intent
import android.graphics.PixelFormat
import android.graphics.drawable.ColorDrawable
import android.media.AudioManager
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.view.*
import android.view.View.OnTouchListener
import android.view.animation.*
import android.widget.EditText
import android.widget.FrameLayout
import android.widget.SeekBar
import android.widget.SeekBar.OnSeekBarChangeListener
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
import androidx.media3.common.util.UnstableApi
import com.bumptech.glide.Glide
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
Expand Down
Loading

0 comments on commit 31624b7

Please sign in to comment.