Skip to content

Commit

Permalink
Setup basic architecture and libs
Browse files Browse the repository at this point in the history
  • Loading branch information
javier.santayana committed Oct 2, 2015
1 parent ccdb753 commit 618d2cb
Show file tree
Hide file tree
Showing 24 changed files with 418 additions and 30 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ dependencies {
compile 'com.jakewharton.timber:timber:2.7.1'
compile 'com.jakewharton:butterknife:6.1.0'
compile 'io.reactivex:rxandroid:1.0.1'
compile 'net.danlew:android.joda:2.8.2'
}

File propFile = file('signing.properties');
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.trips.mochilo" >
package="com.trips.mochilo">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".Mochilo"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
android:theme="@style/AppTheme">
<activity android:name=".ui.activity.main.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
13 changes: 0 additions & 13 deletions app/src/main/java/com/trips/mochilo/MainActivity.java

This file was deleted.

48 changes: 48 additions & 0 deletions app/src/main/java/com/trips/mochilo/Mochilo.java
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 app/src/main/java/com/trips/mochilo/ui/activity/BaseActivity.java
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);
}
}
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);
}
}
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);

}
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.trips.mochilo.ui.activity.main;

public interface MainPresenter {
}
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 app/src/main/java/com/trips/mochilo/ui/dagger/ActivityScope.java
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 {
}
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 {
}
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.
}
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);
}
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;
}
}
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();
}

}
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 {


}
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
}
}
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);
}
Loading

0 comments on commit 618d2cb

Please sign in to comment.