-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
Changes from 3 commits
802b7b0
e2d43ec
af3bc61
5c58adc
132bfb9
49a1a06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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,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; | ||||||
|
||||||
/** | ||||||
|
@@ -27,8 +29,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[]{}; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Refactor button management to improve maintainability The current implementation relies on the order of the Consider using a single data structure, such as a list of custom objects or a map, that encapsulates both the button identifiers and their corresponding Also applies to: 48-50, 52-65 |
||||||
|
||||||
/** | ||||||
* Note: The order in which home cards are returned by this method should be consistent with | ||||||
|
@@ -37,62 +39,45 @@ public class HomeButtons { | |||||
public static HomeCardDisplayData[] buildButtonData(StandardHomeActivity activity, | ||||||
Vector<String> 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); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential logical error in The variable Consider adjusting the assignment to: - boolean hideJobStatus = ConnectManager.shouldShowJobStatus(activity);
+ boolean hideJobStatus = !ConnectManager.shouldShowJobStatus(activity); This ensures that 📝 Committable suggestion
Suggested change
|
||||||
|
||||||
buttonNames = hideJobStatus ? | ||||||
new String[]{"start", "training", "saved", "incomplete", "sync", "report", "logout"} : | ||||||
new String[]{"start", "training", "saved", "incomplete", "connect", "sync", "report", "logout"}; | ||||||
|
||||||
List<HomeCardDisplayData> 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))); | ||||||
} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect logic in condition for adding the "connect" button The condition After correcting the |
||||||
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))); | ||||||
|
||||||
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(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); | ||||||
} | ||||||
|
||||||
return getVisibleButtons(allButtons, buttonsToHide); | ||||||
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<String> buttonsToHide) { | ||||||
int visibleButtonCount = buttonNames.length - buttonsToHide.size(); | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies, I should have provided more guidance here. Hiding the button can be accomplished more easily and without having to make additional modifications to this code. Instead, we just need to enhance StandardHomeActivityUIController.getHiddenButtons so it correctly indicates when to hide the Job Status button. The list of button names returned by that function is passed through to HomeButtons so buttons can be shown or hidden as indicated.