This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.example.samplecompose | |
| import androidx.compose.animation.core.Animatable | |
| import androidx.compose.animation.core.AnimationSpec | |
| import androidx.compose.animation.core.FastOutSlowInEasing | |
| import androidx.compose.animation.core.LinearEasing | |
| import androidx.compose.animation.core.tween | |
| import androidx.compose.foundation.layout.Box | |
| import androidx.compose.material.SnackbarResult | |
| import androidx.compose.runtime.Composable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MainActivity : AppCompatActivity() { | |
| companion object { | |
| private const val TAG = "MainActivity" | |
| } | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| setContentView(R.layout.activity_main) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| lifecycleScope.launchWhenCreated { | |
| withContext(Dispatchers.IO) { | |
| client.newCall(request).enqueue(responseCallback = object : Callback { | |
| override fun onFailure(call: Call, e: IOException) { | |
| Log.e(MainActivity.TAG, "API Call Failure ${e.localizedMessage}") | |
| } | |
| override fun onResponse(call: Call, response: Response) { | |
| Log.d(MainActivity.TAG, "APi Call Success ${response.body.toString()}") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val client = OkHttpClient.Builder().connectTimeout(5, TimeUnit.SECONDS) | |
| .readTimeout(10, TimeUnit.MINUTES) | |
| .writeTimeout(10, TimeUnit.MINUTES) | |
| .build() | |
| val request = Request.Builder() | |
| .url("https://test-sse-backend.herokuapp.com/events") | |
| .header("Accept", "application/json; q=0.5") | |
| .addHeader("Accept", "text/event-stream") | |
| .build() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val eventSourceListener = object : EventSourceListener() { | |
| override fun onOpen(eventSource: EventSource, response: Response) { | |
| super.onOpen(eventSource, response) | |
| Log.d(MainActivity.TAG, "Connection Opened") | |
| } | |
| override fun onClosed(eventSource: EventSource) { | |
| super.onClosed(eventSource) | |
| Log.d(MainActivity.TAG, "Connection Closed") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dependencies { | |
| implementation 'androidx.core:core-ktx:1.7.0' | |
| implementation 'androidx.appcompat:appcompat:1.4.1' | |
| implementation 'com.google.android.material:material:1.5.0' | |
| implementation 'androidx.constraintlayout:constraintlayout:2.1.3' | |
| // Okhttp | |
| implementation "com.squareup.okhttp3:okhttp:4.9.3" | |
| // Server Sent Events |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Preview(showBackground = true) | |
| @Composable | |
| fun PreviewEmployeeInformation( | |
| @PreviewParameter(SampleEmployeeDataProvider::class) employeeData: EmployeeData | |
| ) { | |
| EmployeeInformationUI( | |
| employeeData | |
| ) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SampleEmployeeDataProvider : PreviewParameterProvider<EmployeeData> { | |
| override val values: Sequence<EmployeeData> = sequenceOf( | |
| EmployeeData( | |
| name = "John Rick", | |
| id = 34, | |
| address = "767, abc colony, xyz city", | |
| dob = "01-01-1999", | |
| bankDetails = BankDetails( | |
| accountNumber = 1234, | |
| ifsc = "IFSC", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (employeeData.previousCompanies.isNotEmpty()) { | |
| append("\nPreview Companies-: ") | |
| for (company in employeeData.previousCompanies) { | |
| appendWithStyle(text = "$company ") | |
| } | |
| } else { | |
| append("\nNo Previous Companies") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Preview | |
| @Composable | |
| fun PreviewEmployeeInformation(){ | |
| EmployeeInformationUI( | |
| fakeEmployeeData() | |
| ) | |
| } |
NewerOlder