Search in sources :

Example 26 with LbryUri

use of com.odysee.app.utils.LbryUri in project odysee-android by OdyseeTeam.

the class Subscription method fromClaim.

public static Subscription fromClaim(Claim claim) {
    String u = claim.getPermanentUrl();
    LbryUri lbryUri = LbryUri.tryParse(u);
    if (lbryUri != null)
        u = lbryUri.toString();
    return new Subscription(claim.getName(), u, false);
}
Also used : LbryUri(com.odysee.app.utils.LbryUri)

Example 27 with LbryUri

use of com.odysee.app.utils.LbryUri in project odysee-android by OdyseeTeam.

the class Claim method fromViewHistory.

public static Claim fromViewHistory(ViewHistory viewHistory) {
    // only for stream claims
    Claim claim = new Claim();
    claim.setClaimId(viewHistory.getClaimId());
    claim.setName(viewHistory.getClaimName());
    claim.setValueType(TYPE_STREAM);
    claim.setPermanentUrl(viewHistory.getUri().toString());
    claim.setDevice(viewHistory.getDevice());
    claim.setConfirmations(1);
    StreamMetadata value = new StreamMetadata();
    value.setTitle(viewHistory.getTitle());
    value.setReleaseTime(viewHistory.getReleaseTime());
    if (!Helper.isNullOrEmpty(viewHistory.getThumbnailUrl())) {
        Resource thumbnail = new Resource();
        thumbnail.setUrl(viewHistory.getThumbnailUrl());
        value.setThumbnail(thumbnail);
    }
    if (viewHistory.getCost() != null && viewHistory.getCost().doubleValue() > 0) {
        Fee fee = new Fee();
        fee.setAmount(String.valueOf(viewHistory.getCost().doubleValue()));
        fee.setCurrency(viewHistory.getCurrency());
        value.setFee(fee);
    }
    claim.setValue(value);
    if (!Helper.isNullOrEmpty(viewHistory.getPublisherClaimId())) {
        Claim signingChannel = new Claim();
        signingChannel.setClaimId(viewHistory.getPublisherClaimId());
        signingChannel.setName(viewHistory.getPublisherName());
        LbryUri channelUrl = LbryUri.tryParse(String.format("%s#%s", signingChannel.getName(), signingChannel.getClaimId()));
        signingChannel.setPermanentUrl(channelUrl != null ? channelUrl.toString() : null);
        if (!Helper.isNullOrEmpty(viewHistory.getPublisherTitle())) {
            GenericMetadata channelValue = new GenericMetadata();
            channelValue.setTitle(viewHistory.getPublisherTitle());
            signingChannel.setValue(channelValue);
        }
        claim.setSigningChannel(signingChannel);
    }
    return claim;
}
Also used : LbryUri(com.odysee.app.utils.LbryUri)

Example 28 with LbryUri

use of com.odysee.app.utils.LbryUri in project odysee-android by OdyseeTeam.

the class ClaimCacheKey method fromClaim.

public static ClaimCacheKey fromClaim(Claim claim) {
    ClaimCacheKey key = new ClaimCacheKey();
    key.setClaimId(claim.getClaimId());
    LbryUri claimUrl = !Helper.isNullOrEmpty(claim.getShortUrl()) ? LbryUri.tryParse(claim.getShortUrl()) : LbryUri.tryParse(claim.getPermanentUrl());
    if (claimUrl != null) {
        key.setUrl(claimUrl.toString());
    }
    return key;
}
Also used : LbryUri(com.odysee.app.utils.LbryUri)

Example 29 with LbryUri

use of com.odysee.app.utils.LbryUri in project odysee-android by OdyseeTeam.

the class ClaimCacheKey method fromClaimShortUrl.

public static ClaimCacheKey fromClaimShortUrl(Claim claim) {
    ClaimCacheKey key = new ClaimCacheKey();
    LbryUri url = LbryUri.tryParse(claim.getShortUrl());
    if (url != null) {
        key.setUrl(url.toString());
    }
    return key;
}
Also used : LbryUri(com.odysee.app.utils.LbryUri)

Example 30 with LbryUri

use of com.odysee.app.utils.LbryUri in project odysee-android by OdyseeTeam.

the class PlaylistFragment method onPlaylistLoaded.

private void onPlaylistLoaded(OdyseeCollection collection) {
    currentCollection = collection;
    if (visibilityIcon != null) {
        visibilityIcon.setImageResource(collection.getVisibility() == OdyseeCollection.VISIBILITY_PRIVATE ? R.drawable.ic_private : R.drawable.ic_public);
    }
    Helper.setViewText(textTitle, collection.getName());
    Helper.setViewText(textVideoCount, getResources().getQuantityString(R.plurals.video_count, collection.getItems().size(), collection.getItems().size()));
    // load the claims
    ResolveTask task = new ResolveTask(collection.getItems(), Lbry.API_CONNECTION_STRING, playlistItemsLoading, new ClaimListResultHandler() {

        @Override
        public void onSuccess(List<Claim> claims) {
            // reorder the claims based on the order in the playlist collection, TODO: find a more efficient way to do this
            Map<String, Claim> playlistClaimMap = new LinkedHashMap<>();
            List<String> claimIds = new ArrayList<>();
            List<String> collectionItems = collection.getItems();
            for (int i = 0; i < collectionItems.size(); i++) {
                LbryUri url = LbryUri.tryParse(collectionItems.get(i));
                if (url != null) {
                    claimIds.add(url.getClaimId());
                }
            }
            for (String id : claimIds) {
                for (Claim claim : claims) {
                    if (id.equalsIgnoreCase(claim.getClaimId())) {
                        playlistClaimMap.put(id, claim);
                        break;
                    }
                }
            }
            collection.setClaims(new ArrayList<>(playlistClaimMap.values()));
            adapter = new ClaimListAdapter(collection.getClaims(), ClaimListAdapter.STYLE_SMALL_LIST, getContext());
            adapter.setListener(new ClaimListAdapter.ClaimListItemListener() {

                @Override
                public void onClaimClicked(Claim claim, int position) {
                    Context context = getContext();
                    if (context instanceof MainActivity) {
                        ((MainActivity) context).openPrivatePlaylist(collection, claim, position);
                    }
                }
            });
            if (playlistList != null) {
                playlistList.setAdapter(adapter);
            }
        }

        @Override
        public void onError(Exception error) {
            // pass
            Context context = getContext();
            if (context instanceof MainActivity) {
                ((MainActivity) context).showError(getString(R.string.could_not_load_playlist));
            }
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : Context(android.content.Context) ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) ArrayList(java.util.ArrayList) MainActivity(com.odysee.app.MainActivity) ClaimListAdapter(com.odysee.app.adapter.ClaimListAdapter) SQLiteException(android.database.sqlite.SQLiteException) ArrayList(java.util.ArrayList) List(java.util.List) LbryUri(com.odysee.app.utils.LbryUri) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Claim(com.odysee.app.model.Claim) ResolveTask(com.odysee.app.tasks.claim.ResolveTask)

Aggregations

LbryUri (com.odysee.app.utils.LbryUri)30 LbryUriException (com.odysee.app.exceptions.LbryUriException)10 ArrayList (java.util.ArrayList)10 JSONException (org.json.JSONException)9 Subscription (com.odysee.app.model.lbryinc.Subscription)8 ApiCallException (com.odysee.app.exceptions.ApiCallException)7 Claim (com.odysee.app.model.Claim)7 JSONObject (org.json.JSONObject)7 SQLiteException (android.database.sqlite.SQLiteException)6 MainActivity (com.odysee.app.MainActivity)6 LbryioRequestException (com.odysee.app.exceptions.LbryioRequestException)6 LbryioResponseException (com.odysee.app.exceptions.LbryioResponseException)6 ExecutionException (java.util.concurrent.ExecutionException)6 SuppressLint (android.annotation.SuppressLint)4 Context (android.content.Context)4 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 Tag (com.odysee.app.model.Tag)4 HashMap (java.util.HashMap)4 AccountManager (android.accounts.AccountManager)3 View (android.view.View)3