This file contains 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 solid; | |
public class _5DI { | |
// dependency inversion principle | |
// wrong | |
private class Email { | |
private void sendEmail() { | |
} |
This file contains 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.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}") |
This file contains 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.croutinesdemo | |
import retrofit2.Call | |
import retrofit2.Response | |
import retrofit2.http.GET | |
// api | |
interface API { | |
@GET("/comments") | |
fun getComments(): Call<List<Comment>> // apiCallWithRetrofitDemo1(), apiCallWithRetrofitDemo2() |
This file contains 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
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) { |
This file contains 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
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") | |
} | |
} |
This file contains 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
@UninstallModules(APIModule::class, OtherModule::class) | |
@HiltAndroidTest | |
class MainActivityTest { | |
@get:Rule | |
var hiltRule = HiltAndroidRule(this) | |
@Rule | |
@JvmField | |
val activityRule = ActivityTestRule(MainActivity::class.java, true, false) |
This file contains 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(ActivityComponent::class) | |
class TestOtherModule { | |
@Provides | |
fun giveFeedListAdapter(): FeedListAdapter = FeedListAdapter() | |
} |
This file contains 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 TestAPIModule { | |
@Provides | |
fun giveRetrofitAPIService(): API = | |
Retrofit.Builder() | |
.baseUrl("http://localhost:8080/") | |
// .baseUrl("http://127.0.0.1:8080") // this too works | |
.addConverterFactory(MoshiConverterFactory.create()) |
This file contains 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
android { | |
... | |
defaultConfig { | |
... | |
testInstrumentationRunner "com.example.newsapp.runner.NewsRunner" | |
... | |
} | |
} |
This file contains 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 NewsRunner : AndroidJUnitRunner() { | |
override fun newApplication( | |
cl: ClassLoader?, | |
className: String?, | |
context: Context? | |
): Application { | |
return super.newApplication(cl, HiltTestApplication::class.java.name, context) | |
} | |
} |