use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class Lighthouse method search.
public static List<Claim> search(String rawQuery, int size, int from, boolean nsfw, String relatedTo) throws LbryRequestException, LbryResponseException {
Uri.Builder uriBuilder = Uri.parse(String.format("%s/search", CONNECTION_STRING)).buildUpon().appendQueryParameter("s", rawQuery).appendQueryParameter("resolve", "true").appendQueryParameter("size", String.valueOf(size)).appendQueryParameter("from", String.valueOf(from));
if (!nsfw) {
uriBuilder.appendQueryParameter("nsfw", String.valueOf(nsfw).toLowerCase());
}
if (!Helper.isNullOrEmpty(relatedTo)) {
uriBuilder.appendQueryParameter("related_to", relatedTo);
}
Map<String, Object> cacheKey = buildSearchOptionsKey(rawQuery, size, from, nsfw, relatedTo);
if (searchCache.containsKey(cacheKey)) {
return searchCache.get(cacheKey);
}
List<Claim> results = new ArrayList<>();
Request request = new Request.Builder().url(uriBuilder.toString()).build();
OkHttpClient client = new OkHttpClient();
ResponseBody responseBody = null;
Response response = null;
try {
response = client.newCall(request).execute();
if (response.code() == 200) {
responseBody = response.body();
if (responseBody != null) {
JSONArray array = new JSONArray(responseBody.string());
for (int i = 0; i < array.length(); i++) {
Claim claim = Claim.fromSearchJSONObject(array.getJSONObject(i));
results.add(claim);
}
}
searchCache.put(cacheKey, results);
} else {
throw new LbryResponseException(response.message());
}
} catch (IOException ex) {
throw new LbryRequestException(String.format("search request for '%s' failed", rawQuery), ex);
} catch (JSONException ex) {
throw new LbryResponseException(String.format("the search response for '%s' could not be parsed", rawQuery), ex);
} finally {
if (responseBody != null) {
response.close();
}
}
return results;
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class Helper method isClaimBlocked.
public static boolean isClaimBlocked(Claim claim) {
if (claim.getSigningChannel() != null) {
Claim signingChannel = claim.getSigningChannel();
String channelOutpoint = String.format("%s:%d", signingChannel.getTxid(), signingChannel.getNout());
if (Lbryio.blockedOutpoints.contains(channelOutpoint)) {
return true;
}
}
String outpoint = String.format("%s:%d", claim.getTxid(), claim.getNout());
return Lbryio.blockedOutpoints.contains(outpoint);
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class Helper method filterClaimsByBlockedChannels.
public static List<Claim> filterClaimsByBlockedChannels(List<Claim> claims, List<LbryUri> blockedChannels) {
List<Claim> filtered = new ArrayList<>();
List<String> blockedChannelClaimIds = new ArrayList<>();
for (LbryUri uri : blockedChannels) {
blockedChannelClaimIds.add(uri.getClaimId());
}
for (Claim claim : claims) {
if (blockedChannelClaimIds.contains(claim.getClaimId()) || (claim.getSigningChannel() != null && blockedChannelClaimIds.contains(claim.getSigningChannel().getClaimId()))) {
continue;
}
filtered.add(claim);
}
return filtered;
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class InvitesFragment method enableChannelSpinner.
private void enableChannelSpinner() {
Helper.setViewEnabled(channelSpinner, true);
Claim selectedClaim = (Claim) channelSpinner.getSelectedItem();
if (selectedClaim != null) {
if (selectedClaim.isPlaceholder()) {
showChannelCreator();
}
}
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class InvitesFragment method fetchChannels.
private void fetchChannels() {
if (Lbry.ownChannels != null && Lbry.ownChannels.size() > 0) {
updateChannelList(Lbry.ownChannels);
return;
}
fetchingChannels = true;
disableChannelSpinner();
ClaimListTask task = new ClaimListTask(Claim.TYPE_CHANNEL, progressLoadingChannels, new ClaimListResultHandler() {
@Override
public void onSuccess(List<Claim> claims) {
Lbry.ownChannels = new ArrayList<>(claims);
updateChannelList(Lbry.ownChannels);
if (Lbry.ownChannels == null || Lbry.ownChannels.size() == 0) {
fetchDefaultInviteLink();
}
enableChannelSpinner();
fetchingChannels = false;
}
@Override
public void onError(Exception error) {
fetchDefaultInviteLink();
enableChannelSpinner();
fetchingChannels = false;
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Aggregations