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

Commit

Permalink
Revert "Revert "Merge pull request #73 from luis-ibanez/move_librarie…
Browse files Browse the repository at this point in the history
…s" (#87)"

This reverts commit 575f56d.
  • Loading branch information
Sergio Gutierrez committed Mar 6, 2017
1 parent 318fb2a commit 1e0e0da
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 92 deletions.
19 changes: 0 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,6 @@ 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 @@ -172,10 +161,6 @@ 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 @@ -438,9 +423,7 @@ 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 @@ -471,6 +454,4 @@ 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: 1 addition & 2 deletions rosie/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ 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: 0 additions & 41 deletions rosie/src/main/java/com/karumi/rosie/renderer/RosieRenderer.java

This file was deleted.

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

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 @@ -37,8 +36,8 @@ public abstract class RosieActivity extends FragmentActivity
private PresenterLifeCycleLinker presenterLifeCycleLinker = new PresenterLifeCycleLinker();

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

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 @@ -37,8 +36,8 @@ public abstract class RosieAppCompatActivity extends AppCompatActivity
private PresenterLifeCycleLinker presenterLifeCycleLinker = new PresenterLifeCycleLinker();

/**
* Initializes the object graph associated to the activity scope, links presenters to the
* Activity life cycle and initializes view injection using butter knife.
* Initializes the object graph associated to the activity scope, and links presenters to the
* Activity life cycle.
*/
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -47,11 +46,19 @@ public abstract class RosieAppCompatActivity extends AppCompatActivity
}
int layoutId = getLayoutId();
setContentView(layoutId);
ButterKnife.bind(this);
onPrepareActivity();
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: 13 additions & 5 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,21 +58,29 @@ public abstract class RosieFragment extends Fragment implements RosiePresenter.V
@Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
injectDependencies();
int layoutId = getLayoutId();
View view = inflater.inflate(layoutId, container, false);
ButterKnife.bind(this, view);
View view = inflater.inflate(getLayoutId(), container, false);
onPrepareFragment(view);
return view;
}

/**
* Injects the Fragment views using Butter Knife library and initializes the presenter lifecycle.
* 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,7 +24,6 @@
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,21 +57,28 @@ public abstract class RosieSupportFragment extends Fragment implements RosiePres
@Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
injectDependencies();
int layoutId = getLayoutId();
View view = inflater.inflate(layoutId, container, false);
ButterKnife.bind(this, view);
View view = inflater.inflate(getLayoutId(), container, false);
onPrepareFragment(view);
return view;
}

/**
* Injects the Fragment views using Butter Knife library and initializes the presenter lifecycle.
* 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: 2 additions & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ 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,6 +19,8 @@
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 @@ -30,6 +32,12 @@ 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,10 +17,21 @@
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.karumi.rosie.sample.base.view.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 MarvelRenderer<T> extends Renderer<T> {

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

@Override protected void setUpView(View view) {

}

@Override protected void hookListeners(View view) {

}
}
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 RosieRenderer<CharacterViewModel> {
public class CharacterRenderer extends MarvelRenderer<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 RosieRenderer<CharacterViewModel> {
public class LoadMoreCharactersRenderer extends MarvelRenderer<CharacterViewModel> {

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

0 comments on commit 1e0e0da

Please sign in to comment.