diff --git a/app/build.gradle b/app/build.gradle
index a79151a..59bdcba 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -15,6 +15,8 @@
*/
apply plugin: 'com.android.application'
+apply plugin: 'kotlin-android'
+apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 26
@@ -31,6 +33,11 @@ android {
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
}
+ sourceSets {
+ // May no longer be needed in future versions of Android Studio or the Kotlin Gradle plugin?
+ main.java.srcDirs += 'src/main/kotlin'
+ }
+
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
@@ -43,14 +50,16 @@ dependencies {
def daggerVersion = '2.14'
def butterKnifeVersion = '8.8.0'
def supportVersion = '26.0.1'
+ def kotlinVersion = '1.2.0'
- annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
- annotationProcessor "com.google.dagger:dagger-android-processor:$daggerVersion"
- annotationProcessor "com.jakewharton:butterknife-compiler:$butterKnifeVersion"
+ kapt "com.google.dagger:dagger-compiler:$daggerVersion"
+ kapt "com.google.dagger:dagger-android-processor:$daggerVersion"
+ kapt "com.jakewharton:butterknife-compiler:$butterKnifeVersion"
compile "com.google.dagger:dagger:$daggerVersion"
compile "com.google.dagger:dagger-android:$daggerVersion"
compile "com.google.dagger:dagger-android-support:$daggerVersion"
compile "com.jakewharton:butterknife:$butterKnifeVersion"
compile "com.android.support:appcompat-v7:$supportVersion"
+ compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlinVersion"
}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/App.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/App.java
deleted file mode 100644
index b7973a3..0000000
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/App.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2018 Vandolf Estrellado
- *
- * 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.vestrel00.daggerbutterknifemvp;
-
-import android.app.Activity;
-import android.app.Application;
-
-import javax.inject.Inject;
-
-import dagger.android.AndroidInjector;
-import dagger.android.DispatchingAndroidInjector;
-import dagger.android.HasActivityInjector;
-
-/**
- * The Android {@link Application}.
- *
- * DEPENDENCY INJECTION
- * We could extend {@link dagger.android.support.DaggerApplication} so we can get the boilerplate
- * dagger code for free. However, we want to avoid inheritance (if possible and it is in this case)
- * so that we have to option to inherit from something else later on if needed
- */
-public class App extends Application implements HasActivityInjector {
-
- @Inject
- DispatchingAndroidInjector activityInjector;
-
- @Override
- public void onCreate() {
- super.onCreate();
- DaggerAppComponent.builder().create(this).inject(this);
- }
-
- @Override
- public AndroidInjector activityInjector() {
- return activityInjector;
- }
-
-}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/BaseActivity.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/BaseActivity.java
deleted file mode 100644
index 64d86d8..0000000
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/BaseActivity.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright 2018 Vandolf Estrellado
- *
- * 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.vestrel00.daggerbutterknifemvp.ui.common;
-
-import android.os.Bundle;
-import android.support.annotation.IdRes;
-import android.support.annotation.Nullable;
-import android.support.v4.app.DialogFragment;
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentManager;
-import android.support.v7.app.AppCompatActivity;
-
-import com.vestrel00.daggerbutterknifemvp.navigation.Navigator;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import dagger.android.AndroidInjection;
-import dagger.android.AndroidInjector;
-import dagger.android.DispatchingAndroidInjector;
-import dagger.android.support.HasSupportFragmentInjector;
-
-/**
- * Abstract Activity for all Activities to extend.
- *
- * DEPENDENCY INJECTION
- * We could extend {@link dagger.android.support.DaggerAppCompatActivity} so we can get the
- * boilerplate dagger code for free. However, we want to avoid inheritance (if possible and it is
- * in this case) so that we have to option to inherit from something else later on if needed.
- */
-public abstract class BaseActivity extends AppCompatActivity implements HasSupportFragmentInjector {
-
- @Inject
- protected Navigator navigator;
-
- /**
- * A reference to the FragmentManager is injected and used instead of the getter method. This
- * enables ease of mocking and verification in tests (in case Activity needs testing).
- *
- * For more details, see https://github.com/vestrel00/android-dagger-butterknife-mvp/pull/52
- */
- @Inject
- @Named(BaseActivityModule.ACTIVITY_FRAGMENT_MANAGER)
- FragmentManager fragmentManager;
-
- @Inject
- DispatchingAndroidInjector fragmentInjector;
-
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- AndroidInjection.inject(this);
- super.onCreate(savedInstanceState);
- }
-
- @Override
- public final AndroidInjector supportFragmentInjector() {
- return fragmentInjector;
- }
-
- protected final void addFragment(@IdRes int containerViewId, Fragment fragment) {
- fragmentManager.beginTransaction()
- .add(containerViewId, fragment)
- .commit();
- }
-
- protected final void showDialogFragment(DialogFragment dialogFragment, String tag) {
- dialogFragment.show(fragmentManager, tag);
- }
-}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/BaseActivityModule.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/BaseActivityModule.java
deleted file mode 100644
index 5b1de89..0000000
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/BaseActivityModule.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package com.vestrel00.daggerbutterknifemvp.ui.common;
-
-import android.app.Activity;
-import android.content.Context;
-import android.support.v4.app.FragmentManager;
-import android.support.v7.app.AppCompatActivity;
-
-import com.vestrel00.daggerbutterknifemvp.inject.PerActivity;
-
-import javax.inject.Named;
-
-import dagger.Binds;
-import dagger.Module;
-import dagger.Provides;
-
-/**
- * Provides base activity dependencies. This must be included in all activity modules, which must
- * provide a concrete implementation of {@link AppCompatActivity}.
- */
-@Module
-public abstract class BaseActivityModule {
-
- static final String ACTIVITY_FRAGMENT_MANAGER = "BaseActivityModule.activityFragmentManager";
-
- @Binds
- @PerActivity
- /*
- * PerActivity annotation isn't necessary since Activity instance is unique but is here for
- * convention. In general, providing Application, Activity, Fragment, BroadcastReceiver,
- * etc does not require scoped annotations since they are the components being injected and
- * their instance is unique.
- *
- * However, having a scope annotation makes the module easier to read. We wouldn't have to look
- * at what is being provided in order to understand its scope.
- */
- abstract Activity activity(AppCompatActivity appCompatActivity);
-
- @Binds
- @PerActivity
- abstract Context activityContext(Activity activity);
-
- @Provides
- @Named(ACTIVITY_FRAGMENT_MANAGER)
- @PerActivity
- static FragmentManager activityFragmentManager(AppCompatActivity activity) {
- return activity.getSupportFragmentManager();
- }
-}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/presenter/BasePresenter.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/presenter/BasePresenter.java
deleted file mode 100644
index 9a4a144..0000000
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/presenter/BasePresenter.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2018 Vandolf Estrellado
- *
- * 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.vestrel00.daggerbutterknifemvp.ui.common.presenter;
-
-import android.os.Bundle;
-import android.support.annotation.Nullable;
-
-import com.vestrel00.daggerbutterknifemvp.ui.common.view.MVPView;
-
-/**
- * Abstract {@link Presenter} for all presenters to extend.
- *
- * @param the type of the {@link MVPView}.
- */
-public abstract class BasePresenter implements Presenter {
-
- protected final T view;
-
- protected BasePresenter(T view) {
- this.view = view;
- }
-
- @Override
- public void onStart(@Nullable Bundle savedInstanceState) {
- }
-
- @Override
- public void onResume() {
- }
-
- @Override
- public void onPause() {
- }
-
- @Override
- public void onSaveInstanceState(Bundle outState) {
- }
-
- @Override
- public void onEnd() {
- }
-}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseFragment.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseFragment.java
deleted file mode 100644
index a70489b..0000000
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseFragment.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Copyright 2018 Vandolf Estrellado
- *
- * 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.vestrel00.daggerbutterknifemvp.ui.common.view;
-
-import android.app.Dialog;
-import android.content.Context;
-import android.os.Bundle;
-import android.support.annotation.IdRes;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentManager;
-import android.support.v7.app.AppCompatDialogFragment;
-
-import com.vestrel00.daggerbutterknifemvp.R;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import butterknife.ButterKnife;
-import butterknife.Unbinder;
-import dagger.android.AndroidInjector;
-import dagger.android.DispatchingAndroidInjector;
-import dagger.android.support.AndroidSupportInjection;
-import dagger.android.support.HasSupportFragmentInjector;
-
-/**
- * Abstract (Dialog)Fragment for all (Dialog)Fragments and child (Dialog)Fragments to extend.
- * This contains some boilerplate dependency injection code and activity {@link Context}.
- *
- * WHY EXTEND AppCompatDialogFragment?
- * {@link AppCompatDialogFragment}s are simple extensions of Fragments. DialogFragments can be shown
- * as a dialog floating above the current activity or be embedded into views like regular fragments.
- * Therefore, supporting both Fragments and DialogFragments for dependency injection can simply be
- * achieved by having the base fragment class (this) extend DialogFragment instead of Fragment.
- * We could have separate base classes for Fragments and DialogFragments but that would produce
- * duplicate code. See See https://github.com/vestrel00/android-dagger-butterknife-mvp/pull/64
- *
- * Note that as of Dagger 2.12, the abstract base framework type
- * {@link dagger.android.support.DaggerAppCompatDialogFragment} has been introduced for subclassing
- * if so desired.
- *
- * DEPENDENCY INJECTION
- * We could extend {@link dagger.android.support.DaggerAppCompatDialogFragment} so we can get the
- * boilerplate dagger code for free. However, we want to avoid inheritance (if possible and it is in
- * this case) so that we have to option to inherit from something else later on if needed.
- *
- * VIEW BINDING
- * This fragment handles view bind and unbinding.
- */
-public abstract class BaseFragment extends AppCompatDialogFragment
- implements HasSupportFragmentInjector {
-
- /**
- * A reference to the activity Context is injected and used instead of the getter method. This
- * enables ease of mocking and verification in tests (in case Activity needs testing).
- * More importantly, the getter method (getContext()) is not available for API level below 23.
- * We could use getActivity() though since that is available since API 11. However, exposing the
- * Activity reference is less safe than just exposing the Context since a lot more can be done
- * with the Activity reference.
- *
- * For more details, see https://github.com/vestrel00/android-dagger-butterknife-mvp/pull/52
- */
- @Inject
- protected Context activityContext;
-
- /**
- * A reference to the FragmentManager is injected and used instead of the getter method. This
- * enables ease of mocking and verification in tests (in case Fragment needs testing).
- *
- * For more details, see https://github.com/vestrel00/android-dagger-butterknife-mvp/pull/52
- */
- // Note that this should not be used within a child fragment.
- @Inject
- @Named(BaseFragmentModule.CHILD_FRAGMENT_MANAGER)
- protected FragmentManager childFragmentManager;
-
- @Inject
- DispatchingAndroidInjector childFragmentInjector;
-
- @Nullable
- private Unbinder viewUnbinder;
-
- @Override
- public void onAttach(Context context) {
- // This is called even for API levels below 23.
- AndroidSupportInjection.inject(this);
- super.onAttach(context);
- }
-
- @Override
- @NonNull
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- // Quick fix for the dialog width not taking up most of the screen width.
- setStyle(AppCompatDialogFragment.STYLE_NORMAL, R.style.Theme_AppCompat_Dialog_MinWidth);
- return super.onCreateDialog(savedInstanceState);
- }
-
- @SuppressWarnings("ConstantConditions")
- @Override
- public void onViewStateRestored(Bundle savedInstanceState) {
- super.onViewStateRestored(savedInstanceState);
- /*
- * Bind the views here instead of in onViewCreated so that view state changed listeners
- * are not invoked automatically without user interaction.
- *
- * If we bind before this method (e.g. onViewCreated), then any checked changed
- * listeners bound by ButterKnife will be invoked during fragment recreation (since
- * Android itself saves and restores the views' states. Take a look at this gist for a
- * concrete example: https://gist.github.com/vestrel00/982d585144423f728342787341fa001d
- *
- * The lifecycle order is as follows (same if added via xml or java or if retain
- * instance is true):
- *
- * onAttach
- * onCreateView
- * onViewCreated
- * onActivityCreated
- * onViewStateRestored
- * onResume
- *
- * Note that the onCreate (and other lifecycle events) are omitted on purpose. The
- * caveat to this approach is that views, listeners, and resources bound by
- * Butterknife will be null until onViewStatedRestored. Just be careful not to use any
- * objects bound using Butterknife before onViewStateRestored.
- *
- * Fragments that do not return a non-null View in onCreateView results in onViewCreated
- * and onViewStateRestored not being called. This means that Butterknife.bind will not get
- * called, which is completely fine because there is no View to bind. Furthermore, there is
- * no need to check if getView() returns null here because this lifecycle method only gets
- * called with a non-null View.
- */
- viewUnbinder = ButterKnife.bind(this, getView());
- }
-
- @Override
- public void onDestroyView() {
- // This lifecycle method still gets called even if onCreateView returns a null view.
- if (viewUnbinder != null) {
- viewUnbinder.unbind();
- }
- super.onDestroyView();
- }
-
- @Override
- public final AndroidInjector supportFragmentInjector() {
- return childFragmentInjector;
- }
-
- protected final void addChildFragment(@IdRes int containerViewId, Fragment fragment) {
- childFragmentManager.beginTransaction()
- .add(containerViewId, fragment)
- .commit();
- }
-}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseFragmentModule.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseFragmentModule.java
deleted file mode 100644
index 00b0c58..0000000
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseFragmentModule.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2018 Vandolf Estrellado
- *
- * 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.vestrel00.daggerbutterknifemvp.ui.common.view;
-
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentManager;
-
-import com.vestrel00.daggerbutterknifemvp.inject.PerFragment;
-
-import javax.inject.Named;
-
-import dagger.Module;
-import dagger.Provides;
-
-/**
- * Provides base fragment dependencies. This must be included in all fragment modules, which must
- * provide a concrete implementation of {@link Fragment} and named {@link #FRAGMENT}.
- */
-@Module
-public abstract class BaseFragmentModule {
-
- /**
- * See {@link BaseChildFragmentModule} class documentation regarding the need for this name.
- */
- public static final String FRAGMENT = "BaseFragmentModule.fragment";
-
- static final String CHILD_FRAGMENT_MANAGER = "BaseFragmentModule.childFragmentManager";
-
- @Provides
- @Named(CHILD_FRAGMENT_MANAGER)
- @PerFragment
- static FragmentManager childFragmentManager(@Named(FRAGMENT) Fragment fragment) {
- return fragment.getChildFragmentManager();
- }
-}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/presenter/Example1PresenterImpl.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/presenter/Example1PresenterImpl.java
deleted file mode 100644
index 1fc1dac..0000000
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/presenter/Example1PresenterImpl.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2018 Vandolf Estrellado
- *
- * 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.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.presenter;
-
-import com.vestrel00.daggerbutterknifemvp.inject.PerFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.common.presenter.BasePresenter;
-import com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.view.Example1View;
-import com.vestrel00.daggerbutterknifemvp.util.PerActivityUtil;
-import com.vestrel00.daggerbutterknifemvp.util.PerFragmentUtil;
-import com.vestrel00.daggerbutterknifemvp.util.SingletonUtil;
-
-import javax.inject.Inject;
-
-/**
- * An implementation of {@link Example1Presenter}.
- */
-@PerFragment
-final class Example1PresenterImpl extends BasePresenter implements Example1Presenter {
-
- private final SingletonUtil singletonUtil;
- private final PerActivityUtil perActivityUtil;
- private final PerFragmentUtil perFragmentUtil;
-
- @Inject
- Example1PresenterImpl(Example1View view, SingletonUtil singletonUtil,
- PerActivityUtil perActivityUtil, PerFragmentUtil perFragmentUtil) {
- super(view);
- this.singletonUtil = singletonUtil;
- this.perActivityUtil = perActivityUtil;
- this.perFragmentUtil = perFragmentUtil;
- }
-
- @Override
- public void onDoSomething() {
- // Do something here. Maybe make an asynchronous call to fetch data...
- String something = singletonUtil.doSomething();
- something += "\n" + perActivityUtil.doSomething();
- something += "\n" + perFragmentUtil.doSomething();
- view.showSomething(something);
- }
-}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/view/Example1Fragment.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/view/Example1Fragment.java
deleted file mode 100644
index 42c79e7..0000000
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/view/Example1Fragment.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2018 Vandolf Estrellado
- *
- * 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.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.view;
-
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.TextView;
-
-import com.vestrel00.daggerbutterknifemvp.R;
-import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseViewFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.presenter.Example1Presenter;
-
-import butterknife.BindView;
-import butterknife.OnClick;
-
-/**
- * A fragment implementation of {@link Example1View}.
- */
-public final class Example1Fragment extends BaseViewFragment
- implements Example1View {
-
- @BindView(R.id.some_text)
- TextView someText;
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- return inflater.inflate(R.layout.example_1_fragment, container, false);
- }
-
- @Override
- public void showSomething(String something) {
- someText.setText(something);
- }
-
- @OnClick(R.id.do_something)
- void onDoSomethingClicked() {
- presenter.onDoSomething();
- }
-}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/Example2ActivityModule.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/Example2ActivityModule.java
deleted file mode 100644
index b8d20fb..0000000
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/Example2ActivityModule.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright 2018 Vandolf Estrellado
- *
- * 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.vestrel00.daggerbutterknifemvp.ui.example_2;
-
-import android.support.v7.app.AppCompatActivity;
-
-import com.vestrel00.daggerbutterknifemvp.inject.PerActivity;
-import com.vestrel00.daggerbutterknifemvp.inject.PerFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.common.BaseActivityModule;
-import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.view.Example2AFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.view.Example2AFragmentModule;
-import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.view.Example2BFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.view.Example2BFragmentModule;
-
-import dagger.Binds;
-import dagger.Module;
-import dagger.android.ContributesAndroidInjector;
-
-/**
- * Provides example 2 activity dependencies.
- */
-@Module(includes = BaseActivityModule.class)
-public abstract class Example2ActivityModule {
-
- /**
- * Provides the injector for the {@link Example2AFragment}, which has access to the dependencies
- * provided by this activity and application instance (singleton scoped objects).
- */
- @PerFragment
- @ContributesAndroidInjector(modules = Example2AFragmentModule.class)
- abstract Example2AFragment example2AFragmentInjector();
-
- /**
- * Provides the injector for the {@link Example2BFragment}, which has access to the dependencies
- * provided by this activity and application instance (singleton scoped objects).
- */
- @PerFragment
- @ContributesAndroidInjector(modules = Example2BFragmentModule.class)
- abstract Example2BFragment example2BFragmentInjector();
-
- /**
- * As per the contract specified in {@link BaseActivityModule}; "This must be included in all
- * activity modules, which must provide a concrete implementation of {@link AppCompatActivity}."
- *
- * This provides the activity required to inject the
- * {@link BaseActivityModule#ACTIVITY_FRAGMENT_MANAGER} into the
- * {@link com.vestrel00.daggerbutterknifemvp.ui.common.BaseActivity}.
- *
- * @param example2Activity the example 2 activity
- * @return the activity
- */
- @Binds
- @PerActivity
- abstract AppCompatActivity appCompatActivity(Example2Activity example2Activity);
-}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/presenter/Example2APresenterImpl.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/presenter/Example2APresenterImpl.java
deleted file mode 100644
index 38b3d52..0000000
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/presenter/Example2APresenterImpl.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2018 Vandolf Estrellado
- *
- * 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.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.presenter;
-
-import com.vestrel00.daggerbutterknifemvp.inject.PerFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.common.presenter.BasePresenter;
-import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.view.Example2AView;
-import com.vestrel00.daggerbutterknifemvp.util.PerActivityUtil;
-import com.vestrel00.daggerbutterknifemvp.util.PerFragmentUtil;
-import com.vestrel00.daggerbutterknifemvp.util.SingletonUtil;
-
-import javax.inject.Inject;
-
-/**
- * An implementation of {@link Example2APresenter}.
- */
-@PerFragment
-final class Example2APresenterImpl extends BasePresenter
- implements Example2APresenter {
-
- private final SingletonUtil singletonUtil;
- private final PerActivityUtil perActivityUtil;
- private final PerFragmentUtil perFragmentUtil;
-
- @Inject
- Example2APresenterImpl(Example2AView view, SingletonUtil singletonUtil,
- PerActivityUtil perActivityUtil, PerFragmentUtil perFragmentUtil) {
- super(view);
- this.singletonUtil = singletonUtil;
- this.perActivityUtil = perActivityUtil;
- this.perFragmentUtil = perFragmentUtil;
- }
-
- @Override
- public void onDoSomething() {
- // Do something here. Maybe make an asynchronous call to fetch data...
- String something = singletonUtil.doSomething();
- something += "\n" + perActivityUtil.doSomething();
- something += "\n" + perFragmentUtil.doSomething();
- view.showSomething(something);
- }
-}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/view/Example2AFragment.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/view/Example2AFragment.java
deleted file mode 100644
index eed1efc..0000000
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/view/Example2AFragment.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2018 Vandolf Estrellado
- *
- * 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.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.view;
-
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.TextView;
-
-import com.vestrel00.daggerbutterknifemvp.R;
-import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseViewFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.presenter.Example2APresenter;
-
-import butterknife.BindView;
-import butterknife.OnClick;
-
-/**
- * A fragment implementation of {@link Example2AView}.
- */
-public final class Example2AFragment extends BaseViewFragment
- implements Example2AView {
-
- @BindView(R.id.some_text)
- TextView someText;
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- return inflater.inflate(R.layout.example_2_fragment_a, container, false);
- }
-
- @Override
- public void showSomething(String something) {
- someText.setText(something);
- }
-
- @OnClick(R.id.do_something)
- void onDoSomethingClicked() {
- presenter.onDoSomething();
- }
-}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/presenter/Example2BPresenterImpl.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/presenter/Example2BPresenterImpl.java
deleted file mode 100644
index 854877b..0000000
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/presenter/Example2BPresenterImpl.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2018 Vandolf Estrellado
- *
- * 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.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.presenter;
-
-import com.vestrel00.daggerbutterknifemvp.inject.PerFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.common.presenter.BasePresenter;
-import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.view.Example2BView;
-import com.vestrel00.daggerbutterknifemvp.util.PerActivityUtil;
-import com.vestrel00.daggerbutterknifemvp.util.PerFragmentUtil;
-import com.vestrel00.daggerbutterknifemvp.util.SingletonUtil;
-
-import javax.inject.Inject;
-
-/**
- * An implementation of {@link Example2BPresenter}.
- */
-@PerFragment
-final class Example2BPresenterImpl extends BasePresenter
- implements Example2BPresenter {
-
- private final SingletonUtil singletonUtil;
- private final PerActivityUtil perActivityUtil;
- private final PerFragmentUtil perFragmentUtil;
-
- @Inject
- Example2BPresenterImpl(Example2BView view, SingletonUtil singletonUtil,
- PerActivityUtil perActivityUtil, PerFragmentUtil perFragmentUtil) {
- super(view);
- this.singletonUtil = singletonUtil;
- this.perActivityUtil = perActivityUtil;
- this.perFragmentUtil = perFragmentUtil;
- }
-
- @Override
- public void onDoSomething() {
- // Do something here. Maybe make an asynchronous call to fetch data...
- String something = singletonUtil.doSomething();
- something += "\n" + perActivityUtil.doSomething();
- something += "\n" + perFragmentUtil.doSomething();
- view.showSomething(something);
- }
-}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/view/Example2BFragment.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/view/Example2BFragment.java
deleted file mode 100644
index fefbd2a..0000000
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/view/Example2BFragment.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2018 Vandolf Estrellado
- *
- * 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.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.view;
-
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.TextView;
-
-import com.vestrel00.daggerbutterknifemvp.R;
-import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseViewFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.presenter.Example2BPresenter;
-
-import butterknife.BindView;
-import butterknife.OnClick;
-
-/**
- * A fragment implementation of {@link Example2BView}.
- */
-public final class Example2BFragment extends BaseViewFragment
- implements Example2BView {
-
- @BindView(R.id.some_text)
- TextView someText;
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- return inflater.inflate(R.layout.example_2_fragment_b, container, false);
- }
-
- @Override
- public void showSomething(String something) {
- someText.setText(something);
- }
-
- @OnClick(R.id.do_something)
- void onDoSomethingClicked() {
- presenter.onDoSomething();
- }
-}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/presenter/Example3ChildPresenterImpl.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/presenter/Example3ChildPresenterImpl.java
deleted file mode 100644
index a49222d..0000000
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/presenter/Example3ChildPresenterImpl.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 2018 Vandolf Estrellado
- *
- * 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.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.presenter;
-
-import com.vestrel00.daggerbutterknifemvp.inject.PerChildFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.common.presenter.BasePresenter;
-import com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.view.Example3ChildView;
-import com.vestrel00.daggerbutterknifemvp.util.PerActivityUtil;
-import com.vestrel00.daggerbutterknifemvp.util.PerChildFragmentUtil;
-import com.vestrel00.daggerbutterknifemvp.util.PerFragmentUtil;
-import com.vestrel00.daggerbutterknifemvp.util.SingletonUtil;
-
-import javax.inject.Inject;
-
-/**
- * An implementation of {@link Example3ChildPresenter}.
- */
-@PerChildFragment
-final class Example3ChildPresenterImpl extends BasePresenter
- implements Example3ChildPresenter {
-
- private final SingletonUtil singletonUtil;
- private final PerActivityUtil perActivityUtil;
- private final PerFragmentUtil perFragmentUtil;
- private final PerChildFragmentUtil perChildFragmentUtil;
-
- @Inject
- Example3ChildPresenterImpl(Example3ChildView view, SingletonUtil singletonUtil,
- PerActivityUtil perActivityUtil, PerFragmentUtil perFragmentUtil,
- PerChildFragmentUtil perChildFragmentUtil) {
- super(view);
- this.singletonUtil = singletonUtil;
- this.perActivityUtil = perActivityUtil;
- this.perFragmentUtil = perFragmentUtil;
- this.perChildFragmentUtil = perChildFragmentUtil;
- }
-
- @Override
- public void onDoSomething() {
- // Do something here. Maybe make an asynchronous call to fetch data...
- String something = singletonUtil.doSomething();
- something += "\n" + perActivityUtil.doSomething();
- something += "\n" + perFragmentUtil.doSomething();
- something += "\n" + perChildFragmentUtil.doSomething();
- view.showSomething(something);
- }
-}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/view/Example3ChildFragment.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/view/Example3ChildFragment.java
deleted file mode 100644
index 8e06fc4..0000000
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/view/Example3ChildFragment.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2018 Vandolf Estrellado
- *
- * 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.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.view;
-
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.TextView;
-
-import com.vestrel00.daggerbutterknifemvp.R;
-import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseViewFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.presenter.Example3ChildPresenter;
-
-import butterknife.BindView;
-import butterknife.OnClick;
-
-/**
- * A fragment implementation of {@link Example3ChildView}.
- */
-public final class Example3ChildFragment extends BaseViewFragment
- implements Example3ChildView {
-
- @BindView(R.id.some_text)
- TextView someText;
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- return inflater.inflate(R.layout.example_3_child_fragment, container, false);
- }
-
- @Override
- public void showSomething(String something) {
- someText.setText(something);
- }
-
- @OnClick(R.id.do_something)
- void onDoSomethingClicked() {
- presenter.onDoSomething();
- }
-}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/presenter/Example3ParentPresenterImpl.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/presenter/Example3ParentPresenterImpl.java
deleted file mode 100644
index 6b79ecf..0000000
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/presenter/Example3ParentPresenterImpl.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2018 Vandolf Estrellado
- *
- * 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.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.presenter;
-
-import com.vestrel00.daggerbutterknifemvp.inject.PerFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.common.presenter.BasePresenter;
-import com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.view.Example3ParentView;
-import com.vestrel00.daggerbutterknifemvp.util.PerActivityUtil;
-import com.vestrel00.daggerbutterknifemvp.util.PerFragmentUtil;
-import com.vestrel00.daggerbutterknifemvp.util.SingletonUtil;
-
-import javax.inject.Inject;
-
-/**
- * An implementation of {@link Example3ParentPresenter}.
- */
-@PerFragment
-final class Example3ParentPresenterImpl extends BasePresenter
- implements Example3ParentPresenter {
-
- private final SingletonUtil singletonUtil;
- private final PerActivityUtil perActivityUtil;
- private final PerFragmentUtil perFragmentUtil;
-
- @Inject
- Example3ParentPresenterImpl(Example3ParentView view, SingletonUtil singletonUtil,
- PerActivityUtil perActivityUtil, PerFragmentUtil perFragmentUtil) {
- super(view);
- this.singletonUtil = singletonUtil;
- this.perActivityUtil = perActivityUtil;
- this.perFragmentUtil = perFragmentUtil;
- }
-
- @Override
- public void onDoSomething() {
- // Do something here. Maybe make an asynchronous call to fetch data...
- String something = singletonUtil.doSomething();
- something += "\n" + perActivityUtil.doSomething();
- something += "\n" + perFragmentUtil.doSomething();
- view.showSomething(something);
- }
-}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/view/Example3ParentFragment.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/view/Example3ParentFragment.java
deleted file mode 100644
index c9225f9..0000000
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/view/Example3ParentFragment.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2018 Vandolf Estrellado
- *
- * 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.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.view;
-
-import android.os.Bundle;
-import android.support.annotation.Nullable;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.TextView;
-
-import com.vestrel00.daggerbutterknifemvp.R;
-import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseViewFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.view.Example3ChildFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.presenter.Example3ParentPresenter;
-
-import butterknife.BindView;
-import butterknife.OnClick;
-
-/**
- * A fragment implementation of {@link Example3ParentView}.
- */
-public final class Example3ParentFragment extends BaseViewFragment
- implements Example3ParentView {
-
- @BindView(R.id.some_text)
- TextView someText;
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- return inflater.inflate(R.layout.example_3_parent_fragment, container, false);
- }
-
- @Override
- public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
- super.onViewCreated(view, savedInstanceState);
- if (savedInstanceState == null) {
- addChildFragment(R.id.child_fragment_container, new Example3ChildFragment());
- }
- }
-
- @Override
- public void showSomething(String something) {
- someText.setText(something);
- }
-
- @OnClick(R.id.do_something)
- void onDoSomethingClicked() {
- presenter.onDoSomething();
- }
-}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/MainActivity.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/MainActivity.java
deleted file mode 100644
index 2867860..0000000
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/MainActivity.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright 2018 Vandolf Estrellado
- *
- * 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.vestrel00.daggerbutterknifemvp.ui.main;
-
-import android.os.Bundle;
-import android.support.annotation.Nullable;
-
-import com.vestrel00.daggerbutterknifemvp.R;
-import com.vestrel00.daggerbutterknifemvp.ui.common.BaseActivity;
-import com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.view.Example1Fragment;
-import com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.view.Example3ParentFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.main.view.MainFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.main.view.MainFragmentListener;
-
-/**
- * The main activity that provides a way to navigate to all other activities.
- */
-public final class MainActivity extends BaseActivity implements MainFragmentListener {
-
- private static final String TAG_EXAMPLE_4 = "MainActivity.example_4";
- private static final String TAG_EXAMPLE_5 = "MainActivity.example_5";
-
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main_activity);
-
- if (savedInstanceState == null) {
- addFragment(R.id.fragment_container, new MainFragment());
- }
- }
-
- @Override
- public void onExample1Clicked() {
- navigator.toExample1(this);
- }
-
- @Override
- public void onExample2Clicked() {
- navigator.toExample2(this);
- }
-
- @Override
- public void onExample3Clicked() {
- navigator.toExample3(this);
- }
-
- @Override
- public void onExample4Clicked() {
- showDialogFragment(new Example1Fragment(), TAG_EXAMPLE_4);
- }
-
- @Override
- public void onExample5Clicked() {
- showDialogFragment(new Example3ParentFragment(), TAG_EXAMPLE_5);
- }
-}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/MainActivityModule.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/MainActivityModule.java
deleted file mode 100644
index 573a8aa..0000000
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/MainActivityModule.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright 2018 Vandolf Estrellado
- *
- * 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.vestrel00.daggerbutterknifemvp.ui.main;
-
-import android.support.v7.app.AppCompatActivity;
-
-import com.vestrel00.daggerbutterknifemvp.inject.PerActivity;
-import com.vestrel00.daggerbutterknifemvp.inject.PerFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.common.BaseActivityModule;
-import com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.view.Example1Fragment;
-import com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.view.Example1FragmentModule;
-import com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.view.Example3ParentFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.view.Example3ParentFragmentModule;
-import com.vestrel00.daggerbutterknifemvp.ui.main.view.MainFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.main.view.MainFragmentListener;
-import com.vestrel00.daggerbutterknifemvp.ui.main.view.MainFragmentModule;
-
-import dagger.Binds;
-import dagger.Module;
-import dagger.android.ContributesAndroidInjector;
-
-/**
- * Provides main activity dependencies.
- */
-@Module(includes = BaseActivityModule.class)
-public abstract class MainActivityModule {
-
- /**
- * Provides the injector for the {@link MainFragment}, which has access to the dependencies
- * provided by this activity and application instance (singleton scoped objects).
- */
- @PerFragment
- @ContributesAndroidInjector(modules = MainFragmentModule.class)
- abstract MainFragment mainFragmentInjector();
-
- /**
- * Provides the injector for the {@link Example1Fragment}, which has access to the dependencies
- * provided by this activity and application instance (singleton scoped objects).
- *
- * This is used for example 4, which displays {@link Example1Fragment} as a
- * {@link android.app.DialogFragment}.
- */
- @PerFragment
- @ContributesAndroidInjector(modules = Example1FragmentModule.class)
- abstract Example1Fragment example1FragmentInjector();
-
- /**
- * Provides the injector for the {@link Example3ParentFragment}, which has access to the
- * dependencies provided by this activity and application instance (singleton scoped objects).
- *
- * This is used for example 5, which displays {@link Example3ParentFragment} as a
- * {@link android.app.DialogFragment}.
- */
- @PerFragment
- @ContributesAndroidInjector(modules = Example3ParentFragmentModule.class)
- abstract Example3ParentFragment example3ParentFragmentInjector();
-
- /**
- * As per the contract specified in {@link BaseActivityModule}; "This must be included in all
- * activity modules, which must provide a concrete implementation of {@link AppCompatActivity}."
- *
- * This provides the activity required to inject the
- * {@link BaseActivityModule#ACTIVITY_FRAGMENT_MANAGER} into the
- * {@link com.vestrel00.daggerbutterknifemvp.ui.common.BaseActivity}.
- *
- * @param mainActivity the activity
- * @return the activity
- */
- @Binds
- @PerActivity
- abstract AppCompatActivity appCompatActivity(MainActivity mainActivity);
-
- /**
- * The main activity listens to the events in the {@link MainFragment}.
- *
- * @param mainActivity the activity
- * @return the main fragment listener
- */
- @Binds
- @PerActivity
- abstract MainFragmentListener mainFragmentListener(MainActivity mainActivity);
-
-}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/view/MainFragmentListener.java b/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/view/MainFragmentListener.java
deleted file mode 100644
index ca624d3..0000000
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/view/MainFragmentListener.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 2018 Vandolf Estrellado
- *
- * 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.vestrel00.daggerbutterknifemvp.ui.main.view;
-
-/**
- * Listener for {@link MainFragment} UI events.
- */
-public interface MainFragmentListener {
-
- void onExample1Clicked();
-
- void onExample2Clicked();
-
- void onExample3Clicked();
-
- void onExample4Clicked();
-
- void onExample5Clicked();
-}
diff --git a/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/App.kt b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/App.kt
new file mode 100644
index 0000000..e2ddbe9
--- /dev/null
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/App.kt
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2018 Vandolf Estrellado
+ *
+ * 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.vestrel00.daggerbutterknifemvp
+
+import android.app.Activity
+import android.app.Application
+import dagger.android.DispatchingAndroidInjector
+import dagger.android.HasActivityInjector
+import javax.inject.Inject
+
+/**
+ * The Android [Application].
+ *
+ * **DEPENDENCY INJECTION**
+ *
+ * We could extend [dagger.android.DaggerApplication] so we can get the boilerplate dagger code for
+ * free. However, we want to avoid inheritance (if possible and it is in this case) so that we have
+ * to option to inherit from something else later on if needed
+ */
+class App : Application(), HasActivityInjector {
+
+ @Inject
+ lateinit var activityInjector: DispatchingAndroidInjector
+
+ override fun onCreate() {
+ super.onCreate()
+ DaggerAppComponent.builder().create(this).inject(this)
+ }
+
+ override fun activityInjector() = activityInjector
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/AppComponent.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/AppComponent.kt
similarity index 69%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/AppComponent.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/AppComponent.kt
index c03518a..a8a1c61 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/AppComponent.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/AppComponent.kt
@@ -14,21 +14,19 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp;
+package com.vestrel00.daggerbutterknifemvp
-import javax.inject.Singleton;
-
-import dagger.Component;
-import dagger.android.AndroidInjector;
+import dagger.Component
+import dagger.android.AndroidInjector
+import javax.inject.Singleton
/**
* Injects application dependencies.
*/
@Singleton
-@Component(modules = AppModule.class)
-interface AppComponent extends AndroidInjector {
+@Component(modules = [AppModule::class])
+interface AppComponent : AndroidInjector {
@Component.Builder
- abstract class Builder extends AndroidInjector.Builder {
- }
-}
+ abstract class Builder : AndroidInjector.Builder()
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/AppModule.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/AppModule.kt
similarity index 56%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/AppModule.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/AppModule.kt
index 3faddeb..f55e00f 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/AppModule.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/AppModule.kt
@@ -14,31 +14,28 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp;
+package com.vestrel00.daggerbutterknifemvp
-import android.app.Application;
-
-import com.vestrel00.daggerbutterknifemvp.inject.PerActivity;
-import com.vestrel00.daggerbutterknifemvp.ui.example_1.Example1Activity;
-import com.vestrel00.daggerbutterknifemvp.ui.example_1.Example1ActivityModule;
-import com.vestrel00.daggerbutterknifemvp.ui.example_2.Example2Activity;
-import com.vestrel00.daggerbutterknifemvp.ui.example_2.Example2ActivityModule;
-import com.vestrel00.daggerbutterknifemvp.ui.example_3.Example3Activity;
-import com.vestrel00.daggerbutterknifemvp.ui.example_3.Example3ActivityModule;
-import com.vestrel00.daggerbutterknifemvp.ui.main.MainActivity;
-import com.vestrel00.daggerbutterknifemvp.ui.main.MainActivityModule;
-
-import javax.inject.Singleton;
-
-import dagger.Binds;
-import dagger.Module;
-import dagger.android.ContributesAndroidInjector;
-import dagger.android.support.AndroidSupportInjectionModule;
+import android.app.Application
+import com.vestrel00.daggerbutterknifemvp.inject.PerActivity
+import com.vestrel00.daggerbutterknifemvp.ui.example_1.Example1Activity
+import com.vestrel00.daggerbutterknifemvp.ui.example_1.Example1ActivityModule
+import com.vestrel00.daggerbutterknifemvp.ui.example_2.Example2Activity
+import com.vestrel00.daggerbutterknifemvp.ui.example_2.Example2ActivityModule
+import com.vestrel00.daggerbutterknifemvp.ui.example_3.Example3Activity
+import com.vestrel00.daggerbutterknifemvp.ui.example_3.Example3ActivityModule
+import com.vestrel00.daggerbutterknifemvp.ui.main.MainActivity
+import com.vestrel00.daggerbutterknifemvp.ui.main.MainActivityModule
+import dagger.Binds
+import dagger.Module
+import dagger.android.ContributesAndroidInjector
+import dagger.android.support.AndroidSupportInjectionModule
+import javax.inject.Singleton
/**
* Provides application-wide dependencies.
*/
-@Module(includes = AndroidSupportInjectionModule.class)
+@Module(includes = [AndroidSupportInjectionModule::class])
abstract class AppModule {
@Binds
@@ -51,37 +48,39 @@ abstract class AppModule {
* However, having a scope annotation makes the module easier to read. We wouldn't have to look
* at what is being provided in order to understand its scope.
*/
- abstract Application application(App app);
+ abstract fun application(app: App): Application
/**
- * Provides the injector for the {@link MainActivity}, which has access to the dependencies
- * provided by this application instance (singleton scoped objects).
+ * Provides the injector for the [MainActivity], which has access to the dependencies provided
+ * by this application instance (singleton scoped objects).
*/
@PerActivity
- @ContributesAndroidInjector(modules = MainActivityModule.class)
- abstract MainActivity mainActivityInjector();
+ @ContributesAndroidInjector(modules = [MainActivityModule::class])
+ abstract fun mainActivityInjector(): MainActivity
/**
- * Provides the injector for the {@link Example1Activity}, which has access to the dependencies
+ * Provides the injector for the [Example1Activity], which has access to the dependencies
* provided by this application instance (singleton scoped objects).
*/
@PerActivity
- @ContributesAndroidInjector(modules = Example1ActivityModule.class)
- abstract Example1Activity example1ActivityInjector();
+ @ContributesAndroidInjector(modules = [Example1ActivityModule::class])
+ abstract fun example1ActivityInjector(): Example1Activity
+
/**
- * Provides the injector for the {@link Example2Activity}, which has access to the dependencies
+ * Provides the injector for the [Example2Activity], which has access to the dependencies
* provided by this application instance (singleton scoped objects).
*/
@PerActivity
- @ContributesAndroidInjector(modules = Example2ActivityModule.class)
- abstract Example2Activity example2ActivityInjector();
+ @ContributesAndroidInjector(modules = [Example2ActivityModule::class])
+ abstract fun example2ActivityInjector(): Example2Activity
+
/**
- * Provides the injector for the {@link Example3Activity}, which has access to the dependencies
+ * Provides the injector for the [Example3Activity], which has access to the dependencies
* provided by this application instance (singleton scoped objects).
*/
@PerActivity
- @ContributesAndroidInjector(modules = Example3ActivityModule.class)
- abstract Example3Activity example3ActivityInjector();
+ @ContributesAndroidInjector(modules = [Example3ActivityModule::class])
+ abstract fun example3ActivityInjector(): Example3Activity
}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/inject/PerActivity.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/inject/PerActivity.kt
similarity index 79%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/inject/PerActivity.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/inject/PerActivity.kt
index 1d24a7f..19ae2a2 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/inject/PerActivity.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/inject/PerActivity.kt
@@ -14,12 +14,9 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.inject;
+package com.vestrel00.daggerbutterknifemvp.inject
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
-import javax.inject.Scope;
+import javax.inject.Scope
/**
* A custom scoping annotation that specifies that the lifespan of a dependency be the same as that
@@ -29,6 +26,5 @@
* Activity, Fragment, and child Fragments instead of the entire Application.
*/
@Scope
-@Retention(RetentionPolicy.RUNTIME)
-public @interface PerActivity {
-}
+@Retention(AnnotationRetention.RUNTIME)
+annotation class PerActivity
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/inject/PerChildFragment.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/inject/PerChildFragment.kt
similarity index 66%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/inject/PerChildFragment.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/inject/PerChildFragment.kt
index 5d70a84..22818dc 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/inject/PerChildFragment.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/inject/PerChildFragment.kt
@@ -14,27 +14,23 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.inject;
+package com.vestrel00.daggerbutterknifemvp.inject
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
-import javax.inject.Scope;
+import javax.inject.Scope
/**
* A custom scoping annotation that specifies that the lifespan of a dependency be the same as that
* of a child Fragment (a fragment inside a fragment that is added using
* Fragment.getChildFragmentManager().
- *
- * This is used to annotate dependencies that behave like a singleton within the lifespan of a
- * child Fragment instead of the entire Application, Activity, or parent Fragment.
- *
+ *
+ * This is used to annotate dependencies that behave like a singleton within the lifespan of a child
+ * Fragment instead of the entire Application, Activity, or parent Fragment.
+ *
* Note that this does not support a child fragment within a child fragment as conflicting scopes
- * will occur. Child fragments within child fragments should usually be avoided. However, if
- * another level of child fragment is required, then another scope would need to be created
- * (perhaps PerGrandChild custom scope annotation).
+ * will occur. Child fragments within child fragments should usually be avoided. However, if another
+ * level of child fragment is required, then another scope would need to be created (perhaps
+ * PerGrandChild custom scope annotation).
*/
@Scope
-@Retention(RetentionPolicy.RUNTIME)
-public @interface PerChildFragment {
-}
+@Retention(AnnotationRetention.RUNTIME)
+annotation class PerChildFragment
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/inject/PerFragment.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/inject/PerFragment.kt
similarity index 79%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/inject/PerFragment.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/inject/PerFragment.kt
index 05610af..8b19912 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/inject/PerFragment.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/inject/PerFragment.kt
@@ -14,12 +14,9 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.inject;
+package com.vestrel00.daggerbutterknifemvp.inject
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
-import javax.inject.Scope;
+import javax.inject.Scope
/**
* A custom scoping annotation that specifies that the lifespan of a dependency be the same as that
@@ -29,6 +26,5 @@
* Fragment and child Fragments instead of the entire Application or Activity.
*/
@Scope
-@Retention(RetentionPolicy.RUNTIME)
-public @interface PerFragment {
-}
+@Retention(AnnotationRetention.RUNTIME)
+annotation class PerFragment
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/inject/package-info.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/inject/package-info.java
similarity index 100%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/inject/package-info.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/inject/package-info.java
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/navigation/Navigator.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/navigation/Navigator.kt
similarity index 55%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/navigation/Navigator.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/navigation/Navigator.kt
index 44d6f37..e5a66af 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/navigation/Navigator.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/navigation/Navigator.kt
@@ -14,40 +14,34 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.navigation;
+package com.vestrel00.daggerbutterknifemvp.navigation
-import android.content.Context;
-import android.content.Intent;
-
-import com.vestrel00.daggerbutterknifemvp.ui.example_1.Example1Activity;
-import com.vestrel00.daggerbutterknifemvp.ui.example_2.Example2Activity;
-import com.vestrel00.daggerbutterknifemvp.ui.example_3.Example3Activity;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
+import android.content.Context
+import android.content.Intent
+import com.vestrel00.daggerbutterknifemvp.ui.example_1.Example1Activity
+import com.vestrel00.daggerbutterknifemvp.ui.example_2.Example2Activity
+import com.vestrel00.daggerbutterknifemvp.ui.example_3.Example3Activity
+import javax.inject.Inject
+import javax.inject.Singleton
/**
* Provides methods to navigate to the different activities in the application.
*/
@Singleton
-public final class Navigator {
-
- @Inject
- Navigator() {
- }
+class Navigator @Inject constructor() {
- public void toExample1(Context context) {
- Intent intent = new Intent(context, Example1Activity.class);
- context.startActivity(intent);
+ fun toExample1(context: Context) {
+ val intent = Intent(context, Example1Activity::class.java)
+ context.startActivity(intent)
}
- public void toExample2(Context context) {
- Intent intent = new Intent(context, Example2Activity.class);
- context.startActivity(intent);
+ fun toExample2(context: Context) {
+ val intent = Intent(context, Example2Activity::class.java)
+ context.startActivity(intent)
}
- public void toExample3(Context context) {
- Intent intent = new Intent(context, Example3Activity.class);
- context.startActivity(intent);
+ fun toExample3(context: Context) {
+ val intent = Intent(context, Example3Activity::class.java)
+ context.startActivity(intent)
}
}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/navigation/package-info.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/navigation/package-info.java
similarity index 100%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/navigation/package-info.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/navigation/package-info.java
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/package-info.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/package-info.java
similarity index 100%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/package-info.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/package-info.java
diff --git a/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/BaseActivity.kt b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/BaseActivity.kt
new file mode 100644
index 0000000..1829dbb
--- /dev/null
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/BaseActivity.kt
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2018 Vandolf Estrellado
+ *
+ * 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.vestrel00.daggerbutterknifemvp.ui.common
+
+import android.os.Bundle
+import android.support.annotation.IdRes
+import android.support.v4.app.DialogFragment
+import android.support.v4.app.Fragment
+import android.support.v7.app.AppCompatActivity
+import com.vestrel00.daggerbutterknifemvp.navigation.Navigator
+import dagger.android.AndroidInjection
+import dagger.android.DispatchingAndroidInjector
+import dagger.android.support.HasSupportFragmentInjector
+import javax.inject.Inject
+
+/**
+ * Abstract Activity for all Activities to extend.
+ *
+ * **DEPENDENCY INJECTION**
+ *
+ * We could extend [dagger.android.support.DaggerAppCompatActivity] so we can get the boilerplate
+ * dagger code for free. However, we want to avoid inheritance (if possible and it is in this case)
+ * so that we have to option to inherit from something else later on if needed.
+ */
+abstract class BaseActivity : AppCompatActivity(), HasSupportFragmentInjector {
+
+ @Inject
+ lateinit var fragmentInjector: DispatchingAndroidInjector
+
+ @Inject
+ protected lateinit var navigator: Navigator
+
+ /*
+ * The property `fragmentManager` cannot be declared here with that name as it results in an
+ * 'accidental override' compile-time error. Kotlin automatically generates getters for
+ * properties. In this case, Kotlin generates a method called `getFragmentManager()` for the
+ * property `fragmentManager`, which then conflicts with the Activity's `getFragmentManager()`
+ * method.
+ *
+ * There are workarounds to this;
+ *
+ * 1. Change the property name to something else such as `activityFragmentManager`.
+ * 2. Rename the getter generated by Kotlin using @get:JvmName("activityFragmentManager")
+ *
+ * However, we will not be doing any of the above because subclasses would have to use our
+ * custom getter/property instead of the builtin `fragmentManager`, which may cause confusion.
+ * Furthermore, Kotlin exposes the property `supportFragmentManager` from the getter
+ * `getSupportFragmentManager()`, which will cause even greater confusion.
+ *
+ * The caveat to this is that we would need to use Robolectric in our tests in order to mock and
+ * verify `FragmentManager` usages. For more details around testing (support) `FragmentManager`
+ * usages, see https://github.com/vestrel00/android-dagger-butterknife-mvp/pull/52.
+ */
+ // @Inject
+ // @field:Named(BaseActivityModule.ACTIVITY_FRAGMENT_MANAGER)
+ // protected lateinit var fragmentManager: FragmentManager
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ AndroidInjection.inject(this)
+ super.onCreate(savedInstanceState)
+ }
+
+ override fun supportFragmentInjector() = fragmentInjector
+
+ protected fun addFragment(@IdRes containerViewId: Int, fragment: Fragment) {
+ supportFragmentManager.beginTransaction()
+ .add(containerViewId, fragment)
+ .commit()
+ }
+
+ protected fun showDialogFragment(dialogFragment: DialogFragment, tag: String) =
+ dialogFragment.show(supportFragmentManager, tag)
+}
\ No newline at end of file
diff --git a/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/BaseActivityModule.kt b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/BaseActivityModule.kt
new file mode 100644
index 0000000..6fa1fde
--- /dev/null
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/BaseActivityModule.kt
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2018 Vandolf Estrellado
+ *
+ * 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.vestrel00.daggerbutterknifemvp.ui.common
+
+import android.app.Activity
+import android.content.Context
+import android.support.v4.app.FragmentManager
+import android.support.v7.app.AppCompatActivity
+import com.vestrel00.daggerbutterknifemvp.inject.PerActivity
+import dagger.Binds
+import dagger.Module
+import dagger.Provides
+import javax.inject.Named
+
+
+/**
+ * Provides base activity dependencies. This must be included in all activity modules, which must
+ * provide a concrete implementation of [AppCompatActivity].
+ */
+@Module
+abstract class BaseActivityModule {
+
+ @Module
+ companion object {
+ /*
+ * Note that this is currently unused in this Kotlin project. However, it is used in the
+ * Java branch of this project. We'll keep this private to avoid lint warnings until other
+ * Kotlin classes needs it.
+ */
+ private const val ACTIVITY_FRAGMENT_MANAGER = "BaseActivityModule.activityFragmentManager"
+
+ /*
+ * This is a valid way to declare static provides methods.
+ * See https://github.com/google/dagger/issues/900#issuecomment-337043187
+ */
+ @JvmStatic
+ @Provides
+ @Named(ACTIVITY_FRAGMENT_MANAGER)
+ @PerActivity
+ fun activityFragmentManager(activity: AppCompatActivity): FragmentManager =
+ activity.supportFragmentManager
+ }
+
+ @Binds
+ @PerActivity
+ /*
+ * PerActivity annotation isn't necessary since Activity instance is unique but is here for
+ * convention. In general, providing Application, Activity, Fragment, BroadcastReceiver,
+ * etc does not require scoped annotations since they are the components being injected and
+ * their instance is unique.
+ *
+ * However, having a scope annotation makes the module easier to read. We wouldn't have to look
+ * at what is being provided in order to understand its scope.
+ */
+ abstract fun activity(appCompatActivity: AppCompatActivity): Activity
+
+
+ @Binds
+ @PerActivity
+ abstract fun activityContext(activity: Activity): Context
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/package-info.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/package-info.java
similarity index 100%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/package-info.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/package-info.java
diff --git a/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/presenter/BasePresenter.kt b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/presenter/BasePresenter.kt
new file mode 100644
index 0000000..c3f139d
--- /dev/null
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/presenter/BasePresenter.kt
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2018 Vandolf Estrellado
+ *
+ * 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.vestrel00.daggerbutterknifemvp.ui.common.presenter
+
+import com.vestrel00.daggerbutterknifemvp.ui.common.view.MVPView
+
+/**
+ * Abstract [Presenter] for all presenters to extend.
+ *
+ * @param [T] the type of the [MVPView].
+ */
+abstract class BasePresenter
+protected constructor(protected val view: T) : Presenter
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/presenter/Presenter.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/presenter/Presenter.kt
similarity index 80%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/presenter/Presenter.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/presenter/Presenter.kt
index 8dcee93..05b6fec 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/presenter/Presenter.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/presenter/Presenter.kt
@@ -14,36 +14,35 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.common.presenter;
+package com.vestrel00.daggerbutterknifemvp.ui.common.presenter
-import android.os.Bundle;
-import android.support.annotation.Nullable;
+import android.os.Bundle
/**
* A presenter that defines its own lifecycle methods.
*/
-public interface Presenter {
+interface Presenter {
/**
* Starts the presentation. This should be called in the view's (Activity or Fragment)
* onCreate() or onViewStatedRestored() method respectively.
*
* @param savedInstanceState the saved instance state that contains state saved in
- * {@link #onSaveInstanceState(Bundle)}
+ * [onSaveInstanceState].
*/
- void onStart(@Nullable Bundle savedInstanceState);
+ fun onStart(savedInstanceState: Bundle?) = Unit
/**
* Resumes the presentation. This should be called in the view's (Activity or Fragment)
* onResume() method.
*/
- void onResume();
+ fun onResume() = Unit
/**
* Pauses the presentation. This should be called in the view's Activity or Fragment)
* onPause() method.
*/
- void onPause();
+ fun onPause() = Unit
/**
* Save the state of the presentation (if any). This should be called in the view's
@@ -51,11 +50,11 @@ public interface Presenter {
*
* @param outState the out state to save instance state
*/
- void onSaveInstanceState(Bundle outState);
+ fun onSaveInstanceState(outState: Bundle) = Unit
/**
* Ends the presentation. This should be called in the view's (Activity or Fragment)
* onDestroy() or onDestroyView() method respectively.
*/
- void onEnd();
-}
+ fun onEnd() = Unit
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseChildFragmentModule.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseChildFragmentModule.kt
similarity index 63%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseChildFragmentModule.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseChildFragmentModule.kt
index 0d26278..f9d6e78 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseChildFragmentModule.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseChildFragmentModule.kt
@@ -14,33 +14,33 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.common.view;
+package com.vestrel00.daggerbutterknifemvp.ui.common.view
-import android.app.Fragment;
-
-import dagger.Module;
+import dagger.Module
/**
* Provides base fragment dependencies. This must be included in all child fragment modules, which
- * must provide a concrete implementation of the child {@link Fragment} and named
- * {@link #CHILD_FRAGMENT}.
- *
- * Note that a different {@link javax.inject.Named} for the {@link Fragment} is required in order to
+ * must provide a concrete implementation of the child [android.app.Fragment] and named
+ * [CHILD_FRAGMENT].
+ *
+ * Note that a different [javax.inject.Named] for the [android.app.Fragment] is required in order to
* remove any ambiguity about which fragment is being provided in a child fragment. For example,
* we have parent fragment P and child fragment C. Parent fragment P will provide the Fragment
- * reference using the {@link BaseFragmentModule#FRAGMENT} name. Child fragment C will provide the
- * Fragment reference using the {@link #CHILD_FRAGMENT} name.
- *
+ * reference using the [BaseFragmentModule.FRAGMENT] name. Child fragment C will provide the
+ * Fragment reference using the [CHILD_FRAGMENT] name.
+ *
* If the parent and child fragments are not uniquely named, then the child fragment and its
* dependencies will not know which Fragment is provided to it. It could be the parent fragment
* or the child fragment. Hence the ambiguity, which causes a compile error of
* "android.app.Fragment is bound multiple times".
*/
@Module
-public abstract class BaseChildFragmentModule {
+abstract class BaseChildFragmentModule {
- /**
- * See class documentation regarding the need for this name.
- */
- public static final String CHILD_FRAGMENT = "BaseChildFragmentModule.childFragment";
-}
+ companion object {
+ /**
+ * See class documentation regarding the need for this name.
+ */
+ const val CHILD_FRAGMENT = "BaseChildFragmentModule.childFragment"
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseFragment.kt b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseFragment.kt
new file mode 100644
index 0000000..ff9f19b
--- /dev/null
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseFragment.kt
@@ -0,0 +1,158 @@
+/*
+ * Copyright 2018 Vandolf Estrellado
+ *
+ * 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.vestrel00.daggerbutterknifemvp.ui.common.view
+
+import android.app.Dialog
+import android.content.Context
+import android.os.Bundle
+import android.support.annotation.IdRes
+import android.support.v4.app.Fragment
+import android.support.v7.app.AppCompatDialogFragment
+import butterknife.ButterKnife
+import butterknife.Unbinder
+import com.vestrel00.daggerbutterknifemvp.R
+import dagger.android.DispatchingAndroidInjector
+import dagger.android.support.AndroidSupportInjection
+import dagger.android.support.HasSupportFragmentInjector
+import javax.inject.Inject
+
+/**
+ * Abstract (Dialog)Fragment for all (Dialog)Fragments and child (Dialog)Fragments to extend.
+ * This contains some boilerplate dependency injection code and activity [Context].
+ *
+ * **WHY EXTEND DialogFragment?**
+ *
+ * [AppCompatDialogFragment]s are simple extensions of Fragments. DialogFragments can be shown as a
+ * dialog floating above the current activity or be embedded into views like regular fragments.
+ * Therefore, supporting both Fragments and DialogFragments for dependency injection can simply be
+ * achieved by having the base fragment class (this) extend DialogFragment instead of Fragment.
+ * We could have separate base classes for Fragments and DialogFragments but that would produce
+ * duplicate code. See See https://github.com/vestrel00/android-dagger-butterknife-mvp/pull/64
+ *
+ * Note that as of Dagger 2.12, the abstract base framework type
+ * [dagger.android.support.DaggerAppCompatDialogFragment] has been introduced for subclassing if so
+ * desired.
+ *
+ * **DEPENDENCY INJECTION**
+ *
+ * We could extend [dagger.android.support.DaggerAppCompatDialogFragment] so we can get the
+ * boilerplate dagger code for free. However, we want to avoid inheritance (if possible and it is in
+ * this case) so that we have to option to inherit from something else later on if needed.
+ *
+ * **VIEW BINDING**
+ *
+ * This fragment handles view bind and unbinding.
+ */
+abstract class BaseFragment : AppCompatDialogFragment(), HasSupportFragmentInjector {
+
+ @Inject
+ lateinit var childFragmentInjector: DispatchingAndroidInjector
+
+ /*
+ * The property `childFragmentManager` cannot be declared here with that name as it results in
+ * an 'accidental override' compile-time error. Kotlin automatically generates getters for
+ * properties. In this case, Kotlin generates a method called `getChildFragmentManager()` for
+ * the property `childFragmentManager`, which then conflicts with the Activity's
+ * `getChildFragmentManager()` method.
+ *
+ * There are workarounds to this;
+ *
+ * 1. Change the property name to something else such as `fragmentChildFragmentManager`.
+ * 2. Rename the getter generated by Kotlin using @get:JvmName("fragmentChildFragmentManager")
+ *
+ * However, we will not be doing any of the above because subclasses would have to use our
+ * custom getter/property instead of the builtin `childFragmentManager`, which may cause
+ * confusion.
+ *
+ * The caveat to this is that we would need to use Robolectric in our tests in order to mock and
+ * verify `FragmentManager` usages. For more details around testing `FragmentManager` usages,
+ * see https://github.com/vestrel00/android-dagger-butterknife-mvp/pull/52.
+ */
+ // @Inject
+ // @field:Named(BaseFragmentModule.CHILD_FRAGMENT_MANAGER)
+ // protected lateinit var childFragmentManager: FragmentManager
+
+ /*
+ * This coincides with workaround #1 from the above comment about `childFragmentManager`. We'll
+ * just use the `context` reference provided by Kotlin (from the Fragment's `getContext()`
+ * method).
+ */
+ // @Inject
+ // protected lateinit var activityContext: Context
+
+ private var viewUnbinder: Unbinder? = null
+
+ override fun onAttach(context: Context) {
+ // This is called even for API levels below 23.
+ AndroidSupportInjection.inject(this)
+ super.onAttach(context)
+ }
+
+ override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
+ // Quick fix for the dialog width not taking up most of the screen width.
+ setStyle(AppCompatDialogFragment.STYLE_NORMAL, R.style.Theme_AppCompat_Dialog_MinWidth);
+ return super.onCreateDialog(savedInstanceState)
+ }
+
+ override fun onViewStateRestored(savedInstanceState: Bundle?) {
+ super.onViewStateRestored(savedInstanceState)
+ /*
+ * Bind the views here instead of in onViewCreated so that view state changed listeners
+ * are not invoked automatically without user interaction.
+ *
+ * If we bind before this method (e.g. onViewCreated), then any checked changed
+ * listeners bound by ButterKnife will be invoked during fragment recreation (since
+ * Android itself saves and restores the views' states. Take a look at this gist for a
+ * concrete example: https://gist.github.com/vestrel00/982d585144423f728342787341fa001d
+ *
+ * The lifecycle order is as follows (same if added via xml or java or if retain
+ * instance is true):
+ *
+ * onAttach
+ * onCreateView
+ * onViewCreated
+ * onActivityCreated
+ * onViewStateRestored
+ * onResume
+ *
+ * Note that the onCreate (and other lifecycle events) are omitted on purpose. The
+ * caveat to this approach is that views, listeners, and resources bound by
+ * Butterknife will be null until onViewStatedRestored. Just be careful not to use any
+ * objects bound using Butterknife before onViewStateRestored.
+ *
+ * Fragments that do not return a non-null View in onCreateView results in onViewCreated
+ * and onViewStateRestored not being called. This means that Butterknife.bind will not get
+ * called, which is completely fine because there is no View to bind. Furthermore, there is
+ * no need to check if getView() returns null here because this lifecycle method only gets
+ * called with a non-null View.
+ */
+ viewUnbinder = ButterKnife.bind(this, view!!)
+ }
+
+ override fun onDestroyView() {
+ // This lifecycle method still gets called even if onCreateView returns a null view.
+ viewUnbinder?.unbind()
+ super.onDestroyView()
+ }
+
+ override fun supportFragmentInjector() = childFragmentInjector
+
+ protected fun addChildFragment(@IdRes containerViewId: Int, fragment: Fragment) =
+ childFragmentManager.beginTransaction()
+ .add(containerViewId, fragment)
+ .commit()
+}
\ No newline at end of file
diff --git a/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseFragmentModule.kt b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseFragmentModule.kt
new file mode 100644
index 0000000..ba0b826
--- /dev/null
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseFragmentModule.kt
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2018 Vandolf Estrellado
+ *
+ * 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.vestrel00.daggerbutterknifemvp.ui.common.view
+
+import android.support.v4.app.Fragment
+import android.support.v4.app.FragmentManager
+import com.vestrel00.daggerbutterknifemvp.inject.PerFragment
+import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseFragmentModule.Companion.FRAGMENT
+import dagger.Module
+import dagger.Provides
+import javax.inject.Named
+
+/**
+ * Provides base fragment dependencies. This must be included in all fragment modules, which must
+ * provide a concrete implementation of [Fragment] and named [FRAGMENT].
+ */
+@Module
+abstract class BaseFragmentModule {
+
+ @Module
+ companion object {
+ const val FRAGMENT = "BaseFragmentModule.fragment"
+
+ /*
+ * Note that this is currently unused in this Kotlin project. However, it is used in the
+ * Java branch of this project. We'll keep this private to avoid lint warnings until other
+ * Kotlin classes needs it.
+ */
+ private const val CHILD_FRAGMENT_MANAGER = "BaseFragmentModule.childFragmentManager"
+
+ /*
+ * This is a valid way to declare static provides methods.
+ * See https://github.com/google/dagger/issues/900#issuecomment-337043187
+ */
+ @JvmStatic
+ @Provides
+ @Named(CHILD_FRAGMENT_MANAGER)
+ @PerFragment
+ fun childFragmentManager(@Named(FRAGMENT) fragment: Fragment): FragmentManager =
+ fragment.childFragmentManager
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseViewFragment.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseViewFragment.kt
similarity index 59%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseViewFragment.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseViewFragment.kt
index 2f08047..d83905d 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseViewFragment.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/view/BaseViewFragment.kt
@@ -14,29 +14,24 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.common.view;
+package com.vestrel00.daggerbutterknifemvp.ui.common.view
-import android.os.Bundle;
-import android.support.annotation.CallSuper;
-
-import com.vestrel00.daggerbutterknifemvp.ui.common.presenter.Presenter;
-
-import javax.inject.Inject;
+import android.os.Bundle
+import com.vestrel00.daggerbutterknifemvp.ui.common.presenter.Presenter
+import javax.inject.Inject
/**
- * A {@link BaseFragment} that contains and invokes {@link Presenter} lifecycle invocations.
+ * A [BaseFragment] that contains and invokes [Presenter] lifecycle invocations.
*
- * @param the type of the {@link Presenter}.
+ * @param [T] the type of the [Presenter].
*/
-public abstract class BaseViewFragment extends BaseFragment
- implements MVPView {
+abstract class BaseViewFragment : BaseFragment(), MVPView {
@Inject
- protected T presenter;
+ protected lateinit var presenter: T
- @Override
- public void onViewStateRestored(Bundle savedInstanceState) {
- super.onViewStateRestored(savedInstanceState);
+ override fun onViewStateRestored(savedInstanceState: Bundle?) {
+ super.onViewStateRestored(savedInstanceState)
/*
* The Presenter.onStart method is called in onViewStateRestored so that the Fragment’s
* views are bound before the presentation begins. This ensures that no NullPointerException
@@ -49,31 +44,26 @@ public void onViewStateRestored(Bundle savedInstanceState) {
* keep things as is since I do not consider it appropriate to have a Presenter-View pair
* in a no-UI Fragment. Do feel free to disagree and refactor.
*/
- presenter.onStart(savedInstanceState);
+ presenter.onStart(savedInstanceState)
}
- @Override
- public void onResume() {
- super.onResume();
- presenter.onResume();
+ override fun onResume() {
+ super.onResume()
+ presenter.onResume()
}
- @Override
- public void onPause() {
- super.onPause();
- presenter.onPause();
+ override fun onPause() {
+ super.onPause()
+ presenter.onPause()
}
- @CallSuper
- @Override
- public void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- presenter.onSaveInstanceState(outState);
+ override fun onSaveInstanceState(outState: Bundle) {
+ super.onSaveInstanceState(outState)
+ presenter.onSaveInstanceState(outState)
}
- @Override
- public void onDestroyView() {
- presenter.onEnd();
- super.onDestroyView();
+ override fun onDestroyView() {
+ presenter.onEnd()
+ super.onDestroyView()
}
-}
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/view/MVPView.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/view/MVPView.kt
similarity index 84%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/view/MVPView.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/view/MVPView.kt
index 92b64f4..adeca2d 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/common/view/MVPView.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/common/view/MVPView.kt
@@ -14,12 +14,11 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.common.view;
+package com.vestrel00.daggerbutterknifemvp.ui.common.view
/**
* The type of all views.
- *
- * Note that this is not named "View" because it collides with Android's {@link android.view.View}.
+ *
+ * Note that this is not named "View" because it collides with Android's [android.view.View].
*/
-public interface MVPView {
-}
+interface MVPView
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/Example1Activity.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/Example1Activity.kt
similarity index 62%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/Example1Activity.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/Example1Activity.kt
index 6ecc3ad..781c16a 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/Example1Activity.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/Example1Activity.kt
@@ -14,27 +14,24 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_1;
+package com.vestrel00.daggerbutterknifemvp.ui.example_1
-import android.os.Bundle;
-import android.support.annotation.Nullable;
-
-import com.vestrel00.daggerbutterknifemvp.R;
-import com.vestrel00.daggerbutterknifemvp.ui.common.BaseActivity;
-import com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.view.Example1Fragment;
+import android.os.Bundle
+import com.vestrel00.daggerbutterknifemvp.R
+import com.vestrel00.daggerbutterknifemvp.ui.common.BaseActivity
+import com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.view.Example1Fragment
/**
* Activity that contains a single Fragment.
*/
-public final class Example1Activity extends BaseActivity {
+class Example1Activity : BaseActivity() {
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.example_1_activity);
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.example_1_activity)
if (savedInstanceState == null) {
- addFragment(R.id.fragment_container, new Example1Fragment());
+ addFragment(R.id.fragment_container, Example1Fragment())
}
}
-}
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/Example1ActivityModule.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/Example1ActivityModule.kt
similarity index 50%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/Example1ActivityModule.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/Example1ActivityModule.kt
index 3036753..45d1550 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/Example1ActivityModule.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/Example1ActivityModule.kt
@@ -14,46 +14,40 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_1;
+package com.vestrel00.daggerbutterknifemvp.ui.example_1
-import android.support.v7.app.AppCompatActivity;
-
-import com.vestrel00.daggerbutterknifemvp.inject.PerActivity;
-import com.vestrel00.daggerbutterknifemvp.inject.PerFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.common.BaseActivityModule;
-import com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.view.Example1Fragment;
-import com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.view.Example1FragmentModule;
-
-import dagger.Binds;
-import dagger.Module;
-import dagger.android.ContributesAndroidInjector;
+import android.support.v7.app.AppCompatActivity
+import com.vestrel00.daggerbutterknifemvp.inject.PerActivity
+import com.vestrel00.daggerbutterknifemvp.inject.PerFragment
+import com.vestrel00.daggerbutterknifemvp.ui.common.BaseActivityModule
+import com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.view.Example1Fragment
+import com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.view.Example1FragmentModule
+import dagger.Binds
+import dagger.Module
+import dagger.android.ContributesAndroidInjector
/**
* Provides example 1 activity dependencies.
*/
-@Module(includes = BaseActivityModule.class)
-public abstract class Example1ActivityModule {
+@Module(includes = [BaseActivityModule::class])
+abstract class Example1ActivityModule {
/**
- * Provides the injector for the {@link Example1Fragment}, which has access to the dependencies
+ * Provides the injector for the [Example1Fragment], which has access to the dependencies
* provided by this activity and application instance (singleton scoped objects).
*/
@PerFragment
- @ContributesAndroidInjector(modules = Example1FragmentModule.class)
- abstract Example1Fragment example1FragmentInjector();
+ @ContributesAndroidInjector(modules = [Example1FragmentModule::class])
+ abstract fun example1FragmentInjector(): Example1Fragment
/**
- * As per the contract specified in {@link BaseActivityModule}; "This must be included in all
- * activity modules, which must provide a concrete implementation of {@link AppCompatActivity}."
- *
- * This provides the activity required to inject the
- * {@link BaseActivityModule#ACTIVITY_FRAGMENT_MANAGER} into the
- * {@link com.vestrel00.daggerbutterknifemvp.ui.common.BaseActivity}.
+ * As per the contract specified in [BaseActivityModule]; "This must be included in all
+ * activity modules, which must provide a concrete implementation of [AppCompatActivity]."
*
* @param example1Activity the example 1 activity
* @return the activity
*/
@Binds
@PerActivity
- abstract AppCompatActivity appCompatActivity(Example1Activity example1Activity);
+ abstract fun appCompatActivity(example1Activity: Example1Activity): AppCompatActivity
}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/presenter/Example1Presenter.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/presenter/Example1Presenter.kt
similarity index 81%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/presenter/Example1Presenter.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/presenter/Example1Presenter.kt
index 7e27220..ac1a9e8 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/presenter/Example1Presenter.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/presenter/Example1Presenter.kt
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.presenter;
+package com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.presenter
-import com.vestrel00.daggerbutterknifemvp.ui.common.presenter.Presenter;
+import com.vestrel00.daggerbutterknifemvp.ui.common.presenter.Presenter
/**
- * A {@link Presenter} that does some work and shows the results.
+ * A [Presenter] that does some work and shows the results.
*/
-public interface Example1Presenter extends Presenter {
+interface Example1Presenter : Presenter {
- void onDoSomething();
-}
+ fun onDoSomething()
+}
\ No newline at end of file
diff --git a/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/presenter/Example1PresenterImpl.kt b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/presenter/Example1PresenterImpl.kt
new file mode 100644
index 0000000..3e2acc6
--- /dev/null
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/presenter/Example1PresenterImpl.kt
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2018 Vandolf Estrellado
+ *
+ * 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.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.presenter
+
+import com.vestrel00.daggerbutterknifemvp.inject.PerFragment
+import com.vestrel00.daggerbutterknifemvp.ui.common.presenter.BasePresenter
+import com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.view.Example1View
+import com.vestrel00.daggerbutterknifemvp.util.PerActivityUtil
+import com.vestrel00.daggerbutterknifemvp.util.PerFragmentUtil
+import com.vestrel00.daggerbutterknifemvp.util.SingletonUtil
+import javax.inject.Inject
+
+/**
+ * An implementation of [Example1Presenter].
+ */
+@PerFragment
+class Example1PresenterImpl @Inject constructor(
+ view: Example1View,
+ private val singletonUtil: SingletonUtil,
+ private val perActivityUtil: PerActivityUtil,
+ private val perFragmentUtil: PerFragmentUtil
+) : BasePresenter(view), Example1Presenter {
+
+ // We can use the delegation pattern here (or inheritance or composition). However, we don't
+ // for the sake of this example and parody with the Java branch.
+ override fun onDoSomething() {
+ // Do something here. Maybe make an asynchronous call to fetch data...
+ // We should refactor and make `something` a val (immutable) instead of a var, which is
+ // better because we should make something immutable if we can. However, we don't for the
+ // sake of this example and parody with the Java branch.
+ var something = singletonUtil.doSomething()
+ something += "\n" + perActivityUtil.doSomething()
+ something += "\n" + perFragmentUtil.doSomething()
+ view.showSomething(something)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/presenter/Example1PresenterModule.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/presenter/Example1PresenterModule.kt
similarity index 74%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/presenter/Example1PresenterModule.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/presenter/Example1PresenterModule.kt
index fb58042..c80a1b1 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/presenter/Example1PresenterModule.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/presenter/Example1PresenterModule.kt
@@ -14,20 +14,19 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.presenter;
+package com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.presenter
-import com.vestrel00.daggerbutterknifemvp.inject.PerFragment;
-
-import dagger.Binds;
-import dagger.Module;
+import com.vestrel00.daggerbutterknifemvp.inject.PerFragment
+import dagger.Binds
+import dagger.Module
/**
* Provides example 1 presenter dependencies.
*/
@Module
-public abstract class Example1PresenterModule {
+abstract class Example1PresenterModule {
@Binds
@PerFragment
- abstract Example1Presenter example1Presenter(Example1PresenterImpl example1PresenterImpl);
-}
+ abstract fun example1Presenter(example1PresenterImpl: Example1PresenterImpl): Example1Presenter
+}
\ No newline at end of file
diff --git a/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/view/Example1Fragment.kt b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/view/Example1Fragment.kt
new file mode 100644
index 0000000..e34d76c
--- /dev/null
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/view/Example1Fragment.kt
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2018 Vandolf Estrellado
+ *
+ * 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.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.view
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.TextView
+import butterknife.BindView
+import butterknife.OnClick
+import com.vestrel00.daggerbutterknifemvp.R
+import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseViewFragment
+import com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.presenter.Example1Presenter
+
+/**
+ * A fragment implementation of [Example1View].
+ */
+class Example1Fragment : BaseViewFragment(), Example1View {
+
+ @BindView(R.id.some_text)
+ lateinit var someText: TextView
+
+ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?): View =
+ inflater.inflate(R.layout.example_1_fragment, container, false)
+
+ override fun showSomething(something: String) {
+ someText.text = something
+ }
+
+ @OnClick(R.id.do_something)
+ fun onDoSomethingClicked() = presenter.onDoSomething()
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/view/Example1FragmentModule.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/view/Example1FragmentModule.kt
similarity index 61%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/view/Example1FragmentModule.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/view/Example1FragmentModule.kt
index dcaab12..ebc776d 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/view/Example1FragmentModule.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/view/Example1FragmentModule.kt
@@ -14,32 +14,29 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.view;
+package com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.view
-import android.support.v4.app.Fragment;
-
-import com.vestrel00.daggerbutterknifemvp.inject.PerFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseFragmentModule;
-import com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.presenter.Example1PresenterModule;
-
-import javax.inject.Named;
-
-import dagger.Binds;
-import dagger.Module;
+import android.support.v4.app.Fragment
+import com.vestrel00.daggerbutterknifemvp.inject.PerFragment
+import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseFragmentModule
+import com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.presenter.Example1PresenterModule
+import dagger.Binds
+import dagger.Module
+import javax.inject.Named
/**
* Provides example 1 fragment dependencies.
*/
-@Module(includes = {
- BaseFragmentModule.class,
- Example1PresenterModule.class
-})
-public abstract class Example1FragmentModule {
+@Module(includes = [
+ BaseFragmentModule::class,
+ Example1PresenterModule::class
+])
+abstract class Example1FragmentModule {
/**
- * As per the contract specified in {@link BaseFragmentModule}; "This must be included in all
- * fragment modules, which must provide a concrete implementation of {@link Fragment}
- * and named {@link BaseFragmentModule#FRAGMENT}.
+ * As per the contract specified in [BaseFragmentModule]; "This must be included in all
+ * fragment modules, which must provide a concrete implementation of [Fragment]
+ * and named [BaseFragmentModule.FRAGMENT].
*
* @param example1Fragment the example 1 fragment
* @return the fragment
@@ -47,9 +44,9 @@ public abstract class Example1FragmentModule {
@Binds
@Named(BaseFragmentModule.FRAGMENT)
@PerFragment
- abstract Fragment fragment(Example1Fragment example1Fragment);
+ abstract fun fragment(example1Fragment: Example1Fragment): Fragment
@Binds
@PerFragment
- abstract Example1View example1View(Example1Fragment example1Fragment);
+ abstract fun example1View(example1Fragment: Example1Fragment): Example1View
}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/view/Example1View.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/view/Example1View.kt
similarity index 88%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/view/Example1View.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/view/Example1View.kt
index 1ecfbe7..bb9287f 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/view/Example1View.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/view/Example1View.kt
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.view;
+package com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.view
-import com.vestrel00.daggerbutterknifemvp.ui.common.view.MVPView;
+import com.vestrel00.daggerbutterknifemvp.ui.common.view.MVPView
/**
* A view that contains a button that does something.
*/
-public interface Example1View extends MVPView {
+interface Example1View : MVPView {
- void showSomething(String something);
-}
+ fun showSomething(something: String)
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/package-info.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/package-info.java
similarity index 100%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/package-info.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_1/package-info.java
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/Example2Activity.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/Example2Activity.kt
similarity index 59%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/Example2Activity.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/Example2Activity.kt
index eec3bf2..2059a78 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/Example2Activity.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/Example2Activity.kt
@@ -14,29 +14,26 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_2;
+package com.vestrel00.daggerbutterknifemvp.ui.example_2
-import android.os.Bundle;
-import android.support.annotation.Nullable;
-
-import com.vestrel00.daggerbutterknifemvp.R;
-import com.vestrel00.daggerbutterknifemvp.ui.common.BaseActivity;
-import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.view.Example2AFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.view.Example2BFragment;
+import android.os.Bundle
+import com.vestrel00.daggerbutterknifemvp.R
+import com.vestrel00.daggerbutterknifemvp.ui.common.BaseActivity
+import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.view.Example2AFragment
+import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.view.Example2BFragment
/**
* Activity that contains 2 Fragments.
*/
-public final class Example2Activity extends BaseActivity {
+class Example2Activity : BaseActivity() {
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.example_2_activity);
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.example_2_activity)
if (savedInstanceState == null) {
- addFragment(R.id.fragment_a_container, new Example2AFragment());
- addFragment(R.id.fragment_b_container, new Example2BFragment());
+ addFragment(R.id.fragment_a_container, Example2AFragment())
+ addFragment(R.id.fragment_b_container, Example2BFragment())
}
}
-}
+}
\ No newline at end of file
diff --git a/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/Example2ActivityModule.kt b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/Example2ActivityModule.kt
new file mode 100644
index 0000000..664a6b4
--- /dev/null
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/Example2ActivityModule.kt
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2018 Vandolf Estrellado
+ *
+ * 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.vestrel00.daggerbutterknifemvp.ui.example_2
+
+import android.support.v7.app.AppCompatActivity
+import com.vestrel00.daggerbutterknifemvp.inject.PerActivity
+import com.vestrel00.daggerbutterknifemvp.inject.PerFragment
+import com.vestrel00.daggerbutterknifemvp.ui.common.BaseActivityModule
+import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.view.Example2AFragment
+import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.view.Example2AFragmentModule
+import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.view.Example2BFragment
+import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.view.Example2BFragmentModule
+import dagger.Binds
+import dagger.Module
+import dagger.android.ContributesAndroidInjector
+
+/**
+ * Provides example 2 activity dependencies.
+ */
+@Module(includes = [BaseActivityModule::class])
+abstract class Example2ActivityModule {
+
+ /**
+ * Provides the injector for the [Example2AFragment], which has access to the dependencies
+ * provided by this activity and application instance (singleton scoped objects).
+ */
+ @PerFragment
+ @ContributesAndroidInjector(modules = [Example2AFragmentModule::class])
+ abstract fun example2AFragmentInjector(): Example2AFragment
+
+ /**
+ * Provides the injector for the [Example2BFragment], which has access to the dependencies
+ * provided by this activity and application instance (singleton scoped objects).
+ */
+ @PerFragment
+ @ContributesAndroidInjector(modules = [Example2BFragmentModule::class])
+ abstract fun example2BFragmentInjector(): Example2BFragment
+
+ /**
+ * As per the contract specified in [BaseActivityModule]; "This must be included in all
+ * activity modules, which must provide a concrete implementation of [AppCompatActivity]."
+ *
+ * @param example2Activity the example 2 activity
+ * @return the activity
+ */
+ @Binds
+ @PerActivity
+ abstract fun appCompatActivity(example2Activity: Example2Activity): AppCompatActivity
+}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/presenter/Example2APresenter.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/presenter/Example2APresenter.kt
similarity index 81%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/presenter/Example2APresenter.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/presenter/Example2APresenter.kt
index 8ac9123..cb5aba9 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/presenter/Example2APresenter.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/presenter/Example2APresenter.kt
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.presenter;
+package com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.presenter
-import com.vestrel00.daggerbutterknifemvp.ui.common.presenter.Presenter;
+import com.vestrel00.daggerbutterknifemvp.ui.common.presenter.Presenter
/**
- * A {@link Presenter} that does some work and shows the results.
+ * A [Presenter] that does some work and shows the results.
*/
-public interface Example2APresenter extends Presenter {
+interface Example2APresenter : Presenter {
- void onDoSomething();
-}
+ fun onDoSomething()
+}
\ No newline at end of file
diff --git a/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/presenter/Example2APresenterImpl.kt b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/presenter/Example2APresenterImpl.kt
new file mode 100644
index 0000000..4cecd3a
--- /dev/null
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/presenter/Example2APresenterImpl.kt
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2018 Vandolf Estrellado
+ *
+ * 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.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.presenter
+
+import com.vestrel00.daggerbutterknifemvp.inject.PerFragment
+import com.vestrel00.daggerbutterknifemvp.ui.common.presenter.BasePresenter
+import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.view.Example2AView
+import com.vestrel00.daggerbutterknifemvp.util.PerActivityUtil
+import com.vestrel00.daggerbutterknifemvp.util.PerFragmentUtil
+import com.vestrel00.daggerbutterknifemvp.util.SingletonUtil
+import javax.inject.Inject
+
+/**
+ * An implementation of [Example2APresenter].
+ */
+@PerFragment
+class Example2APresenterImpl @Inject constructor(
+ view: Example2AView,
+ private val singletonUtil: SingletonUtil,
+ private val perActivityUtil: PerActivityUtil,
+ private val perFragmentUtil: PerFragmentUtil
+) : BasePresenter(view), Example2APresenter {
+
+ // We can use the delegation pattern here (or inheritance or composition). However, we don't
+ // for the sake of this example and parody with the Java branch.
+ override fun onDoSomething() {
+ // Do something here. Maybe make an asynchronous call to fetch data...
+ // We should refactor and make `something` a val (immutable) instead of a var, which is
+ // better because we should make something immutable if we can. However, we don't for the
+ // sake of this example and parody with the Java branch.
+ var something = singletonUtil.doSomething()
+ something += "\n" + perActivityUtil.doSomething()
+ something += "\n" + perFragmentUtil.doSomething()
+ view.showSomething(something)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/presenter/Example2APresenterModule.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/presenter/Example2APresenterModule.kt
similarity index 73%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/presenter/Example2APresenterModule.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/presenter/Example2APresenterModule.kt
index 448c10e..c6737d5 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/presenter/Example2APresenterModule.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/presenter/Example2APresenterModule.kt
@@ -14,21 +14,20 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.presenter;
+package com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.presenter
-import com.vestrel00.daggerbutterknifemvp.inject.PerFragment;
-
-import dagger.Binds;
-import dagger.Module;
+import com.vestrel00.daggerbutterknifemvp.inject.PerFragment
+import dagger.Binds
+import dagger.Module
/**
* Provides example 2 A presenter dependencies.
*/
@Module
-public abstract class Example2APresenterModule {
+abstract class Example2APresenterModule {
@Binds
@PerFragment
- abstract Example2APresenter example2APresenter(Example2APresenterImpl example2APresenterImpl);
-
-}
+ abstract fun example2APresenter(example2APresenterImpl: Example2APresenterImpl):
+ Example2APresenter
+}
\ No newline at end of file
diff --git a/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/view/Example2AFragment.kt b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/view/Example2AFragment.kt
new file mode 100644
index 0000000..bcfa852
--- /dev/null
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/view/Example2AFragment.kt
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2018 Vandolf Estrellado
+ *
+ * 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.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.view
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.TextView
+import butterknife.BindView
+import butterknife.OnClick
+import com.vestrel00.daggerbutterknifemvp.R
+import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseViewFragment
+import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.presenter.Example2APresenter
+
+/**
+ * A fragment implementation of [Example2AView].
+ */
+class Example2AFragment : BaseViewFragment(), Example2AView {
+
+ @BindView(R.id.some_text)
+ lateinit var someText: TextView
+
+ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?): View =
+ inflater.inflate(R.layout.example_2_fragment_a, container, false)
+
+ override fun showSomething(something: String) {
+ someText.text = something
+ }
+
+ @OnClick(R.id.do_something)
+ fun onDoSomethingClicked() = presenter.onDoSomething()
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/view/Example2AFragmentModule.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/view/Example2AFragmentModule.kt
similarity index 61%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/view/Example2AFragmentModule.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/view/Example2AFragmentModule.kt
index 223de5d..4a6d71d 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/view/Example2AFragmentModule.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/view/Example2AFragmentModule.kt
@@ -14,32 +14,29 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.view;
+package com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.view
-import android.support.v4.app.Fragment;
-
-import com.vestrel00.daggerbutterknifemvp.inject.PerFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseFragmentModule;
-import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.presenter.Example2APresenterModule;
-
-import javax.inject.Named;
-
-import dagger.Binds;
-import dagger.Module;
+import android.support.v4.app.Fragment
+import com.vestrel00.daggerbutterknifemvp.inject.PerFragment
+import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseFragmentModule
+import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.presenter.Example2APresenterModule
+import dagger.Binds
+import dagger.Module
+import javax.inject.Named
/**
* Provides example 2 A fragment dependencies.
*/
-@Module(includes = {
- BaseFragmentModule.class,
- Example2APresenterModule.class
-})
-public abstract class Example2AFragmentModule {
+@Module(includes = [
+ BaseFragmentModule::class,
+ Example2APresenterModule::class
+])
+abstract class Example2AFragmentModule {
/**
- * As per the contract specified in {@link BaseFragmentModule}; "This must be included in all
- * fragment modules, which must provide a concrete implementation of {@link Fragment}
- * and named {@link BaseFragmentModule#FRAGMENT}.
+ * As per the contract specified in [BaseFragmentModule]; "This must be included in all
+ * fragment modules, which must provide a concrete implementation of [Fragment]
+ * and named [BaseFragmentModule.FRAGMENT].
*
* @param example2AFragment the example 2 A fragment
* @return the fragment
@@ -47,9 +44,9 @@ public abstract class Example2AFragmentModule {
@Binds
@Named(BaseFragmentModule.FRAGMENT)
@PerFragment
- abstract Fragment fragment(Example2AFragment example2AFragment);
+ abstract fun fragment(example2AFragment: Example2AFragment): Fragment
@Binds
@PerFragment
- abstract Example2AView example2AView(Example2AFragment example2AFragment);
+ abstract fun example2AView(example2AFragment: Example2AFragment): Example2AView
}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/view/Example2BView.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/view/Example2AView.kt
similarity index 88%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/view/Example2BView.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/view/Example2AView.kt
index 3087ec9..af80cb2 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/view/Example2BView.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/view/Example2AView.kt
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.view;
+package com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.view
-import com.vestrel00.daggerbutterknifemvp.ui.common.view.MVPView;
+import com.vestrel00.daggerbutterknifemvp.ui.common.view.MVPView
/**
* A view that contains a button that does something.
*/
-public interface Example2BView extends MVPView {
+interface Example2AView : MVPView {
- void showSomething(String something);
-}
+ fun showSomething(something: String)
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/presenter/Example2BPresenter.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/presenter/Example2BPresenter.kt
similarity index 81%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/presenter/Example2BPresenter.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/presenter/Example2BPresenter.kt
index 8a50d16..0f777dd 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/presenter/Example2BPresenter.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/presenter/Example2BPresenter.kt
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.presenter;
+package com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.presenter
-import com.vestrel00.daggerbutterknifemvp.ui.common.presenter.Presenter;
+import com.vestrel00.daggerbutterknifemvp.ui.common.presenter.Presenter
/**
- * A {@link Presenter} that does some work and shows the results.
+ * A [Presenter] that does some work and shows the results.
*/
-public interface Example2BPresenter extends Presenter {
+interface Example2BPresenter : Presenter {
- void onDoSomething();
-}
+ fun onDoSomething()
+}
\ No newline at end of file
diff --git a/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/presenter/Example2BPresenterImpl.kt b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/presenter/Example2BPresenterImpl.kt
new file mode 100644
index 0000000..092cddf
--- /dev/null
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/presenter/Example2BPresenterImpl.kt
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2018 Vandolf Estrellado
+ *
+ * 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.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.presenter
+
+import com.vestrel00.daggerbutterknifemvp.inject.PerFragment
+import com.vestrel00.daggerbutterknifemvp.ui.common.presenter.BasePresenter
+import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.view.Example2BView
+import com.vestrel00.daggerbutterknifemvp.util.PerActivityUtil
+import com.vestrel00.daggerbutterknifemvp.util.PerFragmentUtil
+import com.vestrel00.daggerbutterknifemvp.util.SingletonUtil
+import javax.inject.Inject
+
+/**
+ * An implementation of [Example2BPresenter].
+ */
+@PerFragment
+class Example2BPresenterImpl @Inject constructor(
+ view: Example2BView,
+ private val singletonUtil: SingletonUtil,
+ private val perActivityUtil: PerActivityUtil,
+ private val perFragmentUtil: PerFragmentUtil
+) : BasePresenter(view), Example2BPresenter {
+
+ // We can use the delegation pattern here (or inheritance or composition). However, we don't
+ // for the sake of this example and parody with the Java branch.
+ override fun onDoSomething() {
+ // Do something here. Maybe make an asynchronous call to fetch data...
+ // We should refactor and make `something` a val (immutable) instead of a var, which is
+ // better because we should make something immutable if we can. However, we don't for the
+ // sake of this example and parody with the Java branch.
+ var something = singletonUtil.doSomething()
+ something += "\n" + perActivityUtil.doSomething()
+ something += "\n" + perFragmentUtil.doSomething()
+ view.showSomething(something)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/presenter/Example2BPresenterModule.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/presenter/Example2BPresenterModule.kt
similarity index 73%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/presenter/Example2BPresenterModule.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/presenter/Example2BPresenterModule.kt
index 16a2a83..1038a4d 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/presenter/Example2BPresenterModule.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/presenter/Example2BPresenterModule.kt
@@ -14,21 +14,20 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.presenter;
+package com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.presenter
-import com.vestrel00.daggerbutterknifemvp.inject.PerFragment;
-
-import dagger.Binds;
-import dagger.Module;
+import com.vestrel00.daggerbutterknifemvp.inject.PerFragment
+import dagger.Binds
+import dagger.Module
/**
* Provides example 2 B presenter dependencies.
*/
@Module
-public abstract class Example2BPresenterModule {
+abstract class Example2BPresenterModule {
@Binds
@PerFragment
- abstract Example2BPresenter example2BPresenter(Example2BPresenterImpl example2BPresenterImpl);
-
-}
+ abstract fun example2BPresenter(example2BPresenterImpl: Example2BPresenterImpl):
+ Example2BPresenter
+}
\ No newline at end of file
diff --git a/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/view/Example2BFragment.kt b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/view/Example2BFragment.kt
new file mode 100644
index 0000000..5ecf221
--- /dev/null
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/view/Example2BFragment.kt
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2018 Vandolf Estrellado
+ *
+ * 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.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.view
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.TextView
+import butterknife.BindView
+import butterknife.OnClick
+import com.vestrel00.daggerbutterknifemvp.R
+import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseViewFragment
+import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.presenter.Example2BPresenter
+
+/**
+ * A fragment implementation of [Example2BView].
+ */
+class Example2BFragment : BaseViewFragment(), Example2BView {
+
+ @BindView(R.id.some_text)
+ lateinit var someText: TextView
+
+ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?): View =
+ inflater.inflate(R.layout.example_2_fragment_b, container, false)
+
+ override fun showSomething(something: String) {
+ someText.text = something
+ }
+
+ @OnClick(R.id.do_something)
+ fun onDoSomethingClicked() = presenter.onDoSomething()
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/view/Example2BFragmentModule.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/view/Example2BFragmentModule.kt
similarity index 61%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/view/Example2BFragmentModule.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/view/Example2BFragmentModule.kt
index 5f02977..03dc835 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/view/Example2BFragmentModule.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/view/Example2BFragmentModule.kt
@@ -14,32 +14,29 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.view;
+package com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.view
-import android.support.v4.app.Fragment;
-
-import com.vestrel00.daggerbutterknifemvp.inject.PerFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseFragmentModule;
-import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.presenter.Example2BPresenterModule;
-
-import javax.inject.Named;
-
-import dagger.Binds;
-import dagger.Module;
+import android.support.v4.app.Fragment
+import com.vestrel00.daggerbutterknifemvp.inject.PerFragment
+import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseFragmentModule
+import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.presenter.Example2BPresenterModule
+import dagger.Binds
+import dagger.Module
+import javax.inject.Named
/**
* Provides example 2 B fragment dependencies.
*/
-@Module(includes = {
- BaseFragmentModule.class,
- Example2BPresenterModule.class
-})
-public abstract class Example2BFragmentModule {
+@Module(includes = [
+ BaseFragmentModule::class,
+ Example2BPresenterModule::class
+])
+abstract class Example2BFragmentModule {
/**
- * As per the contract specified in {@link BaseFragmentModule}; "This must be included in all
- * fragment modules, which must provide a concrete implementation of {@link Fragment}
- * and named {@link BaseFragmentModule#FRAGMENT}.
+ * As per the contract specified in [BaseFragmentModule]; "This must be included in all
+ * fragment modules, which must provide a concrete implementation of [Fragment]
+ * and named [BaseFragmentModule.FRAGMENT].
*
* @param example2BFragment the example 2 B fragment
* @return the fragment
@@ -47,9 +44,9 @@ public abstract class Example2BFragmentModule {
@Binds
@Named(BaseFragmentModule.FRAGMENT)
@PerFragment
- abstract Fragment fragment(Example2BFragment example2BFragment);
+ abstract fun fragment(example2BFragment: Example2BFragment): Fragment
@Binds
@PerFragment
- abstract Example2BView example2BView(Example2BFragment example2BFragment);
+ abstract fun example2BView(example2BFragment: Example2BFragment): Example2BView
}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/view/Example2AView.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/view/Example2BView.kt
similarity index 88%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/view/Example2AView.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/view/Example2BView.kt
index 5e269f8..fd1b7d6 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/view/Example2AView.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_b/view/Example2BView.kt
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.view;
+package com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.view
-import com.vestrel00.daggerbutterknifemvp.ui.common.view.MVPView;
+import com.vestrel00.daggerbutterknifemvp.ui.common.view.MVPView
/**
* A view that contains a button that does something.
*/
-public interface Example2AView extends MVPView {
+interface Example2BView : MVPView {
- void showSomething(String something);
-}
+ fun showSomething(something: String)
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/package-info.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/package-info.java
similarity index 100%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/package-info.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_2/package-info.java
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/Example3Activity.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/Example3Activity.kt
similarity index 62%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/Example3Activity.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/Example3Activity.kt
index b18f978..35bf044 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/Example3Activity.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/Example3Activity.kt
@@ -14,27 +14,24 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_3;
+package com.vestrel00.daggerbutterknifemvp.ui.example_3
-import android.os.Bundle;
-import android.support.annotation.Nullable;
-
-import com.vestrel00.daggerbutterknifemvp.R;
-import com.vestrel00.daggerbutterknifemvp.ui.common.BaseActivity;
-import com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.view.Example3ParentFragment;
+import android.os.Bundle
+import com.vestrel00.daggerbutterknifemvp.R
+import com.vestrel00.daggerbutterknifemvp.ui.common.BaseActivity
+import com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.view.Example3ParentFragment
/**
* Activity that contains a single fragment that contains a child fragment.
*/
-public final class Example3Activity extends BaseActivity {
+class Example3Activity : BaseActivity() {
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.example_3_activity);
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.example_3_activity)
if (savedInstanceState == null) {
- addFragment(R.id.parent_fragment_container, new Example3ParentFragment());
+ addFragment(R.id.parent_fragment_container, Example3ParentFragment())
}
}
-}
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/Example3ActivityModule.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/Example3ActivityModule.kt
similarity index 50%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/Example3ActivityModule.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/Example3ActivityModule.kt
index bd46325..8d1a59f 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/Example3ActivityModule.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/Example3ActivityModule.kt
@@ -14,46 +14,40 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_3;
+package com.vestrel00.daggerbutterknifemvp.ui.example_3
-import android.support.v7.app.AppCompatActivity;
-
-import com.vestrel00.daggerbutterknifemvp.inject.PerActivity;
-import com.vestrel00.daggerbutterknifemvp.inject.PerFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.common.BaseActivityModule;
-import com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.view.Example3ParentFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.view.Example3ParentFragmentModule;
-
-import dagger.Binds;
-import dagger.Module;
-import dagger.android.ContributesAndroidInjector;
+import android.support.v7.app.AppCompatActivity
+import com.vestrel00.daggerbutterknifemvp.inject.PerActivity
+import com.vestrel00.daggerbutterknifemvp.inject.PerFragment
+import com.vestrel00.daggerbutterknifemvp.ui.common.BaseActivityModule
+import com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.view.Example3ParentFragment
+import com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.view.Example3ParentFragmentModule
+import dagger.Binds
+import dagger.Module
+import dagger.android.ContributesAndroidInjector
/**
* Provides example 3 activity dependencies.
*/
-@Module(includes = BaseActivityModule.class)
-public abstract class Example3ActivityModule {
+@Module(includes = [BaseActivityModule::class])
+abstract class Example3ActivityModule {
/**
- * Provides the injector for the {@link Example3ParentFragment}, which has access to the
+ * Provides the injector for the [Example3ParentFragment], which has access to the
* dependencies provided by this activity and application instance (singleton scoped objects).
*/
@PerFragment
- @ContributesAndroidInjector(modules = Example3ParentFragmentModule.class)
- abstract Example3ParentFragment example3ParentFragmentInjector();
+ @ContributesAndroidInjector(modules = [Example3ParentFragmentModule::class])
+ abstract fun example3ParentFragmentInjector(): Example3ParentFragment
/**
- * As per the contract specified in {@link BaseActivityModule}; "This must be included in all
- * activity modules, which must provide a concrete implementation of {@link AppCompatActivity}."
- *
- * This provides the activity required to inject the
- * {@link BaseActivityModule#ACTIVITY_FRAGMENT_MANAGER} into the
- * {@link com.vestrel00.daggerbutterknifemvp.ui.common.BaseActivity}.
+ * As per the contract specified in [BaseActivityModule]; "This must be included in all
+ * activity modules, which must provide a concrete implementation of [AppCompatActivity]."
*
* @param example3Activity the example 3 activity
* @return the activity
*/
@Binds
@PerActivity
- abstract AppCompatActivity appCompatActivity(Example3Activity example3Activity);
+ abstract fun appCompatActivity(example3Activity: Example3Activity): AppCompatActivity
}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/presenter/Example3ChildPresenter.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/presenter/Example3ChildPresenter.kt
similarity index 80%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/presenter/Example3ChildPresenter.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/presenter/Example3ChildPresenter.kt
index b332e4b..b3b70d9 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/presenter/Example3ChildPresenter.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/presenter/Example3ChildPresenter.kt
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.presenter;
+package com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.presenter
-import com.vestrel00.daggerbutterknifemvp.ui.common.presenter.Presenter;
+import com.vestrel00.daggerbutterknifemvp.ui.common.presenter.Presenter
/**
- * A {@link Presenter} that does some work and shows the results.
+ * A [Presenter] that does some work and shows the results.
*/
-public interface Example3ChildPresenter extends Presenter {
+interface Example3ChildPresenter : Presenter {
- void onDoSomething();
-}
+ fun onDoSomething()
+}
\ No newline at end of file
diff --git a/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/presenter/Example3ChildPresenterImpl.kt b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/presenter/Example3ChildPresenterImpl.kt
new file mode 100644
index 0000000..0eca722
--- /dev/null
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/presenter/Example3ChildPresenterImpl.kt
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2018 Vandolf Estrellado
+ *
+ * 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.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.presenter
+
+import com.vestrel00.daggerbutterknifemvp.inject.PerChildFragment
+import com.vestrel00.daggerbutterknifemvp.ui.common.presenter.BasePresenter
+import com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.view.Example3ChildView
+import com.vestrel00.daggerbutterknifemvp.util.PerActivityUtil
+import com.vestrel00.daggerbutterknifemvp.util.PerChildFragmentUtil
+import com.vestrel00.daggerbutterknifemvp.util.PerFragmentUtil
+import com.vestrel00.daggerbutterknifemvp.util.SingletonUtil
+import javax.inject.Inject
+
+@PerChildFragment
+class Example3ChildPresenterImpl @Inject constructor(
+ view: Example3ChildView,
+ private val singletonUtil: SingletonUtil,
+ private val perActivityUtil: PerActivityUtil,
+ private val perFragmentUtil: PerFragmentUtil,
+ private val perChildFragmentUtil: PerChildFragmentUtil
+) : BasePresenter(view), Example3ChildPresenter {
+
+ // We can use the delegation pattern here (or inheritance or composition). However, we don't
+ // for the sake of this example and parody with the Java branch.
+ override fun onDoSomething() {
+ // Do something here. Maybe make an asynchronous call to fetch data...
+ // We should refactor and make `something` a val (immutable) instead of a var, which is
+ // better because we should make something immutable if we can. However, we don't for the
+ // sake of this example and parody with the Java branch.
+ var something = singletonUtil.doSomething()
+ something += "\n" + perActivityUtil.doSomething()
+ something += "\n" + perFragmentUtil.doSomething()
+ something += "\n" + perChildFragmentUtil.doSomething()
+ view.showSomething(something)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/presenter/Example3ChildPresenterModule.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/presenter/Example3ChildPresenterModule.kt
similarity index 77%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/presenter/Example3ChildPresenterModule.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/presenter/Example3ChildPresenterModule.kt
index 3dc2389..d8a826d 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/presenter/Example3ChildPresenterModule.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/presenter/Example3ChildPresenterModule.kt
@@ -14,21 +14,20 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.presenter;
+package com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.presenter
-import com.vestrel00.daggerbutterknifemvp.inject.PerChildFragment;
-
-import dagger.Binds;
-import dagger.Module;
+import com.vestrel00.daggerbutterknifemvp.inject.PerChildFragment
+import dagger.Binds
+import dagger.Module
/**
* Provides example 3 child presenter dependencies.
*/
@Module
-public abstract class Example3ChildPresenterModule {
+abstract class Example3ChildPresenterModule {
@Binds
@PerChildFragment
- abstract Example3ChildPresenter
- example3ChildPresenter(Example3ChildPresenterImpl example3ChildPresenterImpl);
-}
+ abstract fun example3ChildPresenter(example3ChildPresenterImpl: Example3ChildPresenterImpl):
+ Example3ChildPresenter
+}
\ No newline at end of file
diff --git a/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/view/Example3ChildFragment.kt b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/view/Example3ChildFragment.kt
new file mode 100644
index 0000000..770df1e
--- /dev/null
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/view/Example3ChildFragment.kt
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2018 Vandolf Estrellado
+ *
+ * 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.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.view
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.TextView
+import butterknife.BindView
+import butterknife.OnClick
+import com.vestrel00.daggerbutterknifemvp.R
+import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseViewFragment
+import com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.presenter.Example3ChildPresenter
+
+/**
+ * A fragment implementation of [Example3ChildView].
+ */
+class Example3ChildFragment : BaseViewFragment(), Example3ChildView {
+
+ @BindView(R.id.some_text)
+ lateinit var someText: TextView
+
+ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?): View =
+ inflater.inflate(R.layout.example_3_child_fragment, container, false)
+
+ override fun showSomething(something: String) {
+ someText.text = something
+ }
+
+ @OnClick(R.id.do_something)
+ fun onDoSomethingClicked() = presenter.onDoSomething()
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/view/Example3ChildFragmentModule.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/view/Example3ChildFragmentModule.kt
similarity index 63%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/view/Example3ChildFragmentModule.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/view/Example3ChildFragmentModule.kt
index acd1a43..31a2cf8 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/view/Example3ChildFragmentModule.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/view/Example3ChildFragmentModule.kt
@@ -14,32 +14,29 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.view;
+package com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.view
-import android.support.v4.app.Fragment;
-
-import com.vestrel00.daggerbutterknifemvp.inject.PerChildFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseChildFragmentModule;
-import com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.presenter.Example3ChildPresenterModule;
-
-import javax.inject.Named;
-
-import dagger.Binds;
-import dagger.Module;
+import android.support.v4.app.Fragment
+import com.vestrel00.daggerbutterknifemvp.inject.PerChildFragment
+import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseChildFragmentModule
+import com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.presenter.Example3ChildPresenterModule
+import dagger.Binds
+import dagger.Module
+import javax.inject.Named
/**
* Provides example 3 child fragment dependencies.
*/
-@Module(includes = {
- BaseChildFragmentModule.class,
- Example3ChildPresenterModule.class
-})
-public abstract class Example3ChildFragmentModule {
+@Module(includes = [
+ BaseChildFragmentModule::class,
+ Example3ChildPresenterModule::class
+])
+abstract class Example3ChildFragmentModule {
/**
- * As per the contract specified in {@link BaseChildFragmentModule}; "This must be included in
+ * As per the contract specified in [BaseChildFragmentModule]; "This must be included in
* all child fragment modules, which must provide a concrete implementation of the child
- * {@link Fragment} and named {@link BaseChildFragmentModule#CHILD_FRAGMENT}..
+ * [Fragment] and named [BaseChildFragmentModule.CHILD_FRAGMENT].
*
* @param example3ChildFragment the example 3 child fragment
* @return the fragment
@@ -47,9 +44,9 @@ public abstract class Example3ChildFragmentModule {
@Binds
@Named(BaseChildFragmentModule.CHILD_FRAGMENT)
@PerChildFragment
- abstract Fragment fragment(Example3ChildFragment example3ChildFragment);
+ abstract fun fragment(example3ChildFragment: Example3ChildFragment): Fragment
@Binds
@PerChildFragment
- abstract Example3ChildView example3ChildView(Example3ChildFragment example3ChildFragment);
+ abstract fun example3ChildView(example3ChildFragment: Example3ChildFragment): Example3ChildView
}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/view/Example3ChildView.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/view/Example3ChildView.kt
similarity index 87%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/view/Example3ChildView.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/view/Example3ChildView.kt
index 22ea24d..eb34d58 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/view/Example3ChildView.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/view/Example3ChildView.kt
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.view;
+package com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.view
-import com.vestrel00.daggerbutterknifemvp.ui.common.view.MVPView;
+import com.vestrel00.daggerbutterknifemvp.ui.common.view.MVPView
/**
* A view that contains a button that does something.
*/
-public interface Example3ChildView extends MVPView {
+interface Example3ChildView : MVPView {
- void showSomething(String something);
-}
+ fun showSomething(something: String)
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/package-info.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/package-info.java
similarity index 100%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/package-info.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/package-info.java
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/presenter/Example3ParentPresenter.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/presenter/Example3ParentPresenter.kt
similarity index 79%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/presenter/Example3ParentPresenter.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/presenter/Example3ParentPresenter.kt
index 1a171f0..11c5e99 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/presenter/Example3ParentPresenter.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/presenter/Example3ParentPresenter.kt
@@ -14,14 +14,11 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.presenter;
+package com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.presenter
-import com.vestrel00.daggerbutterknifemvp.ui.common.presenter.Presenter;
+import com.vestrel00.daggerbutterknifemvp.ui.common.presenter.Presenter
-/**
- * A {@link Presenter} that does some work and shows the results.
- */
-public interface Example3ParentPresenter extends Presenter {
+interface Example3ParentPresenter : Presenter {
- void onDoSomething();
-}
+ fun onDoSomething()
+}
\ No newline at end of file
diff --git a/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/presenter/Example3ParentPresenterImpl.kt b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/presenter/Example3ParentPresenterImpl.kt
new file mode 100644
index 0000000..7aaeaee
--- /dev/null
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/presenter/Example3ParentPresenterImpl.kt
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2018 Vandolf Estrellado
+ *
+ * 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.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.presenter
+
+import com.vestrel00.daggerbutterknifemvp.inject.PerFragment
+import com.vestrel00.daggerbutterknifemvp.ui.common.presenter.BasePresenter
+import com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.view.Example3ParentView
+import com.vestrel00.daggerbutterknifemvp.util.PerActivityUtil
+import com.vestrel00.daggerbutterknifemvp.util.PerFragmentUtil
+import com.vestrel00.daggerbutterknifemvp.util.SingletonUtil
+import javax.inject.Inject
+
+/**
+ * An implementation of [Example3ParentPresenter].
+ */
+@PerFragment
+class Example3ParentPresenterImpl @Inject constructor(
+ view: Example3ParentView,
+ private val singletonUtil: SingletonUtil,
+ private val perActivityUtil: PerActivityUtil,
+ private val perFragmentUtil: PerFragmentUtil
+) : BasePresenter(view), Example3ParentPresenter {
+
+ // We can use the delegation pattern here (or inheritance or composition). However, we don't
+ // for the sake of this example and parody with the Java branch.
+ override fun onDoSomething() {
+ // Do something here. Maybe make an asynchronous call to fetch data...
+ // We should refactor and make `something` a val (immutable) instead of a var, which is
+ // better because we should make something immutable if we can. However, we don't for the
+ // sake of this example and parody with the Java branch.
+ var something = singletonUtil.doSomething()
+ something += "\n" + perActivityUtil.doSomething()
+ something += "\n" + perFragmentUtil.doSomething()
+ view.showSomething(something)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/presenter/Example3ParentPresenterModule.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/presenter/Example3ParentPresenterModule.kt
similarity index 71%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/presenter/Example3ParentPresenterModule.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/presenter/Example3ParentPresenterModule.kt
index b5bf374..314a25d 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/presenter/Example3ParentPresenterModule.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/presenter/Example3ParentPresenterModule.kt
@@ -14,21 +14,20 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.presenter;
+package com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.presenter
-import com.vestrel00.daggerbutterknifemvp.inject.PerFragment;
-
-import dagger.Binds;
-import dagger.Module;
+import com.vestrel00.daggerbutterknifemvp.inject.PerFragment
+import dagger.Binds
+import dagger.Module
/**
* Provides example 3 parent presenter dependencies.
*/
@Module
-public abstract class Example3ParentPresenterModule {
+abstract class Example3ParentPresenterModule {
@Binds
@PerFragment
- abstract Example3ParentPresenter
- example3ParentPresenter(Example3ParentPresenterImpl example3ParentPresenterImpl);
-}
+ abstract fun example3ParentPresenter(example3ParentPresenterImpl: Example3ParentPresenterImpl):
+ Example3ParentPresenter
+}
\ No newline at end of file
diff --git a/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/view/Example3ParentFragment.kt b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/view/Example3ParentFragment.kt
new file mode 100644
index 0000000..ae5b281
--- /dev/null
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/view/Example3ParentFragment.kt
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2018 Vandolf Estrellado
+ *
+ * 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.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.view
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.TextView
+import butterknife.BindView
+import butterknife.OnClick
+import com.vestrel00.daggerbutterknifemvp.R
+import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseViewFragment
+import com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.view.Example3ChildFragment
+import com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.presenter.Example3ParentPresenter
+
+/**
+ * A fragment implementation of [Example3ParentView].
+ */
+class Example3ParentFragment : BaseViewFragment(), Example3ParentView {
+
+ @BindView(R.id.some_text)
+ lateinit var someText: TextView
+
+ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?): View =
+ inflater.inflate(R.layout.example_3_parent_fragment, container, false)
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+ if (savedInstanceState == null) {
+ addChildFragment(R.id.child_fragment_container, Example3ChildFragment())
+ }
+ }
+
+ override fun showSomething(something: String) {
+ someText.text = something
+ }
+
+ @OnClick(R.id.do_something)
+ fun onDoSomethingClicked() = presenter.onDoSomething()
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/view/Example3ParentFragmentModule.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/view/Example3ParentFragmentModule.kt
similarity index 57%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/view/Example3ParentFragmentModule.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/view/Example3ParentFragmentModule.kt
index a8f6567..12ecd56 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/view/Example3ParentFragmentModule.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/view/Example3ParentFragmentModule.kt
@@ -14,45 +14,42 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.view;
+package com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.view
-import android.support.v4.app.Fragment;
-
-import com.vestrel00.daggerbutterknifemvp.inject.PerChildFragment;
-import com.vestrel00.daggerbutterknifemvp.inject.PerFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseFragmentModule;
-import com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.view.Example3ChildFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.view.Example3ChildFragmentModule;
-import com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.presenter.Example3ParentPresenterModule;
-
-import javax.inject.Named;
-
-import dagger.Binds;
-import dagger.Module;
-import dagger.android.ContributesAndroidInjector;
+import android.support.v4.app.Fragment
+import com.vestrel00.daggerbutterknifemvp.inject.PerChildFragment
+import com.vestrel00.daggerbutterknifemvp.inject.PerFragment
+import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseFragmentModule
+import com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.view.Example3ChildFragment
+import com.vestrel00.daggerbutterknifemvp.ui.example_3.child_fragment.view.Example3ChildFragmentModule
+import com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.presenter.Example3ParentPresenterModule
+import dagger.Binds
+import dagger.Module
+import dagger.android.ContributesAndroidInjector
+import javax.inject.Named
/**
* Provides example 3 parent fragment dependencies.
*/
-@Module(includes = {
- BaseFragmentModule.class,
- Example3ParentPresenterModule.class
-})
-public abstract class Example3ParentFragmentModule {
+@Module(includes = [
+ BaseFragmentModule::class,
+ Example3ParentPresenterModule::class
+])
+abstract class Example3ParentFragmentModule {
/**
- * Provides the injector for the {@link Example3ChildFragment}, which has access to the
+ * Provides the injector for the [Example3ChildFragment], which has access to the
* dependencies provided by this fragment and activity and application instance
* (singleton scoped objects).
*/
@PerChildFragment
- @ContributesAndroidInjector(modules = Example3ChildFragmentModule.class)
- abstract Example3ChildFragment example3ChildFragmentInjector();
+ @ContributesAndroidInjector(modules = [Example3ChildFragmentModule::class])
+ abstract fun example3ChildFragmentInjector(): Example3ChildFragment
/**
- * As per the contract specified in {@link BaseFragmentModule}; "This must be included in all
- * fragment modules, which must provide a concrete implementation of {@link Fragment}
- * and named {@link BaseFragmentModule#FRAGMENT}.
+ * As per the contract specified in [BaseFragmentModule]; "This must be included in all
+ * fragment modules, which must provide a concrete implementation of [Fragment]
+ * and named [BaseFragmentModule.FRAGMENT].
*
* @param example3ParentFragment the example 3 parent fragment
* @return the fragment
@@ -60,9 +57,10 @@ public abstract class Example3ParentFragmentModule {
@Binds
@Named(BaseFragmentModule.FRAGMENT)
@PerFragment
- abstract Fragment fragment(Example3ParentFragment example3ParentFragment);
+ abstract fun fragment(example3ParentFragment: Example3ParentFragment): Fragment
@Binds
@PerFragment
- abstract Example3ParentView example3ParentView(Example3ParentFragment example3ParentFragment);
+ abstract fun example3ParentView(example3ParentFragment: Example3ParentFragment):
+ Example3ParentView
}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/view/Example3ParentView.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/view/Example3ParentView.kt
similarity index 87%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/view/Example3ParentView.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/view/Example3ParentView.kt
index b6bfb27..8b1ed75 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/view/Example3ParentView.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/example_3/parent_fragment/view/Example3ParentView.kt
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.view;
+package com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.view
-import com.vestrel00.daggerbutterknifemvp.ui.common.view.MVPView;
+import com.vestrel00.daggerbutterknifemvp.ui.common.view.MVPView
/**
* A view that contains a button that does something.
*/
-public interface Example3ParentView extends MVPView {
+interface Example3ParentView : MVPView {
- void showSomething(String something);
-}
+ fun showSomething(something: String)
+}
\ No newline at end of file
diff --git a/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/main/MainActivity.kt b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/main/MainActivity.kt
new file mode 100644
index 0000000..2323611
--- /dev/null
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/main/MainActivity.kt
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2018 Vandolf Estrellado
+ *
+ * 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.vestrel00.daggerbutterknifemvp.ui.main
+
+import android.os.Bundle
+import com.vestrel00.daggerbutterknifemvp.R
+import com.vestrel00.daggerbutterknifemvp.ui.common.BaseActivity
+import com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.view.Example1Fragment
+import com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.view.Example3ParentFragment
+import com.vestrel00.daggerbutterknifemvp.ui.main.view.MainFragment
+import com.vestrel00.daggerbutterknifemvp.ui.main.view.MainFragmentListener
+
+/**
+ * The main activity that provides a way to navigate to all other activities.
+ */
+class MainActivity : BaseActivity(), MainFragmentListener {
+
+ companion object {
+ private const val TAG_EXAMPLE_4 = "MainActivity.example_4"
+ private const val TAG_EXAMPLE_5 = "MainActivity.example_5"
+ }
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.main_activity)
+
+ if (savedInstanceState == null) {
+ addFragment(R.id.fragment_container, MainFragment())
+ }
+ }
+
+ override fun onExample1Clicked() = navigator.toExample1(this)
+
+ override fun onExample2Clicked() = navigator.toExample2(this)
+
+ override fun onExample3Clicked() = navigator.toExample3(this)
+
+ override fun onExample4Clicked() = showDialogFragment(Example1Fragment(), TAG_EXAMPLE_4)
+
+ override fun onExample5Clicked() = showDialogFragment(Example3ParentFragment(), TAG_EXAMPLE_5)
+}
\ No newline at end of file
diff --git a/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/main/MainActivityModule.kt b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/main/MainActivityModule.kt
new file mode 100644
index 0000000..addb6c2
--- /dev/null
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/main/MainActivityModule.kt
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2018 Vandolf Estrellado
+ *
+ * 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.vestrel00.daggerbutterknifemvp.ui.main
+
+import android.support.v7.app.AppCompatActivity
+import com.vestrel00.daggerbutterknifemvp.inject.PerActivity
+import com.vestrel00.daggerbutterknifemvp.inject.PerFragment
+import com.vestrel00.daggerbutterknifemvp.ui.common.BaseActivityModule
+import com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.view.Example1Fragment
+import com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.view.Example1FragmentModule
+import com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.view.Example3ParentFragment
+import com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.view.Example3ParentFragmentModule
+import com.vestrel00.daggerbutterknifemvp.ui.main.view.MainFragment
+import com.vestrel00.daggerbutterknifemvp.ui.main.view.MainFragmentListener
+import com.vestrel00.daggerbutterknifemvp.ui.main.view.MainFragmentModule
+import dagger.Binds
+import dagger.Module
+import dagger.android.ContributesAndroidInjector
+
+/**
+ * Provides main activity dependencies.
+ */
+@Module(includes = [BaseActivityModule::class])
+abstract class MainActivityModule {
+
+ /**
+ * Provides the injector for the [MainFragment], which has access to the dependencies
+ * provided by this activity and application instance (singleton scoped objects).
+ */
+ @PerFragment
+ @ContributesAndroidInjector(modules = [MainFragmentModule::class])
+ abstract fun mainFragmentInjector(): MainFragment
+
+ /**
+ * Provides the injector for the [Example1Fragment], which has access to the dependencies
+ * provided by this activity and application instance (singleton scoped objects).
+ *
+ * This is used for example 4, which displays [Example1Fragment] as a
+ * [android.app.DialogFragment].
+ */
+ @PerFragment
+ @ContributesAndroidInjector(modules = [Example1FragmentModule::class])
+ abstract fun example1FragmentInjector(): Example1Fragment
+
+ /**
+ * Provides the injector for the [Example3ParentFragment], which has access to the
+ * dependencies provided by this activity and application instance (singleton scoped objects).
+ *
+ * This is used for example 5, which displays [Example3ParentFragment] as a
+ * [android.app.DialogFragment].
+ */
+ @PerFragment
+ @ContributesAndroidInjector(modules = [Example3ParentFragmentModule::class])
+ abstract fun example3ParentFragmentInjector(): Example3ParentFragment
+
+ /**
+ * As per the contract specified in [BaseActivityModule]; "This must be included in all
+ * activity modules, which must provide a concrete implementation of [AppCompatActivity]."
+ *
+ * @param mainActivity the activity
+ * @return the activity
+ */
+ @Binds
+ @PerActivity
+ abstract fun appCompatActivity(mainActivity: MainActivity): AppCompatActivity
+
+ /**
+ * The main activity listens to the events in the [MainFragment].
+ *
+ * @param mainActivity the activity
+ * @return the main fragment listener
+ */
+ @Binds
+ @PerActivity
+ abstract fun mainFragmentListener(mainActivity: MainActivity): MainFragmentListener
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/package-info.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/main/package-info.java
similarity index 100%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/package-info.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/main/package-info.java
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/view/MainFragment.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/main/view/MainFragment.kt
similarity index 59%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/view/MainFragment.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/main/view/MainFragment.kt
index e34995e..5114728 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/view/MainFragment.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/main/view/MainFragment.kt
@@ -14,72 +14,57 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.main.view;
+package com.vestrel00.daggerbutterknifemvp.ui.main.view
-import android.os.Bundle;
-import android.support.annotation.Nullable;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-
-import com.vestrel00.daggerbutterknifemvp.R;
-import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseFragment;
-
-import javax.inject.Inject;
-
-import butterknife.OnClick;
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import butterknife.OnClick
+import com.vestrel00.daggerbutterknifemvp.R
+import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseFragment
+import javax.inject.Inject
/**
* Displays a set of buttons for the other activities.
- *
- * NOTE
+ *
+ * **NOTE**
+ *
* This fragment does not implement a view and host a presenter because there is no logic that
* is done here. This fragment simply notifies the host Activity of the button click events that
* occur.
- *
+ *
* With that said, this does not implement and MVPView interface nor does it extend
* BaseViewFragment.
- *
+ *
* So why not just put the layout of this fragment into the Activity itself? We could do that but
* we would lose the ability to reuse this fragment along with other fragments in different
* activities if we wanted to (not that we would).
- *
+ *
* The activity only acts as the host to 1 or more fragments for inter-fragment communication. All
* views and logic are in fragments.
*/
-public final class MainFragment extends BaseFragment {
+class MainFragment : BaseFragment() {
@Inject
- MainFragmentListener listener;
+ lateinit var listener: MainFragmentListener
- @Override
- public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
- Bundle savedInstanceState) {
- return inflater.inflate(R.layout.main_fragment, container, false);
- }
+ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?): View =
+ inflater.inflate(R.layout.main_fragment, container, false)
@OnClick(R.id.example_1)
- void onExample1Clicked() {
- listener.onExample1Clicked();
- }
+ fun onExample1Clicked() = listener.onExample1Clicked()
@OnClick(R.id.example_2)
- void onExample2Clicked() {
- listener.onExample2Clicked();
- }
+ fun onExample2Clicked() = listener.onExample2Clicked()
@OnClick(R.id.example_3)
- void onExample3Clicked() {
- listener.onExample3Clicked();
- }
+ fun onExample3Clicked() = listener.onExample3Clicked()
@OnClick(R.id.example_4)
- void onExample4Clicked() {
- listener.onExample4Clicked();
- }
+ fun onExample4Clicked() = listener.onExample4Clicked()
@OnClick(R.id.example_5)
- void onExample5Clicked() {
- listener.onExample5Clicked();
- }
-}
+ fun onExample5Clicked() = listener.onExample5Clicked()
+}
\ No newline at end of file
diff --git a/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/main/view/MainFragmentListener.kt b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/main/view/MainFragmentListener.kt
new file mode 100644
index 0000000..8fabd9a
--- /dev/null
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/main/view/MainFragmentListener.kt
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2018 Vandolf Estrellado
+ *
+ * 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.vestrel00.daggerbutterknifemvp.ui.main.view
+
+interface MainFragmentListener {
+
+ fun onExample1Clicked()
+
+ fun onExample2Clicked()
+
+ fun onExample3Clicked()
+
+ fun onExample4Clicked()
+
+ fun onExample5Clicked()
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/view/MainFragmentModule.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/main/view/MainFragmentModule.kt
similarity index 62%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/view/MainFragmentModule.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/main/view/MainFragmentModule.kt
index 08675ff..d8f76e8 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/main/view/MainFragmentModule.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/main/view/MainFragmentModule.kt
@@ -14,28 +14,25 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.ui.main.view;
+package com.vestrel00.daggerbutterknifemvp.ui.main.view
-import android.support.v4.app.Fragment;
-
-import com.vestrel00.daggerbutterknifemvp.inject.PerFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseFragmentModule;
-
-import javax.inject.Named;
-
-import dagger.Binds;
-import dagger.Module;
+import android.support.v4.app.Fragment
+import com.vestrel00.daggerbutterknifemvp.inject.PerFragment
+import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseFragmentModule
+import dagger.Binds
+import dagger.Module
+import javax.inject.Named
/**
* Provides main fragment dependencies.
*/
-@Module(includes = BaseFragmentModule.class)
-public abstract class MainFragmentModule {
+@Module(includes = [BaseFragmentModule::class])
+abstract class MainFragmentModule {
/**
- * As per the contract specified in {@link BaseFragmentModule}; "This must be included in all
- * fragment modules, which must provide a concrete implementation of {@link Fragment}
- * and named {@link BaseFragmentModule#FRAGMENT}.
+ * As per the contract specified in [BaseFragmentModule]; "This must be included in all
+ * fragment modules, which must provide a concrete implementation of [Fragment]
+ * and named [BaseFragmentModule.FRAGMENT].
*
* @param mainFragment the main fragment
* @return the fragment
@@ -43,5 +40,5 @@ public abstract class MainFragmentModule {
@Binds
@Named(BaseFragmentModule.FRAGMENT)
@PerFragment
- abstract Fragment fragment(MainFragment mainFragment);
+ abstract fun fragment(mainFragment: MainFragment): Fragment
}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/package-info.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/package-info.java
similarity index 100%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/package-info.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/ui/package-info.java
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/util/PerActivityUtil.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/util/PerActivityUtil.kt
similarity index 60%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/util/PerActivityUtil.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/util/PerActivityUtil.kt
index 9a4bf55..b3c2327 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/util/PerActivityUtil.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/util/PerActivityUtil.kt
@@ -14,38 +14,28 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.util;
+package com.vestrel00.daggerbutterknifemvp.util
-import android.app.Activity;
-
-import com.vestrel00.daggerbutterknifemvp.inject.PerActivity;
-
-import javax.inject.Inject;
+import android.app.Activity
+import com.vestrel00.daggerbutterknifemvp.inject.PerActivity
+import javax.inject.Inject
/**
* A class that does something.
- *
- * This class has the {@link PerActivity} scope. This means that the Activity and all of its
+ *
+ * This class has the [PerActivity] scope. This means that the Activity and all of its
* Fragments and child fragments and their dependencies will share the same instance of this class.
* However, different activity instances will have their own instances.
- *
+ *
* This is not available at the Application.
*/
@PerActivity
-public final class PerActivityUtil {
-
- private final Activity activity;
-
- @Inject
- PerActivityUtil(Activity activity) {
- this.activity = activity;
- }
+class PerActivityUtil @Inject constructor(private val activity: Activity) {
/**
* @return the result of the work done here as a string. For this example, this returns its
- * {@link #hashCode()} and the activity's {@link #hashCode()}.
+ * [hashCode] and the activity's [hashCode].
*/
- public String doSomething() {
- return "PerActivityUtil: " + hashCode() + ", Activity: " + activity.hashCode();
- }
-}
+ fun doSomething(): String = "PerActivityUtil: " + hashCode() +
+ ", Activity: " + activity.hashCode()
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/util/PerChildFragmentUtil.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/util/PerChildFragmentUtil.kt
similarity index 61%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/util/PerChildFragmentUtil.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/util/PerChildFragmentUtil.kt
index 2afcb25..1cb177d 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/util/PerChildFragmentUtil.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/util/PerChildFragmentUtil.kt
@@ -14,42 +14,32 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.util;
+package com.vestrel00.daggerbutterknifemvp.util
-import android.support.v4.app.Fragment;
-
-import com.vestrel00.daggerbutterknifemvp.inject.PerChildFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseChildFragmentModule;
-
-import javax.inject.Inject;
-import javax.inject.Named;
+import android.support.v4.app.Fragment
+import com.vestrel00.daggerbutterknifemvp.inject.PerChildFragment
+import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseChildFragmentModule
+import javax.inject.Inject
+import javax.inject.Named
/**
* A class that does something.
- *
- * This class has the {@link PerChildFragment} scope. This means that the child Fragment (a fragment
+ *
+ * This class has the [PerChildFragment] scope. This means that the child Fragment (a fragment
* inside a fragment that is added using Fragment.getChildFragmentManager()) and all of its
* dependencies will share the same instance of this class. However, different child fragments
* instances will have their own instances of this class.
- *
+ *
* This is not available at the parent Fragment, Activity, and Application.
*/
@PerChildFragment
-public final class PerChildFragmentUtil {
-
- private final Fragment childFragment;
-
- @Inject
- PerChildFragmentUtil(@Named(BaseChildFragmentModule.CHILD_FRAGMENT) Fragment childFragment) {
- this.childFragment = childFragment;
- }
+class PerChildFragmentUtil @Inject constructor(@param:Named(BaseChildFragmentModule.CHILD_FRAGMENT)
+ private val childFragment: Fragment) {
/**
* @return the result of the work done here as a string. For this example, this returns its
- * {@link #hashCode()} and the child fragment's {@link #hashCode()}.
+ * [hashCode] and the child fragment's [hashCode].
*/
- public String doSomething() {
- return "PerChildFragmentUtil: " + hashCode()
- + ", child Fragment: " + childFragment.hashCode();
- }
+ fun doSomething(): String = "PerChildFragmentUtil: " + hashCode() +
+ ", child Fragment: " + childFragment.hashCode()
}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/util/PerFragmentUtil.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/util/PerFragmentUtil.kt
similarity index 58%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/util/PerFragmentUtil.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/util/PerFragmentUtil.kt
index 84d4b43..94f5c8c 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/util/PerFragmentUtil.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/util/PerFragmentUtil.kt
@@ -14,40 +14,31 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.util;
+package com.vestrel00.daggerbutterknifemvp.util
-import android.support.v4.app.Fragment;
-
-import com.vestrel00.daggerbutterknifemvp.inject.PerFragment;
-import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseFragmentModule;
-
-import javax.inject.Inject;
-import javax.inject.Named;
+import android.support.v4.app.Fragment
+import com.vestrel00.daggerbutterknifemvp.inject.PerFragment
+import com.vestrel00.daggerbutterknifemvp.ui.common.view.BaseFragmentModule
+import javax.inject.Inject
+import javax.inject.Named
/**
* A class that does something.
- *
- * This class has the {@link PerFragment} scope. This means that the Fragment and all of its child
+ *
+ * This class has the [PerFragment] scope. This means that the Fragment and all of its child
* fragments and their dependencies will share the same instance of this class. However, different
* fragment instances will have their own instances.
- *
+ *
* This is not available at the Activity and Application.
*/
@PerFragment
-public final class PerFragmentUtil {
-
- private final Fragment fragment;
-
- @Inject
- PerFragmentUtil(@Named(BaseFragmentModule.FRAGMENT) Fragment fragment) {
- this.fragment = fragment;
- }
+class PerFragmentUtil @Inject constructor(@param:Named(BaseFragmentModule.FRAGMENT)
+ private val fragment: Fragment) {
/**
* @return the result of the work done here as a string. For this example, this returns its
- * {@link #hashCode()} and the fragment's {@link #hashCode()}.
+ * [hashCode] and the fragment's [hashCode].
*/
- public String doSomething() {
- return "PerFragmentUtil: " + hashCode() + ", Fragment: " + fragment.hashCode();
- }
+ fun doSomething(): String = "PerFragmentUtil: " + hashCode() +
+ ", Fragment: " + fragment.hashCode()
}
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/util/SingletonUtil.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/util/SingletonUtil.kt
similarity index 57%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/util/SingletonUtil.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/util/SingletonUtil.kt
index ca8cc1c..16cf424 100644
--- a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/util/SingletonUtil.java
+++ b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/util/SingletonUtil.kt
@@ -14,34 +14,25 @@
* limitations under the License.
*/
-package com.vestrel00.daggerbutterknifemvp.util;
+package com.vestrel00.daggerbutterknifemvp.util
-import android.app.Application;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
+import android.app.Application
+import javax.inject.Inject
+import javax.inject.Singleton
/**
* A class that does something.
- *
- * This class has the {@link Singleton} scope. This means that the Application and all Activities,
+ *
+ * This class has the [Singleton] scope. This means that the Application and all Activities,
* Fragments, and child fragments and their dependencies will share the same instance of this class.
*/
@Singleton
-public final class SingletonUtil {
-
- private final Application application;
-
- @Inject
- SingletonUtil(Application application) {
- this.application = application;
- }
+class SingletonUtil @Inject constructor(private val application: Application) {
/**
* @return the result of the work done here as a string. For this example, this returns its
- * {@link #hashCode()} and the application's {@link #hashCode()}.
+ * [hashCode] and the application's [hashCode].
*/
- public String doSomething() {
- return "SingletonUtil: " + hashCode() + ", Application: " + application.hashCode();
- }
-}
+ fun doSomething(): String = "SingletonUtil: " + hashCode() +
+ ", Application: " + application.hashCode()
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vestrel00/daggerbutterknifemvp/util/package-info.java b/app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/util/package-info.java
similarity index 100%
rename from app/src/main/java/com/vestrel00/daggerbutterknifemvp/util/package-info.java
rename to app/src/main/kotlin/com/vestrel00/daggerbutterknifemvp/util/package-info.java
diff --git a/build.gradle b/build.gradle
index c218659..a3eede4 100644
--- a/build.gradle
+++ b/build.gradle
@@ -22,6 +22,7 @@ buildscript {
dependencies {
classpath "com.android.tools.build:gradle:2.3.3"
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.0"
classpath "com.jakewharton:butterknife-gradle-plugin:8.7.0"
}
}