Search in sources :

Example 61 with NonNull

use of androidx.annotation.NonNull in project AntennaPod by AntennaPod.

the class NewEpisodesFragment method onCreateView.

@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = super.onCreateView(inflater, container, savedInstanceState);
    emptyView.setTitle(R.string.no_new_episodes_head_label);
    emptyView.setMessage(R.string.no_new_episodes_label);
    ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.RIGHT) {

        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
            return false;
        }

        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
            EpisodeItemViewHolder holder = (EpisodeItemViewHolder) viewHolder;
            FeedItemMenuHandler.removeNewFlagWithUndo(NewEpisodesFragment.this, holder.getFeedItem());
        }
    };
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
    itemTouchHelper.attachToRecyclerView(recyclerView);
    return root;
}
Also used : ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) EpisodeItemViewHolder(de.danoeh.antennapod.view.viewholder.EpisodeItemViewHolder) EpisodeItemViewHolder(de.danoeh.antennapod.view.viewholder.EpisodeItemViewHolder) RecyclerView(androidx.recyclerview.widget.RecyclerView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) NonNull(androidx.annotation.NonNull)

Example 62 with NonNull

use of androidx.annotation.NonNull in project AntennaPod by AntennaPod.

the class NextcloudAuthenticationFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    AlertDialog.Builder dialog = new AlertDialog.Builder(getContext());
    dialog.setTitle(R.string.gpodnetauth_login_butLabel);
    dialog.setNegativeButton(R.string.cancel_label, null);
    dialog.setCancelable(false);
    this.setCancelable(false);
    viewBinding = NextcloudAuthDialogBinding.inflate(getLayoutInflater());
    dialog.setView(viewBinding.getRoot());
    viewBinding.loginButton.setOnClickListener(v -> {
        viewBinding.errorText.setVisibility(View.GONE);
        viewBinding.loginButton.setVisibility(View.GONE);
        viewBinding.loginProgressContainer.setVisibility(View.VISIBLE);
        nextcloudLoginFlow = new NextcloudLoginFlow(AntennapodHttpClient.getHttpClient(), viewBinding.serverUrlText.getText().toString(), getContext(), this);
        nextcloudLoginFlow.start();
    });
    return dialog.create();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) NextcloudLoginFlow(de.danoeh.antennapod.net.sync.nextcloud.NextcloudLoginFlow) NonNull(androidx.annotation.NonNull)

Example 63 with NonNull

use of androidx.annotation.NonNull in project AntennaPod by AntennaPod.

the class AntennapodHttpClient method newBuilder.

/**
 * Creates a new HTTP client.  Most users should just use
 * getHttpClient() to get the standard AntennaPod client,
 * but sometimes it's necessary for others to have their own
 * copy so that the clients don't share state.
 * @return http client
 */
@NonNull
public static OkHttpClient.Builder newBuilder() {
    Log.d(TAG, "Creating new instance of HTTP client");
    System.setProperty("http.maxConnections", String.valueOf(MAX_CONNECTIONS));
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    // detect 301 Moved permanently and 308 Permanent Redirect
    builder.networkInterceptors().add(chain -> {
        Request request = chain.request();
        Response response = chain.proceed(request);
        if (response.code() == HttpURLConnection.HTTP_MOVED_PERM || response.code() == StatusLine.HTTP_PERM_REDIRECT) {
            String location = response.header("Location");
            if (location == null) {
                return response;
            }
            if (location.startsWith("/")) {
                // URL is not absolute, but relative
                HttpUrl url = request.url();
                location = url.scheme() + "://" + url.host() + location;
            } else if (!location.toLowerCase().startsWith("http://") && !location.toLowerCase().startsWith("https://")) {
                // Reference is relative to current path
                HttpUrl url = request.url();
                String path = url.encodedPath();
                String newPath = path.substring(0, path.lastIndexOf("/") + 1) + location;
                location = url.scheme() + "://" + url.host() + newPath;
            }
            try {
                DBWriter.updateFeedDownloadURL(request.url().toString(), location).get();
            } catch (Exception e) {
                Log.e(TAG, Log.getStackTraceString(e));
            }
        }
        return response;
    });
    builder.interceptors().add(new BasicAuthorizationInterceptor());
    builder.networkInterceptors().add(new UserAgentInterceptor());
    // set cookie handler
    CookieManager cm = new CookieManager();
    cm.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER);
    builder.cookieJar(new JavaNetCookieJar(cm));
    // set timeouts
    builder.connectTimeout(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
    builder.readTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS);
    builder.writeTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS);
    // 20MB
    builder.cache(new Cache(cacheDirectory, 20L * 1000000));
    // configure redirects
    builder.followRedirects(true);
    builder.followSslRedirects(true);
    ProxyConfig config = UserPreferences.getProxyConfig();
    if (config.type != Proxy.Type.DIRECT && !TextUtils.isEmpty(config.host)) {
        int port = config.port > 0 ? config.port : ProxyConfig.DEFAULT_PORT;
        SocketAddress address = InetSocketAddress.createUnresolved(config.host, port);
        builder.proxy(new Proxy(config.type, address));
        if (!TextUtils.isEmpty(config.username) && config.password != null) {
            builder.proxyAuthenticator((route, response) -> {
                String credentials = Credentials.basic(config.username, config.password);
                return response.request().newBuilder().header("Proxy-Authorization", credentials).build();
            });
        }
    }
    SslClientSetup.installCertificates(builder);
    return builder;
}
Also used : JavaNetCookieJar(okhttp3.JavaNetCookieJar) OkHttpClient(okhttp3.OkHttpClient) UserAgentInterceptor(de.danoeh.antennapod.core.service.UserAgentInterceptor) Request(okhttp3.Request) BasicAuthorizationInterceptor(de.danoeh.antennapod.core.service.BasicAuthorizationInterceptor) HttpUrl(okhttp3.HttpUrl) Response(okhttp3.Response) Proxy(java.net.Proxy) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) CookieManager(java.net.CookieManager) Cache(okhttp3.Cache) NonNull(androidx.annotation.NonNull)

Example 64 with NonNull

use of androidx.annotation.NonNull in project AntennaPod by AntennaPod.

the class FeedItemMenuHandler method onMenuItemClicked.

/**
 * Default menu handling for the given FeedItem.
 *
 * A Fragment instance, (rather than the more generic Context), is needed as a parameter
 * to support some UI operations, e.g., creating a Snackbar.
 */
public static boolean onMenuItemClicked(@NonNull Fragment fragment, int menuItemId, @NonNull FeedItem selectedItem) {
    @NonNull Context context = fragment.requireContext();
    if (menuItemId == R.id.skip_episode_item) {
        IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_SKIP_CURRENT_EPISODE);
    } else if (menuItemId == R.id.remove_item) {
        DBWriter.deleteFeedMediaOfItem(context, selectedItem.getMedia().getId());
    } else if (menuItemId == R.id.remove_new_flag_item) {
        removeNewFlagWithUndo(fragment, selectedItem);
    } else if (menuItemId == R.id.mark_read_item) {
        selectedItem.setPlayed(true);
        DBWriter.markItemPlayed(selectedItem, FeedItem.PLAYED, true);
        if (SynchronizationSettings.isProviderConnected()) {
            FeedMedia media = selectedItem.getMedia();
            // not all items have media, Gpodder only cares about those that do
            if (media != null) {
                EpisodeAction actionPlay = new EpisodeAction.Builder(selectedItem, EpisodeAction.PLAY).currentTimestamp().started(media.getDuration() / 1000).position(media.getDuration() / 1000).total(media.getDuration() / 1000).build();
                SynchronizationQueueSink.enqueueEpisodeActionIfSynchronizationIsActive(context, actionPlay);
            }
        }
    } else if (menuItemId == R.id.mark_unread_item) {
        selectedItem.setPlayed(false);
        DBWriter.markItemPlayed(selectedItem, FeedItem.UNPLAYED, false);
        if (selectedItem.getMedia() != null) {
            EpisodeAction actionNew = new EpisodeAction.Builder(selectedItem, EpisodeAction.NEW).currentTimestamp().build();
            SynchronizationQueueSink.enqueueEpisodeActionIfSynchronizationIsActive(context, actionNew);
        }
    } else if (menuItemId == R.id.add_to_queue_item) {
        DBWriter.addQueueItem(context, selectedItem);
    } else if (menuItemId == R.id.remove_from_queue_item) {
        DBWriter.removeQueueItem(context, true, selectedItem);
    } else if (menuItemId == R.id.add_to_favorites_item) {
        DBWriter.addFavoriteItem(selectedItem);
    } else if (menuItemId == R.id.remove_from_favorites_item) {
        DBWriter.removeFavoriteItem(selectedItem);
    } else if (menuItemId == R.id.reset_position) {
        selectedItem.getMedia().setPosition(0);
        if (PlaybackPreferences.getCurrentlyPlayingFeedMediaId() == selectedItem.getMedia().getId()) {
            PlaybackPreferences.writeNoMediaPlaying();
            IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE);
        }
        DBWriter.markItemPlayed(selectedItem, FeedItem.UNPLAYED, true);
    } else if (menuItemId == R.id.visit_website_item) {
        IntentUtils.openInBrowser(context, FeedItemUtil.getLinkWithFallback(selectedItem));
    } else if (menuItemId == R.id.share_item) {
        ShareDialog shareDialog = ShareDialog.newInstance(selectedItem);
        shareDialog.show((fragment.getActivity().getSupportFragmentManager()), "ShareEpisodeDialog");
    } else {
        Log.d(TAG, "Unknown menuItemId: " + menuItemId);
        return false;
    }
    return true;
}
Also used : Context(android.content.Context) ShareDialog(de.danoeh.antennapod.dialog.ShareDialog) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) NonNull(androidx.annotation.NonNull) EpisodeAction(de.danoeh.antennapod.net.sync.model.EpisodeAction)

Example 65 with NonNull

use of androidx.annotation.NonNull in project AntennaPod by AntennaPod.

the class DBReader method getPlayedItems.

/**
 * Loads a list of FeedItems whose episode has been played.
 *
 * @return A list of FeedItems whose episdoe has been played.
 */
@NonNull
public static List<FeedItem> getPlayedItems() {
    Log.d(TAG, "getPlayedItems() called");
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    try (Cursor cursor = adapter.getPlayedItemsCursor()) {
        List<FeedItem> items = extractItemlistFromCursor(adapter, cursor);
        loadAdditionalFeedItemListData(items);
        return items;
    } finally {
        adapter.close();
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Cursor(android.database.Cursor) NonNull(androidx.annotation.NonNull)

Aggregations

NonNull (androidx.annotation.NonNull)1197 View (android.view.View)191 ArrayList (java.util.ArrayList)154 Context (android.content.Context)128 Nullable (androidx.annotation.Nullable)128 TextView (android.widget.TextView)117 Intent (android.content.Intent)115 List (java.util.List)110 Recipient (org.thoughtcrime.securesms.recipients.Recipient)109 IOException (java.io.IOException)103 Bundle (android.os.Bundle)102 WorkerThread (androidx.annotation.WorkerThread)94 LayoutInflater (android.view.LayoutInflater)89 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)82 AlertDialog (androidx.appcompat.app.AlertDialog)76 Log (org.signal.core.util.logging.Log)76 Cursor (android.database.Cursor)68 ViewGroup (android.view.ViewGroup)65 LinkedList (java.util.LinkedList)64 Stream (com.annimon.stream.Stream)62