fix: notification list blank on click

This commit is contained in:
rebelonion 2024-03-15 17:38:02 -05:00
parent 12c77604f1
commit e00bbb2d8e
5 changed files with 38 additions and 13 deletions

View file

@ -51,6 +51,7 @@ import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.SharedPreferenceBooleanLiveData import ani.dantotsu.settings.saving.SharedPreferenceBooleanLiveData
import ani.dantotsu.subcriptions.Subscription.Companion.startSubscription import ani.dantotsu.subcriptions.Subscription.Companion.startSubscription
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
import ani.dantotsu.util.Logger
import com.google.android.material.snackbar.BaseTransientBottomBar import com.google.android.material.snackbar.BaseTransientBottomBar
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.domain.source.service.SourcePreferences
@ -224,6 +225,7 @@ class MainActivity : AppCompatActivity() {
bottomMargin = navBarHeight bottomMargin = navBarHeight
} }
} }
intent.extras?.let { extras -> intent.extras?.let { extras ->
val fragmentToLoad = extras.getString("FRAGMENT_TO_LOAD") val fragmentToLoad = extras.getString("FRAGMENT_TO_LOAD")
val mediaId = extras.getInt("mediaId", -1) val mediaId = extras.getInt("mediaId", -1)
@ -245,6 +247,7 @@ class MainActivity : AppCompatActivity() {
} }
startActivity(feedIntent) startActivity(feedIntent)
} else if (fragmentToLoad == "NOTIFICATIONS" && activityId != -1) { } else if (fragmentToLoad == "NOTIFICATIONS" && activityId != -1) {
Logger.log("MainActivity, onCreate: $activityId")
val notificationIntent = Intent(this, NotificationActivity::class.java).apply { val notificationIntent = Intent(this, NotificationActivity::class.java).apply {
putExtra("FRAGMENT_TO_LOAD", "NOTIFICATIONS") putExtra("FRAGMENT_TO_LOAD", "NOTIFICATIONS")
putExtra("activityId", activityId) putExtra("activityId", activityId)

View file

@ -128,6 +128,7 @@ object Anilist {
cache: Int? = null cache: Int? = null
): T? { ): T? {
return try { return try {
if (show) Logger.log("Anilist Query: $query")
if (rateLimitReset > System.currentTimeMillis() / 1000) { if (rateLimitReset > System.currentTimeMillis() / 1000) {
toast("Rate limited. Try after ${rateLimitReset - (System.currentTimeMillis() / 1000)} seconds") toast("Rate limited. Try after ${rateLimitReset - (System.currentTimeMillis() / 1000)} seconds")
throw Exception("Rate limited after ${rateLimitReset - (System.currentTimeMillis() / 1000)} seconds") throw Exception("Rate limited after ${rateLimitReset - (System.currentTimeMillis() / 1000)} seconds")
@ -163,7 +164,7 @@ object Anilist {
throw Exception("Rate limited after $retry seconds") throw Exception("Rate limited after $retry seconds")
} }
if (!json.text.startsWith("{")) {throw Exception(currContext()?.getString(R.string.anilist_down))} if (!json.text.startsWith("{")) {throw Exception(currContext()?.getString(R.string.anilist_down))}
if (show) Logger.log("Anilist Query: ${json.text}") if (show) Logger.log("Anilist Response: ${json.text}")
json.parsed() json.parsed()
} else null } else null
} catch (e: Exception) { } catch (e: Exception) {

View file

@ -14,7 +14,6 @@ import ani.dantotsu.MainActivity
import ani.dantotsu.R import ani.dantotsu.R
import ani.dantotsu.connections.anilist.Anilist import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.profile.activity.ActivityItemBuilder import ani.dantotsu.profile.activity.ActivityItemBuilder
import ani.dantotsu.profile.activity.FeedActivity
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 eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.notification.Notifications
@ -72,14 +71,14 @@ class AnilistNotificationWorker(appContext: Context, workerParams: WorkerParamet
private fun createNotification( private fun createNotification(
context: Context, context: Context,
content: String, content: String,
activityId: Int? = null notificationId: Int? = null
): android.app.Notification { ): android.app.Notification {
val title = "New Anilist Notification" val title = "New Anilist Notification"
val intent = Intent(applicationContext, MainActivity::class.java).apply { val intent = Intent(applicationContext, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
putExtra("FRAGMENT_TO_LOAD", "NOTIFICATIONS") putExtra("FRAGMENT_TO_LOAD", "NOTIFICATIONS")
if (activityId != null) { if (notificationId != null) {
putExtra("activityId", activityId) putExtra("activityId", notificationId)
} }
} }
val pendingIntent = PendingIntent.getActivity( val pendingIntent = PendingIntent.getActivity(

View file

@ -19,9 +19,12 @@ import ani.dantotsu.initActivity
import ani.dantotsu.media.MediaDetailsActivity import ani.dantotsu.media.MediaDetailsActivity
import ani.dantotsu.navBarHeight import ani.dantotsu.navBarHeight
import ani.dantotsu.profile.ProfileActivity import ani.dantotsu.profile.ProfileActivity
import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.snackString import ani.dantotsu.snackString
import ani.dantotsu.statusBarHeight import ani.dantotsu.statusBarHeight
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
import ani.dantotsu.util.Logger
import com.xwray.groupie.GroupieAdapter import com.xwray.groupie.GroupieAdapter
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -41,10 +44,15 @@ class NotificationActivity : AppCompatActivity() {
binding = ActivityFollowBinding.inflate(layoutInflater) binding = ActivityFollowBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
binding.listTitle.text = "Notifications" binding.listTitle.text = "Notifications"
binding.listToolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> { topMargin = statusBarHeight } binding.listToolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
binding.listFrameLayout.updateLayoutParams<ViewGroup.MarginLayoutParams> { bottomMargin = navBarHeight } topMargin = statusBarHeight
}
binding.listFrameLayout.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = navBarHeight
}
binding.listRecyclerView.adapter = adapter binding.listRecyclerView.adapter = adapter
binding.listRecyclerView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false) binding.listRecyclerView.layoutManager =
LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
binding.followerGrid.visibility = ViewGroup.GONE binding.followerGrid.visibility = ViewGroup.GONE
binding.followerList.visibility = ViewGroup.GONE binding.followerList.visibility = ViewGroup.GONE
binding.listBack.setOnClickListener { binding.listBack.setOnClickListener {
@ -54,8 +62,13 @@ class NotificationActivity : AppCompatActivity() {
val activityId = intent.getIntExtra("activityId", -1) val activityId = intent.getIntExtra("activityId", -1)
lifecycleScope.launch { lifecycleScope.launch {
val resetNotification = activityId == -1 val resetNotification = activityId == -1
val res = Anilist.query.getNotifications(Anilist.userid?:0, resetNotification = resetNotification) val res = Anilist.query.getNotifications(
Anilist.userid ?: PrefManager.getVal<String>(PrefName.AnilistUserId).toIntOrNull()
?: 0,
resetNotification = resetNotification
)
res?.data?.page?.notifications?.let { notifications -> res?.data?.page?.notifications?.let { notifications ->
Logger.log("Notifications: $notifications")
notificationList = if (activityId != -1) { notificationList = if (activityId != -1) {
notifications.filter { it.id == activityId } notifications.filter { it.id == activityId }
} else { } else {
@ -63,7 +76,7 @@ class NotificationActivity : AppCompatActivity() {
} }
adapter.update(notificationList.map { NotificationItem(it, ::onNotificationClick) }) adapter.update(notificationList.map { NotificationItem(it, ::onNotificationClick) })
} }
withContext(Dispatchers.Main){ withContext(Dispatchers.Main) {
binding.listProgressBar.visibility = ViewGroup.GONE binding.listProgressBar.visibility = ViewGroup.GONE
binding.listRecyclerView.setOnTouchListener { _, event -> binding.listRecyclerView.setOnTouchListener { _, event ->
if (event?.action == MotionEvent.ACTION_UP) { if (event?.action == MotionEvent.ACTION_UP) {
@ -76,11 +89,16 @@ class NotificationActivity : AppCompatActivity() {
page++ page++
binding.followRefresh.visibility = ViewGroup.VISIBLE binding.followRefresh.visibility = ViewGroup.VISIBLE
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
val res = Anilist.query.getNotifications(Anilist.userid?:0, page) val res = Anilist.query.getNotifications(Anilist.userid ?: 0, page)
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
res?.data?.page?.notifications?.let { notifications -> res?.data?.page?.notifications?.let { notifications ->
notificationList += notifications notificationList += notifications
adapter.addAll(notifications.map { NotificationItem(it, ::onNotificationClick) }) adapter.addAll(notifications.map {
NotificationItem(
it,
::onNotificationClick
)
})
} }
binding.followRefresh.visibility = ViewGroup.GONE binding.followRefresh.visibility = ViewGroup.GONE
} }
@ -101,18 +119,21 @@ class NotificationActivity : AppCompatActivity() {
.putExtra("userId", id), null .putExtra("userId", id), null
) )
} }
NotificationClickType.MEDIA -> { NotificationClickType.MEDIA -> {
ContextCompat.startActivity( ContextCompat.startActivity(
this, Intent(this, MediaDetailsActivity::class.java) this, Intent(this, MediaDetailsActivity::class.java)
.putExtra("mediaId", id), null .putExtra("mediaId", id), null
) )
} }
NotificationClickType.ACTIVITY -> { NotificationClickType.ACTIVITY -> {
ContextCompat.startActivity( ContextCompat.startActivity(
this, Intent(this, FeedActivity::class.java) this, Intent(this, FeedActivity::class.java)
.putExtra("activityId", id), null .putExtra("activityId", id), null
) )
} }
NotificationClickType.UNDEFINED -> { NotificationClickType.UNDEFINED -> {
// Do nothing // Do nothing
} }

View file

@ -2,6 +2,7 @@ package ani.dantotsu.util
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.util.Log
import androidx.core.content.FileProvider import androidx.core.content.FileProvider
import ani.dantotsu.BuildConfig import ani.dantotsu.BuildConfig
import ani.dantotsu.connections.crashlytics.CrashlyticsInterface import ani.dantotsu.connections.crashlytics.CrashlyticsInterface
@ -78,7 +79,7 @@ object Logger {
fun log(message: String) { fun log(message: String) {
val trace = Thread.currentThread().stackTrace[3] val trace = Thread.currentThread().stackTrace[3]
loggerExecutor.execute { loggerExecutor.execute {
if (file == null) println(message) if (file == null) Log.d("Internal Logger", "$message)")
else { else {
val className = trace.className val className = trace.className
val methodName = trace.methodName val methodName = trace.methodName