Android-CleanArchitecture | sample app that is part of a series of blog posts | Architecture library
kandi X-RAY | Android-CleanArchitecture Summary
kandi X-RAY | Android-CleanArchitecture Summary
This is a sample app that is part of a series of blog posts I have written about how to architect an android application using Uncle Bob's clean architecture approach.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Download image from url .
- Gets user entities .
- Read the file content .
- Retrieve user entity from cache .
- Transform users model .
- Connect to API
- Creates a message from the given exception .
- sets the onBindViewHolder on the ListViewHolder
- Renders the user model .
- Gets the error message .
Android-CleanArchitecture Key Features
Android-CleanArchitecture Examples and Code Snippets
Community Discussions
Trending Discussions on Android-CleanArchitecture
QUESTION
I've seen good examples of MVP architecture (here and here). Both present only simple interactors, but I wonder how to deal with more complex use case, consisting of steps, which are repeated in other use cases.
For example, my API requires token to authenticate any call. I've created an interactor to get that token (GetToken
). I want to get user's last login date (GetLastLoginDate
) and then fetch a list of changes that occured between that date and now (GetVersionChanges
).
Where those interactor should be chained? I want to keep them separate, because some of them are reused in other parts of the code. I've came up with two solutions.
Presenter should chain all interactors. This solution works as long the use case is not complex and doesn't have many preconditions. It seems to me it's not the right place, because it burdens presenter with another responsibility.
Interactor can use many repositories (no clean architecture rules are broken then). Why not use
TokenRepository
in other interactors? Because getting token is much more complex than just reaching to repository. Repeating the steps in other interactor does not reuse already existing code.
Both solutions have their flaws and are against basic principles (DRY, single responsibility principle).
...ANSWER
Answered 2019-Apr-12 at 16:21If I were you I would just put the logic of getting a token in a separate interactor (maybe named getTokenInteractor) and call that interactor from your others interactor who may need it. That way, it would be in an interactor that you chose either to use a token (and call or not your getTokenInteractor) and also in an interactor that you retrieve it and deal with errors. I would do the same for your "getVersionChanges" use case and let an interactor chain the calls.
Let's imagine you have a presenter who needs to display the version changes. He will call a first interactor (GetVersionChangesInteractor) who will first check if he has a token (by calling getTokenInteractor), then call GetLastLoginDateRepository for retrieving the date, and call GetVersionChangesRepository with that date and finally give the result to your presenter.
That way, your business logic can stay 100% in your interactor and your presenter can focus on how he will display that on screen.
By the way, if your API needs a token for every call you should move it in an Interceptor so you do not have to deal with it at every call.
QUESTION
I am building an app based off of the Android Clean Architecture Kotlin version (https://github.com/android10/Android-CleanArchitecture-Kotlin).
Using this architecture, each time you want to invoke a use case, a Kotlin coroutine is launched and the result is posted in the main thread. This is achieved by this code:
...ANSWER
Answered 2018-Jun-13 at 00:59That's is not the way how firebase works. Firebase is based on callback.
I recommend architecture component's livedata.
Please check the following example.
here is a link: https://android.jlelse.eu/android-architecture-components-with-firebase-907b7699f6a0
QUESTION
I'm working in a mixed Java - Kotlin project. There's a class Either: https://github.com/android10/Android-CleanArchitecture-Kotlin/blob/master/app/src/main/kotlin/com/fernandocejas/sample/core/functional/Either.kt
In one of the Java classes I'm getting an instance of Either as a parameter in such a way:
...ANSWER
Answered 2018-Nov-06 at 20:41I... really wouldn't use this class for anything. It may just be for a specific purpose (given sample
in package name). But either
really needs a type parameter and left
and right
methods don't make sense.
If you somehow have no choice, you should be able to call either
like this:
QUESTION
I just start learn and apply CleanArchitecture
for my Android project.
I see there are 2 great source for following here
1) https://github.com/android10/Android-CleanArchitecture
2) https://github.com/fiveagency/Reedly (https://five.agency/android-architecture-part-4-applying-clean-architecture-on-android-hands-on/)
Currently, the first source use the CompositeDisposable
in domain (inside UseCase
) and the second source use in presentation/app(Presenter
/ViewModel
)
As my current understand, I see the benefit when we put CompositeDisposable
in Presenter/ViewModel
.
- Easy to dispose (because if we
CompositeDisposable
inUseCase
, for eachUseCase
we need to dispose call 1 time) - May easy to combine many
UseCase
(eg:UseCase1
execute then flatMap/zip... withUseCase2
)
I see the benefit when we put CompositeDisposable
in UseCase
- It separate
RX
from presentation
I don't know if is there any other pros/cons of 2 approach. I never use CleanArchitecture
for real project and I know when we follow any approach, it's quite hard to change to another approach.
For me, currently I think I will choose: put CompositeDisposable
in UseCase
.
What should I use? Is there any other approach?
Any help or advice would be great appreciated.
ANSWER
Answered 2018-Aug-07 at 04:34When it comes to clean architecture, I have been using 1) Android-CleanArchitecture for about a year now. And when it comes to disposing CompositeDisposable
, I would do it in Presenter
if I were you, because it is closely related to life-cycle of View and it controls data flow which CompositeDisposable
in this case kind of belongs to.
Suggestion:
Convert 1) Android-CleanArchitecture from MVP to MVVM in Presentation layer with ViewModels and dispose your CompositeDisposable
there. MVVM with Googles new ViewModel library eliminates headaches of managing life-cylce dependent objects yourself, which MVP in this CleanArchitecutre
template fails to deliver.
Hope this cleared things up a bit. Good Luck :)
QUESTION
So I was going through clean architecture in android, really liked it how people even create separate projects for domain, data and presentation layer. I tried to create my own project for clean architecture but couldn't set up different projects for domain, data and presentation layers.
How can I accomplish this kind of project architecture? https://github.com/android10/Android-CleanArchitecture
...ANSWER
Answered 2018-Mar-11 at 09:49Create one project as your main project of type Android Application Project. The separate layers can be added as library modules to your main project.
Then you just need to add these library modules to your gradle file as dependencies. Android studio will usually take care of that. But just in case you needed to change the order of dependencies, you can do that in the gradle files of each module.
QUESTION
So I was following Clean Architecture to design my application. I have an Activity
with a view pager which has two Fragment
in it. Im injecting the PagerAdapter
for this through Dagger.
I understand that calling setRetainInstance(true)
on a fragment prevents it from getting destroyed, and that getActivity()
on such fragment may return a problem if the Activity is destroyed. I'm getting a NullPointException when trying to resume my activity after it has been on background and the activity has been (presumably) destroyed.
So my question is
- Is there a better way to accomplish what I'm trying to do?
- Any resource someone can point me to?
- Also uncertain why the Fragment and the Adapter is still active if the fragment has been destroyed. I get no memory leaks with LeakCanary.
My activity has an Dagger Component MainActivityComponent which is injected as follows. And also extends HasComponent. For more info on this refer to HasComponent
...MainActivity.java
ANSWER
Answered 2018-Jan-26 at 10:45The problem occured when the application stays in the background for a while and a recently displayed activity is recycled by Android. Bringing back the application causes NullPointerException (NPE) as the activity’s component is called by the fragment before it is initialized (both fragment and activity are recreated at the same time).
SolutionIntroducing two lifecycle methods in BaseFragment class.
- onInjectView() — called to do an optional injection on onCreate(Bundle) and if an exception is thrown or false returned, it is called on onActivityCreated(Bundle) again. Within this method you can get the injection component and inject the view. Retrun true if the injection was succesfull, then it will not be called again.
- Based on returned value, the second method is called. The method is named onViewInjected(Bundle), as it is called only when the fragment has been injected and injected fields can be initialized.
QUESTION
I have a Android Clean Architecture project write in Kotlin with 3 modules:
- data (Android Library)
- domaine (Java Library)
- presentation (Android Application)
The 3 modules each have unit tests written with junit. But with Kotlin every class is final by default. I quickly had the problem: How to mock a final class with mockito
It's now possible with Mockito 2
It can be done via the mockito extension mechanism by creating the file /mockito-extensions/org.mockito.plugins.MockMaker
containing a single line:
ANSWER
Answered 2017-Jul-10 at 10:26You can use the inline mocking method by default, by changing your Gradle dependency from the normal Mockito dependency:
QUESTION
What´s the best approach when developing an Android app and trying to follow clean architecture guidelines (but not extremely strict - cause that may be overkill for smaller projects).
In my case, I am unsure which approach is the best (if there is a best one) regarding the data layer and if the data layer should operate on its own model classes or if it may operate directly on the domain layer models.
Also, if the data layer should operate on its own model classes, should data sources like DB
or API
have their own models (like for an API
using Retrofit
and Gson
a model class with Gson
annotations) and then map to data layer models OR should the data layer model itself be the model returned by DB
and API
(this means the data layer model must be annotated for Gson
being able to parse it in case of Retrofit
and Gson
).
This is the case in this project: https://github.com/android10/Android-CleanArchitecture/blob/master/data/src/main/java/com/fernandocejas/android10/sample/data/entity/UserEntity.java
The following images should clarify the 3 approaches I mean:
In Image 1 the DB
and API
return specific model classes. In the case of the API
it may look like (using Retrofit
and Gson
):
ANSWER
Answered 2017-Dec-20 at 11:05If I were you, I would go with the Image1 process. I think it is the job of your datasource to take whatever object is coming from your database or API or any endpoint you have and transform it into something easier to user in your repository.
Between Image1 and Image2, I think it depend of what data you want to store and what is the object you want to store. You may or may not need an ArticleEntity depending of your business rules. And if you don't need it, you don't have to create one.
But for some use case you may need to create that object to add some informations to your Article. For exemple, if you want to place in that a validity date or any other information that you will only use in your repository, you can go for Image2.
QUESTION
I have a project using this structure: https://github.com/android10/Android-CleanArchitecture, and I am trying to convert it to Kotlin.
The domain module compiles just fine, but when I try compile the data module I get the following error:
...ANSWER
Answered 2017-Oct-04 at 13:10I finally found why it was not compiling: I had to call "rebuild project" rather than "make project" in order for Android Studio to take all the changes into account.
QUESTION
I have a ViewPager
with two pages namely Popular and All. What I'm trying to achieve is only push items that have popular tag true to Popular whereas push all items to All.
Currently I have a single class which is used in the PagerAdapter
and passing in the page type. How do I filter out PublishSubject
so that each page only displays necessary items accordingly.
Both my Observer are subscribed to a single
PublishSubject
, but I want to filter when emitting.
Please comment if the question is unclear. I'll try my best to relay this problem. Also sorry if it has already been answered since I couldn't find anything relevant.
The code I'm using is this based on this architecture in which I have a Firebase data store FirebaseSubscriptionDataStore which provides the PublishSubject
. This is later subscribed to by SubscribeToSubscriptionUpdates in SubscriptionListPresenterImpl
Thanks in advance.
...ANSWER
Answered 2017-Sep-24 at 10:11You can basically define two different methods to get Observable
(or Flowable) from PublishSubject
. First observable will emit all of the items and second one only popular ones:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Android-CleanArchitecture
You can use Android-CleanArchitecture like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the Android-CleanArchitecture component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page