Skip to content

Commit

Permalink
Fix the broken build (sky-map-team#449)
Browse files Browse the repository at this point in the history
* Mostly mechanical conversion to Kotlin.

* Trying to get Dagger to work with Kotlin.

* Liberally sprinkle @nullables in the Java code so it compiles again.
As we convert more to Kotlin we'll need to deal with these.

* Fix repositories.

* A bit of reification and some naughty warning suppression and it now
builds without warnings.  Need to get on top of these generics though -
the warning suppressions aren't great.
  • Loading branch information
jaydeetay authored Dec 24, 2021
1 parent a8158c3 commit 045232a
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 54 deletions.
18 changes: 10 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'kotlin-kapt'
}

android {
compileSdkVersion 31
Expand Down Expand Up @@ -81,14 +85,16 @@ android {
dependencies {
implementation project(path: ':datamodel')


// Android support
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.preference:preference:1.1.1'

// Third-party
implementation 'com.google.guava:guava:30.1.1-jre'
implementation 'com.google.dagger:dagger:2.28.3'
annotationProcessor 'com.google.dagger:dagger-compiler:2.28.3'
def dagger_version = "2.40"
implementation "com.google.dagger:dagger:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
// For annotations not in Android but needed by Dagger
implementation 'javax.annotation:jsr250-api:1.0'
// Lite version for Android - it's lighter (obviously) but also doesn't use reflection
Expand Down Expand Up @@ -120,7 +126,3 @@ dependencies {
// Optional -- UI testing with UI Automator
// androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
}

repositories {
mavenCentral()
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@ import javax.inject.Singleton
@Component(modules = [ApplicationModule::class])
interface ApplicationComponent {
// What we expose to dependent components
fun provideStardroidApplication(): StardroidApplication?
fun provideSharedPreferences(): SharedPreferences?
fun provideStardroidApplication(): StardroidApplication
fun provideSharedPreferences(): SharedPreferences
fun provideSensorManager(): SensorManager?
fun provideConnectivityManager(): ConnectivityManager?
fun provideAstronomerModel(): AstronomerModel?
fun provideAstronomerModel(): AstronomerModel
fun provideLocationManager(): LocationManager?
fun provideLayerManager(): LayerManager?
fun provideAccountManager(): AccountManager?
fun provideAnalytics(): AnalyticsInterface?
fun provideLayerManager(): LayerManager
fun provideAccountManager(): AccountManager
fun provideAnalytics(): AnalyticsInterface

@Named("zero")
fun provideMagDec1(): MagneticDeclinationCalculator?
fun provideMagDec1(): MagneticDeclinationCalculator

@Named("real")
fun provideMagDec2(): MagneticDeclinationCalculator?
fun provideMagDec2(): MagneticDeclinationCalculator

// Who can we inject
fun inject(app: StardroidApplication?)
fun inject(activity: EditSettingsActivity?)
fun inject(activity: ImageDisplayActivity?)
fun inject(activity: ImageGalleryActivity?)
fun inject(provider: SearchTermsProvider?)
fun inject(app: StardroidApplication)
fun inject(activity: EditSettingsActivity)
fun inject(activity: ImageDisplayActivity)
fun inject(activity: ImageGalleryActivity)
fun inject(provider: SearchTermsProvider)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import android.net.ConnectivityManager
import android.util.Log
import androidx.core.content.ContextCompat
import androidx.preference.PreferenceManager
import com.google.android.stardroid.ApplicationModule
import com.google.android.stardroid.control.*
import com.google.android.stardroid.layers.*
import com.google.android.stardroid.util.Analytics
Expand Down Expand Up @@ -59,9 +58,9 @@ class ApplicationModule(app: StardroidApplication) {
@Provides
@Singleton
fun provideAstronomerModel(
@Named("zero") magneticDeclinationCalculator: MagneticDeclinationCalculator?
@Named("zero") magneticDeclinationCalculator: MagneticDeclinationCalculator
): AstronomerModel {
return AstronomerModelImpl(magneticDeclinationCalculator!!)
return AstronomerModelImpl(magneticDeclinationCalculator)
}

@Provides
Expand Down Expand Up @@ -116,19 +115,19 @@ class ApplicationModule(app: StardroidApplication) {

@Provides
@Singleton
fun provideAccountManager(context: Context?): AccountManager {
fun provideAccountManager(context: Context): AccountManager {
return AccountManager.get(context)
}

@Provides
@Singleton
fun provideLayerManager(
assetManager: AssetManager?, resources: Resources?, model: AstronomerModel?,
preferences: SharedPreferences?
assetManager: AssetManager, resources: Resources, model: AstronomerModel?,
preferences: SharedPreferences
): LayerManager {
Log.i(TAG, "Initializing LayerManager")
val layerManager = LayerManager(preferences!!)
layerManager.addLayer(StarsLayer(assetManager!!, resources!!))
val layerManager = LayerManager(preferences)
layerManager.addLayer(StarsLayer(assetManager, resources))
layerManager.addLayer(MessierLayer(assetManager, resources))
layerManager.addLayer(ConstellationsLayer(assetManager, resources))
layerManager.addLayer(SolarSystemLayer(model!!, resources, preferences))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.android.stardroid.util.MiscUtil;
import com.google.android.stardroid.util.Toaster;

import javax.annotation.Nullable;
import javax.inject.Inject;

public class CompassCalibrationActivity extends InjectableActivity implements SensorEventListener {
Expand All @@ -27,7 +28,7 @@ public class CompassCalibrationActivity extends InjectableActivity implements Se
private Sensor magneticSensor;
private CheckBox checkBoxView;

@Inject SensorManager sensorManager;
@Inject @Nullable SensorManager sensorManager;
@Inject SensorAccuracyDecoder accuracyDecoder;
@Inject SharedPreferences sharedPreferences;
@Inject Analytics analytics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.Set;
import java.util.TimeZone;

import javax.annotation.Nullable;
import javax.inject.Inject;

public class DiagnosticActivity extends InjectableActivity implements SensorEventListener {
Expand All @@ -42,9 +43,9 @@ public class DiagnosticActivity extends InjectableActivity implements SensorEven

@Inject Analytics analytics;
@Inject StardroidApplication app;
@Inject SensorManager sensorManager;
@Inject ConnectivityManager connectivityManager;
@Inject LocationManager locationManager;
@Inject @Nullable SensorManager sensorManager;
@Inject @Nullable ConnectivityManager connectivityManager;
@Inject @Nullable LocationManager locationManager;
@Inject LocationController locationController;
@Inject AstronomerModel model;
@Inject Handler handler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nullable;
import javax.inject.Inject;

/**
Expand All @@ -65,7 +66,7 @@ public class LocationController extends AbstractController implements LocationLi
private LocationManager locationManager;

@Inject
public LocationController(Context context, LocationManager locationManager) {
public LocationController(Context context, @Nullable LocationManager locationManager) {
this.context = context;
if (locationManager != null) {
Log.d(TAG, "Got location Manager");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.android.stardroid.util.smoothers.ExponentiallyWeightedSmoother;
import com.google.android.stardroid.util.smoothers.PlainSmootherModelAdaptor;

import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Provider;

Expand Down Expand Up @@ -75,7 +76,8 @@ public SensorDampingSettings(float damping, int exponent) {

@Inject
SensorOrientationController(Provider<PlainSmootherModelAdaptor> modelAdaptorProvider,
SensorManager manager, SharedPreferences sharedPreferences) {
@Nullable SensorManager manager,
SharedPreferences sharedPreferences) {
this.manager = manager;
this.modelAdaptorProvider = modelAdaptorProvider;
this.rotationSensor = manager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@
package com.google.android.stardroid.layers

import android.content.res.Resources
import com.google.android.stardroid.renderables.*
import com.google.android.stardroid.renderer.RendererController
import com.google.android.stardroid.renderer.RendererController.AtomicSection
import com.google.android.stardroid.renderer.RendererControllerBase
import com.google.android.stardroid.renderer.RendererControllerBase.RenderManager
import com.google.android.stardroid.renderer.RendererObjectManager.UpdateType
import com.google.android.stardroid.search.SearchResult
import com.google.android.stardroid.renderables.ImagePrimitive
import com.google.android.stardroid.renderables.LinePrimitive
import com.google.android.stardroid.renderables.PointPrimitive
import com.google.android.stardroid.renderables.TextPrimitive
import com.google.android.stardroid.util.MiscUtil
import java.util.*
import java.util.concurrent.locks.ReentrantLock
Expand Down Expand Up @@ -98,31 +95,30 @@ abstract class AbstractLayer(protected val resources: Resources) : Layer {
* Sets the objects on the [RenderManager] to the given values,
* creating (or disabling) the [RenderManager] if necessary.
*/
private fun <E> setSources(
private inline fun <reified E : AbstractPrimitive> setSources(
sources: List<E>, updateType: EnumSet<UpdateType>,
clazz: Class<E>, atomic: AtomicSection
) {
@Suppress("UNCHECKED_CAST")
var manager = renderMap[clazz] as RenderManager<E>?
if (manager == null) {
manager = createRenderManager(clazz, atomic)
manager = createRenderManager(atomic)
renderMap[clazz] = manager
}
manager.queueObjects(sources, updateType, atomic)
}

// TODO(jontayler): see if we can simplify this with a reworking of the renderer code.
// The use of generics here is marginal - it reduces lines of code a little vs having
// primitive-specific versions os setSources but is less readable.
private fun <E> createRenderManager(
clazz: Class<E>,
private inline fun <reified E : AbstractPrimitive> createRenderManager(
controller: RendererControllerBase
) = when (clazz) {
ImagePrimitive::class.java -> controller.createImageManager(layerDepthOrder) as RenderManager<E>
TextPrimitive::class.java -> controller.createLabelManager(layerDepthOrder) as RenderManager<E>
LinePrimitive::class.java -> controller.createLineManager(layerDepthOrder) as RenderManager<E>
PointPrimitive::class.java -> controller.createPointManager(layerDepthOrder) as RenderManager<E>
else -> throw IllegalStateException("Unknown source type: $clazz")
}
) : RenderManager<E> =
@Suppress("UNCHECKED_CAST")
when (E::class) {
ImagePrimitive::class -> controller.createImageManager(layerDepthOrder) as RenderManager<E>
TextPrimitive::class -> controller.createLabelManager(layerDepthOrder) as RenderManager<E>
LinePrimitive::class -> controller.createLineManager(layerDepthOrder) as RenderManager<E>
PointPrimitive::class -> controller.createPointManager(layerDepthOrder) as RenderManager<E>
else -> throw IllegalStateException("Unknown source type: $(E::class)")
}

override fun searchByObjectName(name: String): List<SearchResult> {
// By default, layers will return no search results.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.google.android.stardroid.activities.CompassCalibrationActivity;
import com.google.android.stardroid.base.TimeConstants;

import javax.annotation.Nullable;
import javax.inject.Inject;

/**
Expand All @@ -30,7 +31,8 @@ public class SensorAccuracyMonitor implements SensorEventListener {

@Inject
SensorAccuracyMonitor(
SensorManager sensorManager, Context context, SharedPreferences sharedPreferences,
@Nullable SensorManager sensorManager, Context context,
SharedPreferences sharedPreferences,
Toaster toaster) {
Log.d(TAG, "Creating new accuracy monitor");
this.sensorManager = sensorManager;
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ buildscript {
allprojects {
repositories {
google()
mavenCentral()
}
}

Expand Down

0 comments on commit 045232a

Please sign in to comment.