3.2 Ilovani ishlab chiqishda arxitektura patternining o’rni
Arxitektura pattern larni qo’llash orqali android ilovalarni yaratish doimo dasturchilar tomonidan afzal ko’rilgan ishdir. Arxitektura pattern proyekt fayllariga modularlikni beradi va barcha kodlarga Unit Testing yozilishini ta’minlaydi. Bu dasturchilarga dasturiy ta’minotni saqlab qolish va kelajakda dastur xususiyatlarini kengaytirish vazifasini osonlashtiradi. Dasturchilar orasida juda mashhur bo’lgan ba’zi arxitekturalar mavjud. Ular MVC, MVVM, MVI va boshqalar.
“Tasker” ilovasi - zamonaviy arxitektura patternlaridan biri bo’lgan MVVM da, Clean Architecture prisnsiplari asosida yaratilgan.
Ushbu arxitektura patterni oxirgi yillarda android dasturchilari tomonidan juda ko’p qo’llanilib kelinmoqda. Androidning egasi bo’lmish Google ham hozirda android dasturchilarga ushbu patterndan foydalanishni tavsiya berishmoqda hamda shu patternga mos android komponentalar ishlab chiqishmoqda.
Shu tavsiyaga binoan “Tasker” ilovasi MVVM arxitektura patternida ishlab chiqildi. Klaslar orasidagi bog’lanishlarni, ularning bir-biriga qaramligini kamaytirish, appning keyingi “bug fixing”, “feature” qo’shish kabi holatlarida dasturchining ishini osonlashtirish asosiy maqsad qilib qo’yildi.
Har bir ilova vaqt o’tgan sayin zamon bilan hamnafas bo’lishga, foydalanuvchilarga qiziqarli va foydali ma’lumotlar taqdim etishga, ularning “og’irini yengil” qilishga harakat qiladi. Bu esa unga o’zgartirish hamda qo’shimchalar kiritish zaruriyatini tug’diradi.
Shu vaziyatlarni oldindan inobatga olgan holatda shu arxitektura tanlandiki, keyinchalik bo’ladigan o’zgarishlarga bardoshli bo’lishi, dasturchini ortiqcha qiynamasligi, ilovaning yengil hamda tez ishlashi kabi masalalar a’lo darajada o’z yechimini topdi.
ViewModel:
class AddTaskViewModel: ViewModel() {
var taskTextFieldState by mutableStateOf("")
fun setTextFieldState(str: String) {
taskTextFieldState = str
}
var date by mutableStateOf("")
fun setdate(date: String) {
this.date = date
}
var time by mutableStateOf("")
fun settime(time: String) {
this.time = time
}
var category: Category? by mutableStateOf(null)
fun setcategory(category: Category?) {
this.category = category
}
val pickedCategoryColor: MutableState
get() {
if (category == null) {
return mutableStateOf(R.color.white)
} else {
return mutableStateOf(category!!.backgroundColor!!)
}
}
}
class FabControlViewModel: ViewModel() {
//fab General
var fabState by mutableStateOf(FabState.NOTROTATED)
var fabVisibility by mutableStateOf(true)
var showFabDialog by mutableStateOf(false)
fun setFabstate(state: FabState) {
fabState = state
}
fun setFabvisibility(visible: Boolean) {
fabVisibility = visible
}
fun setShowFabdialog(show: Boolean) {
showFabDialog = show
}
//fabAnimation
var backColorState by mutableStateOf(value = Color.White)
fun setFabBackColor(color: Color) {
backColorState = color
}
var iconColor by mutableStateOf(value = Color(0xFF006CFF))
fun setFabIconColor(color: Color) {
iconColor = color
}
var rotationState by mutableStateOf(0f)
fun setRotationstate(degree: Float) {
rotationState = degree
}
//List Dialog states
var selectedColorState by mutableStateOf(R.color.blue)
fun setSelectedColorstate(color: Int) {
selectedColorState = color
}
var showListDialog by mutableStateOf(value = false)
fun setShowListdialog(show: Boolean) {
showListDialog = show
}
var listDialogTextFieldState by mutableStateOf("")
fun setlistDialogTFState(state: String) {
listDialogTextFieldState = state
}
}
Do'stlaringiz bilan baham: |