Skip to content

Instantly share code, notes, and snippets.

Avatar

Josef Raska jraska

View GitHub Profile
View PushIntegrationtest.kt
class PushIntegrationTest {
lateinit var pushClient: PushServerClient
lateinit var thisDeviceToken: String
@get:Rule
val pushRule = PushAwaitRule()
@Before
fun setUp() {
View Dependencies.kt
class Dependencies : Plugin<Project> {
override fun apply(project: Project) {
// Possibly common dependencies or can stay empty
}
companion object {
val FIREBASE_MESSAGING = "com.google.firebase:firebase-messaging:20.1.7"
}
}
View app-build.gradle
moduleGraphAssert {
maxHeight = 4
allowed = [':.* -> :core', ':feature.* -> :lib.*'] // regex to match module names - anyone can depend on :core, features can depend on libraries
restricted = [':feature-[a-z]* -X> :forbidden-to-depend-on'] // no feature can depend on :forbidden-to-depend-on
}
View ModuleDependencies.kt
fun moduleDependencies(project: Project): List<Project> {
return project.configurations
.filter { it.name == "api" || it.name == "implementation" }
.flatMap { configuration ->
configuration.dependencies.filterIsInstance(DefaultProjectDependency::class.java)
.map { it.dependencyProject }
}
}
View UsersViewModel.kt
class UsersViewModel(val navigator: Navigator) : ViewModel {
fun onUserClicked(user: User) {
// Business logic, analytics, any other compex interactions
navigator.startUserDetail(user.login)
}
}
View AsyncNavigator.kt
class AsyncNavigator(val topActivityProvider: TopActivityProvider) : Navigator {
override fun startUserDetail(login: String) {
topActivityProvider.onTopActivity { activity -> UserDetailActivity.start(activity, login) }
}
override fun showSettings() {
topActivityProvider.onTopActivity { activity -> SettingsActivity.start(activity) }
}
}
View TopActivityProvider.kt
class TopActivityProvider {
private val pendingActions = mutableListOf<(Activity) -> Unit>()
var topActivity: Activity? = null
private set
@AnyThread
fun onTopActivity(action: (Activity) -> Unit) {
val topActivity = this.topActivity
View NavigatorSync.kt
class NavigatorSync(private val topActivityProvider: TopActivityProvider) : Navigator
override fun startUserDetail(login: String) {
topActivityProvider.topActivity?.let { activity -> UserDetailActivity.start(activity, login) }
}
override fun showSettings() {
topActivityProvider.topActivity?.let { activity -> SettingsActivity.start(activity) }
}
}
View TopActivityProviderBasic.kt
class TopActivityProvider {
var topActivity: Activity? = null
private set
private val callbacks: Application.ActivityLifecycleCallbacks = object : ActivityLifecycleCallbacks {
override fun onActivityResumed(activity: Activity) {
topActivity = activity
}
View Navigator.kt
interface Navigator {
fun startUserDetail(login: String)
fun showSettings()
}