Commit 9f79620d authored by Thomas's avatar Thomas
Browse files

Fix issue #1150 - Allow to disable fullscreen media for Pixelfed

parent 238f31e3
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -211,6 +211,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
    public FetchMoreCallBack fetchMoreCallBack;
    private Context context;
    private boolean visiblePixelfed;
    private boolean pixelfedFullScreenMedia;
    private RecyclerView mRecyclerView;

    public StatusAdapter(List<Status> statuses, Timeline.TimeLineEnum timelineType, boolean minified, boolean canBeFederated, boolean checkRemotely) {
@@ -3178,7 +3179,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
                    } else if(timelineType == Timeline.TimeLineEnum.REMOTE && pinnedTimeline != null && pinnedTimeline.remoteInstance != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.PIXELFED){
                        return STATUS_PIXELFED;
                    }else {
                        if(timelineType != Timeline.TimeLineEnum.UNKNOWN && getCurrentAccount(context).software != null && getCurrentAccount(context).software.trim().toLowerCase().equals("pixelfed")) {
                        if(pixelfedFullScreenMedia && timelineType != Timeline.TimeLineEnum.UNKNOWN && getCurrentAccount(context).software != null && getCurrentAccount(context).software.trim().toLowerCase().equals("pixelfed")) {
                            return STATUS_PIXELFED;
                        } else {
                            return STATUS_VISIBLE;
@@ -3198,6 +3199,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
        context = parent.getContext();
        SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
        visiblePixelfed = sharedpreferences.getBoolean(context.getString(R.string.SET_PIXELFED_PRESENTATION) + MainActivity.currentUserID + MainActivity.currentInstance, false);
        pixelfedFullScreenMedia = sharedpreferences.getBoolean(context.getString(R.string.SET_PIXELFED_FULL_MEDIA) + MainActivity.currentUserID + MainActivity.currentInstance, true);
        if (viewType == STATUS_HIDDEN) { //Hidden statuses - ie: filtered
            DrawerStatusHiddenBinding itemBinding = DrawerStatusHiddenBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
            return new StatusViewHolder(itemBinding);
+89 −0
Original line number Diff line number Diff line
package app.fedilab.android.mastodon.ui.fragment.settings;
/* Copyright 2025 Thomas Schneider
 *
 * This file is a part of Fedilab
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation; either version 3 of the
 * License, or (at your option) any later version.
 *
 * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 * Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with Fedilab; if not,
 * see <http://www.gnu.org/licenses>. */

import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.os.Bundle;

import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager;
import androidx.preference.SwitchPreferenceCompat;

import app.fedilab.android.R;
import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.mastodon.helper.Helper;

public class FragmentPixelfedSettings extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {

    boolean recreate;

    @Override
    public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
        addPreferencesFromResource(R.xml.pref_pixelfed);
        createPref();
    }

    @SuppressLint("ApplySharedPref")
    private void createPref() {
        getPreferenceScreen().removeAll();
        SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
        addPreferencesFromResource(R.xml.pref_pixelfed);
        SwitchPreferenceCompat SET_PIXELFED_FULL_MEDIA = findPreference(getString(R.string.SET_PIXELFED_FULL_MEDIA));
        if (SET_PIXELFED_FULL_MEDIA != null) {
            boolean checked = sharedpreferences.getBoolean(getString(R.string.SET_PIXELFED_FULL_MEDIA) + MainActivity.currentUserID + MainActivity.currentInstance, false);
            SET_PIXELFED_FULL_MEDIA.setChecked(checked);
        }
        recreate = false;
    }

    @Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
        if (getActivity() != null) {
            SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
            SharedPreferences.Editor editor = sharedpreferences.edit();
            if (key.compareToIgnoreCase(getString(R.string.SET_PIXELFED_FULL_MEDIA)) == 0) {
                SwitchPreferenceCompat SET_PIXELFED_FULL_MEDIA = findPreference(getString(R.string.SET_PIXELFED_FULL_MEDIA));
                if (SET_PIXELFED_FULL_MEDIA != null) {
                    editor.putBoolean(getString(R.string.SET_PIXELFED_FULL_MEDIA) + MainActivity.currentUserID + MainActivity.currentInstance, SET_PIXELFED_FULL_MEDIA.isChecked());
                }
            }
            recreate = true;
            editor.apply();
        }
    }

    @Override
    public void onResume() {
        super.onResume();

        getPreferenceScreen().getSharedPreferences()
                .registerOnSharedPreferenceChangeListener(this);
    }

    @Override
    public void onPause() {
        super.onPause();
        getPreferenceScreen().getSharedPreferences()
                .unregisterOnSharedPreferenceChangeListener(this);
        if (recreate) {
            recreate = false;
            requireActivity().recreate();
            Helper.recreateMainActivity(requireActivity());
        }
    }


}
+8 −0
Original line number Diff line number Diff line
@@ -111,6 +111,14 @@ public class FragmentSettingsCategories extends PreferenceFragmentCompat {
                return false;
            });
        }
        Preference pref_category_key_pixelfed = findPreference(getString(R.string.pref_category_key_pixelfed));
        if (pref_category_key_pixelfed != null) {
            pref_category_key_pixelfed.setOnPreferenceClickListener(preference -> {
                NavController navController = Navigation.findNavController(requireActivity(), R.id.fragment_container);
                navController.navigate(FragmentSettingsCategoriesDirections.Companion.categoriesToPixelfed());
                return false;
            });
        }

        Preference pref_category_key_home_cache = findPreference(getString(R.string.pref_category_key_home_cache));
        if (pref_category_key_home_cache != null) {
+12 −0
Original line number Diff line number Diff line
@@ -52,6 +52,13 @@
            app:exitAnim="@anim/exit"
            app:popEnterAnim="@anim/pop_enter"
            app:popExitAnim="@anim/pop_exit" />
        <action
            android:id="@+id/categories_to_pixelfed"
            app:destination="@id/FragmentPixelfedSettings"
            app:enterAnim="@anim/enter"
            app:exitAnim="@anim/exit"
            app:popEnterAnim="@anim/pop_enter"
            app:popExitAnim="@anim/pop_exit" />

        <action
            android:id="@+id/categories_to_home_cache"
@@ -111,6 +118,11 @@
        android:name="app.fedilab.android.mastodon.ui.fragment.settings.FragmentPrivacySettings"
        android:label="@string/action_privacy" />

    <fragment
        android:id="@+id/FragmentPixelfedSettings"
        android:name="app.fedilab.android.mastodon.ui.fragment.settings.FragmentPixelfedSettings"
        android:label="PixelFed" />

    <fragment
        android:id="@+id/FragmentHomeCacheSettings"
        android:name="app.fedilab.android.mastodon.ui.fragment.settings.FragmentHomeCacheSettings"
+8 −0
Original line number Diff line number Diff line
@@ -254,6 +254,11 @@
    <string name="set_capitalize">First letter in capital for replies</string>
    <string name="set_resize_picture">Resize pictures</string>
    <string name="set_resize_video">Resize videos</string>


    <string name="set_pixelfed_full_media">Fullscreen media</string>
    <string name="set_pixelfed_full_media_indication">Medias will take the whole width of the screen and aspect ratio for the height will be respected.</string>

    <!-- Quick settings for notifications -->
    <!-- CACHE -->
    <string name="cache_units">Mb</string>
@@ -1162,6 +1167,8 @@

    <string name="SET_DISPLAY_BOOKMARK" translatable="false">SET_DISPLAY_BOOKMARK</string>
    <string name="SET_PIXELFED_PRESENTATION" translatable="false">SET_PIXELFED_PRESENTATION</string>
    <string name="SET_PIXELFED_FULL_MEDIA" translatable="false">SET_PIXELFED_FULL_MEDIA</string>

    <string name="SET_DISPLAY_QUOTES" translatable="false">SET_DISPLAY_QUOTES</string>
    <string name="SET_DISPLAY_REACTIONS" translatable="false">SET_DISPLAY_REACTIONS</string>

@@ -1728,6 +1735,7 @@
    <string name="pref_category_key_interface" translatable="false">pref_category_interface</string>
    <string name="pref_category_key_compose" translatable="false">pref_category_compose</string>
    <string name="pref_category_key_privacy" translatable="false">pref_category_privacy</string>
    <string name="pref_category_key_pixelfed" translatable="false">pref_category_key_pixelfed</string>
    <string name="pref_category_key_home_cache" translatable="false">pref_category_key_home_cache</string>
    <string name="pref_category_key_theming" translatable="false">pref_category_theming</string>
    <string name="pref_category_key_administration" translatable="false">pref_category_administration</string>
Loading