WIP: HomeActivity cleanup #40
No reviewers
Labels
No Label
Difficulty - Beginner friendly
Difficulty = Easy
Difficulty = Hard
Difficulty = Medium
Priority = CRITICAL
Priority = High
Priority = Low
Priority = Normal
Priority = Some day
Status - Fixed somewhere else
Status - No details provided
Status = Can't fix
Status = Duplicate
Status = Help wanted
Status = Invalid
Status = Need more details
Status = Taken
Status = Wontfix
Type - Selfoss works like this
Type = Bug
Type = Chore
Type = Enhancement
Type = Feature
Type = Question
Type = SELFOSS API ISSUE
Type = Tools
Type = UX/Design
Up For Grabs
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: Louvorg/ReaderForSelfoss-multiplatform#40
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "davidoskky/ReaderForSelfoss-multiplatform:dispatchers"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Types of changes
I'm trying to move most of the code in the HomeActivity to the viewmodel and to use Dispatchers.IO for all operations that use the database or the api.
I'm already doing a lot of cleaning in here https://gitea.amine-louveau.fr/Louvorg/ReaderForSelfoss-multiplatform/src/branch/feature/api_timeout_and_settings_cleaning
Maybe wait to continue on this PR ?
Oh, I did not notice that.
I will wait for you to merge that before continuing.
Thanks !
I did a quick review, but as I'll clean some code, don't spend much time on this for now.
I'll try to finish my changes pretty soon.
@ -453,7 +471,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
// TODO: refactor this.
private fun handleDrawerItems() {
tagsBadge = emptyMap()
fun handleDrawerData(maybeDrawerData: DrawerData?, loadedFromCache: Boolean = false) {
Why did you remove this ?
I think that this will break some features.
I already started refactoring this, so I'll handle this.
@ -144,1 +148,4 @@
setContentView(view)
lifecycleScope.launch {
viewModel.refreshingIndicatorProvider.collect { showRefresh ->
binding.swipeRefreshLayout.isRefreshing = showRefresh
The view/activity/fragment should be the one that knows when to display the refresh loading or not.
Alright, I'll find a different way to handle this then.
@ -155,1 +164,4 @@
customTabActivityHelper = CustomTabActivityHelper()
handleSettings()
lifecycleScope.launch {
The view should call the repository and get the data from there.
This seams too complicated.
Storing the items would allow sharing the same data across all activities without passing it around and it can be used to prevent making an api call every time you close an article and come back to the article list; which is in fact unnecessary.
this is intended to fetch the new articles as soon as possible.
Personal use case: selfoss fetches new articles every 15 minutes, in the application I will be reading an article in a couple of minutes and then going back to the articles list to select another one.
Every time I go back to the articles list the fetching starts, which is annoying because of the loading spinner appearing at the top each time.
I have no need for it to be updating so often, and most of those updates are useless anyways because most of the times no new items will be available on the server.
I can manually update the articles list at any time if I wish or if I finished reading all the available ones.
I remember someone else opened an issue some time ago complaining about the frequency of updates as well.
Why don't you swipe between the articles ?
That user in particular had issues with the tags and sources loading. They had a lot of them. That's why the update_sources setting was added.
I have many articles to read and I do not read them in order, it is easier for me to get back to the list and select from there what I want to read rather than swiping through until I find something interesting.
That makes sens, but I still thinks the app needs to refresh
onReload
.We could try to find a way to differenciate between "going back from another activity of the app" and "relaunching the app after it being in the background". This would solve both our use cases.
Yes, I feel this could be a great way to solve this issue.
@ -923,3 +877,3 @@
}
private fun reloadBadgeContent() {
private fun handleBadgesContent() {
This way better !
@ -84,6 +84,15 @@ class MyApp : MultiDexApplication(), DIAware {
).show()
}
}
CoroutineScope(Dispatchers.Main).launch {
I don't think that this should be here. Each activity/fragment should know what they want to display, and how.
@ -29,2 +42,4 @@
}
}
fun updateRemote() {
Why were these moved here ?
updateRemote doesn't necessarily have to be there, I have done it because I think it makes it easier to read through the activity code.
getItems in the viewmodel allows storing the items in the viewmodel which might provide some advantages.
I find it more difficult to read. Moving some code that's only available and usable in a specific activity in a shared
ViewModel
isn't necessary.There is no need to refactor thing this soon. If there is currently no need to have the items in the viewmodel, there is no need to have them here.
@ -43,4 +45,4 @@
init {
// TODO: Dispatchers.IO not available in KMM, an alternative solution should be found
CoroutineScope(Dispatchers.Main).launch {
updateApiVersion()
updateApiVersion()
andreloadBadges()
both check the network availability. This change isn't needed.When init is run the connectivity check always fails.
This allows retrieving the badges every time connectivity gets back.
We could include here all operations that should be run as soon as network connectivity is available, such as fetching sources and tags.
So this is a bug that should be fixed instead of having this workaround.
This isn't a good thing, since items arn't refreshed on connectivity change. We would have a difference in the items count and the badge count.
Fetching sources and tags can be limited via a
update_sources
. It's also something that shouldn't be done as much as items fetching.@ -146,3 +153,4 @@
} else {
getDBTags().map { it.toView() }
}
if (tags != null) {
resetDBTagsWithData
should only be done if network the api call was done, and ifupdate_sources
setting is set to false.@ -163,3 +173,4 @@
} else {
ArrayList(getDBSources().map { it.toView() })
}
if (sources != null) {
resetDBSourcesWithData
should only be done if network the api call was done, and ifupdate_sources
setting is set to false.I guess that most of the stuff in this PR isn't very useful since what we concluded discussing.
I can close this and make a new one only including the changes which are useful after you merge the one you're working on.
Ok, great ! I'll let you know when I finish my refactoring.
@davidoskky I did a big cleaning as tou can see in #45, but I still need to #44.
Pull request closed