Mavzu: Muzqaymoq savdosi tizimini mobil ilovasini yaratish


II. Loyiha qism 2.1. “Muzqaymoq savdosi tizimi” mobil ilovasini yaratish



Download 0,72 Mb.
bet4/5
Sana13.07.2022
Hajmi0,72 Mb.
#786412
1   2   3   4   5
Bog'liq
Dasturiy ta\'minot sifatini ta\'minlash

II. Loyiha qism

2.1. “Muzqaymoq savdosi tizimi” mobil ilovasini yaratish.


viewModel =
ViewModelProvider(this, MainViewModelFactory(App.app)).get(MainViewModel::class.java)

if (!EventBus.getDefault().isRegistered(this)) {


EventBus.getDefault().register(this)
}

bron = intent.getIntExtra(Constants.EXTRA_DATA, 0)

viewModel.error.observe(this, Observer {
send(false)
setProgress(false)
val connectionManager =
getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val networkInfo = connectionManager.activeNetworkInfo
if (networkInfo != null && networkInfo.isConnected) {
showError(it)
}
})

viewModel.message.observe(this, Observer {


showSuccess(it)
})

// viewModel.swipeProgress.observe(this, Observer {


// swipe.isRefreshing = it
// })

// viewModel.progress.observe(this, Observer {


// swipe.isRefreshing = it
// })

viewModel.progressDB.observe(this, Observer {


swipe.isRefreshing = it
})

viewModel.clientsData.observe(this, Observer {


viewModel.insertDBClient(it)
setProgress(false)
})

viewModel.successDbClient.observe(this, Observer {


setData()
})

viewModel.productData.observe(this, Observer {


viewModel.insertDBAllProducts(it)
setProgress(false)
})

viewModel.userInfoResponseData.observe(this, Observer {


Prefs.setUser(it)
setClientDataNav()
setProgress(false)
})

viewModel.orderData.observe(this, Observer {


Prefs.clearItemClient(clientId)
if (Prefs.getAllCartList()?.count() ?: 0 == 0) {
Prefs.clearCart()
send(false)
setProgress(false)
startClearActivity(Constants.EXTRA_DATA, 2)
} else {
send(true)
}
EventBus.getDefault().post(EventModel(Constants.EVENT_UPDATE_CART, 0))
})

if (bron == 1) {


showSuccess(getString(R.string.cleared_bron))
} else if (bron == 2) {
showSuccess(getString(R.string.sent_inform))
}

imgCart.setOnClickListener {


startActivity()
}

imgRefresh.setOnClickListener {


val connectionManager =
getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val networkInfo = connectionManager.activeNetworkInfo
if (networkInfo != null && networkInfo.isConnected) {
setProgress(true)
loadData()
} else {
showWarning(getString(R.string.with_internet))
}
}

swipe.setOnRefreshListener {


setBadge()
initData()
}

svMain.setOnClickListener { svMain.isIconified = false }


svMain.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean {

return false


}

override fun onQueryTextChange(newText: String?): Boolean {


adapter?.search(newText ?: "")
return false
}
})

// tvStatus.text = if (Prefs.getStorage() == null) {


// getString(R.string.storage_main)
// } else {
// Prefs.getStorage()?.name
// }

val toggle = ActionBarDrawerToggle(this, drawer, R.string.app_name, R.string.app_name)


drawer.addDrawerListener(toggle)
toggle.syncState()
navigation.setNavigationItemSelectedListener(this)

imgMenu.setOnClickListener {


drawer.openDrawer(GravityCompat.START)
}

setBadge()

imgSearch.setOnClickListener {
startActivity()
}
override fun onNavigationItemSelected(p0: MenuItem): Boolean {
when (p0.itemId) {
R.id.mm_nav_add_client -> {
val connectionManager =
getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val networkInfo = connectionManager.activeNetworkInfo
if (networkInfo != null && networkInfo.isConnected) {
drawer.closeDrawers()
val fragment = AddClientBottom.newInstance(object : AddClientBottomCallback {
override fun onDismissListener() {
loadData()
showSuccess("Клиент қўшилди")
}
})
fragment.show(supportFragmentManager, fragment.tag)
} else {
showWarning(getString(R.string.with_internet))
}
}

R.id.mm_nav_storage -> {


val connectionManager =
getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val networkInfo = connectionManager.activeNetworkInfo
if (networkInfo != null && networkInfo.isConnected) {
startActivity()
} else {
showWarning(getString(R.string.with_internet))
}
}

R.id.mm_nav_report -> {


startActivity()
}

R.id.mm_nav_send -> {


if (Prefs.getAllCartList()?.count() ?: 0 != 0) {
val connectionManager =
getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val networkInfo = connectionManager.activeNetworkInfo
if (networkInfo != null && networkInfo.isConnected) {
send(true)
setProgress(true)
} else {
showWarning(getString(R.string.with_internet))
}
} else {
showWarning(getString(R.string.no_inform))
}

}

R.id.mm_nav_clear -> {


if (Prefs.getAllCartList()?.count() ?: 0 != 0) {
Prefs.clearCart()
EventBus.getDefault().post(EventModel(Constants.EVENT_UPDATE_CART, 0))
startClearActivity(Constants.EXTRA_DATA, 1)
} else {
showWarning(getString(R.string.no_inform))
}
}

R.id.mm_nav_aboutUs -> {


startActivity()
}

R.id.mm_nav_shareApp -> {


val shareIntent = Intent()
shareIntent.action = Intent.ACTION_SEND
shareIntent.type = "text/plain"
shareIntent.putExtra(
Intent.EXTRA_TEXT, getString(R.string.my_friend_i_offer_2_you_) + " "
+ getString(R.string.app_name)
+ "\n https://play.google.com/store/apps/details?id=${BuildConfig.APPLICATION_ID}"
)
startActivity(Intent.createChooser(shareIntent, getString(R.string.share_title)))
}

R.id.mm_nav_secruty -> {


finish()
}

R.id.mm_nav_logout -> {


Prefs.clearAll()
startClearActivity()
finish()
}
}
return true
}

private fun setClientDataNav() {


val view = navigation.getHeaderView(0)
val user = Prefs.getUser()
view.tvPersonName.text = user?.fullname
view.tvPhone.text = user?.phone
view.tvBonus.text = user?.balance.formattedAmount()
view.tvQulimda.text = user?.price.formattedAmount()
}
private fun setData() {
if (viewModel.successDbClient.value != null) {
recyclerFolder.layoutManager =
LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
adapter = FolderAdapter(
viewModel.successDbClient.value ?: emptyList(),
object : FolderAdapterListener {
override fun onClick(item: List) {
startActivity(
Constants.EXTRA_DATA,
item as Serializable
)
}
})

recyclerFolder.adapter = adapter


}
}
Adapter

class FolderAdapter(val list: List, val callback: FolderAdapterListener) :


BaseAdapter(list.toMutableList(), R.layout.folder_item_layout) {
override fun onBindViewHolder(holder: ItemHolder, position: Int) {
super.onBindViewHolder(holder, position)
val item = items[position] as FolderClientsModel

holder.itemView.tvTitle.text = item.folderName

holder.itemView.setOnClickListener {
callback.onClick(item.Clients)
}
}

fun search(keyword: String) {


items = list.filter {
it.folderName.toUpperCase().contains(keyword.toUpperCase())
}.toMutableList()
notifyDataSetChanged()
}
}

Download 0,72 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish