Skip to content

Commit

Permalink
6.13.9 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
XilinJia committed Nov 11, 2024
1 parent 44b3737 commit ca34912
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 43 deletions.
4 changes: 0 additions & 4 deletions app/src/main/kotlin/ac/mdiq/podcini/storage/database/Feeds.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ object Feeds {
changes.insertions.isNotEmpty() -> {
for (i in changes.insertions) {
Logd(TAG, "monitorFeeds inserted feed: ${changes.list[i].title}")
// updateFeedMap(listOf(changes.list[i]))
monitorFeed(changes.list[i])
}
EventFlow.postEvent(FlowEvent.FeedListEvent(FlowEvent.FeedListEvent.Action.ADDED))
Expand All @@ -103,7 +102,6 @@ object Feeds {
// }
changes.deletions.isNotEmpty() -> {
Logd(TAG, "monitorFeeds feed deleted: ${changes.deletions.size}")
// updateFeedMap(changes.list, true)
buildTags()
}
}
Expand All @@ -123,7 +121,6 @@ object Feeds {
when (changes) {
is UpdatedObject -> {
Logd(TAG, "monitorFeed UpdatedObject0 ${changes.obj.title} ${changes.changedFields.joinToString()}")
// updateFeedMap(listOf(changes.obj))
if (changes.isFieldChanged("preferences")) EventFlow.postEvent(FlowEvent.FeedPrefsChangeEvent(changes.obj))
}
else -> {}
Expand All @@ -136,7 +133,6 @@ object Feeds {
when (changes) {
is UpdatedObject -> {
Logd(TAG, "monitorFeed UpdatedObject ${changes.obj.title} ${changes.changedFields.joinToString()}")
// updateFeedMap(listOf(changes.obj))
if (changes.isFieldChanged("preferences")) EventFlow.postEvent(FlowEvent.FeedPrefsChangeEvent(changes.obj))
}
// is DeletedObject -> {
Expand Down
11 changes: 2 additions & 9 deletions app/src/main/kotlin/ac/mdiq/podcini/ui/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,11 @@ class MainActivity : CastEnabledActivity() {
// init shared preferences
ioScope.launch {
// RealmDB.apply { }
// EpisodesRecyclerView.getSharedPrefs(this@MainActivity)
NavDrawerFragment.getSharedPrefs(this@MainActivity)
SwipeActions.getSharedPrefs(this@MainActivity)
QueuesFragment.getSharedPrefs(this@MainActivity)
// updateFeedMap()
buildTags()
monitorFeeds()
// InTheatre.apply { }
AudioPlayerFragment.getSharedPrefs(this@MainActivity)
PlayerWidget.getSharedPrefs(this@MainActivity)
StatisticsFragment.getSharedPrefs(this@MainActivity)
Expand All @@ -259,12 +256,8 @@ class MainActivity : CastEnabledActivity() {
// requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
MaterialAlertDialogBuilder(this)
.setMessage(R.string.notification_permission_text)
.setPositiveButton(android.R.string.ok) { _: DialogInterface?, _: Int ->
requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
}
.setNegativeButton(R.string.cancel_label) { _: DialogInterface?, _: Int ->
checkAndRequestUnrestrictedBackgroundActivity(this@MainActivity)
}
.setPositiveButton(android.R.string.ok) { _: DialogInterface?, _: Int -> requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS) }
.setNegativeButton(R.string.cancel_label) { _: DialogInterface?, _: Int -> checkAndRequestUnrestrictedBackgroundActivity(this@MainActivity) }
.show()
} else checkAndRequestUnrestrictedBackgroundActivity(this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class NavDrawerFragment : Fragment(), OnSharedPreferenceChangeListener {
(view.layoutParams as ViewGroup.MarginLayoutParams).bottomMargin = bottomInset.toInt()
insets
}
prefs!!.registerOnSharedPreferenceChangeListener(this)
prefs?.registerOnSharedPreferenceChangeListener(this)
return composeView
}

Expand Down Expand Up @@ -169,7 +169,7 @@ class NavDrawerFragment : Fragment(), OnSharedPreferenceChangeListener {

override fun onDestroyView() {
Logd(TAG, "onDestroyView")
prefs!!.unregisterOnSharedPreferenceChangeListener(this)
prefs?.unregisterOnSharedPreferenceChangeListener(this)
super.onDestroyView()
}

Expand Down Expand Up @@ -229,10 +229,10 @@ class NavDrawerFragment : Fragment(), OnSharedPreferenceChangeListener {

fun saveLastNavFragment(tag: String?) {
Logd(TAG, "saveLastNavFragment(tag: $tag)")
val edit: SharedPreferences.Editor = prefs!!.edit()
if (tag != null) edit.putString(PREF_LAST_FRAGMENT_TAG, tag)
else edit.remove(PREF_LAST_FRAGMENT_TAG)
edit.apply()
val edit: SharedPreferences.Editor? = prefs?.edit()
if (tag != null) edit?.putString(PREF_LAST_FRAGMENT_TAG, tag)
else edit?.remove(PREF_LAST_FRAGMENT_TAG)
edit?.apply()
}

fun getLastNavFragment(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,9 @@ class OnlineFeedFragment : Fragment() {
} else if (isEnableAutodownload) {
val autoDownload = autoDownloadChecked
feed1.preferences!!.autoDownload = autoDownload
val editor = prefs!!.edit()
editor.putBoolean(PREF_LAST_AUTO_DOWNLOAD, autoDownload)
editor.apply()
val editor = prefs?.edit()
editor?.putBoolean(PREF_LAST_AUTO_DOWNLOAD, autoDownload)
editor?.apply()
}
if (username != null) {
feed1.preferences!!.username = username
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ class QueuesFragment : Fragment(), Toolbar.OnMenuItemClickListener {
// val isLocked: Boolean = isQueueLocked
if (isQueueLocked) setQueueLock(false)
else {
val shouldShowLockWarning: Boolean = prefs!!.getBoolean(PREF_SHOW_LOCK_WARNING, true)
val shouldShowLockWarning: Boolean = prefs?.getBoolean(PREF_SHOW_LOCK_WARNING, true) ?: true
if (!shouldShowLockWarning) setQueueLock(true)
else {
val builder = MaterialAlertDialogBuilder(requireContext())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ class StatisticsFragment : Fragment() {
timePlayedToday += item.timePlayed
timeSpentToday += item.timeSpent
}
includeMarkedAsPlayed = prefs!!.getBoolean(PREF_INCLUDE_MARKED_PLAYED, false)
timeFilterFrom = prefs!!.getLong(PREF_FILTER_FROM, 0)
timeFilterTo = prefs!!.getLong(PREF_FILTER_TO, Long.MAX_VALUE)
includeMarkedAsPlayed = prefs?.getBoolean(PREF_INCLUDE_MARKED_PLAYED, false)?: false
timeFilterFrom = prefs?.getLong(PREF_FILTER_FROM, 0) ?: 0
timeFilterTo = prefs?.getLong(PREF_FILTER_TO, Long.MAX_VALUE) ?: Long.MAX_VALUE
try {
statsResult = getStatistics(includeMarkedAsPlayed, timeFilterFrom, timeFilterTo)
statsResult.statsItems.sortWith { item1: StatisticsItem, item2: StatisticsItem -> item2.timePlayed.compareTo(item1.timePlayed) }
Expand Down Expand Up @@ -167,7 +167,7 @@ class StatisticsFragment : Fragment() {
}
HorizontalLineChart(chartData)
StatsList(statsResult, chartData) { item ->
context.getString(R.string.duration) + ": " + shortLocalizedDuration(context, item!!.timePlayed) + " \t " + context.getString(R.string.spent) + ": " + shortLocalizedDuration(context, item.timeSpent)
context.getString(R.string.duration) + ": " + shortLocalizedDuration(context, item.timePlayed) + " \t " + context.getString(R.string.spent) + ": " + shortLocalizedDuration(context, item.timeSpent)
}
}
}
Expand All @@ -179,7 +179,7 @@ class StatisticsFragment : Fragment() {

fun loadMonthlyStatistics() {
try {
val includeMarkedAsPlayed = prefs!!.getBoolean(PREF_INCLUDE_MARKED_PLAYED, false)
val includeMarkedAsPlayed = prefs?.getBoolean(PREF_INCLUDE_MARKED_PLAYED, false) ?: false
val months: MutableList<MonthlyStatisticsItem> = ArrayList()
val medias = realm.query(EpisodeMedia::class).query("lastPlayedTime > 0").find()
val groupdMedias = medias.groupBy {
Expand Down Expand Up @@ -288,7 +288,7 @@ class StatisticsFragment : Fragment() {
Text(Formatter.formatShortFileSize(context, downloadChartData.sum.toLong()), color = MaterialTheme.colorScheme.onSurface)
HorizontalLineChart(downloadChartData)
StatsList(downloadstatsData, downloadChartData) { item ->
("${Formatter.formatShortFileSize(context, item!!.totalDownloadSize)}"
("${Formatter.formatShortFileSize(context, item.totalDownloadSize)}"
+ String.format(Locale.getDefault(), "%d%s", item.episodesDownloadCount, context.getString(R.string.episodes_suffix)))
}
}
Expand All @@ -315,7 +315,7 @@ class StatisticsFragment : Fragment() {
}

@Composable
fun StatsList(statisticsData: StatisticsResult, lineChartData: LineChartData, infoCB: (StatisticsItem?)->String) {
fun StatsList(statisticsData: StatisticsResult, lineChartData: LineChartData, infoCB: (StatisticsItem)->String) {
val lazyListState = rememberLazyListState()
val context = LocalContext.current
var showFeedStats by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -386,16 +386,16 @@ class StatisticsFragment : Fragment() {
val dialog = object: DatesFilterDialog(requireContext(), statsResult.oldestDate) {
override fun initParams() {
prefs = Companion.prefs
includeMarkedAsPlayed = prefs!!.getBoolean(PREF_INCLUDE_MARKED_PLAYED, false)
timeFilterFrom = prefs!!.getLong(PREF_FILTER_FROM, 0)
timeFilterTo = prefs!!.getLong(PREF_FILTER_TO, Long.MAX_VALUE)
includeMarkedAsPlayed = prefs?.getBoolean(PREF_INCLUDE_MARKED_PLAYED, false) ?: false
timeFilterFrom = prefs?.getLong(PREF_FILTER_FROM, 0) ?: 0
timeFilterTo = prefs?.getLong(PREF_FILTER_TO, Long.MAX_VALUE) ?: Long.MAX_VALUE
}
override fun callback(timeFilterFrom: Long, timeFilterTo: Long, includeMarkedAsPlayed: Boolean) {
prefs!!.edit()
.putBoolean(PREF_INCLUDE_MARKED_PLAYED, includeMarkedAsPlayed)
.putLong(PREF_FILTER_FROM, timeFilterFrom)
.putLong(PREF_FILTER_TO, timeFilterTo)
.apply()
prefs?.edit()
?.putBoolean(PREF_INCLUDE_MARKED_PLAYED, includeMarkedAsPlayed)
?.putLong(PREF_FILTER_FROM, timeFilterFrom)
?.putLong(PREF_FILTER_TO, timeFilterTo)
?.apply()
EventFlow.postEvent(FlowEvent.StatisticsEvent())
}
}
Expand All @@ -418,11 +418,11 @@ class StatisticsFragment : Fragment() {
}

private fun doResetStatistics() {
prefs!!.edit()
.putBoolean(PREF_INCLUDE_MARKED_PLAYED, false)
.putLong(PREF_FILTER_FROM, 0)
.putLong(PREF_FILTER_TO, Long.MAX_VALUE)
.apply()
prefs?.edit()
?.putBoolean(PREF_INCLUDE_MARKED_PLAYED, false)
?.putLong(PREF_FILTER_FROM, 0)
?.putLong(PREF_FILTER_TO, Long.MAX_VALUE)
?.apply()

lifecycleScope.launch {
try {
Expand Down

0 comments on commit ca34912

Please sign in to comment.