kotlin- PaymentSessionConfiguration - android

Hello I am trying to update stripe but when I have to call PaymentSessionConfig my code blocks because the companion of the PaymentSessionConfig class is in private, I cannot modify the class because it is in read only, here is the line :
mPaymentSession = PaymentSession (activity = summaryActivity, config = PaymentSessionConfig)
and the error message I have :
Cannot access 'Companion': it is private in 'PaymentSessionConfig'
Type mismatch.
Required:
PaymentSessionConfig
Found:
PaymentSessionConfig.Companion

Can you share the details of what versions of the SDK you're updating from and to? The migration docs cover a lot of details changes for various versions.
Is it possible you mean to reference some paymentSessionConfig, or what is your config here?
See this example implementation using the PaymentSessionConfig.Builder() (github)

Related

How to get instance in Kotlin with Context.getSystemService(Class)

In Google Android Kotlin documentation,
Every now and then there is a below line present in android documentation that:
Instances of this class must be obtained using Context.getSystemService(Class)
For example:
Instances of this class must be obtained using Context.getSystemService(Class) with the argument AppOpsManager.class or Context.getSystemService(String) with the argument Context.APP_OPS_SERVICE.
Can someone please clarify what this is and how do I create a instance for class AppOpsManager.
Usually we can create instance like:
val use = AppOpsManager()
Please help and explain the above Context.getSystemService().
Thank You.
From Android Developer documentation:
AppOpsManager
API for interacting with "application operation" tracking.
This API is not generally intended for third party application
developers; most features are only available to system applications.
Instances of this class must be obtained using
Context.getSystemService(Class) with the argument
AppOpsManager.class or Context.getSystemService(String) with the
argument Context.APP_OPS_SERVICE.
To create an instance of this class you must use getSystemService from a context instance.
val appOpsManager: AppOpsManager? = getSystemService(Context.APP_OPS_SERVICE) as AppOpsManager?
If your minSdkVersion is 23 then you can use this code instead.
val appOpsManager: AppOpsManager? = getSystemService(AppOpsManager::class.java)
Use the following:
context.getSystemService(AppOpsManager::class.java)
val aom = getSystemService(context, AppOpsManager::class.java)

Is there better way for handle kotlinx serialization?

I use kotlinx.serialization on Kotlin native project, I a defined Super class for my models and all of the models extends from it.
I defined a function to called toJSON() for serialize variables and fields inside model that all of class models have it.
#Serializable
open class Model {
fun toJSON(): String = JSON.stringify(this);
}
And I created a subclass
class Me : Model() {
var name:String = "Jack";
}
but when I invoke JSON.stringify(this), IDE get a Warning to me:
This declaration is experimental and its usage must be marked with '#kotlinx.serialization.ImplicitReflectionSerializer' or '#UseExperimental(kotlinx.serialization.ImplicitReflectionSerializer::class)'
I paid attention and I used #ImplicitReflectionSerializer annotation while not worked.
Where is my problem?
This is discussed here. It's the particular overload you're using which is still experimental. So your options are either to use the other overload (which takes in a serializer) or to use one of the annotations mentioned in the error message. If you look at the answer to the question I linked (and the comments following it), you'll see it talks about using #UseExperimental and where it should be used.

Combining `by lazy` and `object` results in compiler-error "cannot find symbol"

I cannot compile anymore after the update to Kotlin 1.3.0 (works in 1.2.71) when trying to use by lazy and object. This seems to happen only on my project. A demo-project is working fine.
I want to add an interface to a given class and lazy-load its values.
I've created a small example which is not working in my project but working fine in any other:
open class Foo
interface Bar {
val lazyLoadedString : String
}
class Test {
private val foo by lazy {
object : Foo(), Bar {
override val lazyLoadedString = "Demo"
}
}
}
As soon as I combine object and by lazy, it cannot compile anymore and shows the following error. Using each one alone works.
Test.java:9: error: cannot find symbol
private final my.package.Test$foo$2$1 getFoo()
symbol: class Test$foo$2$1
location: package my.package
When looking closer, you'll see that the generated java file shows this error and not the kotlin-code.
Any ideas on this?
It looks like kapt is broken in Kotlin 1.3.0 for this particular kind of code.
In the code above, it was the annotation processor registered by Realm that triggered it, but any other annotation processor would have resulted in the same error.
The issue is being tracked here: https://youtrack.jetbrains.net/issue/KT-28053

MVVM with multiple projects Xamarin

Hellow , i am a student and i am working on a project. It is a Xamarin native project (cross-platform). I Use MVVM. This was working perfect when i was using 1 shared project and my 3other projects (android,iOS,winphone). Now I have different projects for my shared code.
-Appname.Repositories
-Appname.Services
-Appname.Viewmodel
Now the problem is that when i start my app using an constructor in my viewmodel with an interface he is given me the next error :
//Constructor
public LoginViewModel(IMvxMessenger messenger, IUserDataService userDataService) : base(messenger)
{
_userDataService = userDataService;
}
Error:
MvvmCross.Platform.Exceptions.MvxException: Failed to construct and initialize ViewModel for type C_Tracker.Mobile.Domain.ViewModel.LoginViewModel from locator MvxDefaultViewModelLocator - check InnerException for more information
InnerException :
MvvmCross.Platform.Exceptions.MvxIoCResolveException: Failed to resolve parameter for parameter userDataService of type IUserDataService
But when i use a constructor without this interface it is working.
public LoginViewModel(IMvxMessenger messenger) : base(messenger)
{
}
Please help me.
Probably you forgot about Dependencies Injection.
Add to Setup.cs something like this Mvx.RegisterType<IUserDataService, UserDataService>();
For more information about ServiceLocator please check https://github.com/MvvmCross/MvvmCross/wiki/service-location-and-inversion-of-control

invalid 'this' to a Java object in Nativescript Plugin

I am trying to develop a nativescript plugin to perform some functionality with the Azure SDK. The docs for the SDK show below:
So I have added the following function to my plugin:
MobileServiceUser.newUser = function (userId, client) {
var userObject = com.microsoft.windowsazure.mobileservices.authentication.MobileServiceUser(userId); // causing the error
client.setCurrentUser(userObject);
};
UserId is a string.
However, the top line throws the error:
JS: Error: Trying to link invalid 'this' to a Java object
I have a full repo showing the minimal implimentation to create this issue on Github.
I would be really grateful of any suggestions how to fix this.
This answer is a little late but I recently ran into this issue myself. Hopefully this answer helps someone in the future!
The error is a bit plain but if you take a look at the code source, you'll see that it's actually telling you that you cannot link a variable to the Object/Class itself as a reference:
MobileServiceUser.newUser = function (userId, client) {
var userObject = com.microsoft.windowsazure.mobileservices.authentication.MobileServiceUser(userId);
};
When you want to instantiate a class, you need to use the keyword new to signify this action. Without new listed before the class constructor call, the program just sees that you're making a direct link between userObject and the class itself. This should fix your problem:
var userObject = new com.microsoft.windowsazure.mobileservices.authentication.MobileServiceUser(userId);
Cheers
~Px

Categories

Resources