Июль 2022

Weather App JetPack Compose #6 : WeatherModel

WeatherModel data class WeatherModel( val city: String, val time: String, val currentTemp: String, val condition: String, val icon: String, val maxTemp: String, val minTemp: String, val hours: String) 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.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 =… Подробнее »Weather App JetPack Compose #6 : WeatherModel

Weather App JetPack Compose #5: ListItem

UI.kt import androidx.compose.foundation.layout.*import androidx.compose.foundation.shape.RoundedCornerShapeimport androidx.compose.material.Cardimport androidx.compose.material.Textimport androidx.compose.runtime.Composableimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.graphics.Colorimport androidx.compose.ui.text.TextStyleimport androidx.compose.ui.text.font.FontStyleimport androidx.compose.ui.tooling.preview.Previewimport androidx.compose.ui.unit.dpimport androidx.compose.ui.unit.spimport coil.compose.AsyncImageimport com.meter_alc_rgb.weatherappcomposey.ui.theme.BlueLight@Preview(showBackground = true)@Composablefun ListItem() { Card( modifier = Modifier .fillMaxWidth() .padding(top = 3.dp), backgroundColor = BlueLight, elevation = 0.dp, shape = RoundedCornerShape(5.dp) ) { Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically ) { Column( modifier = Modifier.padding( start = 8.dp, top = 5.dp, bottom = 5.dp ) ) { Text(text =… Подробнее »Weather App JetPack Compose #5: ListItem

Weather app #13 : Парсинг массива с прогнозом

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 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.Rimport com.meter_alc_rgb.weatherappcursey.adapters.VpAdapterimport com.meter_alc_rgb.weatherappcursey.adapters.WeatherModelimport com.meter_alc_rgb.weatherappcursey.databinding.FragmentMainBindingimport org.json.JSONObjectconst val API_KEY = “Ваш API KEY”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 override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View {… Подробнее »Weather app #13 : Парсинг массива с прогнозом

Weather app #12 : Парсинг полученных данных

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 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.Rimport com.meter_alc_rgb.weatherappcursey.adapters.VpAdapterimport com.meter_alc_rgb.weatherappcursey.adapters.WeatherModelimport com.meter_alc_rgb.weatherappcursey.databinding.FragmentMainBindingimport org.json.JSONObjectconst val API_KEY = ” Ваш API KEY”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 override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View… Подробнее »Weather app #12 : Парсинг полученных данных

WeatherApp #11: Получение данный с Weather API

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 KEY”class MainFragment : Fragment() { private var mFusedLocationClient: FusedLocationProviderClient? = null private val model : MainViewModel by activityViewModels() private val fList = listOf<Fragment>( HoursFragment.newInstance(), DaysFragment.newInstance()… Подробнее »WeatherApp #11: Получение данный с Weather API

WeatherApp #10: RecyclerView Adapter – Part 2

WeatherAdapter.kt import android.view.LayoutInflaterimport android.view.Viewimport android.view.ViewGroupimport androidx.recyclerview.widget.DiffUtilimport androidx.recyclerview.widget.ListAdapterimport androidx.recyclerview.widget.RecyclerViewimport com.meter_alc_rgb.weatherappcursey.Rimport com.meter_alc_rgb.weatherappcursey.databinding.ListItemBindingclass WeatherAdapter : ListAdapter<WeatherModel, WeatherAdapter.Holder>(Comparator()) { class Holder(view: View) : RecyclerView.ViewHolder(view){ val binding = ListItemBinding.bind(view) fun bind(item: WeatherModel) = with(binding){ tvDate.text = item.time tvCondition.text = item.condition tvTemp.text = item.currentTemp } } class Comparator : DiffUtil.ItemCallback<WeatherModel>(){ override fun areItemsTheSame(oldItem: WeatherModel, newItem: WeatherModel): Boolean { return oldItem == newItem } override fun areContentsTheSame(oldItem: WeatherModel, newItem: WeatherModel): Boolean { return oldItem == newItem }… Подробнее »WeatherApp #10: RecyclerView Adapter – Part 2

Weather App JetPack Compose #4: TabLayout

MainScreen.kt import androidx.compose.foundation.Imageimport androidx.compose.foundation.layout.*import androidx.compose.foundation.shape.RoundedCornerShapeimport androidx.compose.material.*import androidx.compose.runtime.Composableimport 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.ui.theme.BlueLightimport kotlinx.coroutines.launch@Preview(showBackground = true)@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 ) { Text( text… Подробнее »Weather App JetPack Compose #4: TabLayout

WeatherApp #9: RecyclerView Adapter – Part 1

WeatherAdapter import android.view.Viewimport androidx.recyclerview.widget.ListAdapterimport androidx.recyclerview.widget.RecyclerViewimport com.meter_alc_rgb.weatherappcursey.databinding.ListItemBindingclass WeatherAdapter : ListAdapter<WeatherModel, WeatherAdapter.Holder>() { class Holder(view: View) : RecyclerView.ViewHolder(view){ val binding = ListItemBinding.bind(view) fun bind(item: WeatherModel) = with(binding){ tvDate.text = item.time tvCondition.text = item.condition tvTemp.text = item.currentTemp } }} fragment_hours.xml <?xml version=”1.0″ encoding=”utf-8″?><androidx.constraintlayout.widget.ConstraintLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:layout_height=”match_parent” tools:context=”.fragments.HoursFragment”> <androidx.recyclerview.widget.RecyclerView android:id=”@+id/rcView” android:layout_width=”match_parent” android:layout_height=”match_parent” app:layout_constraintBottom_toBottomOf=”parent” app:layout_constraintEnd_toEndOf=”parent” app:layout_constraintHorizontal_bias=”0.0″ app:layout_constraintStart_toStartOf=”parent” app:layout_constraintTop_toTopOf=”parent” app:layout_constraintVertical_bias=”1.0″ /> <TextView android:id=”@+id/tvEmpty” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:gravity=”center” android:text=”Empty” android:visibility=”gone” app:layout_constraintBottom_toBottomOf=”parent” app:layout_constraintEnd_toEndOf=”parent” app:layout_constraintStart_toStartOf=”parent” app:layout_constraintTop_toTopOf=”parent” /></androidx.constraintlayout.widget.ConstraintLayout>

Weather app Jetpack Compose #3

MainScreen.kt import androidx.compose.foundation.Imageimport androidx.compose.foundation.layout.*import androidx.compose.material.Cardimport androidx.compose.material.Iconimport androidx.compose.material.IconButtonimport androidx.compose.material.Textimport androidx.compose.runtime.Composableimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.draw.alphaimport 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.meter_alc_rgb.weatherappcomposey.Rimport com.meter_alc_rgb.weatherappcomposey.ui.theme.BlueLight@Preview(showBackground = true)@Composablefun MainScreen() { Image( painter = painterResource( id = R.drawable.weather_bg ), contentDescription = “im1”, modifier = Modifier .fillMaxSize() .alpha(0.5f), contentScale = ContentScale.FillBounds ) Column( modifier = Modifier .fillMaxSize() .padding(5.dp) ) { Card( modifier = Modifier.fillMaxWidth(), backgroundColor = BlueLight, elevation = 0.dp ) { Column( modifier = Modifier.fillMaxWidth(),… Подробнее »Weather app Jetpack Compose #3