Integration of get user data api call on SplashFragment

BottomNav on HomeActivity
Worked on sidebar menu
- sidebar implementation
- ui for user data
- theme switching
- language switching
This commit is contained in:
2024-05-15 21:04:35 +05:30
parent 6153339bea
commit d4ac42b62a
49 changed files with 499 additions and 20 deletions

View File

@@ -17,7 +17,9 @@
tools:targetApi="31" >
<activity
android:name=".home.HomeActivity"
android:exported="false" />
android:exported="false"
android:screenOrientation="portrait"
/>
<activity
android:name=".onboard.OnboardActivity"
android:exported="false"

View File

@@ -1,30 +1,97 @@
package com.woka.home
import android.graphics.Color
import android.os.Bundle
import android.util.Log
import android.view.Gravity
import android.view.View.GONE
import android.view.View.VISIBLE
import android.view.WindowManager
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.view.GravityCompat
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.Observer
import com.bumptech.glide.Glide
import com.woka.R
import com.woka.WokaApp.Companion.userPrefs
import com.woka.databinding.ActivityHomeBinding
import com.woka.mvvm.userDataModels.UserDataResponse
import com.woka.networking.ApiResult
import com.woka.utils.TAG
import kotlinx.coroutines.launch
import com.woka.utils.UserType
import com.woka.utils.WokaBaseActivity
import com.woka.utils.toast
class HomeActivity : AppCompatActivity() {
class HomeActivity : WokaBaseActivity(), Observer<ApiResult<UserDataResponse>> {
private lateinit var binding: ActivityHomeBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_home)
binding = ActivityHomeBinding.inflate(layoutInflater)
setContentView(binding.root)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
Log.d(TAG, "onCreate: ${userPrefs?.userType} ${userPrefs?.accessToken}")
userPrefs?.userLiveData?.observe(this, this)
initViews()
clickEvents()
}
private fun initViews() {
binding.apply {
bottomNav.setOnItemSelectedListener {
if (bottomNav.selectedItemId != it.itemId)
toast(it.title.toString())
true
}
}
}
private fun clickEvents() {
binding.apply {
sideMenu.setOnClickListener {
homeDrawer.openDrawer(GravityCompat.END)
}
closeDrawer.setOnClickListener {
homeDrawer.closeDrawer(GravityCompat.END)
}
}
}
override fun onChanged(value: ApiResult<UserDataResponse>) {
when(value){
is ApiResult.Error -> {}
is ApiResult.Loading -> {}
is ApiResult.Success -> {
Log.d(TAG, "onChanged: ${value.data?.result}")
value.data?.result?.let {
binding.apply {
it.avtar?.let {
Glide.with(this@HomeActivity)
.load(it)
.placeholder(R.drawable.profile_placeholder)
.error(R.drawable.profile_placeholder)
.into(sbUserImage)
}
sbUserName.text = it.fullname
sbBtn.text = getString(R.string.logout)
}
}
}
}
}
}

View File

@@ -7,7 +7,7 @@ data class UserData(
val child_detail: ChildDetail?,
val email: String?,
val fullname: String?,
val gender: Gender?,
val gender: String?,
val id: Int?,
val is_active: String?,
val language: Language?,

View File

@@ -1,23 +1,36 @@
package com.woka.onboard.fragments
import android.animation.Animator
import android.content.Intent
import android.media.MediaPlayer
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.animation.Animation
import android.view.animation.Animation.AnimationListener
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.FragmentNavigatorExtras
import androidx.navigation.fragment.findNavController
import com.woka.R
import com.woka.WokaApp.Companion.userPrefs
import com.woka.databinding.FragmentSplashBinding
import com.woka.home.HomeActivity
import com.woka.mvvm.userDataModels.UserDataResponse
import com.woka.networking.ApiResult
import com.woka.utils.TAG
import com.woka.utils.UserType
import com.woka.utils.toast
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
/*
Root fragment to the launcher activity i.e. WelcomeActivity
*/
class SplashFragment : Fragment() {
class SplashFragment : Fragment(), Observer<ApiResult<UserDataResponse>> {
private lateinit var binding: FragmentSplashBinding
@@ -38,11 +51,10 @@ class SplashFragment : Fragment() {
animateLogo()
lifecycleScope.launch {
delay(6000)
val extras = FragmentNavigatorExtras(binding.logo to "logo")
findNavController().navigate(R.id.action_splashFragment_to_languageFragment,
null, null, extras)
if (userPrefs?.userType == UserType.CHILD || userPrefs?.userType == UserType.GUARDIAN){
// some type of user is logged in
// thus, loading data
userPrefs?.loadUserData()
}
}
@@ -54,6 +66,25 @@ class SplashFragment : Fragment() {
private fun animateLogo() {
binding.logo.animate().scaleXBy(1f).scaleYBy(1f)
.setDuration(2000)
.setListener(object : Animator.AnimatorListener{
override fun onAnimationStart(animation: Animator) {}
override fun onAnimationEnd(animation: Animator) {
lifecycleScope.launch {
delay(2000)
if (userPrefs?.userType == UserType.NONE || userPrefs?.userType == UserType.GUEST){
// no user or guest is logged in
goForward()
}else{
// some user is logged in listening to user data
userPrefs?.userLiveData?.removeObserver(this@SplashFragment)
userPrefs?.userLiveData?.observe(viewLifecycleOwner, this@SplashFragment)
}
}
}
override fun onAnimationCancel(animation: Animator) {}
override fun onAnimationRepeat(animation: Animator) {}
})
.start()
}
@@ -63,4 +94,35 @@ class SplashFragment : Fragment() {
player?.release()
player = null
}
private fun goForward(){
if (userPrefs?.userType == UserType.NONE){
// none of the user is logged in
// going through normal onboard process
val extras = FragmentNavigatorExtras(binding.logo to "logo")
findNavController().navigate(R.id.action_splashFragment_to_languageFragment,
null, null, extras)
}else{
// going to home activity as any of the user is logged in
activity?.let {
startActivity(Intent(it, HomeActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
})
it.finish()
}
}
}
override fun onChanged(value: ApiResult<UserDataResponse>) {
// on user data loaded
when (value){
is ApiResult.Error -> {
toast(value.errorMessage)
}
is ApiResult.Loading -> {}
is ApiResult.Success -> {
goForward()
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 744 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 974 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="23dp"
android:height="23dp"
android:viewportWidth="23"
android:viewportHeight="23">
<path
android:pathData="M1.799,0L0.057,1.746L9.759,11.471L0,21.274L1.722,23L11.5,13.217L21.259,23L23,21.254L13.241,11.471L22.943,1.746L21.201,0L11.5,9.726L1.799,0Z"
android:fillColor="#ffffff"/>
</vector>

View File

@@ -0,0 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48">
<group>
<clip-path
android:pathData="M0,0h48v48h-48z"/>
<path
android:pathData="M24,0.346C10.94,0.346 0.346,10.94 0.346,24C0.346,37.06 10.94,47.654 24,47.654C37.06,47.654 47.654,37.06 47.654,24C47.654,10.94 37.06,0.346 24,0.346ZM36.433,16.68L23.748,35.387C23.373,35.942 22.774,36.317 22.183,36.317C21.591,36.317 20.942,35.993 20.524,35.582L13.082,28.132C12.577,27.627 12.577,26.798 13.082,26.293L14.921,24.454C15.425,23.949 16.255,23.949 16.752,24.454L21.599,29.293L32.127,13.76C32.531,13.168 33.346,13.017 33.938,13.413L36.094,14.877C36.678,15.274 36.837,16.089 36.433,16.68Z"
android:fillColor="#6DC200"/>
</group>
</vector>

View File

@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="19dp"
android:height="18dp"
android:viewportWidth="19"
android:viewportHeight="18">
<path
android:pathData="M13.737,0C10.994,0 9.474,2.05 9.474,2.05C9.474,2.05 7.953,0 5.211,0C2.332,0 0,2.415 0,5.395C0,9.487 4.653,13.451 5.95,14.704C7.444,16.146 9.474,18 9.474,18C9.474,18 11.503,16.146 12.997,14.704C14.294,13.451 18.947,9.487 18.947,5.395C18.947,2.415 16.615,0 13.737,0Z"
android:fillColor="#09005D"/>
</vector>

View File

@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="19dp"
android:height="18dp"
android:viewportWidth="19"
android:viewportHeight="18">
<path
android:pathData="M14.665,0C14.255,0 13.922,0.337 13.922,0.751V4.342L9.996,0.375C9.706,0.082 9.218,0.082 8.928,0.375L0.218,9.199C-0.073,9.493 -0.073,9.962 0.218,10.255C0.508,10.549 0.973,10.549 1.263,10.255L9.462,1.971L17.684,10.279C17.83,10.426 18.027,10.514 18.219,10.514C18.41,10.514 18.584,10.426 18.73,10.279C19.02,9.986 19.02,9.516 18.73,9.223L16.151,6.618V0.751C16.151,0.337 15.818,0 15.408,0H14.665ZM9.462,3.356L1.286,11.617V15.747C1.286,16.991 2.285,18 3.516,18H15.408C16.639,18 17.638,16.991 17.638,15.747V11.617L9.462,3.356ZM11.692,11.241C11.692,10.828 11.358,10.49 10.949,10.49H7.976C7.566,10.49 7.232,10.828 7.232,11.241V15.747C7.232,16.161 7.566,16.498 7.976,16.498H10.949C11.358,16.498 11.692,16.161 11.692,15.747V11.241Z"
android:fillColor="#09005D"
android:fillType="evenOdd"/>
</vector>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white"/>
<corners android:radius="30dp"/>
</shape>

View File

@@ -1,11 +1,286 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/home_drawer"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="end"
tools:context=".home.HomeActivity">
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.cardview.widget.CardView
android:id="@+id/side_menu"
android:layout_width="@dimen/_40sdp"
android:layout_height="@dimen/_40sdp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:cardCornerRadius="@dimen/_20sdp"
app:cardElevation="3dp"
android:layout_margin="20dp"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/image"
android:src="@drawable/ic_menu"
/>
</androidx.cardview.widget.CardView>
<androidx.fragment.app.FragmentContainerView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/bottom_nav"
app:layout_constraintTop_toTopOf="parent"
/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:backgroundTint="@color/white"
app:menu="@menu/home_bottom_menu"
app:itemIconTint="@color/color_primary"
app:itemTextColor="@color/color_primary"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.navigation.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="@color/color_primary"
android:fitsSystemWindows="true"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
android:scrollbars="none"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="25dp"
android:layout_marginBottom="15dp"
android:layout_marginTop="50dp"
android:orientation="vertical">
<ImageView
android:id="@+id/close_drawer"
android:layout_width="20dp"
android:layout_height="20dp"
android:contentDescription="@string/image"
android:src="@drawable/ic_close"
android:layout_gravity="end"
/>
<ImageView
android:id="@+id/sb_user_image"
android:layout_width="@dimen/_40sdp"
android:layout_height="@dimen/_40sdp"
android:contentDescription="@string/image"
android:scaleType="fitXY"
android:src="@drawable/profile_placeholder"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
/>
<TextView
android:id="@+id/sb_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Aditya Gaikwad"
android:textColor="@color/white"
android:fontFamily="@font/exo_2_bold"
android:textSize="@dimen/_14ssp"
android:textAlignment="center"
android:layout_gravity="center"
android:maxLines="1"
android:ellipsize="end"
android:layout_marginTop="10dp"
/>
<Button
android:id="@+id/sb_btn"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@drawable/grad_btn_bg_4"
tools:text="Logout"
android:textSize="@dimen/_11ssp"
android:textColor="@color/white"
android:fontFamily="@font/exo_2_bold"
android:layout_marginTop="15dp"
android:layout_marginHorizontal="15dp"
android:layout_gravity="center_horizontal"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/theme"
android:fontFamily="@font/exo_2_bold"
android:textColor="@color/white"
android:textSize="@dimen/_11ssp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="25dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal"
style="@style/Theme.MaterialComponents"
android:gravity="center"
>
<androidx.cardview.widget.CardView
android:layout_width="80dp"
android:layout_height="120dp"
app:cardCornerRadius="3dp"
android:layout_marginEnd="12dp"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/image"
android:src="@drawable/theme_1"
/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/image"
android:src="@drawable/theme_selected_tint"/>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:contentDescription="@string/image"
android:src="@drawable/ic_green_tick"
/>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="80dp"
android:layout_height="120dp"
app:strokeWidth="1dp"
app:strokeColor="@color/white"
app:cardCornerRadius="3dp"
android:layout_marginStart="12dp"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/image"
android:src="@drawable/theme_2"
/>
</androidx.cardview.widget.CardView>
</LinearLayout>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_gravity="center_horizontal"
app:cardCornerRadius="30dp"
app:cardBackgroundColor="#050038"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/english"
android:textAllCaps="true"
android:fontFamily="@font/exo_2_medium"
android:textColor="#050038"
android:textAlignment="center"
android:textSize="@dimen/_11ssp"
android:background="@drawable/lang_tab_bg"
android:paddingVertical="10dp"
/>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/hindi"
android:textAllCaps="true"
android:fontFamily="@font/exo_2_medium"
android:textColor="@color/white"
android:textAlignment="center"
android:textSize="@dimen/_11ssp"
android:background="@android:color/transparent"
android:paddingVertical="10dp"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</ScrollView>
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/home_bm"
android:title="@string/home"
android:icon="@drawable/ic_home"
/>
<item android:id="@+id/explore_woka_bm"
android:title="@string/explore_woka"
android:icon="@drawable/ic_woka"
/>
<item android:id="@+id/my_list_bm"
android:title="@string/my_list"
android:icon="@drawable/ic_heart_filled"
/>
</menu>

View File

@@ -2,7 +2,7 @@
<!-- Base application theme. -->
<style name="Base.Theme.Woka" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your dark theme here. -->
<item name="colorPrimary">@color/color_primary</item>
<item name="colorPrimary">@color/color_primary</item>
<item name="android:textCursorDrawable">@drawable/cursor_drawable</item>
</style>
</resources>

View File

@@ -103,4 +103,9 @@
<string name="required">Required</string>
<string name="boy">BOY</string>
<string name="girl">GIRL</string>
<string name="home">Home</string>
<string name="explore_woka">Explore Woka</string>
<string name="my_list">My List</string>
<string name="logout">Logout</string>
<string name="theme">THEME</string>
</resources>

View File

@@ -2,7 +2,7 @@
<!-- Base application theme. -->
<style name="Base.Theme.Woka" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your light theme here. -->
<item name="colorPrimary">@color/color_primary</item>
<item name="colorPrimary">@color/color_primary</item>
<item name="android:textCursorDrawable">@drawable/cursor_drawable</item>
</style>