Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
Building Coinverse's Android app

AdamHurwitz AdamSHurwitz

🚀
Building Coinverse's Android app
View GitHub Profile
@AdamSHurwitz
AdamSHurwitz / FeedViewTestExtension.kt
Created Oct 3, 2020
Android Model-View-Intent with Unit Tests - FeedViewTestExtension.kt
View 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() {
@AdamSHurwitz
AdamSHurwitz / FeedViewTest.kt
Last active Oct 4, 2020
Android Model-View-Intent with Unit Tests - FeedViewTest.kt Mocks
View FeedViewTest.kt
@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)
@AdamSHurwitz
AdamSHurwitz / Glide.markdown
Created Sep 24, 2020
First Load — Total Time for Glide
View Glide.markdown
Trials Time (ms)
1 447
2 413
3 404
4 438
5 473
6 444
7 442
8 422
@AdamSHurwitz
AdamSHurwitz / Coil.markdown
Last active Sep 24, 2020
First Load — Total Time for Coil
View Coil.markdown
Trials Time (ms)
1 872
2 478
3 393
4 506
5 439
6 443
7 520
8 461
@AdamSHurwitz
AdamSHurwitz / placeholder.xml
Last active Sep 14, 2020
Vector Image Placeholder
View placeholder.xml
<?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"
@AdamSHurwitz
AdamSHurwitz / MainActivity.kt
Last active Aug 14, 2020
ODG - Navigation: BottomNavigationView
View MainActivity.kt
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)
}
View AndroidManifest.xml
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
@AdamSHurwitz
AdamSHurwitz / GetMediaFilesSavedLocally.kt
Last active Aug 12, 2020
Get media files saved locally
View GetMediaFilesSavedLocally.kt
/**
* 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
@AdamSHurwitz
AdamSHurwitz / ClickListener.java
Created Jul 22, 2020
ODG - Android Touch Feedback: Click listener abbreviation
View ClickListener.java
// Pass method
layoutName.setOnClickListener(onItemClicked);
private View.OnClickListener onItemClicked = view → // Do something;
// Or
private View.OnClickListener onItemClicked =
view → {
// Do something;
};
@AdamSHurwitz
AdamSHurwitz / FeedFragment.kt
Last active Jul 20, 2020
Android Model-View-Intent with Kotlin Flow - LiveData FeedViewState.kt
View FeedFragment.kt
// The view observes the immutable LiveData value emissions
private fun initViewStates() {
feedViewModel.state.feedList.observe(viewLifecycleOwner) { pagedList ->
adapter.submitList(pagedList)
}
}