Synchronize UI thread (Pivot item from active to non active view) - windows-runtime

I would like to synchronize the UI thread with changes in a view (pivot item 1 active view) which is active when the changes begin and switch to non active state (User interaction like changing the pivot item from the pivot item 1 to pivot item 2) before finishing the changes.
The changes never happens and the view is restored as the point when switching from active to non active state.
The UI stack composed from
ScrollViewer
Grid
List view
Grid
The grid controls contains progress bars to handle refresh
private async void scrollViewer_ViewChanged2(object sender, ScrollViewerViewChangedEventArgs e)
{
var listView = scrollViewer.GetDescendantsOfType<ListView>().FirstOrDefault();
var context = DataContext as IMainStreamViewModel;
if (e.IsIntermediate) return;
var dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
if (Math.Abs(scrollViewer.VerticalOffset) < 0.01 && _isPullRefresh)
{
// Adding item the Observable collection that is the
// the item source for the listview
// The method just add element using the core dispatcher
context.PullToRefreshInsertion_Top(dispatcher, listView);
}
else if (_scrollBar.Value >= _scrollBar.Maximum)
{
// same action but in bottom of the observable collection
// The method just add element using the core dispatcher
context.PullToRefreshAdd_Bottom(dispatcher, listView);
}
_isPullRefresh = false;
// Set the current element to be displayed in the list view
await dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() => listView.ScrollIntoView(listView.SelectedItem));
// Scroll to the the listview and hidding the progress control
await Task.FromResult(scrollViewer.ChangeView(null, 60, null));
}
Finally the element may be added but the scroll viewer dont reset his position and listview also
How to solve the sychronisation, i think the problem come from the IsActiveView state if the UI element is not in the ACTIVE VIEW it doesn't execute or skip the event.
UPDATE 1 :
The situation is as :
Pivot control that contain two pivot items :
Pivot item one contain :
***Scrollviewer
******Grid that contain a custom progress bar top refresh
******ListView containing the data that user can see and interact with
******Grid that contain a custom progress bar bottom refresh
Pivot item two contain some Richtextblock ...
When i'm doing the pull to refresh from the pivot item one and before the custom progress bar disappears do swipe to the next pivot item.
When i come back to the first pivot item, it was freezed at the state when i want to refresh and the top or bottom progress bar still visible.
I solved that by doing some trick and add some isVisible property in my view model and i fire the event whenever i'm in this pivot item i call updatelayout() and now it works.
I think the problem come from the fact when i'm doing swipe, the UI thread cancels all operations and start executing the operations attached to the active view this is why the update layout event for the first pivot item never fire.

Related

Track Share events to FirebaseAnalytics

I have a share function on the app that allows users to share app to others, but I want to track number of shares. The share item is on the action bar, not on the app dropdown menu.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
//some other code here for items search item
//share menu item
MenuItem shareItem = menu.findItem(R.id.menu_item_share);
// Fetch and store ShareActionProvider
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem);
String playStoreLink = Constants.PLAYSTORE_LINK + getPackageName();
String shareText = "Install app" + playStoreLink;
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
.setType("text/plain").setText(shareText).getIntent();
// Set the share Intent
mShareActionProvider.setShareIntent(shareIntent);
return true;
}
I have managed to implement tracking on other events by simply adding code in onClick() events but share event doesnt have onClick.
Code for tracking events example
Bundle param = new Bundle();
param.putString("call_data", "1");
mFirebaseAnalytics.logEvent("calls_made", param);
I've been strugling with the exact challenge, the quick answer is NO.
BUT, you can create your own share dialog in which you can detect on which app the user chose to share and then use analytics as desired:
Find the solution here
Another solution with ShareActionProvider

Limit number of items realized or detect items in view for LongListSelector

I'm trying to implement infinite scrolling for the LongListSelector.
I initially populate the list with 15 items, and rely on the ItemRealized event to detect when I'm at the end of the list and need to load more. 5 items are visible on a WXGA screen at once.
My problem is that all 15 items are realized on the first load, and it immediately loads more. This is not desirable as each load is tied to an expensive network call.
Is it possible to limit the number of items to realize outside of view (I would set it to < 15), or is there a way to rely on items getting in view instead of being realized?
I think you need to maintain one property in your viewmodel which will decide when to load..
Code should be something like for any fixed item(here 15 in your case)
private void ItemRealized(object sender, ItemRealizationEventArgs e)
{
if (e.ItemKind == LongListSelectorItemKind.Item)
{
ViewModel vm = DataContext as ViewModel;
var item = e.Container.Content;
var items = nameoflonglistSelector.ItemsSource;
var index = items.IndexOf(item);
if (vm.Isloading == false && index == nameoflonglistSelector.ItemsSource.Count-1) //initally it will be false
{
vm.laodextraData();
vm.Isloading = true;
}
}
}

AS3 - how to make 4 buttons and go to another frame when all 4 buttons clicked in random order

Hello I hawe 4 buttons on one frame and I can't figure out how to go to another frame when I clicked all 4 buttons in random order. Condition is one - all 4 buttons must be clicked at least once.
my buttons:
Button1
Button2
Button3
Button4
in frame 1 - when al clicked - goto frame 2
Here is a pretty common way of getting this done.
private var _buttonsRemaining:int;
private function setup():void{
button1.addEventListener(MouseEvent.CLICK,onButtonClicked);
button2.addEventListener(MouseEvent.CLICK,onButtonClicked);
button3.addEventListener(MouseEvent.CLICK,onButtonClicked);
button4.addEventListener(MouseEvent.CLICK,onButtonClicked);
_buttonsRemaining = 4;
}
private function onButtonClicked(e:MouseEvent):void{
(e.target as EventDispatcher).removeEventListener(MouseEvent.CLICK,onButtonClicked);
_buttonsRemaining --;
if(_buttonsRemaining <= 0){
allClicked();
}
}
private function allClicked():void{
trace("all buttons clicked.");
}
Unlike above, I like to declare 'allClicked' as an Event-friendly method. This way you can dispatch an event -- Event.COMPLETE maybe -- to trigger the method.
private function allClicked(e:Event=null):void{
//...
}
I am not sure if I understand your problem right. I assume you mean be "frame" the view of a view controller, and you want to show another view of another view controller as soon as all of your 4 buttons in the 1st view have been pushed at least once.
I assume you have already your first view controller and its view, together with the 4 buttons, defined in the storyboard. You could then drag a new view controller from the library to your storyboard. You had to define a new subclass of an UIViewController in your app, and set the class of the new view controller in the storyboard to this new subclass.
Next you had to check if all of your buttons have been pressed. You could thus define one #property bool buttonXpressed for each button X, and set this property to YES when the IBAction method of this button is pressed. In each of these IBActions, you could check if all 4 properties are set to YES, and if so, you could present the view of the 2nd view controller by calling the presentViewController:animated:completion: method with the 2nd view controller as argument.

Scroll issue over selectionlistener using ListModel

In Codenameone, I've used the list as container renderer to form and after parsing JSON data using hastable, I shown results on items of the list. The list contains hastable has been passed over ListModel and it works fine . Whenever I use ListModel , I just want to click on list item and action triggers. Problem is using ListModel it has only
datalist.addSelectionListener(new SelectionListener() {
public void selectionChanged(int oldSelected, int newSelected) {
// TODO Auto-generated method stub
}
});
I won't be able to scroll the whole page due to select on any item, it triggers the action.
Any option how I can scroll whole results on page as well onClick so that I can trigger the action?
Use action listener in the List not the list model.

How do I disable/enable a handled toolitem based on which MPart is selected?

I have several toolitems that I want to enable/disable based on which MPart the user selected. How can I accomplish that ?
You can add the following code to the handler of your toolbar items:
#CanExecute
public boolean canExecute(#Named(IServiceConstants.ACTIVE_PART) MPart part) {
// enable item if active part is part with id "my.part.id"
if ("my.part.id".equals(part.getElementId())) {
return true;
}
// disable item if any other part is active
return false;
}
#CanExecute is called before the handled entry is shown in menus or toolbars. If an entry cannot be executed, its state is set to "disabled".
In the above code, the active part is injected and can then be used to determine the handler's executable state.