Skip to content

Instantly share code, notes, and snippets.

View ProArun's full-sized avatar

Arun Kumar Aditya ProArun

View GitHub Profile
@ProArun
ProArun / MainCoroutineRule.kt
Last active August 20, 2023 06:33
Coroutine unit test
class MainCoroutineRule : TestWatcher(){
//TestWatcher is class which is use to make JUnit rule.
val testDispatcher = StandardTestDispatcher()
override fun starting(discription: Description?){
super.starting(description)
Dispatchers.setMain(testDispatcher)
}
override fun finished(description: Description?){
@ProArun
ProArun / AnimatedContentExample
Created October 2, 2024 16:40
AnimatedContent in Jetpack Compose Example 2
@OptIn(ExperimentalAnimationApi::class)
@Composable
fun AnimatedContentExample(modifier: Modifier = Modifier) {
var expanded by remember {
mutableStateOf(false)
}
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Card(modifier = Modifier.clickable {
@ProArun
ProArun / LazyColumnPosition
Created October 3, 2024 18:35
Save and Restore the Scroll Position of a LazyColumn Persistently
@OptIn(FlowPreview::class)
@Composable
fun LazyColumnPosition(modifier: Modifier = Modifier) {
val context = LocalContext.current
val pref by lazy {
context.getSharedPreferences("prefs", MODE_PRIVATE)
}
val scrollPosition = pref.getInt("scroll_position", 0)
@ProArun
ProArun / AnnotatedString
Created November 12, 2024 18:05
AnnotatedString
@Composable
fun AnnotatedString(modifier: Modifier = Modifier) {
// Define tags for expanded and minified text
val tagExpanded = "expanded_text"
val tagMinified = "minified_text"
// Maintain the state of text toggling (expanded or minified)
val textToggleState = remember { mutableStateOf(Pair(tagMinified, "Read more ...")) }
@ProArun
ProArun / day1.1
Created November 13, 2024 17:20
41. First Missing Positive
class Solution {
public int firstMissingPositive(int[] nums) {
// Solution 1
// int result = 1;
// Map<Integer,Integer> map = new HashMap<Integer,Integer>();
// for(int i = 0; i < nums.length; i++ ){
// map.put(nums[i],i);
// }