Skip to content

Commit

Permalink
feed refresh bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
XilinJia committed Feb 22, 2024
1 parent db8f8a9 commit c18343f
Show file tree
Hide file tree
Showing 38 changed files with 316 additions and 258 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 3020099
versionName "3.2.4"
versionCode 3020100
versionName "3.2.5"

def commit = ""
try {
Expand Down
67 changes: 34 additions & 33 deletions app/src/main/java/ac/mdiq/podcini/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,16 @@ import kotlin.math.min
*/
@UnstableApi
class MainActivity : CastEnabledActivity() {
// some device doesn't have a drawer
private var drawerLayout: DrawerLayout? = null
private var drawerToggle: ActionBarDrawerToggle? = null
private var navDrawer: View? = null

private lateinit var navDrawer: View
private lateinit var dummyView : View
var bottomSheet: LockableBottomSheetBehavior<*>? = null
lateinit var bottomSheet: LockableBottomSheetBehavior<*>
private set

private var drawerToggle: ActionBarDrawerToggle? = null

@JvmField
val recycledViewPool: RecyclerView.RecycledViewPool = RecyclerView.RecycledViewPool()
private var lastTheme = 0
Expand All @@ -81,6 +85,9 @@ class MainActivity : CastEnabledActivity() {
@UnstableApi public override fun onCreate(savedInstanceState: Bundle?) {
lastTheme = getNoTitleTheme(this)
setTheme(lastTheme)

DBReader.updateFeedList()

if (savedInstanceState != null) {
ensureGeneratedViewIdGreaterThan(savedInstanceState.getInt(KEY_GENERATED_VIEW_ID, 0))
}
Expand All @@ -104,8 +111,6 @@ class MainActivity : CastEnabledActivity() {
.build()
}

DBReader.updateFeedList()

val fm = supportFragmentManager
if (fm.findFragmentByTag(MAIN_FRAGMENT_TAG) == null) {
if (UserPreferences.DEFAULT_PAGE_REMEMBER != defaultPage) {
Expand Down Expand Up @@ -137,8 +142,8 @@ class MainActivity : CastEnabledActivity() {
checkFirstLaunch()
val bottomSheet = findViewById<View>(R.id.audioplayerFragment)
this.bottomSheet = BottomSheetBehavior.from(bottomSheet) as LockableBottomSheetBehavior<*>
this.bottomSheet?.isHideable = false
this.bottomSheet?.setBottomSheetCallback(bottomSheetCallback)
this.bottomSheet.isHideable = false
this.bottomSheet.setBottomSheetCallback(bottomSheetCallback)

restartUpdateAlarm(this, false)
SynchronizationQueueSink.syncNowIfNotSyncedRecently()
Expand Down Expand Up @@ -249,8 +254,7 @@ class MainActivity : CastEnabledActivity() {
drawerLayout!!.addDrawerListener(drawerToggle!!)
drawerToggle!!.syncState()
drawerToggle!!.isDrawerIndicatorEnabled = !displayUpArrow
drawerToggle!!.toolbarNavigationClickListener =
View.OnClickListener { v: View? -> supportFragmentManager.popBackStack() }
drawerToggle!!.toolbarNavigationClickListener = View.OnClickListener { v: View? -> supportFragmentManager.popBackStack() }
} else if (!displayUpArrow) {
toolbar.navigationIcon = null
} else {
Expand All @@ -261,9 +265,7 @@ class MainActivity : CastEnabledActivity() {

override fun onDestroy() {
super.onDestroy()
if (drawerLayout != null) {
drawerLayout!!.removeDrawerListener(drawerToggle!!)
}
drawerLayout?.removeDrawerListener(drawerToggle!!)
}

private fun checkFirstLaunch() {
Expand All @@ -278,20 +280,20 @@ class MainActivity : CastEnabledActivity() {
}

val isDrawerOpen: Boolean
get() = drawerLayout != null && navDrawer != null && drawerLayout!!.isDrawerOpen(navDrawer!!)
get() = drawerLayout?.isDrawerOpen(navDrawer)?:false

private fun updateInsets() {
setPlayerVisible(findViewById<View>(R.id.audioplayerFragment).visibility == View.VISIBLE)
val playerHeight = resources.getDimension(R.dimen.external_player_height).toInt()
bottomSheet!!.peekHeight = playerHeight + navigationBarInsets.bottom
bottomSheet.peekHeight = playerHeight + navigationBarInsets.bottom
}

fun setPlayerVisible(visible: Boolean) {
bottomSheet!!.setLocked(!visible)
bottomSheet.setLocked(!visible)
if (visible) {
bottomSheetCallback.onStateChanged(dummyView, bottomSheet!!.state) // Update toolbar visibility
bottomSheetCallback.onStateChanged(dummyView, bottomSheet.state) // Update toolbar visibility
} else {
bottomSheet!!.setState(BottomSheetBehavior.STATE_COLLAPSED)
bottomSheet.setState(BottomSheetBehavior.STATE_COLLAPSED)
}
val mainView = findViewById<FragmentContainerView>(R.id.main_view)
val params = mainView.layoutParams as MarginLayoutParams
Expand Down Expand Up @@ -360,9 +362,8 @@ class MainActivity : CastEnabledActivity() {
// change than we want now.
t.commitAllowingStateLoss()

if (drawerLayout != null) { // Tablet layout does not have a drawer
drawerLayout!!.closeDrawer(navDrawer!!)
}
// Tablet layout does not have a drawer
drawerLayout?.closeDrawer(navDrawer)
}

@JvmOverloads
Expand Down Expand Up @@ -409,7 +410,7 @@ class MainActivity : CastEnabledActivity() {
val width = (screenWidth * screenPercent).toInt()
val maxWidth = resources.getDimension(R.dimen.nav_drawer_max_screen_size).toInt()

navDrawer!!.layoutParams.width = min(width.toDouble(), maxWidth.toDouble()).toInt()
navDrawer.layoutParams.width = min(width.toDouble(), maxWidth.toDouble()).toInt()
}

private val screenWidth: Int
Expand All @@ -422,7 +423,7 @@ class MainActivity : CastEnabledActivity() {
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
super.onRestoreInstanceState(savedInstanceState)

if (bottomSheet!!.state == BottomSheetBehavior.STATE_EXPANDED) {
if (bottomSheet.state == BottomSheetBehavior.STATE_EXPANDED) {
bottomSheetCallback.onSlide(dummyView, 1.0f)
}
}
Expand Down Expand Up @@ -484,16 +485,16 @@ class MainActivity : CastEnabledActivity() {
@Deprecated("Deprecated in Java")
override fun onBackPressed() {
if (isDrawerOpen) {
drawerLayout!!.closeDrawer(navDrawer!!)
} else if (bottomSheet!!.state == BottomSheetBehavior.STATE_EXPANDED) {
bottomSheet!!.setState(BottomSheetBehavior.STATE_COLLAPSED)
drawerLayout?.closeDrawer(navDrawer)
} else if (bottomSheet.state == BottomSheetBehavior.STATE_EXPANDED) {
bottomSheet.setState(BottomSheetBehavior.STATE_COLLAPSED)
} else if (supportFragmentManager.backStackEntryCount != 0) {
super.onBackPressed()
} else {
val toPage = defaultPage
if (NavDrawerFragment.getLastNavFragment(this) == toPage || UserPreferences.DEFAULT_PAGE_REMEMBER == toPage) {
if (backButtonOpensDrawer() && drawerLayout != null) {
drawerLayout!!.openDrawer(navDrawer!!)
if (backButtonOpensDrawer()) {
drawerLayout?.openDrawer(navDrawer)
} else {
super.onBackPressed()
}
Expand Down Expand Up @@ -528,23 +529,23 @@ class MainActivity : CastEnabledActivity() {
loadFeedFragmentById(feedId, args)
}
}
bottomSheet!!.setState(BottomSheetBehavior.STATE_COLLAPSED)
bottomSheet.setState(BottomSheetBehavior.STATE_COLLAPSED)
} else if (intent.hasExtra(MainActivityStarter.EXTRA_FRAGMENT_TAG)) {
val tag = intent.getStringExtra(MainActivityStarter.EXTRA_FRAGMENT_TAG)
val args = intent.getBundleExtra(MainActivityStarter.EXTRA_FRAGMENT_ARGS)
if (tag != null) {
loadFragment(tag, args)
}
bottomSheet!!.setState(BottomSheetBehavior.STATE_COLLAPSED)
bottomSheet.setState(BottomSheetBehavior.STATE_COLLAPSED)
} else if (intent.getBooleanExtra(MainActivityStarter.EXTRA_OPEN_PLAYER, false)) {
bottomSheet!!.state = BottomSheetBehavior.STATE_EXPANDED
bottomSheet.state = BottomSheetBehavior.STATE_EXPANDED
bottomSheetCallback.onSlide(dummyView, 1.0f)
} else {
handleDeeplink(intent.data)
}

if (intent.getBooleanExtra(MainActivityStarter.EXTRA_OPEN_DRAWER, false) && drawerLayout != null) {
drawerLayout!!.open()
if (intent.getBooleanExtra(MainActivityStarter.EXTRA_OPEN_DRAWER, false)) {
drawerLayout?.open()
}
if (intent.getBooleanExtra(MainActivityStarter.EXTRA_OPEN_DOWNLOAD_LOGS, false)) {
DownloadLogFragment().show(supportFragmentManager, null)
Expand All @@ -565,7 +566,7 @@ class MainActivity : CastEnabledActivity() {

fun showSnackbarAbovePlayer(text: CharSequence?, duration: Int): Snackbar {
val s: Snackbar
if (bottomSheet!!.state == BottomSheetBehavior.STATE_COLLAPSED) {
if (bottomSheet.state == BottomSheetBehavior.STATE_COLLAPSED) {
s = Snackbar.make(findViewById(R.id.main_view), text!!, duration)
if (findViewById<View>(R.id.audioplayerFragment).visibility == View.VISIBLE) {
s.setAnchorView(findViewById(R.id.audioplayerFragment))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import java.util.concurrent.ExecutionException
try {
DBWriter.updateFeedDownloadURL(original, updated).get()
feed.download_url = updated
runOnce(activityRef.get(), feed)
runOnce(activityRef.get()!!, feed)
} catch (e: ExecutionException) {
throw RuntimeException(e)
} catch (e: InterruptedException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class AddFeedFragment : Fragment() {
viewBinding = AddfeedBinding.inflate(inflater)
activity = getActivity() as? MainActivity

Log.d(TAG, "fregment onCreateView")
displayUpArrow = parentFragmentManager.backStackEntryCount != 0
if (savedInstanceState != null) {
displayUpArrow = savedInstanceState.getBoolean(KEY_UP_ARROW)
Expand Down
33 changes: 17 additions & 16 deletions app/src/main/java/ac/mdiq/podcini/fragment/AllEpisodesFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import ac.mdiq.podcini.model.feed.FeedItemFilter
import ac.mdiq.podcini.model.feed.SortOrder
import ac.mdiq.podcini.storage.preferences.UserPreferences.allEpisodesSortOrder
import ac.mdiq.podcini.storage.preferences.UserPreferences.prefFilterAllEpisodes
import android.util.Log
import androidx.annotation.OptIn
import org.apache.commons.lang3.StringUtils
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
Expand All @@ -27,25 +29,24 @@ import org.greenrobot.eventbus.Subscribe
class AllEpisodesFragment : EpisodesListFragment() {
@UnstableApi override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
val root = super.onCreateView(inflater, container, savedInstanceState)
toolbar?.inflateMenu(R.menu.episodes)
toolbar?.setTitle(R.string.episodes_label)
Log.d(TAG, "fregment onCreateView")

toolbar.inflateMenu(R.menu.episodes)
toolbar.setTitle(R.string.episodes_label)
updateToolbar()
updateFilterUi()
txtvInformation?.setOnClickListener { v: View? ->
AllEpisodesFilterDialog.newInstance(getFilter()).show(
childFragmentManager, null)
txtvInformation.setOnClickListener { v: View? ->
AllEpisodesFilterDialog.newInstance(getFilter()).show(childFragmentManager, null)
}
return root
}

override fun loadData(): List<FeedItem> {
return DBReader.getEpisodes(0, page * EPISODES_PER_PAGE, getFilter(),
allEpisodesSortOrder)
return DBReader.getEpisodes(0, page * EPISODES_PER_PAGE, getFilter(), allEpisodesSortOrder)
}

override fun loadMoreData(page: Int): List<FeedItem> {
return DBReader.getEpisodes((page - 1) * EPISODES_PER_PAGE, EPISODES_PER_PAGE, getFilter(),
allEpisodesSortOrder)
return DBReader.getEpisodes((page - 1) * EPISODES_PER_PAGE, EPISODES_PER_PAGE, getFilter(), allEpisodesSortOrder)
}

override fun loadTotalItemCount(): Int {
Expand All @@ -64,7 +65,7 @@ class AllEpisodesFragment : EpisodesListFragment() {
return PREF_NAME
}

override fun onMenuItemClick(item: MenuItem): Boolean {
@OptIn(UnstableApi::class) override fun onMenuItemClick(item: MenuItem): Boolean {
if (super.onOptionsItemSelected(item)) {
return true
}
Expand Down Expand Up @@ -100,15 +101,15 @@ class AllEpisodesFragment : EpisodesListFragment() {
}

private fun updateFilterUi() {
swipeActions?.setFilter(getFilter())
swipeActions.setFilter(getFilter())
if (getFilter().values.isNotEmpty()) {
if (txtvInformation != null) txtvInformation!!.visibility = View.VISIBLE
emptyView?.setMessage(R.string.no_all_episodes_filtered_label)
txtvInformation.visibility = View.VISIBLE
emptyView.setMessage(R.string.no_all_episodes_filtered_label)
} else {
if (txtvInformation != null) txtvInformation!!.visibility = View.GONE
emptyView?.setMessage(R.string.no_all_episodes_label)
txtvInformation.visibility = View.GONE
emptyView.setMessage(R.string.no_all_episodes_label)
}
toolbar?.menu?.findItem(R.id.action_favorites)?.setIcon(
toolbar.menu?.findItem(R.id.action_favorites)?.setIcon(
if (getFilter().showIsFavorite) R.drawable.ic_star else R.drawable.ic_star_border)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class AudioPlayerFragment : Fragment(), SeekBar.OnSeekBarChangeListener, Toolbar
super.onCreateView(inflater, container, savedInstanceState)
val root: View = inflater.inflate(R.layout.audioplayer_fragment, container, false)
root.setOnTouchListener { v: View?, event: MotionEvent? -> true } // Avoid clicks going through player to fragments below

Log.d(TAG, "fregment onCreateView")
toolbar = root.findViewById(R.id.toolbar)
toolbar.title = ""
toolbar.setNavigationOnClickListener { v: View? ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class ChaptersFragment : AppCompatDialogFragment() {
fun onCreateView(inflater: LayoutInflater): View {
val root = inflater.inflate(R.layout.simple_list_fragment, null, false)
root.findViewById<View>(R.id.toolbar).visibility = View.GONE

Log.d(TAG, "fregment onCreateView")
val recyclerView = root.findViewById<RecyclerView>(R.id.recyclerView)
progressBar = root.findViewById(R.id.progLoading)
layoutManager = LinearLayoutManager(activity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class CompletedDownloadsFragment : Fragment(), SelectableAdapter.OnSelectModeLis
savedInstanceState: Bundle?
): View {
val root: View = inflater.inflate(R.layout.simple_list_fragment, container, false)

Log.d(TAG, "fregment onCreateView")
toolbar = root.findViewById(R.id.toolbar)
toolbar.setTitle(R.string.downloads_label)
toolbar.inflateMenu(R.menu.downloads_completed)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/ac/mdiq/podcini/fragment/CoverFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class CoverFragment : Fragment() {
private var media: Playable? = null

@UnstableApi override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {

Log.d(TAG, "fregment onCreateView")
viewBinding = CoverFragmentBinding.inflate(inflater)
viewBinding.imgvCover.setOnClickListener { v: View? -> onPlayPause() }
viewBinding.openDescription.setOnClickListener { view: View? ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class DiscoveryFragment : Fragment(), Toolbar.OnMenuItemClickListener {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
val root = inflater.inflate(R.layout.fragment_itunes_search, container, false)

Log.d(TAG, "fregment onCreateView")
gridView = root.findViewById(R.id.gridView)
adapter = ItunesAdapter(requireActivity(), ArrayList())
gridView.setAdapter(adapter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class DownloadLogFragment : BottomSheetDialogFragment(), OnItemClickListener, To
override fun onCreateView(inflater: LayoutInflater,
container: ViewGroup?, savedInstanceState: Bundle?
): View {
Log.d(TAG, "fregment onCreateView")
viewBinding = DownloadLogFragmentBinding.inflate(inflater)
viewBinding.toolbar.inflateMenu(R.menu.download_log)
viewBinding.toolbar.setOnMenuItemClickListener(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ abstract class EpisodesListFragment : Fragment(), SelectableAdapter.OnSelectMode

@UnstableApi override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
super.onCreateView(inflater, container, savedInstanceState)

val root: View = inflater.inflate(R.layout.episodes_list_fragment, container, false)

Log.d(TAG, "fregment onCreateView")
txtvInformation = root.findViewById(R.id.txtvInformation)
toolbar = root.findViewById(R.id.toolbar)
toolbar.setOnMenuItemClickListener(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class ExternalPlayerFragment : Fragment() {
savedInstanceState: Bundle?
): View? {
val root = inflater.inflate(R.layout.external_player_fragment, container, false)

Log.d(TAG, "fregment onCreateView")
imgvCover = root.findViewById(R.id.imgvCover)
txtvTitle = root.findViewById(R.id.txtvTitle)
butPlay = root.findViewById(R.id.butPlay)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class FeedInfoFragment : Fragment(), Toolbar.OnMenuItemClickListener {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View {
val root: View = inflater.inflate(R.layout.feedinfo, null)

Log.d(TAG, "fregment onCreateView")
toolbar = root.findViewById(R.id.toolbar)
toolbar.title = ""
toolbar.inflateMenu(R.menu.feedinfo)
Expand Down
Loading

0 comments on commit c18343f

Please sign in to comment.