Skip to content

Commit

Permalink
Merge pull request #2881 from dimagi/dv/CCCT-498-connect-home
Browse files Browse the repository at this point in the history
Added additional states to items in Connect jobs list.
  • Loading branch information
OrangeAndGreen authored Oct 22, 2024
2 parents 1dddcb3 + ea3e7b8 commit aa656e4
Show file tree
Hide file tree
Showing 22 changed files with 71 additions and 55 deletions.
Binary file added app/res/drawable-hdpi/ic_connect_download_green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/res/drawable-hdpi/ic_connect_expired.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/res/drawable-ldpi/ic_connect_download_green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/res/drawable-ldpi/ic_connect_expired.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/res/drawable-mdpi/ic_connect_download_green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/res/drawable-mdpi/ic_connect_expired.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/res/drawable-xhdpi/ic_connect_download_green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/res/drawable-xhdpi/ic_connect_expired.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/res/drawable-xxhdpi/ic_connect_expired.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/res/drawable-xxxhdpi/ic_connect_expired.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions app/res/drawable/connect_rounded_corner_grey.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/connect_lighter_grey" />
<corners android:radius="16dp" />
</shape>
13 changes: 12 additions & 1 deletion app/res/layout/item_login_connect_home_apps.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:lineSpacingExtra="5dp"
android:minLines="2"
android:minLines="1"
android:text=""
android:textColor="@color/black"
android:textSize="14sp"
Expand Down Expand Up @@ -80,6 +80,17 @@
app:layout_constraintStart_toEndOf="@+id/llOpportunity"
app:layout_constraintTop_toTopOf="@+id/llOpportunity" />

<ImageView
android:id="@+id/imgDownload"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginStart="16dp"
android:contentDescription="@null"
android:src="@drawable/ic_connect_download_green"
app:layout_constraintBottom_toBottomOf="@+id/llOpportunity"
app:layout_constraintStart_toEndOf="@+id/progressBar"
app:layout_constraintTop_toTopOf="@+id/llOpportunity"/>

<org.commcare.views.connect.connecttextview.ConnectRegularTextView
android:id="@+id/tvDate"
android:layout_width="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion app/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ License.
<string name="connect_deactivate_dialog_title">Es-tu sûr?</string>
<string name="connect_deactivate_dialog_description">Vous souhaitez désactiver votre compte définitivement ?</string>

<string name="connect_new_opportunity">New Opportunity</string>
<string name="connect_new_opportunity">Nouvelle opportunité</string>
<string name="connect_learn">Apprendre</string>
<string name="connect_delivery">Livraison</string>
<string name="connect_commcare_app">Application CommCare</string>
Expand Down
3 changes: 3 additions & 0 deletions app/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,14 @@
<color name="connect_dark_blue_color">#3942C7</color>
<color name="connect_darker_blue_color">#353BA8</color>
<color name="connect_blue_color">#3A42C7</color>
<color name="connect_blue_color_50">#803A42C7</color>
<color name="connect_blue_color_10">#1A3A42C7</color>
<color name="connect_blackist_dark_blue_color">#141859</color>
<color name="connect_yellowish_orange_color">#F3B34D</color>
<color name="connect_light_orange_color">#FFDFD5</color>
<color name="connect_light_grey">#E5E7EB</color>
<color name="connect_lighter_grey">#E2E8F0</color>
<color name="connect_middle_grey">#94A3B8</color>
<color name="connect_subtext">#080B3F</color>
<color name="connect_secondary_text">#6B7280</color>
<color name="connect_warning_color">#EA6944</color>
Expand Down
3 changes: 2 additions & 1 deletion app/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -859,8 +859,9 @@
<string name="connect_deactivate_dialog_title">Are you sure?</string>
<string name="connect_deactivate_dialog_description">You want to deactivate you account permanently?</string>

<string name="connect_new_opportunity">Nouvelle opportunité</string>
<string name="connect_new_opportunity">New Opportunity</string>
<string name="connect_learn">Learn</string>
<string name="connect_delivery">Delivery</string>
<string name="connect_expired">Expired</string>
<string name="connect_commcare_app">CommCare App</string>
</resources>
6 changes: 6 additions & 0 deletions app/src/org/commcare/activities/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.content.RestrictionsManager;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
Expand Down Expand Up @@ -128,6 +129,11 @@ protected void onCreate(Bundle savedInstanceState) {
}

uiController.setupUI();

ColorDrawable colorDrawable
= new ColorDrawable(getResources().getColor(R.color.connect_blue_color));
getSupportActionBar().setBackgroundDrawable(colorDrawable);

formAndDataSyncer = new FormAndDataSyncer();

ConnectManager.init(this);
Expand Down
6 changes: 6 additions & 0 deletions app/src/org/commcare/activities/StandardHomeActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.commcare.activities;

import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
Expand All @@ -10,6 +11,7 @@
import org.commcare.CommCareNoficationManager;
import org.commcare.connect.ConnectManager;
import org.commcare.android.database.connect.models.ConnectJobRecord;
import org.commcare.dalvik.R;
import org.commcare.google.services.analytics.AnalyticsParamValue;
import org.commcare.google.services.analytics.FirebaseAnalyticsUtil;
import org.commcare.interfaces.CommCareActivityUIController;
Expand Down Expand Up @@ -54,6 +56,10 @@ public void onCreateSessionSafe(Bundle savedInstanceState) {
super.onCreateSessionSafe(savedInstanceState);
uiController.setupUI();

ColorDrawable colorDrawable
= new ColorDrawable(getResources().getColor(R.color.connect_blue_color));
getSupportActionBar().setBackgroundDrawable(colorDrawable);

updateSecondaryPhoneConfirmationTile();
}

Expand Down
32 changes: 22 additions & 10 deletions app/src/org/commcare/adapters/JobListConnectHomeAppsAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ private static String formatDate(String dateStr) {

public void bind(Context mContext, ItemLoginConnectHomeAppsBinding binding, ConnectLoginJobListModel connectLoginJobListModel, OnJobSelectionClick launcher) {
binding.tvTitle.setText(connectLoginJobListModel.getName());
binding.tvDate.setText(formatDate(connectLoginJobListModel.getLastAccessed().toString()));
binding.tvDate.setText(formatDate(connectLoginJobListModel.getDate().toString()));
binding.imgDownload.setVisibility(connectLoginJobListModel.isAppInstalled() ? View.GONE : View.VISIBLE);
handleProgressBarUI(mContext, connectLoginJobListModel, binding);
configureJobType(mContext, connectLoginJobListModel, binding);

Expand All @@ -98,10 +99,10 @@ public void handleProgressBarUI(Context context, ConnectLoginJobListModel item,
int progressColor = 0;
String jobType = item.getJobType();

if (jobType.equals(JOB_LEARNING)) {
if (jobType.equals(JOB_LEARNING) && !item.getJob().passedAssessment()) {
progress = item.getLearningProgress();
progressColor = context.getResources().getColor(R.color.connect_blue_color);
} else if (jobType.equals(JOB_DELIVERY)) {
} else if (jobType.equals(JOB_DELIVERY) && !item.getJob().isFinished()) {
progress = item.getDeliveryProgress();
progressColor = context.getResources().getColor(R.color.connect_green);
}
Expand All @@ -119,23 +120,34 @@ private void configureJobType(Context context, ConnectLoginJobListModel item, It
if (item.isNew()) {
setJobType(context, R.drawable.connect_rounded_corner_orange_yellow,
context.getResources().getString(R.string.connect_new_opportunity), R.drawable.ic_connect_new_opportunity,
R.color.connect_yellowish_orange_color, binding);
255, R.color.connect_yellowish_orange_color, binding);
} else if (item.isLearningApp()) {
boolean passedAssessment = item.getJob().passedAssessment();
int textId = passedAssessment ? R.string.connect_learn_review : R.string.connect_learn;
int textColorId = passedAssessment ? R.color.connect_blue_color_50 : R.color.connect_blue_color;
int iconAlpha = passedAssessment ? 128 : 255;
setJobType(context, R.drawable.connect_rounded_corner_teslish_blue,
context.getResources().getString(R.string.connect_learn), R.drawable.ic_connect_learning,
R.color.connect_blue_color, binding);
context.getResources().getString(textId), R.drawable.ic_connect_learning, iconAlpha,
textColorId, binding);
} else if (item.isDeliveryApp()) {
setJobType(context, R.drawable.connect_rounded_corner_light_green,
context.getResources().getString(R.string.connect_delivery), R.drawable.ic_connect_delivery,
R.color.connect_green, binding);
boolean finished = item.getJob().isFinished();
int textId = finished ? R.string.connect_expired : R.string.connect_delivery;
int textColorId = finished ? R.color.connect_middle_grey : R.color.connect_green;
int drawableId = finished ? R.drawable.connect_rounded_corner_grey : R.drawable.connect_rounded_corner_light_green;
int iconId = finished ? R.drawable.ic_connect_expired : R.drawable.ic_connect_delivery;

setJobType(context, drawableId,
context.getResources().getString(textId), iconId, 255,
textColorId, binding);
}
}

private void setJobType(Context context, int backgroundResId, String jobTypeText,
int iconResId, int textColorResId, ItemLoginConnectHomeAppsBinding binding) {
int iconResId, int iconAlpha, int textColorResId, ItemLoginConnectHomeAppsBinding binding) {
binding.llOpportunity.setBackground(ContextCompat.getDrawable(context, backgroundResId));
binding.tvJobType.setText(jobTypeText);
binding.imgJobType.setImageDrawable(ContextCompat.getDrawable(context, iconResId));
binding.imgJobType.setImageAlpha(iconAlpha);
binding.tvJobType.setTextColor(ContextCompat.getColor(context, textColorResId));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,15 @@ public int getMaxPossibleVisits() {

public int getLearningCompletePercentage() {
int numLearning = getNumLearningModules();
return numLearning > 0 ? (100 * getCompletedLearningModules() / getNumLearningModules()) : 100;
return numLearning > 0 ? (100 * getCompletedLearningModules() / numLearning) : 100;
}

public boolean attemptedAssessment() {
return getLearningCompletePercentage() >= 100 && assessments != null && assessments.size() > 0;
}

public boolean passedAssessment() {
return getLearningCompletePercentage() >= 100 && getAssessmentScore() >= getLearnAppInfo().getPassingScore();
return status == STATUS_DELIVERING || (getLearningCompletePercentage() >= 100 && getAssessmentScore() >= getLearnAppInfo().getPassingScore());
}

public int getAssessmentScore() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ public ConnectJobsListsFragment() {
// Required empty public constructor
}

public static ConnectJobsListsFragment newInstance(IConnectAppLauncher appLauncher) {
ConnectJobsListsFragment fragment = new ConnectJobsListsFragment();
fragment.launcher = appLauncher;
return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -194,23 +188,22 @@ private void initRecyclerView() {
RecyclerView rvJobList = view.findViewById(R.id.rvJobList);
JobListConnectHomeAppsAdapter adapter = new JobListConnectHomeAppsAdapter(getContext(), jobList, (job, isLearning, appId, jobType) -> {
if (jobType.equals(JOB_NEW_OPPORTUNITY)) {
launchJobInfo(job, jobType, rvJobList, isAppInstalled(appId));
launchJobInfo(job);
} else {
launchAppForJob(job, isLearning, rvJobList);
launchAppForJob(job, isLearning);
}
});
rvJobList.setLayoutManager(new LinearLayoutManager(getContext()));
rvJobList.setNestedScrollingEnabled(true);
rvJobList.setAdapter(adapter);
}

private void launchJobInfo(ConnectJobRecord job, String jobType, View view, boolean appInstalled) {
private void launchJobInfo(ConnectJobRecord job) {
ConnectManager.setActiveJob(job);
NavDirections directions = getNavigationDirections(jobType, appInstalled);
Navigation.findNavController(view).navigate(directions);
Navigation.findNavController(view).navigate(ConnectJobsListsFragmentDirections.actionConnectJobsListFragmentToConnectJobIntroFragment(true));
}

private void launchAppForJob(ConnectJobRecord job, boolean isLearning, View view) {
private void launchAppForJob(ConnectJobRecord job, boolean isLearning) {
ConnectManager.setActiveJob(job);

String appId = isLearning ? job.getLearnAppInfo().getAppId() : job.getDeliveryAppInfo().getAppId();
Expand All @@ -224,29 +217,6 @@ private void launchAppForJob(ConnectJobRecord job, boolean isLearning, View view
}
}

private NavDirections getNavigationDirections(String jobType, boolean appInstalled) {
if (appInstalled) {
return switch (jobType) {
case JOB_NEW_OPPORTUNITY ->
ConnectJobsListsFragmentDirections.actionConnectJobsListFragmentToConnectJobIntroFragment(true);
case JOB_LEARNING ->
ConnectJobsListsFragmentDirections.actionConnectJobsListFragmentToConnectJobLearningProgressFragment();
case JOB_DELIVERY ->
ConnectJobsListsFragmentDirections.actionConnectJobsListFragmentToConnectJobDeliveryProgressFragment();
default ->
throw new RuntimeException(String.format("Unexpected job status: %s", jobType));
};
} else {
String title = getDownloadTitle(jobType);
boolean isLearning = jobType.equals(JOB_LEARNING) || jobType.equals(JOB_NEW_OPPORTUNITY);
return ConnectJobsListsFragmentDirections.actionConnectJobsListFragmentToConnectDownloadingFragment(title, isLearning);
}
}

private String getDownloadTitle(String jobType) {
return jobType.equals(JOB_DELIVERY) ? getString(R.string.connect_downloading_delivery) : getString(R.string.connect_downloading_learn);
}

private void setJobListData(List<ConnectJobRecord> jobs) {
jobList = new ArrayList<>();
ArrayList<ConnectLoginJobListModel> availableNewJobs = new ArrayList<>();
Expand All @@ -259,9 +229,11 @@ private void setJobListData(List<ConnectJobRecord> jobs) {

switch (jobStatus) {
case STATUS_AVAILABLE_NEW, STATUS_AVAILABLE:
availableNewJobs.add(createJobModel(
job, JOB_NEW_OPPORTUNITY, NEW_APP, false, true, false, false
));
if(!job.isFinished()) {
availableNewJobs.add(createJobModel(
job, JOB_NEW_OPPORTUNITY, NEW_APP, true, true, false, false
));
}
break;

case STATUS_LEARNING:
Expand All @@ -285,7 +257,7 @@ private void setJobListData(List<ConnectJobRecord> jobs) {

}

Collections.sort(otherJobs, (job1, job2) -> job2.getLastAccessed().compareTo(job1.getLastAccessed()));
Collections.sort(otherJobs, (job1, job2) -> job1.getLastAccessed().compareTo(job2.getLastAccessed()));
jobList.addAll(availableNewJobs);
jobList.addAll(otherJobs);
initRecyclerView();
Expand All @@ -304,7 +276,7 @@ private ConnectLoginJobListModel createJobModel(
job.getTitle(),
String.valueOf(job.getJobId()),
getAppIdForType(job, jobType),
job.getProjectStartDate(),
job.getProjectEndDate(),
getDescriptionForType(job, jobType),
getOrganizationForType(job, jobType),
isAppInstalled,
Expand Down

0 comments on commit aa656e4

Please sign in to comment.