-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
javier.santayana
committed
Oct 2, 2015
1 parent
ccdb753
commit 618d2cb
Showing
24 changed files
with
418 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.trips.mochilo; | ||
|
||
import android.app.Application; | ||
import android.content.Context; | ||
|
||
import com.trips.mochilo.ui.dagger.components.AppComponent; | ||
import com.trips.mochilo.ui.dagger.components.DaggerAppComponent; | ||
import com.trips.mochilo.ui.dagger.modules.AppModule; | ||
|
||
import net.danlew.android.joda.JodaTimeAndroid; | ||
|
||
import timber.log.Timber; | ||
|
||
public class Mochilo extends Application { | ||
|
||
private AppComponent mAppcomponent; | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
setupGraph(); | ||
JodaTimeAndroid.init(this); | ||
planTimber(); | ||
} | ||
|
||
private void planTimber() { | ||
if (BuildConfig.DEBUG) { | ||
Timber.plant(new Timber.DebugTree()); | ||
} | ||
} | ||
|
||
private void setupGraph() { | ||
if (mAppcomponent == null) { | ||
mAppcomponent = DaggerAppComponent.builder() | ||
.appModule(new AppModule(this)) | ||
.build(); | ||
mAppcomponent.inject(this); | ||
} | ||
} | ||
|
||
public AppComponent component() { | ||
return mAppcomponent; | ||
} | ||
|
||
public static Mochilo get(Context context) { | ||
return ((Mochilo) context.getApplicationContext()); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
app/src/main/java/com/trips/mochilo/ui/activity/BaseActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.trips.mochilo.ui.activity; | ||
|
||
import android.os.Bundle; | ||
import android.os.PersistableBundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
|
||
import com.trips.mochilo.Mochilo; | ||
|
||
import butterknife.ButterKnife; | ||
|
||
public abstract class BaseActivity extends AppCompatActivity { | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) { | ||
super.onCreate(savedInstanceState, persistentState); | ||
Mochilo.get(this).component().inject(this); | ||
} | ||
|
||
protected abstract void injectScopeComponent(); | ||
|
||
protected void setButterContentView(int layout) { | ||
setContentView(layout); | ||
ButterKnife.inject(this); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
app/src/main/java/com/trips/mochilo/ui/activity/main/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.trips.mochilo.ui.activity.main; | ||
|
||
import android.os.Bundle; | ||
|
||
import com.trips.mochilo.Mochilo; | ||
import com.trips.mochilo.R; | ||
import com.trips.mochilo.ui.activity.BaseActivity; | ||
import com.trips.mochilo.ui.fragments.DatePickerFragment; | ||
|
||
import butterknife.OnClick; | ||
|
||
public class MainActivity extends BaseActivity implements MainView { | ||
|
||
private MainComponent mMainComponent; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setButterContentView(R.layout.activity_main); | ||
} | ||
|
||
@OnClick(R.id.bt) | ||
public void onClick() { | ||
DatePickerFragment.newInstance().show(getSupportFragmentManager(), DatePickerFragment.class.getSimpleName()); | ||
} | ||
|
||
@Override | ||
protected void injectScopeComponent() { | ||
mMainComponent = DaggerMainComponent.builder() | ||
.appComponent(Mochilo.get(this).component()) | ||
.mainModule(new MainModule(this)) | ||
.build(); | ||
mMainComponent.inject(this); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/trips/mochilo/ui/activity/main/MainComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.trips.mochilo.ui.activity.main; | ||
|
||
import com.trips.mochilo.ui.dagger.ActivityScope; | ||
import com.trips.mochilo.ui.dagger.components.AppComponent; | ||
|
||
import dagger.Component; | ||
|
||
@ActivityScope | ||
@Component( | ||
dependencies = AppComponent.class, | ||
modules = MainModule.class | ||
) | ||
public interface MainComponent { | ||
void inject(MainActivity activity); | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
app/src/main/java/com/trips/mochilo/ui/activity/main/MainModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.trips.mochilo.ui.activity.main; | ||
|
||
import com.trips.mochilo.ui.dagger.ActivityScope; | ||
|
||
import dagger.Module; | ||
import dagger.Provides; | ||
|
||
@Module | ||
public class MainModule { | ||
private MainView mView; | ||
|
||
public MainModule(MainView view) { | ||
this.mView = view; | ||
} | ||
|
||
@Provides | ||
@ActivityScope | ||
public MainView provideActivityView() { | ||
return mView; | ||
} | ||
|
||
@Provides | ||
@ActivityScope | ||
public MainPresenter provideActivityPresenter(MainView view) { | ||
return new MainPresenterImpl(view); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
app/src/main/java/com/trips/mochilo/ui/activity/main/MainPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.trips.mochilo.ui.activity.main; | ||
|
||
public interface MainPresenter { | ||
} |
4 changes: 4 additions & 0 deletions
4
app/src/main/java/com/trips/mochilo/ui/activity/main/MainView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.trips.mochilo.ui.activity.main; | ||
|
||
public interface MainView { | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/trips/mochilo/ui/dagger/ActivityScope.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.trips.mochilo.ui.dagger; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
import javax.inject.Scope; | ||
|
||
@Scope | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface ActivityScope { | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/trips/mochilo/ui/dagger/ApplicationContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.trips.mochilo.ui.dagger; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
import javax.inject.Qualifier; | ||
|
||
@Qualifier | ||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface ApplicationContext { | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/trips/mochilo/ui/dagger/components/ActivityComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.trips.mochilo.ui.dagger.components; | ||
|
||
import com.trips.mochilo.ui.dagger.ActivityScope; | ||
import com.trips.mochilo.ui.dagger.modules.ActivityModule; | ||
|
||
import dagger.Component; | ||
|
||
@ActivityScope | ||
@Component( | ||
dependencies = AppComponent.class, | ||
modules = ActivityModule.class | ||
) | ||
public interface ActivityComponent { | ||
//Exposed to sub-graphs. | ||
} |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/trips/mochilo/ui/dagger/components/AppComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.trips.mochilo.ui.dagger.components; | ||
|
||
import com.trips.mochilo.Mochilo; | ||
import com.trips.mochilo.ui.activity.BaseActivity; | ||
import com.trips.mochilo.ui.dagger.modules.AppModule; | ||
import com.trips.mochilo.ui.dagger.modules.InteractorsModule; | ||
|
||
import javax.inject.Singleton; | ||
|
||
import dagger.Component; | ||
|
||
@Singleton | ||
@Component( | ||
modules = { | ||
AppModule.class, | ||
InteractorsModule.class, | ||
} | ||
) | ||
public interface AppComponent { | ||
void inject(Mochilo app); | ||
|
||
void inject(BaseActivity activity); | ||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/trips/mochilo/ui/dagger/modules/ActivityModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.trips.mochilo.ui.dagger.modules; | ||
|
||
import android.app.Activity; | ||
|
||
import com.trips.mochilo.ui.dagger.ActivityScope; | ||
|
||
import dagger.Module; | ||
import dagger.Provides; | ||
|
||
@Module | ||
public class ActivityModule { | ||
|
||
private final Activity activity; | ||
|
||
public ActivityModule(Activity activity) { | ||
this.activity = activity; | ||
} | ||
|
||
@Provides | ||
@ActivityScope | ||
Activity activity() { | ||
return activity; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/trips/mochilo/ui/dagger/modules/AppModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.trips.mochilo.ui.dagger.modules; | ||
|
||
import android.content.Context; | ||
|
||
import com.trips.mochilo.Mochilo; | ||
import com.trips.mochilo.ui.dagger.ApplicationContext; | ||
|
||
import javax.inject.Singleton; | ||
|
||
import dagger.Module; | ||
import dagger.Provides; | ||
|
||
@Module | ||
public class AppModule { | ||
|
||
private Mochilo mApp; | ||
|
||
public AppModule(Mochilo app) { | ||
mApp = app; | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
@ApplicationContext | ||
public Context provideApplicationContext() { | ||
return mApp.getApplicationContext(); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/trips/mochilo/ui/dagger/modules/InteractorsModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.trips.mochilo.ui.dagger.modules; | ||
|
||
import dagger.Module; | ||
|
||
@Module | ||
public class InteractorsModule { | ||
|
||
|
||
} |
30 changes: 30 additions & 0 deletions
30
app/src/main/java/com/trips/mochilo/ui/fragments/DatePickerFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.trips.mochilo.ui.fragments; | ||
|
||
import android.app.DatePickerDialog; | ||
import android.app.Dialog; | ||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.v4.app.DialogFragment; | ||
import android.widget.DatePicker; | ||
|
||
import org.joda.time.DateTime; | ||
|
||
public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener { | ||
|
||
public static DialogFragment newInstance() { | ||
return new DatePickerFragment(); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Dialog onCreateDialog(Bundle savedInstanceState) { | ||
// Use the current date as the default date in the picker | ||
DateTime dateTime = DateTime.now(); | ||
// Create a new instance of DatePickerDialog and return it | ||
return new DatePickerDialog(getActivity(), this, dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth()); | ||
} | ||
|
||
public void onDateSet(DatePicker view, int year, int month, int day) { | ||
// Do something with the date chosen by the user | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
app/src/main/java/com/trips/mochilo/utils/FragmentPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.trips.mochilo.utils; | ||
|
||
public interface FragmentPresenter<T> { | ||
void init(T view); | ||
} |
Oops, something went wrong.