-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Created example2: an activity with 2 fragments that utilizes the scoped utils. Closes #7
- Loading branch information
Showing
18 changed files
with
685 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/Example2Activity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2017 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.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.Example2AFragment; | ||
import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.Example2BFragment; | ||
|
||
/** | ||
* Activity that contains 2 Fragments. | ||
*/ | ||
public final class Example2Activity extends BaseActivity { | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
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()); | ||
} | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/Example2ActivityModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2017 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.app.Activity; | ||
import android.app.Fragment; | ||
|
||
import com.vestrel00.daggerbutterknifemvp.inject.PerActivity; | ||
import com.vestrel00.daggerbutterknifemvp.ui.common.BaseActivityModule; | ||
import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.Example2AFragment; | ||
import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_a.Example2AFragmentSubcomponent; | ||
import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.Example2BFragment; | ||
import com.vestrel00.daggerbutterknifemvp.ui.example_2.fragment_b.Example2BFragmentSubcomponent; | ||
|
||
import dagger.Binds; | ||
import dagger.Module; | ||
import dagger.android.AndroidInjector; | ||
import dagger.android.FragmentKey; | ||
import dagger.multibindings.IntoMap; | ||
|
||
/** | ||
* Provides example 2 activity dependencies. | ||
*/ | ||
@Module(includes = BaseActivityModule.class, | ||
subcomponents = { | ||
Example2AFragmentSubcomponent.class, | ||
Example2BFragmentSubcomponent.class | ||
}) | ||
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). | ||
*/ | ||
// TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector | ||
@Binds | ||
@IntoMap | ||
@FragmentKey(Example2AFragment.class) | ||
abstract AndroidInjector.Factory<? extends Fragment> | ||
example2AFragmentInjectorFactory(Example2AFragmentSubcomponent.Builder builder); | ||
|
||
/** | ||
* Provides the injector for the {@link Example2BFragment}, which has access to the dependencies | ||
* provided by this activity and application instance (singleton scoped objects). | ||
*/ | ||
// TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector | ||
@Binds | ||
@IntoMap | ||
@FragmentKey(Example2BFragment.class) | ||
abstract AndroidInjector.Factory<? extends Fragment> | ||
example2BFragmentInjectorFactory(Example2BFragmentSubcomponent.Builder builder); | ||
|
||
/** | ||
* As per the contract specified in {@link BaseActivityModule}; "This must be included in all | ||
* activity modules, which must rovide a concrete implementation of {@link Activity}." | ||
* <p> | ||
* 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 Activity activity(Example2Activity example2Activity); | ||
} |
40 changes: 40 additions & 0 deletions
40
...in/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/Example2ActivitySubcomponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2017 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 com.vestrel00.daggerbutterknifemvp.inject.PerActivity; | ||
|
||
import dagger.Subcomponent; | ||
import dagger.android.AndroidInjector; | ||
|
||
/** | ||
* Injects example 2 activity dependencies. | ||
* <p> | ||
* TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector | ||
*/ | ||
@PerActivity | ||
@Subcomponent(modules = Example2ActivityModule.class) | ||
public interface Example2ActivitySubcomponent extends AndroidInjector<Example2Activity> { | ||
|
||
/** | ||
* The builder for this subcomponent. | ||
*/ | ||
@Subcomponent.Builder | ||
abstract class Builder extends AndroidInjector.Builder<Example2Activity> { | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
...in/java/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/Example2AFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright 2017 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; | ||
|
||
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.BaseFragment; | ||
import com.vestrel00.daggerbutterknifemvp.util.PerActivityUtil; | ||
import com.vestrel00.daggerbutterknifemvp.util.PerFragmentUtil; | ||
import com.vestrel00.daggerbutterknifemvp.util.SingletonUtil; | ||
|
||
import javax.inject.Inject; | ||
|
||
/** | ||
* A fragment that contains a button that does something. | ||
*/ | ||
public final class Example2AFragment extends BaseFragment implements View.OnClickListener { | ||
|
||
@Inject | ||
SingletonUtil singletonUtil; | ||
|
||
@Inject | ||
PerActivityUtil perActivityUtil; | ||
|
||
@Inject | ||
PerFragmentUtil perFragmentUtil; | ||
|
||
private 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 onViewCreated(View view, @Nullable Bundle savedInstanceState) { | ||
super.onViewCreated(view, savedInstanceState); | ||
|
||
// TODO (Butterknife) replace with butterknife view binding | ||
someText = (TextView) view.findViewById(R.id.some_text); | ||
view.findViewById(R.id.do_something).setOnClickListener(this); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
switch (v.getId()) { | ||
case R.id.do_something: | ||
onDoSomethingClicked(); | ||
break; | ||
default: | ||
throw new IllegalArgumentException("Unhandled view " + v.getId()); | ||
} | ||
} | ||
|
||
private void onDoSomethingClicked() { | ||
String something = singletonUtil.doSomething(); | ||
something += "\n" + perActivityUtil.doSomething(); | ||
something += "\n" + perFragmentUtil.doSomething(); | ||
showSomething(something); | ||
} | ||
|
||
private void showSomething(String something) { | ||
someText.setText(something); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...a/com/vestrel00/daggerbutterknifemvp/ui/example_2/fragment_a/Example2AFragmentModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2017 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; | ||
|
||
import android.app.Fragment; | ||
|
||
import com.vestrel00.daggerbutterknifemvp.inject.PerFragment; | ||
import com.vestrel00.daggerbutterknifemvp.ui.common.BaseFragmentModule; | ||
|
||
import javax.inject.Named; | ||
|
||
import dagger.Binds; | ||
import dagger.Module; | ||
|
||
/** | ||
* Provides example 2 A fragment dependencies. | ||
*/ | ||
@Module(includes = { | ||
BaseFragmentModule.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}. | ||
* | ||
* @param example2AFragment the example 2 A fragment | ||
* @return the fragment | ||
*/ | ||
@Binds | ||
@Named(BaseFragmentModule.FRAGMENT) | ||
@PerFragment | ||
abstract Fragment fragment(Example2AFragment example2AFragment); | ||
} |
Oops, something went wrong.