Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
5f9cade3c0
@ -1,6 +1,6 @@
|
|||||||
package ru.myitschool.work.core
|
package ru.myitschool.work.core
|
||||||
|
|
||||||
object Constants {
|
object Constants {
|
||||||
// "http://localhost:8080"
|
|
||||||
const val SERVER_ADDRESS = "http://10.0.2.2:8080"
|
const val SERVER_ADDRESS = "http://10.0.2.2:8080"
|
||||||
|
// const val SERVER_ADDRESS = "https://nto.den4iksop.org"
|
||||||
}
|
}
|
@ -6,17 +6,22 @@ import androidx.fragment.app.Fragment
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.navigation.fragment.findNavController
|
||||||
import ru.myitschool.work.R
|
import ru.myitschool.work.R
|
||||||
import ru.myitschool.work.databinding.FragmentEntryListBinding
|
import ru.myitschool.work.databinding.FragmentEntryListBinding
|
||||||
import ru.myitschool.work.databinding.FragmentLoginBinding
|
import ru.myitschool.work.databinding.FragmentLoginBinding
|
||||||
|
import ru.myitschool.work.ui.login.LoginDestination
|
||||||
import ru.myitschool.work.ui.login.LoginViewModel
|
import ru.myitschool.work.ui.login.LoginViewModel
|
||||||
|
import ru.myitschool.work.ui.profile.ProfileDestination
|
||||||
|
import ru.myitschool.work.ui.profile.ProfileViewModel
|
||||||
|
import ru.myitschool.work.utils.collectWhenStarted
|
||||||
|
|
||||||
class EntryListFragment : Fragment(R.layout.fragment_entry_list) {
|
class EntryListFragment : Fragment(R.layout.fragment_entry_list) {
|
||||||
|
|
||||||
private var _binding: FragmentEntryListBinding? = null
|
private var _binding: FragmentEntryListBinding? = null
|
||||||
private val binding: FragmentEntryListBinding get() = _binding!!
|
private val binding: FragmentEntryListBinding get() = _binding!!
|
||||||
|
|
||||||
private val viewModel: LoginViewModel by viewModels()
|
private val viewModel: EntryListViewModel by viewModels()
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
@ -26,8 +31,20 @@ class EntryListFragment : Fragment(R.layout.fragment_entry_list) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initCallback (){
|
private fun initCallback (){
|
||||||
|
binding.floatingActionButton2.setOnClickListener { viewModel.closeEntryList() }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun subscribe(){
|
||||||
|
viewModel.action.collectWhenStarted(this){ action ->
|
||||||
|
when(action) {
|
||||||
|
is EntryListViewModel.Action.OpenProfile -> {
|
||||||
|
findNavController().navigate(LoginDestination) {
|
||||||
|
popUpTo<ProfileDestination> { inclusive = true }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun subscribe(){}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,46 @@
|
|||||||
package ru.myitschool.work.ui.entrylist
|
package ru.myitschool.work.ui.entrylist
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.asSharedFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import ru.myitschool.work.ui.profile.ProfileViewModel
|
||||||
|
import ru.myitschool.work.ui.profile.ProfileViewModel.Action
|
||||||
|
import ru.myitschool.work.ui.profile.ProfileViewModel.State
|
||||||
|
import ru.myitschool.work.utils.MutablePublishFlow
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Locale
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
class EntryListViewModel : ViewModel() {
|
|
||||||
// TODO: Implement the ViewModel
|
@HiltViewModel
|
||||||
|
class EntryListViewModel @Inject constructor(
|
||||||
|
@ApplicationContext private val context: Context,
|
||||||
|
) : ViewModel() {
|
||||||
|
private val _action = MutablePublishFlow<Action>()
|
||||||
|
val action = _action.asSharedFlow()
|
||||||
|
|
||||||
|
private val _state = MutableStateFlow<State>(initialState)
|
||||||
|
val state = _state.asStateFlow()
|
||||||
|
|
||||||
|
fun closeEntryList(){
|
||||||
|
viewModelScope.launch {
|
||||||
|
_action.emit(Action.OpenProfile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sealed interface Action {
|
||||||
|
data object OpenProfile: Action
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val initialState = State.Loading
|
||||||
|
}
|
||||||
}
|
}
|
@ -57,9 +57,13 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) {
|
|||||||
}
|
}
|
||||||
is ProfileViewModel.State.Show -> {
|
is ProfileViewModel.State.Show -> {
|
||||||
swipeRefreshLayout.isRefreshing = false
|
swipeRefreshLayout.isRefreshing = false
|
||||||
binding.fullname.text = state.fullname
|
|
||||||
binding.position.text = state.position
|
binding.position.text = state.position
|
||||||
binding.lastEntry.text = state.lastEntry
|
binding.lastEntry.text = state.lastEntry
|
||||||
|
if (state.admin){
|
||||||
|
binding.fullname.text = state.fullname + " admin"
|
||||||
|
}else{
|
||||||
|
binding.fullname.text = state.fullname
|
||||||
|
}
|
||||||
Picasso.get()
|
Picasso.get()
|
||||||
.load(state.imageUrl)
|
.load(state.imageUrl)
|
||||||
.error(R.drawable.ic_no_img)
|
.error(R.drawable.ic_no_img)
|
||||||
|
@ -66,7 +66,8 @@ class ProfileViewModel @Inject constructor(
|
|||||||
fullname = value.fullname,
|
fullname = value.fullname,
|
||||||
imageUrl = value.imageUrl,
|
imageUrl = value.imageUrl,
|
||||||
position = value.position,
|
position = value.position,
|
||||||
lastEntry = simpleDateFormat.format(Date(value.lastEntryMillis))
|
lastEntry = simpleDateFormat.format(Date(value.lastEntryMillis)),
|
||||||
|
admin = false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -84,7 +85,6 @@ class ProfileViewModel @Inject constructor(
|
|||||||
|
|
||||||
sealed interface State {
|
sealed interface State {
|
||||||
data object Loading : State
|
data object Loading : State
|
||||||
|
|
||||||
data class Error(
|
data class Error(
|
||||||
val errorText: String,
|
val errorText: String,
|
||||||
) : State
|
) : State
|
||||||
@ -94,6 +94,7 @@ class ProfileViewModel @Inject constructor(
|
|||||||
val imageUrl: String,
|
val imageUrl: String,
|
||||||
val position: String,
|
val position: String,
|
||||||
val lastEntry: String,
|
val lastEntry: String,
|
||||||
|
val admin: Boolean,
|
||||||
) : State
|
) : State
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +104,7 @@ class ProfileViewModel @Inject constructor(
|
|||||||
data object OpenLog : Action
|
data object OpenLog : Action
|
||||||
}
|
}
|
||||||
|
|
||||||
private companion object {
|
companion object {
|
||||||
private val simpleDateFormat = SimpleDateFormat(
|
private val simpleDateFormat = SimpleDateFormat(
|
||||||
"yyyy-MM-DD HH:mm",
|
"yyyy-MM-DD HH:mm",
|
||||||
Locale.US
|
Locale.US
|
||||||
|
Loading…
x
Reference in New Issue
Block a user