Extension for toast
This commit is contained in:
@@ -16,15 +16,18 @@
|
||||
android:theme="@style/Theme.Woka"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".onboard.OnboardActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:windowSoftInputMode="adjustPan"
|
||||
android:name=".home.HomeActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".onboard.WelcomeActivity"
|
||||
android:name=".onboard.OnboardActivity"
|
||||
android:exported="false"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/Theme.App.Starting"
|
||||
android:exported="true">
|
||||
android:windowSoftInputMode="adjustPan" />
|
||||
<activity
|
||||
android:name=".onboard.WelcomeActivity"
|
||||
android:exported="true"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/Theme.App.Starting">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
|
||||
21
app/src/main/java/com/woka/home/HomeActivity.kt
Normal file
21
app/src/main/java/com/woka/home/HomeActivity.kt
Normal file
@@ -0,0 +1,21 @@
|
||||
package com.woka.home
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import com.woka.R
|
||||
|
||||
class HomeActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
setContentView(R.layout.activity_home)
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,9 @@ import android.media.MediaPlayer
|
||||
import android.os.Bundle
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.navigation.NavOptions
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
import com.woka.R
|
||||
import com.woka.utils.WokaBaseActivity
|
||||
|
||||
@@ -23,6 +24,13 @@ class OnboardActivity : WokaBaseActivity() {
|
||||
insets
|
||||
}
|
||||
|
||||
// val hostFragment = supportFragmentManager.findFragmentById(R.id.fc_onboard) as NavHostFragment
|
||||
// hostFragment.navController.navigate(R.id.action_onboardFragment_to_signInFragment,
|
||||
// null,
|
||||
// NavOptions.Builder()
|
||||
// .setPopUpTo(R.id.onboardFragment, true)
|
||||
// .build())
|
||||
|
||||
player = MediaPlayer.create(this, R.raw.audiotwo)
|
||||
player?.isLooping = true
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.woka.utils.CHILD_TYPE
|
||||
import com.woka.utils.PARENT_TYPE
|
||||
import com.woka.utils.ProgressView
|
||||
import com.woka.utils.closeKeyboard
|
||||
import com.woka.utils.toast
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/*
|
||||
@@ -87,7 +88,7 @@ class GetCodeFragment : Fragment() {
|
||||
when (it) {
|
||||
is ApiResult.Error -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.errorMessage}", Toast.LENGTH_SHORT).show()
|
||||
toast(it.errorMessage)
|
||||
}
|
||||
|
||||
is ApiResult.Loading -> {
|
||||
@@ -96,10 +97,7 @@ class GetCodeFragment : Fragment() {
|
||||
|
||||
is ApiResult.Success -> {
|
||||
viewModel.startOTPTimeCountDown()
|
||||
Toast.makeText(
|
||||
activity,
|
||||
"${it.message}", Toast.LENGTH_SHORT
|
||||
).show()
|
||||
toast(it.message)
|
||||
progressView.hide()
|
||||
uniqueString = it.data?.unique_string ?: ""
|
||||
|
||||
@@ -115,7 +113,7 @@ class GetCodeFragment : Fragment() {
|
||||
when (it) {
|
||||
is ApiResult.Error -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.errorMessage}", Toast.LENGTH_SHORT).show()
|
||||
activity?.toast(it.errorMessage)
|
||||
}
|
||||
|
||||
is ApiResult.Loading -> {
|
||||
@@ -124,7 +122,7 @@ class GetCodeFragment : Fragment() {
|
||||
|
||||
is ApiResult.Success -> {
|
||||
viewModel.startOTPTimeCountDown()
|
||||
Toast.makeText(activity, "${it.message}", Toast.LENGTH_SHORT).show()
|
||||
activity?.toast(it.message)
|
||||
progressView.hide()
|
||||
|
||||
viewModel.clearForgotPwdSendOTPData()
|
||||
@@ -138,7 +136,7 @@ class GetCodeFragment : Fragment() {
|
||||
when (it) {
|
||||
is ApiResult.Error -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.errorMessage}", Toast.LENGTH_SHORT).show()
|
||||
toast(it.errorMessage)
|
||||
}
|
||||
|
||||
is ApiResult.Loading -> {
|
||||
@@ -154,8 +152,7 @@ class GetCodeFragment : Fragment() {
|
||||
val listOfChild = viewModel.getChildList(email)
|
||||
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.message}", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
toast(it.message)
|
||||
|
||||
if (listOfChild is ApiResult.Error) {
|
||||
if (listOfChild.error is NoSuccessError) {
|
||||
@@ -163,11 +160,7 @@ class GetCodeFragment : Fragment() {
|
||||
gotoSignUpFragment()
|
||||
} else {
|
||||
// some other error happened
|
||||
Toast.makeText(
|
||||
activity,
|
||||
"${listOfChild.errorMessage}",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
toast(listOfChild.errorMessage)
|
||||
}
|
||||
} else if (listOfChild is ApiResult.Success && listOfChild.data?.result != null) {
|
||||
// child list is available
|
||||
@@ -188,8 +181,7 @@ class GetCodeFragment : Fragment() {
|
||||
} else {
|
||||
// child type
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.message}", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
toast(it.message)
|
||||
|
||||
gotoSignUpFragment()
|
||||
}
|
||||
@@ -203,7 +195,7 @@ class GetCodeFragment : Fragment() {
|
||||
when (it) {
|
||||
is ApiResult.Error -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.errorMessage}", Toast.LENGTH_SHORT).show()
|
||||
toast(it.errorMessage)
|
||||
}
|
||||
|
||||
is ApiResult.Loading -> {
|
||||
@@ -212,11 +204,7 @@ class GetCodeFragment : Fragment() {
|
||||
|
||||
is ApiResult.Success -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(
|
||||
activity,
|
||||
"${it.message}", Toast.LENGTH_SHORT
|
||||
)
|
||||
.show()
|
||||
toast(it.message)
|
||||
|
||||
findNavController().navigate(R.id.action_getCodeFragment_to_newPasswordFragment2,
|
||||
Bundle().apply
|
||||
@@ -344,10 +332,7 @@ class GetCodeFragment : Fragment() {
|
||||
private fun getOTP(): String? {
|
||||
binding.apply {
|
||||
if (et1.text.isEmpty() || et2.text.isEmpty() || et3.text.isEmpty() || et4.text.isEmpty()) {
|
||||
Toast.makeText(
|
||||
activity,
|
||||
getString(R.string.please_enter_otp_code), Toast.LENGTH_SHORT
|
||||
).show()
|
||||
toast(getString(R.string.please_enter_otp_code))
|
||||
return null
|
||||
}
|
||||
return "${et1.text}${et2.text}${et3.text}${et4.text}"
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.woka.onboard.mvvm.OnboardViewModel
|
||||
import com.woka.utils.CHILD_TYPE
|
||||
import com.woka.utils.PARENT_TYPE
|
||||
import com.woka.utils.ProgressView
|
||||
import com.woka.utils.toast
|
||||
|
||||
/*
|
||||
This fragment is to get the email user input
|
||||
@@ -75,7 +76,7 @@ class GetEmailFragment : Fragment() {
|
||||
when (it) {
|
||||
is ApiResult.Error -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.errorMessage}", Toast.LENGTH_SHORT).show()
|
||||
toast(it.errorMessage)
|
||||
}
|
||||
|
||||
is ApiResult.Loading -> {
|
||||
@@ -99,7 +100,7 @@ class GetEmailFragment : Fragment() {
|
||||
when (it) {
|
||||
is ApiResult.Error -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.errorMessage}", Toast.LENGTH_SHORT).show()
|
||||
toast(it.errorMessage)
|
||||
}
|
||||
|
||||
is ApiResult.Loading -> {
|
||||
@@ -129,7 +130,7 @@ class GetEmailFragment : Fragment() {
|
||||
when (it) {
|
||||
is ApiResult.Error -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.errorMessage}", Toast.LENGTH_SHORT).show()
|
||||
toast(it.errorMessage)
|
||||
}
|
||||
|
||||
is ApiResult.Loading -> {
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.woka.onboard.fragments.GetEmailFragment.Companion.IS_UNDER_16
|
||||
import com.woka.onboard.models.Interest
|
||||
import com.woka.onboard.mvvm.OnboardViewModel
|
||||
import com.woka.utils.Gender
|
||||
import com.woka.utils.toast
|
||||
import java.util.Calendar
|
||||
|
||||
class GetMoreInfoFragment : Fragment() {
|
||||
@@ -88,12 +89,11 @@ class GetMoreInfoFragment : Fragment() {
|
||||
|
||||
next.setOnClickListener {
|
||||
if (viewModel.selectedGender == Gender.NONE) {
|
||||
Toast.makeText(activity, getString(R.string.select_a_gender), Toast.LENGTH_SHORT).show()
|
||||
toast(getString(R.string.select_a_gender))
|
||||
return@setOnClickListener
|
||||
}
|
||||
if (isUnder16 && viewModel.interestTopics.isEmpty()){
|
||||
Toast.makeText(activity,
|
||||
getString(R.string.please_select_your_interests), Toast.LENGTH_SHORT).show()
|
||||
toast(getString(R.string.please_select_your_interests))
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.woka.networking.ApiResult
|
||||
import com.woka.onboard.fragments.GetCodeFragment.Companion.EMAIL_ARG
|
||||
import com.woka.onboard.mvvm.OnboardViewModel
|
||||
import com.woka.utils.ProgressView
|
||||
import com.woka.utils.toast
|
||||
|
||||
class NewPasswordFragment : Fragment() {
|
||||
|
||||
@@ -52,14 +53,14 @@ class NewPasswordFragment : Fragment() {
|
||||
when(it){
|
||||
is ApiResult.Error -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.errorMessage}", Toast.LENGTH_SHORT).show()
|
||||
toast(it.errorMessage)
|
||||
}
|
||||
is ApiResult.Loading -> {
|
||||
progressView.show()
|
||||
}
|
||||
is ApiResult.Success -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.message}", Toast.LENGTH_SHORT).show()
|
||||
toast(it.message)
|
||||
findNavController().popBackStack(R.id.signInFragment, false)
|
||||
}
|
||||
null -> {}
|
||||
@@ -97,15 +98,13 @@ class NewPasswordFragment : Fragment() {
|
||||
password.text?.let { pwdTxt ->
|
||||
if (pwdTxt.length < 6){
|
||||
allOkay = false
|
||||
Toast.makeText(activity,
|
||||
getString(R.string.must_be_at_least_6_characters), Toast.LENGTH_SHORT).show()
|
||||
toast(getString(R.string.must_be_at_least_6_characters))
|
||||
}else {
|
||||
// password is valid
|
||||
confirmPassword.text?.let {confirmPwdTxt ->
|
||||
if (confirmPwdTxt.toString() != pwdTxt.toString()){
|
||||
allOkay = false
|
||||
Toast.makeText(activity,
|
||||
getString(R.string.password_does_not_match), Toast.LENGTH_SHORT).show()
|
||||
toast(getString(R.string.password_does_not_match))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.woka.onboard.fragments
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.fragment.app.Fragment
|
||||
@@ -11,6 +12,7 @@ import androidx.lifecycle.ViewModelProvider
|
||||
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.onboard.AvatarAdapter
|
||||
import com.woka.onboard.fragments.GetEmailFragment.Companion.IS_UNDER_16
|
||||
@@ -19,6 +21,7 @@ import com.woka.onboard.models.RegisterRequestData
|
||||
import com.woka.onboard.mvvm.OnboardViewModel
|
||||
import com.woka.utils.Gender
|
||||
import com.woka.utils.ProgressView
|
||||
import com.woka.utils.toast
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Locale
|
||||
|
||||
@@ -62,8 +65,7 @@ class SelectAvatarFragment : Fragment() {
|
||||
|
||||
next.setOnClickListener {
|
||||
if (viewModel.selectedAvatarPos == null) {
|
||||
Toast.makeText(activity,
|
||||
getString(R.string.please_select_an_avatar), Toast.LENGTH_SHORT).show()
|
||||
toast(getString(R.string.please_select_an_avatar))
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
@@ -84,7 +86,6 @@ class SelectAvatarFragment : Fragment() {
|
||||
)
|
||||
}
|
||||
|
||||
Log.d("aditya_testing", "clickEvents: $registerRequestData")
|
||||
viewModel.registerUser(registerRequestData)
|
||||
}
|
||||
}
|
||||
@@ -96,7 +97,7 @@ class SelectAvatarFragment : Fragment() {
|
||||
when (it) {
|
||||
is ApiResult.Error -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.errorMessage}", Toast.LENGTH_SHORT).show()
|
||||
toast(it.errorMessage)
|
||||
}
|
||||
|
||||
is ApiResult.Loading -> {
|
||||
@@ -125,16 +126,19 @@ class SelectAvatarFragment : Fragment() {
|
||||
when (it) {
|
||||
is ApiResult.Error -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.errorMessage}", Toast.LENGTH_SHORT).show()
|
||||
toast(it.errorMessage)
|
||||
}
|
||||
is ApiResult.Loading -> {
|
||||
progressView.show(getString(R.string.please_wait))
|
||||
}
|
||||
is ApiResult.Success -> {
|
||||
progressView.hide()
|
||||
Log.d("aditya_testing", "onViewCreated: ${it.data}")
|
||||
Toast.makeText(activity, "${it.message}", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
activity?.let {activity ->
|
||||
toast(it.message)
|
||||
|
||||
startActivity(Intent(activity, HomeActivity::class.java))
|
||||
activity.finish()
|
||||
}
|
||||
}
|
||||
null -> {}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.woka.onboard.fragments.GetEmailFragment.Companion.IS_RESET_PASSWORD_I
|
||||
import com.woka.onboard.mvvm.OnboardViewModel
|
||||
import com.woka.utils.DecisionDialog
|
||||
import com.woka.utils.ProgressView
|
||||
import com.woka.utils.toast
|
||||
|
||||
class SignInFragment : Fragment() {
|
||||
|
||||
@@ -67,7 +68,7 @@ class SignInFragment : Fragment() {
|
||||
when(it){
|
||||
is ApiResult.Error -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.errorMessage}", Toast.LENGTH_SHORT).show()
|
||||
toast(it.errorMessage)
|
||||
}
|
||||
is ApiResult.Loading -> {
|
||||
progressView.show()
|
||||
@@ -78,7 +79,7 @@ class SignInFragment : Fragment() {
|
||||
if (data.already_logged_in){
|
||||
dialog.show()
|
||||
}else{
|
||||
Toast.makeText(activity, "${it.message}", Toast.LENGTH_SHORT).show()
|
||||
toast(it.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,14 +91,15 @@ class SignInFragment : Fragment() {
|
||||
when(it){
|
||||
is ApiResult.Error -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.errorMessage}", Toast.LENGTH_SHORT).show()
|
||||
toast(it.errorMessage)
|
||||
|
||||
}
|
||||
is ApiResult.Loading -> {
|
||||
progressView.show()
|
||||
}
|
||||
is ApiResult.Success -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.message}", Toast.LENGTH_SHORT).show()
|
||||
toast(it.message)
|
||||
}
|
||||
null -> {}
|
||||
}
|
||||
@@ -134,13 +136,12 @@ class SignInFragment : Fragment() {
|
||||
|
||||
password.text?.let { password ->
|
||||
if (password.length < 6){
|
||||
Toast.makeText(activity,
|
||||
getString(R.string.password_must_be_at_least_6_characters), Toast.LENGTH_SHORT).show()
|
||||
toast(getString(R.string.password_must_be_at_least_6_characters))
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
viewModel.login(username.text.toString(), password.toString())
|
||||
}?:Toast.makeText(activity, getString(R.string.something_went_wrong), Toast.LENGTH_SHORT).show()
|
||||
}?:toast(getString(R.string.something_went_wrong))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.woka.onboard.mvvm.OnboardViewModel
|
||||
import com.woka.utils.CHILD_TYPE
|
||||
import com.woka.utils.PARENT_TYPE
|
||||
import com.woka.utils.ProgressView
|
||||
import com.woka.utils.toast
|
||||
|
||||
class SignUpFragment : Fragment() {
|
||||
|
||||
@@ -62,7 +63,7 @@ class SignUpFragment : Fragment() {
|
||||
when (it) {
|
||||
is ApiResult.Error -> {
|
||||
progressView.hide()
|
||||
Toast.makeText(activity, "${it.errorMessage}", Toast.LENGTH_SHORT).show()
|
||||
toast(it.errorMessage)
|
||||
}
|
||||
|
||||
is ApiResult.Loading -> {
|
||||
@@ -121,9 +122,7 @@ class SignUpFragment : Fragment() {
|
||||
email?.let {
|
||||
val userType = if (isUnder16) CHILD_TYPE else PARENT_TYPE
|
||||
viewModel.checkUserNameExist(it, username.text.toString(), userType)
|
||||
} ?: Toast.makeText(activity,
|
||||
getString(R.string.something_went_wrong), Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
} ?: toast(getString(R.string.something_went_wrong))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,11 +144,7 @@ class SignUpFragment : Fragment() {
|
||||
|
||||
if (password.text != null && password.text!!.length < 6) {
|
||||
allOkay = false
|
||||
Toast.makeText(
|
||||
activity,
|
||||
getString(R.string.password_must_be_at_least_6_characters),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
toast(getString(R.string.password_must_be_at_least_6_characters))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ import android.view.View
|
||||
import android.view.View.GONE
|
||||
import android.view.View.VISIBLE
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.woka.WokaApp.Companion.userPrefs
|
||||
import java.util.Locale
|
||||
|
||||
@@ -39,4 +41,12 @@ fun Activity.closeKeyboard(){
|
||||
(this.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager)
|
||||
.hideSoftInputFromWindow(it.windowToken, 0)
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.toast(text: String?, length: Int = Toast.LENGTH_SHORT){
|
||||
Toast.makeText(this, "$text", length).show()
|
||||
}
|
||||
|
||||
fun Fragment.toast(text: String?, length: Int = Toast.LENGTH_SHORT){
|
||||
activity?.toast(text, length)
|
||||
}
|
||||
10
app/src/main/res/layout/activity_home.xml
Normal file
10
app/src/main/res/layout/activity_home.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".home.HomeActivity">
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Reference in New Issue
Block a user