use of com.odysee.app.exceptions.LbryioRequestException in project odysee-android by OdyseeTeam.
the class FetchRewardsSupplier method get.
@Override
public List<Reward> get() {
List<Reward> rewards = new ArrayList<>();
try {
JSONArray results = (JSONArray) Lbryio.parseResponse(Lbryio.call("reward", "list", options, null));
rewards = new ArrayList<>();
if (results != null) {
for (int i = 0; i < results.length(); i++) {
rewards.add(Reward.fromJSONObject(results.getJSONObject(i)));
}
}
} catch (LbryioResponseException | JSONException | LbryioRequestException e) {
e.printStackTrace();
}
return rewards;
}
use of com.odysee.app.exceptions.LbryioRequestException in project odysee-android by OdyseeTeam.
the class NotificationListSupplier method get.
@Override
public List<LbryNotification> get() {
List<LbryNotification> notifications = new ArrayList<>();
try {
JSONArray array = (JSONArray) Lbryio.parseResponse(Lbryio.call("notification", "list", options, null));
if (array != null) {
for (int i = 0; i < array.length(); i++) {
JSONObject item = array.getJSONObject(i);
if (item.has("notification_parameters")) {
LbryNotification notification = new LbryNotification();
JSONObject notificationParams = item.getJSONObject("notification_parameters");
if (notificationParams.has("device")) {
JSONObject device = notificationParams.getJSONObject("device");
notification.setTitle(Helper.getJSONString("title", null, device));
notification.setDescription(Helper.getJSONString("text", null, device));
notification.setTargetUrl(Helper.getJSONString("target", null, device));
}
if (notificationParams.has("dynamic") && !notificationParams.isNull("dynamic")) {
JSONObject dynamic = notificationParams.getJSONObject("dynamic");
if (dynamic.has("comment_author") || dynamic.has("channel_thumbnail")) {
String url = null;
if (dynamic.has("comment_author"))
url = Helper.getJSONString("comment_author", null, dynamic);
else if (dynamic.has("channel_thumbnail"))
url = Helper.getJSONString("channel_thumbnail", null, dynamic);
notification.setAuthorThumbnailUrl(url);
}
if (dynamic.has("channelURI")) {
String channelUrl = Helper.getJSONString("channelURI", null, dynamic);
if (!Helper.isNullOrEmpty(channelUrl)) {
notification.setTargetUrl(channelUrl);
}
}
if (dynamic.has("claim_thumbnail")) {
String claimThumbnailUrl = Helper.getJSONString("claim_thumbnail", null, dynamic);
if (!Helper.isNullOrEmpty(claimThumbnailUrl)) {
notification.setClaimThumbnailUrl(claimThumbnailUrl);
}
}
if (dynamic.has("hash") && "comment".equalsIgnoreCase(Helper.getJSONString("notification_rule", null, item))) {
notification.setTargetUrl(String.format("%s?comment_hash=%s", notification.getTargetUrl(), dynamic.getString("hash")));
}
}
notification.setRule(Helper.getJSONString("notification_rule", null, item));
notification.setRemoteId(Helper.getJSONLong("id", 0, item));
notification.setRead(Helper.getJSONBoolean("is_read", false, item));
notification.setSeen(Helper.getJSONBoolean("is_seen", false, item));
try {
SimpleDateFormat dateFormat = new SimpleDateFormat(Helper.ISO_DATE_FORMAT_JSON, Locale.US);
notification.setTimestamp(dateFormat.parse(Helper.getJSONString("created_at", dateFormat.format(new Date()), item)));
} catch (ParseException ex) {
notification.setTimestamp(new Date());
}
if (notification.getRemoteId() > 0 && !Helper.isNullOrEmpty(notification.getDescription())) {
notifications.add(notification);
}
}
}
}
} catch (ClassCastException | LbryioRequestException | LbryioResponseException | JSONException | IllegalStateException ex) {
ex.printStackTrace();
return null;
}
return notifications;
}
use of com.odysee.app.exceptions.LbryioRequestException in project odysee-android by OdyseeTeam.
the class FetchInviteStatusTask method doInBackground.
protected List<Invitee> doInBackground(Void... params) {
List<Invitee> invitees = null;
try {
JSONObject status = (JSONObject) Lbryio.parseResponse(Lbryio.call("user", "invite_status", null, null));
JSONArray inviteesArray = status.getJSONArray("invitees");
invitees = new ArrayList<>();
for (int i = 0; i < inviteesArray.length(); i++) {
JSONObject inviteeObject = inviteesArray.getJSONObject(i);
Invitee invitee = new Invitee();
invitee.setEmail(Helper.getJSONString("email", null, inviteeObject));
invitee.setInviteRewardClaimable(Helper.getJSONBoolean("invite_reward_claimable", false, inviteeObject));
invitee.setInviteRewardClaimed(Helper.getJSONBoolean("invite_reward_claimed", false, inviteeObject));
if (!Helper.isNullOrEmpty(invitee.getEmail())) {
invitees.add(invitee);
}
}
} catch (ClassCastException | LbryioRequestException | LbryioResponseException | JSONException ex) {
error = ex;
}
return invitees;
}
use of com.odysee.app.exceptions.LbryioRequestException in project odysee-android by OdyseeTeam.
the class FileViewFragment method logFileView.
private void logFileView(String url, long timeToStart) {
Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
if (actualClaim != null) {
String authToken = Lbryio.AUTH_TOKEN;
Map<String, String> options = new HashMap<>();
options.put("uri", url);
options.put("claim_id", actualClaim.getClaimId());
options.put("outpoint", String.format("%s:%d", actualClaim.getTxid(), actualClaim.getNout()));
if (timeToStart > 0) {
options.put("time_to_start", String.valueOf(timeToStart));
}
if (!Helper.isNullOrEmpty(authToken)) {
options.put("auth_token", authToken);
}
Activity activity = getActivity();
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
Supplier<Boolean> s = new Supplier<Boolean>() {
@Override
public Boolean get() {
try {
Lbryio.call("file", "view", options, null).close();
return true;
} catch (LbryioRequestException | LbryioResponseException ex) {
return false;
}
}
};
CompletableFuture<Boolean> cf = CompletableFuture.supplyAsync(s);
cf.whenComplete((result, ex) -> {
if (result) {
if (activity != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
claimEligibleRewards();
}
});
}
if (ex != null) {
if (activity != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
((MainActivity) activity).showError(ex.getMessage());
}
});
}
}
}
});
} else {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
Lbryio.call("file", "view", options, null).close();
if (activity != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
claimEligibleRewards();
}
});
}
} catch (LbryioRequestException | LbryioResponseException ex) {
if (activity != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
((MainActivity) activity).showError(ex.getMessage());
}
});
}
}
}
});
t.start();
}
}
}
use of com.odysee.app.exceptions.LbryioRequestException in project odysee-android by OdyseeTeam.
the class UserExistsWithPassword method call.
@Override
public Boolean call() throws Exception {
Map<String, String> options = new HashMap<>();
options.put("email", email);
try {
Response response = Lbryio.call("user", "exists", options, Helper.METHOD_POST, ctx);
if (response.isSuccessful()) {
ResponseBody responseBody = response.body();
if (responseBody != null) {
String responseString = responseBody.string();
response.close();
JSONObject jsonData = new JSONObject(responseString);
if (jsonData.has("data"))
return (jsonData.getJSONObject("data").getBoolean("has_password"));
} else {
response.close();
}
}
return false;
} catch (LbryioRequestException | LbryioResponseException e) {
Log.e(TAG, e.toString());
return false;
}
}
Aggregations