Created
September 30, 2020 06:09
-
-
Save melikeeroglu/7c8f4ecb02a5d468ed0f7ed567df7782 to your computer and use it in GitHub Desktop.
HiAnimals getAllPhotos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void getAllPhotos(Context mContext) { | |
if (mCloudDBZone == null) { | |
Log.w(Constant.DB_ZONE_WRAPPER, "GET USER DETAIL : CloudDBZone is null, try re-open it"); | |
return; | |
} | |
SharedPreferences pref = mContext.getSharedPreferences("MyPref", mContext.MODE_PRIVATE); | |
String token = pref.getString("token",null); | |
CloudDBZoneTask<CloudDBZoneSnapshot<Photo>> queryTask = mCloudDBZone.executeQuery( | |
CloudDBZoneQuery.where(Photo.class).orderByDesc("id").equalTo("token",token ).limit(1), | |
CloudDBZoneQuery.CloudDBZoneQueryPolicy.POLICY_QUERY_FROM_CLOUD_ONLY); | |
queryTask.addOnSuccessListener(snapshot -> { | |
photoListResult (snapshot); | |
Log.w(Constant.DB_ZONE_WRAPPER, "GET PHOTO LIST : GoResults: "); | |
}).addOnFailureListener(e -> { | |
if (mUiCallBack != null) { | |
mUiCallBack.updateUiOnError("GET PHOTO LIST : Query photo list from cloud failed"); | |
} | |
}); | |
} | |
private void photoListResult (CloudDBZoneSnapshot<Photo> snapshot) { | |
CloudDBZoneObjectList<Photo> photoCursor = snapshot.getSnapshotObjects(); | |
List<Photo> photoList = new ArrayList<>(); | |
try { | |
while (photoCursor.hasNext()) { | |
Photo photo = photoCursor.next(); | |
photoList.add(photo); | |
Log.w(Constant.DB_ZONE_WRAPPER, "USER DETAIL RESULT : processQueryResult: "); | |
} | |
} catch (AGConnectCloudDBException e) { | |
Log.w(Constant.DB_ZONE_WRAPPER, "USER DETAIL RESULT : processQueryResult: " + e.getMessage()); | |
} | |
snapshot.release(); | |
if (mUiCallBack != null) { | |
mUiCallBack.onAddOrQueryPhoto(photoList); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment