neco2018

Retrofit2 | #8

https://youtu.be/tYl0v8lQcT4 LoginFragment.kt import android.os.Bundleimport androidx.fragment.app.Fragmentimport android.view.LayoutInflaterimport android.view.Viewimport android.view.ViewGroupimport androidx.fragment.app.activityViewModelsimport androidx.navigation.fragment.findNavControllerimport com.example.retrofitlesson.databinding.FragmentLoginBindingimport com.example.retrofitlesson.retrofit.AuthRequestimport com.example.retrofitlesson.retrofit.MainApiimport com.squareup.picasso.Picassoimport kotlinx.coroutines.CoroutineScopeimport kotlinx.coroutines.Dispatchersimport kotlinx.coroutines.launchimport okhttp3.OkHttpClientimport okhttp3.logging.HttpLoggingInterceptorimport org.json.JSONObjectimport retrofit2.Retrofitimport retrofit2.converter.gson.GsonConverterFactoryclass LoginFragment : Fragment() { private lateinit var binding: FragmentLoginBinding private lateinit var mainApi: MainApi private val viewModel: LoginViewModel by activityViewModels() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View { binding = FragmentLoginBinding.inflate(inflater, container, false) return binding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view,… Подробнее »Retrofit2 | #8

Retrofit2 | #7

BaseActivity.kt import android.os.Bundleimport androidx.appcompat.app.AppCompatActivityimport com.example.retrofitlesson.databinding.ContentBaseBindingclass BaseActivity : AppCompatActivity() { private lateinit var binding: ContentBaseBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ContentBaseBinding.inflate(layoutInflater) setContentView(binding.root) }} content_base.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” android:layout_width=”match_parent” android:layout_height=”match_parent” app:layout_behavior=”@string/appbar_scrolling_view_behavior”> <fragment android:id=”@+id/nav_host_fragment_content_base” android:name=”androidx.navigation.fragment.NavHostFragment” android:layout_width=”0dp” android:layout_height=”0dp” app:defaultNavHost=”true” app:layout_constraintBottom_toBottomOf=”parent” app:layout_constraintEnd_toEndOf=”parent” app:layout_constraintStart_toStartOf=”parent” app:layout_constraintTop_toTopOf=”parent” app:navGraph=”@navigation/nav_graph” /></androidx.constraintlayout.widget.ConstraintLayout> nav_graph.xml <?xml version=”1.0″ encoding=”utf-8″?><navigation 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:id=”@+id/nav_graph” app:startDestination=”@id/loginFragment”> <fragment android:id=”@+id/loginFragment” android:name=”com.example.retrofitlesson.LoginFragment” tools:layout=”@layout/fragment_login”> <action android:id=”@+id/action_loginFragment_to_productsFragment” app:destination=”@id/productsFragment” /> </fragment> <fragment android:id=”@+id/productsFragment” android:name=”com.example.retrofitlesson.ProductsFragment” tools:layout=”@layout/fragment_products”> </fragment></navigation> LoginFragment.kt… Подробнее »Retrofit2 | #7

Retrofit2 | #6

MainActivity.kt import android.os.Bundleimport android.util.Logimport android.widget.Buttonimport android.widget.ListAdapterimport android.widget.SearchView.OnQueryTextListenerimport android.widget.TextViewimport androidx.appcompat.app.AppCompatActivityimport androidx.recyclerview.widget.LinearLayoutManagerimport com.example.retrofitlesson.adapter.ProductAdapterimport com.example.retrofitlesson.databinding.ActivityMainBindingimport com.example.retrofitlesson.retrofit.AuthRequestimport com.example.retrofitlesson.retrofit.MainApiimport com.example.retrofitlesson.retrofit.Userimport com.squareup.picasso.Picassoimport kotlinx.coroutines.CoroutineScopeimport kotlinx.coroutines.Dispatchersimport kotlinx.coroutines.launchimport okhttp3.OkHttpClientimport okhttp3.logging.HttpLoggingInterceptorimport retrofit2.Retrofitimport retrofit2.converter.gson.GsonConverterFactoryclass MainActivity : AppCompatActivity() { private lateinit var adapter: ProductAdapter lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) supportActionBar?.title = “Гость” adapter = ProductAdapter() binding.rcView.layoutManager = LinearLayoutManager(this) binding.rcView.adapter = adapter val interceptor = HttpLoggingInterceptor() interceptor.level = HttpLoggingInterceptor.Level.BODY val client = OkHttpClient.Builder() .addInterceptor(interceptor)… Подробнее »Retrofit2 | #6

Retrofit2 | #5

MainActivity.kt import android.os.Bundle import android.widget.SearchView.OnQueryTextListener import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager import com.example.retrofitlesson.adapter.ProductAdapter import com.example.retrofitlesson.databinding.ActivityMainBinding import com.example.retrofitlesson.retrofit.MainApi import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import okhttp3.OkHttpClient import okhttp3.logging.HttpLoggingInterceptor import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory class MainActivity : AppCompatActivity() { private lateinit var adapter: ProductAdapter lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) adapter = ProductAdapter() binding.rcView.layoutManager = LinearLayoutManager(this) binding.rcView.adapter = adapter val interceptor = HttpLoggingInterceptor() interceptor.level = HttpLoggingInterceptor.Level.BODY val… Подробнее »Retrofit2 | #5

RuleGame Compose | #2

https://youtu.be/5DsjouGYJnE NumberUtils.kt object ValueList { val list = listOf( 0, 32, 15, 19, 4, 21, 2, 25, 17, 34, 6, 27, 13, 36, 11, 30, 8, 23, 10, 5, 24, 16, 33, 1, 20, 14, 31, 9, 22, 18, 29, 7, 28, 12, 35, 3, 26 ) } RuleScreen.kt import android.util.Log import androidx.compose.animation.core.LinearOutSlowInEasing import androidx.compose.animation.core.animateFloatAsState import androidx.compose.animation.core.tween import androidx.compose.foundation.Image import androidx.compose.foundation.layout.* import androidx.compose.material.Button import androidx.compose.material.ButtonColors import androidx.compose.material.ButtonDefaults import androidx.compose.material.Text import… Подробнее »RuleGame Compose | #2

RuleGame JetpackCompose | #1

https://youtu.be/BoVmq24wRGE MainActivity.kt import android.os.Bundleimport androidx.activity.ComponentActivityimport androidx.activity.compose.setContentimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.material.MaterialThemeimport androidx.compose.material.Surfaceimport androidx.compose.material.Textimport androidx.compose.runtime.Composableimport androidx.compose.ui.Modifierimport androidx.compose.ui.tooling.preview.Previewimport com.example.rulegamecompose.rule_screen.RuleScreenimport com.example.rulegamecompose.ui.theme.GreenBgimport com.example.rulegamecompose.ui.theme.RuleGameComposeThemeclass MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { RuleGameComposeTheme { // A surface container using the ‘background’ color from the theme Surface( modifier = Modifier.fillMaxSize(), color = GreenBg ) { RuleScreen() } } } }} RuleScreen.kt import androidx.compose.foundation.Imageimport androidx.compose.foundation.layout.*import androidx.compose.material.Buttonimport androidx.compose.material.ButtonDefaultsimport androidx.compose.material.Textimport androidx.compose.runtime.Composableimport androidx.compose.ui.Modifierimport androidx.compose.ui.graphics.Colorimport androidx.compose.ui.graphics.Color.Companion.Redimport androidx.compose.ui.graphics.Color.Companion.Whiteimport androidx.compose.ui.res.painterResourceimport androidx.compose.ui.text.font.FontWeightimport androidx.compose.ui.unit.dpimport… Подробнее »RuleGame JetpackCompose | #1

Retrofit2 | #4

https://youtu.be/Bh3F4aWDRz0 MainActivity.kt import android.os.Bundleimport android.util.Logimport android.widget.Buttonimport android.widget.ListAdapterimport android.widget.TextViewimport androidx.appcompat.app.AppCompatActivityimport androidx.recyclerview.widget.LinearLayoutManagerimport com.example.retrofitlesson.adapter.ProductAdapterimport com.example.retrofitlesson.databinding.ActivityMainBindingimport com.example.retrofitlesson.retrofit.AuthRequestimport com.example.retrofitlesson.retrofit.MainApiimport com.squareup.picasso.Picassoimport kotlinx.coroutines.CoroutineScopeimport kotlinx.coroutines.Dispatchersimport kotlinx.coroutines.launchimport okhttp3.OkHttpClientimport okhttp3.logging.HttpLoggingInterceptorimport retrofit2.Retrofitimport retrofit2.converter.gson.GsonConverterFactoryclass MainActivity : AppCompatActivity() { private lateinit var adapter: ProductAdapter lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) adapter = ProductAdapter() binding.rcView.layoutManager = LinearLayoutManager(this) binding.rcView.adapter = adapter val interceptor = HttpLoggingInterceptor() interceptor.level = HttpLoggingInterceptor.Level.BODY val client = OkHttpClient.Builder() .addInterceptor(interceptor) .build() val retrofit =… Подробнее »Retrofit2 | #4

Retrofit2 | #3

MainActivity.kt import android.os.Bundleimport android.widget.Buttonimport android.widget.TextViewimport androidx.appcompat.app.AppCompatActivityimport com.example.retrofitlesson.databinding.ActivityMainBindingimport com.example.retrofitlesson.retrofit.AuthRequestimport com.example.retrofitlesson.retrofit.MainApiimport com.squareup.picasso.Picassoimport kotlinx.coroutines.CoroutineScopeimport kotlinx.coroutines.Dispatchersimport kotlinx.coroutines.launchimport okhttp3.OkHttpClientimport okhttp3.logging.HttpLoggingInterceptorimport retrofit2.Retrofitimport retrofit2.converter.gson.GsonConverterFactoryclass MainActivity : AppCompatActivity() { lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) val interceptor = HttpLoggingInterceptor() interceptor.level = HttpLoggingInterceptor.Level.BODY val client = OkHttpClient.Builder() .addInterceptor(interceptor) .build() val retrofit = Retrofit.Builder() .baseUrl(“https://dummyjson.com”).client(client) .addConverterFactory(GsonConverterFactory.create()).build() val mainApi = retrofit.create(MainApi::class.java) binding.button.setOnClickListener { CoroutineScope(Dispatchers.IO).launch { val user = mainApi.auth( AuthRequest( binding.usarename.text.toString(), binding.password.text.toString() )… Подробнее »Retrofit2 | #3

Retrofit2 | #2

Зависимости: implementation ‘com.squareup.okhttp3:logging-interceptor:4.7.2’implementation ‘com.squareup.okhttp3:okhttp:4.7.2’ MainActivity.kt import android.os.Bundleimport android.widget.Buttonimport android.widget.TextViewimport androidx.appcompat.app.AppCompatActivityimport com.example.retrofitlesson.retrofit.ProductApiimport kotlinx.coroutines.CoroutineScopeimport kotlinx.coroutines.Dispatchersimport kotlinx.coroutines.launchimport okhttp3.OkHttpClientimport okhttp3.logging.HttpLoggingInterceptorimport retrofit2.Retrofitimport retrofit2.converter.gson.GsonConverterFactoryclass MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val tv = findViewById<TextView>(R.id.tv) val b = findViewById<Button>(R.id.button) val interceptor = HttpLoggingInterceptor() interceptor.level = HttpLoggingInterceptor.Level.BODY val client = OkHttpClient.Builder() .addInterceptor(interceptor) .build() val retrofit = Retrofit.Builder() .baseUrl(“https://dummyjson.com”).client(client) .addConverterFactory(GsonConverterFactory.create()).build() val productApi = retrofit.create(ProductApi::class.java) b.setOnClickListener { CoroutineScope(Dispatchers.IO).launch { val product = productApi.getProductById(3) runOnUiThread {… Подробнее »Retrofit2 | #2