Search in sources :

Example 46 with MainActivity

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

the class ChannelFragment method renderClaim.

private void renderClaim() {
    if (claim == null) {
        renderNothingAtLocation();
        return;
    }
    loadSubCount();
    checkIsFollowing();
    layoutLoadingState.setVisibility(View.GONE);
    layoutDisplayArea.setVisibility(View.VISIBLE);
    if (claim.getTags().contains("disable-support"))
        buttonTip.setVisibility(View.GONE);
    else
        buttonTip.setVisibility(View.VISIBLE);
    String thumbnailUrl = "";
    String coverUrl = claim.getCoverUrl();
    textTitle.setText(Helper.isNullOrEmpty(claim.getTitle()) ? claim.getName() : claim.getTitle());
    Context context = getContext();
    if (context != null) {
        thumbnailUrl = claim.getThumbnailUrl(imageThumbnail.getLayoutParams().width, imageThumbnail.getLayoutParams().height, 85);
    }
    if (context != null && !Helper.isNullOrEmpty(coverUrl)) {
        Glide.with(context.getApplicationContext()).load(coverUrl).centerCrop().into(imageCover);
    }
    if (context != null && !Helper.isNullOrEmpty(thumbnailUrl)) {
        Glide.with(context.getApplicationContext()).load(thumbnailUrl).apply(RequestOptions.circleCropTransform()).into(imageThumbnail);
        noThumbnailView.setVisibility(View.GONE);
    } else {
        imageThumbnail.setVisibility(View.GONE);
        int bgColor = Helper.generateRandomColorForValue(claim.getClaimId());
        Helper.setIconViewBackgroundColor(noThumbnailView, bgColor, false, getContext());
        noThumbnailView.setVisibility(View.VISIBLE);
        if (claim.getName() != null) {
            textAlpha.setText(claim.getName().substring(1, 2));
        }
    }
    try {
        if (tabPager.getAdapter() == null && context instanceof MainActivity) {
            tabPager.setAdapter(new ChannelPagerAdapter(claim, commentHash, (MainActivity) context));
            if (!Helper.isNullOrEmpty(commentHash)) {
                // set the Comments tab active if a comment hash is set
                new Handler().postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        tabPager.setCurrentItem(3);
                    }
                }, 500);
            }
        }
        new TabLayoutMediator(tabLayout, tabPager, new TabLayoutMediator.TabConfigurationStrategy() {

            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                switch(position) {
                    case 0:
                        tab.setText(R.string.content);
                        break;
                    case 1:
                        tab.setText(R.string.playlists);
                        break;
                    case 2:
                        tab.setText(R.string.about);
                        break;
                    case 3:
                        tab.setText(R.string.comments);
                        break;
                }
            }
        }).attach();
    } catch (IllegalStateException ex) {
    // TODO: Fix why this is happening
    // pass
    }
}
Also used : Context(android.content.Context) Handler(android.os.Handler) AbandonHandler(com.odysee.app.tasks.claim.AbandonHandler) ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) MainActivity(com.odysee.app.MainActivity) NonNull(androidx.annotation.NonNull)

Example 47 with MainActivity

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

the class ChannelManagerFragment method onActionItemClicked.

@Override
public boolean onActionItemClicked(androidx.appcompat.view.ActionMode actionMode, MenuItem menuItem) {
    if (R.id.action_edit == menuItem.getItemId()) {
        if (adapter != null && adapter.getSelectedCount() > 0) {
            Claim claim = adapter.getSelectedItems().get(0);
            // start channel editor with the claim
            Context context = getContext();
            if (context instanceof MainActivity) {
                Map<String, Object> params = new HashMap<>();
                params.put("claim", claim);
                ((MainActivity) context).openFragment(ChannelFormFragment.class, true, params);
            }
            actionMode.finish();
            return true;
        }
    }
    if (R.id.action_delete == menuItem.getItemId()) {
        if (adapter != null && adapter.getSelectedCount() > 0) {
            final List<Claim> selectedClaims = new ArrayList<>(adapter.getSelectedItems());
            String message = getResources().getQuantityString(R.plurals.confirm_delete_channels, selectedClaims.size());
            Context c = getContext();
            if (c != null) {
                AlertDialog.Builder builder = new AlertDialog.Builder(c).setTitle(R.string.delete_selection).setMessage(message).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        handleDeleteSelectedClaims(selectedClaims);
                    }
                }).setNegativeButton(R.string.no, null);
                builder.show();
            }
            return true;
        }
    }
    return false;
}
Also used : Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) MainActivity(com.odysee.app.MainActivity) Claim(com.odysee.app.model.Claim)

Example 48 with MainActivity

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

the class ChannelManagerFragment method onEnterSelectionMode.

public void onEnterSelectionMode() {
    Context context = getContext();
    if (context instanceof MainActivity) {
        MainActivity activity = (MainActivity) context;
        activity.startSupportActionMode(this);
    }
}
Also used : Context(android.content.Context) MainActivity(com.odysee.app.MainActivity)

Example 49 with MainActivity

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

the class ChannelContentFragment method onPause.

public void onPause() {
    Context context = getContext();
    if (context != null) {
        ((MainActivity) context).removeDownloadActionListener(this);
    }
    PreferenceManager.getDefaultSharedPreferences(context).registerOnSharedPreferenceChangeListener(this);
    super.onPause();
}
Also used : Context(android.content.Context) MainActivity(com.odysee.app.MainActivity)

Example 50 with MainActivity

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

the class ChannelContentFragment method onCreateView.

public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_channel_content, container, false);
    currentSortBy = ContentSortDialogFragment.ITEM_SORT_BY_NEW;
    currentContentFrom = ContentFromDialogFragment.ITEM_FROM_PAST_WEEK;
    sortLink = root.findViewById(R.id.channel_content_sort_link);
    contentFromLink = root.findViewById(R.id.channel_content_time_link);
    sortLinkText = root.findViewById(R.id.channel_content_sort_link_text);
    contentFromLinkText = root.findViewById(R.id.channel_content_time_link_text);
    bigContentLoading = root.findViewById(R.id.channel_content_main_progress);
    contentLoading = root.findViewById(R.id.channel_content_load_progress);
    noContentView = root.findViewById(R.id.channel_content_no_claim_search_content);
    contentList = root.findViewById(R.id.channel_content_list);
    LinearLayoutManager llm = new LinearLayoutManager(getContext());
    contentList.setLayoutManager(llm);
    contentList.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
            if (contentClaimSearchLoading) {
                return;
            }
            LinearLayoutManager lm = (LinearLayoutManager) recyclerView.getLayoutManager();
            if (lm != null) {
                int visibleItemCount = lm.getChildCount();
                int totalItemCount = lm.getItemCount();
                int pastVisibleItems = lm.findFirstVisibleItemPosition();
                if (pastVisibleItems + visibleItemCount >= totalItemCount) {
                    if (!contentHasReachedEnd) {
                        // load more
                        currentClaimSearchPage++;
                        fetchClaimSearchContent();
                    }
                }
            }
        }
    });
    sortLink.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            ContentSortDialogFragment dialog = ContentSortDialogFragment.newInstance();
            dialog.setCurrentSortByItem(currentSortBy);
            dialog.setSortByListener(new ContentSortDialogFragment.SortByListener() {

                @Override
                public void onSortByItemSelected(int sortBy) {
                    onSortByChanged(sortBy);
                }
            });
            Context context = getContext();
            if (context instanceof MainActivity) {
                MainActivity activity = (MainActivity) context;
                dialog.show(activity.getSupportFragmentManager(), ContentSortDialogFragment.TAG);
            }
        }
    });
    contentFromLink.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            ContentFromDialogFragment dialog = ContentFromDialogFragment.newInstance();
            dialog.setCurrentFromItem(currentContentFrom);
            dialog.setContentFromListener(new ContentFromDialogFragment.ContentFromListener() {

                @Override
                public void onContentFromItemSelected(int contentFromItem) {
                    onContentFromChanged(contentFromItem);
                }
            });
            Context context = getContext();
            if (context instanceof MainActivity) {
                MainActivity activity = (MainActivity) context;
                dialog.show(activity.getSupportFragmentManager(), ContentFromDialogFragment.TAG);
            }
        }
    });
    return root;
}
Also used : Context(android.content.Context) MainActivity(com.odysee.app.MainActivity) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) ContentFromDialogFragment(com.odysee.app.dialog.ContentFromDialogFragment) RecyclerView(androidx.recyclerview.widget.RecyclerView) ContentSortDialogFragment(com.odysee.app.dialog.ContentSortDialogFragment)

Aggregations

MainActivity (com.odysee.app.MainActivity)138 Context (android.content.Context)119 Claim (com.odysee.app.model.Claim)39 View (android.view.View)31 TextView (android.widget.TextView)30 RecyclerView (androidx.recyclerview.widget.RecyclerView)26 AttributeProviderContext (org.commonmark.renderer.html.AttributeProviderContext)25 ArrayList (java.util.ArrayList)21 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)19 ImageView (android.widget.ImageView)18 SuppressLint (android.annotation.SuppressLint)15 AdapterView (android.widget.AdapterView)14 NestedScrollView (androidx.core.widget.NestedScrollView)14 JSONException (org.json.JSONException)13 JSONObject (org.json.JSONObject)13 SolidIconView (com.odysee.app.ui.controls.SolidIconView)12 HashMap (java.util.HashMap)12 ClaimListAdapter (com.odysee.app.adapter.ClaimListAdapter)11 ApiCallException (com.odysee.app.exceptions.ApiCallException)11 WebView (android.webkit.WebView)10