-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A: 6 - Created example1: an activity with a fragment that utilizes the scoped utils. Closes #6 #23
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
40 changes: 40 additions & 0 deletions
40
app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/Example1Activity.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_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.Example1Fragment; | ||
|
||
/** | ||
* Activity that contains a single Fragment. | ||
*/ | ||
public final class Example1Activity extends BaseActivity { | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.example_1_activity); | ||
|
||
if (savedInstanceState == null) { | ||
addFragment(R.id.fragment_container, new Example1Fragment()); | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/Example1ActivityModule.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,65 @@ | ||
/* | ||
* 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_1; | ||
|
||
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_1.fragment.Example1Fragment; | ||
import com.vestrel00.daggerbutterknifemvp.ui.example_1.fragment.Example1FragmentSubcomponent; | ||
|
||
import dagger.Binds; | ||
import dagger.Module; | ||
import dagger.android.AndroidInjector; | ||
import dagger.android.FragmentKey; | ||
import dagger.multibindings.IntoMap; | ||
|
||
/** | ||
* Provides example 1 activity dependencies. | ||
*/ | ||
@Module(includes = BaseActivityModule.class, | ||
subcomponents = Example1FragmentSubcomponent.class) | ||
abstract class Example1ActivityModule { | ||
|
||
/** | ||
* Provides the injector for the {@link Example1Fragment}, 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(Example1Fragment.class) | ||
abstract AndroidInjector.Factory<? extends Fragment> | ||
example1FragmentInjectorFactory(Example1FragmentSubcomponent.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 example1Activity the example 1 activity | ||
* @return the activity | ||
*/ | ||
@Binds | ||
@PerActivity | ||
abstract Activity activity(Example1Activity example1Activity); | ||
} |
40 changes: 40 additions & 0 deletions
40
...in/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/Example1ActivitySubcomponent.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_1; | ||
|
||
|
||
import com.vestrel00.daggerbutterknifemvp.inject.PerActivity; | ||
|
||
import dagger.Subcomponent; | ||
import dagger.android.AndroidInjector; | ||
|
||
/** | ||
* Injects example 1 activity dependencies. | ||
* <p> | ||
* TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector | ||
*/ | ||
@PerActivity | ||
@Subcomponent(modules = Example1ActivityModule.class) | ||
public interface Example1ActivitySubcomponent extends AndroidInjector<Example1Activity> { | ||
|
||
/** | ||
* The builder for this subcomponent. | ||
*/ | ||
@Subcomponent.Builder | ||
abstract class Builder extends AndroidInjector.Builder<Example1Activity> { | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
.../main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/Example1Fragment.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_1.fragment; | ||
|
||
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 Example1Fragment extends BaseFragment implements View.OnClickListener { | ||
|
||
private TextView someText; | ||
|
||
@Inject | ||
SingletonUtil singletonUtil; | ||
|
||
@Inject | ||
PerActivityUtil perActivityUtil; | ||
|
||
@Inject | ||
PerFragmentUtil perFragmentUtil; | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||
Bundle savedInstanceState) { | ||
return inflater.inflate(R.layout.example_1_fragment, 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
...java/com/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/Example1FragmentModule.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_1.fragment; | ||
|
||
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 1 fragment dependencies. | ||
*/ | ||
@Module(includes = { | ||
BaseFragmentModule.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}. | ||
* | ||
* @param example1Fragment the example 1 fragment | ||
* @return the fragment | ||
*/ | ||
@Binds | ||
@Named(BaseFragmentModule.FRAGMENT) | ||
@PerFragment | ||
abstract Fragment fragment(Example1Fragment example1Fragment); | ||
} |
39 changes: 39 additions & 0 deletions
39
...om/vestrel00/daggerbutterknifemvp/ui/example_1/fragment/Example1FragmentSubcomponent.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,39 @@ | ||
/* | ||
* 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_1.fragment; | ||
|
||
import com.vestrel00.daggerbutterknifemvp.inject.PerFragment; | ||
|
||
import dagger.Subcomponent; | ||
import dagger.android.AndroidInjector; | ||
|
||
/** | ||
* Injects example 1 fragment dependencies. | ||
* <p> | ||
* TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector | ||
*/ | ||
@PerFragment | ||
@Subcomponent(modules = Example1FragmentModule.class) | ||
public interface Example1FragmentSubcomponent extends AndroidInjector<Example1Fragment> { | ||
|
||
/** | ||
* The builder for this subcomponent. | ||
*/ | ||
@Subcomponent.Builder | ||
abstract class Builder extends AndroidInjector.Builder<Example1Fragment> { | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_1/package-info.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,20 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* Shows how to create an activity that contains a single fragment. | ||
*/ | ||
package com.vestrel00.daggerbutterknifemvp.ui.example_1; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private should be below package protected to follow the public, protected, package, private access modifier order.
Fixed in the next PR.