Skip to content

Commit

Permalink
Merge pull request #6987 from Bnyro/master
Browse files Browse the repository at this point in the history
feat: add update info dialog to inform users about current Piped situation
  • Loading branch information
Bnyro authored Jan 20, 2025
2 parents 8911810 + 2d6533d commit c7deb0e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,5 @@ object PreferenceKeys {
const val IMAGE_PROXY_URL = "image_proxy_url"
const val SELECTED_CHANNEL_GROUP = "selected_channel_group"
const val SELECTED_DOWNLOAD_SORT_TYPE = "selected_download_sort_type"
const val LAST_SHOWN_INFO_MESSAGE_VERSION_CODE = "last_shown_info_message_version"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.libretube.ui.activities

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.content.res.Configuration
import android.os.Build
Expand All @@ -18,6 +19,8 @@ import androidx.appcompat.widget.SearchView
import androidx.core.content.pm.ShortcutManagerCompat
import androidx.core.net.toUri
import androidx.core.os.bundleOf
import androidx.core.text.bold
import androidx.core.text.buildSpannedString
import androidx.core.view.allViews
import androidx.core.view.children
import androidx.core.view.isNotEmpty
Expand Down Expand Up @@ -55,6 +58,7 @@ import com.github.libretube.ui.models.SearchViewModel
import com.github.libretube.ui.models.SubscriptionsViewModel
import com.github.libretube.ui.preferences.BackupRestoreSettings.Companion.FILETYPE_ANY
import com.github.libretube.util.UpdateChecker
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.elevation.SurfaceColors
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -176,6 +180,8 @@ class MainActivity : BaseActivity() {
setupSubscriptionsBadge()

loadIntentData()

showUserInfoDialogIfNeeded()
}

@ColorInt
Expand Down Expand Up @@ -607,4 +613,59 @@ class MainActivity : BaseActivity() {
exportPlaylistId = playlistId
createPlaylistsFile.launch("${playlistName}.${format.fileExtension}")
}

private fun showUserInfoDialogIfNeeded() {
// don't show the update information dialog for debug builds
if (BuildConfig.DEBUG) return

val lastShownVersionCode =
PreferenceHelper.getInt(PreferenceKeys.LAST_SHOWN_INFO_MESSAGE_VERSION_CODE, -1)

// mapping of version code to info message
val infoMessages = listOf(
59 to getUpdateInfoText(this)
)

val message =
infoMessages.lastOrNull { (versionCode, _) -> versionCode > lastShownVersionCode }?.second
?: return

MaterialAlertDialogBuilder(this)
.setTitle(R.string.update_information)
.setMessage(message)
.setNegativeButton(R.string.okay, null)
.setPositiveButton(R.string.never_show_again) { _, _ ->
PreferenceHelper.putInt(
PreferenceKeys.LAST_SHOWN_INFO_MESSAGE_VERSION_CODE,
BuildConfig.VERSION_CODE
)
}
.show()
}

private fun getUpdateInfoText(context: Context) = buildSpannedString {
append("Most public Piped instances are not able to load any videos as of today because they're rate-limited very quickly by YouTube. Therefore please consider enabling ")
bold {
append(context.getString(R.string.local_stream_extraction))
}
append(" under ")
bold {
append("Settings -> Instance")
}
append(" in order to fetch video streams directly from YouTube without Piped in-between. Any other content will still be loaded via Piped.")

appendLine()
appendLine()

append("Due to the above mentioned issue, some instances do not properly generate the subscriptions feed. To fetch the feed directly from your phone, enable ")
bold {
append(context.getString(R.string.local_feed_extraction))
}
append(". Note that this might be slow if you have a lot of subscriptions.")

appendLine()
appendLine()

append("Please see the pinned issues at GitHub for more information on that topic.")
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@
<string name="external_player">External player</string>
<string name="screenshot">Screenshot</string>
<string name="crashlog">Crashlog</string>
<string name="never_show_again">Never show this again</string>
<string name="update_information">Update information</string>

<!-- Backup & Restore Settings -->
<string name="import_subscriptions_from">Import subscriptions from</string>
Expand Down

0 comments on commit c7deb0e

Please sign in to comment.