killing fragment observing live-data instance in a shared view model - viewmodel

I am using shared view model to get values from socket across an activity, with help of observing a live-data instance, and navigation component to navigate between fragments so there's a situation where i show a payment receipt value then user clicks pay this fragment should navigate to another fragment and destroy the first one but what's actually happening it's still alive due to shared view model live-data instance that i was observing, so how to kill this fragment instance when navigating to another fragment
so first i was in trip status -> payment -> thanks
here's my navigation code
private fun updateTripStatusUI(isPayed: Boolean = false) {
if (isPayed) {
findNavController(R.id.navigationFragment).popBackStack()
findNavController(R.id.navigationFragment).navigate(
TripStatusFragmentDirections.actionTripStatusFragmentToThanksFragment()
)
} else
findNavController(R.id.navigationFragment).navigate(TripStatusFragmentDirections.actionGlobalPaymentFragment())
}
and here's my graph
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/trip_graph"
app:startDestination="#id/tripStatusFragment">
<fragment
android:id="#+id/tripStatusFragment"
android:name="package.TripStatusFragment"
android:label="fragment_trip_status"
tools:layout="#layout/fragment_trip_status">
<action
android:id="#+id/action_tripStatusFragment_to_thanksFragment"
app:destination="#id/thanksFragment"
app:enterAnim="#anim/nav_default_enter_anim"
app:exitAnim="#anim/nav_default_exit_anim"
app:popEnterAnim="#anim/popup_enter"
app:popExitAnim="#anim/popup_exit" />
</fragment>
<fragment
android:id="#+id/paymentFragment"
android:name="package.PaymentFragment"
android:label="PaymentFragment"
tools:layout="#layout/fragment_payment" />
<fragment
android:id="#+id/thanksFragment"
android:name="package.ThanksFragment"
android:label="ThanksFragment"
tools:layout="#layout/fragment_thanks" />
<action
android:id="#+id/action_global_paymentFragment"
app:destination="#id/paymentFragment"
app:enterAnim="#anim/nav_default_enter_anim"
app:exitAnim="#anim/nav_default_exit_anim"
app:popEnterAnim="#anim/nav_default_pop_enter_anim"
app:popExitAnim="#anim/nav_default_pop_exit_anim" />
</navigation>
and in ThanksFragment i navigate back to TripStatusFragment with this line
findNavController().navigate(R.id.tripStatusFragment)

Related

How can I open an App using it own background service

I'm creating Xamarin.Forms App and it has a service that runs in the background monitoring if any messages arrive. If a message arrives, the service should open the App.
I tried to open the App using Intent (Dependency Service) and I also tried using Xamarin.Essentials. Neither way worked.
My last attempt was with Xamarin.Essentials and gave the following error:
[Error][1]
[1]: https://i.stack.imgur.com/5jPGf.png
This is my code using Intent (Dependency Service):
//Intent (Dependency Service)
string teste = "com.saferit.saferproject";
openAppManager = DependencyService.Get<IAppHandler>();
openAppManager.Initialize(teste);
openAppManager.LaunchApp();
[enter image description here][2]
[2]: https://i.stack.imgur.com/lLx3g.png
This is my native code for Android
public void LaunchApp()
{
Intent intent = new Intent();
intent.SetClassName(Package, "activity");
intent.AddFlags(ActivityFlags.NewTask);
Xamarin.Forms.Forms.Context.StartActivity(intent);
}
[Complete Native Code][3]
[3]: https://i.stack.imgur.com/G4zOV.png
This is my AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.saferit.saferproject" android:installLocation="preferExternal">
<uses-sdk android:minSdkVersion="27" android:targetSdkVersion="29" />
<!--<application android:label="SaferProject.Android"></application>-->
<application android:label="com.saferit.saferproject" android:icon="#drawable/logo">
<activity android:icon="#drawable/logo" android:label="com.saferit.saferproject" android:name="com.saferit.saferproject">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="com.saferit.saferproject" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
This is my attempt using Xamarin.Essential:
//Xamarin.Essentials
var appname = "com.saferit.saferproject://";
var supportsUri = await Launcher.CanOpenAsync(appname);
if (supportsUri)
await Launcher.OpenAsync(appname);
Looking for here at stackoverflow I found this question:
Open Notification list page when user clicks on navigation
I tried to implement it on my App but I also couldn't get it to work.
In all three cases the errors are very similar.
I think the problem is in the configuration of the URI of my App.
Can someone help me?

How to create Orbeon custom control XBL with predefined visibility, control name, default value?

I have created a custom control (hidden text box with some predefined value), where I want to set visibility=false(), controlName="Mycustom", default value="This is my custom control" in XBL file. So that whenever we use that custom control from Orbeon Form Builder, it will come with all default values with no need to set anything.
XBL:
<xbl:xbl xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xxi="http://orbeon.org/oxf/xml/xinclude"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
xmlns:saxon="http://saxon.sf.net/"
xmlns:xbl="http://www.w3.org/ns/xbl"
xmlns:exf="http://www.exforms.org/exf/1-0"
xmlns:xxbl="http://orbeon.org/oxf/xml/xbl">
<metadata xmlns="http://orbeon.org/oxf/xml/form-builder">
<display-name lang="en">Epson Custom Controls</display-name>
</metadata>
<xbl:binding id="fr-custom" element="fr|custom" >
<metadata xmlns="http://orbeon.org/oxf/xml/form-builder">
<display-name lang="en">My Custom Control</display-name>
<icon lang="en">
<small-icon>/forms/orbeon/builder/images/input.png</small-icon>
<large-icon>/forms/orbeon/builder/images/input.png</large-icon>
</icon>
<templates>
<bind xxf:whitespace="trim"/>
<view>
<xf:input id="myCustom" ref="" xmlns="">
<xf:label>My Custom lable</xf:label>
<xf:hint ref=""/>
<xf:help ref=""/>
<xf:alert ref=""/>
</xf:input>
</view>
</templates>
</metadata>
</xbl:binding>
</xbl:xbl>
Using above control I want hidden text box with value='This is my custom control' and its control name should be Mycustom.
Update
I have tried with below changes, but it is not working
<templates>
<bind xxf:whitespace="trim" relevant="false()" xxf:default="'This is my custom control'"/>
<view>
<xf:input id="myCustom" ref="" xmlns="">
<xf:label>Success Message</xf:label>
<xf:hint ref=""/>
<xf:help ref=""/>
<xf:alert ref=""/>
</xf:input>
</view>
</templates>
With above changes now its working (control is hidden with some default value).
Can you please let me know how to put if condition
properties-local.xml:
<property as="xs:string" name="oxf.fr.detail.process.save-final-custom.*.*">
require-uploads
then validate-all
then save
if({xxf:instance('fr-form-instance')//customMessage} != null)
{
then success-message(message = "{xxf:instance('fr-form-instance')//customMessage}")
}
recover error-message("database-error")
</property>
Here I want to override this success-message if it properly configured from backed. If it's value is null then want to show OOTB message(don't override).
Update2
Integrated changes in Hybris. below are the changes I have made in Hybris
Create XBL > orbeon > custom > custom.xbl
<bind xxf:whitespace="trim" relevant="false()" xxf:default="'This is my custom control'"/>
Issue :- When we select custom control, it will bind without any lable/message/visibility etc. But if I refresh left control panel then label start appearing on the form. but still default message is not set.
Let's take the items you mentioned one by one:
visibility="false()" – I imagine you're referring to the relevant attribute in XForms, instead of the visibility attribute. (Form Builder calls this "visibility", because this is what it is, but in XForms, the attribute is relevant.) This can be done by having inside the <templates> a <bind relevant="false()"/>.
controlName="Mycustom" – You can't set the id of the control in XBL. (BTW, when using Form Builder, the XForms id is inferred from the control name defined by the form author in Form Builder.) The id is set by whoever uses the control, not whoever defines it, otherwise, for one, this would prevent you from having multiple instances of that control in the form.
default value="This is my custom control" – As in #1 above, you can do this with <bind xxf:default="'This is my custom control'">. Note the added single quotes, as the value of xxf:default is an XPath expression.

Remove blocks for every action in a controller

Hello guys i have created a controller. I want every action in this controller that is rendering layout to exclude header and footer. Is it possible to this via the xml.
<adminhtml_trips_index>
<remove name="header" />
<remove name="menu" />
<remove name="footer" />
without doing this for each action?
Also is there some event observer like _beforeRenderLayout.
The only solution i have at the moment is to invoke my custom made exclude_redundant_blocks() function, after $this->loadLayout() in every action.
Why not override the loadLayout method in your own controller and exclude the blocks after that instead of doing it in every action?
Something like this:
public function loadLayout($ids=null, $generateBlocks=true, $generateXml=true)
{
parent::loadLayout($ids, $generateBlocks, $generateXml);
//remove blocks here
return $this;
}
Or an other way would be to create a customer layout handle that removes the unwanted blocks
<custom_handle>
<remove name="header" />
<remove name="menu" />
<remove name="footer" />
</custom_handle>
Then load that handle in each action.
again rewrite the loadLayout method and make it look like this
public function loadLayout($ids=null, $generateBlocks=true, $generateXml=true)
{
$this->getLayout()->getUpdate()->addHandle('custom_handle')
return parent::loadLayout($ids, $generateBlocks, $generateXml);
}
the code above is untested, but in theory it should work.

Load page event in Flex?

I'm currently working on this website (http://www.jowannes.com/thomasschoof/flash/LauraBarsby.html) and I created a little gallery. When you press the image it becomes the background of the website. Now this has some problems if the background is white and you look at the other pages again, you can't read the text any more.
I would like it to be when you go back to another page, the background changes to it's original one. So basically I'm looking for the page (component?) load event or something alike, but I can't seem to find it.
CreationCompleted doesn't work for this, because when you navigate to it the second time it's already created, this the background doesn't change.
I'm setting the background like this:
Main page:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:component="component.*">
<fx:Script>
<![CDATA[
public function changeBackground(bitmapFillObj:BitmapFill):void
{
backgroundContainer.backgroundFill = bitmapFillObj;
}
]]>
</fx:Script>
<fx:Declarations>
<s:BitmapFill id="_bg1" source="#Embed('assets/bg1.jpg')"/>
<s:BitmapFill id="_bg2" source="#Embed('assets/bg2.jpg')"/>
</fx:Declarations>
<s:BorderContainer id="backgroundContainer" width="100%" height="100%" backgroundImage="#Embed('assets/bg1.jpg')" borderAlpha="0">
<component:home/>
</s:BorderContainer>
</s:WindowedApplication>
Component:
<fx:Script>
<![CDATA[
import mx.core.FlexGlobals;
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:layout>
<s:HorizontalLayout/>
</s:layout>
<s:Button label="click to show bg 1" click="FlexGlobals.topLevelApplication.changeBackground(FlexGlobals.topLevelApplication._bg1)"/>
<s:Button label="click to show bg 2" click="FlexGlobals.topLevelApplication.changeBackground(FlexGlobals.topLevelApplication._bg2)"/>
I also have the problem that the images become stretched, because I can't set the fillmode NOR can I center them, any ideas for this?
I hope somebody can help me, Thanks
Thomas
I found the solution: In a viewstack you have a handler called change=, I just put my method in there and it worked.

How to access backstage checkbox value in an Office addin?

I have a boolean property Settings.Default.MarkAsRead in the Setting.settings file, which I can access in my Ribbon class. What I'd like to do is set the value of a check box in my backstage section depending on the value of this property. Also if the user modifies it, I'll need to save the new value.
Any way I can do this?
This is my (simplified) xml:
<?xml version="1.0" encoding="UTF-8"?>
<customUI onLoad="Ribbon_Load"
xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<backstage>
<tab id="MyBackstageSection" label="MyBackstageSection"
columnWidthPercent="30" insertAfterMso="TabInfo" visible="true" >
<firstColumn>
<group id="grpOne" label="Configuration">
<bottomItems>
<checkBox id="markAsRead" label="Mark as read"
getPressed="markAsRead_GetPressed" />
<button id="save" label="Save Preferences" onAction="save_Click"/>
</bottomItems>
</group>
</firstColumn>
</tab>
</backstage>
</customUI>
I didn't find a way to access the xml elements from the Ribbon_Load method, so I've created a boolean property in the ribbon class that I update using the GetPressed and OnAction callbacks:
xml:
<checkBox id="markAsRead" label="Mark as read"
onAction="markAsRead_OnAction" getPressed="markAsRead_GetPressed"/>
c#:
private bool MarkAsRead { get; set; }
public bool markAsRead_GetPressed(Office.IRibbonControl control)
{
this.MarkAsRead = Settings.Default.MarkAsRead;
return this.MarkAsRead;
}
public void markAsRead_OnAction(Office.IRibbonControl control, bool isPressed)
{
this.MarkAsRead = isPressed;
}

Resources