'Android Clean Architecture UseCase

I am developing a simple application.

  1. The user navigates through the elements of the RecyclerView to the end screen.
  2. When scrolling LastFragment to the very bottom of the fragment, the SharedPref saves the status to true. Then the next element becomes available.
  3. LastFragment has a button that plays a sound when clicked I'm trying to build an application according to the principles of clean architecture and

I don't understand where UseCase is. Could you explain to me which UseCase should be used here?

enter image description here



Solution 1:[1]

You need to have something like:

PersistEndWasReachedUseCase

Or whatever name you like that will call the: "SaveToSharePrefs" Logic.

They should be part of your Domain Layer:

https://developer.android.com/topic/architecture/domain-layer

But at the same time, you need to be clean. This means that your logic should not know where it saves states. It might be a DB, SharePrefs, a remote server, etc.

That is why you should you a repository pattern:

https://developer.android.com/codelabs/basic-android-kotlin-training-repository-pattern#0

https://www.raywenderlich.com/24509368-repository-pattern-with-jetpack-compose

So you need to also have a Data Layer:

https://developer.android.com/topic/architecture/data-layer

But long story short - what clean means - You put your business logic in the inner layers. They depend on interfaces declared in these layers. And then outside layers implement these interfaces.

Basically this is an Inversion of control. Check SOLID.

https://miro.medium.com/max/1400/1*B4LEEv0PbmqvYolUH-mCzw.png

As per the image - you push the implementation details: Room, SharedPrefs, etc in the outer layers. And the inner layers are pure Kotlin/Java code. It knows nothing about implementation details - they are hidden by interfaces.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yavor Mitev