In BlackBerry 10, how to read a ListView clearSelection() signal parameters? - blackberry-10

For ListView one can programattically do a clearSelection():
"This function does not cause signals to be emitted for individual items. Instead, a single selectionChanged() is emitted with ListView::AllItems and false as parameters."
http://developer.blackberry.com/cascades/reference/bb_cascades_listview.html#function-clearselection
How can I listen for this when clearSelection() is called at onSelectionChanged?
Something like:
onSelectionChanged:{
if((!selected)&&(indexPath == listViewid.AllItems)){
//do something
}
}
I don't understand " Instead, a singleselectionChanged() is emitted with ListView::AllItems and false as parameters" and how to listen for those paramters.

Related

Scala swing wait for a button press after pressing a button

So What I want to do is to press a button and inside the ButtonClicked Event I want to wait completing the event, until I press a specific button/one of the specified buttons.
I also know that there are some similar questions to this topic but I wasnt able to find a fix out of the answers
So basically this:
reactions += {
case event.ButtonClicked(`rollDice`) =>
some code ...
wait for one of the specified buttons to be pressed and then continue
some code ...
Is there an easy way to solve this problem without the use of threads?
There are certainly some abstractions you could set up around the event layer, but you asked for "easy", so my suggestion is to set a flag/state when the dice are rolled, and then check for that flag in the other buttons' event handler.
private var postDiceRollState: Option[InfoRelatedToRollDice] = None
reactions += {
case event.ButtonClicked(`rollDice`) =>
// capture whatever info you need to pass along to the later button handler
val relevantInfo = /* some code... */
// store that info in the "state"
postDiceRollState = Some(relevantInfo)
case event.ButtonClicked(other) if isPostDiceRollButton(other) =>
// when the other button gets clicked, pull the relevant info from your "state"
postDiceRollState match {
case Some(relevantInfo) =>
postDiceRollState = None // clear state
doInterestingStuff(relevantInfo) // "some code..."
case None =>
// nothing happens if you didn't roll the dice first
}
}
Note: I represented the "flag" as an Option, under the assumption that you might have some information you want to capture about the rollDice event. If you don't actually have anything to put in there, you could represent your state as private var didRollDice: Boolean = false and set/clear would be setting it to true/false respectively.

How to launch function one time when I have a recurrent call in flutter?

Hello I want to call my function just one time when my variable returns true, even if I have 20xtrue.
Currently I am listening to a variable from didChangeDependencies() so I have a continue stream of data, and when my variable is true, I have some true that call my function. I am trying to call my function only for the first true. To fix it a little, I have added a tempo after true to switch to false after some milliseconds but it's ugly, and some time my function doesn't see the true...
Sounds like you should put this into a for loop, so you can exit/break the loop when the value is true. Simplified version of this is the following:
for(var item in items){
if(item.status){ // true
//notify or do the thing you want to do
break;
}
}
note: this cannot be achieved with a forEach. It has to be a for loop to do this.
Is this what you want? Otherwise please try to elaborate on your problem.

Using "ViewState" in RxSwift/MVVM

This question is very broad but I'm not sure which aspect of it I should focus on. I have a goal to abstract away the recurring patterns of my screens such as errors, loading, empty data. The views that represent these states will not change much between the many screens I have. Perhaps they could be parameterized to allow that flexibility (e.g. showError(message: "404")).
I liked this article as a method of encapsulating the reusable UI aspects of this.
But it appears to work in an imperative context. So I have an API call and I can showError and in the response I can hideError. Thats all fine.
Now I use an RxSwift/MVVM approach where each screen binds to inputs and outputs. And I like to simplify the state my screen knows about by using a "View State" concept.
As you can see in this snippet, I can reduce a lot of logic a single Observable that the view renders.
let getFoos: (String) -> Observable<FooViewStateState> = { query in
fooService.perform(query)
.map { results in
if results.isEmpty {
return ViewState.noResults(query: query)
} else {
return ViewState.matches(query: query, results: results.map { $0.name })
}
}
.startWith(ViewState.searching(query))
}
The problem is that by using an enum ViewState its now unclear to me how to use the imperative API from before "showLoading / hideLoading ... showError / hideError, etc..." when I'm switching on the cases of this enum. If the ViewState Observable emits .loading I'd have to hide the error screen, hide the empty screen, etc..

While using ag-grid dataSurce, how can I know if the getRows function being called due to scrolling or filtering

As we know, in infinite rowModelType, we have to set dataSource for the ag-grid.
const dataSource = {
rowCount: count
getRows: (params: IGetRowsParams) => this.getRows(params, [])
};
this.gridApi.setDatasource(dataSource);
Now, dataSource.getRows method is called whenever there is need to fetch the rows in the grid (due to scrolling) OR the filter is changed.
I need to decide how many ajax calls need to be made depending on this reason. Below code blocks explains this.
private getRows(params: IGetRowsParams, data: any) {
// two ajax calls can be made from here
// 1. getCount
// 2. getData
// if this getRows function is called due to scrolling in the grid,
// I just want to call getData - no need to call getCount as I already know it
// if this is called due to change in filter,
// I need to call getCount as well as the no of rows will be different
// How can I know here due to which above mentioned reasons, getRows is getting called?
}
Is there anyway to know it within getRows function?

scala : double "selection changed" event raised for ListView component

here is the part of code:
val lsv_syns = new ListView[String]()
val scp_syns = new ScrollPane() {
listenTo(lsv_syns.mouse.moves,lsv_syns.selection)
reactions += {
case me: MouseExited => {
txf_mot.requestFocus()
}
case SelectionChanged(`lsv_syns`)=> {
println("sélection:"+lsv_syns.selection.items(0))
}
}
}
As you can see, the listView is in a scrollPane; don't pay attention to the mouseExited event, the interesting thing is the selectionChanged, which seems to be called twice when I only click on time on an other line, because the println is called two times.
thanks.
Well i also recently worked with a ListView and now that you mentioned it, it also does my calculation twice.
The answer seems to be related to mouse events. Following the stack trace SelectionChanged is called twice. One coming from the Java event MousePressed and one from MouseReleased.
When you change the selection with KeyEvents it is only called once.
My first (and I guess not nice) idea to avoid the problem would be to ignore one of the events:
reactions += {
case SelectionChanged(`lsv_syns`) if !lsv_syns.selection.adjusting => {
println("sélection:"+lsv_syns.selection.items(0))
}
}
Both ListSelection events share the same data except getValueIsAdjusting. So if you check for it you can avoid doing your stuff twice.
Warning: !lsv_syns.selection.adjusting will result in printing on key release and not on press!
If you put lsv_syns.selection.adjusting it will correspond to key press but it will also filter key events. As I said. Not nice at all...