Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 20 additions & 27 deletions app/src/org/commcare/activities/CommCareSetupActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
import org.commcare.CommCareApp;
import org.commcare.CommCareApplication;
import org.commcare.android.database.connect.models.ConnectJobRecord;
import org.commcare.android.database.connect.models.ConnectUserRecord;
import org.commcare.connect.ConnectConstants;
import org.commcare.connect.repository.ConnectRepository;
import org.commcare.connect.ConnectNavHelper;
import org.commcare.connect.PersonalIdManager;
import org.commcare.personalId.UnlockPolicy;
import org.commcare.connect.database.ConnectJobUtils;
import org.commcare.connect.database.ConnectUserDatabaseUtil;
import org.commcare.connect.network.PersonalIdOrConnectApiErrorHandler;
import org.commcare.connect.network.connect.ConnectApiHandler;
import org.commcare.dalvik.BuildConfig;
import org.commcare.dalvik.R;
import org.commcare.engine.resource.AppInstallStatus;
Expand Down Expand Up @@ -999,30 +998,24 @@ public void checkManagedConfiguration() {
}

private void refreshOpportunities() {
CommCareActivity activity = this;
ConnectUserRecord user = ConnectUserDatabaseUtil.getUser(activity);
new ConnectApiHandler<List<ConnectJobRecord>>() {

@Override
public void onFailure(@NonNull PersonalIdOrConnectApiErrorCodes errorCode, @Nullable Throwable t) {
String error = PersonalIdOrConnectApiErrorHandler.handle(activity, errorCode, t);
Toast.makeText(activity, error, Toast.LENGTH_LONG).show();
}

@Override
public void onSuccess(List<ConnectJobRecord> jobs) {
boolean connectAccess = !jobs.isEmpty();
String toastMessage = getString(R.string.setup_refresh_opportunities_no_jobs);
if (connectAccess) {
ConnectUserDatabaseUtil.turnOnConnectAccess(activity);

updateConnectButton();
refreshDrawer();

toastMessage = getString(R.string.setup_refresh_opportunities_with_jobs);
ConnectRepository.getInstance(this).retrieveOpportunitiesForJava(
(success, error) -> {
if (success) {
boolean connectAccess = !ConnectJobUtils.getCompositeJobs(
this, ConnectJobRecord.STATUS_ALL_JOBS, null).isEmpty();
if (connectAccess) {
ConnectUserDatabaseUtil.turnOnConnectAccess(this);
updateConnectButton();
refreshDrawer();
}
String toastMessage = connectAccess
? getString(R.string.setup_refresh_opportunities_with_jobs)
: getString(R.string.setup_refresh_opportunities_no_jobs);
Toast.makeText(this, toastMessage, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, error, Toast.LENGTH_LONG).show();
}
}
Toast.makeText(activity, toastMessage, Toast.LENGTH_LONG).show();
}
}.getConnectOpportunities(activity, user);
);
}
}
3 changes: 2 additions & 1 deletion app/src/org/commcare/activities/StandardHomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.commcare.CommCareNoficationManager;
import org.commcare.connect.ConnectJobHelper;
import org.commcare.android.database.connect.models.ConnectJobRecord;
import org.commcare.connect.repository.ConnectRepository;
import org.commcare.connect.ConnectNavHelper;
import org.commcare.connect.EmailOfferHelper;
import org.commcare.dalvik.R;
Expand Down Expand Up @@ -369,7 +370,7 @@ void refreshCCUpdateOption() {
public void fetchJobProgressOverNetwork() {
ConnectJobRecord job = getActiveJob();
if(job != null && job.getStatus() == ConnectJobRecord.STATUS_DELIVERING) {
ConnectJobHelper.INSTANCE.updateDeliveryProgress(this, job, (success, error) -> {
ConnectRepository.getInstance(this).updateDeliveryProgressForJava(job, (success, error) -> {
if (success) {
uiController.updateConnectJobProgress();
}
Expand Down
80 changes: 0 additions & 80 deletions app/src/org/commcare/connect/ConnectJobClaimController.kt

This file was deleted.

150 changes: 0 additions & 150 deletions app/src/org/commcare/connect/ConnectJobHelper.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
package org.commcare.connect

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To consider: There's almost nothing left in this class and I'm thinking it would make sense for the remaining methods to be merged into ConnectJobUtils. There are a couple static helper methods at the end of that class already, and two of the remaining three methods in this class lean pretty heavily on ConnectJobUtils anyway.

One downside to that though is that Helper is Kotlin and Utils is Java, so maybe better would be to prioritize converting Utils to Kotlin in a separate ticket and then merging the Helper functions over.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call - 95f1bfe


import android.content.Context
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.commcare.CommCareApplication
import org.commcare.android.database.connect.models.ConnectJobRecord
import org.commcare.connect.database.ConnectJobUtils
import org.commcare.connect.database.ConnectUserDatabaseUtil
import org.commcare.connect.network.PersonalIdOrConnectApiErrorHandler
import org.commcare.connect.network.connect.ConnectApiHandler
import org.commcare.connect.network.connect.ConnectNetworkClient
import org.commcare.connect.network.connect.models.ConnectPaymentConfirmationModel
import org.commcare.connect.network.connect.models.applyToJob
import org.commcare.google.services.analytics.AnalyticsParamValue.FINISH_DELIVERY
import org.commcare.google.services.analytics.AnalyticsParamValue.PAID_DELIVERY
import org.commcare.google.services.analytics.AnalyticsParamValue.START_DELIVERY
import org.commcare.google.services.analytics.FirebaseAnalyticsUtil

object ConnectJobHelper {
fun getJobForSeatedApp(context: Context): ConnectJobRecord? {
Expand All @@ -38,142 +24,6 @@ object ConnectJobHelper {
return !record.isLearning || job.status != ConnectJobRecord.STATUS_DELIVERING
}

fun updateJobProgress(
context: Context,
job: ConnectJobRecord,
listener: ConnectActivityCompleteListener,
) {
when (job.status) {
ConnectJobRecord.STATUS_LEARNING -> {
updateLearningProgress(context, job, listener)
}

ConnectJobRecord.STATUS_DELIVERING -> {
updateDeliveryProgress(context, job, listener)
}

else -> {
listener.connectActivityComplete(true)
}
}
}

fun updateLearningProgress(
context: Context,
job: ConnectJobRecord,
listener: ConnectActivityCompleteListener,
) {
val user = ConnectUserDatabaseUtil.getUser(context)!!
CoroutineScope(Dispatchers.IO).launch {
val result = ConnectNetworkClient.getInstance().getLearningProgress(user, job)
result.fold(
onSuccess = { model ->
model.applyToJob(job, context)
if (job.passedAssessment()) {
FirebaseAnalyticsUtil.reportCccApiLearnProgress(true)
}
withContext(Dispatchers.Main) {
listener.connectActivityComplete(true)
}
},
onFailure = {
FirebaseAnalyticsUtil.reportCccApiLearnProgress(false)
withContext(Dispatchers.Main) {
listener.connectActivityComplete(false)
}
},
)
}
}

fun updateDeliveryProgress(
context: Context,
job: ConnectJobRecord,
listener: ConnectActivityCompleteListener,
) {
val user = ConnectUserDatabaseUtil.getUser(context)!!
CoroutineScope(Dispatchers.IO).launch {
val result = ConnectNetworkClient.getInstance().getDeliveryProgress(user, job)
result.fold(
onSuccess = { model ->
val events = mutableSetOf<String?>()
if (model.updatedJob) {
events.add(START_DELIVERY)
}
if (model.hasDeliveries && job.getDeliveryProgressPercentage() == 100) {
events.add(FINISH_DELIVERY)
}
if (model.hasPayment && job.payments.isNotEmpty()) {
events.add(PAID_DELIVERY)
}

model.applyToJob(job, context)

events.forEach { event ->
FirebaseAnalyticsUtil.reportCccApiDeliveryProgress(true, event)
}
withContext(Dispatchers.Main) {
listener.connectActivityComplete(true)
}
},
onFailure = {
FirebaseAnalyticsUtil.reportCccApiDeliveryProgress(false, null)
withContext(Dispatchers.Main) {
listener.connectActivityComplete(false)
}
},
)
}
}

fun updatePaymentsConfirmed(
context: Context,
paymentConfirmations: List<ConnectPaymentConfirmationModel>,
listener: ConnectActivityCompleteListener,
) {
val user = ConnectUserDatabaseUtil.getUser(context)

object : ConnectApiHandler<Boolean>() {
override fun onSuccess(data: Boolean) {
for (paymentConfirmation in paymentConfirmations) {
paymentConfirmation.payment.confirmed = paymentConfirmation.toConfirm
ConnectJobUtils.storePayment(context, paymentConfirmation.payment)
}

FirebaseAnalyticsUtil.reportCccApiPaymentConfirmation(true)
listener.connectActivityComplete(true)
}

override fun onFailure(
errorCode: PersonalIdOrConnectApiErrorCodes,
t: Throwable?,
) {
val error = PersonalIdOrConnectApiErrorHandler.handle(context, errorCode, t)
FirebaseAnalyticsUtil.reportCccApiPaymentConfirmation(false)
listener.connectActivityComplete(false, error)
}
}.setPaymentConfirmations(context, user, paymentConfirmations)
}

fun retrieveOpportunities(
context: Context,
listener: ConnectActivityCompleteListener,
) {
val user = ConnectUserDatabaseUtil.getUser(context)
object : ConnectApiHandler<List<ConnectJobRecord>>() {
override fun onFailure(
errorCode: PersonalIdOrConnectApiErrorCodes,
t: Throwable?,
) {
listener.connectActivityComplete(false)
}

override fun onSuccess(data: List<ConnectJobRecord>) {
listener.connectActivityComplete(true)
}
}.getConnectOpportunities(context, user!!)
}

fun resolveGenericOpportunityDestination(
currentAction: String?,
job: ConnectJobRecord?,
Expand Down
Loading
Loading