-
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 example3: an activity with 1 fragment that contains a child fragment that utilizes the scoped utils. Closes #8
- Loading branch information
Showing
17 changed files
with
688 additions
and
4 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
40 changes: 40 additions & 0 deletions
40
app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/Example3Activity.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_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.Example3ParentFragment; | ||
|
||
/** | ||
* Activity that contains a single fragment that contains a child fragment. | ||
*/ | ||
public final class Example3Activity extends BaseActivity { | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.example_3_activity); | ||
|
||
if (savedInstanceState == null) { | ||
addFragment(R.id.parent_fragment_container, new Example3ParentFragment()); | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/Example3ActivityModule.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_3; | ||
|
||
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_3.parent_fragment.Example3ParentFragment; | ||
import com.vestrel00.daggerbutterknifemvp.ui.example_3.parent_fragment.Example3ParentFragmentSubcomponent; | ||
|
||
import dagger.Binds; | ||
import dagger.Module; | ||
import dagger.android.AndroidInjector; | ||
import dagger.android.FragmentKey; | ||
import dagger.multibindings.IntoMap; | ||
|
||
/** | ||
* Provides example 3 activity dependencies. | ||
*/ | ||
@Module(includes = BaseActivityModule.class, | ||
subcomponents = Example3ParentFragmentSubcomponent.class) | ||
abstract class Example3ActivityModule { | ||
|
||
/** | ||
* Provides the injector for the {@link Example3ParentFragment}, 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(Example3ParentFragment.class) | ||
abstract AndroidInjector.Factory<? extends Fragment> | ||
example3ParentFragmentInjectorFactory(Example3ParentFragmentSubcomponent.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 example3Activity the example 3 activity | ||
* @return the activity | ||
*/ | ||
@Binds | ||
@PerActivity | ||
abstract Activity activity(Example3Activity example3Activity); | ||
} |
38 changes: 38 additions & 0 deletions
38
...in/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/Example3ActivitySubcomponent.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,38 @@ | ||
/* | ||
* 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_3; | ||
|
||
|
||
import com.vestrel00.daggerbutterknifemvp.inject.PerActivity; | ||
|
||
import dagger.Subcomponent; | ||
import dagger.android.AndroidInjector; | ||
|
||
/** | ||
* Injects example 3 activity dependencies. | ||
*/ | ||
@PerActivity | ||
@Subcomponent(modules = Example3ActivityModule.class) | ||
public interface Example3ActivitySubcomponent extends AndroidInjector<Example3Activity> { | ||
|
||
/** | ||
* The builder for this subcomponent. | ||
*/ | ||
@Subcomponent.Builder | ||
abstract class Builder extends AndroidInjector.Builder<Example3Activity> { | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
...com/vestrel00/daggerbutterknifemvp/ui/example_3/child_fragment/Example3ChildFragment.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,91 @@ | ||
/* | ||
* 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_3.child_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.PerChildFragmentUtil; | ||
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 Example3ChildFragment extends BaseFragment implements View.OnClickListener { | ||
|
||
@Inject | ||
SingletonUtil singletonUtil; | ||
|
||
@Inject | ||
PerActivityUtil perActivityUtil; | ||
|
||
@Inject | ||
PerFragmentUtil perFragmentUtil; | ||
|
||
@Inject | ||
PerChildFragmentUtil perChildFragmentUtil; | ||
|
||
private 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 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(); | ||
something += "\n" + perChildFragmentUtil.doSomething(); | ||
showSomething(something); | ||
} | ||
|
||
private void showSomething(String something) { | ||
someText.setText(something); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...strel00/daggerbutterknifemvp/ui/example_3/child_fragment/Example3ChildFragmentModule.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_3.child_fragment; | ||
|
||
import android.app.Fragment; | ||
|
||
import com.vestrel00.daggerbutterknifemvp.inject.PerChildFragment; | ||
import com.vestrel00.daggerbutterknifemvp.ui.common.BaseChildFragmentModule; | ||
|
||
import javax.inject.Named; | ||
|
||
import dagger.Binds; | ||
import dagger.Module; | ||
|
||
/** | ||
* Provides example 3 child fragment dependencies. | ||
*/ | ||
@Module(includes = { | ||
BaseChildFragmentModule.class, | ||
}) | ||
abstract class Example3ChildFragmentModule { | ||
|
||
/** | ||
* As per the contract specified in {@link 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}.. | ||
* | ||
* @param example3ChildFragment the example 3 child fragment | ||
* @return the fragment | ||
*/ | ||
@Binds | ||
@Named(BaseChildFragmentModule.CHILD_FRAGMENT) | ||
@PerChildFragment | ||
abstract Fragment fragment(Example3ChildFragment example3ChildFragment); | ||
} |
39 changes: 39 additions & 0 deletions
39
...0/daggerbutterknifemvp/ui/example_3/child_fragment/Example3ChildFragmentSubcomponent.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_3.child_fragment; | ||
|
||
import com.vestrel00.daggerbutterknifemvp.inject.PerChildFragment; | ||
|
||
import dagger.Subcomponent; | ||
import dagger.android.AndroidInjector; | ||
|
||
/** | ||
* Injects example 3 child fragment dependencies. | ||
* <p> | ||
* TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector | ||
*/ | ||
@PerChildFragment | ||
@Subcomponent(modules = Example3ChildFragmentModule.class) | ||
public interface Example3ChildFragmentSubcomponent extends AndroidInjector<Example3ChildFragment> { | ||
|
||
/** | ||
* The builder for this subcomponent. | ||
*/ | ||
@Subcomponent.Builder | ||
abstract class Builder extends AndroidInjector.Builder<Example3ChildFragment> { | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/vestrel00/daggerbutterknifemvp/ui/example_3/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 that contains a child fragment. | ||
*/ | ||
package com.vestrel00.daggerbutterknifemvp.ui.example_3; |
Oops, something went wrong.