Skip to content

Instantly share code, notes, and snippets.

@senamit2708
senamit2708 / readme.txt
Created September 3, 2023 04:40
chaining in constraint layout
To chain these seven CardViews in a ConstraintLayout with equal distance between them, you can use chains and guidelines. Here's how you can do it:
1. First, define horizontal guidelines to create equal spacing between the CardViews. Add these lines to your ConstraintLayout:
```xml
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
@senamit2708
senamit2708 / lambdafile.kt
Created July 18, 2023 07:43
lambda function learning
fun main(){
var fn: (a: Int, b: Int) -> Int = ::sum
var lambdaOne: (Int,Int)->Int = {x: Int, y: Int -> x+y }
multiLineLambda()
val singleParameter: (Int) -> (Int) = {x: Int -> x * x}
val simplifySingleParameter: (Int) -> (Int) = {it * it}
calculator(1, 2){a,b -> a +b} //if lambda expression is the last parameter of a function
//you can write that lamdba in above way also.
@senamit2708
senamit2708 / build.gradle(Module: app)
Created July 13, 2023 05:42
how to define library constant in gradle file
//navigation
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
//room database
implementation "androidx.room:room-ktx:$room_version"
kapt "androidx.room:room-compiler:$room_version"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
@senamit2708
senamit2708 / ApiInterface.kt
Last active July 12, 2023 12:30
Retrofit with IgnoreError and continue with coroutine
package com.example.coroutinelearning.retrofits
import com.example.coroutinelearning.entity.Root
import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Query
interface ApiInterface {
@GET("/api/users")
@senamit2708
senamit2708 / ApiInterface.kt
Created July 12, 2023 11:17
Retrofit: Parallel network call
package com.example.coroutinelearning.retrofits
import com.example.coroutinelearning.entity.Root
import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Query
interface ApiInterface {
@GET("/api/users")
@senamit2708
senamit2708 / ApiInterface.kt
Created July 12, 2023 09:07
Retrofit with Series network call having coroutine and sealed class
package com.example.coroutinelearning.retrofits
import com.example.coroutinelearning.entity.Root
import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Query
interface ApiInterface {
@GET("/api/users")
@senamit2708
senamit2708 / ApiInterface.kt
Created July 11, 2023 14:27
Retrofit with coroutine -> Advance One
package com.example.coroutinelearning.retrofits
import com.example.coroutinelearning.entity.Root
import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Query
interface ApiInterface {
@GET("/api/users")
@senamit2708
senamit2708 / AndroidMainfest.xml
Created July 11, 2023 07:11
Retrofit Basic Learning
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
@senamit2708
senamit2708 / NewUserEntryFragment.kt
Last active August 11, 2023 13:13
extension function
private fun saveUserDetailToDB() {
val name = binding.txtName.text.toString()
var mobNo = binding.txtMobNo.text.toString()
mobNo = mobNo.addMobileExtension() //extension function
var user = User(name = name, mobileNumber = mobNo)
user = user.firstLetterCapital() //extension function
userViewModel.saveUserDetail(user)
}
@senamit2708
senamit2708 / Employee.kt
Created July 6, 2023 09:10
Sealed Class Learning
package com.example.coroutinelearning.entity
sealed class Employee //there is no need of {}, its optional
//if you use {}, u have to call class with use of Employee class, like Employee.Manager from fragment/activity. else u will be
//able to directly call it.
data class Manager(val name: String, val age: Int, val team: List<String>) : Employee()
class SeniorDev(val name: String, val age: Int, val project: String) : Employee()
object JuniorDev : Employee()