Skip to content

Commit

Permalink
populate the session id on screen and set up cart (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
breedx-splk authored Jun 3, 2024
1 parent a14dcaf commit 94c5d6c
Show file tree
Hide file tree
Showing 25 changed files with 130 additions and 24 deletions.
Binary file added demo-app/src/main/ic_cart-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AstronomyShopActivity : AppCompatActivity() {
setOf(
R.id.navigation_home,
R.id.navigation_dashboard,
R.id.navigation_notifications,
R.id.navigation_cart,
),
)
setupActionBarWithNavController(navController, appBarConfiguration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package io.opentelemetry.android.demo

import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
Expand Down Expand Up @@ -76,7 +77,9 @@ class MainActivity : ComponentActivity() {
})
}
}
Log.d(TAG, "Main Activity started ")
}
}
viewModel.sessionIdState.value = OtelSampleApplication.rum?.rumSessionId!!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import io.opentelemetry.api.common.Attributes
import io.opentelemetry.api.trace.Tracer
import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter

private const val TAG = "otel.demo"
const val TAG = "otel.demo"

class OtelSampleApplication : Application() {
@SuppressLint("RestrictedApi")
Expand Down
16 changes: 10 additions & 6 deletions demo-app/src/main/java/io/opentelemetry/android/demo/SessionId.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material3.Card
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
Expand All @@ -22,16 +23,19 @@ import kotlinx.coroutines.flow.StateFlow
@Composable
fun SessionId(sessionId: StateFlow<String>) {
Row {
Card(modifier = Modifier.size(width = 250.dp, height = 75.dp)) {
Card(modifier = Modifier.size(width = 295.dp, height = 75.dp)) {
Column(
modifier =
Modifier
.fillMaxWidth()
.padding(vertical = 25.dp),
Modifier
.fillMaxWidth()
.padding(vertical = 25.dp),
Arrangement.Center,
) {
CenterText(text = "session.id", fontSize = 12.sp)
CenterText(text = sessionId.collectAsState().value, fontSize = 12.sp)
CenterText(text = "session.id", fontSize = 14.sp)
//TODO: Fix me -- this selection doesn't work
SelectionContainer {
CenterText(text = sessionId.collectAsState().value, fontSize = 14.sp)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.android.demo.ui.notifications
package io.opentelemetry.android.demo.ui.cart

import android.os.Bundle
import android.view.LayoutInflater
Expand All @@ -14,7 +14,7 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import io.opentelemetry.android.demo.databinding.FragmentNotificationsBinding

class NotificationsFragment : Fragment() {
class CartFragment : Fragment() {
// Renamed from _binding (default) due to ktlint problem below
private var binding: FragmentNotificationsBinding? = null

Expand All @@ -32,14 +32,14 @@ class NotificationsFragment : Fragment() {
container: ViewGroup?,
savedInstanceState: Bundle?,
): View {
val notificationsViewModel =
ViewModelProvider(this).get(NotificationsViewModel::class.java)
val cartViewModel =
ViewModelProvider(this).get(CartViewModel::class.java)

binding = FragmentNotificationsBinding.inflate(inflater, container, false)
val root: View = getBinding().root

val textView: TextView = getBinding().textNotifications
notificationsViewModel.text.observe(viewLifecycleOwner) {
cartViewModel.text.observe(viewLifecycleOwner) {
textView.text = it
}
return root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.android.demo.ui.notifications
package io.opentelemetry.android.demo.ui.cart

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class NotificationsViewModel : ViewModel() {
class CartViewModel : ViewModel() {
private val _text =
MutableLiveData<String>().apply {
value = "This is notifications Fragment"
value = "This is cart Fragment"
}
val text: LiveData<String> = _text
}
74 changes: 74 additions & 0 deletions demo-app/src/main/res/drawable/ic_cart_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<vector
android:height="108dp"
android:width="108dp"
android:viewportHeight="108"
android:viewportWidth="108"
xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z"/>
<path android:fillColor="#00000000" android:pathData="M9,0L9,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,0L19,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M29,0L29,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M39,0L39,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M49,0L49,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M59,0L59,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M69,0L69,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M79,0L79,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M89,0L89,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M99,0L99,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,9L108,9"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,19L108,19"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,29L108,29"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,39L108,39"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,49L108,49"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,59L108,59"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,69L108,69"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,79L108,79"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,89L108,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,99L108,99"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,29L89,29"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,39L89,39"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,49L89,49"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,59L89,59"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,69L89,69"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,79L89,79"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M29,19L29,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M39,19L39,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M49,19L49,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M59,19L59,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M69,19L69,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M79,19L79,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
</vector>
15 changes: 15 additions & 0 deletions demo-app/src/main/res/drawable/ic_cart_foreground.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#000000">
<group android:scaleX="0.58"
android:scaleY="0.58"
android:translateX="5.04"
android:translateY="5.04">
<path
android:fillColor="@android:color/white"
android:pathData="M7,18c-1.1,0 -1.99,0.9 -1.99,2S5.9,22 7,22s2,-0.9 2,-2 -0.9,-2 -2,-2zM1,2v2h2l3.6,7.59 -1.35,2.45c-0.16,0.28 -0.25,0.61 -0.25,0.96 0,1.1 0.9,2 2,2h12v-2L7.42,15c-0.14,0 -0.25,-0.11 -0.25,-0.25l0.03,-0.12 0.9,-1.63h7.45c0.75,0 1.41,-0.41 1.75,-1.03l3.58,-6.49c0.08,-0.14 0.12,-0.31 0.12,-0.48 0,-0.55 -0.45,-1 -1,-1L5.21,4l-0.94,-2L1,2zM17,18c-1.1,0 -1.99,0.9 -1.99,2s0.89,2 1.99,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"/>
</group>
</vector>
2 changes: 1 addition & 1 deletion demo-app/src/main/res/layout/fragment_notifications.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.notifications.NotificationsFragment">
tools:context=".ui.cart.CartFragment">

<TextView
android:id="@+id/text_notifications"
Expand Down
6 changes: 3 additions & 3 deletions demo-app/src/main/res/menu/bottom_nav_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
android:title="@string/title_dashboard" />

<item
android:id="@+id/navigation_notifications"
android:icon="@drawable/ic_notifications_black_24dp"
android:title="@string/title_notifications" />
android:id="@+id/navigation_cart"
android:icon="@drawable/ic_cart_foreground"
android:title="@string/title_cart" />

</menu>
5 changes: 5 additions & 0 deletions demo-app/src/main/res/mipmap-anydpi-v26/ic_cart.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_cart_background"/>
<foreground android:drawable="@drawable/ic_cart_foreground"/>
</adaptive-icon>
5 changes: 5 additions & 0 deletions demo-app/src/main/res/mipmap-anydpi-v26/ic_cart_round.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_cart_background"/>
<foreground android:drawable="@drawable/ic_cart_foreground"/>
</adaptive-icon>
Binary file added demo-app/src/main/res/mipmap-hdpi/ic_cart.webp
Binary file not shown.
Binary file not shown.
Binary file added demo-app/src/main/res/mipmap-mdpi/ic_cart.webp
Binary file not shown.
Binary file not shown.
Binary file added demo-app/src/main/res/mipmap-xhdpi/ic_cart.webp
Binary file not shown.
Binary file not shown.
Binary file added demo-app/src/main/res/mipmap-xxhdpi/ic_cart.webp
Binary file not shown.
Binary file not shown.
Binary file added demo-app/src/main/res/mipmap-xxxhdpi/ic_cart.webp
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions demo-app/src/main/res/navigation/mobile_navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
tools:layout="@layout/fragment_dashboard" />

<fragment
android:id="@+id/navigation_notifications"
android:name="io.opentelemetry.android.demo.ui.notifications.NotificationsFragment"
android:label="@string/title_notifications"
android:id="@+id/navigation_cart"
android:name="io.opentelemetry.android.demo.ui.cart.CartFragment"
android:label="@string/title_cart"
tools:layout="@layout/fragment_notifications" />
</navigation>
2 changes: 1 addition & 1 deletion demo-app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<string name="title_activity_astronomy_shop">AstronomyShopActivity</string>
<string name="title_home">Home</string>
<string name="title_dashboard">Dashboard</string>
<string name="title_notifications">Notifications</string>
<string name="title_cart">Cart</string>
</resources>

0 comments on commit 94c5d6c

Please sign in to comment.