Search in sources :

Example 11 with ClaimListAdapter

use of com.odysee.app.adapter.ClaimListAdapter in project odysee-android by OdyseeTeam.

the class LibraryFragment method initContentListAdapter.

private void initContentListAdapter(List<Claim> claims) {
    Context context = getContext();
    if (context != null) {
        contentListAdapter = new ClaimListAdapter(claims, context);
        // contentListAdapter.setCanEnterSelectionMode(currentFilter == FILTER_DOWNLOADS);
        contentListAdapter.setCanEnterSelectionMode(true);
        contentListAdapter.setSelectionModeListener(this);
        contentListAdapter.setHideFee(currentFilter != FILTER_PURCHASES);
        contentListAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {

            @Override
            public void onClaimClicked(Claim claim, int position) {
                Context context = getContext();
                if (context instanceof MainActivity) {
                    MainActivity activity = (MainActivity) context;
                    if (claim.getName().startsWith("@")) {
                        activity.openChannelUrl(claim.getPermanentUrl());
                    } else {
                        activity.openFileUrl(claim.getPermanentUrl());
                    }
                }
            }
        });
    }
}
Also used : Context(android.content.Context) MainActivity(com.odysee.app.MainActivity) ClaimListAdapter(com.odysee.app.adapter.ClaimListAdapter) Claim(com.odysee.app.model.Claim)

Example 12 with ClaimListAdapter

use of com.odysee.app.adapter.ClaimListAdapter in project odysee-android by OdyseeTeam.

the class LibraryFragment method initRecentAdapter.

private void initRecentAdapter(List<Claim> claims) {
    Context context = getContext();
    if (context != null) {
        contentListAdapter = new ClaimListAdapter(claims, ClaimListAdapter.STYLE_SMALL_LIST_HORIZONTAL, context);
        // contentListAdapter.setCanEnterSelectionMode(currentFilter == FILTER_DOWNLOADS);
        contentListAdapter.setCanEnterSelectionMode(true);
        contentListAdapter.setSelectionModeListener(this);
        contentListAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {

            @Override
            public void onClaimClicked(Claim claim, int position) {
                Context context = getContext();
                if (context instanceof MainActivity) {
                    MainActivity activity = (MainActivity) context;
                    if (claim.getName().startsWith("@")) {
                        activity.openChannelUrl(claim.getPermanentUrl());
                    } else {
                        activity.openFileUrl(claim.getPermanentUrl());
                    }
                }
            }
        });
    }
}
Also used : Context(android.content.Context) MainActivity(com.odysee.app.MainActivity) ClaimListAdapter(com.odysee.app.adapter.ClaimListAdapter) Claim(com.odysee.app.model.Claim)

Example 13 with ClaimListAdapter

use of com.odysee.app.adapter.ClaimListAdapter 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

ClaimListAdapter (com.odysee.app.adapter.ClaimListAdapter)13 Claim (com.odysee.app.model.Claim)12 Context (android.content.Context)11 MainActivity (com.odysee.app.MainActivity)11 ArrayList (java.util.ArrayList)7 List (java.util.List)7 JSONObject (org.json.JSONObject)6 View (android.view.View)5 RecyclerView (androidx.recyclerview.widget.RecyclerView)5 ClaimSearchResultHandler (com.odysee.app.tasks.claim.ClaimSearchResultHandler)5 ClaimSearchTask (com.odysee.app.tasks.claim.ClaimSearchTask)5 JSONException (org.json.JSONException)5 WebView (android.webkit.WebView)3 AdapterView (android.widget.AdapterView)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 NestedScrollView (androidx.core.widget.NestedScrollView)3 PhotoView (com.github.chrisbanes.photoview.PhotoView)3 PlayerView (com.google.android.exoplayer2.ui.PlayerView)3 ClaimListResultHandler (com.odysee.app.tasks.claim.ClaimListResultHandler)3