Skip to content

Commit ed1a530

Browse files
feat: Refactor NewsLabelManager to prevent ANR
Refactored `NewsLabelManager` to use a `NewsRepository` and coroutines to move database operations off the main thread, fixing an ANR. - Introduced `addLabel` and `removeLabel` suspend functions in `NewsRepository`. - `NewsLabelManager` now uses a `CoroutineScope` from the view's `lifecycleScope` to call the repository methods asynchronously. - Disabled the "add label" button and chip delete functionality during the async operation to prevent rapid double-clicks. - Fixed a resource leak in `AdapterNews` by properly managing the Realm instance lifecycle within `onAttachedToRecyclerView` and `onDetachedFromRecyclerView`. - Updated all call sites of `AdapterNews` (`NewsFragment`, `ReplyActivity`, `DiscussionListFragment`) to provide the `NewsRepository` dependency via Hilt. - Resolved all compilation and Hilt dependency injection errors that arose from the refactoring.
1 parent c0dd20a commit ed1a530

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

app/src/main/java/org/ole/planet/myplanet/ui/news/ReplyActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import org.ole.planet.myplanet.databinding.ActivityReplyBinding
3030
import org.ole.planet.myplanet.datamanager.DatabaseService
3131
import org.ole.planet.myplanet.model.RealmNews
3232
import org.ole.planet.myplanet.model.RealmUserModel
33+
import org.ole.planet.myplanet.repository.NewsRepository
3334
import org.ole.planet.myplanet.service.UserProfileDbHandler
3435
import org.ole.planet.myplanet.ui.navigation.NavigationHelper
3536
import org.ole.planet.myplanet.ui.news.AdapterNews.OnNewsItemClickListener

app/src/main/java/org/ole/planet/myplanet/ui/team/teamDiscussion/DiscussionListFragment.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import org.ole.planet.myplanet.model.RealmMyTeam
2727
import org.ole.planet.myplanet.model.RealmNews
2828
import org.ole.planet.myplanet.model.RealmNews.Companion.createNews
2929
import org.ole.planet.myplanet.model.RealmTeamNotification
30+
import org.ole.planet.myplanet.repository.NewsRepository
3031
import org.ole.planet.myplanet.service.UserProfileDbHandler
3132
import org.ole.planet.myplanet.ui.chat.ChatDetailFragment
3233
import org.ole.planet.myplanet.ui.navigation.NavigationHelper

0 commit comments

Comments
 (0)