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 / NewsApplication.kt
Last active July 6, 2020 18:38
application class - gist 3
@HiltAndroidApp
class NewsApplication : Application()
@Audhil
Audhil / build.gradle
Last active July 6, 2020 18:10
project level build.gradle - gist 2
// project level build.gradle
classpath 'com.google.dagger:hilt-android-gradle-plugin:{latest_version}'
@Audhil
Audhil / build.gradle
Last active July 6, 2020 18:10
dagger-hilt - dependencies - gist 1
// app/build.gradle
implementation "com.google.dagger:hilt-android:{latest_version}"
kapt "com.google.dagger:hilt-android-compiler:{latest_version}"
@Audhil
Audhil / FileReader.kt
Last active July 6, 2020 17:57
util - to read fake json response from src code for Instrumentation test cases. for eg., fake response in MockWebServer
object FileReader {
fun readStringFromFile(fileName: String): String {
try {
val inputStream =
(InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as HiltTestApplication).assets.open(
fileName
)
val builder = StringBuilder()
val reader = InputStreamReader(inputStream, "UTF-8")
@Audhil
Audhil / APIModule.kt
Created July 4, 2020 11:07
okhttp with cache contorl - retrofit2, rxJava2, Dagger-Hilt
@Module
@InstallIn(ApplicationComponent::class)
class APIModule {
private val cacheSize: Long = 10 * 1024 * 1024 // 10 MiB
private val cache by lazy {
Cache(NewsApplication.INSTANCE.cacheDir, cacheSize)
}
@Audhil
Audhil / DemoActivity.kt
Last active January 10, 2025 16:02
make autocompletetextview as spinner with textInputLayout
class DemoActivity : AppCompatActivity() {
private val fruits by lazy {
arrayOf("Pomogranate", "Banana", "Mango", "Sappota", "Grape")
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_demo)
@Audhil
Audhil / UpDownCastDemo.java
Created June 21, 2020 18:46
UpCasting & DownCasting in Java - the F*ck you need to know
package _0UpDownCastJava;
// https://www.geeksforgeeks.org/upcasting-vs-downcasting-in-java/
public class UpDownCastDemo {
static class Parent {
String name;
void someMetho() {
System.out.println("yup I'm from Parent! Name: " + name);
@Audhil
Audhil / customtask.gradle
Created March 25, 2020 16:33
custom task for gradle
// custom task - https://blog.mindorks.com/gradle-for-android-developers-getting-the-most-of-it
task copyDebugAPKInDeskTop(dependsOn: 'assembleDebug') {
doLast {
def dest = "/Users/mohammed-2284/Desktop/"
def name = "GAppTrendingRepos.apk"
ext.apk = file("/Users/mohammed-2284/Documents/ZDaggerMigration/WorkerlyXMigration/app/build/outputs/apk/debug/app-debug.apk")
if (ext.apk.exists()) {
copy {
from ext.apk.absolutePath
@Audhil
Audhil / ApplySample.kt
Created February 27, 2020 10:13
kotlin scope function
fun main() {
val valueIs = SomeObj()
val result = valueIs.apply {
this.firstName = "Mohammed"
this.secondName = "Audhil"
}
println(valueIs) // SomeObj(firstName=Mohammed, secondName=Audhil)
println(result) // SomeObj(firstName=Mohammed, secondName=Audhil)
}
@Audhil
Audhil / AlsoSample2.kt
Created February 27, 2020 10:09
kotlin scope function
fun main() {
val valueIs = SomeObj()
val result = valueIs.also {
it.firstName = "Mohammed"
it.secondName = "Audhil"
}
println(valueIs) // SomeObj(firstName=Mohammed, secondName=Audhil)
println(result) // SomeObj(firstName=Mohammed, secondName=Audhil)
}