Skip to content

Commit

Permalink
removed unnecessary net load
Browse files Browse the repository at this point in the history
  • Loading branch information
XilinJia committed Feb 19, 2024
1 parent 14d823a commit 7d5bf3a
Show file tree
Hide file tree
Showing 35 changed files with 228 additions and 154 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ android {
// Version code schema:
// "1.2.3-beta4" -> 1020304
// "1.2.3" -> 1020395
versionCode 3020097
versionName "3.2.2"
versionCode 3020098
versionName "3.2.3"

def commit = ""
try {
Expand Down
32 changes: 22 additions & 10 deletions app/src/main/java/ac/mdiq/podvinci/fragment/AudioPlayerFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,22 @@ class AudioPlayerFragment : Fragment(), SeekBar.OnSeekBarChangeListener, Toolbar
}
})

controller = newPlaybackController()
controller?.init()
loadMediaInfo(false)
EventBus.getDefault().register(this)

return root
}

override fun onDestroyView() {
super.onDestroyView()
controller?.release()
controller = null
EventBus.getDefault().unregister(this)
Log.d(TAG, "Fragment destroyed")
}

private fun setChapterDividers(media: Playable?) {
if (media == null) {
return
Expand Down Expand Up @@ -241,9 +254,8 @@ class AudioPlayerFragment : Fragment(), SeekBar.OnSeekBarChangeListener, Toolbar
}

private fun loadMediaInfo(includingChapters: Boolean) {
if (disposable != null) {
disposable!!.dispose()
}
disposable?.dispose()

disposable = Maybe.create<Playable> { emitter: MaybeEmitter<Playable?> ->
val media: Playable? = controller?.getMedia()
if (media != null) {
Expand Down Expand Up @@ -308,20 +320,20 @@ class AudioPlayerFragment : Fragment(), SeekBar.OnSeekBarChangeListener, Toolbar

override fun onStart() {
super.onStart()
controller = newPlaybackController()
controller?.init()
loadMediaInfo(false)
EventBus.getDefault().register(this)
// controller = newPlaybackController()
// controller?.init()
// loadMediaInfo(false)
// EventBus.getDefault().register(this)
txtvRev.text = NumberFormat.getInstance().format(UserPreferences.rewindSecs.toLong())
txtvFF.text = NumberFormat.getInstance().format(UserPreferences.fastForwardSecs.toLong())
}

override fun onStop() {
super.onStop()
controller?.release()
controller = null
// controller?.release()
// controller = null
// EventBus.getDefault().unregister(this)
progressIndicator.visibility = View.GONE // Controller released; we will not receive buffering updates
EventBus.getDefault().unregister(this)
disposable?.dispose()
}

Expand Down
32 changes: 24 additions & 8 deletions app/src/main/java/ac/mdiq/podvinci/fragment/ChaptersFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ class ChaptersFragment : AppCompatDialogFragment() {
CoordinatorLayout.LayoutParams.MATCH_PARENT, CoordinatorLayout.LayoutParams.WRAP_CONTENT)
recyclerView.layoutParams = wrapHeight

return root
}

override fun onStart() {
super.onStart()
controller = object : PlaybackController(activity) {
override fun loadMediaInfo() {
this@ChaptersFragment.loadMediaInfo(false)
Expand All @@ -104,16 +99,37 @@ class ChaptersFragment : AppCompatDialogFragment() {
controller?.init()
EventBus.getDefault().register(this)
loadMediaInfo(false)

return root
}

override fun onStop() {
super.onStop()
disposable?.dispose()
override fun onDestroyView() {
super.onDestroyView()
controller?.release()
controller = null
EventBus.getDefault().unregister(this)
}

override fun onStart() {
super.onStart()
// controller = object : PlaybackController(activity) {
// override fun loadMediaInfo() {
// [email protected](false)
// }
// }
// controller?.init()
// EventBus.getDefault().register(this)
// loadMediaInfo(false)
}

override fun onStop() {
super.onStop()
disposable?.dispose()
// controller?.release()
// controller = null
// EventBus.getDefault().unregister(this)
}

@Subscribe(threadMode = ThreadMode.MAIN)
fun onEventMainThread(event: PlaybackPositionEvent) {
updateChapterSelection(getCurrentChapter(media), false)
Expand Down
41 changes: 30 additions & 11 deletions app/src/main/java/ac/mdiq/podvinci/fragment/CoverFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.annotation.OptIn
import androidx.core.content.ContextCompat
import androidx.core.graphics.BlendModeColorFilterCompat
import androidx.core.graphics.BlendModeCompat
Expand Down Expand Up @@ -78,9 +79,27 @@ class CoverFragment : Fragment() {
}
viewBinding.butPrevChapter.setOnClickListener { v: View? -> seekToPrevChapter() }
viewBinding.butNextChapter.setOnClickListener { v: View? -> seekToNextChapter() }

controller = object : PlaybackController(activity) {
override fun loadMediaInfo() {
this@CoverFragment.loadMediaInfo(false)
}
}
controller?.init()
loadMediaInfo(false)
EventBus.getDefault().register(this)

return viewBinding.root
}

@OptIn(UnstableApi::class) override fun onDestroyView() {
super.onDestroyView()
controller?.release()
controller = null
EventBus.getDefault().unregister(this)
Log.d(TAG, "Fragment destroyed")
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
configureForOrientation(resources.configuration)
}
Expand Down Expand Up @@ -231,22 +250,22 @@ class CoverFragment : Fragment() {

@UnstableApi override fun onStart() {
super.onStart()
controller = object : PlaybackController(activity) {
override fun loadMediaInfo() {
this@CoverFragment.loadMediaInfo(false)
}
}
controller?.init()
loadMediaInfo(false)
EventBus.getDefault().register(this)
// controller = object : PlaybackController(activity) {
// override fun loadMediaInfo() {
// [email protected](false)
// }
// }
// controller?.init()
// loadMediaInfo(false)
// EventBus.getDefault().register(this)
}

@UnstableApi override fun onStop() {
super.onStop()
disposable?.dispose()
controller?.release()
controller = null
EventBus.getDefault().unregister(this)
// controller?.release()
// controller = null
// EventBus.getDefault().unregister(this)
}

@Subscribe(threadMode = ThreadMode.MAIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import ac.mdiq.podvinci.model.playback.MediaType
import ac.mdiq.podvinci.model.playback.Playable
import ac.mdiq.podvinci.playback.base.PlayerStatus
import ac.mdiq.podvinci.view.PlayButton
import androidx.annotation.OptIn
import io.reactivex.Maybe
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
Expand Down Expand Up @@ -68,9 +69,19 @@ class ExternalPlayerFragment : Fragment() {
}
}
}
controller = setupPlaybackController()
controller!!.init()
loadMediaInfo()
EventBus.getDefault().register(this)
return root
}

@OptIn(UnstableApi::class) override fun onDestroyView() {
super.onDestroyView()
controller?.release()
controller = null
EventBus.getDefault().unregister(this)
}
@UnstableApi
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Expand Down Expand Up @@ -105,22 +116,20 @@ class ExternalPlayerFragment : Fragment() {
}
}

@UnstableApi
override fun onStart() {
super.onStart()
controller = setupPlaybackController()
controller!!.init()
loadMediaInfo()
EventBus.getDefault().register(this)
// controller = setupPlaybackController()
// controller!!.init()
// loadMediaInfo()
// EventBus.getDefault().register(this)
}

@UnstableApi
override fun onStop() {
super.onStop()
controller?.release()
controller = null

EventBus.getDefault().unregister(this)
// controller?.release()
// controller = null
//
// EventBus.getDefault().unregister(this)
}

@UnstableApi
Expand All @@ -146,7 +155,6 @@ class ExternalPlayerFragment : Fragment() {
super.onDestroy()
Log.d(TAG, "Fragment is about to be destroyed")
disposable?.dispose()

}

@UnstableApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba
private lateinit var nextPageLoader: MoreContentListFooterUtil

private var displayUpArrow = false
private var headerCreated = false
private var feedID: Long = 0
private var feed: Feed? = null
private var headerCreated = false
private var disposable: Disposable? = null

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -236,8 +236,8 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba
}
R.id.refresh_complete_item -> {
Thread {
feed?.nextPageLink = feed!!.download_url
feed?.pageNr = 0
feed!!.nextPageLink = feed!!.download_url
feed!!.pageNr = 0
try {
DBWriter.resetPagedFeedPage(feed).get()
FeedUpdateManager.runOnce(context, feed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import io.reactivex.schedulers.Schedulers
@UnstableApi
class ItemDescriptionFragment : Fragment() {
private lateinit var webvDescription: ShownotesWebView

private var webViewLoader: Disposable? = null
private var controller: PlaybackController? = null

Expand All @@ -36,9 +37,7 @@ class ItemDescriptionFragment : Fragment() {
val root = inflater.inflate(R.layout.item_description_fragment, container, false)
webvDescription = root.findViewById(R.id.webview)
webvDescription.setTimecodeSelectedListener { time: Int? ->
if (controller != null) {
controller!!.seekTo(time!!)
}
controller?.seekTo(time!!)
}
webvDescription.setPageFinishedListener {
// Restoring the scroll position might not always work
Expand All @@ -56,11 +55,21 @@ class ItemDescriptionFragment : Fragment() {
}
})
registerForContextMenu(webvDescription)
controller = object : PlaybackController(activity) {
override fun loadMediaInfo() {
load()
}
}
controller?.init()

load()
return root
}

override fun onDestroy() {
super.onDestroy()
override fun onDestroyView() {
super.onDestroyView()
controller?.release()
controller = null
Log.d(TAG, "Fragment destroyed")
webvDescription.removeAllViews()
webvDescription.destroy()
Expand All @@ -71,13 +80,12 @@ class ItemDescriptionFragment : Fragment() {
}

@UnstableApi private fun load() {
Log.d(TAG, "load()")
if (webViewLoader != null) {
webViewLoader!!.dispose()
}
Log.d(TAG, "load() called")
webViewLoader?.dispose()

val context = context ?: return
webViewLoader = Maybe.create { emitter: MaybeEmitter<String?> ->
val media = controller!!.getMedia()
val media = controller?.getMedia()
if (media == null) {
emitter.onComplete()
return@create
Expand Down Expand Up @@ -112,8 +120,7 @@ class ItemDescriptionFragment : Fragment() {
if (controller?.getMedia() != null) {
Log.d(TAG, "Saving scroll position: " + webvDescription.scrollY)
editor.putInt(PREF_SCROLL_Y, webvDescription.scrollY)
editor.putString(PREF_PLAYABLE_ID, controller!!.getMedia()!!.getIdentifier()
.toString())
editor.putString(PREF_PLAYABLE_ID, controller!!.getMedia()!!.getIdentifier().toString())
} else {
Log.d(TAG, "savePreferences was called while media or webview was null")
editor.putInt(PREF_SCROLL_Y, -1)
Expand Down Expand Up @@ -145,23 +152,21 @@ class ItemDescriptionFragment : Fragment() {

override fun onStart() {
super.onStart()
controller = object : PlaybackController(activity) {
override fun loadMediaInfo() {
load()
}
}
controller?.init()
load()
// controller = object : PlaybackController(activity) {
// override fun loadMediaInfo() {
// load()
// }
// }
// controller?.init()
// load()
}

override fun onStop() {
super.onStop()

if (webViewLoader != null) {
webViewLoader!!.dispose()
}
controller!!.release()
controller = null
webViewLoader?.dispose()
// controller?.release()
// controller = null
}

companion object {
Expand Down
Loading

0 comments on commit 7d5bf3a

Please sign in to comment.