Skip to content

Commit bb44d81

Browse files
authored
chore: add inline xml example to java sample (#507)
1 parent 93ac388 commit bb44d81

File tree

9 files changed

+377
-2
lines changed

9 files changed

+377
-2
lines changed

samples/java_layout/src/main/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@
127127
android:name=".ui.settings.InternalSettingsActivity"
128128
android:exported="false"
129129
android:label="@string/label_internal_settings_activity" />
130+
<activity
131+
android:name=".ui.inline.InlineExamplesActivity"
132+
android:exported="false"
133+
android:label="@string/label_inline_examples_activity" />
130134

131135
<meta-data
132136
android:name="com.google.firebase.messaging.default_notification_icon"

samples/java_layout/src/main/java/io/customer/android/sample/java_layout/ui/dashboard/DashboardActivity.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import io.customer.android.sample.java_layout.databinding.ActivityDashboardBinding;
3333
import io.customer.android.sample.java_layout.sdk.CustomerIORepository;
3434
import io.customer.android.sample.java_layout.ui.core.BaseActivity;
35+
import io.customer.android.sample.java_layout.ui.inline.InlineExamplesActivity;
3536
import io.customer.android.sample.java_layout.ui.login.LoginActivity;
3637
import io.customer.android.sample.java_layout.ui.settings.InternalSettingsActivity;
3738
import io.customer.android.sample.java_layout.ui.settings.SettingsActivity;
@@ -148,6 +149,9 @@ private void setupViews() {
148149
binding.showPushPromptButton.setOnClickListener(view -> {
149150
requestNotificationPermission();
150151
});
152+
binding.inlineExamplesXmlLayoutButton.setOnClickListener(view -> {
153+
startInlineExamplesActivity(InlineExamplesActivity.FRAGMENT_ANDROID_XML);
154+
});
151155
binding.logoutButton.setOnClickListener(view -> {
152156
authViewModel.clearLoggedInUser();
153157
});
@@ -196,6 +200,13 @@ private void startTrackingFragmentActivity(String fragmentName) {
196200
startActivity(intent);
197201
}
198202

203+
private void startInlineExamplesActivity(String fragmentName) {
204+
Intent intent = new Intent(DashboardActivity.this, InlineExamplesActivity.class);
205+
Bundle extras = InlineExamplesActivity.getExtras(fragmentName);
206+
intent.putExtras(extras);
207+
startActivity(intent);
208+
}
209+
199210
private void requestNotificationPermission() {
200211
if (isNotificationPermissionGranted()) {
201212
// Ask for notification permission if not granted
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.customer.android.sample.java_layout.ui.inline
2+
3+
import io.customer.android.sample.java_layout.databinding.FragmentAndroidXmlInlineExampleBinding
4+
import io.customer.android.sample.java_layout.ui.core.BaseFragment
5+
6+
class AndroidXMLInlineExampleFragment : BaseFragment<FragmentAndroidXmlInlineExampleBinding>() {
7+
override fun inflateViewBinding(): FragmentAndroidXmlInlineExampleBinding {
8+
return FragmentAndroidXmlInlineExampleBinding.inflate(layoutInflater)
9+
}
10+
11+
companion object {
12+
@JvmStatic
13+
fun newInstance() = AndroidXMLInlineExampleFragment()
14+
}
15+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package io.customer.android.sample.java_layout.ui.inline
2+
3+
import android.os.Bundle
4+
import android.view.View
5+
import androidx.fragment.app.Fragment
6+
import com.google.android.material.progressindicator.LinearProgressIndicator
7+
import io.customer.android.sample.java_layout.R
8+
import io.customer.android.sample.java_layout.databinding.ActivitySimpleFragmentBinding
9+
import io.customer.android.sample.java_layout.ui.core.BaseFragmentContainerActivity
10+
import io.customer.android.sample.java_layout.ui.user.AuthViewModel
11+
import io.customer.sdk.tracking.TrackableScreen
12+
13+
class InlineExamplesActivity :
14+
BaseFragmentContainerActivity<ActivitySimpleFragmentBinding>(),
15+
TrackableScreen {
16+
private lateinit var authViewModel: AuthViewModel
17+
18+
override val fragmentContainer: View get() = binding.container
19+
override val progressIndicator: LinearProgressIndicator get() = binding.progressIndicator
20+
override fun getFragmentTitle(): String = getScreenName()
21+
22+
override fun getScreenName(): String = when (fragmentName) {
23+
FRAGMENT_ANDROID_XML -> getString(R.string.inline_examples_xml_layout)
24+
else -> getString(R.string.label_inline_examples_activity)
25+
}
26+
27+
override fun inflateViewBinding(): ActivitySimpleFragmentBinding {
28+
return ActivitySimpleFragmentBinding.inflate(layoutInflater)
29+
}
30+
31+
override fun injectDependencies() {
32+
authViewModel = viewModelProvider[AuthViewModel::class.java]
33+
}
34+
35+
override fun setupContent() {
36+
setupToolbar(binding.topAppBar, useAsSupportActionBar = true)
37+
setupWithAuthViewModel(authViewModel)
38+
}
39+
40+
override fun findFragmentByName(fragmentName: String): Fragment? = when (fragmentName) {
41+
FRAGMENT_ANDROID_XML -> AndroidXMLInlineExampleFragment.newInstance()
42+
else -> null
43+
}
44+
45+
companion object {
46+
const val FRAGMENT_ANDROID_XML: String = "FRAGMENT_ANDROID_XML"
47+
48+
@JvmStatic
49+
fun getExtras(fragmentName: String?): Bundle {
50+
return BaseFragmentContainerActivity.getExtras(fragmentName)
51+
}
52+
}
53+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="rectangle">
4+
<solid android:color="@android:color/darker_gray" />
5+
<corners android:radius="8dp" />
6+
</shape>

samples/java_layout/src/main/res/layout/activity_dashboard.xml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,26 @@
193193
android:layout_marginTop="@dimen/margin_default"
194194
android:text="@string/view_logs"
195195
android:visibility="gone"
196-
app:layout_constraintBottom_toTopOf="@id/logout_button"
196+
app:layout_constraintBottom_toTopOf="@id/inline_examples_xml_layout_button"
197197
app:layout_constraintEnd_toEndOf="parent"
198198
app:layout_constraintStart_toStartOf="parent"
199199
app:layout_constraintTop_toBottomOf="@id/show_push_prompt_button"
200200
app:layout_constraintWidth_max="@dimen/material_button_max_width"
201201
tools:visibility="visible" />
202202

203+
<Button
204+
android:id="@+id/inline_examples_xml_layout_button"
205+
style="?attr/materialButtonStyle"
206+
android:layout_width="0dp"
207+
android:layout_height="wrap_content"
208+
android:layout_marginTop="@dimen/margin_default"
209+
android:text="@string/inline_examples_xml_layout"
210+
app:layout_constraintBottom_toTopOf="@id/logout_button"
211+
app:layout_constraintEnd_toEndOf="parent"
212+
app:layout_constraintStart_toStartOf="parent"
213+
app:layout_constraintTop_toBottomOf="@id/view_logs_button"
214+
app:layout_constraintWidth_max="@dimen/material_button_max_width"/>
215+
203216
<Button
204217
android:id="@+id/logout_button"
205218
style="?attr/materialButtonStyle"
@@ -210,7 +223,7 @@
210223
app:layout_constraintBottom_toBottomOf="parent"
211224
app:layout_constraintEnd_toEndOf="parent"
212225
app:layout_constraintStart_toStartOf="parent"
213-
app:layout_constraintTop_toBottomOf="@id/view_logs_button"
226+
app:layout_constraintTop_toBottomOf="@id/inline_examples_xml_layout_button"
214227
app:layout_constraintWidth_max="@dimen/material_button_max_width" />
215228

216229
<TextView

0 commit comments

Comments
 (0)