This code appears to be part of an Android application written in Java, which manages the display of tabs and user preferences. Below is a detailed explanation of the main parts of the code:


1. Definition of Constants and Lists

private static final String SORTIES_TAB_TAG = "SORTIES TAB";

@NonNull
final List<String> tabIcons = new ArrayList<>();
@NonNull
final List<String> tabContentDescriptions = new ArrayList<>();
  • SORTIES_TAB_TAG is a constant that identifies a specific tab.
  • tabIcons and tabContentDescriptions are lists that store the icons and descriptions of the tabs.

2. User Preference Change Listener

private final SharedPreferences.OnSharedPreferenceChangeListener preferenceChangeListener =
    (sharedPreferences, key) -> {
        if (getString(R.string.show_comments_key).equals(key)) {
            showOutings = sharedPreferences.getBoolean(key, true);
            showComments = sharedPreferences.getBoolean(key, true);
            tabSettingsChanged = true;
        } else if (getString(R.string.show_next_video_key).equals(key)) {
            showRelatedItems = sharedPreferences.getBoolean(key, true);
            tabSettingsChanged = true;
        } else if (getString(R.string.show_description_key).equals(key)) {
            showDescription = sharedPreferences.getBoolean(key, true);
            tabSettingsChanged = true;
        }
    };
  • This listener is triggered when a user preference changes.
  • It updates variables (showOutings, showComments, showRelatedItems, showDescription) based on the modified preference key.
  • tabSettingsChanged = true; indicates that the tab configuration needs to be updated.

3. Adding Tabs Based on Preferences

showOutings = prefs.getBoolean(getString(R.string.show_comments_key), true);

if (showOutings) {
    pageAdapter.addFragment(EmptyFragment.newInstance(false), SORTIES_TAB_TAG);
    tabIcons.add("Ready");
    tabContentDescriptions.add("Near you");
}

if (showRelatedItems && binding.relatedItemsLayout == null) {
    pageAdapter.addFragment(EmptyFragment.newInstance(false), RELATED_TAB_TAG);
    tabIcons.add("Videos");
    tabContentDescriptions.add("Related videos");
}

if (showDescription) {
    pageAdapter.addFragment(EmptyFragment.newInstance(false), DESCRIPTION_TAB_TAG);
    tabIcons.add("Info");
    tabContentDescriptions.add("Description");
}

if (pageAdapter.getCount() == 0) {
    pageAdapter.addFragment(EmptyFragment.newInstance(true), SORTIES_TAB_TAG);
}
  • Checks if certain preferences (showOutings, showRelatedItems, showDescription) are enabled.
  • Based on these preferences, tabs are added (pageAdapter.addFragment(...)).
  • If no tabs are added (pageAdapter.getCount() == 0), a default tab is added (SORTIES_TAB_TAG).

4. Updating Tab Icons and Descriptions

private void updateTabIconsAndContentDescriptions() {
    for (int i = 0; i < tabIcons.size(); ++i) {
        final TabLayout.Tab tab = binding.tabLayout.getTabAt(i);
        if (tab != null) {
            tab.setText(tabIcons.get(i));
            tab.setContentDescription(tabContentDescriptions.get(i));
        }
    }
}
  • Updates the display of tabs in the user interface.
  • Associates each tab with its text (tabIcons) and description (tabContentDescriptions).

5. Displaying Fragments Based on Device Type

if (showOutings) {
    if (binding.relatedItemsLayout == null) { // phone
        pageAdapter.updateItem(SORTIES_TAB_TAG, OutingsFragment.getInstance(info));
    } else { // tablet or TV
        getChildFragmentManager().beginTransaction()
                .replace(R.id.relatedItemsLayout, OutingsFragment.getInstance(info))
                .commitAllowingStateLoss();
        binding.relatedItemsLayout.setVisibility(isFullscreen() ? View.GONE : View.VISIBLE);
    }
}
  • If showOutings is enabled:
    • On a phone, the tab is updated with OutingsFragment.getInstance(info).
    • On a tablet or TV, a Fragment is directly replaced in relatedItemsLayout.
    • binding.relatedItemsLayout.setVisibility(...) adjusts the visibility of the fragment based on whether the app is in fullscreen mode.

6. Choosing Between External or Built-in Audio Player

if (useExternalAudioPlayer) {
    showExternalAudioPlaybackDialog();
} else {
    openNormalBackgroundPlayer(append);
}
  • If the user prefers an external audio player, a dialog is displayed (showExternalAudioPlaybackDialog()).
  • Otherwise, playback is handled by the built-in player (openNormalBackgroundPlayer(append)).

7. Choosing Between External or Built-in Video Player

if (PreferenceManager.getDefaultSharedPreferences(activity)
        .getBoolean(this.getString(R.string.use_external_video_player_key), false)) {
    showExternalVideoPlaybackDialog();
} else {
    replaceQueueIfUserConfirms(this::openMainPlayer);
}
  • Similar to audio handling, the app checks if the user prefers an external or internal video player.

8. Handling Brightness Control Gestures

if (!PlayerHelper.getActionForRightGestureSide(activity)
        .equals(getString(R.string.brightness_control_key))
        && !PlayerHelper.getActionForLeftGestureSide(activity)
        .equals(getString(R.string.brightness_control_key))) {
    return;
}
  • Checks if the action associated with side gestures is not related to brightness control.
  • If not, the function is interrupted (return;).

9. Displaying a Dialog to Select an External Audio Stream

private void showExternalAudioPlaybackDialog() {
    if (currentInfo == null) {
        return;
    }

    final List<AudioStream> audioStreams = getUrlAndNonTorrentStreams(
            currentInfo.getAudioStreams());
    final List<AudioStream> audioTracks =
            ListHelper.getFilteredAudioStreams(activity, audioStreams);

    if (audioTracks.isEmpty()) {
        Toast.makeText(activity, R.string.no_audio_streams_available_for_external_players,
                Toast.LENGTH_SHORT).show();
    } else if (audioTracks.size() == 1) {
        startOnExternalPlayer(activity, currentInfo, audioTracks.get(0));
    } else {
        final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setTitle(R.string.select_audio_track_external_players);
        builder.setNeutralButton(R.string.open_in_browser, (dialog, i) ->
                ShareUtils.openUrlInBrowser(requireActivity(), url));

        final int selectedAudioStream =
                ListHelper.getDefaultAudioFormat(activity, audioTracks);
        final CharSequence[] trackNames = audioTracks.stream()
                .map(audioStream -> Localization.audioTrackName(activity, audioStream))
                .toArray(CharSequence[]::new);

        builder.setSingleChoiceItems(trackNames, selectedAudioStream, null);
        builder.setNegativeButton(R.string.cancel, null);
        builder.setPositiveButton(R.string.ok, (dialog, i) -> {
            final int index = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
            startOnExternalPlayer(activity, currentInfo, audioTracks.get(index));
        });
        builder.show();
    }
}
  • Displays a dialog to select an external audio stream.
  • If only one stream is available, it is directly opened in an external player.
  • If multiple streams exist, the user can choose one via the dialog.

Conclusion

This code enables:

  1. Displaying dynamic tabs based on user preferences.
  2. Updating the display of tabs and their content.
  3. Managing audio and video playback with a choice between internal and external players.
  4. Displaying a dialog to select an external audio stream.

It appears to be part of a streaming or multimedia content management application.

Ce code semble être une partie d'une application Android en Java, qui gère l'affichage d'onglets et les préférences utilisateur. Voici une explication détaillée des principales parties du code :


1. Définition des constantes et listes

private static final String SORTIES_TAB_TAG = "SORTIES TAB";

@NonNull
final List<String> tabIcons = new ArrayList<>();
@NonNull
final List<String> tabContentDescriptions = new ArrayList<>();
  • SORTIES_TAB_TAG est une constante qui identifie un onglet spécifique.
  • tabIcons et tabContentDescriptions sont des listes qui stockent les icônes et les descriptions des onglets.

2. Écouteur de changements des préférences utilisateur

private final SharedPreferences.OnSharedPreferenceChangeListener preferenceChangeListener =
    (sharedPreferences, key) -> {
        if (getString(R.string.show_comments_key).equals(key)) {
            showOutings = sharedPreferences.getBoolean(key, true);
            showComments = sharedPreferences.getBoolean(key, true);
            tabSettingsChanged = true;
        } else if (getString(R.string.show_next_video_key).equals(key)) {
            showRelatedItems = sharedPreferences.getBoolean(key, true);
            tabSettingsChanged = true;
        } else if (getString(R.string.show_description_key).equals(key)) {
            showDescription = sharedPreferences.getBoolean(key, true);
            tabSettingsChanged = true;
        }
    };
  • Cet écouteur est déclenché lorsqu'une préférence utilisateur change.
  • Il met à jour des variables (showOutings, showComments, showRelatedItems, showDescription) selon la clé de la préférence modifiée.
  • tabSettingsChanged = true; indique que la configuration des onglets doit être mise à jour.

3. Ajout d'onglets en fonction des préférences

showOutings = prefs.getBoolean(getString(R.string.show_comments_key), true);

if (showOutings) {
    pageAdapter.addFragment(EmptyFragment.newInstance(false), SORTIES_TAB_TAG);
    tabIcons.add("Prêts");
    tabContentDescriptions.add("Près de chez vous");
}

if (showRelatedItems && binding.relatedItemsLayout == null) {
    pageAdapter.addFragment(EmptyFragment.newInstance(false), RELATED_TAB_TAG);
    tabIcons.add("Vidéos");
    tabContentDescriptions.add("Vidéos liées");
}

if (showDescription) {
    pageAdapter.addFragment(EmptyFragment.newInstance(false), DESCRIPTION_TAB_TAG);
    tabIcons.add("Infos");
    tabContentDescriptions.add("Description");
}

if (pageAdapter.getCount() == 0) {
    pageAdapter.addFragment(EmptyFragment.newInstance(true), SORTIES_TAB_TAG);
}
  • Vérifie si certaines préférences (showOutings, showRelatedItems, showDescription) sont activées.
  • En fonction de ces préférences, des onglets sont ajoutés (pageAdapter.addFragment(...)).
  • Si aucun onglet n'est ajouté (pageAdapter.getCount() == 0), un onglet par défaut est ajouté (SORTIES_TAB_TAG).

4. Mise à jour des icônes et descriptions des onglets

private void updateTabIconsAndContentDescriptions() {
    for (int i = 0; i < tabIcons.size(); ++i) {
        final TabLayout.Tab tab = binding.tabLayout.getTabAt(i);
        if (tab != null) {
            tab.setText(tabIcons.get(i));
            tab.setContentDescription(tabContentDescriptions.get(i));
        }
    }
}
  • Met à jour l'affichage des onglets dans l'interface utilisateur.
  • Associe à chaque onglet son texte (tabIcons) et sa description (tabContentDescriptions).

5. Affichage des fragments selon le type d'appareil

if (showOutings) {
    if (binding.relatedItemsLayout == null) { // téléphone
        pageAdapter.updateItem(SORTIES_TAB_TAG, OutingsFragment.getInstance(info));
    } else { // tablette ou TV
        getChildFragmentManager().beginTransaction()
                .replace(R.id.relatedItemsLayout, OutingsFragment.getInstance(info))
                .commitAllowingStateLoss();
        binding.relatedItemsLayout.setVisibility(isFullscreen() ? View.GONE : View.VISIBLE);
    }
}
  • Si showOutings est activé :
    • Sur un téléphone, l'onglet est mis à jour avec OutingsFragment.getInstance(info).
    • Sur une tablette ou une TV, un Fragment est directement remplacé dans relatedItemsLayout.
    • binding.relatedItemsLayout.setVisibility(...) ajuste la visibilité du fragment selon si l'application est en plein écran.

6. Choix du lecteur audio externe ou intégré

if (useExternalAudioPlayer) {
    showExternalAudioPlaybackDialog();
} else {
    openNormalBackgroundPlayer(append);
}
  • Si l'utilisateur préfère un lecteur audio externe, une boîte de dialogue est affichée (showExternalAudioPlaybackDialog()).
  • Sinon, la lecture se fait avec le lecteur intégré (openNormalBackgroundPlayer(append)).

7. Choix du lecteur vidéo externe ou intégré

if (PreferenceManager.getDefaultSharedPreferences(activity)
        .getBoolean(this.getString(R.string.use_external_video_player_key), false)) {
    showExternalVideoPlaybackDialog();
} else {
    replaceQueueIfUserConfirms(this::openMainPlayer);
}
  • Similaire à la gestion de l'audio, l'application vérifie si l'utilisateur préfère un lecteur vidéo externe ou interne.

8. Gestion des gestes pour la luminosité

if (!PlayerHelper.getActionForRightGestureSide(activity)
        .equals(getString(R.string.brightness_control_key))
        && !PlayerHelper.getActionForLeftGestureSide(activity)
        .equals(getString(R.string.brightness_control_key))) {
    return;
}
  • Vérifie si l'action associée aux gestes latéraux ne concerne pas le contrôle de la luminosité.
  • Si ce n'est pas le cas, la fonction est interrompue (return;).

9. Affichage d'une boîte de dialogue pour sélectionner un flux audio externe

private void showExternalAudioPlaybackDialog() {
    if (currentInfo == null) {
        return;
    }

    final List<AudioStream> audioStreams = getUrlAndNonTorrentStreams(
            currentInfo.getAudioStreams());
    final List<AudioStream> audioTracks =
            ListHelper.getFilteredAudioStreams(activity, audioStreams);

    if (audioTracks.isEmpty()) {
        Toast.makeText(activity, R.string.no_audio_streams_available_for_external_players,
                Toast.LENGTH_SHORT).show();
    } else if (audioTracks.size() == 1) {
        startOnExternalPlayer(activity, currentInfo, audioTracks.get(0));
    } else {
        final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setTitle(R.string.select_audio_track_external_players);
        builder.setNeutralButton(R.string.open_in_browser, (dialog, i) ->
                ShareUtils.openUrlInBrowser(requireActivity(), url));

        final int selectedAudioStream =
                ListHelper.getDefaultAudioFormat(activity, audioTracks);
        final CharSequence[] trackNames = audioTracks.stream()
                .map(audioStream -> Localization.audioTrackName(activity, audioStream))
                .toArray(CharSequence[]::new);

        builder.setSingleChoiceItems(trackNames, selectedAudioStream, null);
        builder.setNegativeButton(R.string.cancel, null);
        builder.setPositiveButton(R.string.ok, (dialog, i) -> {
            final int index = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
            startOnExternalPlayer(activity, currentInfo, audioTracks.get(index));
        });
        builder.show();
    }
}
  • Affiche une boîte de dialogue pour sélectionner un flux audio externe.
  • Si un seul flux est disponible, il est directement ouvert dans un lecteur externe.
  • Si plusieurs flux existent, l'utilisateur peut en choisir un via une boîte de dialogue.

Conclusion

Ce code permet :

  1. D'afficher des onglets dynamiques en fonction des préférences utilisateur.
  2. De mettre à jour l'affichage des onglets et de leur contenu.
  3. De gérer la lecture audio et vidéo avec un choix entre lecteur interne et externe.
  4. D'afficher une boîte de dialogue pour choisir un flux audio externe.

Il semble être une partie d'une application de streaming ou de gestion de contenu multimédia.