Skip to content

Instantly share code, notes, and snippets.

@Singleton
public class ActivityNotLeakerISwear implements Application.ActivityLifecycleCallbacks {
private static final Logger LOGGER = LoggerFactory.getLogger(URLHandler.class);
@Nullable
private Activity currentActivity;
@Inject
public ActivityNotLeakerISwear() {
}
public final class Injector {
private static final String INJECTOR_SERVICE = "ACTIVITY_COMPONENT";
private static final String INJECTOR_SERVICE_APP = "INJECTOR_SERVICE_APP";
private Injector() {
}
public static AppComponent obtainAppComponent(Context context) {
//noinspection ResourceType
client = mock(Client.class);
Lazy<Client> lazyClient = mock(Lazy.class);
when(client.get()).thenReturn(client);
assetStore = new AssetStore(lazyClient);
allprojects {
repositories {
mavenLocal()
maven {
url 'https://plugins.gradle.org/m2/'
}
maven {
url = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
}
public class ToDoApplication extends Application implements HasActivityInjector {
@Inject
DispatchingAndroidInjector<Activity> activityInjector;
@Override
public void onCreate() {
super.onCreate();
DaggerAppComponent.builder().application(this).build().inject(this);
}
/*
* Copyright 2013 Chris Banes
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
//MIKE: I am sorry for following code, the reason we need this is that slf4j adds the impl in our compile tasks
//test tasks then add no-op slf4j but the impl one stil gets chosen as it is first on the classpath
def testConfig = false
configurations.all { configInner ->
if (configInner.name.contains("Unit"))
testConfig = true
}
configurations.all { config ->
if (testConfig && (config.name.contains("Unit") || config.name.contains('googleDebugCompile'))) {
fun setLocaleFromEdition(activity: Activity) {
// At startup, check to see if edition is Espanol. If not, switch it,
// in order to ensure a full spanish experience. AND-5113
if (appPreferences.getPreference(activity.resources.getString(R.string.key_edition), "") == activity.resources.getString(R.string.espanol_edition_value)) {
setLocale(activity.baseContext, Locale("es"))
} else {
// Since we don't support any other languages other than English or Spanish, set the
// Locale to english here to avoid language specific date and other formatting issues...
setLocale(activity.baseContext, Locale("en"))
}
fun parse(dataResponse: ProgramQuery.Data): Program {
val programBuilder = ImmutableProgram.builder()
val moreBlocksBuilder = ImmutableList.builder<BlockItem>()
dataResponse.program_beta()?.apply {
latestNews()?.fragments()?.block()?.let {
programBuilder.briefings(it.asBriefingViewModel())
programBuilder.latestNews(it.asLatestNewsViewModel())
@digitalbuddha
digitalbuddha / dagger.java
Created November 2, 2017 21:02
Dagger Injector
abstract class BaseActivity : AppCompatActivity() {
val activityComponent: ActivityComponent by unsafeLazy {
Injector.create(this)
}
}`
class MyActivity : BaseActivity() {
@Inject lateinit var foo: Foo
override fun onCreate(savedInstanceState: Bundle?) {