How can I implement an architecturally clean sign-in screen in Jetpack compose? - firebase-authentication

My app uses Firebase authentication and I'm implementing a typical sign-in screen with buttons to sign in with Google, email etc. It's surprisingly difficult. I have a LocalUser class to hold the user's profile (name, email etc), state (whether they're logged in or in the process of logging in etc), and provide methods to start the process when a button is clicked. This seems like an ideal candidate for a ViewModel.
The trouble is, ViewModels mustn't hold a reference to an Activity, but the Google Identity SDK needs such a reference as part of its mechanism for providing its result to my code. I can't think of a way to decouple the ViewModel that doesn't still leave the ViewModel referencing the Activity, albeit indirectly.
Is it OK to just remove the ViewModel inheritance from my LocalUser class and pass it directly to my sign in screen (and from there to each control that needs it)? Is it OK for a Composable to hold a reference to Activity?

Related

how to handle heavy API request without blocking the UI in react native

i have some heavy API request made through my app. so i want to implement feature that if user hit any API request then after user should navigate through any screen but there is some loading icon indicating that API request is in progress.
For example :-
if user is in create-product screen and after clicking on create product button user should navigate through any screen like profile,,product-view or any other screen while API request is processing but i want to show some loading indicator from any screen that API request is in progress in background.
What you want is a singleton
Which is
A design pattern that ensures that exactly one application-wide instance of a particular class exists. One of the Gang of Four's creational design patterns.
I recommend you read more about it
It will be useful for your case
Here is how to make it with react native
React native- Best way to create singleton pattern

Managing session temporarily in ibm mobilefirst?

i have to develop a multipage application that includes invocation of several web services.
My first page has a login page. based on the user input i have to traverse to next page while calling the next web service simultaneously. so obviously this all depends on the login page information that has the userid and password and the response from the web service such as personId etc.
i need to store this information temporarily for a particular session but... how to do this?
There are two kinds of page:
There are the UI states as seen by the user. Your Login page and your Next page are examples of these. From the user's perspective they see a succession of pages.
However you are writing an App, a single controlling thing that is in charge of all those "UI pages". I suppose that you are using MobileFirst to create a hybrid application that is effectively executing in a browser. From that browser's perspective you have a single HTML page. This is important, MobileFirst only works with single-page applications.
Now the browser loads the HTML and JavaScript for your single application page and that JavaScript stays resident as the user moves between the different "UI Pages", so the JavaScript can have variables for keeping the state you are asking about. The actual UI navigation from "page" to "page" is usually done by hiding and revealing DIVs.
Hence your WebService call results will be delivered (asynchronously) to some JavaScript function you define, and in the meantime your code can hide the login page and reveal the next page as required. The login data being held in JavaScript variabes.
All of this is simplified by using a framework such as AngularJS which abstracts the messy details of hiding and revealing and dealing with asynch delivery.

Create and use global view in C# WP8 XAML

I was trying to digg something on this topic before, but have no luck. What I'm trying to achieve is pretty simple, but seems to be hard to achieve :-)
I have a WP8 app (C# XAML) and I need to implement global messages (something like toasts) which could be displayed across whole application no matter of current navigation processes. Such toast message(s) should be displayed even while user is navigating between pages. To use the built in toasts is not a way (in case some other solution exists) since I'm possibly in need to have more than one message displayed at the same time (each one is independent of another) and should disappear after specified period of time.
So, my question is. Is there any way how to implement and use some kind of global view instance which sits above all pages and can be called from any page?
All I found until now is the possible ability to use PhoneApplicationFrame, but I would like rather avoid that if possible. I'm still unsure if this is even the way it can be done, but I suppose so. Do you have any alternatives or assurance this is possible and only way to achieve this goal?
Thank you all for your time and answers.
You can have UerControl for the Functionality you are looking for. It is Control that has its own Seprate Xaml and cs file. You can call it from any page into your Project. UserControl provides the base class for defining a new control that encapsulates related existing controls and provides its own logic. You have a XAML file and C# class file for a user control. The class file extends the UserControl class and adds additional behaviours and properties. The XAML file encapsulates the composing controls, the styles, the templates, animations and whatever necessary to form the UI. Since it is a just composition, it is really easy to create. for more Reference you can go here Why and how to create a User Control in Windows Phone
I have ended up rolling my own custom navigation using a single master page. As such any global controls are instantiated once at startup. Navigations are called from my viewmodels and result in usercontrols being removed and added to the visual tree as necessary (using transition animations to give the impression of page navigation) This works but im not sure whether it is best practice and would appreciate some opinions and comments on this. Certainly it solves the problem of global views described.

Synchronous state provider?

I'm creating a TabPanel component where the specific tabs are created/defined by user configuration.
So far, I've taken the approach of just using a stateful component to keep the users preferences of which tabs to show and been using the simple Ext.state.LocalStorageProvider to keep the users preferences.
But I actually ultimately want to store the user preferences/config in my database, so I created my own StateProvider that will store/load the prefs via AJAX calls.
The problem I've encountered is that my tab panel is loaded far sooner than the AJAX calls inside my StateProvider return, so what I need is some way to do a synchronous ajax call (which I know is morally wrong) or to somehow delay my tab panel from rendering until the preferences in my state provider are finished loading.
Anyone had a similar issue? It might be as simple as sleeping one thread for a while, but I know that's not nice either.
I think this is a bit old, but as I have found a similar problem...
Instead of sleeping, you can load the tab panel on the listener of your StateProvider ajax calls. So when your call returns, the tab will still not be loaded.

Creating a Logon Screen

What is the best way to make password/logon screen? Iread somewhere that it is better to use a popup control. If so where exactly do I need to create it, in App.xaml?
There are number of things you need to consider while implementing a login screen for your Windows Phone 7 application. Here is a sample that can give you an idea of how to get started, if you haven't. One of the important aspects of a login screen is its appearance on the "back stack" - the list that grows while you are within your application, each item in this list is accessible through the "back" button. Ideally, you wouldn't want the user to press the back button and view the login screen. In other words, the login screen should never be in the "back stack". Therefore, it is probably best to implement the login screen as popup, see Peter Torr's post discussing this.
Peter Torr published an article on "Places" which could help you design your application with the login screen.
Regarding implementation of a popup, I posted a simple example in the Answer linked below which you can check out. In this case it implements a context menu.. you can populate the popup with whichever contents make sense for your login screen.
http://social.msdn.microsoft.com/Forums/en-US/windowsphone7series/thread/e6d2a444-91d9-4d69-937e-689b24c36c09
I recommend reading the two links Indyfromoz has hooked you up with for how to handle a login screen wrt the navigation service. This are the most relevant and the current posts on the topic of handling login screens and the like wrt the navigation service.