Skip to content

Instantly share code, notes, and snippets.

View pfmaggi's full-sized avatar

Pietro F. Maggi pfmaggi

View GitHub Profile
#!/bin/bash
DEVICES=`adb devices | grep -v devices | grep device | cut -f 1`
for device in $DEVICES; do
DISPLAYS=`adb -s $device shell dumpsys SurfaceFlinger --display-id | cut -d" " -f 2`
for display in $DISPLAYS; do
echo "Capturing from $display on $device"
output="screen_$(echo $device)_$(echo $display)_$(date +%Y%m%d_%H%M%S).png"
adb -s $device exec-out screencap -p -d $display > $output
done
@pfmaggi
pfmaggi / IoschedFirebaseMessagingService.kt
Created March 31, 2020 18:46
Code for the Medium article: "Customizing WorkManager"
/* Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
private fun scheduleFetchEventData() {
val constraints = Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build()
val conferenceDataWorker = OneTimeWorkRequestBuilder<ConferenceDataWorker>()
.setInitialDelay(MINIMUM_LATENCY, TimeUnit.SECONDS)
.setConstraints(constraints)
@pfmaggi
pfmaggi / SharedModule.kt
Created March 31, 2020 18:43
Code for the Medium article: "Customizing WorkManager"
/* Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
@Singleton
@Provides
fun provideWorkManagerConfiguration(
ioschedWorkerFactory: IoschedWorkerFactory
): Configuration {
return Configuration.Builder()
.setWorkerFactory(ioschedWorkerFactory)
.build()
@pfmaggi
pfmaggi / SharedModule.kt
Created March 31, 2020 18:40
Code for the Medium article: "Customizing WorkManager"
/* Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
@Singleton
@Provides
fun provideWorkManagerConfiguration(
ioschedWorkerFactory: IoschedWorkerFactory
): Configuration {
return Configuration.Builder()
.setMinimumLoggingLevel(android.util.Log.DEBUG)
.setWorkerFactory(ioschedWorkerFactory)
@pfmaggi
pfmaggi / MainApplication.kt
Created March 31, 2020 18:37
Code for the Medium article: "Customizing WorkManager"
/* Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
@Inject lateinit var workerConfiguration: Configuration
// Setup custom configuration for WorkManager with a DelegatingWorkerFactory
override fun getWorkManagerConfiguration(): Configuration {
return workerConfiguration
}
@pfmaggi
pfmaggi / IoschedWorkerFactory.kt
Created March 31, 2020 18:09
Code for the Medium article: "Customizing WorkManager"
/* Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
@Singleton
class IoschedWorkerFactory @Inject constructor(
refreshConferenceDataUseCase: RefreshConferenceDataUseCase
) : DelegatingWorkerFactory() {
init {
addFactory(ConferenceDataWorkerFactory(refreshConferenceDataUseCase))
}
}
@pfmaggi
pfmaggi / ConferenceDataWorkerFactory.kt
Created March 31, 2020 17:50
Code for the Medium article: "Customizing WorkManager"
/* Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
class ConferenceDataWorkerFactory(
private val refreshEventDataUseCase: RefreshConferenceDataUseCase
) : WorkerFactory() {
override fun createWorker(
appContext: Context,
workerClassName: String,
workerParameters: WorkerParameters
@pfmaggi
pfmaggi / ConferenceDataWorker.kt
Last active March 31, 2020 17:46
Code for the Medium article: "Customizing WorkManager"
/* Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
/**
* A Job that refreshes the conference data in the repository (if the app is active) and
* in the cache (if the app is not active).
*/
class ConferenceDataWorker(
ctx: Context,
params: WorkerParameters,
private val refreshEventDataUseCase: RefreshConferenceDataUseCase
@pfmaggi
pfmaggi / MyApplication.kt
Created March 31, 2020 17:39
Code for the Medium article: "Customizing WorkManager"
/* Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
class MyApplication : Application(), Configuration.Provider {
@Inject lateinit var myWorkerFactory: MyWorkerFactory
...
override fun getWorkManagerConfiguration(): Configuration =
Configuration.Builder()
.setMinimumLoggingLevel(android.util.Log.INFO)
@pfmaggi
pfmaggi / MyApplication.kt
Created March 31, 2020 17:37
Code for the Medium article: "Customizing WorkManager"
/* Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
class MyApplication : Application(), Configuration.Provider {
// other @Inject variables
lateinit var appComponent: AppComponent
override fun onCreate() {
super.onCreate()