Блог

Room & SQLite (Kotlin)

https://youtu.be/sXXlvGZ24H8 Зависимости: plugins { id ‘com.android.application’ id ‘org.jetbrains.kotlin.android’ id ‘kotlin-kapt’} dependencies { implementation ‘androidx.room:room-ktx:2.4.3’ implementation ‘androidx.lifecycle:lifecycle-livedata-ktx:2.5.1’ kapt ‘androidx.room:room-compiler:2.4.3’ implementation ‘androidx.core:core-ktx:1.7.0’ implementation ‘androidx.appcompat:appcompat:1.5.1’ implementation ‘com.google.android.material:material:1.6.1’ implementation ‘androidx.constraintlayout:constraintlayout:2.1.4’ testImplementation ‘junit:junit:4.13.2’ androidTestImplementation ‘androidx.test.ext:junit:1.1.3’ androidTestImplementation ‘androidx.test.espresso:espresso-core:3.4.0’} MainActivity import androidx.appcompat.app.AppCompatActivityimport android.os.Bundleimport androidx.lifecycle.asLiveDataimport com.text_game.roomtest.databinding.ActivityMainBindingclass MainActivity : AppCompatActivity() { lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) val db = MainDb.getDb(this) db.getDao().getAllItem().asLiveData().observe(this){ list-> binding.tvList.text = “” list.forEach { val text =… Подробнее »Room & SQLite (Kotlin)

Weather app #20 : AlertDialog для выбора города.

https://youtu.be/pbBPK0eT3bo MainFragment import android.Manifestimport android.content.Contextimport android.content.Intentimport android.content.pm.PackageManagerimport android.location.LocationManagerimport android.os.Bundleimport android.provider.Settingsimport android.util.Logimport androidx.fragment.app.Fragmentimport android.view.LayoutInflaterimport android.view.Viewimport android.view.ViewGroupimport android.widget.Toastimport androidx.activity.result.ActivityResultLauncherimport androidx.activity.result.contract.ActivityResultContractsimport androidx.core.app.ActivityCompatimport androidx.fragment.app.FragmentActivityimport androidx.fragment.app.activityViewModelsimport com.android.volley.Requestimport com.android.volley.toolbox.StringRequestimport com.android.volley.toolbox.Volleyimport com.google.android.gms.location.FusedLocationProviderClientimport com.google.android.gms.location.LocationRequestimport com.google.android.gms.location.LocationServicesimport com.google.android.gms.location.Priorityimport com.google.android.gms.tasks.CancellationTokenSourceimport com.google.android.material.tabs.TabLayoutMediatorimport com.meter_alc_rgb.weatherappcursey.DialogManagerimport com.meter_alc_rgb.weatherappcursey.MainViewModelimport com.meter_alc_rgb.weatherappcursey.Rimport com.meter_alc_rgb.weatherappcursey.adapters.VpAdapterimport com.meter_alc_rgb.weatherappcursey.adapters.WeatherModelimport com.meter_alc_rgb.weatherappcursey.databinding.FragmentMainBindingimport com.squareup.picasso.Picassoimport org.json.JSONObjectconst val API_KEY = “Ваш API ключ”class MainFragment : Fragment() { private lateinit var fLocationClient: FusedLocationProviderClient private val fList = listOf( HoursFragment.newInstance(), DaysFragment.newInstance() ) private val tList = listOf( “Hours”, “Days” ) private… Подробнее »Weather app #20 : AlertDialog для выбора города.

Weather app #19 : isLocationEnabled()

https://youtu.be/l_MYPJVEiZ4 MainActivity import android.Manifestimport android.content.Contextimport android.content.Intentimport android.content.pm.PackageManagerimport android.location.LocationManagerimport android.os.Bundleimport android.provider.Settingsimport android.util.Logimport androidx.fragment.app.Fragmentimport android.view.LayoutInflaterimport android.view.Viewimport android.view.ViewGroupimport android.widget.Toastimport androidx.activity.result.ActivityResultLauncherimport androidx.activity.result.contract.ActivityResultContractsimport androidx.core.app.ActivityCompatimport androidx.fragment.app.FragmentActivityimport androidx.fragment.app.activityViewModelsimport com.android.volley.Requestimport com.android.volley.toolbox.StringRequestimport com.android.volley.toolbox.Volleyimport com.google.android.gms.location.FusedLocationProviderClientimport com.google.android.gms.location.LocationRequestimport com.google.android.gms.location.LocationServicesimport com.google.android.gms.location.Priorityimport com.google.android.gms.tasks.CancellationTokenSourceimport com.google.android.material.tabs.TabLayoutMediatorimport com.meter_alc_rgb.weatherappcursey.DialogManagerimport com.meter_alc_rgb.weatherappcursey.MainViewModelimport com.meter_alc_rgb.weatherappcursey.Rimport com.meter_alc_rgb.weatherappcursey.adapters.VpAdapterimport com.meter_alc_rgb.weatherappcursey.adapters.WeatherModelimport com.meter_alc_rgb.weatherappcursey.databinding.FragmentMainBindingimport com.squareup.picasso.Picassoimport org.json.JSONObjectconst val API_KEY = “Ваш API ключ”class MainFragment : Fragment() { private lateinit var fLocationClient: FusedLocationProviderClient private val fList = listOf( HoursFragment.newInstance(), DaysFragment.newInstance() ) private val tList = listOf( “Hours”, “Days” ) private… Подробнее »Weather app #19 : isLocationEnabled()

Weather App JetPack Compose #8 : getWeatherDyDays()

MainScreen import androidx.compose.foundation.Imageimport androidx.compose.foundation.layout.*import androidx.compose.foundation.lazy.LazyColumnimport androidx.compose.foundation.lazy.itemsIndexedimport androidx.compose.foundation.shape.RoundedCornerShapeimport androidx.compose.material.*import androidx.compose.runtime.Composableimport androidx.compose.runtime.MutableStateimport androidx.compose.runtime.rememberCoroutineScopeimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.draw.alphaimport androidx.compose.ui.draw.clipimport androidx.compose.ui.graphics.Colorimport androidx.compose.ui.layout.ContentScaleimport androidx.compose.ui.res.painterResourceimport androidx.compose.ui.text.TextStyleimport androidx.compose.ui.tooling.preview.Previewimport androidx.compose.ui.unit.dpimport androidx.compose.ui.unit.spimport coil.compose.AsyncImageimport com.google.accompanist.pager.ExperimentalPagerApiimport com.google.accompanist.pager.HorizontalPagerimport com.google.accompanist.pager.pagerTabIndicatorOffsetimport com.google.accompanist.pager.rememberPagerStateimport com.meter_alc_rgb.weatherappcomposey.Rimport com.meter_alc_rgb.weatherappcomposey.data.WeatherModelimport com.meter_alc_rgb.weatherappcomposey.ui.theme.BlueLightimport kotlinx.coroutines.launch@Composablefun MainCard() { Column( modifier = Modifier .padding(5.dp) ) { Card( modifier = Modifier.fillMaxWidth(), backgroundColor = BlueLight, elevation = 0.dp ) { Column( modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally ) { Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween ) {… Подробнее »Weather App JetPack Compose #8 : getWeatherDyDays()

Weather app #18 : Location

MainFragment import android.Manifestimport android.content.pm.PackageManagerimport android.os.Bundleimport android.util.Logimport androidx.fragment.app.Fragmentimport android.view.LayoutInflaterimport android.view.Viewimport android.view.ViewGroupimport android.widget.Toastimport androidx.activity.result.ActivityResultLauncherimport androidx.activity.result.contract.ActivityResultContractsimport androidx.core.app.ActivityCompatimport androidx.fragment.app.FragmentActivityimport androidx.fragment.app.activityViewModelsimport com.android.volley.Requestimport com.android.volley.toolbox.StringRequestimport com.android.volley.toolbox.Volleyimport com.google.android.gms.location.FusedLocationProviderClientimport com.google.android.gms.location.LocationRequestimport com.google.android.gms.location.LocationServicesimport com.google.android.gms.tasks.CancellationTokenSourceimport com.google.android.material.tabs.TabLayoutMediatorimport com.meter_alc_rgb.weatherappcursey.MainViewModelimport com.meter_alc_rgb.weatherappcursey.Rimport com.meter_alc_rgb.weatherappcursey.adapters.VpAdapterimport com.meter_alc_rgb.weatherappcursey.adapters.WeatherModelimport com.meter_alc_rgb.weatherappcursey.databinding.FragmentMainBindingimport com.squareup.picasso.Picassoimport org.json.JSONObjectconst val API_KEY = “Ваш API ключ”class MainFragment : Fragment() { private lateinit var fLocationClient: FusedLocationProviderClient private val fList = listOf( HoursFragment.newInstance(), DaysFragment.newInstance() ) private val tList = listOf( “Hours”, “Days” ) private lateinit var pLauncher: ActivityResultLauncher<String> private lateinit var… Подробнее »Weather app #18 : Location

Weather app #17 : Оброботка нажатий на список дней.

MainFragment import android.Manifestimport android.os.Bundleimport android.util.Logimport androidx.fragment.app.Fragmentimport android.view.LayoutInflaterimport android.view.Viewimport android.view.ViewGroupimport android.widget.Toastimport androidx.activity.result.ActivityResultLauncherimport androidx.activity.result.contract.ActivityResultContractsimport androidx.fragment.app.FragmentActivityimport androidx.fragment.app.activityViewModelsimport com.android.volley.Requestimport com.android.volley.toolbox.StringRequestimport com.android.volley.toolbox.Volleyimport com.google.android.material.tabs.TabLayoutMediatorimport com.meter_alc_rgb.weatherappcursey.MainViewModelimport com.meter_alc_rgb.weatherappcursey.Rimport com.meter_alc_rgb.weatherappcursey.adapters.VpAdapterimport com.meter_alc_rgb.weatherappcursey.adapters.WeatherModelimport com.meter_alc_rgb.weatherappcursey.databinding.FragmentMainBindingimport com.squareup.picasso.Picassoimport org.json.JSONObjectconst val API_KEY = “Ваш API ключ”class MainFragment : Fragment() { private val fList = listOf( HoursFragment.newInstance(), DaysFragment.newInstance() ) private val tList = listOf( “Hours”, “Days” ) private lateinit var pLauncher: ActivityResultLauncher<String> private lateinit var binding: FragmentMainBinding private val model: MainViewModel by activityViewModels() override fun onCreateView(… Подробнее »Weather app #17 : Оброботка нажатий на список дней.

Weather app #16 : Список прогноза по дням

MainFragment import android.Manifestimport android.os.Bundleimport android.util.Logimport androidx.fragment.app.Fragmentimport android.view.LayoutInflaterimport android.view.Viewimport android.view.ViewGroupimport android.widget.Toastimport androidx.activity.result.ActivityResultLauncherimport androidx.activity.result.contract.ActivityResultContractsimport androidx.fragment.app.FragmentActivityimport androidx.fragment.app.activityViewModelsimport com.android.volley.Requestimport com.android.volley.toolbox.StringRequestimport com.android.volley.toolbox.Volleyimport com.google.android.material.tabs.TabLayoutMediatorimport com.meter_alc_rgb.weatherappcursey.MainViewModelimport com.meter_alc_rgb.weatherappcursey.Rimport com.meter_alc_rgb.weatherappcursey.adapters.VpAdapterimport com.meter_alc_rgb.weatherappcursey.adapters.WeatherModelimport com.meter_alc_rgb.weatherappcursey.databinding.FragmentMainBindingimport com.squareup.picasso.Picassoimport org.json.JSONObjectconst val API_KEY = “Ваш API ключь”class MainFragment : Fragment() { private val fList = listOf( HoursFragment.newInstance(), DaysFragment.newInstance() ) private val tList = listOf( “Hours”, “Days” ) private lateinit var pLauncher: ActivityResultLauncher<String> private lateinit var binding: FragmentMainBinding private val model: MainViewModel by activityViewModels() override fun onCreateView(… Подробнее »Weather app #16 : Список прогноза по дням

Weather App JetPack Compose #7 : getData()

build.gradle (module dependencies) dependencies { implementation “com.android.volley:volley:1.2.1” implementation “com.google.accompanist:accompanist-pager:0.19.0” implementation “com.google.accompanist:accompanist-pager-indicators:0.19.0” implementation ‘androidx.core:core-ktx:1.7.0’ implementation “androidx.compose.ui:ui:$compose_version” implementation “androidx.compose.material:material:$compose_version” implementation “androidx.compose.ui:ui-tooling-preview:$compose_version” implementation ‘androidx.lifecycle:lifecycle-runtime-ktx:2.3.1’ implementation ‘androidx.activity:activity-compose:1.3.1’ implementation(“io.coil-kt:coil-compose:2.0.0-rc01”) testImplementation ‘junit:junit:4.13.2’ androidTestImplementation ‘androidx.test.ext:junit:1.1.3’ androidTestImplementation ‘androidx.test.espresso:espresso-core:3.4.0’ androidTestImplementation “androidx.compose.ui:ui-test-junit4:$compose_version” debugImplementation “androidx.compose.ui:ui-tooling:$compose_version” debugImplementation “androidx.compose.ui:ui-test-manifest:$compose_version”} MainActivity import android.content.Contextimport android.os.Bundleimport android.util.Logimport androidx.activity.ComponentActivityimport androidx.activity.compose.setContentimport androidx.compose.foundation.Imageimport androidx.compose.foundation.layout.Columnimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.ui.Modifierimport androidx.compose.ui.draw.alphaimport androidx.compose.ui.layout.ContentScaleimport androidx.compose.ui.res.painterResourceimport com.android.volley.Requestimport com.android.volley.toolbox.StringRequestimport com.android.volley.toolbox.Volleyimport com.meter_alc_rgb.weatherappcomposey.screens.MainCardimport com.meter_alc_rgb.weatherappcomposey.screens.TabLayoutimport com.meter_alc_rgb.weatherappcomposey.ui.theme.WeatherAppComposeYThemeconst val API_KEY = “Ваш API KEY”class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?)… Подробнее »Weather App JetPack Compose #7 : getData()

Weather app #15 : Список прогноза по часам

HoursFragment import android.os.Bundleimport android.util.Logimport androidx.fragment.app.Fragmentimport android.view.LayoutInflaterimport android.view.Viewimport android.view.ViewGroupimport androidx.fragment.app.activityViewModelsimport androidx.recyclerview.widget.LinearLayoutManagerimport com.meter_alc_rgb.weatherappcursey.MainViewModelimport com.meter_alc_rgb.weatherappcursey.Rimport com.meter_alc_rgb.weatherappcursey.adapters.WeatherAdapterimport com.meter_alc_rgb.weatherappcursey.adapters.WeatherModelimport com.meter_alc_rgb.weatherappcursey.databinding.FragmentHoursBindingimport org.json.JSONArrayimport org.json.JSONObjectclass HoursFragment : Fragment() { private lateinit var binding: FragmentHoursBinding private lateinit var adapter: WeatherAdapter private val model: MainViewModel by activityViewModels() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View { binding = FragmentHoursBinding.inflate(inflater, container, false) return binding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) initRcView() model.liveDataCurrent.observe(viewLifecycleOwner){ adapter.submitList(getHoursList(it)) }… Подробнее »Weather app #15 : Список прогноза по часам

Weather app #14 : Показ прогноза на экране

MainFragment import android.Manifestimport android.content.Contextimport android.content.Intentimport android.content.pm.PackageManagerimport android.location.Geocoderimport android.location.Locationimport android.location.LocationManagerimport android.os.Bundleimport android.os.Looperimport android.provider.Settingsimport android.util.Logimport androidx.fragment.app.Fragmentimport android.view.LayoutInflaterimport android.view.Viewimport android.view.ViewGroupimport android.widget.Toastimport androidx.activity.result.ActivityResultLauncherimport androidx.activity.result.contract.ActivityResultContractsimport androidx.appcompat.app.AppCompatActivityimport androidx.core.app.ActivityCompatimport androidx.fragment.app.FragmentActivityimport androidx.fragment.app.activityViewModelsimport com.android.volley.Requestimport com.android.volley.toolbox.StringRequestimport com.android.volley.toolbox.Volleyimport com.google.android.gms.location.*import com.google.android.gms.tasks.*import com.google.android.material.tabs.TabLayoutMediatorimport com.meter_alc_rgb.weatherappcurse.MainViewModelimport com.meter_alc_rgb.weatherappcurse.Rimport com.meter_alc_rgb.weatherappcurse.adapters.VpAdapterimport com.meter_alc_rgb.weatherappcurse.adapters.WeatherItemimport com.meter_alc_rgb.weatherappcurse.databinding.FragmentMainBindingimport com.meter_alc_rgb.weatherappcurse.utils.DialogManagerimport com.meter_alc_rgb.weatherappcurse.utils.TimeUtilsimport com.squareup.picasso.Picassoimport org.json.JSONObjectimport java.lang.NumberFormatExceptionconst val API_KEY = “Ваш API ключ”class MainFragment : Fragment() { private var mFusedLocationClient: FusedLocationProviderClient? = null private val model : MainViewModel by activityViewModels() private val fList = listOf<Fragment>( HoursFragment.newInstance(), DaysFragment.newInstance()… Подробнее »Weather app #14 : Показ прогноза на экране