Search in sources :

Example 36 with MainActivity

use of de.danoeh.antennapod.activity.MainActivity in project AntennaPod by AntennaPod.

the class SubscriptionFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_subscriptions, container, false);
    toolbar = root.findViewById(R.id.toolbar);
    toolbar.setOnMenuItemClickListener(this);
    displayUpArrow = getParentFragmentManager().getBackStackEntryCount() != 0;
    if (savedInstanceState != null) {
        displayUpArrow = savedInstanceState.getBoolean(KEY_UP_ARROW);
    }
    ((MainActivity) getActivity()).setupToolbarToggle(toolbar, displayUpArrow);
    toolbar.inflateMenu(R.menu.subscriptions);
    for (int i = 0; i < COLUMN_CHECKBOX_IDS.length; i++) {
        // Do this in Java to localize numbers
        toolbar.getMenu().findItem(COLUMN_CHECKBOX_IDS[i]).setTitle(String.format(Locale.getDefault(), "%d", i + MIN_NUM_COLUMNS));
    }
    refreshToolbarState();
    if (getArguments() != null) {
        displayedFolder = getArguments().getString(ARGUMENT_FOLDER, null);
        if (displayedFolder != null) {
            toolbar.setTitle(displayedFolder);
        }
    }
    subscriptionRecycler = root.findViewById(R.id.subscriptions_grid);
    GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), prefs.getInt(PREF_NUM_COLUMNS, getDefaultNumOfColumns()), RecyclerView.VERTICAL, false);
    subscriptionRecycler.setLayoutManager(gridLayoutManager);
    subscriptionRecycler.addItemDecoration(new SubscriptionsRecyclerAdapter.GridDividerItemDecorator());
    gridLayoutManager.setSpanCount(prefs.getInt(PREF_NUM_COLUMNS, getDefaultNumOfColumns()));
    registerForContextMenu(subscriptionRecycler);
    subscriptionAddButton = root.findViewById(R.id.subscriptions_add);
    progressBar = root.findViewById(R.id.progLoading);
    feedsFilteredMsg = root.findViewById(R.id.feeds_filtered_message);
    feedsFilteredMsg.setOnClickListener((l) -> SubscriptionsFilterDialog.showDialog(requireContext()));
    SwipeRefreshLayout swipeRefreshLayout = root.findViewById(R.id.swipeRefresh);
    swipeRefreshLayout.setDistanceToTriggerSync(getResources().getInteger(R.integer.swipe_refresh_distance));
    swipeRefreshLayout.setOnRefreshListener(() -> {
        AutoUpdateManager.runImmediate(requireContext());
        new Handler(Looper.getMainLooper()).postDelayed(() -> swipeRefreshLayout.setRefreshing(false), getResources().getInteger(R.integer.swipe_to_refresh_duration_in_ms));
    });
    speedDialView = root.findViewById(R.id.fabSD);
    speedDialView.setOverlayLayout(root.findViewById(R.id.fabSDOverlay));
    speedDialView.inflate(R.menu.nav_feed_action_speeddial);
    speedDialView.setOnChangeListener(new SpeedDialView.OnChangeListener() {

        @Override
        public boolean onMainActionSelected() {
            return false;
        }

        @Override
        public void onToggleChanged(boolean isOpen) {
        }
    });
    speedDialView.setOnActionSelectedListener(actionItem -> {
        new FeedMultiSelectActionHandler((MainActivity) getActivity(), subscriptionAdapter.getSelectedItems()).handleAction(actionItem.getId());
        return true;
    });
    return root;
}
Also used : Handler(android.os.Handler) EmptyViewHandler(de.danoeh.antennapod.view.EmptyViewHandler) FeedMultiSelectActionHandler(de.danoeh.antennapod.fragment.actions.FeedMultiSelectActionHandler) MainActivity(de.danoeh.antennapod.activity.MainActivity) SpeedDialView(com.leinardi.android.speeddial.SpeedDialView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) SuppressLint(android.annotation.SuppressLint) SubscriptionsRecyclerAdapter(de.danoeh.antennapod.adapter.SubscriptionsRecyclerAdapter) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) SpeedDialView(com.leinardi.android.speeddial.SpeedDialView) FeedMultiSelectActionHandler(de.danoeh.antennapod.fragment.actions.FeedMultiSelectActionHandler)

Example 37 with MainActivity

use of de.danoeh.antennapod.activity.MainActivity in project AntennaPod by AntennaPod.

the class AddFeedFragment method addLocalFolderResult.

private void addLocalFolderResult(final Uri uri) {
    if (uri == null) {
        return;
    }
    Observable.fromCallable(() -> addLocalFolder(uri)).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(feed -> {
        Fragment fragment = FeedItemlistFragment.newInstance(feed.getId());
        ((MainActivity) getActivity()).loadChildFragment(fragment);
    }, error -> {
        Log.e(TAG, Log.getStackTraceString(error));
        ((MainActivity) getActivity()).showSnackbarAbovePlayer(error.getLocalizedMessage(), Snackbar.LENGTH_LONG);
    });
}
Also used : MainActivity(de.danoeh.antennapod.activity.MainActivity) Fragment(androidx.fragment.app.Fragment) GpodnetMainFragment(de.danoeh.antennapod.fragment.gpodnet.GpodnetMainFragment)

Example 38 with MainActivity

use of de.danoeh.antennapod.activity.MainActivity in project AntennaPod by AntennaPod.

the class ItemFragment method openPodcast.

private void openPodcast() {
    Fragment fragment = FeedItemlistFragment.newInstance(item.getFeedId());
    ((MainActivity) getActivity()).loadChildFragment(fragment);
}
Also used : MainActivity(de.danoeh.antennapod.activity.MainActivity) Fragment(androidx.fragment.app.Fragment)

Example 39 with MainActivity

use of de.danoeh.antennapod.activity.MainActivity in project AntennaPod by AntennaPod.

the class GpodnetMainFragment method setupToolbar.

private void setupToolbar(Toolbar toolbar) {
    toolbar.setTitle(R.string.gpodnet_main_label);
    toolbar.setNavigationOnClickListener(v -> getParentFragmentManager().popBackStack());
    toolbar.inflateMenu(R.menu.search);
    MenuItem searchItem = toolbar.getMenu().findItem(R.id.action_search);
    final SearchView sv = (SearchView) searchItem.getActionView();
    sv.setQueryHint(getString(R.string.gpodnet_search_hint));
    sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            Activity activity = getActivity();
            if (activity != null) {
                searchItem.collapseActionView();
                ((MainActivity) activity).loadChildFragment(OnlineSearchFragment.newInstance(GpodnetPodcastSearcher.class, query));
            }
            return true;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            return false;
        }
    });
}
Also used : SearchView(androidx.appcompat.widget.SearchView) MainActivity(de.danoeh.antennapod.activity.MainActivity) Activity(android.app.Activity) MenuItem(android.view.MenuItem)

Example 40 with MainActivity

use of de.danoeh.antennapod.activity.MainActivity in project AntennaPod by AntennaPod.

the class DownloadLogAdapter method bind.

private void bind(DownloadLogItemViewHolder holder, DownloadStatus status, int position) {
    String statusText = "";
    if (status.getFeedfileType() == Feed.FEEDFILETYPE_FEED) {
        statusText += context.getString(R.string.download_type_feed);
    } else if (status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
        statusText += context.getString(R.string.download_type_media);
    }
    statusText += " ยท ";
    statusText += DateUtils.getRelativeTimeSpanString(status.getCompletionDate().getTime(), System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, 0);
    holder.status.setText(statusText);
    if (status.getTitle() != null) {
        holder.title.setText(status.getTitle());
    } else {
        holder.title.setText(R.string.download_log_title_unknown);
    }
    if (status.isSuccessful()) {
        holder.icon.setTextColor(ContextCompat.getColor(context, R.color.download_success_green));
        holder.icon.setText("{fa-check-circle}");
        holder.icon.setContentDescription(context.getString(R.string.download_successful));
        holder.secondaryActionButton.setVisibility(View.INVISIBLE);
        holder.reason.setVisibility(View.GONE);
        holder.tapForDetails.setVisibility(View.GONE);
    } else {
        if (status.getReason() == DownloadError.ERROR_PARSER_EXCEPTION_DUPLICATE) {
            holder.icon.setTextColor(ContextCompat.getColor(context, R.color.download_warning_yellow));
            holder.icon.setText("{fa-exclamation-circle}");
        } else {
            holder.icon.setTextColor(ContextCompat.getColor(context, R.color.download_failed_red));
            holder.icon.setText("{fa-times-circle}");
        }
        holder.icon.setContentDescription(context.getString(R.string.error_label));
        holder.reason.setText(status.getReason().getErrorString(context));
        holder.reason.setVisibility(View.VISIBLE);
        holder.tapForDetails.setVisibility(View.VISIBLE);
        if (newerWasSuccessful(position - runningDownloads.size(), status.getFeedfileType(), status.getFeedfileId())) {
            holder.secondaryActionButton.setVisibility(View.INVISIBLE);
            holder.secondaryActionButton.setOnClickListener(null);
            holder.secondaryActionButton.setTag(null);
        } else {
            holder.secondaryActionIcon.setImageResource(R.drawable.ic_refresh);
            holder.secondaryActionButton.setVisibility(View.VISIBLE);
            if (status.getFeedfileType() == Feed.FEEDFILETYPE_FEED) {
                holder.secondaryActionButton.setOnClickListener(v -> {
                    holder.secondaryActionButton.setVisibility(View.INVISIBLE);
                    Feed feed = DBReader.getFeed(status.getFeedfileId());
                    if (feed == null) {
                        Log.e(TAG, "Could not find feed for feed id: " + status.getFeedfileId());
                        return;
                    }
                    DBTasks.forceRefreshFeed(context, feed, true);
                });
            } else if (status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
                holder.secondaryActionButton.setOnClickListener(v -> {
                    holder.secondaryActionButton.setVisibility(View.INVISIBLE);
                    FeedMedia media = DBReader.getFeedMedia(status.getFeedfileId());
                    if (media == null) {
                        Log.e(TAG, "Could not find feed media for feed id: " + status.getFeedfileId());
                        return;
                    }
                    DownloadService.download(context, true, DownloadRequestCreator.create(media).build());
                    ((MainActivity) context).showSnackbarAbovePlayer(R.string.status_downloading_label, Toast.LENGTH_SHORT);
                });
            }
        }
    }
}
Also used : DateUtils(android.text.format.DateUtils) DownloadRequestCreator(de.danoeh.antennapod.core.service.download.DownloadRequestCreator) ArrayList(java.util.ArrayList) DownloadRequest(de.danoeh.antennapod.core.service.download.DownloadRequest) Toast(android.widget.Toast) View(android.view.View) DownloadLogItemViewHolder(de.danoeh.antennapod.view.viewholder.DownloadLogItemViewHolder) ContextCompat(androidx.core.content.ContextCompat) DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus) Log(android.util.Log) Feed(de.danoeh.antennapod.model.feed.Feed) Formatter(android.text.format.Formatter) Downloader(de.danoeh.antennapod.core.service.download.Downloader) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) ThemeUtils(de.danoeh.antennapod.ui.common.ThemeUtils) R(de.danoeh.antennapod.R) DownloadError(de.danoeh.antennapod.core.util.DownloadError) ViewGroup(android.view.ViewGroup) MainActivity(de.danoeh.antennapod.activity.MainActivity) List(java.util.List) BaseAdapter(android.widget.BaseAdapter) DBReader(de.danoeh.antennapod.core.storage.DBReader) ListFragment(androidx.fragment.app.ListFragment) Activity(android.app.Activity) DownloadService(de.danoeh.antennapod.core.service.download.DownloadService) DBTasks(de.danoeh.antennapod.core.storage.DBTasks) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Feed(de.danoeh.antennapod.model.feed.Feed)

Aggregations

MainActivity (de.danoeh.antennapod.activity.MainActivity)43 View (android.view.View)15 TextView (android.widget.TextView)11 Nullable (androidx.annotation.Nullable)6 Context (android.content.Context)5 ImageView (android.widget.ImageView)5 Fragment (androidx.fragment.app.Fragment)5 EpisodeItemListRecyclerView (de.danoeh.antennapod.view.EpisodeItemListRecyclerView)5 DialogInterface (android.content.DialogInterface)4 Bundle (android.os.Bundle)4 MenuItem (android.view.MenuItem)4 NonNull (androidx.annotation.NonNull)4 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 ConfirmationDialog (de.danoeh.antennapod.core.dialog.ConfirmationDialog)4 EmptyViewHandler (de.danoeh.antennapod.view.EmptyViewHandler)4 Activity (android.app.Activity)3 Handler (android.os.Handler)3 ViewGroup (android.view.ViewGroup)3 Toolbar (androidx.appcompat.widget.Toolbar)3 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)3