Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
shunchaki
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shohboz Qoraboev
shunchaki
Commits
be0a3fe1
Commit
be0a3fe1
authored
Dec 07, 2021
by
shohboz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ADD]
MUS-107
Feature, home page viewModel
parent
0ce41d2e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
110 additions
and
1 deletion
+110
-1
HomeFragment.kt
app/src/main/java/uz/ssd/mobiuz/ui/home/HomeFragment.kt
+81
-1
HomeViewModel.kt
app/src/main/java/uz/ssd/mobiuz/ui/home/HomeViewModel.kt
+29
-0
No files found.
app/src/main/java/uz/ssd/mobiuz/ui/home/HomeFragment.kt
View file @
be0a3fe1
package
uz.ssd.mobiuz.ui.home
package
uz.ssd.mobiuz.ui.home
import
android.annotation.SuppressLint
import
android.content.Intent
import
android.os.Bundle
import
android.os.Bundle
import
android.view.View
import
android.view.View
import
androidx.core.os.bundleOf
import
androidx.core.view.isVisible
import
androidx.fragment.app.viewModels
import
androidx.lifecycle.lifecycleScope
import
dagger.hilt.android.AndroidEntryPoint
import
dagger.hilt.android.AndroidEntryPoint
import
kotlinx.coroutines.flow.collect
import
uz.ssd.mobiuz.AuthActivity
import
uz.ssd.mobiuz.MainActivity
import
uz.ssd.mobiuz.R
import
uz.ssd.mobiuz.R
import
uz.ssd.mobiuz.databinding.FragmentHomeBinding
import
uz.ssd.mobiuz.databinding.FragmentHomeBinding
import
uz.ssd.mobiuz.model.SharedPref
import
uz.ssd.mobiuz.network.model.Customer
import
uz.ssd.mobiuz.network.model.UiStateObject
import
uz.ssd.mobiuz.ui.base.BaseFragment
import
uz.ssd.mobiuz.ui.base.BaseFragment
import
uz.ssd.mobiuz.utils.ButtonClick
import
uz.ssd.mobiuz.utils.ButtonClick
import
uz.ssd.mobiuz.utils.CONSTANTS
import
uz.ssd.mobiuz.utils.Utils
import
uz.ssd.mobiuz.utils.extensions.showCustomExitDialog
import
uz.ssd.mobiuz.utils.extensions.showMessage
import
uz.ssd.mobiuz.utils.extensions.toMoneyFormat
import
javax.inject.Inject
@AndroidEntryPoint
@AndroidEntryPoint
class
HomeFragment
:
BaseFragment
(
R
.
layout
.
fragment_home
)
{
class
HomeFragment
:
BaseFragment
(
R
.
layout
.
fragment_home
)
{
@Inject
lateinit
var
pref
:
SharedPref
private
var
_bn
:
FragmentHomeBinding
?
=
null
private
var
_bn
:
FragmentHomeBinding
?
=
null
private
val
bn
get
()
=
_bn
?:
throw
NullPointerException
(
"cannot inflate"
)
private
val
bn
get
()
=
_bn
?:
throw
NullPointerException
(
"cannot inflate"
)
private
val
viewModel
:
HomeViewModel
by
viewModels
()
private
var
customer
:
Customer
?
=
null
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
viewModel
.
mainIndex
()
}
override
fun
onViewCreated
(
view
:
View
,
savedInstanceState
:
Bundle
?)
{
override
fun
onViewCreated
(
view
:
View
,
savedInstanceState
:
Bundle
?)
{
_bn
=
FragmentHomeBinding
.
bind
(
view
)
_bn
=
FragmentHomeBinding
.
bind
(
view
)
...
@@ -27,7 +56,15 @@ class HomeFragment : BaseFragment(R.layout.fragment_home) {
...
@@ -27,7 +56,15 @@ class HomeFragment : BaseFragment(R.layout.fragment_home) {
bn
.
apply
{
bn
.
apply
{
btnMenu
.
setOnClickListener
(
object
:
ButtonClick
()
{
btnMenu
.
setOnClickListener
(
object
:
ButtonClick
()
{
override
fun
onSingleClick
(
v
:
View
?)
{
override
fun
onSingleClick
(
v
:
View
?)
{
showCustomExitDialog
{
pref
.
setUserToken
(
""
)
pref
.
isRegistered
=
false
pref
.
pin_code
=
""
val
intent
=
Intent
(
requireContext
(),
AuthActivity
::
class
.
java
)
intent
.
flags
=
Intent
.
FLAG_ACTIVITY_NEW_TASK
or
Intent
.
FLAG_ACTIVITY_TASK_ON_HOME
startActivity
(
intent
)
requireActivity
().
finish
()
}
}
}
})
})
btnAddSum
.
setOnClickListener
(
object
:
ButtonClick
()
{
btnAddSum
.
setOnClickListener
(
object
:
ButtonClick
()
{
...
@@ -39,6 +76,49 @@ class HomeFragment : BaseFragment(R.layout.fragment_home) {
...
@@ -39,6 +76,49 @@ class HomeFragment : BaseFragment(R.layout.fragment_home) {
}
}
override
fun
collects
()
{
override
fun
collects
()
{
viewLifecycleOwner
.
lifecycleScope
.
launchWhenStarted
{
viewModel
.
mainIndexUiState
.
collect
{
when
(
it
)
{
is
UiStateObject
.
SUCCESS
->
{
showProgressDialog
(
false
)
customer
=
it
.
data
loadData
()
}
is
UiStateObject
.
ERROR
->
{
showProgressDialog
(
false
)
showMessage
(
it
.
message
)
}
is
UiStateObject
.
ERRORS
->
{
showProgressDialog
(
false
)
}
is
UiStateObject
.
LOADING
->
{
showProgressDialog
(
true
)
}
else
->
Unit
}
}
}
}
@SuppressLint
(
"SetTextI18n"
)
private
fun
loadData
()
{
customer
?.
customer
?.
info
?.
let
{
bn
.
apply
{
txtBalance
.
text
=
"${it.balance.amount.toMoneyFormat()} ${it.balance.currency}"
it
.
counters
.
let
{
txtCountMb
.
text
=
it
.
BYTE
.
value
.
toMoneyFormat
()
txtTypeMb
.
text
=
it
.
BYTE
.
unit
txtCountMinut
.
text
=
it
.
SECOND
.
value
.
toMoneyFormat
()
txtTypeMinut
.
text
=
it
.
SECOND
.
unit
txtCountSms
.
text
=
it
.
ITEM
.
value
.
toMoneyFormat
()
txtTypeSms
.
text
=
it
.
ITEM
.
unit
}
txtMyNumber
.
text
=
pref
.
userPhone
}
}
}
}
...
...
app/src/main/java/uz/ssd/mobiuz/ui/home/HomeViewModel.kt
0 → 100644
View file @
be0a3fe1
package
uz.ssd.mobiuz.ui.home
import
androidx.lifecycle.ViewModel
import
androidx.lifecycle.viewModelScope
import
dagger.hilt.android.lifecycle.HiltViewModel
import
kotlinx.coroutines.flow.MutableStateFlow
import
kotlinx.coroutines.flow.StateFlow
import
kotlinx.coroutines.launch
import
uz.ssd.mobiuz.model.UserAuth
import
uz.ssd.mobiuz.network.model.Action
import
uz.ssd.mobiuz.network.model.Customer
import
uz.ssd.mobiuz.network.model.UiStateObject
import
uz.ssd.mobiuz.network.repository.AuthRepository
import
javax.inject.Inject
@HiltViewModel
class
HomeViewModel
@Inject
constructor
(
private
val
repository
:
AuthRepository
)
:
ViewModel
()
{
private
val
_mainIndexUiState
=
MutableStateFlow
<
UiStateObject
<
Customer
>>(
UiStateObject
.
EMPTY
)
val
mainIndexUiState
:
StateFlow
<
UiStateObject
<
Customer
>>
=
_mainIndexUiState
fun
mainIndex
()
=
viewModelScope
.
launch
{
_mainIndexUiState
.
value
=
UiStateObject
.
LOADING
_mainIndexUiState
.
value
=
repository
.
mainIndex
()
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment