Skip to content

Country Row

Harsh B. Bhakta edited this page Aug 15, 2020 · 4 revisions

Country Row is the country item that you see inside the recycler view / list. It can be customized using CPRowConfig (source). Since it's embeded part of the recycler view, CPRecyclerViewHelper [todo: add link] will take in an instance of CPRowConfig.

Configuration - CPListConfig source

Flag

  • By default, country's emoji flag is loaded
  • How to provide custom flag images?
    • Add flags as your drawable resources
    • Create a class CustomFlagImageProvider that extends CPFlagImageProvider(source)
    • Provide an instance of CustomFlagImageProvider to CPRowConfig through extension functions [todo: add link] or CPRecyclerViewHelper [todo: add link].

Primary Text

  • By default, country's name is set as primary text.
  • How to provide custom primary text?
    • CPRowConfig (source) takes a lambda primaryTextGenerator which is responsible for generating primary text using CPCountry (source).
    • Check source of CPCountry to find all the properties that you can use to generate this.
  • Example
    • To add alpha3 code at end of the name do following:
       val primaryTextGenerator = { cpCountry: CPCountry -> 
             "${cpCountry.name} (${cpCountry.alpha3})"
         }
  • Provide primaryTextGenerator to CPRowConfig through extension functions [todo: add link] or CPRecyclerViewHelper [todo: add link].

Secondary Text

  • By default, secondary text is null (that's why hidden)
  • How to provide custom secondary text?
    • CPRowConfig (source) takes a lambda secondaryTextGenerator which is responsible for generating secondary text using CPCountry (source).
    • Check source of CPCountry to find all the properties that you can use to generate this.
  • Example
    • To add country's capital as secondary text do following:
       val secondaryTextGenerator = { cpCountry: CPCountry ->
             cpCountry.capitalEnglishName
         }
  • Provide secondaryTextGenerator to CPRowConfig through extension functions [todo: add link] or CPRecyclerViewHelper [todo: add link].

Highlighted Text

  • By default, highlighted text is null (that's why hidden)
  • How to provide custom highlighted text?
    • CPRowConfig (source) takes a lambda highlightedTextGenerator which is responsible for generating secondary text using CPCountry (source).
    • Check source of CPCountry to find all the properties that you can use to generate this.
  • Example
    • To add phone code as highlighted text do following:
       val highlightedTextGenerator = { cpCountry: CPCountry ->
             "+${cpCountry.phoneCode}"
         }
  • Provide highlightedTextGenerator to CPRowConfig through extension functions [todo: add link] or CPRecyclerViewHelper [todo: add link].
Clone this wiki locally