feat(Media): Toggleable Comments (#521)

* Smooth theme transitions
This commit is contained in:
Sadwhy 2024-11-17 12:21:44 +06:00 committed by GitHub
parent 56e557738c
commit d1e2ca8b5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 85 additions and 40 deletions

View file

@ -105,6 +105,14 @@ class App : MultiDexApplication() {
LogcatLogger.install(AndroidLogcatLogger(LogPriority.VERBOSE)) LogcatLogger.install(AndroidLogcatLogger(LogPriority.VERBOSE))
} }
if (PrefManager.getVal<Int>(PrefName.CommentsEnabled) == 0) {
if (BuildConfig.FLAVOR.contains("fdroid")) {
PrefManager.setVal(PrefName.CommentsEnabled, 2)
} else {
PrefManager.setVal(PrefName.CommentsEnabled, 1)
}
}
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
animeExtensionManager = Injekt.get() animeExtensionManager = Injekt.get()
animeExtensionManager.findAvailableExtensions() animeExtensionManager.findAvailableExtensions()
@ -128,7 +136,9 @@ class App : MultiDexApplication() {
downloadAddonManager = Injekt.get() downloadAddonManager = Injekt.get()
torrentAddonManager.init() torrentAddonManager.init()
downloadAddonManager.init() downloadAddonManager.init()
if (PrefManager.getVal<Int>(PrefName.CommentsEnabled) == 1) {
CommentsAPI.fetchAuthToken(this@App) CommentsAPI.fetchAuthToken(this@App)
}
val useAlarmManager = PrefManager.getVal<Boolean>(PrefName.UseAlarmManager) val useAlarmManager = PrefManager.getVal<Boolean>(PrefName.UseAlarmManager)
val scheduler = TaskScheduler.create(this@App, useAlarmManager) val scheduler = TaskScheduler.create(this@App, useAlarmManager)

View file

@ -287,7 +287,7 @@ class MainActivity : AppCompatActivity() {
.get() > 0 || preferences.mangaExtensionUpdatesCount().get() > 0 .get() > 0 || preferences.mangaExtensionUpdatesCount().get() > 0
) { ) {
snackString(R.string.extension_updates_available) snackString(R.string.extension_updates_available)
?.setDuration(Snackbar.LENGTH_LONG) ?.setDuration(Snackbar.LENGTH_SHORT)
?.setAction(R.string.review) { ?.setAction(R.string.review) {
startActivity(Intent(this, ExtensionsActivity::class.java)) startActivity(Intent(this, ExtensionsActivity::class.java))
} }

View file

@ -27,8 +27,11 @@ import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
object CommentsAPI { object CommentsAPI {
private const val ADDRESS: String = "https://api.dantotsu.app" private const val API_ADDRESS: String = "https://api.dantotsu.app"
private const val LOCAL_HOST: String = "https://127.0.0.1"
private var isOnline: Boolean = true private var isOnline: Boolean = true
private var commentsEnabled = PrefManager.getVal<Int>(PrefName.CommentsEnabled) == 1
private val ADDRESS: String get() = if (commentsEnabled) API_ADDRESS else LOCAL_HOST
var authToken: String? = null var authToken: String? = null
var userId: String? = null var userId: String? = null
var isBanned: Boolean = false var isBanned: Boolean = false
@ -369,10 +372,9 @@ object CommentsAPI {
} }
errorMessage("Failed to login after multiple attempts") errorMessage("Failed to login after multiple attempts")
} }
private fun errorMessage(reason: String) { private fun errorMessage(reason: String) {
Logger.log(reason) if (commentsEnabled) Logger.log(reason)
if (isOnline) snackString(reason) if (isOnline && commentsEnabled) snackString(reason)
} }
fun logout() { fun logout() {

View file

@ -372,7 +372,9 @@ class MediaDetailsActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedLi
navBar.createTab(R.drawable.ic_round_comment_24, R.string.comments, R.id.comment) navBar.createTab(R.drawable.ic_round_comment_24, R.string.comments, R.id.comment)
navBar.addTab(infoTab) navBar.addTab(infoTab)
navBar.addTab(watchTab) navBar.addTab(watchTab)
if (PrefManager.getVal<Int>(PrefName.CommentsEnabled) == 1) {
navBar.addTab(commentTab) navBar.addTab(commentTab)
}
if (model.continueMedia == null && media.cameFromContinue) { if (model.continueMedia == null && media.cameFromContinue) {
model.continueMedia = PrefManager.getVal(PrefName.ContinueMedia) model.continueMedia = PrefManager.getVal(PrefName.ContinueMedia)
selected = 1 selected = 1

View file

@ -20,21 +20,18 @@ class AlarmManagerScheduler(private val context: Context) : TaskScheduler {
return return
} }
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
val intent = when (taskType) {
TaskType.COMMENT_NOTIFICATION -> Intent(
context,
CommentNotificationReceiver::class.java
)
TaskType.ANILIST_NOTIFICATION -> Intent( val intent = when {
context, taskType == TaskType.COMMENT_NOTIFICATION && PrefManager.getVal<Int>(PrefName.CommentsEnabled) == 1 ->
AnilistNotificationReceiver::class.java Intent(context, CommentNotificationReceiver::class.java)
)
TaskType.SUBSCRIPTION_NOTIFICATION -> Intent( taskType == TaskType.ANILIST_NOTIFICATION ->
context, Intent(context, AnilistNotificationReceiver::class.java)
SubscriptionNotificationReceiver::class.java
) taskType == TaskType.SUBSCRIPTION_NOTIFICATION ->
Intent(context, SubscriptionNotificationReceiver::class.java)
else -> return
} }
val pendingIntent = PendingIntent.getBroadcast( val pendingIntent = PendingIntent.getBroadcast(
@ -64,21 +61,18 @@ class AlarmManagerScheduler(private val context: Context) : TaskScheduler {
override fun cancelTask(taskType: TaskType) { override fun cancelTask(taskType: TaskType) {
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
val intent = when (taskType) {
TaskType.COMMENT_NOTIFICATION -> Intent(
context,
CommentNotificationReceiver::class.java
)
TaskType.ANILIST_NOTIFICATION -> Intent( val intent = when {
context, taskType == TaskType.COMMENT_NOTIFICATION && PrefManager.getVal<Int>(PrefName.CommentsEnabled) == 1 ->
AnilistNotificationReceiver::class.java Intent(context, CommentNotificationReceiver::class.java)
)
TaskType.SUBSCRIPTION_NOTIFICATION -> Intent( taskType == TaskType.ANILIST_NOTIFICATION ->
context, Intent(context, AnilistNotificationReceiver::class.java)
SubscriptionNotificationReceiver::class.java
) taskType == TaskType.SUBSCRIPTION_NOTIFICATION ->
Intent(context, SubscriptionNotificationReceiver::class.java)
else -> return
} }
val pendingIntent = PendingIntent.getBroadcast( val pendingIntent = PendingIntent.getBroadcast(

View file

@ -11,6 +11,8 @@ import androidx.lifecycle.Lifecycle
import androidx.viewpager2.adapter.FragmentStateAdapter import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2 import androidx.viewpager2.widget.ViewPager2
import ani.dantotsu.R import ani.dantotsu.R
import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.databinding.ActivityNotificationBinding import ani.dantotsu.databinding.ActivityNotificationBinding
import ani.dantotsu.initActivity import ani.dantotsu.initActivity
import ani.dantotsu.navBarHeight import ani.dantotsu.navBarHeight
@ -24,6 +26,8 @@ class NotificationActivity : AppCompatActivity() {
lateinit var binding: ActivityNotificationBinding lateinit var binding: ActivityNotificationBinding
private var selected: Int = 0 private var selected: Int = 0
lateinit var navBar: AnimatedBottomBar lateinit var navBar: AnimatedBottomBar
private val CommentsEnabled = PrefManager.getVal<Int>(PrefName.CommentsEnabled) == 1
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
ThemeManager(this).applyTheme() ThemeManager(this).applyTheme()
@ -38,19 +42,23 @@ class NotificationActivity : AppCompatActivity() {
binding.root.updateLayoutParams<ViewGroup.MarginLayoutParams> { binding.root.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = navBarHeight bottomMargin = navBarHeight
} }
val tabs = listOf(
val tabs = mutableListOf(
Pair(R.drawable.ic_round_person_24, "User"), Pair(R.drawable.ic_round_person_24, "User"),
Pair(R.drawable.ic_round_movie_filter_24, "Media"), Pair(R.drawable.ic_round_movie_filter_24, "Media"),
Pair(R.drawable.ic_round_notifications_active_24, "Subs"), Pair(R.drawable.ic_round_notifications_active_24, "Subs")
Pair(R.drawable.ic_round_comment_24, "Comments")
) )
if (CommentsEnabled) {
tabs.add(Pair(R.drawable.ic_round_comment_24, "Comments"))
}
tabs.forEach { (icon, title) -> navBar.addTab(navBar.createTab(icon, title)) } tabs.forEach { (icon, title) -> navBar.addTab(navBar.createTab(icon, title)) }
binding.notificationBack.setOnClickListener { onBackPressedDispatcher.onBackPressed() } binding.notificationBack.setOnClickListener { onBackPressedDispatcher.onBackPressed() }
val getOne = intent.getIntExtra("activityId", -1) val getOne = intent.getIntExtra("activityId", -1)
if (getOne != -1) navBar.isVisible = false if (getOne != -1) navBar.isVisible = false
binding.notificationViewPager.isUserInputEnabled = false binding.notificationViewPager.isUserInputEnabled = false
binding.notificationViewPager.adapter = ViewPagerAdapter(supportFragmentManager, lifecycle, getOne) binding.notificationViewPager.adapter = ViewPagerAdapter(supportFragmentManager, lifecycle, getOne, CommentsEnabled)
binding.notificationViewPager.setCurrentItem(selected, false) binding.notificationViewPager.setCurrentItem(selected, false)
navBar.selectTabAt(selected) navBar.selectTabAt(selected)
navBar.setOnTabSelectListener(object : AnimatedBottomBar.OnTabSelectListener { navBar.setOnTabSelectListener(object : AnimatedBottomBar.OnTabSelectListener {
@ -65,18 +73,21 @@ class NotificationActivity : AppCompatActivity() {
} }
}) })
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
if (this::navBar.isInitialized) { if (this::navBar.isInitialized) {
navBar.selectTabAt(selected) navBar.selectTabAt(selected)
} }
} }
private class ViewPagerAdapter( private class ViewPagerAdapter(
fragmentManager: FragmentManager, fragmentManager: FragmentManager,
lifecycle: Lifecycle, lifecycle: Lifecycle,
val id: Int = -1 val id: Int = -1,
val commentsEnabled: Boolean
) : FragmentStateAdapter(fragmentManager, lifecycle) { ) : FragmentStateAdapter(fragmentManager, lifecycle) {
override fun getItemCount(): Int = if (id != -1) 1 else 4 override fun getItemCount(): Int = if (id != -1) 1 else if (commentsEnabled) 4 else 3
override fun createFragment(position: Int): Fragment = when (position) { override fun createFragment(position: Int): Fragment = when (position) {
0 -> newInstance(if (id != -1) ONE else USER, id) 0 -> newInstance(if (id != -1) ONE else USER, id)

View file

@ -24,6 +24,7 @@ import ani.dantotsu.openLinkInBrowser
import ani.dantotsu.others.CustomBottomDialog import ani.dantotsu.others.CustomBottomDialog
import ani.dantotsu.settings.saving.PrefManager import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.snackString
import ani.dantotsu.startMainActivity import ani.dantotsu.startMainActivity
import ani.dantotsu.statusBarHeight import ani.dantotsu.statusBarHeight
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
@ -233,10 +234,31 @@ class SettingsAccountActivity : AppCompatActivity() {
}, },
isActivity = true isActivity = true
), ),
Settings(
type = 2,
name = getString(R.string.comments_button),
desc = getString(R.string.comments_button_desc),
icon = R.drawable.ic_round_comment_24,
isChecked = PrefManager.getVal<Int>(PrefName.CommentsEnabled) == 1,
switch = { isChecked, _ ->
PrefManager.setVal(PrefName.CommentsEnabled, if (isChecked) 1 else 2 )
reload()
},
isVisible = Anilist.token != null
),
) )
) )
binding.settingsRecyclerView.layoutManager = binding.settingsRecyclerView.layoutManager =
LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
} }
fun reload() {
snackString(getString(R.string.restart_app_extra))
//snackString(R.string.restart_app_extra)
//?.setDuration(Snackbar.LENGTH_LONG)
//?.setAction(R.string.do_it) {
//startMainActivity(this@SettingsAccountActivity)
//} Disabled for now. Doesn't update the ADDRESS even after this
}
} }

View file

@ -46,6 +46,7 @@ enum class PrefName(val data: Pref) { //TODO: Split this into multiple files
IncludeAnimeList(Pref(Location.General, Boolean::class, true)), IncludeAnimeList(Pref(Location.General, Boolean::class, true)),
IncludeMangaList(Pref(Location.General, Boolean::class, true)), IncludeMangaList(Pref(Location.General, Boolean::class, true)),
AdultOnly(Pref(Location.General, Boolean::class, false)), AdultOnly(Pref(Location.General, Boolean::class, false)),
CommentsEnabled(Pref(Location.General, Int::class, 0)),
//User Interface //User Interface
UseOLED(Pref(Location.UI, Boolean::class, false)), UseOLED(Pref(Location.UI, Boolean::class, false)),

View file

@ -323,6 +323,7 @@
<string name="fav_anime">Favourite Anime</string> <string name="fav_anime">Favourite Anime</string>
<string name="fav_manga">Favourite Manga</string> <string name="fav_manga">Favourite Manga</string>
<string name="restart_app">Restart the app?</string> <string name="restart_app">Restart the app?</string>
<string name="restart_app_extra">Restart the app to apply changes</string>
<string name="next">Next</string> <string name="next">Next</string>
<string name="previous">Previous</string> <string name="previous">Previous</string>
<string name="current_page">Current Page</string> <string name="current_page">Current Page</string>
@ -746,6 +747,8 @@
<string name="restore_settings">Import Settings</string> <string name="restore_settings">Import Settings</string>
<string name="restore_settings_underline"><u>Restore Settings</u></string> <string name="restore_settings_underline"><u>Restore Settings</u></string>
<string name="try_internal_cast_experimental">Try Internal Cast (Experimental)</string> <string name="try_internal_cast_experimental">Try Internal Cast (Experimental)</string>
<string name="comments_button">Enable Comments</string>
<string name="comments_button_desc">Dantotsu\'s very own comments server</string>
<string name="comments">Comments</string> <string name="comments">Comments</string>
<string name="newest">Newest</string> <string name="newest">Newest</string>