Search in sources :

Example 56 with MainActivity

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

the class ChannelFormFragment method launchFilePicker.

private void launchFilePicker() {
    Context context = getContext();
    if (context instanceof MainActivity) {
        MainActivity.startingFilePickerActivity = true;
        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        intent.setType("image/*");
        ((MainActivity) context).startActivityForResult(Intent.createChooser(intent, getString(coverFilePickerActive ? R.string.select_cover : R.string.select_thumbnail)), MainActivity.REQUEST_FILE_PICKER);
    }
}
Also used : Context(android.content.Context) Intent(android.content.Intent) MainActivity(com.odysee.app.MainActivity)

Example 57 with MainActivity

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

the class FollowingFragment method fetchClaimSearchContent.

private void fetchClaimSearchContent(boolean reset) {
    if (reset && contentListAdapter != null) {
        contentListAdapter.clearItems();
        currentClaimSearchPage = 1;
    }
    contentClaimSearchLoading = true;
    Helper.setViewVisibility(noContentView, View.GONE);
    Map<String, Object> claimSearchOptions = buildContentOptions();
    contentClaimSearchTask = new ClaimSearchTask(claimSearchOptions, Lbry.API_CONNECTION_STRING, getLoadingView(), new ClaimSearchResultHandler() {

        @Override
        public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
            claims = Helper.filterClaimsByOutpoint(claims);
            claims = Helper.filterClaimsByBlockedChannels(claims, Lbryio.blockedChannels);
            Date d = new Date();
            Calendar cal = new GregorianCalendar();
            cal.setTime(d);
            // Remove claims with a release time in the future
            claims.removeIf(e -> {
                Claim.GenericMetadata metadata = e.getValue();
                return metadata instanceof Claim.StreamMetadata && (((Claim.StreamMetadata) metadata).getReleaseTime()) > (cal.getTimeInMillis() / 1000L);
            });
            // Sort claims so those which are livestreaming now are shwon on the top of the list
            Collections.sort(claims, new Comparator<Claim>() {

                @Override
                public int compare(Claim claim, Claim t1) {
                    if (claim.isLive() && !t1.isLive())
                        return -1;
                    else if (!claim.isLive() && t1.isLive())
                        return 1;
                    else
                        return 0;
                }
            });
            if (contentListAdapter == null) {
                Context context = getContext();
                if (context != null) {
                    contentListAdapter = new ClaimListAdapter(claims, context);
                    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("@")) {
                                    // channel claim
                                    activity.openChannelClaim(claim);
                                } else {
                                    activity.openFileClaim(claim);
                                }
                            }
                        }
                    });
                }
            } else {
                contentListAdapter.addItems(claims);
            }
            if (contentList != null && contentList.getAdapter() == null) {
                contentList.setAdapter(contentListAdapter);
            }
            contentHasReachedEnd = hasReachedEnd;
            contentClaimSearchLoading = false;
            checkNoContent(false);
        }

        @Override
        public void onError(Exception error) {
            contentClaimSearchLoading = false;
            checkNoContent(false);
        }
    });
    contentClaimSearchTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : Context(android.content.Context) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) MainActivity(com.odysee.app.MainActivity) ClaimListAdapter(com.odysee.app.adapter.ClaimListAdapter) Date(java.util.Date) JSONException(org.json.JSONException) LbryUriException(com.odysee.app.exceptions.LbryUriException) ClaimSearchTask(com.odysee.app.tasks.claim.ClaimSearchTask) ClaimSearchResultHandler(com.odysee.app.tasks.claim.ClaimSearchResultHandler) JSONObject(org.json.JSONObject) List(java.util.List) ArrayList(java.util.ArrayList) Claim(com.odysee.app.model.Claim)

Example 58 with MainActivity

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

the class FollowingFragment method onPause.

public void onPause() {
    Context context = getContext();
    if (context instanceof MainActivity) {
        ((MainActivity) context).removeDownloadActionListener(this);
        PreferenceManager.getDefaultSharedPreferences(context).unregisterOnSharedPreferenceChangeListener(this);
        // Store current state of the channel filter as a preference
        SharedPreferences sharedpreferences = context.getSharedPreferences("lbry_shared_preferences", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedpreferences.edit();
        editor.putBoolean("subscriptions_filter_visibility", horizontalChannelList.getVisibility() == View.VISIBLE);
        editor.apply();
    }
    super.onPause();
}
Also used : Context(android.content.Context) SharedPreferences(android.content.SharedPreferences) MainActivity(com.odysee.app.MainActivity)

Example 59 with MainActivity

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

the class FollowingFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_following, container, false);
    // Following page is sorted by new by default, past week if sort is top
    currentSortBy = ContentSortDialogFragment.ITEM_SORT_BY_NEW;
    currentContentFrom = ContentFromDialogFragment.ITEM_FROM_PAST_WEEK;
    findFollowingContainer = root.findViewById(R.id.find_following_container);
    titleView = root.findViewById(R.id.find_following_page_title);
    infoView = root.findViewById(R.id.following_page_info);
    horizontalChannelList = root.findViewById(R.id.following_channel_list);
    layoutSortContainer = root.findViewById(R.id.following_filter_container);
    sortLink = root.findViewById(R.id.following_sort_link);
    sortLinkText = root.findViewById(R.id.following_sort_link_text);
    filterLink = root.findViewById(R.id.filter_by_channel_link);
    contentFromLink = root.findViewById(R.id.following_time_link);
    contentFromLinkText = root.findViewById(R.id.following_time_link_text);
    suggestedChannelGrid = root.findViewById(R.id.following_suggested_grid);
    suggestedDoneButton = root.findViewById(R.id.following_suggested_done_button);
    contentList = root.findViewById(R.id.following_content_list);
    bigContentLoading = root.findViewById(R.id.following_main_progress);
    contentLoading = root.findViewById(R.id.following_content_progress);
    channelListLoading = root.findViewById(R.id.following_channel_load_progress);
    discoverLink = root.findViewById(R.id.following_discover_link);
    noContentView = root.findViewById(R.id.following_no_claim_search_content);
    Context context = getContext();
    GridLayoutManager glm = new GridLayoutManager(context, 3);
    suggestedChannelGrid.setLayoutManager(glm);
    suggestedChannelGrid.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
            if (suggestedClaimSearchLoading) {
                return;
            }
            GridLayoutManager lm = (GridLayoutManager) recyclerView.getLayoutManager();
            if (lm != null) {
                int visibleItemCount = lm.getChildCount();
                int totalItemCount = lm.getItemCount();
                int pastVisibleItems = lm.findFirstVisibleItemPosition();
                if (pastVisibleItems + visibleItemCount >= totalItemCount) {
                    if (!suggestedHasReachedEnd) {
                        // load more
                        currentSuggestedPage++;
                        fetchSuggestedChannels();
                    }
                }
            }
        }
    });
    LinearLayoutManager cllm = new LinearLayoutManager(context, RecyclerView.HORIZONTAL, false);
    horizontalChannelList.setLayoutManager(cllm);
    LinearLayoutManager llm = new LinearLayoutManager(context);
    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();
                    }
                }
            }
        }
    });
    suggestedDoneButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            int selected = suggestedChannelAdapter == null ? 0 : suggestedChannelAdapter.getSelectedCount();
            int remaining = MIN_SUGGESTED_SUBSCRIBE_COUNT - selected;
            if (remaining == MIN_SUGGESTED_SUBSCRIBE_COUNT) {
                Snackbar.make(getView(), R.string.select_five_subscriptions, Snackbar.LENGTH_LONG).show();
            } else {
                fetchSubscriptions();
                showSubscribedContent();
                fetchAndResolveChannelList();
            }
        }
    });
    if (context != null) {
        SharedPreferences sharedpreferences = context.getSharedPreferences("lbry_shared_preferences", Context.MODE_PRIVATE);
        Helper.setViewVisibility(horizontalChannelList, sharedpreferences.getBoolean("subscriptions_filter_visibility", false) ? View.VISIBLE : View.GONE);
    }
    filterLink.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Helper.setViewVisibility(horizontalChannelList, horizontalChannelList.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
        }
    });
    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);
            }
        }
    });
    discoverLink.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Helper.setViewEnabled(discoverLink, false);
            buildChannelIdsAndUrls();
            currentSuggestedPage = 1;
            discoverDialog = DiscoverDialogFragment.newInstance();
            discoverDialog.setAdapter(suggestedChannelAdapter);
            discoverDialog.setDialogActionsListener(new DiscoverDialogFragment.DiscoverDialogListener() {

                @Override
                public void onScrollEndReached() {
                    if (suggestedClaimSearchLoading) {
                        return;
                    }
                    currentSuggestedPage++;
                    fetchSuggestedChannels();
                }

                @Override
                public void onCancel() {
                    discoverDialog = null;
                    excludeChannelIdsForDiscover = null;
                    if (suggestedChannelAdapter != null) {
                        suggestedChannelAdapter.clearItems();
                    }
                    Helper.setViewEnabled(discoverLink, true);
                }

                @Override
                public void onResume() {
                    if (suggestedChannelAdapter == null || suggestedChannelAdapter.getItemCount() == 0) {
                        discoverDialog.setLoading(true);
                        fetchSuggestedChannels();
                    }
                }
            });
            Context context = getContext();
            if (context instanceof MainActivity) {
                MainActivity activity = (MainActivity) context;
                discoverDialog.show(activity.getSupportFragmentManager(), DiscoverDialogFragment.TAG);
            }
        }
    });
    return root;
}
Also used : Context(android.content.Context) SharedPreferences(android.content.SharedPreferences) 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) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) RecyclerView(androidx.recyclerview.widget.RecyclerView) ContentSortDialogFragment(com.odysee.app.dialog.ContentSortDialogFragment)

Example 60 with MainActivity

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

the class FollowingFragment method onResume.

public void onResume() {
    super.onResume();
    Context context = getContext();
    Helper.setWunderbarValue(null, context);
    PreferenceManager.getDefaultSharedPreferences(context).registerOnSharedPreferenceChangeListener(this);
    if (context instanceof MainActivity) {
        MainActivity activity = (MainActivity) context;
        LbryAnalytics.setCurrentScreen(activity, "Subscriptions", "Subscriptions");
        activity.addDownloadActionListener(this);
    }
    // check if subscriptions exist
    if (suggestedChannelAdapter != null) {
        showSuggestedChannels();
        if (suggestedChannelGrid != null) {
            suggestedChannelGrid.setAdapter(suggestedChannelAdapter);
        }
    }
    if (Lbryio.subscriptions != null && Lbryio.subscriptions.size() > 0) {
        fetchLoadedSubscriptions(true);
    } else {
        fetchSubscriptions();
    }
}
Also used : Context(android.content.Context) MainActivity(com.odysee.app.MainActivity)

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