Skip to content

Commit

Permalink
Merge branch 'master' into rachaprince/fix-loi-customid-consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
gino-m authored Nov 7, 2023
2 parents 9acdaa1 + 172107e commit 5865817
Show file tree
Hide file tree
Showing 147 changed files with 1,255 additions and 1,558 deletions.
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
.*
!.gitignore
!gradle/
**/google_maps_api.xml
**/google-services.json
**/secrets.properties

# Blank config. Needed for Cloud builds.
!ground/google-services.json

# Taken from Android.gitignore https://github.com/github/gitignore/blob/master/Android.gitignore
#
Expand Down
34 changes: 8 additions & 26 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,41 +138,23 @@ either the commit message for your changes or in your pull request.

### Add Google Maps API Key(s)

If you do not have them, generate *release* and *debug* Google Maps API keys by
following the instructions at:

https://developers.google.com/maps/documentation/android-api/signup.

Edit or create `ground/secrets.properties` and set the `GOOGLE_MAPS_API_KEY` property to your API key.
```
GOOGLE_MAPS_API_KEY=AIbzvW8e0ub...
```

Verify the SHA-1 certificate fingerprint described in the API key generation instructions is
registered with package name `com.google.android.ground`. To check, visit

https://console.cloud.google.com/apis/credentials

To view the SHA-1 of the debug key generated by Android Studio run:

```
$ keytool -list -v -keystore "$HOME/.android/debug.keystore" -alias androiddebugkey -storepass android -keypass android
```

### Set up Firebase

1. Create a new Firebase project at:

https://console.firebase.google.com/

2. Save config file for Android app to `ground/src/debug/google-services.json`:
2. Add a new Android app with package name `com.google.android.ground`.

https://support.google.com/firebase/answer/7015592
3. Add the debug SHA-1 of your device.

This includes the API key and URL for your new Firebase project.
To view the SHA-1 of the debug key generated by Android Studio run:

**Note:** Do not overwrite `ground/google-services.json`, this is used with Google Cloud build and should be left as-is.
```
$ keytool -list -v -keystore "$HOME/.android/debug.keystore" -alias androiddebugkey -storepass android -keypass android
```
4. Download the config file for the Android app to `ground/src/debug/google-services.json`
### Set up Google Cloud Build (optional)
Expand Down Expand Up @@ -201,7 +183,7 @@ $ cd cloud-builder
$ gcloud builds submit --config=cloudbuild.yaml --substitutions=_ANDROID_VERSION=30
```
5. Ensure that the docker image is uploaded under "Container Registry" in cloud project
5. Ensure that the Docker image is uploaded under "Container Registry" in cloud project
### Troubleshooting
Expand Down
12 changes: 9 additions & 3 deletions config/detekt/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
<SmellBaseline>
<ManuallySuppressedIssues></ManuallySuppressedIssues>
<CurrentIssues>
<ID>DataClassShouldBeImmutable:TaskButton.kt$TaskButton$private var taskUpdatedCallback: ((button: TaskButton, taskData: TaskData?) -&gt; Unit)? = null</ID>
<ID>LongMethod:SubmissionLocalDataStoreConverterTest.kt$SubmissionLocalDataStoreConverterTest$@Test fun testToSubmission()</ID>
<ID>LoopWithTooManyJumpStatements:DataBindingIdlingResource.kt$DataBindingIdlingResource$for</ID>
<ID>DataClassShouldBeImmutable:TaskButton.kt$TaskButton$private var taskUpdatedCallback:
((button: TaskButton, value: Value?) -&gt; Unit)? = null
</ID>
<ID>
LongMethod:SubmissionLocalDataStoreConverterTest.kt$SubmissionLocalDataStoreConverterTest$@Test
fun testToSubmission()
</ID>
<ID>LoopWithTooManyJumpStatements:DataBindingIdlingResource.kt$DataBindingIdlingResource$for
</ID>
</CurrentIssues>
</SmellBaseline>
2 changes: 1 addition & 1 deletion config/jacoco/jacoco.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ tasks.register('jacocoTestStagingUnitTestReport', JacocoReport) {
html.required = true
}
classDirectories.from = fileTree(
dir: 'build/intermediates/classes/debug/transformDebugClassesWithAsm/dirs/com/google/android/ground',
dir: 'build/intermediates/classes/devDebug/transformDevDebugClassesWithAsm/dirs/com/google/android/ground',
excludes: [
'**/databinding/*',
'**/local/room/dao/*',
Expand Down
6 changes: 4 additions & 2 deletions config/lint/lint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@
<issue id="TypographyQuotes" severity="error" />
<issue id="Typos" severity="error" />
<issue id="Untranslatable" severity="error" />
<issue id="UnusedResources" severity="error" />
<issue id="UnusedResources" severity="error">
<ignore path="res/font/display_700.xml" />
</issue>
<issue id="UselessLeaf" severity="error" />
<issue id="UselessParent" severity="error" />
<issue id="UseCompatLoadingForDrawables" severity="error" />
<issue id="UseCompatTextViewDrawableXml" severity="error" />
<issue id="ValidActionsXml" severity="error" />
<issue id="WrongThreadInterprocedural" severity="error" />
<issue id="usesCleartextTraffic">
<ignore path="AndroidManifest.xml"/>
<ignore path="AndroidManifest.xml" />
</issue>
</lint>
28 changes: 18 additions & 10 deletions ground/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@ project.ext {
coroutinesVersion = "1.6.4"
}

// Load secrets.properties
def secretsFile = file('secrets.properties')
def secrets = new Properties()
if (secretsFile.exists()) {
secrets.load(new FileInputStream(secretsFile))
}
def googleMapsApiKey = secrets.getProperty('GOOGLE_MAPS_API_KEY', '')
// Extract API key from google-services.json for use with Google Maps SDK.
import groovy.json.JsonSlurper
def inputFile = new File("ground/src/debug/google-services.json")
def json = inputFile.exists() ? new JsonSlurper().parseText(inputFile.text) : null
def googleMapsApiKey = json ? json.client[0].api_key[0].current_key : ''

def getCommitSha1 = { ->
def stdout = new ByteArrayOutputStream()
Expand Down Expand Up @@ -74,6 +72,7 @@ android {
buildConfigField "String", "EMULATOR_HOST", "\"10.0.2.2\""
buildConfigField "int", "FIRESTORE_EMULATOR_PORT", "8080"
buildConfigField "int", "AUTH_EMULATOR_PORT", "9099"
manifestPlaceholders.usesCleartextTraffic = true
}

// Use flag -PtestBuildType with desired variant to change default behavior.
Expand Down Expand Up @@ -127,7 +126,16 @@ android {
dimension "backend"
versionNameSuffix "-dev"
buildConfigField "boolean", "USE_EMULATORS", "false"
manifestPlaceholders.usesCleartextTraffic = false
}
sig {
dimension "backend"
versionNameSuffix "-sig"
buildConfigField "boolean", "USE_EMULATORS", "false"
}
ecam {
dimension "backend"
versionNameSuffix "-ecam"
buildConfigField "boolean", "USE_EMULATORS", "false"
}
}

Expand Down Expand Up @@ -193,9 +201,9 @@ dependencies {
testImplementation 'org.json:json:20180813'

// Firebase and related libraries.
implementation platform('com.google.firebase:firebase-bom:32.2.3')
implementation platform('com.google.firebase:firebase-bom:32.4.1')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-firestore-ktx'
implementation 'com.google.firebase:firebase-firestore'
implementation 'com.google.firebase:firebase-functions-ktx'
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.firebase:firebase-perf'
Expand Down
51 changes: 0 additions & 51 deletions ground/google-services.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,7 @@ class DataBindingIdlingResource : IdlingResource {
override fun getName(): String = String.format(Locale.getDefault(), "DataBinding $ID")

override fun isIdleNow(): Boolean {
var idle = false
for (b in bindings()) {
if (b == null) {
continue
}
if (!b.hasPendingBindings()) {
idle = true
break
}
}
val idle = bindings().none { it?.hasPendingBindings() ?: false }
if (idle) {
if (wasNotIdle) {
// Notify observers to avoid Espresso race detector.
Expand Down
33 changes: 0 additions & 33 deletions ground/src/main/java/com/google/android/ground/AbstractActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,15 @@ import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.annotation.DrawableRes
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.google.android.ground.ui.common.TwoLineToolbar
import com.google.android.ground.ui.util.DrawableUtil
import com.google.android.ground.util.Debug
import javax.annotation.OverridingMethodsMustInvokeSuper
import javax.inject.Inject

/** Base activity class containing common helper methods. */
abstract class AbstractActivity : AppCompatActivity() {

@Inject lateinit var drawableUtil: DrawableUtil

override fun onCreate(savedInstanceState: Bundle?) {
Debug.logLifecycleEvent(this)
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -77,31 +71,4 @@ abstract class AbstractActivity : AppCompatActivity() {
Debug.logLifecycleEvent(this)
super.onDestroy()
}

fun setActionBar(toolbar: TwoLineToolbar, @DrawableRes upIconId: Int) {
setActionBar(toolbar, false)
// We override the color here programmatically since calling setHomeAsUpIndicator uses the color
// of the set icon, not the applied theme. This allows us to change the primary color
// programmatically without needing to remember to update the icon.
val icon = drawableUtil.getDrawable(toolbar.rootView, upIconId, R.attr.colorPrimary)
supportActionBar!!.setHomeAsUpIndicator(icon)
}

fun setActionBar(toolbar: TwoLineToolbar, showTitle: Boolean) {
setSupportActionBar(toolbar)

// Workaround to get rid of application title from toolbar. Simply setting "" here or in layout
// XML doesn't work.
supportActionBar!!.setDisplayShowTitleEnabled(showTitle)
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
supportActionBar!!.setDisplayShowHomeEnabled(true)

// TODO: Remove this workaround once setupActionBarWithNavController() works with custom
// Toolbars (https://issuetracker.google.com/issues/109868820).
toolbar.setNavigationOnClickListener { onToolbarUpClicked() }
}

protected open fun onToolbarUpClicked() {
finish()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ class MainActivity : Hilt_MainActivity() {
return navController.navigateUp()
}

override fun onToolbarUpClicked() {
if (!dispatchBackPressed()) navigateUp()
}

@Deprecated("Deprecated in Java")
override fun onBackPressed() {
if (!dispatchBackPressed()) super.onBackPressed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class SettingsActivity : Hilt_SettingsActivity() {
val binding = SettingsActivityBinding.inflate(layoutInflater)
setContentView(binding.root)

setActionBar(binding.settingsToolbar, true)
with(binding.settingsToolbar) {
setSupportActionBar(this)
setNavigationOnClickListener { finish() }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import com.google.android.ground.model.geometry.Geometry
import com.google.android.ground.model.job.Job
import com.google.android.ground.model.locationofinterest.LocationOfInterest
import com.google.android.ground.model.mutation.Mutation
import com.google.android.ground.model.submission.GeometryData
import com.google.android.ground.model.submission.TaskDataDelta
import com.google.android.ground.model.submission.GeometryTaskResponse
import com.google.android.ground.model.submission.ValueDelta
import com.google.android.ground.repository.LocationOfInterestRepository
import com.google.android.ground.repository.SubmissionRepository
import com.google.android.ground.repository.UserRepository
Expand All @@ -37,26 +37,27 @@ constructor(
) {

/**
* Creates a Submission for the given [job] with the user's responses from the [taskDataDeltas].
* If [loiId] is null a new LOI is created based on the first [TaskDataDelta] since the Suggest
* LOI task is the first task in the Data Collection flow when a new LOI is being suggested.
* Creates a Submission for the given [job] with the user's responses from the [ValueDelta]s. If
* [loiId] is null a new LOI is created based on the first [ValueDelta] since the Suggest LOI task
* is the first task in the Data Collection flow when a new LOI is being suggested.
*/
@Transaction
@Suppress("UseIfInsteadOfWhen")
suspend operator fun invoke(
loiId: String?,
job: Job,
surveyId: String,
taskDataDeltas: List<TaskDataDelta>
deltas: List<ValueDelta>
) {
Timber.v("Submitting data for loi: $loiId")
var loiIdToSubmit = loiId
val taskDataDeltasToSubmit = taskDataDeltas.toMutableList()
val deltasToSubmit = deltas.toMutableList()

if (loiId == null) {
// loiIds are null for Suggest LOI data collection flows
when (val suggestLoiTaskData = taskDataDeltasToSubmit.removeAt(0).newTaskData) {
is GeometryData -> loiIdToSubmit = saveLoi(suggestLoiTaskData.geometry, job, surveyId).id
when (val suggestLoiValue = deltasToSubmit.removeAt(0).newValue) {
is GeometryTaskResponse ->
loiIdToSubmit = saveLoi(suggestLoiValue.geometry, job, surveyId).id
else -> error("No suggest LOI Task found when loi ID was null")
}
}
Expand All @@ -65,7 +66,7 @@ constructor(
.saveSubmission(
surveyId,
requireNotNull(loiIdToSubmit) { "No LOI found present for submission" },
taskDataDeltasToSubmit
deltasToSubmit
)
.blockingAwait()
}
Expand Down
Loading

0 comments on commit 5865817

Please sign in to comment.