Skip to content

Instantly share code, notes, and snippets.

View AdamMc331's full-sized avatar

Adam McNeilly AdamMc331

View GitHub Profile
@AdamMc331
AdamMc331 / DynamicInterval.kt
Created July 30, 2023 00:58
Interval Flowables
private fun buildFlowableFromIntervals(
intervals: List<Interval>,
): Flowable<ApiResponse> {
val intervalFlowables = intervals.map(::buildFlowableForInterval)
val completeFlowable = Flowable.concat(intervalFlowables)
return completeFlowable
.flatMap {
apiSingle().toFlowable()
@AdamMc331
AdamMc331 / AnalyticsEvent.kt
Created February 17, 2022 04:18
Demonstrating my approach to analytics tracking.
/**
* Interface defining the contract of any event that can be tracked in the app. It includes a unique key identifying the event,
* and ability to record properties.
*/
interface AnalyticsEvent {
val eventName: String
val properties: Map<String, Any>
}
@AdamMc331
AdamMc331 / UIImage.kt
Created November 30, 2021 15:46
Shows how UIImage concept can be used for prod and previews.
sealed class UiImage {
data class LocalImage(val imageRes: Int) : UiImage()
data class RemoteImage(val imageUrl: String) : UiImage()
}
// Component
@Composable
fun UserProfile(
avatar: UiImage,
)
class DramaCategoryFragment : Fragment(R.layout.fragment_drama_category),
MovieListAdapter.FavouriteMovieListener {
// ...
private fun getDramaMovies() {
val movieAPI = MoviesData.defaultInstance()
// ...
@AdamMc331
AdamMc331 / .gitignore
Created August 12, 2021 15:06
Short example of storing API Keys for an Android repo.
local.properties
# Don't forget to ignore this from your source control
val cameroonNumberTranslator = object : OffsetMapping {
override fun originalToTransformed(offset: Int): Int {
// [offset [0 - 2] remain the same]
if (offset <= 2) return offset
// [3 - 5] transformed to [4 - 6] respectively
if (offset <= 5) return offset + 1
// [6 - 8] transformed to [8 - 10] respectively
if (offset <= 8 ) return offset + 2
return 11 // Total number of digits, plus two hyphens
}
@AdamMc331
AdamMc331 / Fragment.kt
Created June 8, 2021 21:38
Example for navigating with ViewModel to Fragment
class Fragment : Fragment() {
fun listenForNavigation() {
lifecycleScope.launchWhenResumed {
val directions = viewModel.navigationChannel.receive()
findNavController().navigate(directions)
}
}
}
@AdamMc331
AdamMc331 / gist:27c6e95d52068b665eb465dd082eb9af
Created March 24, 2021 15:25
Day/Night Jetpack Compose Preview template. I called this `dayNightPrev`.
// NOTES: This doesn't help you import it into Intellij, I don't have the time to write that up right now, but if you know how
// to create your own live template, you can copy and paste the below.
@Preview(
name = "Night Mode",
uiMode = Configuration.UI_MODE_NIGHT_YES,
)
@Preview(
name = "Day Mode",
uiMode = Configuration.UI_MODE_NIGHT_NO,
@AdamMc331
AdamMc331 / MissingJsonClassAnnotationDetector.kt
Last active February 26, 2021 20:24
A custom lint check for verifying any classes using the `@Json` annotation must also use the `@JsonClass` annotation.
package // ...
import com.android.tools.lint.client.api.UElementHandler
import com.android.tools.lint.detector.api.Category
import com.android.tools.lint.detector.api.Detector
import com.android.tools.lint.detector.api.Implementation
import com.android.tools.lint.detector.api.Issue
import com.android.tools.lint.detector.api.JavaContext
import com.android.tools.lint.detector.api.Scope
import com.android.tools.lint.detector.api.Severity
@AdamMc331
AdamMc331 / PrescriptionCardListController.kt
Created December 11, 2020 01:34
Demonstrating an EpoxyGroupModel implementation and what I would like to do if possible.
/**
* This class is the current implementation.
*
* Notice that in [addPendingPrescriptionCard] and [addActivePrescriptionCard],
* we have relatively identical code:
*
* 1. Create the group.
* 2. Create all the models and add them to the group.
* 3. Add the group to the main controller.
*