Search code examples
bixby

Match multiple concept


Wish to show my input view, with a message vary from time, and showing content based on another variable.

This is my input-view

input-view{
    match{
        userWantToHear(this){
            from-output:getStart //action to get list of selection
        }
    }

    message{
        switch (this){//should be another value which is (timePeriod)
            case ("M"){
                template-macro (morning-template)
            }
            case ("A"){
                template-macro (afternoon-template)
            }
            case ("N"){
                template-macro (night-template)
            }
            default{
                template-macro (normal-template)
            }
        }
    }

    render{
        selection-of (this){ //this should be (userWantToHear)
            where-each (one){
                spoken-summary{ 
                    template ("#{value(one)}")
                }
                cell-card{
                    slot2{
                        content{
                            primary{
                                template ("#{value(one)}")
                            }
                        }
                    }
                }
            }
        }
    }
}

So what my thought is, create a structure to contain both of them.

structure (menu) {
  description (__DESCRIPTION__)
  property (timeperiod){
    type (timePeriod)
    min (Required) max (One)
  }

  property (whatuserwant) {
    type (userWantToHear)
    min (Required) max (One)
  }

}

And i also create a action to get them.

action (getMenu) {
  type(Search)
    collect{
        input (timeperiod){
            type (timePeriod)
            min (Required) max (One)
            default-init{
                intent{
                    goal: getTime
                }
            }
        }
    input (whatuserwant){
      type (userWantToHear)
      min (Required) max (One)
      default-init{
        intent{
          goal: getStart
        }
      }
    }
    }
  output (menu)
}

The result from the input-view will be pass into the action below, which is userWantToHear

action (getNews) {
    type (Search)
    description (__DESCRIPTION__)
    collect {
        input (whatuserwant){
            type (userWantToHear)
            min (Required) max (One)
            default-init{
                intent{
                    goal: getMenu
                }
            }
        }
    }
    output (newsAudio)
}

So i wonder how the input view is gonna accept the structure and access the property inside it for each section, and get back the input i want? Currently from my side, it's able to get the selection, but the message doesn't change according to "timePeriod" where i believe it doesn't pass in into the input view yet.


Solution

  • I think there are two questions here in your post.

    1. How do I render different views? Answer: use if-else or switch statement to select template macros.

    2. How to I access concept not in match Type(this)? Answer: use complicated match pattern that link these concept through an action. Consider the following code block.

      match: IntAge(this) {
        to-input: GetStructPerson (action)
      }
      message {
        template ("Enter age of #{value(action.name)}")
      }
    

    You can read more and download sample capsule in Bixby Developer Center