Retrieved data and stored in local database but while trying to pull relation from the local database I get empty list which indicates that the relation data is not pinned to the local database.
public void retrieveThreadListStoreInDB()
{
ParseQuery<ParseObject> query = ParseQuery.getQuery("Threads");
query.include("postedBy");
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> list, ParseException e) {
if(e == null)
{
// Query is successful now lets load data from parse
ParseObject.pinAllInBackground((List<ParseObject>) list, new SaveCallback() {
#Override
public void done(ParseException e) {
if(e == null)
{
if(!isFinishing())
{
// TODO : Notify to refresh data
}
}
else
{
Log.d("DEBUG","ERROR PINNING DATA WITH EXCEPTION : "+e);
}
}
});
}
}
});
So how should I pin "relation" data to the local database ???
What is the best way to read comments which is a relation. shall I store them in local datastore or pull data in the background ??
make sure you enableLocalDatastore store in application class Parse.enableLocalDatastore(getApplicationContext());
Parse local data store will not work with cache policy. We can access relational data like below
private void getParseData() {
if (parseObjectId != null) {
mApp.show_PDialog(context, "Loading..");
ParseQuery<ParseObject> parseQuery = new ParseQuery<>("Profile");
parseQuery.getInBackground(parseObjectId, new GetCallback<ParseObject>() {
#Override
public void done(ParseObject parseObject, ParseException e) {
if (e == null) {
try {
newName = parseObject.getString("name");
newGender = parseObject.getString("gender");
newDOB.setTime(parseObject.getDate("dob"));
newTOB.setTime(parseObject.getDate("tob"));
newCurrentLocation = parseObject.getParseObject("currentLocation");
newPOB = parseObject.getParseObject("placeOfBirth");
if (newName != null) {
displayName.setText(newName);
}
if (newGender != null) {
gender.setText(newGender);
}
if (newDOB != null) {
DateFormat df = new SimpleDateFormat("MMM dd, yyyy", Locale.getDefault());
df.setTimeZone(TimeZone.getTimeZone("UTC"));
String subdateStr = df.format(newDOB.getTime());
datePicker.setText(subdateStr);
}
if (newTOB != null) {
DateFormat df = new SimpleDateFormat("hh:mm a", Locale.getDefault());
df.setTimeZone(TimeZone.getTimeZone("UTC"));
String subdateStr = df.format(newTOB.getTime());
timepicker.setText(subdateStr);
}
if (newPOB != null) {
placeOfBirth.setText(newPOB.fetchIfNeeded().getString("name")
+ ", " + newPOB.fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getString("name") + ", " + newPOB.getParseObject("Parent").fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getString("name"));
}
if (newCurrentLocation != null) {
currentLocation.setText(newCurrentLocation.fetchIfNeeded().getString("name")
+ ", " + newCurrentLocation.fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getString("name") + ", " + newCurrentLocation.fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getString("name"));
}
} catch (ParseException e1) {
e1.printStackTrace();
}
} else {
e.printStackTrace();
}
mApp.dialog.dismiss();
}
});
} else {
getActivity().finish();
}
}
Related
Currently i have 2 users:
Tester1 and AnotherTester
I've been trying to create a public group channel using my Tester1
but whenever i try to create one.
It's not showing in my list using AnotherTester
Here is my code in creating public group channel
GroupChannelParams params = new GroupChannelParams()
.setPublic(true)
.setDiscoverable(true)
.setEphemeral(false)
// .addUserIds(users)
.setDistinct(false)
.setName(channelName);
GroupChannel.createChannel(params, new GroupChannel.GroupChannelCreateHandler() {
#Override
public void onResult(GroupChannel groupChannel, SendBirdException e) {
if (e != null) { // Error.
Toast.makeText(context, "" + e.getMessage(), Toast.LENGTH_SHORT).show();
Logs.logError(e.getMessage());
retrySendConnection(context, String.valueOf(e.getCode()), e.getMessage());
return;
} else {
// inviteUser(groupChannel);
Logs.logData(groupChannel.getUrl());
Intent i = new Intent(MainActivity.this, channelChatActivity.class);
i.putExtra("channelUrl", groupChannel.getUrl());
startActivity(i);
}
}
});
So Tester1 is the one that created a public group channel
but when i switch to AnotherTester, it doesn't show the public group channel.
Here is my code in retrieving AnotherTester channels
GroupChannelListQuery channelListQuery1 = GroupChannel.createMyGroupChannelListQuery();
channelListQuery1.setIncludeEmpty(true);
channelListQuery1.next(new GroupChannelListQuery.GroupChannelListQueryResultHandler() {
#Override
public void onResult(List<GroupChannel> list, SendBirdException e) {
if (e != null) {
Logs.logError(e.getMessage());// Error.
return;
} else {
groupChannelList.addAll(list);
groupChannelAdapter = new groupChannelAdapter(context, groupChannelList);
initializeRecyclerView(channelAdapter);
}
}
});
i hope you can help me.
You need to do atleast one message in that , then it will show to another user. Please try once to send one message.
Please try this code :-
private void createGroupChannel(List<String> userIds, boolean distinct, final String toID) {
GroupChannel.createChannelWithUserIds(userIds, distinct, "tsg-chat-" + SessionUtils.getCurrentMemberId(this) + "-" + toID, "", "", new GroupChannel.GroupChannelCreateHandler() {
#Override
public void onResult(GroupChannel groupChannel, SendBirdException e) {
if (e != null) {
// Error!
return;
}
}
});
}
I had integrated quickblox chat in my application and want to maintain user online and offline status and tried following options.
1) as described in doc i had followed this link https://quickblox.com/developers/SimpleSample-users-android#Online.5COffline_status but one issue is there that it not give clarity about user online status
2) used Ping Manager: https://quickblox.com/developers/Android_XMPP_Chat_Sample#Ping_a_user
but it always give QBResponseException
3) QBRoaster: this option is not suitable as requirement.
[note : I am using quickblox version 3.3.1]
I have implemented QBPingManager as following
public void checkUserOnlineStatus(String mOpponentName) {
QBChatService.getInstance().getPingManager().setPingInterval(1);
Performer<QBUser> qbUser = QBUsers.getUserByLogin(mOpponentName);
qbUser.performAsync(new QBEntityCallback<QBUser>() {
#Override
public void onSuccess(QBUser qbUser, Bundle bundle) {
final int mOpponentUserId = qbUser.getId();
final QBPingManager pingManager = QBChatService.getInstance().getPingManager();
pingManager.pingServer(new QBEntityCallback<Void>() {
#Override
public void onSuccess(Void aVoid, Bundle bundle) {
pingManager.pingUser(mOpponentUserId, new QBEntityCallback<Void>() {
#Override
public void onSuccess(Void aVoid, Bundle bundle) {
Timber.tag(TAG).w("Opponent User is online ");
}
#Override
public void onError(QBResponseException e) {
Timber.tag(TAG).e("message(ping user): " + e.getMessage() + "\n localized message: " + e.getLocalizedMessage());
e.printStackTrace();
}
});
}
#Override
public void onError(QBResponseException e) {
Timber.tag(TAG).e("message (ping server): " + e.getMessage() + "\n localized message: " + e.getLocalizedMessage());
}
});
}
#Override
public void onError(QBResponseException e) {
Timber.tag(TAG).e("Error : " + e.getMessage() + "\n Message : " + e.getLocalizedMessage());
}
});
}
any help is appreciated thank you.
Here we will find online/offline status with last seen time/date :-
To get online/offline status of user you need to send and has to confirm subscription request
// to confirm subscription request
QBSubscriptionListener subscriptionListener = new QBSubscriptionListener() {
#Override
public void subscriptionRequested(int userId) {
try {
if (chatRoster != null)
chatRoster.confirmSubscription(userId);
} catch (SmackException.NotConnectedException e) {
} catch (SmackException.NotLoggedInException e) {
} catch (XMPPException e) {
} catch (SmackException.NoResponseException e) {
}
}
};
chatRoster = QBChatService.getInstance().getRoster(QBRoster.SubscriptionMode.mutual, subscriptionListener);
// to send subscription request
try {
chatRoster.subscribe(qbChatDialog.getRecipientId()); //getRecipientId is Opponent UserID
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
Send presence whenever user comes online/offline
QBPresence presence = new QBPresence(QBPresence.Type.online, "I am now available", 1, QBPresence.Mode.available);
try {
chatRoster.sendPresence(presence);
} catch (SmackException.NotConnectedException e) {
} catch (Exception e) {
e.printStackTrace();
}
Get Presence of opponent user
QBPresence presence = chatRoster.getPresence(qbChatDialog.getRecipientId());
if (presence.getType() == QBPresence.Type.online) {
//online
}else{
//offline
}
Identify when user's online status has been changed
QBRosterListener rosterListener = new QBRosterListener() {
#Override
public void entriesDeleted(Collection<Integer> userIds) {
}
#Override
public void entriesAdded(Collection<Integer> userIds) {
}
#Override
public void entriesUpdated(Collection<Integer> userIds) {
}
#Override
public void presenceChanged(QBPresence presence1) {
try {
int userid = presence1.getUserId();
int recid = qbChatDialog.getRecipientId();//opponent user id
if (userid == recid) {
if (presence1.getType() == QBPresence.Type.online)
status.setText(getResources().getString(R.string.online));
else {
status.setText("");
String lastseen = getlastseen();
if (lastseen.length() > 0) {
status.setText(lastseen);
}
}
} else {
}
} catch (Exception e) {
}
}
};
To get Last Seen of offline user
private String getlastseen() {
String lastseen = "";
String appendstring = "";
try {
long lastUserActivity = QBChatService.getInstance().getLastUserActivity(qbChatDialog.getRecipientId()); //returns last activity in seconds or error
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.SECOND, -(int) lastUserActivity);
String format = "dd MMM yyyy hh:mm a";
if (DateUtils.isToday(calendar.getTimeInMillis())) {
format = "hh:mm a";
appendstring = ChatActivity.this.getResources().getString(R.string.today) + ",";
} else if (isyesterday(calendar.getTimeInMillis())) {
format = "hh:mm a";
appendstring = ChatActivity.this.getResources().getString(R.string.yesterday) + ",";
} else if (Calendar.YEAR == Calendar.getInstance().YEAR)
format = "dd MMM hh:mm aa";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
lastseen = simpleDateFormat.format(calendar.getTime());
} catch (XMPPException.XMPPErrorException | SmackException.NotConnectedException e) {
} catch (Exception e) {
e.printStackTrace();
}
return appendstring + lastseen;
}
You can use new feature of QuickBlox Android SDK since version 3.3.3 which called 'last activity'. You can call QBChatService.getInstance().getLastUserActivity(userId); As result you will get:
- 0 if opponent online or
- seconds ago opponent was online or
- error if user newer logged to chat.
public void pictureQuery() {
friendsPic = new ArrayList<>();
for (int i = 0; i < friendsList.length(); i++) {
ParseQuery parseQuery = ParseQuery.getQuery("Data");
parseQuery.whereEqualTo("firstName", "John");
//parseQuery.whereEqualTo("userId",friendsID.get(i));
parseQuery.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
if (objects.size() > 0) {
String link = objects.get(0).get("picUrl").toString();
Bitmap bitmap = null;
try {
bitmap = task.execute(link).get();
friendsPic.add(bitmap);
} catch (Exception e1) {
e1.printStackTrace();
}
Log.i("FDA, done", friendsPic.toString());
} else {
Log.i("FD", "0002");
}
} else {
e.printStackTrace();
}
}
});
}
}
Hi guys,
I am trying to retrieve picture URL from parse server (stored as a string), originally I was trying to make a query using the Id, but also tried to hard code it using:
parseQuery.whereEqualTo("firstName", "John");
It always seems to go to the else statement of object.size() > 0 i.e.
Log.i("FD", "0002");
I think i've checked everything including:
size of friendsList ( for the for loop )
spelling, made sure that "Data", "firstName" and "John" are the same on Parse Server
The value of friendsID.get(i)
Tried to use findFirstInBackground instead (same issue)
I have also compared it with my other code for different data ( that works ) :
ParseQuery parseQuery = ParseQuery.getQuery("SportData");
parseQuery.whereEqualTo("id", mApp.getId());
parseQuery.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
if (objects.size() > 0) {
saveSportData(objects.get(0), false);
} else if (objects.size() < 1) {
saveSportData(null, true);
}
} else {
e.printStackTrace();
}
}
});
Any idea what am I doing wrong, or what may be causing it ?
Thanks a lot.
I have an application that insert & retrieve data from parse. but i need to insert multiple entry in a single task under one id. I can do that using loop but is there anyway to insert multiple entry at once? For an example: I have an user id "ABC" and this user entry some data like : data-1(abc, Ny, water), data-2(xyz,bristol, air), data-3( qwe, ca, fire). how can i insert all 3 data under ABC id altogether into parse?
ParseObject userOrder = new ParseObject("tableName");
userOrder.put("userId", userId);
userOrder.put("data",data);
userOrder.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null){
//successfully data inserted
}
else {
//there is an error in data insertion }
}
});
Yes you can do that using saveAllinBackground
final List<ParseObject> parseTaskObjects = new ArrayList<>();
for (TaskResponse taskResponse : ((MainApplication)(getApplicationContext())).getTaskResponses()) {
ParseObject parse_assignment = new ParseObject("TaskResponse");
parse_assignment.put("TaskID", list.get(((MainApplication) (getApplicationContext())).getTaskResponses().indexOf(taskResponse)));
parse_assignment.put("AssignmentId", assignment);
if (taskResponse.getTaskType() == TaskType.LOCATION.ordinal()) {
parse_assignment.put("LocationResp", getParseGeoPointFromLatLng(taskResponse.getLocationResponse().latitude, taskResponse.getLocationResponse().longitude));
} else if (taskResponse.getTaskType() == TaskType.PICTURE.ordinal()) {
ParseFile file = new ParseFile("image.jpg", taskResponse.getPictureResponse());
file.saveInBackground();
parse_assignment.put("PicResp", file);
} else if (taskResponse.getTaskType() == TaskType.TAGS.ordinal()) {
parse_assignment.put("TagResp", taskResponse.getTagResponse());
} else if (taskResponse.getTaskType() == TaskType.TEXT.ordinal()) {
parse_assignment.put("TextResp", taskResponse.getTextResponse());
} else if (taskResponse.getTaskType() == TaskType.NUMBER.ordinal()) {
parse_assignment.put("NumResp", taskResponse.getNumberResponse());
}
parseTaskObjects.add(parse_assignment);
}
ParseObject.saveAllInBackground(parseTaskObjects, new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Toast.makeText(Stint_task.this, "Stint Tasks Completed Successfully", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(Stint_task.this, "Stint Failed", Toast.LENGTH_SHORT).show();
}
}
});
I am trying to parse a boolean value after using it with parseObject, but I cannot parse it?
Here is my code:
ParseQuery<ParseObject> query = ParseQuery.getQuery("SmsTable");
query.whereEqualTo("deviceId", android_id);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, com.parse.ParseException e) {
if (e == null) {
for (ParseObject smsObject : objects) {
if (smsObject!=null) {
Date time = (Date) smsObject.get("date");
myMsg = (String) smsObject.get("message");
usrNum = (String) smsObject.get("phoneNumber");
happend = (boolean) smsObject.get("happend");
result = time;
}
if (result != null) {
if (System.currentTimeMillis() >= result.getTime() && happend == false) {
// count++;
if (usrNum != null && myMsg != null) {
Log.d("message", myMsg);
Log.d("time", String.valueOf(result));
sendMsg2(myMsg, usrNum);
smsObject.put("happend", true);
}
}
}
}
}
}
});
You should call default methods of ParseObject to retrieve data instead of parsing :
ParseQuery<ParseObject> query = ParseQuery.getQuery("SmsTable");
query.whereEqualTo("deviceId", android_id);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, com.parse.ParseException e) {
if (e == null) {
for (ParseObject smsObject : objects) {
if (smsObject!=null) {
Date time = smsObject.getDate("date");
myMsg = smsObject.getString("message");
usrNum = smsObject.getString("phoneNumber");
happend = smsObject.getBoolean("happend");
result = time;
}
if (result != null) {
if (System.currentTimeMillis() >= result.getTime() && happend == false) {
// count++;
if (usrNum != null && myMsg != null) {
Log.d("message", myMsg);
Log.d("time", String.valueOf(result));
sendMsg2(myMsg, usrNum);
smsObject.put("happend", true);
}
}
}
}
}
}
});
You can simply use For loop for getting single object of Parse object and can use getBoolean() method for getting boolean value.
public void done(List<ParseObject> objects, com.parse.ParseException e) {
if (e == null) {
for (int i = 0; i < objects.size(); i++) {
happend = objects.get(i).getBoolean("happend");
}
}
}