Replies: 3 comments 2 replies
-
@Docile-Alligator what do you think about this? |
Beta Was this translation helpful? Give feedback.
-
Thank you for these!
|
Beta Was this translation helpful? Give feedback.
-
I don't have much free time anymore, so I'm going to stop actively contributing to Infinity. However there are some ideas that I think are cool but I haven't completed implementing. Feel free to use them however you want.
|
Beta Was this translation helpful? Give feedback.
-
I've been contributing to Infinity for some time now and I came up with some ideas that I believe can improve the overall quality of the code. Since they aren't actually fixing any bugs and some ideas require massive refactorings, I wanted to get some feedback first. Please let me know what you think about this, if you agree/disagree with the ideas or if you want to discuss them in more detail.
Here's the list. There is no strict order but I tried to put simpler stuff first and more complex stuff at the end.
Fix lint issues. 2600 errors/warnings. 1700 of them are
NonConstantResourceId
about layout ids used inButterKnife
. Some are real things worth fixing, others can be added to baseline/ignored.Fix android studio warnings. 4000 warnings, 1000 of them in Android Lint category. Also 1000 of them are about making fields final. 200 are deprecation warnings.
Run lint and static analyzer as github actions.
Use
IntDef
s andStringDef
s. Examples: vote type, placeholder type. Makes code more self-documenting without switching to enums. Will help catch errors like forgotten comparison or wrong constant.Use
ColorInt
,StyleRes
and other annotations. Same benefits as previous one.Use nullability annotations. There are some personal preferences (does everything need to be annotated? are non-annotated fields nullable by default?) and not everything can be annotated. But combined with final fields this might simplify some code.
Fix
LiveData
usages. There are a couple of places similar toTransformations.switchMap(someLiveData, someValue -> doStuff(someLiveData.getValue()));
Reduce boilerplate for accessing
SharedPreferences
. There is a lot of code like(accountName == null ? "" : accountName) + SharedPreferencesUtils.SOME_KEY
or parsing a string from preferences into int. It would be nice to abstract such details. Maybe also migrate toDataStore
library, but that's probably not worth it.Reduce code duplication. This is a part of many ideas, but sometimes it is just duplicated code. Examples:
ItemSwipeHelper
, voting inPostRecyclerViewAdapter
, adapter callbacks.Reduce the number of Retrofit api creations. This can be done by injecting
Provider<API>
instead of Retrofit instances. Has performance benefits and uses types to catch errors compile time.Use Retrofit converters and optional query parameters for sort type and time. Allows to call
api.foo(sort.getType(),sort.getTime())
without null checks. Or maybe just optional query and helper methods:api.foo(sort.getTypeValue(), sort.getTimeValue())
. I actually prefer the first variant because it does not allow any arbitrary string as parameter.Replace
ButterKnife
withViewBinding
. This is needed anyways because of changes in Gradle 8. Included in lint issues.Update paging code. Included in android studio warnings. Also handle loading status by the paging library.
Apply auth headers using
Authenticator
/Interceptor
. This should simplify logic and remove code duplication. Should be careful with account switching, but current authenticator implementation doesn’t really handle account switching anyways. Also related to this is an option to createOauthRedditAPI
andNoOauthRedditAPI
, both extendingRedditAPI
and inject one of them. This allows to add type safety without duplicating common paths.Stop updating data based on
getBindingAdapterPosition()
and use its id instead. BecauseViewHolders
can be reused, this can lead to bugs: by the time callback is calledViewHolder
can be bound to another piece of data, so wrong data will be updated (e.g. Pressing "See removed comment" will "edit" wrong message #822).Stop updating views in
ViewHolder
s manually and usenotifyItemChanged
, maybe withpayload
argument for efficiency. Reduces code duplication.Use Dagger more. This one is tricky, it looks like there is no more code that could be injected with dagger right away. But the two potential use cases are Fetch* classes and ViewModel factories.
Use constructor injection in fragments. Available in new versions of
androidx.fragment
library by using a factory. Allows to make more stuff final/immutable.Treat more ui settings changes like configuration changes and recreate activities (or just adapters). Allows to make more stuff final/immutable and simplify code.
Separate adapters and data manipulation. Simplifies code in the sense of following single responsibility principle and separating unrelated things.
Move to a “single source of truth” architecture. Related to the previous one. Enforces consistency of data everywhere by allowing changes only in one place.
Beta Was this translation helpful? Give feedback.
All reactions