Skip to content
This repository has been archived by the owner on Jan 9, 2020. It is now read-only.

Fix #86 #87

Merged
merged 1 commit into from
Mar 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ public abstract class MyBaseActivity extends FragmentActivity

Rosie provides you some base classes to be extended and give you a quick access to the Dependency Injection and Model View Presenter features, but the usage of inheritance to use these features is not mandatory.

####Butter Knife

By extending Rosie view classes, you will have access in your activities and fragments to [ButterKnife] [butterknife] annotations to easily inject your views:

```java
public class SampleActivity extends RosieActivity {
@Bind(R.id.sample_view) TextView sampleView;
/*...*/
}
```

####Dagger

Besides, you can define the [Dagger] [dagger] module that will contain the dependencies for your activity by overriding the ``getActivityScopeModules`` method:
Expand Down Expand Up @@ -161,6 +172,10 @@ To understand when the lifecycle methods are called take a look at the following
| ``pause`` | ``onPause`` | ``onPause`` |
| ``destroy`` | ``onDestroy`` | ``onDestroy`` |

####Renderers

Finally, Rosie includes the [Renderers] [renderers] library to simplify your ``RecyclerView`` handling code. If you decide to use Renderers, remember to extend directly from ``RosieRenderer<T>`` to have ButterKnife injections for free in your renderer views.

###Domain

The domain package is meant to contain all your business logic that will change from app to app. For that reason, Rosie only provides a single ``RosieUseCase`` class that will help you execute your use cases in background following the command pattern.
Expand Down Expand Up @@ -423,7 +438,9 @@ Libraries used in this project
* [JUnit] [junit]
* [Mockito] [mockito]
* [Robolectric] [robolectric]
* [ButterKnife] [butterknife]
* [Dagger] [dagger]
* [Renderers] [renderers]
* [Android Priority Job Queue] [jobqueue]

License
Expand Down Expand Up @@ -454,4 +471,6 @@ License
[mockito]: https://github.com/mockito/mockito
[robolectric]: https://github.com/robolectric/robolectric
[dagger]: https://github.com/square/dagger
[butterknife]: https://github.com/JakeWharton/butterknife
[renderers]: https://github.com/pedrovgs/renderers
[jobqueue]: https://github.com/yigit/android-priority-jobqueue
3 changes: 2 additions & 1 deletion rosie/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ android {

dependencies {
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'

provided 'com.squareup.dagger:dagger-compiler:1.2.2'

compile 'com.squareup.dagger:dagger:1.2.2'
compile 'com.birbit:android-priority-jobqueue:1.3.5'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.github.pedrovgs:renderers:3.0.0'

testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-all:1.10.19'
Expand Down
41 changes: 41 additions & 0 deletions rosie/src/main/java/com/karumi/rosie/renderer/RosieRenderer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2015 Karumi.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.karumi.rosie.renderer;

import android.view.View;
import butterknife.ButterKnife;
import com.pedrogomez.renderers.Renderer;

/**
* Renderer extension create to provide Butter Knife view injection in a transparent way. Your
* Renderer classes should extend from this one to be able tu use Butter Knife annotations.
* Remember to call super in you overridden render method.
*/
public abstract class RosieRenderer<T> extends Renderer<T> {

@Override public void render() {
ButterKnife.bind(this, getRootView());
}

@Override protected void setUpView(View view) {

}

@Override protected void hookListeners(View view) {

}
}
15 changes: 4 additions & 11 deletions rosie/src/main/java/com/karumi/rosie/view/RosieActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import butterknife.ButterKnife;
import com.karumi.rosie.application.RosieApplication;
import com.karumi.rosie.module.RosieActivityModule;
import dagger.ObjectGraph;
Expand All @@ -36,8 +37,8 @@ public abstract class RosieActivity extends FragmentActivity
private PresenterLifeCycleLinker presenterLifeCycleLinker = new PresenterLifeCycleLinker();

/**
* Initializes the object graph associated to the activity scope and links presenters to the
* Activity life cycle.
* Initializes the object graph associated to the activity scope, links presenters to the
* Activity life cycle and initializes view injection using butter knife.
*/
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -46,19 +47,11 @@ public abstract class RosieActivity extends FragmentActivity
}
int layoutId = getLayoutId();
setContentView(layoutId);
onPrepareActivity();
ButterKnife.bind(this);
onPreparePresenter();
presenterLifeCycleLinker.initializeLifeCycle(this, this);
}

/**
* Called just after setContentView .
* Override this method to configure your activity and set up views if needed.
*/
protected void onPrepareActivity() {

}

/**
* Called before to initialize all the presenter instances linked to the component lifecycle.
* Override this method to configure your presenter with extra data if needed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import butterknife.ButterKnife;
import com.karumi.rosie.application.RosieApplication;
import com.karumi.rosie.module.RosieActivityModule;
import dagger.ObjectGraph;
Expand All @@ -36,8 +37,8 @@ public abstract class RosieAppCompatActivity extends AppCompatActivity
private PresenterLifeCycleLinker presenterLifeCycleLinker = new PresenterLifeCycleLinker();

/**
* Initializes the object graph associated to the activity scope, and links presenters to the
* Activity life cycle.
* Initializes the object graph associated to the activity scope, links presenters to the
* Activity life cycle and initializes view injection using butter knife.
*/
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -46,19 +47,11 @@ public abstract class RosieAppCompatActivity extends AppCompatActivity
}
int layoutId = getLayoutId();
setContentView(layoutId);
onPrepareActivity();
ButterKnife.bind(this);
onPreparePresenter();
presenterLifeCycleLinker.initializeLifeCycle(this, this);
}

/**
* Called just after setContentView .
* Override this method to configure your activity and set up views if needed.
*/
protected void onPrepareActivity() {

}

/**
* Called before to initialize all the presenter instances linked to the component lifecycle.
* Override this method to configure your presenter with extra data if needed.
Expand Down
18 changes: 5 additions & 13 deletions rosie/src/main/java/com/karumi/rosie/view/RosieFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.ButterKnife;

/**
* Base Fragment created to implement some common functionality to every Fragment using this
Expand Down Expand Up @@ -58,29 +58,21 @@ public abstract class RosieFragment extends Fragment implements RosiePresenter.V
@Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
injectDependencies();
View view = inflater.inflate(getLayoutId(), container, false);
onPrepareFragment(view);
int layoutId = getLayoutId();
View view = inflater.inflate(layoutId, container, false);
ButterKnife.bind(this, view);
return view;
}

/**
* Initializes the presenter lifecycle.
* Injects the Fragment views using Butter Knife library and initializes the presenter lifecycle.
*/
@Override public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
onPreparePresenter();
presenterLifeCycleLinker.initializeLifeCycle(this, this);
}

/**
* Called before returning the view in onCreateView.
* Override this method to configure your fragment or bind views.
*/
protected void onPrepareFragment(View view) {

}


/**
* Called before to initialize all the presenter instances linked to the component lifecycle.
* Override this method to configure your presenter with extra data if needed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import butterknife.ButterKnife;

/**
* Base Fragment created to implement some common functionality to every Fragment using this
Expand Down Expand Up @@ -57,28 +58,21 @@ public abstract class RosieSupportFragment extends Fragment implements RosiePres
@Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
injectDependencies();
View view = inflater.inflate(getLayoutId(), container, false);
onPrepareFragment(view);
int layoutId = getLayoutId();
View view = inflater.inflate(layoutId, container, false);
ButterKnife.bind(this, view);
return view;
}

/**
* Initializes the presenter lifecycle.
* Injects the Fragment views using Butter Knife library and initializes the presenter lifecycle.
*/
@Override public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
onPreparePresenter();
presenterLifeCycleLinker.initializeLifeCycle(this, this);
}

/**
* Called before returning the view in onCreateView.
* Override this method to configure your fragment or bind views.
*/
protected void onPrepareFragment(View view) {

}

/**
* Called before to initialize all the presenter instances linked to the component lifecycle.
* Override this method to configure your presenter with extra data if needed.
Expand Down
2 changes: 0 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ dependencies {
compile 'com.karumi:dividers:1.0.3'
compile 'com.victor:lib:1.0.1' // https://github.com/yankai-victor/Loading
compile 'com.karumi:marvelapiclient:0.0.4'
compile 'com.github.pedrovgs:renderers:3.0.0'
compile 'com.jakewharton:butterknife:7.0.1'
provided 'com.squareup.dagger:dagger-compiler:1.2.2'
compile project(':rosie')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.view.View;

import butterknife.ButterKnife;
import butterknife.OnClick;
import com.karumi.rosie.sample.R;
import com.karumi.rosie.view.RosieActivity;
Expand All @@ -32,12 +30,6 @@ public abstract class MarvelActivity extends RosieActivity {
finish();
}

@Override
protected void onPrepareActivity() {
super.onPrepareActivity();
ButterKnife.bind(this);
}

public void showGenericError() {
View rootView = getWindow().getDecorView().findViewById(android.R.id.content);
Snackbar.make(rootView, getString(R.string.generic_error), Snackbar.LENGTH_SHORT).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,10 @@
package com.karumi.rosie.sample.base.view.fragment;

import android.support.design.widget.Snackbar;
import android.view.View;

import com.karumi.rosie.sample.R;
import com.karumi.rosie.view.RosieFragment;

import butterknife.ButterKnife;

public abstract class MarvelFragment extends RosieFragment {

@Override
protected void onPrepareFragment(View view) {
super.onPrepareFragment(view);
ButterKnife.bind(this, view);
}

public void showGenericError() {
Snackbar.make(getView(), getString(R.string.generic_error), Snackbar.LENGTH_SHORT).show();
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
import android.widget.TextView;
import butterknife.Bind;
import butterknife.OnClick;
import com.karumi.rosie.renderer.RosieRenderer;
import com.karumi.rosie.sample.R;
import com.karumi.rosie.sample.base.view.renderer.MarvelRenderer;
import com.karumi.rosie.sample.characters.view.presenter.CharactersPresenter;
import com.karumi.rosie.sample.characters.view.viewmodel.CharacterViewModel;
import com.squareup.picasso.Picasso;

public class CharacterRenderer extends MarvelRenderer<CharacterViewModel> {
public class CharacterRenderer extends RosieRenderer<CharacterViewModel> {

private final CharactersPresenter presenter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.karumi.rosie.renderer.RosieRenderer;
import com.karumi.rosie.sample.R;
import com.karumi.rosie.sample.base.view.renderer.MarvelRenderer;
import com.karumi.rosie.sample.characters.view.viewmodel.CharacterViewModel;

public class LoadMoreCharactersRenderer extends MarvelRenderer<CharacterViewModel> {
public class LoadMoreCharactersRenderer extends RosieRenderer<CharacterViewModel> {

@Override protected View inflate(LayoutInflater inflater, ViewGroup parent) {
return inflater.inflate(R.layout.item_load_more, parent, false);
Expand Down