Skip to content

Commit

Permalink
sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmateos committed Feb 14, 2024
1 parent bb9f009 commit d1189c6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 140 deletions.
113 changes: 0 additions & 113 deletions app/src/main/java/org/dhis2/bindings/Bindings.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,119 +204,6 @@ public static void setEventIcon(ImageView view, Event event, Enrollment enrollme
}
}

@BindingAdapter(value = {"eventColor", "eventProgramStage", "eventProgram"})
public static void setEventColor(View view, Event event, ProgramStage programStage, Program program) {
if (event != null) {
int bgColor;
if (DateUtils.getInstance().isEventExpired(null, event.completedDate(), program.completeEventsExpiryDays())) {
bgColor = R.drawable.item_event_dark_gray_ripple;
} else if (event.status() != null) {
switch (event.status()) {
case ACTIVE:
Date eventDate = event.eventDate();
if (programStage.periodType() != null && programStage.periodType().name().contains(PeriodType.Weekly.name()))
eventDate = DateUtils.getInstance().getNextPeriod(programStage.periodType(), eventDate, 0, true);
if (DateUtils.getInstance().isEventExpired(eventDate, null, event.status(), program.completeEventsExpiryDays(), programStage.periodType() != null ? programStage.periodType() : program.expiryPeriodType(), program.expiryDays())) {
bgColor = R.drawable.item_event_dark_gray_ripple;
} else
bgColor = R.drawable.item_event_yellow_ripple;
break;
case COMPLETED:
if (DateUtils.getInstance().isEventExpired(null, event.completedDate(), program.completeEventsExpiryDays())) {
bgColor = R.drawable.item_event_dark_gray_ripple;
} else
bgColor = R.drawable.item_event_gray_ripple;
break;
case SCHEDULE:
if (DateUtils.getInstance().isEventExpired(
event.dueDate(),
null,
event.status(),
program.completeEventsExpiryDays(),
programStage.periodType() != null ? programStage.periodType() : program.expiryPeriodType(),
program.expiryDays())) {
bgColor = R.drawable.item_event_dark_gray_ripple;
} else
bgColor = R.drawable.item_event_green_ripple;
break;
case VISITED:
case SKIPPED:
default:
bgColor = R.drawable.item_event_red_ripple;
break;
}
} else {
bgColor = R.drawable.item_event_red_ripple;
}
view.setBackground(AppCompatResources.getDrawable(view.getContext(), bgColor));
}
}


@BindingAdapter("stateText")
public static void setStateText(TextView textView, State state) {
switch (state) {
case TO_POST:
textView.setText(textView.getContext().getString(R.string.state_to_post));
break;
case TO_UPDATE:
textView.setText(textView.getContext().getString(R.string.state_to_update));
break;
case ERROR:
textView.setText(textView.getContext().getString(R.string.state_error));
break;
case SYNCED:
textView.setText(textView.getContext().getString(R.string.state_synced));
break;
default:
break;
}
}

@BindingAdapter("fromResBgColor")
public static void setFromResBgColor(View view, int color) {
String tintedColor;

ArrayList<Double> rgb = new ArrayList<>();
rgb.add(Color.red(color) / 255.0d);
rgb.add(Color.green(color) / 255.0d);
rgb.add(Color.blue(color) / 255.0d);

Double r = null;
Double g = null;
Double b = null;
for (Double c : rgb) {
if (c <= 0.03928d)
c = c / 12.92d;
else
c = Math.pow(((c + 0.055d) / 1.055d), 2.4d);

if (r == null)
r = c;
else if (g == null)
g = c;
else
b = c;
}

double L = 0.2126d * r + 0.7152d * g + 0.0722d * b;


if (L > 0.179d)
tintedColor = "#000000"; // bright colors - black font
else
tintedColor = "#FFFFFF"; // dark colors - white font

if (view instanceof TextView) {
((TextView) view).setTextColor(Color.parseColor(tintedColor));
}
if (view instanceof ImageView) {
Drawable drawable = ((ImageView) view).getDrawable();
if (drawable != null)
drawable.setColorFilter(Color.parseColor(tintedColor), PorterDuff.Mode.SRC_IN);
((ImageView) view).setImageDrawable(drawable);
}
}

@BindingAdapter("imageBackground")
public static void setImageBackground(ImageView imageView, Drawable drawable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class EventCaptureActivity :
themeManager!!.setProgramTheme(intent.getStringExtra(Constants.PROGRAM_UID)!!)
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_event_capture)
binding?.presenter = presenter
binding.presenter = presenter
val navigationInitialPage =
if (intent.getBooleanExtra(EXTRA_DETAILS_AS_FIRST_PAGE, false)) {
0
Expand All @@ -110,15 +110,15 @@ class EventCaptureActivity :
showProgress()
presenter!!.initNoteCounter()
presenter!!.init()
binding?.syncButton?.setOnClickListener { showSyncDialog() }
binding.syncButton.setOnClickListener { showSyncDialog() }

if (intent.shouldLaunchSyncDialog()) {
showSyncDialog()
}
}

private fun setUpViewPagerAdapter(initialPage: Int) {
binding!!.eventViewPager.isUserInputEnabled = false
binding.eventViewPager.isUserInputEnabled = false
adapter = EventCapturePagerAdapter(
this,
intent.getStringExtra(Constants.PROGRAM_UID),
Expand All @@ -128,15 +128,15 @@ class EventCaptureActivity :
pageConfigurator!!.displayRelationships(),
intent.getBooleanExtra(OPEN_ERROR_LOCATION, false),
)
binding!!.eventViewPager.adapter = adapter
binding!!.eventViewPager.setCurrentItem(initialPage, false)
binding!!.eventViewPager.registerOnPageChangeCallback(object : OnPageChangeCallback() {
binding.eventViewPager.adapter = adapter
binding.eventViewPager.setCurrentItem(initialPage, false)
binding.eventViewPager.registerOnPageChangeCallback(object : OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
super.onPageSelected(position)
if (position == 0 && eventMode !== EventMode.NEW) {
binding!!.syncButton.visibility = View.VISIBLE
binding.syncButton.visibility = View.VISIBLE
} else {
binding!!.syncButton.visibility = View.GONE
binding.syncButton.visibility = View.GONE
}
if (position != 1) {
hideProgress()
Expand All @@ -146,16 +146,16 @@ class EventCaptureActivity :
}

private fun setUpNavigationBar(initialPage: Int) {
binding!!.navigationBar.setInitialPage(initialPage)
binding!!.navigationBar.pageConfiguration(pageConfigurator!!)
binding!!.navigationBar.setOnNavigationItemSelectedListener { item: MenuItem ->
binding!!.eventViewPager.currentItem = adapter!!.getDynamicTabIndex(item.itemId)
binding.navigationBar.setInitialPage(initialPage)
binding.navigationBar.pageConfiguration(pageConfigurator!!)
binding.navigationBar.setOnNavigationItemSelectedListener { item: MenuItem ->
binding.eventViewPager.currentItem = adapter!!.getDynamicTabIndex(item.itemId)
true
}
}

fun openDetails() {
binding?.navigationBar?.selectItemAt(0)
binding.navigationBar.selectItemAt(0)
}

fun openForm() {
Expand All @@ -164,7 +164,7 @@ class EventCaptureActivity :
it.dismiss()
}
}
binding?.navigationBar?.selectItemAt(1)
binding.navigationBar.selectItemAt(1)
}

override fun onResume() {
Expand All @@ -190,7 +190,7 @@ class EventCaptureActivity :
}

private fun finishEditMode() {
if (binding!!.navigationBar.isHidden()) {
if (binding.navigationBar.isHidden()) {
showNavigationBar()
} else {
attemptFinish()
Expand Down Expand Up @@ -222,13 +222,13 @@ class EventCaptureActivity :
}

private fun isFormScreen(): Boolean {
return adapter?.isFormScreenShown(binding?.eventViewPager?.currentItem) == true
return adapter?.isFormScreenShown(binding.eventViewPager.currentItem) == true
}

override fun updatePercentage(primaryValue: Float) {
binding!!.completion.setCompletionPercentage(primaryValue)
binding.completion.setCompletionPercentage(primaryValue)
if (!presenter!!.completionPercentageVisibility) {
binding!!.completion.visibility = View.GONE
binding.completion.visibility = View.GONE
}
}

Expand All @@ -237,7 +237,7 @@ class EventCaptureActivity :
emptyMandatoryFields: Map<String, String>,
eventCompletionDialog: EventCompletionDialog,
) {
if (binding!!.navigationBar.selectedItemId == R.id.navigation_data_entry) {
if (binding.navigationBar.selectedItemId == R.id.navigation_data_entry) {
val dialog = BottomSheetDialog(
bottomSheetDialogUiModel = eventCompletionDialog.bottomSheetDialogUiModel,
onMainButtonClicked = {
Expand Down Expand Up @@ -340,12 +340,12 @@ class EventCaptureActivity :
orgUnit: String,
catOption: String,
) {
binding!!.programStageName.text = stageName
binding.programStageName.text = stageName
val eventDataString = StringBuilder(String.format("%s | %s", eventDate, orgUnit))
if (catOption != null && !catOption.isEmpty()) {
eventDataString.append(String.format(" | %s", catOption))
}
binding!!.eventSecundaryInfo.text = eventDataString
binding.eventSecundaryInfo.text = eventDataString
}

override fun getPresenter(): EventCaptureContract.Presenter {
Expand Down Expand Up @@ -420,33 +420,33 @@ class EventCaptureActivity :
)
.setPositiveButton(
R.string.change_event_date,
) { _, _ -> binding!!.navigationBar.selectItemAt(0) }
) { _, _ -> binding.navigationBar.selectItemAt(0) }
.setNegativeButton(R.string.go_back) { _, _ -> back() }
.setCancelable(false)
.show()
}

override fun updateNoteBadge(numberOfNotes: Int) {
binding!!.navigationBar.updateBadge(R.id.navigation_notes, numberOfNotes)
binding.navigationBar.updateBadge(R.id.navigation_notes, numberOfNotes)
}

override fun showProgress() {
runOnUiThread { binding!!.toolbarProgress.show() }
runOnUiThread { binding.toolbarProgress.show() }
}

override fun hideProgress() {
Handler(Looper.getMainLooper()).postDelayed(
{ runOnUiThread { binding!!.toolbarProgress.hide() } },
{ runOnUiThread { binding.toolbarProgress.hide() } },
1000,
)
}

override fun showNavigationBar() {
binding!!.navigationBar.show()
binding.navigationBar.show()
}

override fun hideNavigationBar() {
binding!!.navigationBar.hide()
binding.navigationBar.hide()
}

override fun relationshipMap(): LiveData<Boolean> {
Expand Down

0 comments on commit d1189c6

Please sign in to comment.