Skip to content

Instantly share code, notes, and snippets.

View adam-hurwitz's full-sized avatar

Adam Hurwitz adam-hurwitz

View GitHub Profile
@adam-hurwitz
adam-hurwitz / FeedViewTest.kt
Last active October 4, 2020 09:16
Android Model-View-Intent with Unit Tests - FeedViewTest.kt Bind Interface
private lateinit var test: FeedViewTestCase
private val intent = FeedViewIntent()
@ParameterizedTest
@MethodSource("FeedViewTestCaseStream")
fun `FeedView`(feedViewTestCase: FeedViewTestCase) = testCoroutineDispatcher.runBlockingTest {
test = feedViewTestCase
mockComponents(test)
val viewModel = FeedViewModel(...)
viewModel.bindIntents(object : FeedView {
@adam-hurwitz
adam-hurwitz / FeedViewTestExtension.kt
Created October 3, 2020 23:51
Android Model-View-Intent with Unit Tests - FeedViewTestExtension.kt
@ExperimentalCoroutinesApi
class FeedViewTestExtension : BeforeEachCallback, AfterEachCallback, ParameterResolver {
override fun beforeEach(context: ExtensionContext?) {
// Set TestCoroutineDispatcher.
Dispatchers.setMain(context?.root
?.getStore(TEST_COROUTINE_DISPATCHER_NAMESPACE)
?.get(TEST_COROUTINE_DISPATCHER_KEY, TestCoroutineDispatcher::class.java)!!)
// Set LiveData Executor.
ArchTaskExecutor.getInstance().setDelegate(object : TaskExecutor() {
@adam-hurwitz
adam-hurwitz / FeedViewTest.kt
Last active October 4, 2020 00:08
Android Model-View-Intent with Unit Tests - FeedViewTest.kt Mocks
@ExperimentalCoroutinesApi
@ExtendWith(FeedViewTestExtension::class)
class FeedViewTest(
val testCoroutineDispatcher: TestCoroutineDispatcher,
val testCoroutineScope: TestCoroutineScope
) {
private fun FeedViewTestCaseStream() = feedViewTestCaseStream()
private lateinit var test: FeedViewTestCase
private val repository = mockkClass(FeedRepository::class)
@adam-hurwitz
adam-hurwitz / Glide.markdown
Created September 24, 2020 04:14
First Load — Total Time for Glide
Trials Time (ms)
1 447
2 413
3 404
4 438
5 473
6 444
7 442
8 422
@adam-hurwitz
adam-hurwitz / Coil.markdown
Last active September 24, 2020 04:14
First Load — Total Time for Coil
Trials Time (ms)
1 872
2 478
3 393
4 506
5 439
6 443
7 520
8 461
@adam-hurwitz
adam-hurwitz / placeholder.xml
Last active September 14, 2020 02:12
Vector Image Placeholder
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/placeholder">
<stroke
android:width="1dp"
android:color="@color/colorAccent"/>
<padding
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
@adam-hurwitz
adam-hurwitz / MainActivity.kt
Last active August 14, 2020 22:46
ODG - Navigation: BottomNavigationView
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val appBarConfiguration = AppBarConfiguration(setOf(R.id.nav_home, R.id.nav_screenTwo))
val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host) as NavHostFragment
val navController = navHostFragment.navController
setupActionBarWithNavController(navController, appBarConfiguration)
bottomNavigation.setupWithNavController(navController)
}
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
@adam-hurwitz
adam-hurwitz / GetMediaFilesSavedLocally.kt
Last active August 12, 2020 20:51
Get media files saved locally
/**
* From Google's CameraXbasic sample app's MainActivity.kt and GalleryFragment.kt
* See: [https://github.com/android/camera-samples/tree/master/CameraXBasic#cameraxbasic]
*/
val EXTENSION_WHITELIST = arrayOf("JPG")
/** Use external media if it is available, our app's file directory otherwise */
fun getOutputDirectory(context: Context): File {
val appContext = context.applicationContext
@adam-hurwitz
adam-hurwitz / ClickListener.java
Created July 22, 2020 19:25
ODG - Android Touch Feedback: Click listener abbreviation
// Pass method
layoutName.setOnClickListener(onItemClicked);
private View.OnClickListener onItemClicked = view → // Do something;
// Or
private View.OnClickListener onItemClicked =
view → {
// Do something;
};