From 802b7b0245b13af875f8abca57d29a16d2fb6067 Mon Sep 17 00:00:00 2001 From: Jay Panchal Date: Wed, 4 Dec 2024 13:19:06 +0530 Subject: [PATCH 1/4] Hide job status button Hide job status button in home screen while job is in review --- .../org/commcare/activities/HomeButtons.java | 142 ++++++++++++------ .../StandardHomeActivityUIController.java | 25 +-- .../org/commcare/connect/ConnectManager.java | 65 ++++---- 3 files changed, 148 insertions(+), 84 deletions(-) diff --git a/app/src/org/commcare/activities/HomeButtons.java b/app/src/org/commcare/activities/HomeButtons.java index fb59cef594..7b05a19f1f 100644 --- a/app/src/org/commcare/activities/HomeButtons.java +++ b/app/src/org/commcare/activities/HomeButtons.java @@ -3,12 +3,13 @@ import android.content.Context; import android.content.Intent; import android.text.Spannable; +import android.util.Log; import android.view.View; import android.widget.Toast; -import org.commcare.connect.ConnectManager; import org.commcare.adapters.HomeCardDisplayData; import org.commcare.adapters.SquareButtonViewHolder; +import org.commcare.connect.ConnectManager; import org.commcare.dalvik.R; import org.commcare.google.services.analytics.AnalyticsParamValue; import org.commcare.google.services.analytics.FirebaseAnalyticsUtil; @@ -27,8 +28,8 @@ */ public class HomeButtons { - private final static String[] buttonNames = - new String[]{"start", "training", "saved", "incomplete", "connect", "sync", "report", "logout"}; + private static String[] buttonNames = + new String[]{}; /** * Note: The order in which home cards are returned by this method should be consistent with @@ -48,49 +49,100 @@ public static HomeCardDisplayData[] buildButtonData(StandardHomeActivity activit logoutMessageKey = "home.logout.demo"; } - HomeCardDisplayData[] allButtons = new HomeCardDisplayData[]{ - HomeCardDisplayData.homeCardDataWithStaticText(Localization.get(homeMessageKey), - R.color.white, - R.drawable.start, - R.color.cc_attention_positive_color, - getStartButtonListener(activity)), - HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("training.root.title"), R.color.white, - R.drawable.home_training, R.color.cc_dark_cool_accent_color, - getTrainingButtonListener(activity)), - HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("home.forms.saved"), - R.color.white, - R.drawable.home_saved, - R.color.cc_light_cool_accent_color, - getViewOldFormsListener(activity)), - HomeCardDisplayData.homeCardDataWithDynamicText(Localization.get("home.forms.incomplete"), R.color.white, - R.drawable.home_incomplete, - R.color.solid_dark_orange, - getIncompleteButtonListener(activity), - null, - getIncompleteButtonTextSetter(activity)), - HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("home.connect"), R.color.white, - R.drawable.baseline_save_24, R.color.orange_500, - getConnectButtonListener(activity)), - HomeCardDisplayData.homeCardDataWithNotification(Localization.get(syncKey), R.color.white, - R.color.white, - R.drawable.sync, - R.color.cc_brand_color, - R.color.cc_brand_text, - getSyncButtonListener(activity), - getSyncButtonSubTextListener(activity), - getSyncButtonTextSetter(activity)), - HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("home.report"), R.color.white, - R.drawable.home_report, R.color.cc_attention_negative_color, - getReportButtonListener(activity)), - HomeCardDisplayData.homeCardDataWithNotification(Localization.get(logoutMessageKey), R.color.white, - R.color.white, - R.drawable.logout, R.color.cc_neutral_color, R.color.cc_neutral_text, - getLogoutButtonListener(activity), - null, - getLogoutButtonTextSetter(activity)), - }; + Log.e("DEBUG_TESTING", "buildButtonData: "+ ConnectManager.shouldShowJobStatus()); + if (!ConnectManager.shouldShowJobStatus()) { + buttonNames = + new String[]{"start", "training", "saved", "incomplete", "connect", "sync", "report", "logout"}; - return getVisibleButtons(allButtons, buttonsToHide); + HomeCardDisplayData[] allButtons = new HomeCardDisplayData[]{ + HomeCardDisplayData.homeCardDataWithStaticText(Localization.get(homeMessageKey), + R.color.white, + R.drawable.start, + R.color.cc_attention_positive_color, + getStartButtonListener(activity)), + HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("training.root.title"), R.color.white, + R.drawable.home_training, R.color.cc_dark_cool_accent_color, + getTrainingButtonListener(activity)), + HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("home.forms.saved"), + R.color.white, + R.drawable.home_saved, + R.color.cc_light_cool_accent_color, + getViewOldFormsListener(activity)), + HomeCardDisplayData.homeCardDataWithDynamicText(Localization.get("home.forms.incomplete"), R.color.white, + R.drawable.home_incomplete, + R.color.solid_dark_orange, + getIncompleteButtonListener(activity), + null, + getIncompleteButtonTextSetter(activity)), + HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("home.connect"), R.color.white, + R.drawable.baseline_save_24, R.color.orange_500, + getConnectButtonListener(activity)), + HomeCardDisplayData.homeCardDataWithNotification(Localization.get(syncKey), R.color.white, + R.color.white, + R.drawable.sync, + R.color.cc_brand_color, + R.color.cc_brand_text, + getSyncButtonListener(activity), + getSyncButtonSubTextListener(activity), + getSyncButtonTextSetter(activity)), + HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("home.report"), R.color.white, + R.drawable.home_report, R.color.cc_attention_negative_color, + getReportButtonListener(activity)), + HomeCardDisplayData.homeCardDataWithNotification(Localization.get(logoutMessageKey), R.color.white, + R.color.white, + R.drawable.logout, R.color.cc_neutral_color, R.color.cc_neutral_text, + getLogoutButtonListener(activity), + null, + getLogoutButtonTextSetter(activity)), + }; + return getVisibleButtons(allButtons, buttonsToHide); + } else { + buttonNames = + new String[]{"start", "training", "saved", "incomplete", "sync", "report", "logout"}; + + HomeCardDisplayData[] allButtons = new HomeCardDisplayData[]{ + HomeCardDisplayData.homeCardDataWithStaticText(Localization.get(homeMessageKey), + R.color.white, + R.drawable.start, + R.color.cc_attention_positive_color, + getStartButtonListener(activity)), + HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("training.root.title"), R.color.white, + R.drawable.home_training, R.color.cc_dark_cool_accent_color, + getTrainingButtonListener(activity)), + HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("home.forms.saved"), + R.color.white, + R.drawable.home_saved, + R.color.cc_light_cool_accent_color, + getViewOldFormsListener(activity)), + HomeCardDisplayData.homeCardDataWithDynamicText(Localization.get("home.forms.incomplete"), R.color.white, + R.drawable.home_incomplete, + R.color.solid_dark_orange, + getIncompleteButtonListener(activity), + null, + getIncompleteButtonTextSetter(activity)), +// HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("home.connect"), R.color.white, +// R.drawable.baseline_save_24, R.color.orange_500, +// getConnectButtonListener(activity)), + HomeCardDisplayData.homeCardDataWithNotification(Localization.get(syncKey), R.color.white, + R.color.white, + R.drawable.sync, + R.color.cc_brand_color, + R.color.cc_brand_text, + getSyncButtonListener(activity), + getSyncButtonSubTextListener(activity), + getSyncButtonTextSetter(activity)), + HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("home.report"), R.color.white, + R.drawable.home_report, R.color.cc_attention_negative_color, + getReportButtonListener(activity)), + HomeCardDisplayData.homeCardDataWithNotification(Localization.get(logoutMessageKey), R.color.white, + R.color.white, + R.drawable.logout, R.color.cc_neutral_color, R.color.cc_neutral_text, + getLogoutButtonListener(activity), + null, + getLogoutButtonTextSetter(activity)), + }; + return getVisibleButtons(allButtons, buttonsToHide); + } } private static HomeCardDisplayData[] getVisibleButtons(HomeCardDisplayData[] allButtons, diff --git a/app/src/org/commcare/activities/StandardHomeActivityUIController.java b/app/src/org/commcare/activities/StandardHomeActivityUIController.java index 66be918865..c3b781828e 100644 --- a/app/src/org/commcare/activities/StandardHomeActivityUIController.java +++ b/app/src/org/commcare/activities/StandardHomeActivityUIController.java @@ -1,10 +1,11 @@ package org.commcare.activities; +import static org.commcare.android.database.connect.models.ConnectJobRecord.STATUS_DELIVERING; + import android.annotation.SuppressLint; import android.content.Context; import android.view.View; import android.view.ViewTreeObserver; -import android.widget.ProgressBar; import android.widget.TextView; import androidx.cardview.widget.CardView; @@ -35,7 +36,6 @@ import java.util.Date; import java.util.Hashtable; import java.util.List; -import java.util.Locale; import java.util.Vector; /** @@ -77,8 +77,7 @@ private void updateJobTileDetails() { boolean show = record != null && !record.getIsLearning(); viewJobCard.setVisibility(show ? View.VISIBLE : View.GONE); - - if(show) { + if (show) { ConnectBoldTextView tvJobTitle = viewJobCard.findViewById(R.id.tv_job_title); ConnectMediumTextView tvViewMore = viewJobCard.findViewById(R.id.tv_view_more); ConnectMediumTextView tvJobDiscrepation = viewJobCard.findViewById(R.id.tv_job_discrepation); @@ -97,7 +96,7 @@ private void updateJobTileDetails() { boolean showHours = workingHours != null; tv_job_time.setVisibility(showHours ? View.VISIBLE : View.GONE); hoursTitle.setVisibility(showHours ? View.VISIBLE : View.GONE); - if(showHours) { + if (showHours) { tv_job_time.setText(workingHours); } @@ -110,7 +109,7 @@ private void updateOpportunityMessage() { String appId = CommCareApplication.instance().getCurrentApp().getUniqueId(); ConnectAppRecord record = ConnectManager.getAppRecord(activity, appId); boolean show = record != null && !record.getIsLearning(); - if(show) { + if (show) { ConnectJobRecord job = ConnectManager.getActiveJob(); if (job.isFinished()) { warningText = activity.getString(R.string.connect_progress_warning_ended); @@ -146,14 +145,14 @@ private void updateOpportunityMessage() { } } - if(totalMaxes.size() > 0 || dailyMaxes.size() > 0) { + if (totalMaxes.size() > 0 || dailyMaxes.size() > 0) { warningText = ""; - if(totalMaxes.size() > 0) { + if (totalMaxes.size() > 0) { String maxes = String.join(", ", totalMaxes); warningText = activity.getString(R.string.connect_progress_warning_max_reached_multi, maxes); } - if(dailyMaxes.size() > 0) { + if (dailyMaxes.size() > 0) { String maxes = String.join(", ", dailyMaxes); warningText += activity.getString(R.string.connect_progress_warning_daily_max_reached_multi, maxes); } @@ -168,7 +167,7 @@ private void updateOpportunityMessage() { } connectMessageCard.setVisibility(warningText == null ? View.GONE : View.VISIBLE); - if(warningText != null) { + if (warningText != null) { TextView tv = connectMessageCard.findViewById(R.id.tvConnectMessage); tv.setText(warningText); } @@ -194,11 +193,15 @@ public void updateConnectProgress() { RecyclerView recyclerView = viewJobCard.findViewById(R.id.rdDeliveryTypeList); ConnectJobRecord job = ConnectManager.getActiveJob(); + if (job.getStatus() == STATUS_DELIVERING && job.isFinished()) { + recyclerView.setVisibility(View.GONE); + } + updateOpportunityMessage(); deliveryPaymentInfoList.clear(); - if(job != null) { + if (job != null) { //Note: Only showing a single daily progress bar for now //Adding more entries to the list would show multiple progress bars //(i.e. one for each payment type) diff --git a/app/src/org/commcare/connect/ConnectManager.java b/app/src/org/commcare/connect/ConnectManager.java index ffda95d5c1..b6fd1cb8b0 100644 --- a/app/src/org/commcare/connect/ConnectManager.java +++ b/app/src/org/commcare/connect/ConnectManager.java @@ -1,12 +1,29 @@ package org.commcare.connect; +import static org.commcare.android.database.connect.models.ConnectJobRecord.STATUS_DELIVERING; +import static org.commcare.android.database.connect.models.ConnectJobRecord.STATUS_LEARNING; +import static org.commcare.connect.ConnectConstants.CONNECTID_REQUEST_CODE; + import android.app.Activity; import android.content.Context; import android.content.Intent; +import android.util.Log; import android.view.View; -import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.biometric.BiometricManager; +import androidx.biometric.BiometricPrompt; +import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.work.BackoffPolicy; +import androidx.work.Constraints; +import androidx.work.ExistingPeriodicWorkPolicy; +import androidx.work.NetworkType; +import androidx.work.PeriodicWorkRequest; +import androidx.work.WorkManager; + import org.commcare.AppUtils; import org.commcare.CommCareApplication; import org.commcare.activities.CommCareActivity; @@ -59,21 +76,6 @@ import java.util.Random; import java.util.concurrent.TimeUnit; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; -import androidx.biometric.BiometricManager; -import androidx.biometric.BiometricPrompt; -import androidx.constraintlayout.widget.ConstraintLayout; -import androidx.work.BackoffPolicy; -import androidx.work.Constraints; -import androidx.work.ExistingPeriodicWorkPolicy; -import androidx.work.NetworkType; -import androidx.work.PeriodicWorkRequest; -import androidx.work.WorkManager; - -import static org.commcare.connect.ConnectConstants.CONNECTID_REQUEST_CODE; - /** * Manager class for ConnectID, handles workflow navigation and user management * @@ -93,7 +95,6 @@ public class ConnectManager { private BiometricManager biometricManager; - public static int getFailureAttempt() { return getInstance().failedPinAttempts; } @@ -165,7 +166,7 @@ public static void init(Context parent) { } } - public static BiometricManager getBiometricManager(CommCareActivity parent){ + public static BiometricManager getBiometricManager(CommCareActivity parent) { ConnectManager instance = getInstance(); if (instance.biometricManager == null) { instance.biometricManager = BiometricManager.from(parent); @@ -265,7 +266,7 @@ public static String formatDateTime(Date date) { public static boolean shouldShowSecondaryPhoneConfirmationTile(Context context) { boolean show = false; - if(isConnectIdConfigured()) { + if (isConnectIdConfigured()) { ConnectUserRecord user = getUser(context); show = !user.getSecondaryPhoneVerified(); } @@ -412,7 +413,7 @@ public static void forgetAppCredentials(String appId, String userId) { public static void updateAppAccess(CommCareActivity activity, String appId, String username) { ConnectLinkedAppRecord record = ConnectDatabaseHelper.getAppData(activity, appId, username); - if(record != null) { + if (record != null) { record.setLastAccessed(new Date()); ConnectDatabaseHelper.storeApp(activity, record); } @@ -669,9 +670,9 @@ public static boolean wasAppLaunchedFromConnect(String appId) { } public static String checkAutoLoginAndOverridePassword(Context context, String appId, String username, - String passwordOrPin, boolean appLaunchedFromConnect, boolean uiInAutoLogin) { + String passwordOrPin, boolean appLaunchedFromConnect, boolean uiInAutoLogin) { if (isConnectIdConfigured()) { - if(appLaunchedFromConnect) { + if (appLaunchedFromConnect) { //Configure some things if we haven't already ConnectLinkedAppRecord record = ConnectDatabaseHelper.getAppData(context, appId, username); @@ -686,7 +687,7 @@ record = prepareConnectManagedApp(context, appId, username); username); passwordOrPin = record != null ? record.getPassword() : null; - if(record != null && record.isUsingLocalPassphrase()) { + if (record != null && record.isUsingLocalPassphrase()) { //Report to analytics so we know when this stops happening FirebaseAnalyticsUtil.reportCccAppAutoLoginWithLocalPassphrase(seatedAppId); } @@ -774,7 +775,7 @@ public void processSuccess(int responseCode, InputStream responseData) { JSONArray modules = json.getJSONArray(key); List learningRecords = new ArrayList<>(modules.length()); for (int i = 0; i < modules.length(); i++) { - JSONObject obj = (JSONObject)modules.get(i); + JSONObject obj = (JSONObject) modules.get(i); ConnectJobLearningRecord record = ConnectJobLearningRecord.fromJson(obj, job.getJobId()); learningRecords.add(record); } @@ -785,7 +786,7 @@ public void processSuccess(int responseCode, InputStream responseData) { JSONArray assessments = json.getJSONArray(key); List assessmentRecords = new ArrayList<>(assessments.length()); for (int i = 0; i < assessments.length(); i++) { - JSONObject obj = (JSONObject)assessments.get(i); + JSONObject obj = (JSONObject) assessments.get(i); ConnectJobAssessmentRecord record = ConnectJobAssessmentRecord.fromJson(obj, job.getJobId()); assessmentRecords.add(record); } @@ -874,9 +875,9 @@ public void processSuccess(int responseCode, InputStream responseData) { if (json.has(key)) { JSONArray array = json.getJSONArray(key); for (int i = 0; i < array.length(); i++) { - JSONObject obj = (JSONObject)array.get(i); + JSONObject obj = (JSONObject) array.get(i); ConnectJobDeliveryRecord delivery = ConnectJobDeliveryRecord.fromJson(obj, job.getJobId()); - if(delivery != null) { + if (delivery != null) { //Note: Ignoring faulty deliveries (non-fatal exception logged) deliveries.add(delivery); } @@ -893,7 +894,7 @@ public void processSuccess(int responseCode, InputStream responseData) { if (json.has(key)) { JSONArray array = json.getJSONArray(key); for (int i = 0; i < array.length(); i++) { - JSONObject obj = (JSONObject)array.get(i); + JSONObject obj = (JSONObject) array.get(i); payments.add(ConnectJobPaymentRecord.fromJson(obj, job.getJobId())); } @@ -984,4 +985,12 @@ public static String generatePassword() { return password.toString(); } + + public static boolean shouldShowJobStatus() { + ConnectJobRecord job = ConnectManager.getActiveJob(); + int jobStatus = job.getStatus(); + boolean passedAssessment = job.passedAssessment(); + Log.e("DEBUG_TESTING", "passedAssessment: " + passedAssessment + " jobStatus: " + jobStatus); + return jobStatus == STATUS_DELIVERING && passedAssessment; + } } From e2d43ece44d5a81d61b17376d5ccd386cfd4c9ae Mon Sep 17 00:00:00 2001 From: Jay Panchal Date: Wed, 11 Dec 2024 17:14:48 +0530 Subject: [PATCH 2/4] Solved home screen issues Solved home screen issues --- .../org/commcare/activities/HomeButtons.java | 141 +++++------------- .../org/commcare/connect/ConnectManager.java | 13 +- 2 files changed, 43 insertions(+), 111 deletions(-) diff --git a/app/src/org/commcare/activities/HomeButtons.java b/app/src/org/commcare/activities/HomeButtons.java index 7b05a19f1f..c6a8d1b312 100644 --- a/app/src/org/commcare/activities/HomeButtons.java +++ b/app/src/org/commcare/activities/HomeButtons.java @@ -3,7 +3,6 @@ import android.content.Context; import android.content.Intent; import android.text.Spannable; -import android.util.Log; import android.view.View; import android.widget.Toast; @@ -19,6 +18,8 @@ import org.commcare.utils.SyncDetailCalculations; import org.javarosa.core.services.locale.Localization; +import java.util.ArrayList; +import java.util.List; import java.util.Vector; /** @@ -38,113 +39,45 @@ public class HomeButtons { public static HomeCardDisplayData[] buildButtonData(StandardHomeActivity activity, Vector buttonsToHide, boolean isDemoUser) { - String syncKey, homeMessageKey, logoutMessageKey; - if (!isDemoUser) { - homeMessageKey = "home.start"; - syncKey = "home.sync"; - logoutMessageKey = "home.logout"; - } else { - syncKey = "home.sync.demo"; - homeMessageKey = "home.start.demo"; - logoutMessageKey = "home.logout.demo"; - } + String homeMessageKey = isDemoUser ? "home.start.demo" : "home.start"; + String syncKey = isDemoUser ? "home.sync.demo" : "home.sync"; + String logoutMessageKey = isDemoUser ? "home.logout.demo" : "home.logout"; + + boolean hideJobStatus = ConnectManager.shouldShowJobStatus(activity); + + buttonNames = hideJobStatus ? + new String[]{"start", "training", "saved", "incomplete", "sync", "report", "logout"} : + new String[]{"start", "training", "saved", "incomplete", "connect", "sync", "report", "logout"}; - Log.e("DEBUG_TESTING", "buildButtonData: "+ ConnectManager.shouldShowJobStatus()); - if (!ConnectManager.shouldShowJobStatus()) { - buttonNames = - new String[]{"start", "training", "saved", "incomplete", "connect", "sync", "report", "logout"}; - - HomeCardDisplayData[] allButtons = new HomeCardDisplayData[]{ - HomeCardDisplayData.homeCardDataWithStaticText(Localization.get(homeMessageKey), - R.color.white, - R.drawable.start, - R.color.cc_attention_positive_color, - getStartButtonListener(activity)), - HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("training.root.title"), R.color.white, - R.drawable.home_training, R.color.cc_dark_cool_accent_color, - getTrainingButtonListener(activity)), - HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("home.forms.saved"), - R.color.white, - R.drawable.home_saved, - R.color.cc_light_cool_accent_color, - getViewOldFormsListener(activity)), - HomeCardDisplayData.homeCardDataWithDynamicText(Localization.get("home.forms.incomplete"), R.color.white, - R.drawable.home_incomplete, - R.color.solid_dark_orange, - getIncompleteButtonListener(activity), - null, - getIncompleteButtonTextSetter(activity)), - HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("home.connect"), R.color.white, - R.drawable.baseline_save_24, R.color.orange_500, - getConnectButtonListener(activity)), - HomeCardDisplayData.homeCardDataWithNotification(Localization.get(syncKey), R.color.white, - R.color.white, - R.drawable.sync, - R.color.cc_brand_color, - R.color.cc_brand_text, - getSyncButtonListener(activity), - getSyncButtonSubTextListener(activity), - getSyncButtonTextSetter(activity)), - HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("home.report"), R.color.white, - R.drawable.home_report, R.color.cc_attention_negative_color, - getReportButtonListener(activity)), - HomeCardDisplayData.homeCardDataWithNotification(Localization.get(logoutMessageKey), R.color.white, - R.color.white, - R.drawable.logout, R.color.cc_neutral_color, R.color.cc_neutral_text, - getLogoutButtonListener(activity), - null, - getLogoutButtonTextSetter(activity)), - }; - return getVisibleButtons(allButtons, buttonsToHide); - } else { - buttonNames = - new String[]{"start", "training", "saved", "incomplete", "sync", "report", "logout"}; - - HomeCardDisplayData[] allButtons = new HomeCardDisplayData[]{ - HomeCardDisplayData.homeCardDataWithStaticText(Localization.get(homeMessageKey), - R.color.white, - R.drawable.start, - R.color.cc_attention_positive_color, - getStartButtonListener(activity)), - HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("training.root.title"), R.color.white, - R.drawable.home_training, R.color.cc_dark_cool_accent_color, - getTrainingButtonListener(activity)), - HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("home.forms.saved"), - R.color.white, - R.drawable.home_saved, - R.color.cc_light_cool_accent_color, - getViewOldFormsListener(activity)), - HomeCardDisplayData.homeCardDataWithDynamicText(Localization.get("home.forms.incomplete"), R.color.white, - R.drawable.home_incomplete, - R.color.solid_dark_orange, - getIncompleteButtonListener(activity), - null, - getIncompleteButtonTextSetter(activity)), -// HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("home.connect"), R.color.white, -// R.drawable.baseline_save_24, R.color.orange_500, -// getConnectButtonListener(activity)), - HomeCardDisplayData.homeCardDataWithNotification(Localization.get(syncKey), R.color.white, - R.color.white, - R.drawable.sync, - R.color.cc_brand_color, - R.color.cc_brand_text, - getSyncButtonListener(activity), - getSyncButtonSubTextListener(activity), - getSyncButtonTextSetter(activity)), - HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("home.report"), R.color.white, - R.drawable.home_report, R.color.cc_attention_negative_color, - getReportButtonListener(activity)), - HomeCardDisplayData.homeCardDataWithNotification(Localization.get(logoutMessageKey), R.color.white, - R.color.white, - R.drawable.logout, R.color.cc_neutral_color, R.color.cc_neutral_text, - getLogoutButtonListener(activity), - null, - getLogoutButtonTextSetter(activity)), - }; - return getVisibleButtons(allButtons, buttonsToHide); + List buttons = new ArrayList<>(); + + buttons.add(createStaticButton(Localization.get(homeMessageKey), R.color.white, R.drawable.start, R.color.cc_attention_positive_color, getStartButtonListener(activity))); + buttons.add(createStaticButton(Localization.get("training.root.title"), R.color.white, R.drawable.home_training, R.color.cc_dark_cool_accent_color, getTrainingButtonListener(activity))); + buttons.add(createStaticButton(Localization.get("home.forms.saved"), R.color.white, R.drawable.home_saved, R.color.cc_light_cool_accent_color, getViewOldFormsListener(activity))); + buttons.add(createDynamicButton(Localization.get("home.forms.incomplete"), R.color.white, R.drawable.home_incomplete, R.color.solid_dark_orange, getIncompleteButtonListener(activity), null, getIncompleteButtonTextSetter(activity))); + if (!hideJobStatus) { + buttons.add(createStaticButton(Localization.get("home.connect"), R.color.white, R.drawable.baseline_save_24, R.color.orange_500, getConnectButtonListener(activity))); } + buttons.add(createNotificationButton(Localization.get(syncKey), R.color.white, R.color.white, R.drawable.sync, R.color.cc_brand_color, R.color.cc_brand_text, getSyncButtonListener(activity), getSyncButtonSubTextListener(activity), getSyncButtonTextSetter(activity))); + buttons.add(createStaticButton(Localization.get("home.report"), R.color.white, R.drawable.home_report, R.color.cc_attention_negative_color, getReportButtonListener(activity))); + buttons.add(createNotificationButton(Localization.get(logoutMessageKey), R.color.white, R.color.white, R.drawable.logout, R.color.cc_neutral_color, R.color.cc_neutral_text, getLogoutButtonListener(activity), null, getLogoutButtonTextSetter(activity))); + + return getVisibleButtons(buttons.toArray(new HomeCardDisplayData[0]), buttonsToHide); + } + + private static HomeCardDisplayData createStaticButton(String text, int textColor, int imageResource, int bgColor, View.OnClickListener listener) { + return HomeCardDisplayData.homeCardDataWithStaticText(text, textColor, imageResource, bgColor, listener); + } + + private static HomeCardDisplayData createDynamicButton(String text, int textColor, int imageResource, int bgColor, View.OnClickListener listener, View.OnClickListener subTextListener, HomeButtons.TextSetter textSetter) { + return HomeCardDisplayData.homeCardDataWithDynamicText(text, textColor, imageResource, bgColor, listener, subTextListener, textSetter); } + private static HomeCardDisplayData createNotificationButton(String text, int textColor, int subTextColor, int imageResource, int bgColor, int subTextBgColor, View.OnClickListener listener, View.OnClickListener subTextListener, HomeButtons.TextSetter textSetter) { + return HomeCardDisplayData.homeCardDataWithNotification(text, textColor, subTextColor, imageResource, bgColor, subTextBgColor, listener, subTextListener, textSetter); + } + + private static HomeCardDisplayData[] getVisibleButtons(HomeCardDisplayData[] allButtons, Vector buttonsToHide) { int visibleButtonCount = buttonNames.length - buttonsToHide.size(); diff --git a/app/src/org/commcare/connect/ConnectManager.java b/app/src/org/commcare/connect/ConnectManager.java index b6fd1cb8b0..fc74cdd8a1 100644 --- a/app/src/org/commcare/connect/ConnectManager.java +++ b/app/src/org/commcare/connect/ConnectManager.java @@ -1,13 +1,12 @@ package org.commcare.connect; import static org.commcare.android.database.connect.models.ConnectJobRecord.STATUS_DELIVERING; -import static org.commcare.android.database.connect.models.ConnectJobRecord.STATUS_LEARNING; import static org.commcare.connect.ConnectConstants.CONNECTID_REQUEST_CODE; +import static org.commcare.connect.ConnectConstants.DELIVERY_APP; import android.app.Activity; import android.content.Context; import android.content.Intent; -import android.util.Log; import android.view.View; import android.widget.Toast; @@ -27,6 +26,7 @@ import org.commcare.AppUtils; import org.commcare.CommCareApplication; import org.commcare.activities.CommCareActivity; +import org.commcare.activities.StandardHomeActivity; import org.commcare.activities.connect.ConnectActivity; import org.commcare.activities.connect.ConnectIdActivity; import org.commcare.android.database.connect.models.ConnectAppRecord; @@ -986,11 +986,10 @@ public static String generatePassword() { return password.toString(); } - public static boolean shouldShowJobStatus() { + public static boolean shouldShowJobStatus(Activity activity) { + String appId = CommCareApplication.instance().getCurrentApp().getUniqueId(); + ConnectAppRecord record = ConnectManager.getAppRecord(activity, appId); ConnectJobRecord job = ConnectManager.getActiveJob(); - int jobStatus = job.getStatus(); - boolean passedAssessment = job.passedAssessment(); - Log.e("DEBUG_TESTING", "passedAssessment: " + passedAssessment + " jobStatus: " + jobStatus); - return jobStatus == STATUS_DELIVERING && passedAssessment; + return job.getStatus() == STATUS_DELIVERING && record.getIsLearning(); } } From 5c58adcb24eed65b73d8eddee51b7ec2fd638055 Mon Sep 17 00:00:00 2001 From: Jay Panchal Date: Thu, 12 Dec 2024 12:08:51 +0530 Subject: [PATCH 3/4] Change logic for hide job status button Change logic for hide job status button --- .../org/commcare/activities/HomeButtons.java | 95 +++++++++++-------- .../StandardHomeActivityUIController.java | 3 +- .../org/commcare/connect/ConnectManager.java | 7 +- 3 files changed, 61 insertions(+), 44 deletions(-) diff --git a/app/src/org/commcare/activities/HomeButtons.java b/app/src/org/commcare/activities/HomeButtons.java index c6a8d1b312..0608f5fa52 100644 --- a/app/src/org/commcare/activities/HomeButtons.java +++ b/app/src/org/commcare/activities/HomeButtons.java @@ -6,9 +6,9 @@ import android.view.View; import android.widget.Toast; +import org.commcare.connect.ConnectManager; import org.commcare.adapters.HomeCardDisplayData; import org.commcare.adapters.SquareButtonViewHolder; -import org.commcare.connect.ConnectManager; import org.commcare.dalvik.R; import org.commcare.google.services.analytics.AnalyticsParamValue; import org.commcare.google.services.analytics.FirebaseAnalyticsUtil; @@ -18,8 +18,6 @@ import org.commcare.utils.SyncDetailCalculations; import org.javarosa.core.services.locale.Localization; -import java.util.ArrayList; -import java.util.List; import java.util.Vector; /** @@ -29,8 +27,8 @@ */ public class HomeButtons { - private static String[] buttonNames = - new String[]{}; + private final static String[] buttonNames = + new String[]{"start", "training", "saved", "incomplete", "connect", "sync", "report", "logout"}; /** * Note: The order in which home cards are returned by this method should be consistent with @@ -39,45 +37,62 @@ public class HomeButtons { public static HomeCardDisplayData[] buildButtonData(StandardHomeActivity activity, Vector buttonsToHide, boolean isDemoUser) { - String homeMessageKey = isDemoUser ? "home.start.demo" : "home.start"; - String syncKey = isDemoUser ? "home.sync.demo" : "home.sync"; - String logoutMessageKey = isDemoUser ? "home.logout.demo" : "home.logout"; - - boolean hideJobStatus = ConnectManager.shouldShowJobStatus(activity); - - buttonNames = hideJobStatus ? - new String[]{"start", "training", "saved", "incomplete", "sync", "report", "logout"} : - new String[]{"start", "training", "saved", "incomplete", "connect", "sync", "report", "logout"}; - - List buttons = new ArrayList<>(); - - buttons.add(createStaticButton(Localization.get(homeMessageKey), R.color.white, R.drawable.start, R.color.cc_attention_positive_color, getStartButtonListener(activity))); - buttons.add(createStaticButton(Localization.get("training.root.title"), R.color.white, R.drawable.home_training, R.color.cc_dark_cool_accent_color, getTrainingButtonListener(activity))); - buttons.add(createStaticButton(Localization.get("home.forms.saved"), R.color.white, R.drawable.home_saved, R.color.cc_light_cool_accent_color, getViewOldFormsListener(activity))); - buttons.add(createDynamicButton(Localization.get("home.forms.incomplete"), R.color.white, R.drawable.home_incomplete, R.color.solid_dark_orange, getIncompleteButtonListener(activity), null, getIncompleteButtonTextSetter(activity))); - if (!hideJobStatus) { - buttons.add(createStaticButton(Localization.get("home.connect"), R.color.white, R.drawable.baseline_save_24, R.color.orange_500, getConnectButtonListener(activity))); + String syncKey, homeMessageKey, logoutMessageKey; + if (!isDemoUser) { + homeMessageKey = "home.start"; + syncKey = "home.sync"; + logoutMessageKey = "home.logout"; + } else { + syncKey = "home.sync.demo"; + homeMessageKey = "home.start.demo"; + logoutMessageKey = "home.logout.demo"; } - buttons.add(createNotificationButton(Localization.get(syncKey), R.color.white, R.color.white, R.drawable.sync, R.color.cc_brand_color, R.color.cc_brand_text, getSyncButtonListener(activity), getSyncButtonSubTextListener(activity), getSyncButtonTextSetter(activity))); - buttons.add(createStaticButton(Localization.get("home.report"), R.color.white, R.drawable.home_report, R.color.cc_attention_negative_color, getReportButtonListener(activity))); - buttons.add(createNotificationButton(Localization.get(logoutMessageKey), R.color.white, R.color.white, R.drawable.logout, R.color.cc_neutral_color, R.color.cc_neutral_text, getLogoutButtonListener(activity), null, getLogoutButtonTextSetter(activity))); - return getVisibleButtons(buttons.toArray(new HomeCardDisplayData[0]), buttonsToHide); - } - - private static HomeCardDisplayData createStaticButton(String text, int textColor, int imageResource, int bgColor, View.OnClickListener listener) { - return HomeCardDisplayData.homeCardDataWithStaticText(text, textColor, imageResource, bgColor, listener); - } - - private static HomeCardDisplayData createDynamicButton(String text, int textColor, int imageResource, int bgColor, View.OnClickListener listener, View.OnClickListener subTextListener, HomeButtons.TextSetter textSetter) { - return HomeCardDisplayData.homeCardDataWithDynamicText(text, textColor, imageResource, bgColor, listener, subTextListener, textSetter); - } + HomeCardDisplayData[] allButtons = new HomeCardDisplayData[]{ + HomeCardDisplayData.homeCardDataWithStaticText(Localization.get(homeMessageKey), + R.color.white, + R.drawable.start, + R.color.cc_attention_positive_color, + getStartButtonListener(activity)), + HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("training.root.title"), R.color.white, + R.drawable.home_training, R.color.cc_dark_cool_accent_color, + getTrainingButtonListener(activity)), + HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("home.forms.saved"), + R.color.white, + R.drawable.home_saved, + R.color.cc_light_cool_accent_color, + getViewOldFormsListener(activity)), + HomeCardDisplayData.homeCardDataWithDynamicText(Localization.get("home.forms.incomplete"), R.color.white, + R.drawable.home_incomplete, + R.color.solid_dark_orange, + getIncompleteButtonListener(activity), + null, + getIncompleteButtonTextSetter(activity)), + HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("home.connect"), R.color.white, + R.drawable.baseline_save_24, R.color.orange_500, + getConnectButtonListener(activity)), + HomeCardDisplayData.homeCardDataWithNotification(Localization.get(syncKey), R.color.white, + R.color.white, + R.drawable.sync, + R.color.cc_brand_color, + R.color.cc_brand_text, + getSyncButtonListener(activity), + getSyncButtonSubTextListener(activity), + getSyncButtonTextSetter(activity)), + HomeCardDisplayData.homeCardDataWithStaticText(Localization.get("home.report"), R.color.white, + R.drawable.home_report, R.color.cc_attention_negative_color, + getReportButtonListener(activity)), + HomeCardDisplayData.homeCardDataWithNotification(Localization.get(logoutMessageKey), R.color.white, + R.color.white, + R.drawable.logout, R.color.cc_neutral_color, R.color.cc_neutral_text, + getLogoutButtonListener(activity), + null, + getLogoutButtonTextSetter(activity)), + }; - private static HomeCardDisplayData createNotificationButton(String text, int textColor, int subTextColor, int imageResource, int bgColor, int subTextBgColor, View.OnClickListener listener, View.OnClickListener subTextListener, HomeButtons.TextSetter textSetter) { - return HomeCardDisplayData.homeCardDataWithNotification(text, textColor, subTextColor, imageResource, bgColor, subTextBgColor, listener, subTextListener, textSetter); + return getVisibleButtons(allButtons, buttonsToHide); } - private static HomeCardDisplayData[] getVisibleButtons(HomeCardDisplayData[] allButtons, Vector buttonsToHide) { int visibleButtonCount = buttonNames.length - buttonsToHide.size(); @@ -218,4 +233,4 @@ void update(HomeCardDisplayData cardDisplayData, Context context, String notificationText); } -} +} \ No newline at end of file diff --git a/app/src/org/commcare/activities/StandardHomeActivityUIController.java b/app/src/org/commcare/activities/StandardHomeActivityUIController.java index 39273e5c2f..84f800322a 100644 --- a/app/src/org/commcare/activities/StandardHomeActivityUIController.java +++ b/app/src/org/commcare/activities/StandardHomeActivityUIController.java @@ -4,6 +4,7 @@ import android.annotation.SuppressLint; import android.content.Context; +import android.util.Log; import android.view.View; import android.view.ViewTreeObserver; import android.widget.TextView; @@ -237,7 +238,7 @@ private static Vector getHiddenButtons(Context context) { if (!CommCareApplication.instance().getCurrentApp().hasVisibleTrainingContent()) { hiddenButtons.add("training"); } - if (ConnectManager.getAppRecord(context, ccApp.getUniqueId()) == null) { + if (ConnectManager.getAppRecord(context, ccApp.getUniqueId()) == null || !ConnectManager.shouldShowJobStatus(context)) { hiddenButtons.add("connect"); } diff --git a/app/src/org/commcare/connect/ConnectManager.java b/app/src/org/commcare/connect/ConnectManager.java index 725a149ba3..87e61caad2 100644 --- a/app/src/org/commcare/connect/ConnectManager.java +++ b/app/src/org/commcare/connect/ConnectManager.java @@ -1,6 +1,7 @@ package org.commcare.connect; import static org.commcare.android.database.connect.models.ConnectJobRecord.STATUS_DELIVERING; +import static org.commcare.android.database.connect.models.ConnectJobRecord.STATUS_LEARNING; import static org.commcare.connect.ConnectConstants.CONNECTID_REQUEST_CODE; import static org.commcare.connect.ConnectConstants.DELIVERY_APP; @@ -987,10 +988,10 @@ public static String generatePassword() { return password.toString(); } - public static boolean shouldShowJobStatus(Activity activity) { + public static boolean shouldShowJobStatus(Context context) { String appId = CommCareApplication.instance().getCurrentApp().getUniqueId(); - ConnectAppRecord record = ConnectManager.getAppRecord(activity, appId); + ConnectAppRecord record = ConnectManager.getAppRecord(context, appId); ConnectJobRecord job = ConnectManager.getActiveJob(); - return job.getStatus() == STATUS_DELIVERING && record.getIsLearning(); + return (job.getStatus() == STATUS_LEARNING && record.getIsLearning()) || (job.getStatus() == STATUS_DELIVERING && !record.getIsLearning()); } } From 49a1a067fda0f88fee03a89056b322880a0c3322 Mon Sep 17 00:00:00 2001 From: Dave Viggiano Date: Thu, 12 Dec 2024 10:07:58 -0500 Subject: [PATCH 4/4] Small improvement to logic for hiding Job Status button --- .../StandardHomeActivityUIController.java | 4 ++-- app/src/org/commcare/connect/ConnectManager.java | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/src/org/commcare/activities/StandardHomeActivityUIController.java b/app/src/org/commcare/activities/StandardHomeActivityUIController.java index 84f800322a..00c5f2554b 100644 --- a/app/src/org/commcare/activities/StandardHomeActivityUIController.java +++ b/app/src/org/commcare/activities/StandardHomeActivityUIController.java @@ -195,7 +195,7 @@ public void updateConnectProgress() { RecyclerView recyclerView = viewJobCard.findViewById(R.id.rdDeliveryTypeList); ConnectJobRecord job = ConnectManager.getActiveJob(); - if (job.getStatus() == STATUS_DELIVERING && job.isFinished()) { + if (job == null || job.getStatus() == STATUS_DELIVERING && job.isFinished()) { recyclerView.setVisibility(View.GONE); } @@ -238,7 +238,7 @@ private static Vector getHiddenButtons(Context context) { if (!CommCareApplication.instance().getCurrentApp().hasVisibleTrainingContent()) { hiddenButtons.add("training"); } - if (ConnectManager.getAppRecord(context, ccApp.getUniqueId()) == null || !ConnectManager.shouldShowJobStatus(context)) { + if (!ConnectManager.shouldShowJobStatus(context, ccApp.getUniqueId())) { hiddenButtons.add("connect"); } diff --git a/app/src/org/commcare/connect/ConnectManager.java b/app/src/org/commcare/connect/ConnectManager.java index 87e61caad2..32cd502c4d 100644 --- a/app/src/org/commcare/connect/ConnectManager.java +++ b/app/src/org/commcare/connect/ConnectManager.java @@ -988,10 +988,14 @@ public static String generatePassword() { return password.toString(); } - public static boolean shouldShowJobStatus(Context context) { - String appId = CommCareApplication.instance().getCurrentApp().getUniqueId(); - ConnectAppRecord record = ConnectManager.getAppRecord(context, appId); - ConnectJobRecord job = ConnectManager.getActiveJob(); - return (job.getStatus() == STATUS_LEARNING && record.getIsLearning()) || (job.getStatus() == STATUS_DELIVERING && !record.getIsLearning()); + public static boolean shouldShowJobStatus(Context context, String appId) { + ConnectAppRecord record = getAppRecord(context, appId); + ConnectJobRecord job = getActiveJob(); + if(record == null || job == null) { + return false; + } + + return (job.getStatus() == STATUS_LEARNING && record.getIsLearning()) || + (job.getStatus() == STATUS_DELIVERING && !record.getIsLearning()); } }