How to use adapter inside the application in worklight - android

Im new to worklight. Now im started using adapter. Check this link one of my stackoverflow friend have same doubt click this Calling the procedure inside the application. The Adapter im using is SqlAdapter. But in the ibm worklight tutorial they gave example for HttpAdapter and clubing the procedure inside the function. But not for SqlAdapter. If any suggestion kindly let me know. if u want to my source i will ready to provide. Still my research continues

The call from an application to an adapter is the same for all types of adapters.
function getData() {
var invocationData = {
adapter : 'ADAPTER_NAME',
procedure : 'PROCEDURE_NAME',
parameters : []
};
WL.Client.invokeProcedure(invocationData,{
onSuccess : getDataSuccess,
onFailure : getDataFailure,
});
}
For more information check module 6 - Invoking Adapter Procedures from the Client Applications (PDF, 370KB) and the exercise and code sample (ZIP, 53.7KB)

Here i retrieved the values. but its not displaying in html page. this is my code
function wlCommonInit(){
// Common initialization code goes here
WL.Logger.debug("inside the wlcommoninit");
busyIndicator = new WL.BusyIndicator('AppBody');
getData();
}
function loadFeedsSuccess(result){
WL.Logger.debug("Feed retrieve success");
}
function loadFeedsFailure(result){
WL.Logger.error("Feed retrieve failure");
}
function getData() {
var invocationData = {
adapter : 'SqlAdap',
procedure : 'procedure1',
parameters : []
};
WL.Client.invokeProcedure(invocationData,{
onSuccess : loadFeedsSuccess,
onFailure : loadFeedsFailure,
});
}

Related

Android pass variable from Java activity to Kotlin adapter

I don't know why I'm blanking on this... but I've got a java activity which displays comments... and I need to pass the id of the photo that's being commented onto the adapter that gets all of the comments. The adapter is called CommentGrabber:
commentGrabber = new CommentGrabber(this);
...and it's executed like this:
private void requestComment() {
commentGrabber.getComment();
}
The "id" variable of the current photo can be had at any time by getting its intent but I've saved it to a string called "photo_id."
final String photo_id = getIntent().getStringExtra("id");
This is what the adapter side looks like:
fun getComment(String photo_id) {
//this is where the function is handled
}
So I just need to figure out how to get the "photo_id" from my comment activity to "getComment" in the adapter.
I would have the adapter method expect an argument like below:
fun getComment(photo_id : String) {
// from there then pass the photo_id to the service call
}
You would then call it like so:
adapter.getComment(photo_id);
Whenever you want to fetch comments by id.
I hope this makes sense. If you need further clarification, please do not hesitate to ask.

Call with a button a saved number in another page( IONIC, Angular)

Hi I want to call a number which is saved in another page.
I don't know how to explain this well but I put some captures, and the code that I'm trying to use, I just only want to catch the value of the number and put into the button to call.
I'm using ionic framework and angular. I'm very new at this but I want to create an app and I'm stuck with this.
Sorry for my english is not my native language.
Client Detail
Call button
Button page .ts
Detail html page(the first image)
button page html (click) function
import { ICompanyAddress } from './../interfaces/Map';
import { Injectable } from '#angular/core';
#Injectable({
providedIn: 'root'
})
export class SharedDataService {
_phoneNumber: string;
constructor() { }
get phoneNumber(): string {
return this._phoneNumber;
}
set phoneNumber(newValue: string) {
this._phoneNumber = newValue;
}
}
Now You could change access its data from any page and changing its value:
example1 (change phoneNumber from a page)
constructor(private sharedDataService : SharedDataService) {
this.changePhoneNumber()
}
changePhoneNumber(){
this.sharedDataService.phoneNumber = '12345678'
}
example1 (get last phoneNumber changed value in a page)
constructor(private sharedDataService : SharedDataService) {
console.log(this.sharedDataService.phoneNumber)// 12345678
}
For that, you can create services and then store your PhoneNumber in services.
Check this out .I hope it will help you.

How to remove an item from repeated list in Android proto DataStore?

Here is the proto file with the definition for a list of strings.
message MyMessages {
repeated string message = 1;
}
Here is the function for removing a message from the repeated message list.
suspend fun removeMsg(msg : String) {
myMessagesStore.updateData { myMessages ->
val existingMessages = myMessages.toBuilder().messageList;
if (existingMessages.contains(msg)) {
existingMessages.remove(msg)
myMessages.toBuilder().clear().addAllMessage(existingMessages).build()
} else {
myMessages
}
}
}
When the above code runs, it crashed on existingMessages.remove(msg) with the error:
java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableCollection.remove
existingMessages is a MutableList which contains the remove function, why is this crashing on this and what's the proper way to remove an item from a repeated list item in proto DataStore?
Updates:
existingMessages is
/**
* <code>repeated string message = 1;</code>
* #return A list containing the message.
*/
#java.lang.Override
public java.util.List<java.lang.String>
getMessageList() {
return java.util.Collections.unmodifiableList(
instance.getMessageList());
}
It looks like the generated class from proto is making the repeated list unmodfiableList. Then my question is why there isn't a myMessages.toBuilder().removeMessage(newMessage) function from the generated class similar to the addMessage function such as this:
myMessages.toBuilder().addMessage(newMessage)
Could you please post the exact data type of existingMessages.
I am not an expert in proto DataStore, so please correct me incase I am wrong.
As per the exception message, there could be few main reason behind the crash:
The existingMessages is immutable list. As per the exception, we can see that the name of the collection is java.util.Collections$UnmodifiableCollection.
The existingMessages is a custom mutable list, which haven't implemented the #remove function.
To fix this, you can choose one of the following approach based on your guidelines:
Update the type of messageList in Builder class as MutableList for other external classes.
In case you are using custom implementation of list and the #remove is not implemented, please implement it.
In case you can't change the return type of messageList, simply use #filter method to copy and skip the required message as follow:
existingMessages.filter { it != msg }

Android and Firebase Firestore: Wait nested tasks to complete

I think it is a simple problem, I have 3 main collections: collection_A, collection_B and collection_C. The problem is: I need a document "A" of collection_A. The document "A" contains an array attribute "collection_B_uids", after get document "A" I need to get every document of collection_B that is in collection_B_uids, so I did this:
public Task foo() {
return FirebaseFirestore.getInstance().collection("collection_A").document("A").get()
.addOnSuccessListener(docA -> {
List<String> collection_B_uids = docA.get("collection_B_uids");
// ...
for (String uid : collection_B_uids) {
FirebaseFirestore.getInstance().collection("collection_B").document(uid).get()
.addOnSuccessListener(docB -> {
// ...
});
}
});
}
Works fine, but then I need to access some documents of collection_C by another array attribute in every document of collection_B. I want to use the return of foo like that:
foo().addOnSuccessListener(...)
And that final addOnSuccessListener should be executed after all nested tasks are completed. I already use Tasks.whenAllSuccess inside the main Task, but it didn't worked.
My guesses:
a) create a recursive function using 2 listener at time;
b) use continueWithTask or continueWith (prefered);
c) create a global AsyncTask an then use Tasks.await (please, don't).
Ps: I'm not english native

Populate a list in Kotlin with a for loop

It's been a while that I just started to learn how to develop in Kotlin.
There is this thing that I am working on, I am trying to parse a list into another type of list. Basically they are the same thing but with different names. But when I try to populate the new list with the data that I get from the list given as parameter in the function the list only gets populated with the first object.
Here is my function:
fun convertRoomClass(course: List<Course>) : List<Courses> {
lateinit var list : List<Courses>
course.forEach {
val id = it.pathID
val name = it.pathName
val desc = it.pathDescription
val crs : Courses = Courses(id, name!!, desc!!)
list = listOf(crs)
}
return list
}
The error in your code is that you are making a list in every iteration of the loop. You should make the list first and then add every item from the loop to it!
fun convertRoomClass(courses: List<Course>) : List<AnotherCourseClass> {
val newList = mutableListOf<AnotherCourseClass>()
courses.forEach {
newList += AnotherCourseClass(it.pathID, it.pathName, it.pathDescription)
}
return newList
}
A better solution is to use the map function
fun convertRoomClass(courses: List<Course>) = courses.map {
AnotherCourseClass(it.pathID, it. pathName, it.pathDescription)
}
You might be looking for Kotlin Map
Example:
course.map { Courses(it.pathID, it.pathName,it.pathDescription) }
You're getting the list with only on object, cause the function listOf(crs) returns a list of all objects that are passed as a parameters. Saying the same thing in Java you're doing something like this:
for (course: Courses) {
Course course = new Course(...);
List<Course> list = new ArrayList<>();
list.add(course);
return list;
}
As you can see the it created new list with a single object per iteration.
What you're trying to achieve, can be done with operator map{...} which simply transforms every object in the initial list using code passed inside map and returns list of transformed objects
course.map{ Courses(...) }
Also, I've noticed that you're using the !! operator when creating a Courses object. Probably because the Course can have nullable name, while Courses can't. I'm considering this as a bad practice, cause in this case you're saying
Please throw an Exception if the name is null.
I think that a much better approach is to provide an alternative, like:
val name = course.name ?: "default", saying
Please use name or "default" if the name is null.
or skip objects without name, or any other approach that suits your situation.
You could use MutableList instead of List. That enable you to append new element at the end of your list instead of replace the entire list by doing : list = listOf(crs)
So replace the type of your var lateinit var list : List<Courses> by lateinit var list : MutableList<Courses> then replace list = listOf(crs) by list.add(crs)
Hope it helps and have fun :)

Categories

Resources