bet 3/4 Sana 31.05.2023 Hajmi 1,59 Mb. #946818
Bog'liq
хисобот
Amaliy qism:
Ushbu amaliyot mo’baynida men yaratgan android dasturdan birining android studioda yozilgan kodi:
package uz.tbteam.newtaxidriver
import android.Manifest
import android.animation.Animator
import android.animation.Animator.AnimatorListener
import android.annotation.SuppressLint
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.PackageManager
import android.content.res.ColorStateList
import android.content.res.Configuration
import android.graphics.Bitmap
import android.graphics.Color
import android.graphics.Rect
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.ColorDrawable
import android.location.Location
import android.location.LocationListener
import android.location.LocationManager
import android.net.ConnectivityManager
import android.net.Uri
import android.os.Bundle
import android.os.Looper
import android.provider.Settings
import android.util.Log
import android.view.*
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.widget.LinearLayoutCompat
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.children
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.fragment.findNavController
import androidx.navigation.ui.NavigationUI
import androidx.navigation.ui.NavigationUI.setupWithNavController
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.request.target.SimpleTarget
import com.bumptech.glide.request.transition.Transition
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.Polygon
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.snackbar.Snackbar
import com.google.android.play.core.appupdate.AppUpdateManager
import com.google.android.play.core.appupdate.AppUpdateManagerFactory
import com.google.android.play.core.install.model.AppUpdateType
import com.google.android.play.core.install.model.AppUpdateType.IMMEDIATE
import com.google.android.play.core.install.model.UpdateAvailability
import com.karumi.dexter.Dexter
import com.karumi.dexter.PermissionToken
import com.karumi.dexter.listener.PermissionDeniedResponse
import com.karumi.dexter.listener.PermissionGrantedResponse
import com.karumi.dexter.listener.PermissionRequest
import com.karumi.dexter.listener.single.PermissionListener
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import uz.tbteam.newtaxidriver.databinding.ActivityMainBinding
import uz.tbteam.newtaxidriver.dialogs.cityTaxi.OrderCancelledDialog
import uz.tbteam.newtaxidriver.fragments.mainActivity.cityTaxi.viewModel.GeoServiceViewModel
import uz.tbteam.newtaxidriver.modelApi.mainActivity.cityTaxi.getPolygon.GetPolygon
import uz.tbteam.newtaxidriver.modelApi.mainActivity.cityTaxi.tariffs.GetTariffsListModel
import uz.tbteam.newtaxidriver.models.cityTaxi.ActiveOrder
import uz.tbteam.newtaxidriver.responseApis.ResApis
import uz.tbteam.newtaxidriver.service.FloatingService
import uz.tbteam.newtaxidriver.service.MainBackgroundService
import uz.tbteam.newtaxidriver.utils.*
import java.lang.Exception
import java.text.SimpleDateFormat
import java.util.*
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
private lateinit var navController: NavController
private lateinit var geoViewModel: GeoServiceViewModel
override fun onCreate(savedInstanceState: Bundle?) {
setTheme()
checkUpdateNewVersion()
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater )
setContentView(binding.root )
window .addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON )
setUpBottomNavigationView()
setCheckOrder()
registerRecievers()
if (checkCallingOrSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION ) == PackageManager.PERMISSION_GRANTED ) {
getSingleLocation()
} else {
requestPermissionForLocation()
}
geoViewModel = ViewModelProvider(this)[GeoServiceViewModel::class.java ]
setViewModelListener()
reloadEnabledTariffs()
}
private fun setViewModelListener() {
geoViewModel.polygon.observe(this, polygonObserver)
}
private val polygonObserver = Observer > {
when (it ) {
is ResApis.Error -> {
if (it .message.contains ("no rows")) {
SharedPref.setCityPolygon(this, null)
SharedPref.setDistrictPolygon(this, null)
}
PolygonUtils.isSent = false
geoViewModel.polygon.postValue(ResApis.Loading())
}
is ResApis.Success -> {
if (it.data.content != null) {
SharedPref.setCityPolygon(this, it .data.content.city)
SharedPref.setDistrictPolygon(this, it .data.content.district)
} else {
SharedPref.setCityPolygon(this, null)
SharedPref.setDistrictPolygon(this, null)
}
PolygonUtils.isSent = false
geoViewModel.polygon.postValue(ResApis.Loading())
}
else -> {}
}
}
Ushbu amaliyot mo’baynida men yaratgan android dasturdan birining dizayni:
Korxonaning rasmlar:
Do'stlaringiz bilan baham: