Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CCCT-567 || Home Screen UI Fixes #2917

Merged
merged 6 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion app/src/org/commcare/activities/HomeButtons.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,4 @@ void update(HomeCardDisplayData cardDisplayData,
Context context,
String notificationText);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
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.util.Log;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.cardview.widget.CardView;
Expand Down Expand Up @@ -35,7 +37,6 @@
import java.util.Date;
import java.util.Hashtable;
import java.util.List;
import java.util.Locale;
import java.util.Vector;

/**
Expand Down Expand Up @@ -78,8 +79,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);
Expand All @@ -98,7 +98,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);
}

Expand All @@ -111,7 +111,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);
Expand Down Expand Up @@ -147,14 +147,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);
}
Expand All @@ -169,7 +169,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);
}
Expand All @@ -195,11 +195,15 @@ public void updateConnectProgress() {
RecyclerView recyclerView = viewJobCard.findViewById(R.id.rdDeliveryTypeList);
ConnectJobRecord job = ConnectManager.getActiveJob();

if (job == null || 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)
Expand Down Expand Up @@ -234,7 +238,7 @@ private static Vector<String> getHiddenButtons(Context context) {
if (!CommCareApplication.instance().getCurrentApp().hasVisibleTrainingContent()) {
hiddenButtons.add("training");
}
if (ConnectManager.getAppRecord(context, ccApp.getUniqueId()) == null) {
if (!ConnectManager.shouldShowJobStatus(context, ccApp.getUniqueId())) {
hiddenButtons.add("connect");
}

Expand Down
69 changes: 41 additions & 28 deletions app/src/org/commcare/connect/ConnectManager.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
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.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;
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;
Expand Down Expand Up @@ -60,21 +78,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
*
Expand All @@ -94,7 +97,6 @@ public class ConnectManager {
private BiometricManager biometricManager;



public static int getFailureAttempt() {
return getInstance().failedPinAttempts;
}
Expand Down Expand Up @@ -166,7 +168,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);
Expand Down Expand Up @@ -266,7 +268,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();
}
Comment on lines +271 to 274
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add Null Check for 'user' to Prevent NullPointerException

The method getUser(context) may return null, which would cause a NullPointerException when calling user.getSecondaryPhoneVerified(). Ensure that user is not null before accessing its methods.

Apply this diff to add a null check:

 if (isConnectIdConfigured()) {
     ConnectUserRecord user = getUser(context);
+    if (user != null) {
         show = !user.getSecondaryPhoneVerified();
+    } else {
+        show = false; // Handle null user appropriately
+    }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (isConnectIdConfigured()) {
ConnectUserRecord user = getUser(context);
show = !user.getSecondaryPhoneVerified();
}
if (isConnectIdConfigured()) {
ConnectUserRecord user = getUser(context);
if (user != null) {
show = !user.getSecondaryPhoneVerified();
} else {
show = false; // Handle null user appropriately
}
}

Expand Down Expand Up @@ -413,7 +415,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);
}
Expand Down Expand Up @@ -670,9 +672,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);
Expand All @@ -687,7 +689,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);
}
Expand Down Expand Up @@ -775,7 +777,7 @@ public void processSuccess(int responseCode, InputStream responseData) {
JSONArray modules = json.getJSONArray(key);
List<ConnectJobLearningRecord> 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);
}
Expand All @@ -786,7 +788,7 @@ public void processSuccess(int responseCode, InputStream responseData) {
JSONArray assessments = json.getJSONArray(key);
List<ConnectJobAssessmentRecord> 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);
}
Expand Down Expand Up @@ -875,9 +877,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);
}
Expand All @@ -894,7 +896,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()));
}

Expand Down Expand Up @@ -985,4 +987,15 @@ public static String generatePassword() {

return password.toString();
}

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());
}
}