Skip to content

Commit d6b34d3

Browse files
committed
Referencing strings between modules
1 parent 6764b34 commit d6b34d3

File tree

6 files changed

+62
-15
lines changed

6 files changed

+62
-15
lines changed

app/src/main/res/navigation/main_nav_graph.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
4-
android:id="@+id/nav_graph"
5-
app:startDestination="@id/splashFragment">
6-
7-
<fragment
8-
android:id="@+id/splashFragment"
9-
android:name="cz.skywall.multimoduleexample.SplashFragment"
10-
android:label="Splash fragment" />
4+
android:id="@+id/nav_graph">
115

126
<include-dynamic
137
android:id="@+id/home_navigation_graph"

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
<string name="app_name">MultimoduleExample</string>
33
<string name="title_dummy_service">dummy service</string>
44

5+
<string name="string_from_app">String from :app</string>
56
</resources>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="string_from_common">String from :common</string>
3+
</resources>

home/src/main/java/cz/skywall/multimoduleexample/home/ui/home/HomeFragment.kt

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package cz.skywall.multimoduleexample.home.ui.home
22

3+
import android.annotation.SuppressLint
34
import android.content.Intent
45
import android.content.SharedPreferences
56
import android.os.Bundle
67
import android.view.LayoutInflater
78
import android.view.View
89
import android.view.ViewGroup
9-
import android.widget.TextView
1010
import cz.skywal.mutimoduleexmaple.dummy_service.DummyService
11+
import cz.skywall.multimoduleexample.home.R
12+
import cz.skywall.multimoduleexample.common.R as CR
13+
import cz.skywall.multimoduleexample.R as AR
1114
import cz.skywall.multimoduleexample.home.base.BaseFragment
1215
import cz.skywall.multimoduleexample.home.data.repository.DummyRepository
1316
import cz.skywall.multimoduleexample.home.data.repository.DummyRepository2
1417
import cz.skywall.multimoduleexample.network.ApiService
18+
import kotlinx.android.synthetic.main.fragment_home.*
1519
import javax.inject.Inject
1620

1721
class HomeFragment : BaseFragment() {
@@ -29,23 +33,30 @@ class HomeFragment : BaseFragment() {
2933
lateinit var dummyRepository2: DummyRepository2
3034

3135

36+
override fun inject() {
37+
homeComponent.plus(HomeFragmentModule()).inject(this)
38+
}
39+
3240
override fun onCreateView(
3341
inflater: LayoutInflater,
3442
container: ViewGroup?,
3543
savedInstanceState: Bundle?
3644
): View {
37-
return TextView(requireActivity()).apply { text = "Home Fragment" }
38-
}
39-
40-
override fun inject() {
41-
homeComponent.plus(HomeFragmentModule()).inject(this)
42-
43-
requireActivity().startService(Intent(requireActivity(), DummyService::class.java))
45+
return inflater.inflate(R.layout.fragment_home, container, false)
4446
}
4547

48+
@SuppressLint("SetTextI18n")
4649
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
4750
sharedPreferences.all
4851
dummyRepository.toString()
4952
dummyRepository2.toString()
53+
54+
requireActivity().startService(Intent(requireActivity(), DummyService::class.java))
55+
56+
combined_text.text =
57+
"""Combined:
58+
${resources.getString(CR.string.string_from_common)}
59+
${resources.getString(AR.string.string_from_app)}
60+
${resources.getString(R.string.string_from_home)}"""
5061
}
5162
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:orientation="vertical">
6+
7+
<LinearLayout
8+
android:layout_width="wrap_content"
9+
android:layout_height="wrap_content"
10+
android:layout_gravity="center"
11+
android:orientation="vertical">
12+
13+
<TextView
14+
android:layout_width="wrap_content"
15+
android:layout_height="wrap_content"
16+
android:text="@string/string_from_common" />
17+
18+
<TextView
19+
android:layout_width="wrap_content"
20+
android:layout_height="wrap_content"
21+
android:text="@string/string_from_app" />
22+
23+
<TextView
24+
android:layout_width="wrap_content"
25+
android:layout_height="wrap_content"
26+
android:text="@string/string_from_home" />
27+
28+
<TextView
29+
android:id="@+id/combined_text"
30+
android:layout_width="wrap_content"
31+
android:layout_height="wrap_content" />
32+
33+
</LinearLayout>
34+
</FrameLayout>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string name="string_from_home">String from :home</string>
4+
</resources>

0 commit comments

Comments
 (0)