-
Notifications
You must be signed in to change notification settings - Fork 3
Home
This is documentation for Visum framework. See the contents to the right.
#What's going on Visum helps you build clean, testable and beautiful app.
##How Visum helps you? Visum enforces you to build your application with MVP architecture. Visum helps you to organize inversion of control in very convenient and useful way. For example you don't want lose your recyclerView items data on orientation change. Sounds interesting? Get familiar with Visum!
#Getting familiar. Let's build simple app step by step getting familiar with Visum structure.
First of all please refer to MVP definition to be sure we talking about the same thing.
Now let's build our MVPed app. Cross the Android Visum corresponds as View following Android components: Activity, Fragment and Android.View (We refer to Android. View mentioning package name to distinguish it from View from MVP).
Remember all logic that refers to UI, display stuff goes to your View. All logic refers to Android specific problems which demand context stays in View (such as handling intents, broadcasts and so on). Presenter retrieves data from repositories (the model), and pass it in the view, gets user events from view and updates model. Presenter shouldn't know anything about Android or Android packaged classes. This will make your testing much easier. Model of course all about data handling.
Visum have abstract implementations for your Views and Presenters
##VisumPresenter
is a class that handles attachment and detachment of a View.
It's also empowered with rx steroids, which makes it handle your subscriptions making you not to worry about Android Views lifecycle. All your rx subscriptions are to be unsubscribed on view detached.Use subscribe()
method to gain this benefits.
##VisumClient Is another side of Visum. You can call it dark if you want. VisumClient helps you organize inversion of control. Inversion of control is a powerful concept in programming find out more. Lately in Android community Dagger2 has become a standard of dependency injection, hence Visum as a modern library uses Dagger2 to help you with your very own DI.
Concept of VisumClient
is simple, but very helpful.
The idea is that every View has a Presenter and a Component what is component? find out here.
The Presenter is injected into View, it's provided by a Component. And the same presenter will always attach to the same View. (Talking about the same view we mean more that same instance of a view. It's same view as a logical concept. To easily distinguish same view from another view is just think about it as the same screen or just the same stuff). This provides you with following benefits:
Being recreated on orientation changed view itself loses all it data, except you save it manually with saveInstantState
. But presenter survives orientation change, which gives you a lot of afford not needing to reload big amounts of data.
To implement this behavior Visum requires you to:
- Implement ComponentCache.
- Provide same instance of ComponentCache to all classes implementations of
VisumClient
. There's an interface ComponentCacheProvider for the class which holds instance of ComponentCache. Usually it's your Application class. - Implement
VisumClient
by a client class.
So if you using one of default VisumClient implementation (listed above) you just need to implement inject(Object)
method. And implementation is always trivial:
@Override
public void inject(Object from) {
((MyComponent) from).inject(this);
}
##VisumView
Usually talking about View in context of Visum we talk about VisumView.
VisumView is a View which attaches and detaches VisumPresenter
.
But to make things not that simple and obvious Visum has some 'in house' implementation of VisumView
.
You can find it on page VisumViews.
If you navigated to one of the described above view. You could notice that VisumViews implementation are not that trivial as you could expect. This is because those have one more interface, that we hadn't talked yet. And that's what Visum proudly presents you VisumClient.
##ComponentCache
Is a cache which holds all your alive components. You manually add and remove Components which leads to manual component scope control. If you are using Visum implementations of ViewClient you can not bother about it. VisumActivity
, VisumFragment
, VisumWidget
, VisumAndroidService
etc. handles creating and removing components for you.