-
Notifications
You must be signed in to change notification settings - Fork 0
/
DetailsFragment.kt
78 lines (72 loc) · 3.13 KB
/
DetailsFragment.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package app.mardsoul.requestbin.ui.details
import android.os.Bundle
import android.view.View
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.navArgs
import app.mardsoul.requestbin.R
import app.mardsoul.requestbin.app
import app.mardsoul.requestbin.databinding.FragmentDetailsBinding
import app.mardsoul.requestbin.domain.entities.dto.BinInformationDto
import app.mardsoul.requestbin.ui.BaseFragment
import app.mardsoul.requestbin.utils.convertYesNoString
import kotlinx.coroutines.launch
class DetailsFragment : BaseFragment<FragmentDetailsBinding>(FragmentDetailsBinding::inflate) {
private val viewModel: DetailsViewModel by viewModels {
DetailsViewModelFactory(
requireContext().app.searchUseCase,
requireContext().app.historyUseCase
)
}
private val args: DetailsFragmentArgs by navArgs()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
lifecycleScope.launch {
viewModel.uiState.collect {
bindInformation(it.binInformationDto)
}
}
viewModel.searchBinInformation(args.binNumber)
}
private fun bindInformation(binInformationDto: BinInformationDto?) {
with(binding) {
binNumberTextView.text = args.binNumber
schemeValueTextView.text =
getString(R.string.scheme_value_text, binInformationDto?.scheme)
brandValueTextView.text =
getString(R.string.brand_value_text, binInformationDto?.brand)
cardLengthValueTextView.text =
getString(R.string.card_length_value_text, binInformationDto?.numberDto?.length)
cardLuhnValueTextView.text =
getString(
R.string.card_luhn_value_text,
binInformationDto?.numberDto?.luhn?.convertYesNoString()
)
typeValueTextView.text =
getString(R.string.type_value_text, binInformationDto?.type)
prepaidValueTextView.text =
getString(
R.string.prepaid_value_text,
binInformationDto?.prepaid?.convertYesNoString()
)
countryValueTextView.text =
getString(
R.string.country_value_text,
binInformationDto?.countryDto?.alpha2,
binInformationDto?.countryDto?.name
)
countryLatLonTextView.text =
getString(
R.string.country_lat_lon_text,
binInformationDto?.countryDto?.latitude,
binInformationDto?.countryDto?.longitude
)
bankNameTextView.text =
getString(R.string.bank_name_text, binInformationDto?.bankDto?.name)
bankUrlTextView.text =
getString(R.string.bank_url_text, binInformationDto?.bankDto?.url)
bankPhoneTextView.text =
getString(R.string.bank_phone_text, binInformationDto?.bankDto?.phone)
}
}
}