Search in sources :

Example 6 with Claim

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;
}
Also used : OkHttpClient(okhttp3.OkHttpClient) ArrayList(java.util.ArrayList) Request(okhttp3.Request) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) LbryResponseException(com.odysee.app.exceptions.LbryResponseException) IOException(java.io.IOException) Uri(android.net.Uri) LbryRequestException(com.odysee.app.exceptions.LbryRequestException) ResponseBody(okhttp3.ResponseBody) Response(okhttp3.Response) Claim(com.odysee.app.model.Claim)

Example 7 with Claim

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);
}
Also used : Claim(com.odysee.app.model.Claim)

Example 8 with Claim

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;
}
Also used : ArrayList(java.util.ArrayList) Claim(com.odysee.app.model.Claim)

Example 9 with Claim

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();
        }
    }
}
Also used : Claim(com.odysee.app.model.Claim)

Example 10 with Claim

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);
}
Also used : ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) ArrayList(java.util.ArrayList) ClaimListTask(com.odysee.app.tasks.claim.ClaimListTask) Claim(com.odysee.app.model.Claim)

Aggregations

Claim (com.odysee.app.model.Claim)133 Context (android.content.Context)51 MainActivity (com.odysee.app.MainActivity)44 JSONException (org.json.JSONException)42 View (android.view.View)41 TextView (android.widget.TextView)37 RecyclerView (androidx.recyclerview.widget.RecyclerView)36 ApiCallException (com.odysee.app.exceptions.ApiCallException)36 ArrayList (java.util.ArrayList)32 ImageView (android.widget.ImageView)31 AdapterView (android.widget.AdapterView)29 NestedScrollView (androidx.core.widget.NestedScrollView)28 ClaimListResultHandler (com.odysee.app.tasks.claim.ClaimListResultHandler)26 JSONObject (org.json.JSONObject)26 ExecutionException (java.util.concurrent.ExecutionException)25 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)24 LbryUriException (com.odysee.app.exceptions.LbryUriException)24 SolidIconView (com.odysee.app.ui.controls.SolidIconView)24 WebView (android.webkit.WebView)23 PhotoView (com.github.chrisbanes.photoview.PhotoView)23