Search in sources :

Example 1 with SettingsFragment

use of com.ferg.awfulapp.preferences.fragments.SettingsFragment in project Awful.apk by Awful.

the class SettingsActivity method onSubmenuSelected.

@Override
public void onSubmenuSelected(@NonNull SettingsFragment sourceFragment, @NonNull String submenuFragmentName) {
    try {
        SettingsFragment fragment = (SettingsFragment) (Class.forName(submenuFragmentName).newInstance());
        boolean fromRootMenu = sourceFragment instanceof RootSettings;
        displayFragment(fragment, fromRootMenu);
    } catch (IllegalAccessException | ClassNotFoundException | InstantiationException e) {
        Timber.e(e, "Unable to create fragment (%s)", submenuFragmentName);
    }
}
Also used : SettingsFragment(com.ferg.awfulapp.preferences.fragments.SettingsFragment) RootSettings(com.ferg.awfulapp.preferences.fragments.RootSettings)

Example 2 with SettingsFragment

use of com.ferg.awfulapp.preferences.fragments.SettingsFragment in project Awful.apk by Awful.

the class SettingsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    prefs = AwfulPreferences.getInstance(this, this);
    currentThemeName = prefs.theme;
    updateTheme();
    // theme needs to be set BEFORE the super call, or it'll be inconsistent
    super.onCreate(savedInstanceState);
    setContentView(R.layout.settings);
    View leftPane = findViewById(R.id.root_fragment_container);
    if (leftPane != null && leftPane.getVisibility() == View.VISIBLE) {
        isDualPane = true;
    }
    FragmentManager fm = getFragmentManager();
    // we need to start with the root fragment, so it's always under the backstack
    if (savedInstanceState == null) {
        fm.beginTransaction().replace(R.id.main_fragment_container, new RootSettings(), ROOT_FRAGMENT_TAG).commit();
        fm.executePendingTransactions();
    }
    // hide the root fragment in dual-pane mode (there's a copy visible in the layout),
    // but make sure it's shown in single-pane (we might have switched from dual-pane)
    SettingsFragment fragment = (SettingsFragment) fm.findFragmentByTag(ROOT_FRAGMENT_TAG);
    if (fragment != null) {
        if (isDualPane) {
            fm.beginTransaction().hide(fragment).commit();
        } else {
            fm.beginTransaction().show(fragment).commit();
        }
    }
    Toolbar toolbar = (Toolbar) findViewById(R.id.awful_toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    updateTitleBar();
}
Also used : FragmentManager(android.app.FragmentManager) SettingsFragment(com.ferg.awfulapp.preferences.fragments.SettingsFragment) RootSettings(com.ferg.awfulapp.preferences.fragments.RootSettings) View(android.view.View) Toolbar(android.support.v7.widget.Toolbar)

Example 3 with SettingsFragment

use of com.ferg.awfulapp.preferences.fragments.SettingsFragment in project Awful.apk by Awful.

the class SettingsActivity method updateTitleBar.

/**
 * Update the action bar's title according to what's being displayed.
 * <p>
 * Call this whenever the layout or fragment stack changes.
 */
private void updateTitleBar() {
    ActionBar actionBar = getSupportActionBar();
    if (actionBar == null) {
        return;
    }
    FragmentManager fm = getFragmentManager();
    // make sure fragment transactions are finished before we poke around in there
    fm.executePendingTransactions();
    // if there's a submenu fragment present, get the title from that
    // need to check #isAdded because popping the last submenu fragment off the backstack doesn't immediately remove it from the manager,
    // i.e. the find call won't return null (but it will later - this was fun to troubleshoot)
    Fragment fragment = fm.findFragmentByTag(SUBMENU_FRAGMENT_TAG);
    if (fragment == null || !fragment.isAdded()) {
        fragment = fm.findFragmentByTag(ROOT_FRAGMENT_TAG);
    }
    actionBar.setTitle(((SettingsFragment) fragment).getTitle());
}
Also used : FragmentManager(android.app.FragmentManager) SettingsFragment(com.ferg.awfulapp.preferences.fragments.SettingsFragment) Fragment(android.app.Fragment) ActionBar(android.support.v7.app.ActionBar)

Example 4 with SettingsFragment

use of com.ferg.awfulapp.preferences.fragments.SettingsFragment in project Awful.apk by Awful.

the class SettingsActivity method onPreferenceChange.

@Override
public void onPreferenceChange(AwfulPreferences preferences, String key) {
    // update the summaries on any loaded fragments
    for (String tag : new String[] { ROOT_FRAGMENT_TAG, SUBMENU_FRAGMENT_TAG }) {
        SettingsFragment fragment = (SettingsFragment) getFragmentManager().findFragmentByTag(tag);
        if (fragment != null) {
            fragment.setSummaries();
        }
    }
    if (!getMPrefs().theme.equals(this.currentThemeName)) {
        this.currentThemeName = getMPrefs().theme;
        updateTheme();
        recreate();
    }
}
Also used : SettingsFragment(com.ferg.awfulapp.preferences.fragments.SettingsFragment)

Aggregations

SettingsFragment (com.ferg.awfulapp.preferences.fragments.SettingsFragment)4 FragmentManager (android.app.FragmentManager)2 RootSettings (com.ferg.awfulapp.preferences.fragments.RootSettings)2 Fragment (android.app.Fragment)1 ActionBar (android.support.v7.app.ActionBar)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1