From d1189c63ce98db23ba99cfa943fc283963b5c618 Mon Sep 17 00:00:00 2001 From: manu Date: Wed, 14 Feb 2024 16:28:44 +0100 Subject: [PATCH] sonar --- .../java/org/dhis2/bindings/Bindings.java | 113 ------------------ .../eventCapture/EventCaptureActivity.kt | 54 ++++----- 2 files changed, 27 insertions(+), 140 deletions(-) diff --git a/app/src/main/java/org/dhis2/bindings/Bindings.java b/app/src/main/java/org/dhis2/bindings/Bindings.java index c80c620e2b6..dac7553a339 100644 --- a/app/src/main/java/org/dhis2/bindings/Bindings.java +++ b/app/src/main/java/org/dhis2/bindings/Bindings.java @@ -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 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) { diff --git a/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventCapture/EventCaptureActivity.kt b/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventCapture/EventCaptureActivity.kt index 9e1a71aa393..c5fd8794aa0 100644 --- a/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventCapture/EventCaptureActivity.kt +++ b/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventCapture/EventCaptureActivity.kt @@ -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 @@ -110,7 +110,7 @@ class EventCaptureActivity : showProgress() presenter!!.initNoteCounter() presenter!!.init() - binding?.syncButton?.setOnClickListener { showSyncDialog() } + binding.syncButton.setOnClickListener { showSyncDialog() } if (intent.shouldLaunchSyncDialog()) { showSyncDialog() @@ -118,7 +118,7 @@ class EventCaptureActivity : } private fun setUpViewPagerAdapter(initialPage: Int) { - binding!!.eventViewPager.isUserInputEnabled = false + binding.eventViewPager.isUserInputEnabled = false adapter = EventCapturePagerAdapter( this, intent.getStringExtra(Constants.PROGRAM_UID), @@ -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() @@ -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() { @@ -164,7 +164,7 @@ class EventCaptureActivity : it.dismiss() } } - binding?.navigationBar?.selectItemAt(1) + binding.navigationBar.selectItemAt(1) } override fun onResume() { @@ -190,7 +190,7 @@ class EventCaptureActivity : } private fun finishEditMode() { - if (binding!!.navigationBar.isHidden()) { + if (binding.navigationBar.isHidden()) { showNavigationBar() } else { attemptFinish() @@ -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 } } @@ -237,7 +237,7 @@ class EventCaptureActivity : emptyMandatoryFields: Map, 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 = { @@ -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 { @@ -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 {