Woka support scrolling issue resolved
Completed UserProfileActivity.kt with api integration Completed whole flow of add child from guardian app with all api integration of child registration Deactivate account api integration. Flow changes in user log in
This commit is contained in:
@@ -37,10 +37,12 @@ import com.woka.home.fragments.Home2Fragment
|
||||
import com.woka.home.fragments.MyListFragment
|
||||
import com.woka.home.sidebar.aboutwoka.AboutActivity
|
||||
import com.woka.home.sidebar.faqs.FaqActivity
|
||||
import com.woka.home.sidebar.profile.UserProfileActivity
|
||||
import com.woka.home.sidebar.support.SupportActivity
|
||||
import com.woka.mvvm.userDataModels.UserDataResponse
|
||||
import com.woka.userdata.userDataModels.UserDataResponse
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.onboard.OnboardActivity
|
||||
import com.woka.onboard.OnboardActivity.Companion.ADD_CHILD_INTENT
|
||||
import com.woka.onboard.OnboardActivity.Companion.LOG_IN_INTENT
|
||||
import com.woka.onboard.OnboardActivity.Companion.ONBOARD_ACTIVITY_INTENT
|
||||
import com.woka.utils.DecisionDialog
|
||||
@@ -89,39 +91,7 @@ class HomeActivity : WokaBaseActivity(),
|
||||
progressView = ProgressView(this)
|
||||
decisionDialog = DecisionDialog(this)
|
||||
|
||||
userPrefs?.userLiveData?.observe(this, this)
|
||||
|
||||
viewModel.logoutLiveData.observe(this){
|
||||
when(it){
|
||||
is ApiResult.Error -> {
|
||||
progressView.hide()
|
||||
toast(it.errorMessage)
|
||||
}
|
||||
is ApiResult.Loading -> {
|
||||
progressView.show(getString(R.string.logging_you_out))
|
||||
}
|
||||
is ApiResult.Success -> {
|
||||
startActivity(Intent(this, OnboardActivity::class.java).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
||||
})
|
||||
finish()
|
||||
|
||||
userPrefs?.logout()
|
||||
}
|
||||
null -> {}
|
||||
}
|
||||
}
|
||||
|
||||
minuteReceiver = object : BroadcastReceiver(){
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
// this function is called every minute
|
||||
if (intent?.action == Intent.ACTION_TIME_TICK){
|
||||
updateBackground()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
registerReceiver(minuteReceiver, IntentFilter(Intent.ACTION_TIME_TICK))
|
||||
setObservers()
|
||||
|
||||
initViews()
|
||||
|
||||
@@ -161,6 +131,61 @@ class HomeActivity : WokaBaseActivity(),
|
||||
unregisterReceiver(minuteReceiver)
|
||||
}
|
||||
|
||||
private fun setObservers(){
|
||||
userPrefs?.userLiveData?.observe(this, this)
|
||||
|
||||
viewModel.logoutLiveData.observe(this){
|
||||
when(it){
|
||||
is ApiResult.Error -> {
|
||||
progressView.hide()
|
||||
toast(it.errorMessage)
|
||||
}
|
||||
is ApiResult.Loading -> {
|
||||
progressView.show(getString(R.string.logging_you_out))
|
||||
}
|
||||
is ApiResult.Success -> {
|
||||
startActivity(Intent(this, OnboardActivity::class.java).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
||||
})
|
||||
finish()
|
||||
|
||||
userPrefs?.logout()
|
||||
}
|
||||
null -> {}
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.deActivateLiveData.observe(this){
|
||||
when(it){
|
||||
is ApiResult.Error -> {
|
||||
progressView.hide()
|
||||
toast(it.errorMessage)
|
||||
}
|
||||
is ApiResult.Loading -> progressView.show()
|
||||
is ApiResult.Success -> {
|
||||
startActivity(Intent(this, OnboardActivity::class.java).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
||||
})
|
||||
finish()
|
||||
|
||||
userPrefs?.logout()
|
||||
}
|
||||
null -> {}
|
||||
}
|
||||
}
|
||||
|
||||
minuteReceiver = object : BroadcastReceiver(){
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
// this function is called every minute
|
||||
if (intent?.action == Intent.ACTION_TIME_TICK){
|
||||
updateBackground()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
registerReceiver(minuteReceiver, IntentFilter(Intent.ACTION_TIME_TICK))
|
||||
}
|
||||
|
||||
private fun initViews() {
|
||||
binding.apply {
|
||||
val versionName = "VER ${BuildConfig.VERSION_NAME}"
|
||||
@@ -180,7 +205,12 @@ class HomeActivity : WokaBaseActivity(),
|
||||
|
||||
getString(R.string.login_register)
|
||||
}else{
|
||||
// hiding menu options
|
||||
// showing menu options
|
||||
val type = userPrefs?.userType
|
||||
if (userPrefs?.userType == UserType.GUARDIAN){
|
||||
sbAddChild.show()
|
||||
}
|
||||
|
||||
sbDeActivateAccount.show()
|
||||
sbMyOrders.show()
|
||||
sbMyProfile.show()
|
||||
@@ -276,6 +306,31 @@ class HomeActivity : WokaBaseActivity(),
|
||||
startActivity(Intent(this@HomeActivity, SupportActivity::class.java),
|
||||
ActivityOptions.makeSceneTransitionAnimation(this@HomeActivity).toBundle())
|
||||
}
|
||||
|
||||
sbMyProfileCard.setOnClickListener {
|
||||
startActivity(Intent(this@HomeActivity, UserProfileActivity::class.java))
|
||||
}
|
||||
|
||||
sbAddChildCard.setOnClickListener {
|
||||
startActivity(Intent(this@HomeActivity, OnboardActivity::class.java)
|
||||
.apply {
|
||||
putExtra(ONBOARD_ACTIVITY_INTENT, ADD_CHILD_INTENT)
|
||||
})
|
||||
}
|
||||
|
||||
sbDeActivateAccountCard.setOnClickListener {
|
||||
decisionDialog.apply {
|
||||
title = getString(R.string.deactivate_woka_account)
|
||||
message =
|
||||
getString(R.string.by_clicking_on_the_button_below_your_account_will_get_deactivated_your_data_will_be_erased_after_a_month)
|
||||
setPositiveButton(getString(R.string.yes)){
|
||||
viewModel.deActivateAccount()
|
||||
}
|
||||
setNegativeButton(getString(R.string.no))
|
||||
show()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,16 +9,12 @@ import androidx.lifecycle.viewModelScope
|
||||
import com.google.android.exoplayer2.ExoPlayer
|
||||
import com.google.android.exoplayer2.MediaItem
|
||||
import com.woka.home.BottomNavigation.Companion.HOME
|
||||
import com.woka.mvvm.UserApiService
|
||||
import com.woka.mvvm.UserRepository
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.networking.RetrofitHelper
|
||||
import com.woka.userdata.UserRepository
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class HomeViewModel: ViewModel(){
|
||||
|
||||
private val userRepository = UserRepository(RetrofitHelper.getRetrofit().create(UserApiService::class.java))
|
||||
|
||||
var selectedBottomTab: Int = HOME
|
||||
var isHomeBackgroundBlurred: Boolean = false
|
||||
|
||||
@@ -30,6 +26,10 @@ class HomeViewModel: ViewModel(){
|
||||
val logoutLiveData: LiveData<ApiResult<Any>?>
|
||||
get() = _logoutLiveData
|
||||
|
||||
private val _deActivateLiveData = MutableLiveData<ApiResult<Any>?>()
|
||||
val deActivateLiveData: LiveData<ApiResult<Any>?>
|
||||
get() = _deActivateLiveData
|
||||
|
||||
var player: ExoPlayer? = null
|
||||
|
||||
fun initPlayer(context: Context) {
|
||||
@@ -51,7 +51,14 @@ class HomeViewModel: ViewModel(){
|
||||
fun logout(){
|
||||
viewModelScope.launch {
|
||||
_logoutLiveData.postValue(ApiResult.Loading())
|
||||
_logoutLiveData.postValue(userRepository.logout())
|
||||
_logoutLiveData.postValue(UserRepository.logout())
|
||||
}
|
||||
}
|
||||
|
||||
fun deActivateAccount(){
|
||||
viewModelScope.launch {
|
||||
_deActivateLiveData.postValue(ApiResult.Loading())
|
||||
_deActivateLiveData.postValue(UserRepository.deActivateAccount())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.Intent.ACTION_TIME_TICK
|
||||
import android.content.IntentFilter
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.LayoutInflater
|
||||
@@ -17,15 +16,13 @@ import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.google.android.exoplayer2.ExoPlayer
|
||||
import com.google.android.exoplayer2.MediaItem
|
||||
import com.woka.R
|
||||
import com.woka.WokaApp.Companion.userPrefs
|
||||
import com.woka.databinding.FragmentHome1Binding
|
||||
import com.woka.home.HomeViewModel
|
||||
import com.woka.home.MoreHomeActivity
|
||||
import com.woka.home.TimePeriod
|
||||
import com.woka.mvvm.userDataModels.UserDataResponse
|
||||
import com.woka.userdata.userDataModels.UserDataResponse
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.players.LiveStreamPlayerActivity
|
||||
import com.woka.utils.UserType
|
||||
|
||||
@@ -1,24 +1,17 @@
|
||||
package com.woka.home.fragments
|
||||
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.media.MediaMetadataRetriever
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.TextureView
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.google.android.exoplayer2.ExoPlayer
|
||||
import com.google.android.exoplayer2.MediaItem
|
||||
import com.woka.R
|
||||
import com.woka.WokaApp
|
||||
import com.woka.databinding.FragmentHome2Binding
|
||||
import com.woka.home.HomeViewModel
|
||||
import com.woka.mvvm.userDataModels.UserDataResponse
|
||||
import com.woka.userdata.userDataModels.UserDataResponse
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.players.LiveStreamPlayerActivity
|
||||
import com.woka.utils.UserType
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.woka.home.sidebar.profile
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.userdata.UserRepository
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class ProfileViewModel: ViewModel() {
|
||||
|
||||
private val _updateProfileLiveData = MutableLiveData<ApiResult<Any>>()
|
||||
val updateProfileLiveData: LiveData<ApiResult<Any>>
|
||||
get() = _updateProfileLiveData
|
||||
|
||||
fun updateProfile(email: String, name: String, gender: String){
|
||||
viewModelScope.launch {
|
||||
_updateProfileLiveData.postValue(ApiResult.Loading())
|
||||
_updateProfileLiveData.postValue(UserRepository.updateProfile(
|
||||
name, email, gender
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
package com.woka.home.sidebar.profile
|
||||
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.transition.Slide
|
||||
import android.view.Gravity.END
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.bumptech.glide.Glide
|
||||
import com.woka.R
|
||||
import com.woka.WokaApp.Companion.userPrefs
|
||||
import com.woka.databinding.ActivityUserProfileBinding
|
||||
import com.woka.userdata.userDataModels.UserData
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.utils.Gender
|
||||
import com.woka.utils.ProgressView
|
||||
import com.woka.utils.WokaBaseActivity
|
||||
import com.woka.utils.hide
|
||||
import com.woka.utils.toast
|
||||
|
||||
class UserProfileActivity : WokaBaseActivity() {
|
||||
|
||||
private lateinit var binding: ActivityUserProfileBinding
|
||||
|
||||
private lateinit var viewModel: ProfileViewModel
|
||||
|
||||
private lateinit var progressView: ProgressView
|
||||
|
||||
private var selectedGender = Gender.NONE
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
binding = ActivityUserProfileBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { v, insets ->
|
||||
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
|
||||
insets
|
||||
}
|
||||
|
||||
viewModel = ViewModelProvider(this)[ProfileViewModel::class.java]
|
||||
progressView = ProgressView(this, getString(R.string.please_wait))
|
||||
|
||||
clickEvents()
|
||||
|
||||
setObservers()
|
||||
}
|
||||
|
||||
private fun clickEvents() {
|
||||
binding.apply {
|
||||
genderM.setOnClickListener { selectGender(Gender.MALE) }
|
||||
genderF.setOnClickListener { selectGender(Gender.FEMALE) }
|
||||
|
||||
backBtn.setOnClickListener {
|
||||
onBackPressedDispatcher.onBackPressed()
|
||||
}
|
||||
|
||||
update.setOnClickListener {
|
||||
if (allOkay()){
|
||||
viewModel.updateProfile(
|
||||
email = email.text.toString(),
|
||||
name = fullName.text.toString(),
|
||||
gender = if (selectedGender == Gender.MALE) {
|
||||
"2"
|
||||
}else{
|
||||
"1"
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setObservers() {
|
||||
userPrefs?.userLiveData?.observe(this){
|
||||
when(it){
|
||||
is ApiResult.Error -> {
|
||||
binding.main.hide()
|
||||
toast(it.errorMessage)
|
||||
}
|
||||
is ApiResult.Loading -> {}
|
||||
is ApiResult.Success -> {
|
||||
it.data?.result?.let { userData ->
|
||||
updateUserData(userData)
|
||||
}
|
||||
}
|
||||
null -> {}
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.updateProfileLiveData.observe(this){
|
||||
when(it){
|
||||
is ApiResult.Error -> {
|
||||
progressView.hide()
|
||||
toast(it.errorMessage)
|
||||
}
|
||||
is ApiResult.Loading -> progressView.show()
|
||||
is ApiResult.Success -> {
|
||||
progressView.hide()
|
||||
toast(it.message)
|
||||
|
||||
val userData = userPrefs?.userData?.copy(
|
||||
fullname = binding.fullName.text.toString()
|
||||
)
|
||||
userPrefs?.updateUserData(userData)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun allOkay(): Boolean{
|
||||
var allOkay = true
|
||||
|
||||
binding.apply {
|
||||
if (fullName.text.isEmpty()){
|
||||
allOkay = false
|
||||
fullName.error = getString(R.string.required)
|
||||
}
|
||||
|
||||
if (selectedGender == Gender.NONE){
|
||||
allOkay = false
|
||||
toast(getString(R.string.select_a_gender))
|
||||
}
|
||||
}
|
||||
|
||||
return allOkay
|
||||
}
|
||||
|
||||
private fun updateUserData(userData: UserData){
|
||||
binding.apply {
|
||||
val userName = ", ${userData.username}"
|
||||
userUsername.text = userName
|
||||
|
||||
userData.avtar?.let {
|
||||
Glide.with(this@UserProfileActivity)
|
||||
.load(it)
|
||||
.placeholder(android.R.color.darker_gray)
|
||||
.placeholder(R.drawable.profile_placeholder)
|
||||
.into(profileImage)
|
||||
}
|
||||
|
||||
fullName.setText(userData.fullname)
|
||||
|
||||
email.text = userData.email
|
||||
|
||||
birthdate.text = userData.birthdate
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private fun selectGender(gender: Gender) {
|
||||
binding.apply {
|
||||
when (gender) {
|
||||
Gender.MALE -> {
|
||||
genderM.setCardBackgroundColor(Color.WHITE)
|
||||
genderM.cardElevation = 5f
|
||||
|
||||
genderF.setCardBackgroundColor(resources.getColor(R.color.white_50))
|
||||
genderF.cardElevation = 0f
|
||||
}
|
||||
|
||||
Gender.FEMALE -> {
|
||||
genderF.setCardBackgroundColor(Color.WHITE)
|
||||
genderF.cardElevation = 5f
|
||||
|
||||
genderM.setCardBackgroundColor(resources.getColor(R.color.white_50))
|
||||
genderM.cardElevation = 0f
|
||||
}
|
||||
|
||||
Gender.NONE -> {
|
||||
genderM.setCardBackgroundColor(resources.getColor(R.color.white_50))
|
||||
genderM.cardElevation = 0f
|
||||
|
||||
genderF.setCardBackgroundColor(resources.getColor(R.color.white_50))
|
||||
genderF.cardElevation = 0f
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
selectedGender = gender
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.woka.home.sidebar.support
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.transition.Slide
|
||||
import android.util.Patterns
|
||||
import android.view.Gravity
|
||||
import android.view.MotionEvent
|
||||
import android.widget.ArrayAdapter
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.core.view.ViewCompat
|
||||
@@ -67,12 +69,15 @@ class SupportActivity : WokaBaseActivity() {
|
||||
is ApiResult.Success -> {
|
||||
progressView.hide()
|
||||
toast(it.message)
|
||||
|
||||
onBackPressedDispatcher.onBackPressed()
|
||||
}
|
||||
null -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
private fun initViews() {
|
||||
binding.apply {
|
||||
|
||||
@@ -93,6 +98,19 @@ class SupportActivity : WokaBaseActivity() {
|
||||
)
|
||||
|
||||
subjectSpinner.setAdapter(adapter)
|
||||
|
||||
message.setOnTouchListener { v, event ->
|
||||
if (message.hasFocus()) {
|
||||
v.parent.requestDisallowInterceptTouchEvent(true)
|
||||
when (event.action and MotionEvent.ACTION_MASK) {
|
||||
MotionEvent.ACTION_SCROLL -> {
|
||||
v.parent.requestDisallowInterceptTouchEvent(false)
|
||||
return@setOnTouchListener true
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,6 @@ interface ModuleApiService {
|
||||
@POST("guest_queries_store")
|
||||
suspend fun supportForGuest(@Body body: FormBody): Response<ApiResponse<Any>>
|
||||
|
||||
@POST("guest_queries_store")
|
||||
@POST("user_queries_store")
|
||||
suspend fun supportForUser(@Body body: FormBody): Response<ApiResponse<Any>>
|
||||
}
|
||||
@@ -23,7 +23,7 @@ object ModuleRepository {
|
||||
|
||||
suspend fun supportForUser(userId: String, subject: String, message: String): ApiResult<Any> {
|
||||
return RetrofitHelper.handleApiCall {
|
||||
moduleApiService.supportForGuest(
|
||||
moduleApiService.supportForUser(
|
||||
FormBody.Builder()
|
||||
.add("user_id", userId)
|
||||
.add("subject", subject)
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.woka.mvvm
|
||||
|
||||
import com.woka.mvvm.userDataModels.UserDataResponse
|
||||
import com.woka.networking.ApiResponse
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.GET
|
||||
|
||||
interface UserApiService {
|
||||
|
||||
@GET("get_user_data")
|
||||
suspend fun getUserData(): Response<ApiResponse<UserDataResponse>>
|
||||
|
||||
@GET("user_logout")
|
||||
suspend fun logout(): Response<ApiResponse<Any>>
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.woka.mvvm
|
||||
|
||||
import com.woka.mvvm.userDataModels.UserDataResponse
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.networking.RetrofitHelper.handleApiCall
|
||||
|
||||
class UserRepository(private val userApiService: UserApiService) {
|
||||
|
||||
suspend fun getUserData(): ApiResult<UserDataResponse>{
|
||||
return handleApiCall{
|
||||
userApiService.getUserData()
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun logout(): ApiResult<Any>{
|
||||
return handleApiCall {
|
||||
userApiService.logout()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,13 @@ import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.navigation.NavOptions
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
import com.woka.R
|
||||
import com.woka.WokaApp.Companion.userPrefs
|
||||
import com.woka.onboard.fragments.GetCodeFragment
|
||||
import com.woka.onboard.fragments.GetCodeFragment.Companion.EMAIL_ARG
|
||||
import com.woka.onboard.fragments.GetEmailFragment
|
||||
import com.woka.onboard.fragments.GetEmailFragment.Companion.IS_UNDER_16
|
||||
import com.woka.onboard.fragments.SignUpFragment
|
||||
import com.woka.onboard.fragments.SignUpFragment.Companion.ADD_CHILD_EVENT
|
||||
import com.woka.utils.WokaBaseActivity
|
||||
|
||||
class OnboardActivity : WokaBaseActivity() {
|
||||
@@ -16,6 +23,8 @@ class OnboardActivity : WokaBaseActivity() {
|
||||
const val ONBOARD_ACTIVITY_INTENT = "onboard_act_intent"
|
||||
|
||||
const val LOG_IN_INTENT = "login_intent"
|
||||
|
||||
const val ADD_CHILD_INTENT = "add_child_intent"
|
||||
}
|
||||
|
||||
private var player: MediaPlayer? = null
|
||||
@@ -40,6 +49,20 @@ class OnboardActivity : WokaBaseActivity() {
|
||||
.setPopUpTo(R.id.onboardFragment, true)
|
||||
.build()
|
||||
)
|
||||
}else if (intent.getStringExtra(ONBOARD_ACTIVITY_INTENT) == ADD_CHILD_INTENT){
|
||||
val hostFragment =
|
||||
supportFragmentManager.findFragmentById(R.id.fc_onboard) as NavHostFragment
|
||||
hostFragment.navController.navigate(
|
||||
R.id.action_onboardFragment_to_signUpFragment,
|
||||
Bundle().apply {
|
||||
putBoolean(IS_UNDER_16, true)
|
||||
putString(EMAIL_ARG, userPrefs?.userData?.email)
|
||||
putBoolean(ADD_CHILD_EVENT, true)
|
||||
},
|
||||
NavOptions.Builder()
|
||||
.setPopUpTo(R.id.onboardFragment, true)
|
||||
.build()
|
||||
)
|
||||
}
|
||||
|
||||
player = MediaPlayer.create(this, R.raw.audiotwo)
|
||||
|
||||
@@ -9,20 +9,26 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.woka.R
|
||||
import com.woka.WokaApp.Companion.userPrefs
|
||||
import com.woka.databinding.FragmentSelectAvatarBinding
|
||||
import com.woka.home.HomeActivity
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.networking.RetrofitHelper
|
||||
import com.woka.onboard.AvatarAdapter
|
||||
import com.woka.onboard.fragments.GetEmailFragment.Companion.IS_UNDER_16
|
||||
import com.woka.onboard.models.Avatar
|
||||
import com.woka.onboard.models.RegisterRequestData
|
||||
import com.woka.onboard.mvvm.OnboardViewModel
|
||||
import com.woka.userdata.UserRepository
|
||||
import com.woka.utils.Gender
|
||||
import com.woka.utils.ProgressView
|
||||
import com.woka.utils.UserType
|
||||
import com.woka.utils.toast
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Locale
|
||||
|
||||
@@ -47,7 +53,7 @@ class SelectAvatarFragment : Fragment() {
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
): View {
|
||||
binding = FragmentSelectAvatarBinding.inflate(inflater, container, false)
|
||||
activity?.let {
|
||||
viewModel = ViewModelProvider(it)[OnboardViewModel::class.java]
|
||||
@@ -133,23 +139,32 @@ class SelectAvatarFragment : Fragment() {
|
||||
progressView.show(getString(R.string.please_wait))
|
||||
}
|
||||
is ApiResult.Success -> {
|
||||
progressView.hide()
|
||||
|
||||
activity?.let {activity ->
|
||||
toast(it.message)
|
||||
|
||||
it.data?.result?.let { result->
|
||||
lifecycleScope.launch {
|
||||
// logging out
|
||||
if (userPrefs?.userType == UserType.GUARDIAN || userPrefs?.userType == UserType.CHILD){
|
||||
progressView.show(getString(R.string.logging_you_out))
|
||||
UserRepository.logout()
|
||||
}
|
||||
|
||||
// saving to user prefs
|
||||
userPrefs?.accessToken = result.remember_token?:"no_token_received"
|
||||
userPrefs?.userType = UserType.createUserType(result.user_type)
|
||||
// saving to user prefs
|
||||
userPrefs?.accessToken = result.remember_token?:"no_token_received"
|
||||
userPrefs?.userType = UserType.createUserType(result.user_type)
|
||||
|
||||
userPrefs?.loadUserData()
|
||||
userPrefs?.loadUserData()
|
||||
|
||||
startActivity(Intent(activity, HomeActivity::class.java).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
||||
})
|
||||
activity.finish()
|
||||
progressView.hide()
|
||||
startActivity(Intent(activity, HomeActivity::class.java).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
||||
})
|
||||
activity.finish()
|
||||
}
|
||||
}
|
||||
progressView.hide()
|
||||
}
|
||||
}
|
||||
null -> {}
|
||||
|
||||
@@ -33,6 +33,8 @@ class SignInFragment : Fragment() {
|
||||
|
||||
private lateinit var dialog: DecisionDialog
|
||||
|
||||
private lateinit var deactivatedDialog: DecisionDialog
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
@@ -59,6 +61,21 @@ class SignInFragment : Fragment() {
|
||||
|
||||
setNegativeButton(getString(R.string.no))
|
||||
}
|
||||
|
||||
deactivatedDialog = DecisionDialog(it).apply {
|
||||
title = getString(R.string.activate_woka_account)
|
||||
message = getString(R.string.would_you_like_to_re_activate_your_account)
|
||||
|
||||
setPositiveButton(getString(R.string.yes)){
|
||||
viewModel.loginProceed(
|
||||
binding.username.text.toString(),
|
||||
binding.password.text.toString(),
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
setNegativeButton(getString(R.string.no))
|
||||
}
|
||||
}
|
||||
|
||||
clickEvents()
|
||||
@@ -80,7 +97,9 @@ class SignInFragment : Fragment() {
|
||||
is ApiResult.Success -> {
|
||||
progressView.hide()
|
||||
it.data?.result?.let {data->
|
||||
if (data.already_logged_in){
|
||||
if (data.is_deactive){
|
||||
deactivatedDialog.show()
|
||||
}else if (data.already_logged_in){
|
||||
dialog.show()
|
||||
}else{
|
||||
toast(it.message)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.woka.onboard.fragments
|
||||
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
@@ -20,13 +21,26 @@ import com.woka.utils.PARENT_TYPE
|
||||
import com.woka.utils.ProgressView
|
||||
import com.woka.utils.toast
|
||||
|
||||
/*
|
||||
This fragment is opened for two intents
|
||||
|
||||
1. The normal registration flow
|
||||
2. Adding child from home
|
||||
|
||||
*/
|
||||
class SignUpFragment : Fragment() {
|
||||
|
||||
companion object{
|
||||
const val ADD_CHILD_EVENT = "add_child_event"
|
||||
}
|
||||
|
||||
private lateinit var binding: FragmentSignUpBinding
|
||||
|
||||
private var isUnder16 = false
|
||||
private var email: String? = null
|
||||
|
||||
private var addChildIntent = false
|
||||
|
||||
private lateinit var viewModel: OnboardViewModel
|
||||
private lateinit var progressView: ProgressView
|
||||
|
||||
@@ -35,6 +49,7 @@ class SignUpFragment : Fragment() {
|
||||
arguments?.let {
|
||||
isUnder16 = it.getBoolean(IS_UNDER_16, false)
|
||||
email = it.getString(EMAIL_ARG)
|
||||
addChildIntent = it.getBoolean(ADD_CHILD_EVENT, false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +62,7 @@ class SignUpFragment : Fragment() {
|
||||
activity?.let {
|
||||
viewModel = ViewModelProvider(it)[OnboardViewModel::class.java]
|
||||
progressView = ProgressView(it)
|
||||
it.window?.statusBarColor = Color.parseColor("#6ed5fe")
|
||||
}
|
||||
|
||||
initViews()
|
||||
@@ -101,13 +117,22 @@ class SignUpFragment : Fragment() {
|
||||
|
||||
private fun initViews() {
|
||||
binding.apply {
|
||||
if (isUnder16) {
|
||||
if (isUnder16 && !addChildIntent) {
|
||||
doNotShare.visibility = VISIBLE
|
||||
}
|
||||
|
||||
name.setText(viewModel.name)
|
||||
username.setText(viewModel.userName)
|
||||
password.setText(viewModel.password)
|
||||
|
||||
if (addChildIntent){
|
||||
title.text = getString(R.string.add_child_account)
|
||||
usernameTitle.text = getString(R.string.username)
|
||||
nameTitle.text = getString(R.string.child_name)
|
||||
passwordTitle.text = getString(R.string.password)
|
||||
|
||||
viewModel.email = email
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,12 +4,9 @@ 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
|
||||
@@ -19,9 +16,8 @@ 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.userdata.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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.woka.onboard.models
|
||||
|
||||
import com.woka.mvvm.userDataModels.UserData
|
||||
import com.woka.userdata.userDataModels.UserData
|
||||
|
||||
data class LoginResponse(
|
||||
val result: UserData?
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.woka.onboard.models
|
||||
|
||||
import com.woka.mvvm.userDataModels.UserData
|
||||
import com.woka.userdata.userDataModels.UserData
|
||||
|
||||
data class RegisterResponse(
|
||||
val result: UserData
|
||||
|
||||
@@ -33,12 +33,13 @@ class OnboardRepository(private val apiService: OnboardApiService) {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun loginProceed(userName: String, password: String): ApiResult<LoginResponse> {
|
||||
suspend fun loginProceed(userName: String, password: String, isActivate: Boolean): ApiResult<LoginResponse> {
|
||||
return handleApiCall {
|
||||
apiService.loginProceed(
|
||||
FormBody.Builder()
|
||||
.add("username", userName)
|
||||
.add("password", password)
|
||||
.add("is_activate", if (isActivate) "1" else "0")
|
||||
.build()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -141,10 +141,10 @@ class OnboardViewModel: ViewModel(){
|
||||
}
|
||||
}
|
||||
|
||||
fun loginProceed(userName: String, password: String){
|
||||
fun loginProceed(userName: String, password: String, isActivate: Boolean = false){
|
||||
viewModelScope.launch {
|
||||
_loginProceedLiveData.postValue(ApiResult.Loading())
|
||||
val response = repository.loginProceed(userName, password)
|
||||
val response = repository.loginProceed(userName, password, isActivate)
|
||||
_loginProceedLiveData.postValue(response)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,17 +4,14 @@ import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Context.MODE_PRIVATE
|
||||
import android.content.SharedPreferences
|
||||
import android.provider.Settings
|
||||
import android.provider.Settings.Secure
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.woka.home.Theme
|
||||
import com.woka.mvvm.UserApiService
|
||||
import com.woka.mvvm.UserRepository
|
||||
import com.woka.mvvm.userDataModels.UserData
|
||||
import com.woka.mvvm.userDataModels.UserDataResponse
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.networking.RetrofitHelper
|
||||
import com.woka.userdata.UserRepository
|
||||
import com.woka.userdata.userDataModels.UserData
|
||||
import com.woka.userdata.userDataModels.UserDataResponse
|
||||
import com.woka.utils.UserType
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -38,6 +35,27 @@ class UserPreference(context: Context) {
|
||||
val deviceId: String = Secure.getString(context.contentResolver, Secure.ANDROID_ID)
|
||||
|
||||
var userData: UserData? = null
|
||||
private set
|
||||
|
||||
fun updateUserData(userData: UserData?){
|
||||
when (val currentData = userLiveData.value){
|
||||
is ApiResult.Error -> {}
|
||||
is ApiResult.Loading -> {}
|
||||
is ApiResult.Success -> {
|
||||
_userLiveData.postValue(
|
||||
ApiResult.Success(
|
||||
UserDataResponse(
|
||||
userData,
|
||||
currentData.data?.userNotificationsCount
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
this.userData = userData
|
||||
}
|
||||
null -> {}
|
||||
}
|
||||
}
|
||||
|
||||
var appLanguage: String
|
||||
get() = userPrefs.getString(APP_LANGUAGE, "en") ?: "en"
|
||||
@@ -58,9 +76,6 @@ class UserPreference(context: Context) {
|
||||
get() = userPrefs.getString(GUEST_USER_NAME, null)
|
||||
set(value) = userPrefs.edit().putString(GUEST_USER_NAME, value).apply()
|
||||
|
||||
private val userRepository =
|
||||
UserRepository(RetrofitHelper.getRetrofit().create(UserApiService::class.java))
|
||||
|
||||
private val _userLiveData = MutableLiveData<ApiResult<UserDataResponse>?>()
|
||||
val userLiveData: LiveData<ApiResult<UserDataResponse>?>
|
||||
get() = _userLiveData
|
||||
@@ -68,7 +83,7 @@ class UserPreference(context: Context) {
|
||||
fun loadUserData() {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
_userLiveData.postValue(ApiResult.Loading())
|
||||
val result = userRepository.getUserData()
|
||||
val result = UserRepository.getUserData()
|
||||
|
||||
when (result){
|
||||
is ApiResult.Error -> {}
|
||||
|
||||
24
app/src/main/java/com/woka/userdata/UserApiService.kt
Normal file
24
app/src/main/java/com/woka/userdata/UserApiService.kt
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.woka.userdata
|
||||
|
||||
import com.woka.userdata.userDataModels.UserDataResponse
|
||||
import com.woka.networking.ApiResponse
|
||||
import okhttp3.FormBody
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.POST
|
||||
|
||||
interface UserApiService {
|
||||
|
||||
@GET("get_user_data")
|
||||
suspend fun getUserData(): Response<ApiResponse<UserDataResponse>>
|
||||
|
||||
@GET("user_logout")
|
||||
suspend fun logout(): Response<ApiResponse<Any>>
|
||||
|
||||
@POST("update_profile")
|
||||
suspend fun updateProfile(@Body formBody: FormBody): Response<ApiResponse<Any>>
|
||||
|
||||
@GET("user_deactivate_account")
|
||||
suspend fun deActivateAccount(): Response<ApiResponse<Any>>
|
||||
}
|
||||
42
app/src/main/java/com/woka/userdata/UserRepository.kt
Normal file
42
app/src/main/java/com/woka/userdata/UserRepository.kt
Normal file
@@ -0,0 +1,42 @@
|
||||
package com.woka.userdata
|
||||
|
||||
import com.woka.userdata.userDataModels.UserDataResponse
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.networking.RetrofitHelper
|
||||
import com.woka.networking.RetrofitHelper.handleApiCall
|
||||
import okhttp3.FormBody
|
||||
|
||||
object UserRepository {
|
||||
|
||||
private val userApiService = RetrofitHelper.getRetrofit().create(UserApiService::class.java)
|
||||
|
||||
suspend fun getUserData(): ApiResult<UserDataResponse>{
|
||||
return handleApiCall{
|
||||
userApiService.getUserData()
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun logout(): ApiResult<Any>{
|
||||
return handleApiCall {
|
||||
userApiService.logout()
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun updateProfile(name: String, email: String, gender: String): ApiResult<Any>{
|
||||
return handleApiCall {
|
||||
userApiService.updateProfile(
|
||||
FormBody.Builder()
|
||||
.add("fullname", name)
|
||||
.add("email", email)
|
||||
.add("gender", gender)
|
||||
.build()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun deActivateAccount(): ApiResult<Any>{
|
||||
return handleApiCall {
|
||||
userApiService.deActivateAccount()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.woka.mvvm.userDataModels
|
||||
package com.woka.userdata.userDataModels
|
||||
|
||||
data class ChildDetail(
|
||||
val avatar_name: String?,
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.woka.mvvm.userDataModels
|
||||
package com.woka.userdata.userDataModels
|
||||
|
||||
data class Gender(
|
||||
val gender_name: String?,
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.woka.mvvm.userDataModels
|
||||
package com.woka.userdata.userDataModels
|
||||
|
||||
data class InterestTopic(
|
||||
val id: Int?,
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.woka.mvvm.userDataModels
|
||||
package com.woka.userdata.userDataModels
|
||||
|
||||
data class Language(
|
||||
val id: Int?,
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.woka.mvvm.userDataModels
|
||||
package com.woka.userdata.userDataModels
|
||||
|
||||
data class UserData(
|
||||
val already_logged_in: Boolean,
|
||||
val is_deactive: Boolean,
|
||||
val avtar: String?,
|
||||
val birthdate: String?,
|
||||
val child_detail: ChildDetail?,
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.woka.mvvm.userDataModels
|
||||
package com.woka.userdata.userDataModels
|
||||
|
||||
data class UserDataResponse(
|
||||
val result: UserData?,
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.woka.mvvm.userDataModels
|
||||
package com.woka.userdata.userDataModels
|
||||
|
||||
data class UserNotificationData(
|
||||
val created_at: String?,
|
||||
@@ -1,5 +1,5 @@
|
||||
package com.woka.utils
|
||||
|
||||
enum class Gender(value: Int){
|
||||
enum class Gender(val value: Int){
|
||||
MALE(0), FEMALE(1), NONE(-1)
|
||||
}
|
||||
Reference in New Issue
Block a user