Skip to content

Instantly share code, notes, and snippets.

View Audhil's full-sized avatar
🎯
Focusing

Mohammed Audhil Audhil

🎯
Focusing
View GitHub Profile
@Audhil
Audhil / ContentView.swift
Created May 4, 2021 15:28
hands dirty on Swift-UI
//
// ContentView.swift
// SwiftUI-Appu
//
// Created by Mohammed Audhil S on 18/04/21.
//
import SwiftUI
struct ContentView: View {
@Audhil
Audhil / _1ActivityWithOverflowMenu.kt
Last active November 27, 2020 17:22
A simple activity demonstrating use of a NavHostFragment with a navigation drawer or overflow menu. for ref: https://codelabs.developers.google.com/codelabs/android-navigation/#8 explore for deeplinks with navigations and more src code @ https://drive.google.com/drive/folders/10El0eDzCEL1OnTKlFBXwZfq4XdtukGMA?usp=sharing
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.navigation_activity)
val toolbar = findViewById<Toolbar>(R.id.toolbar)
setSupportActionBar(toolbar)
val host: NavHostFragment = supportFragmentManager
.findFragmentById(R.id.my_nav_host_fragment) as NavHostFragment? ?: return
@Audhil
Audhil / designSwiggyApp.txt
Created September 30, 2020 14:34
designing a Swiggy app!
Designing Swiggy-app!
requirements
Kotlin
MVVM - MVI etc
android arch components
Dagger-Hilt, MockK
retrofit2
kotlin coroutines
@Audhil
Audhil / DependencyInversion.java
Created September 29, 2020 19:54
SOLID - get it break it!
package solid;
public class _5DI {
// dependency inversion principle
// wrong
private class Email {
private void sendEmail() {
}
@Audhil
Audhil / api_chaining.kt
Last active September 23, 2020 15:14
Coroutines in NutShell! - (pay attention to file names)
lifecycleScope.launch(Dispatchers.IO) {
val time = measureTimeMillis {
val res1 = async {
println("yup 1st launched: ${Thread.currentThread().name}")
getNetworkResp1()
}.await()
try {
val res2 = async {
println("yup 2nd launched: ${Thread.currentThread().name}")
@Audhil
Audhil / API.kt
Last active September 19, 2020 18:42
Kotlin CoRoutines in NutShell!
package com.example.croutinesdemo
import retrofit2.Call
import retrofit2.Response
import retrofit2.http.GET
// api
interface API {
@GET("/comments")
fun getComments(): Call<List<Comment>> // apiCallWithRetrofitDemo1(), apiCallWithRetrofitDemo2()
@Audhil
Audhil / Event.kt
Created September 13, 2020 17:12
handle livedata only once!
open class Event<out T>(private val content: T) {
var hasBeenHandled = false
private set // Allow external read but not write
/**
* Returns the content and prevents its use again.
*/
fun getContentIfNotHandled(): T? {
return if (hasBeenHandled) {
@Audhil
Audhil / writetofile.kt
Created September 4, 2020 17:11
handy func to write content to internal storage file - useful to print logs, when it gets truncated by logcat!
private fun writeToFile(data: String, context: Context) {
try {
val outputStreamWriter = OutputStreamWriter(context.openFileOutput("config.txt", Context.MODE_PRIVATE))
outputStreamWriter.write(data)
outputStreamWriter.close()
} catch (e: IOException) {
showELog("File write failed: $e")
}
}
@Audhil
Audhil / MainActivityTest.kt
Created August 23, 2020 17:13
instrumentation tests - actual test cases
@UninstallModules(APIModule::class, OtherModule::class)
@HiltAndroidTest
class MainActivityTest {
@get:Rule
var hiltRule = HiltAndroidRule(this)
@Rule
@JvmField
val activityRule = ActivityTestRule(MainActivity::class.java, true, false)
@Audhil
Audhil / TestOtherModule.kt
Created August 23, 2020 17:09
instrumentation tests - Test equivalent for OtherModule.kt
@Module
@InstallIn(ActivityComponent::class)
class TestOtherModule {
@Provides
fun giveFeedListAdapter(): FeedListAdapter = FeedListAdapter()
}