Skip to content

Commit

Permalink
Fix Form equality for StateFlow
Browse files Browse the repository at this point in the history
  • Loading branch information
seadowg committed Jan 17, 2024
1 parent 781c04c commit c506468
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ open class DatabaseConnection(

val readableDatabase: SQLiteDatabase
get() {
StrictMode.noteSlowCall("Accessing DB")
StrictMode.noteSlowCall(" Accessing DB")
return dbHelper.readableDatabase
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.asLiveData
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update
import org.odk.collect.android.formmanagement.matchexactly.ServerFormsSynchronizer
import org.odk.collect.android.notifications.Notifier
import org.odk.collect.android.projects.ProjectDependencyProvider
Expand Down Expand Up @@ -180,7 +179,7 @@ class FormsDataService(

private fun syncWithDb(projectId: String) {
val projectDependencies = projectDependencyProviderFactory.create(projectId)
getFormsFlow(projectId).update { projectDependencies.formsRepository.all }
getFormsFlow(projectId).value = projectDependencies.formsRepository.all
}

private fun getFormsFlow(projectId: String): MutableStateFlow<List<Form>> {
Expand Down
17 changes: 14 additions & 3 deletions forms/src/main/java/org/odk/collect/forms/Form.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

/**
* A form definition stored on the device.
* <p>
Expand Down Expand Up @@ -281,13 +283,22 @@ public Long getLastDetectedAttachmentsUpdateDate() {
}

@Override
public boolean equals(Object other) {
return other == this || other instanceof Form && this.md5Hash.equals(((Form) other).md5Hash);
public boolean equals(Object o) {
if (this == o) {
return true;
}

if (o == null || getClass() != o.getClass()) {
return false;
}

Form form = (Form) o;
return deleted == form.deleted && Objects.equals(dbId, form.dbId) && Objects.equals(displayName, form.displayName) && Objects.equals(description, form.description) && Objects.equals(formId, form.formId) && Objects.equals(version, form.version) && Objects.equals(formFilePath, form.formFilePath) && Objects.equals(submissionUri, form.submissionUri) && Objects.equals(base64RSAPublicKey, form.base64RSAPublicKey) && Objects.equals(md5Hash, form.md5Hash) && Objects.equals(date, form.date) && Objects.equals(jrCacheFilePath, form.jrCacheFilePath) && Objects.equals(formMediaPath, form.formMediaPath) && Objects.equals(language, form.language) && Objects.equals(autoSend, form.autoSend) && Objects.equals(autoDelete, form.autoDelete) && Objects.equals(geometryXPath, form.geometryXPath) && Objects.equals(lastDetectedAttachmentsUpdateDate, form.lastDetectedAttachmentsUpdateDate);
}

@Override
public int hashCode() {
return md5Hash.hashCode();
return Objects.hash(dbId, displayName, description, formId, version, formFilePath, submissionUri, base64RSAPublicKey, md5Hash, date, jrCacheFilePath, formMediaPath, language, autoSend, autoDelete, geometryXPath, deleted, lastDetectedAttachmentsUpdateDate);
}

@Override
Expand Down

0 comments on commit c506468

Please sign in to comment.