diff --git a/app/src/main/java/ani/dantotsu/App.kt b/app/src/main/java/ani/dantotsu/App.kt index e30179bcf0b..a12d288dfd3 100644 --- a/app/src/main/java/ani/dantotsu/App.kt +++ b/app/src/main/java/ani/dantotsu/App.kt @@ -105,6 +105,14 @@ class App : MultiDexApplication() { LogcatLogger.install(AndroidLogcatLogger(LogPriority.VERBOSE)) } + if (PrefManager.getVal(PrefName.CommentsEnabled) == 0) { + if (BuildConfig.FLAVOR.contains("fdroid")) { + PrefManager.setVal(PrefName.CommentsEnabled, 2) + } else { + PrefManager.setVal(PrefName.CommentsEnabled, 1) + } + } + CoroutineScope(Dispatchers.IO).launch { animeExtensionManager = Injekt.get() animeExtensionManager.findAvailableExtensions() @@ -128,7 +136,9 @@ class App : MultiDexApplication() { downloadAddonManager = Injekt.get() torrentAddonManager.init() downloadAddonManager.init() - CommentsAPI.fetchAuthToken(this@App) + if (PrefManager.getVal(PrefName.CommentsEnabled) == 1) { + CommentsAPI.fetchAuthToken(this@App) + } val useAlarmManager = PrefManager.getVal(PrefName.UseAlarmManager) val scheduler = TaskScheduler.create(this@App, useAlarmManager) diff --git a/app/src/main/java/ani/dantotsu/MainActivity.kt b/app/src/main/java/ani/dantotsu/MainActivity.kt index 412ed67692c..2e87a7a5df0 100644 --- a/app/src/main/java/ani/dantotsu/MainActivity.kt +++ b/app/src/main/java/ani/dantotsu/MainActivity.kt @@ -287,7 +287,7 @@ class MainActivity : AppCompatActivity() { .get() > 0 || preferences.mangaExtensionUpdatesCount().get() > 0 ) { snackString(R.string.extension_updates_available) - ?.setDuration(Snackbar.LENGTH_LONG) + ?.setDuration(Snackbar.LENGTH_SHORT) ?.setAction(R.string.review) { startActivity(Intent(this, ExtensionsActivity::class.java)) } diff --git a/app/src/main/java/ani/dantotsu/connections/comments/CommentsAPI.kt b/app/src/main/java/ani/dantotsu/connections/comments/CommentsAPI.kt index 57d08531e69..8f6fb98d010 100644 --- a/app/src/main/java/ani/dantotsu/connections/comments/CommentsAPI.kt +++ b/app/src/main/java/ani/dantotsu/connections/comments/CommentsAPI.kt @@ -27,8 +27,11 @@ import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get 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 commentsEnabled = PrefManager.getVal(PrefName.CommentsEnabled) == 1 + private val ADDRESS: String get() = if (commentsEnabled) API_ADDRESS else LOCAL_HOST var authToken: String? = null var userId: String? = null var isBanned: Boolean = false @@ -369,10 +372,9 @@ object CommentsAPI { } errorMessage("Failed to login after multiple attempts") } - private fun errorMessage(reason: String) { - Logger.log(reason) - if (isOnline) snackString(reason) + if (commentsEnabled) Logger.log(reason) + if (isOnline && commentsEnabled) snackString(reason) } fun logout() { diff --git a/app/src/main/java/ani/dantotsu/media/MediaDetailsActivity.kt b/app/src/main/java/ani/dantotsu/media/MediaDetailsActivity.kt index d9b44e999d0..151327f99c9 100644 --- a/app/src/main/java/ani/dantotsu/media/MediaDetailsActivity.kt +++ b/app/src/main/java/ani/dantotsu/media/MediaDetailsActivity.kt @@ -372,7 +372,9 @@ class MediaDetailsActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedLi navBar.createTab(R.drawable.ic_round_comment_24, R.string.comments, R.id.comment) navBar.addTab(infoTab) navBar.addTab(watchTab) - navBar.addTab(commentTab) + if (PrefManager.getVal(PrefName.CommentsEnabled) == 1) { + navBar.addTab(commentTab) + } if (model.continueMedia == null && media.cameFromContinue) { model.continueMedia = PrefManager.getVal(PrefName.ContinueMedia) selected = 1 diff --git a/app/src/main/java/ani/dantotsu/notifications/AlarmManagerScheduler.kt b/app/src/main/java/ani/dantotsu/notifications/AlarmManagerScheduler.kt index f5ed216cc54..8a1cc10fc85 100644 --- a/app/src/main/java/ani/dantotsu/notifications/AlarmManagerScheduler.kt +++ b/app/src/main/java/ani/dantotsu/notifications/AlarmManagerScheduler.kt @@ -20,21 +20,18 @@ class AlarmManagerScheduler(private val context: Context) : TaskScheduler { return } 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( - context, - AnilistNotificationReceiver::class.java - ) + val intent = when { + taskType == TaskType.COMMENT_NOTIFICATION && PrefManager.getVal(PrefName.CommentsEnabled) == 1 -> + Intent(context, CommentNotificationReceiver::class.java) - TaskType.SUBSCRIPTION_NOTIFICATION -> Intent( - context, - SubscriptionNotificationReceiver::class.java - ) + taskType == TaskType.ANILIST_NOTIFICATION -> + Intent(context, AnilistNotificationReceiver::class.java) + + taskType == TaskType.SUBSCRIPTION_NOTIFICATION -> + Intent(context, SubscriptionNotificationReceiver::class.java) + + else -> return } val pendingIntent = PendingIntent.getBroadcast( @@ -64,21 +61,18 @@ class AlarmManagerScheduler(private val context: Context) : TaskScheduler { override fun cancelTask(taskType: TaskType) { 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( - context, - AnilistNotificationReceiver::class.java - ) + val intent = when { + taskType == TaskType.COMMENT_NOTIFICATION && PrefManager.getVal(PrefName.CommentsEnabled) == 1 -> + Intent(context, CommentNotificationReceiver::class.java) + + taskType == TaskType.ANILIST_NOTIFICATION -> + Intent(context, AnilistNotificationReceiver::class.java) + + taskType == TaskType.SUBSCRIPTION_NOTIFICATION -> + Intent(context, SubscriptionNotificationReceiver::class.java) - TaskType.SUBSCRIPTION_NOTIFICATION -> Intent( - context, - SubscriptionNotificationReceiver::class.java - ) + else -> return } val pendingIntent = PendingIntent.getBroadcast( diff --git a/app/src/main/java/ani/dantotsu/profile/notification/NotificationActivity.kt b/app/src/main/java/ani/dantotsu/profile/notification/NotificationActivity.kt index 05412474b65..087c94b5474 100644 --- a/app/src/main/java/ani/dantotsu/profile/notification/NotificationActivity.kt +++ b/app/src/main/java/ani/dantotsu/profile/notification/NotificationActivity.kt @@ -11,6 +11,8 @@ import androidx.lifecycle.Lifecycle import androidx.viewpager2.adapter.FragmentStateAdapter import androidx.viewpager2.widget.ViewPager2 import ani.dantotsu.R +import ani.dantotsu.settings.saving.PrefManager +import ani.dantotsu.settings.saving.PrefName import ani.dantotsu.databinding.ActivityNotificationBinding import ani.dantotsu.initActivity import ani.dantotsu.navBarHeight @@ -24,6 +26,8 @@ class NotificationActivity : AppCompatActivity() { lateinit var binding: ActivityNotificationBinding private var selected: Int = 0 lateinit var navBar: AnimatedBottomBar + private val CommentsEnabled = PrefManager.getVal(PrefName.CommentsEnabled) == 1 + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) ThemeManager(this).applyTheme() @@ -38,19 +42,23 @@ class NotificationActivity : AppCompatActivity() { binding.root.updateLayoutParams { bottomMargin = navBarHeight } - val tabs = listOf( + + val tabs = mutableListOf( Pair(R.drawable.ic_round_person_24, "User"), Pair(R.drawable.ic_round_movie_filter_24, "Media"), - Pair(R.drawable.ic_round_notifications_active_24, "Subs"), - Pair(R.drawable.ic_round_comment_24, "Comments") + Pair(R.drawable.ic_round_notifications_active_24, "Subs") ) + if (CommentsEnabled) { + tabs.add(Pair(R.drawable.ic_round_comment_24, "Comments")) + } + tabs.forEach { (icon, title) -> navBar.addTab(navBar.createTab(icon, title)) } binding.notificationBack.setOnClickListener { onBackPressedDispatcher.onBackPressed() } val getOne = intent.getIntExtra("activityId", -1) if (getOne != -1) navBar.isVisible = 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) navBar.selectTabAt(selected) navBar.setOnTabSelectListener(object : AnimatedBottomBar.OnTabSelectListener { @@ -65,18 +73,21 @@ class NotificationActivity : AppCompatActivity() { } }) } + override fun onResume() { super.onResume() if (this::navBar.isInitialized) { navBar.selectTabAt(selected) } } + private class ViewPagerAdapter( fragmentManager: FragmentManager, lifecycle: Lifecycle, - val id: Int = -1 + val id: Int = -1, + val commentsEnabled: Boolean ) : 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) { 0 -> newInstance(if (id != -1) ONE else USER, id) @@ -86,4 +97,4 @@ class NotificationActivity : AppCompatActivity() { else -> newInstance(MEDIA) } } -} +} \ No newline at end of file diff --git a/app/src/main/java/ani/dantotsu/settings/SettingsAccountActivity.kt b/app/src/main/java/ani/dantotsu/settings/SettingsAccountActivity.kt index a2c48b50581..7a5324004bb 100644 --- a/app/src/main/java/ani/dantotsu/settings/SettingsAccountActivity.kt +++ b/app/src/main/java/ani/dantotsu/settings/SettingsAccountActivity.kt @@ -24,6 +24,7 @@ import ani.dantotsu.openLinkInBrowser import ani.dantotsu.others.CustomBottomDialog import ani.dantotsu.settings.saving.PrefManager import ani.dantotsu.settings.saving.PrefName +import ani.dantotsu.snackString import ani.dantotsu.startMainActivity import ani.dantotsu.statusBarHeight import ani.dantotsu.themes.ThemeManager @@ -233,10 +234,31 @@ class SettingsAccountActivity : AppCompatActivity() { }, 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(PrefName.CommentsEnabled) == 1, + switch = { isChecked, _ -> + PrefManager.setVal(PrefName.CommentsEnabled, if (isChecked) 1 else 2 ) + reload() + }, + isVisible = Anilist.token != null + ), ) ) binding.settingsRecyclerView.layoutManager = 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 + } } + diff --git a/app/src/main/java/ani/dantotsu/settings/saving/Preferences.kt b/app/src/main/java/ani/dantotsu/settings/saving/Preferences.kt index 3bd63aae1ad..fb61242247b 100644 --- a/app/src/main/java/ani/dantotsu/settings/saving/Preferences.kt +++ b/app/src/main/java/ani/dantotsu/settings/saving/Preferences.kt @@ -46,6 +46,7 @@ enum class PrefName(val data: Pref) { //TODO: Split this into multiple files IncludeAnimeList(Pref(Location.General, Boolean::class, true)), IncludeMangaList(Pref(Location.General, Boolean::class, true)), AdultOnly(Pref(Location.General, Boolean::class, false)), + CommentsEnabled(Pref(Location.General, Int::class, 0)), //User Interface UseOLED(Pref(Location.UI, Boolean::class, false)), diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 83ac7c29e62..3e5b51f91f9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -323,6 +323,7 @@ Favourite Anime Favourite Manga Restart the app? + Restart the app to apply changes Next Previous Current Page @@ -746,6 +747,8 @@ Import Settings Restore Settings Try Internal Cast (Experimental) + Enable Comments + Dantotsu\'s very own comments server Comments Newest