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
@HiltAndroidApp | |
class NewsApplication : Application() |
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
// project level build.gradle | |
classpath 'com.google.dagger:hilt-android-gradle-plugin:{latest_version}' |
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
// app/build.gradle | |
implementation "com.google.dagger:hilt-android:{latest_version}" | |
kapt "com.google.dagger:hilt-android-compiler:{latest_version}" |
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
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") |
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
@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) | |
} |
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 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) |
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 _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); |
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
// 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 |
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
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) | |
} |
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
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) | |
} |