Untitled
unknown
plain_text
a year ago
18 kB
3
Indexable
Never
Aaaaaa class DynamicMenuPresenterImpl(private var view: DynamicMenuView) : DynamicMenuPresenter { override fun checkFilter(filter: String, sections: List<DynamicMenuSection>) { val sectionsWithIconAndDescription: List<DynamicMenuSection> = sections if (filter.isEmpty()) { view.hideInlineInfoView() view.setAdapterContent(sectionsWithIconAndDescription) } else { val sectionsWithoutIconAndDescription: List<DynamicMenuSection> = sections analyticsValue = filter view.setAdapterContentFilter( removeIconAndDescription(sectionsWithoutIconAndDescription), filter) } } private fun removeIconAndDescription(sections: List<DynamicMenuSection>) : List<DynamicMenuSection> { sections.forEach { dynamicMenuSection -> dynamicMenuSection.content?.forEach { dynamicMenuContent -> dynamicMenuContent.icon = null dynamicMenuContent.description = null dynamicMenuContent.children?.forEach { dynamicMenuSection -> dynamicMenuSection.content?.forEach { dynamicMenuSectionContent -> dynamicMenuContent.description = null dynamicMenuSectionContent.children?.forEach { dynamicMenuSectionContentChildren -> dynamicMenuSectionContentChildren.content?.forEach { dynamicMenuSectionContentLastChildren -> dynamicMenuSectionContentLastChildren.description = null } } } } } } return sections } } package br.com.santander.modulo.dynamicmenu.presentation import android.content.Intent import android.graphics.Color import android.os.Bundle import android.os.Handler import android.os.Looper import android.view.View import android.widget.FrameLayout import android.widget.ImageView import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import br.com.santander.modulo.dynamicmenu.DynamicMenuApplication import br.com.santander.modulo.dynamicmenu.DynamicMenuRouter import br.com.santander.modulo.dynamicmenu.DynamicMenuRouter.Companion.DYNAMIC_MENU_RESULT_FULL_CLOSE_CODE import br.com.santander.modulo.dynamicmenu.R import br.com.santander.modulo.dynamicmenu.model.* import br.com.santander.modulo.dynamicmenu.presentation.adapter.BuildAdapter import br.com.santander.modulo.dynamicmenu.presentation.adapter.DynamicMenuAdapter import br.com.santander.modulo.dynamicmenu.presentation.util.ActivityAnimation import br.com.santander.modulo.dynamicmenu.presentation.util.PresentationUtils import br.com.santander.modulo.dynamicmenu.presenter.DynamicMenuPresenter import br.com.santander.modulo.dynamicmenu.presenter.DynamicMenuPresenterImpl import br.com.santander.modulo.dynamicmenu.presenter.DynamicMenuPresenterImpl.Companion.analyticsValue import br.com.santander.ui.inlineInfoView.SantanderInlineInfoView import br.com.santander.ui.inlineInfoView.SantanderInlineInfoViewCallback import br.com.santander.ui.inlineInfoView.SantanderInlineInfoViewColors import br.com.santander.ui.listAction.SantanderDefaultAdapterItem import br.com.santander.ui.searchBox.SantanderSearchBarFloat interface DynamicMenuView { fun showMenu(model: DynamicMenuModel) fun closeMenu() fun setFirstLabel(label: String) fun setSecondLabel(label: String) fun setExitLabel(label: String?) fun setExitLabelColor(color: String?) fun setExitIconColor(icon: String?, iconColor: String?) fun setMyDataComponents(icon: String?, iconColor: String?, action: String?) fun setMyDataComponentsColor(firstLabelColor: String?, secondLabelColor: String?) fun setExitLabelAccessibility(label: String?) fun launchSubMenu(menuItem: DynamicMenuContent) fun showInLineInfoView(value: String) fun showSearchBar(model: DynamicMenuModel, search: DynamicMenuSearchBar) fun setAdapterContent(sections: List<DynamicMenuSection>) fun setAdapterContentFilter(sections: List<DynamicMenuSection>, filter: String) fun hideInlineInfoView() fun hideIconEmptyState() fun showIconEmptyState() fun launchUnavailabilityItem(dynamicMenuUnavailability: DynamicMenuUnavailability) fun analyticsClick(label: String) fun analyticsFill(label: String, value: String) } class DynamicMenuActivity : AppCompatActivity(), DynamicMenuView { private val activityAnimation = ActivityAnimation(ActivityAnimation.AnimType.FADE_IN_FADE_OUT) private var layoutLogout: FrameLayout? = null private var layoutClose: FrameLayout? = null private var btnExit: ImageView? = null private var tvExit: TextView? = null private var recyclerView: RecyclerView? = null private var adapter: DynamicMenuAdapter? = null private var emptyStateView: SantanderInlineInfoView? = null private var searchBarview: SantanderSearchBarFloat? = null private val handler = Handler(Looper.getMainLooper()) private var searchRunnable: Runnable? = null private var userInput: String = "" private val DELAY: Long = 300 private var searchBar: DynamicMenuSearchBar? = null private var santanderDefaultAdapterItem: SantanderDefaultAdapterItem? = null private val presenter: DynamicMenuPresenter by lazy { DynamicMenuPresenterImpl(this) } companion object{ lateinit var firstLabel: String lateinit var secondLabel: String } override fun onCreate(savedInstanceState: Bundle?) { overridePendingTransition(activityAnimation.animStart, activityAnimation.animEnd) super.onCreate(savedInstanceState) setContentView(R.layout.activity_dynamic_menu) initViews() presenter.showMenu() } private fun initViews(){ santanderDefaultAdapterItem = findViewById(R.id.dynamic_menu_header_my_data) layoutLogout = findViewById(R.id.dynamic_menu_header_layout_logout) layoutClose = findViewById(R.id.dynamic_menu_header_layout_btn_close) btnExit = findViewById(R.id.dynamic_menu_header_iv_btn_exit) tvExit = findViewById(R.id.dynamic_menu_header_tv_btn_exit) recyclerView = findViewById(R.id.rv_dynamic_menu_list) emptyStateView = findViewById(R.id.empty_state_dynamic_menu) searchBarview = findViewById(R.id.dynamic_menu_header_search_bar) } override fun showMenu(model: DynamicMenuModel) { layoutLogout?.setOnClickListener { presenter.buildHeaderLogout(model.header) } setAdapterContent(model.sections) layoutClose?.setOnClickListener { presenter.checkValueFromSearchAnalytics(PresentationUtils.ANALYTICS_LABEL_BUTTON_CLOSE_MENU, analyticsValue) closeMenu() } } override fun setAdapterContent(sections: List<DynamicMenuSection>){ adapter = BuildAdapter(this).initAdapter() recyclerView?.adapter = adapter recyclerView?.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false) adapter?.items = presenter.toContent(sections) } override fun setAdapterContentFilter(sections: List<DynamicMenuSection>, filter: String){ adapter = BuildAdapter(this).initAdapter() recyclerView?.adapter = adapter recyclerView?.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false) adapter?.items = presenter.contentFilter(sections, filter) } override fun setFirstLabel(label: String){ firstLabel = label } override fun setSecondLabel(label: String){ secondLabel = label } override fun setExitLabel(label: String?){ tvExit?.text = label } override fun setExitLabelColor(color: String?){ tvExit?.setTextColor(PresentationUtils.getColorText(color)) } override fun setExitIconColor(icon: String?, iconColor: String?){ btnExit?.setImageDrawable(PresentationUtils.getIconWithColor(this, icon, iconColor)) } override fun setMyDataComponents(icon: String?, iconColor: String?, action: String?) { santanderDefaultAdapterItem?.setComponentsMyData( firstLabel, secondLabel, "$firstLabel, $secondLabel", PresentationUtils.getMyDataIcon(this, icon, iconColor), false, false, true, 120, 120 ) santanderDefaultAdapterItem?.setOnSantanderDefaultAdapterItemClick(1000L) { if (action != null) { DynamicMenuApplication.instance?.onItemClicked?.invoke(action) } } } override fun setMyDataComponentsColor(firstLabelColor: String?, secondLabelColor: String?){ santanderDefaultAdapterItem?.setColorTextMyData(PresentationUtils.getColorText(firstLabelColor), PresentationUtils.getColorText(secondLabelColor)) } override fun setExitLabelAccessibility(label: String?){ tvExit?.contentDescription = label } override fun launchSubMenu(menuItem: DynamicMenuContent){ DynamicMenuRouter.launchSubMenu(this, menuItem) } override fun launchUnavailabilityItem(dynamicMenuUnavailability: DynamicMenuUnavailability) { DynamicMenuUnavailabilityActivity.dynamicMenuUnavailability = dynamicMenuUnavailability this.startActivity(Intent(this, DynamicMenuUnavailabilityActivity()::class.java)) } override fun analyticsClick(label: String) { DynamicMenuApplication.instance?.analyticsProviders?.get( PresentationUtils.ANALYTICS_FIREBASE)?.tagSearchBar( PresentationUtils.ANALYTICS_ACTION_CLICK, label ) } override fun analyticsFill(label: String, value: String) { DynamicMenuApplication.instance?.analyticsProviders?.get( PresentationUtils.ANALYTICS_FIREBASE)?.tagSearchBar( PresentationUtils.ANALYTICS_ACTION_FILL, PresentationUtils.ANALYTICS_LABEL_INPUT + label + PresentationUtils.ANALYTICS_SEPARATOR + value ) } override fun showSearchBar(model: DynamicMenuModel, search: DynamicMenuSearchBar) { searchBar = search searchBarview?.visibility = View.VISIBLE searchBarview?.setSearchIcon(PresentationUtils.getSearchIcon(this, search.searchIcon)) searchBarview?.setClearIcon(PresentationUtils.getSearchIcon(this, search.clearIcon)) searchBarview?.setHint(PresentationUtils.isNotNullorEmptySearch(search.hint)) searchBarview?.setAccessibilityCardView(PresentationUtils.isNotNullorEmptySearch(search.accessibility)) searchBarview?.setColorCardView(Color.parseColor(search.colorBackground)) searchBarview?.setColorEditText(Color.parseColor(search.colorText)) searchBarview?.setCornerRadiusCardView(4f) searchBarview?.setClearIconOnclickListener { presenter.checkValueFromSearchAnalytics(PresentationUtils.ANALYTICS_LABEL_BUTTON_ERASE_FILL, analyticsValue) } searchBarview?.onTextChangeCallback = { userInput = it searchRunnable?.let { searchRunnable -> handler.removeCallbacks(searchRunnable) } searchRunnable = Runnable { if ((it == userInput && it.length >= 2) || it.isEmpty()) presenter.checkFilter(it, model.sections) } handler.postDelayed(searchRunnable!!, DELAY) } searchBarview?.doSearchCallback = { presenter.checkFilter(it, model.sections) } } override fun showInLineInfoView(value: String){ analyticsValue = value emptyStateView?.visibility = View.VISIBLE recyclerView?.visibility = View.GONE presenter.checkIconEmptyState(searchBar?.emptyState?.icon) emptyStateView?.lineConfig(SantanderInlineInfoViewColors.BORDERLESS) emptyStateView?.setDescription(PresentationUtils.isNotNullorEmptyDescription(searchBar?.emptyState?.description)) emptyStateView?.setTextButtonLinkCallback(PresentationUtils.isNotNullorEmptyLink(searchBar?.emptyState?.link), SantanderInlineInfoViewCallback { presenter.checkValueFromSearchAnalytics(PresentationUtils.ANALYTICS_LABEL_LINK_CALL_TO_US, analyticsValue) hideInlineInfoView() DynamicMenuApplication.instance?.onItemClicked?.invoke(PresentationUtils.isNotNullorEmptyCallback(searchBar?.emptyState?.action)) closeMenu() }) } override fun hideIconEmptyState(){ emptyStateView?.hideIcon(View.GONE) } override fun showIconEmptyState(){ emptyStateView?.setIcon(PresentationUtils.getEmptyStateIcon(this, searchBar?.emptyState?.icon)) } override fun hideInlineInfoView(){ emptyStateView?.visibility = View.GONE recyclerView?.visibility = View.VISIBLE } override fun onBackPressed() { closeMenu() } override fun closeMenu() { finish() overridePendingTransition(activityAnimation.animStart, activityAnimation.animEnd) } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if(resultCode == DYNAMIC_MENU_RESULT_FULL_CLOSE_CODE) { finish() } } } package br.com.santander.modulo.dynamicmenu.model import android.os.Parcelable import com.google.gson.annotations.SerializedName import kotlinx.parcelize.Parcelize abstract class Validatable { abstract val toggle: String? abstract val validate: List<Map<String, String>>? } data class DynamicMenuModel( @SerializedName("header") val header: DynamicMenuHeader, @SerializedName("sections") val sections: List<DynamicMenuSection> ) data class DynamicMenuHeader( @SerializedName("firstLabel") val firstLabel: String, @SerializedName("colorFirstLabel") val colorFirstLabel: String?, @SerializedName("secondLabel") val secondLabel: String, @SerializedName("colorSecondLabel") val colorSecondLabel: String?, @SerializedName("icon") val icon: String?, @SerializedName("colorIcon") val colorIcon: String?, @SerializedName("action") val action: String?, @SerializedName("button") val button: DynamicMenuContent, @SerializedName("searchBar") val searchBar: DynamicMenuSearchBar? ) @Parcelize data class DynamicMenuSearchBar( @SerializedName("searchIcon") val searchIcon: String?, @SerializedName("clearIcon") val clearIcon: String?, @SerializedName("hint") val hint: String?, @SerializedName("toggle") override val toggle: String?, @SerializedName("accessibility") val accessibility: String?, @SerializedName("colorBackground") val colorBackground: String?, @SerializedName("colorText") val colorText: String?, @SerializedName("emptyState") val emptyState: DynamicMenuSearchBarEmptyState?, @SerializedName("validate") override val validate: List<Map<String, String>>? ): Parcelable, Validatable() @Parcelize data class DynamicMenuSearchBarEmptyState( @SerializedName("icon") val icon: String?, @SerializedName("colorIcon") val colorIcon: String?, @SerializedName("description") val description: String?, @SerializedName("link") val link: String?, @SerializedName("accessibility") val accessibility: String?, @SerializedName("action") val action: String?, @SerializedName("colorBackground") val colorBackground: String? ): Parcelable @Parcelize data class DynamicMenuUnavailability( @SerializedName("title") var title: String?, @SerializedName("base64Image") val base64Image: String?, @SerializedName("errorMessage") val errorMessage: String?, @SerializedName("procedure") val procedure: String?, @SerializedName("textButton") val textButton: String?, @SerializedName("actionButton") val actionButton: String?, @SerializedName("textLink") val textLink: String?, @SerializedName("actionLink") val actionLink: String? ) : Parcelable @Parcelize data class DynamicMenuSection( @SerializedName("title") var title: String?, @SerializedName("content") val content: List<DynamicMenuContent>?, @SerializedName("toggle") override val toggle: String?, @SerializedName("validate") override val validate: List<Map<String, String>>? ) : Parcelable, Validatable() @Parcelize data class DynamicMenuContent( @SerializedName("id") var id: String?, @SerializedName("title") var title: String?, @SerializedName("name") val name: String, @SerializedName("colorText") val colorText: String?, @SerializedName("badgeNotification") val badgeNotification: Boolean = false, @SerializedName("description") var description: String?, @SerializedName("highlight") val highlight: Boolean = false, @SerializedName("keep") val keep: Boolean = false, @SerializedName("icon") var icon: String?, @SerializedName("colorIcon") val colorIcon: String?, @SerializedName("accessibility") val accessibility: String?, @SerializedName("analytics") val analytics: List<Map<String, String>?>?, @SerializedName("tag") val tag: String?, @SerializedName("action") val action: String?, @SerializedName("badge") val badge: Boolean = false, @SerializedName("toggle") override val toggle: String?, @SerializedName("validate") override val validate: List<Map<String, String>>?, @SerializedName("separator") var separator: Boolean = false, @SerializedName("isUnavailable") var isUnavailable: Boolean = false, @SerializedName("children") val children: List<DynamicMenuSection>?, @SerializedName("unavailability") val unavailability: DynamicMenuUnavailability?, ) : Parcelable, Validatable()