Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 63ad2982 authored by Mark Harman's avatar Mark Harman Committed by Mohammed Althaf T
Browse files

Switch to using separate PreferenceScreens (so we can later move to AndroidX preference ibrary).

parent f0a4c738
Loading
Loading
Loading
Loading
+47 −1
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ import androidx.appcompat.app.AppCompatActivity;

/** The main Activity for Open Camera.
 */
public class MainActivity extends AppCompatActivity {
public class MainActivity extends AppCompatActivity implements PreferenceFragment.OnPreferenceStartFragmentCallback {
    private static final String TAG = "MainActivity";

    private static int activity_count = 0;
@@ -3331,6 +3331,45 @@ public class MainActivity extends AppCompatActivity {
        editor.apply();
    }

    @Override
    public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
        if( MyDebug.LOG ) {
            Log.d(TAG, "onPreferenceStartFragment");
            Log.d(TAG, "pref: " + pref.getFragment());
        }

        // instantiate the new fragment
        //final Bundle args = pref.getExtras();
        // we want to pass the caller preference fragment's bundle to the new sub-screen (this will be a
        // copy of the bundle originally created in openSettings()
        final Bundle args = new Bundle(caller.getArguments());

        final Fragment fragment = Fragment.instantiate(this, pref.getFragment(), args);
        fragment.setTargetFragment(caller, 0);
        if( MyDebug.LOG )
            Log.d(TAG, "replace fragment");
        /*getFragmentManager().beginTransaction()
                .replace(R.id.content, fragment)
                .addToBackStack(null)
                .commit();*/
        getFragmentManager().beginTransaction().add(android.R.id.content, fragment, "PREFERENCE_FRAGMENT_"+pref.getFragment()).addToBackStack(null).commitAllowingStateLoss();

        /*
        // AndroidX version:
        final Fragment fragment = getSupportFragmentManager().getFragmentFactory().instantiate(
                getClassLoader(),
                pref.getFragment());
        fragment.setArguments(args);
        fragment.setTargetFragment(caller, 0);
        // replace the existing fragment with the new fragment:
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.content, fragment)
                .addToBackStack(null)
                .commit();
         */
        return true;
    }

    public void updateForSettings(boolean update_camera) {
        updateForSettings(update_camera, null);
    }
@@ -3689,6 +3728,13 @@ public class MainActivity extends AppCompatActivity {
        }
    }

    public boolean isSettingsOnBackPressedCallbackEnabled() {
        if( settingsOnBackPressedCallback != null ) {
            return settingsOnBackPressedCallback.isEnabled();
        }
        return false;
    }

    public void enableSettingsOnBackPressedCallback(boolean enabled) {
        if( MyDebug.LOG )
            Log.d(TAG, "enableSettingsOnBackPressedCallback: " + enabled);
Loading