Skip to content

Instantly share code, notes, and snippets.

View parthdesai1208's full-sized avatar
🏢
Working from office

Parth Desai parthdesai1208

🏢
Working from office
View GitHub Profile
@parthdesai1208
parthdesai1208 / Internet Checker
Created March 2, 2021 16:40
Check internet across multiple OS version
fun Context?.isOnline(failBlock : () -> Unit = { globalIntenetFailBock() }, successBlock : () -> Unit ) {
this?.apply {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
val b : Boolean = false
if (cm == null) b = false
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
NetworkCapabilities cap = cm.getNetworkCapabilities(cm.getActiveNetwork())
if (cap == null) b = false
b = cap.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
@parthdesai1208
parthdesai1208 / GPay UPI
Created March 7, 2021 14:48
Accept payment using GPay UPI
private val GOOGLE_REQUEST_CODE: Int = 123
val uriapp = Uri.Builder()
.scheme("upi")
.authority("pay")
.appendQueryParameter("pa", "merchant@bank") //VPA Name here
.appendQueryParameter("pn", "Merchant Name") //merchant name here
.appendQueryParameter("mc", "1234") //merchant code here
.appendQueryParameter("tr", "123456789") //transaction reference id here
.appendQueryParameter("tn", "For shopping") //transaction note here
@parthdesai1208
parthdesai1208 / Live Template
Last active June 2, 2022 16:53
Collections of live template for android studio
Abbreviation: fun0
Description: Function with no parameters
Template text:
fun $NAME$() : $RETURN$ {
return $RETURN$
}
*******************************************************************************************************************************************
Abbreviation: key
Description: Key for a bundle
Template text:
@parthdesai1208
parthdesai1208 / Set Margin
Created August 10, 2021 17:40
Constraint Layout At RunTime
val constraintSet = ConstraintSet()
constraintSet.clone(root_view_of_constaint_layout)
constraintSet.setMargin(view_which_we_apply_margin_on, top/bottom/start/end, int_dp)
constraintSet.applyTo(root_view_of_constaint_layout)
@parthdesai1208
parthdesai1208 / Client
Last active April 6, 2022 13:17
Retrofit
object NursingApiClient {
lateinit var retrofit: Retrofit
val service: ApiInterface by lazy {
val builder = Retrofit.Builder()
.baseUrl(BASE_URL) //e.g., "https://api.github.com/"
//(we can change it at runtime to deal with multiple API versions)
//like, Production, staging, developments etc.
.addConverterFactory(GsonConverterFactory.create())
@parthdesai1208
parthdesai1208 / three sum
Created January 12, 2022 18:40
Kotlin Code assessment
Three Sum
Have the function ThreeSum(arr) take the array of integers stored in arr, and determine if any three distinct numbers
(excluding the first element) in the array can sum up to the first element in the array.
For example: if arr is [8, 2, 1, 4, 10, 5, -1, -1] then there are actually three sets of triplets that sum to
the number 8: [2, 1, 5], [4, 5, -1] and [10, -1, -1].
Your program should return the string true if 3 distinct elements sum to the first element,
otherwise your program should return the string false. The input array will always contain at least 4 elements.
Examples
Input: arrayOf(10, 2, 3, 1, 5, 3, 1, 4, -4, -3, -2)
@parthdesai1208
parthdesai1208 / surface
Last active February 9, 2022 09:24
Jetpack Compose
@Preview
@Composable
fun ForSurface() {
Surface(
shape = MaterialTheme.shapes.medium,
elevation = 2.dp,
border = BorderStroke(1.dp, colorResource(id = R.color.black)), //apply border
color = colorResource(id = R.color.teal_200), //apply foreground color
contentColor = colorResource(id = R.color.white), //apply color to all child view
modifier = Modifier
@parthdesai1208
parthdesai1208 / LazyColumn basic
Last active February 10, 2022 14:19
RecyclerView like in compose
@Preview
@Composable
private fun columnRecyclerView(names: List<String> = List(1000) { "$it" }) {
val context = LocalContext.current
Column(
modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
LazyColumn(modifier = Modifier.padding(vertical = 4.dp)) {
items(names) { name ->
@parthdesai1208
parthdesai1208 / FAB
Last active March 4, 2022 06:05
compose components
FloatingActionButton(onClick = { }, backgroundColor = MaterialTheme.colors.secondary) {
Icon(
painter = painterResource(id = R.drawable.ic_baseline_arrow_upward_24),
contentDescription = "Go Up"
)
@parthdesai1208
parthdesai1208 / custom modifier
Last active March 8, 2022 11:21
compose custom view
fun Modifier.baseLineToTop(firstBaselineToTop: Dp): Modifier {
return this.then(
layout { measurable, constraints ->
val placeable = measurable.measure(constraints = constraints)
// Check the composable has a first baseline
check(placeable[FirstBaseline] != AlignmentLine.Unspecified)
val firstBaseline = placeable[FirstBaseline]