Search in sources :

Example 1 with SettingsFragment

use of com.naman14.timber.fragments.SettingsFragment in project Timber by naman14.

the class LastFmLoginDialog method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new MaterialDialog.Builder(getActivity()).positiveText("Login").negativeText("Cancel").title("Login to LastFM").customView(R.layout.dialog_lastfm_login, false).onPositive(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            String username = ((EditText) dialog.findViewById(R.id.lastfm_username)).getText().toString();
            String password = ((EditText) dialog.findViewById(R.id.lastfm_password)).getText().toString();
            if (username.length() == 0 || password.length() == 0)
                return;
            final ProgressDialog progressDialog = new ProgressDialog(getActivity());
            progressDialog.setMessage("Logging in..");
            progressDialog.show();
            LastFmClient.getInstance(getActivity()).getUserLoginInfo(new UserLoginQuery(username, password), new UserListener() {

                @Override
                public void userSuccess() {
                    progressDialog.dismiss();
                    if (getTargetFragment() instanceof SettingsFragment) {
                        ((SettingsFragment) getTargetFragment()).updateLastFM();
                    }
                }

                @Override
                public void userInfoFailed() {
                    progressDialog.dismiss();
                    Toast.makeText(getTargetFragment().getActivity(), "Failed to Login", Toast.LENGTH_SHORT).show();
                }
            });
        }
    }).build();
}
Also used : SettingsFragment(com.naman14.timber.fragments.SettingsFragment) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) UserLoginQuery(com.naman14.timber.lastfmapi.models.UserLoginQuery) ProgressDialog(android.app.ProgressDialog) UserListener(com.naman14.timber.lastfmapi.callbacks.UserListener)

Example 2 with SettingsFragment

use of com.naman14.timber.fragments.SettingsFragment in project Timber by naman14.

the class SettingsActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    if (PreferencesUtility.getInstance(this).getTheme().equals("dark"))
        setTheme(R.style.AppThemeNormalDark);
    else if (PreferencesUtility.getInstance(this).getTheme().equals("black"))
        setTheme(R.style.AppThemeNormalBlack);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    action = getIntent().getAction();
    if (action.equals(Constants.SETTINGS_STYLE_SELECTOR)) {
        getSupportActionBar().setTitle(R.string.now_playing);
        String what = getIntent().getExtras().getString(Constants.SETTINGS_STYLE_SELECTOR_WHAT);
        Fragment fragment = StyleSelectorFragment.newInstance(what);
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().add(R.id.fragment_container, fragment).commit();
    } else {
        getSupportActionBar().setTitle(R.string.settings);
        PreferenceFragment fragment = new SettingsFragment();
        android.app.FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.fragment_container, fragment).commit();
    }
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) SettingsFragment(com.naman14.timber.fragments.SettingsFragment) PreferenceFragment(android.preference.PreferenceFragment) Fragment(android.support.v4.app.Fragment) StyleSelectorFragment(com.naman14.timber.subfragments.StyleSelectorFragment) PreferenceFragment(android.preference.PreferenceFragment) SettingsFragment(com.naman14.timber.fragments.SettingsFragment) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

SettingsFragment (com.naman14.timber.fragments.SettingsFragment)2 ProgressDialog (android.app.ProgressDialog)1 PreferenceFragment (android.preference.PreferenceFragment)1 NonNull (android.support.annotation.NonNull)1 Fragment (android.support.v4.app.Fragment)1 FragmentManager (android.support.v4.app.FragmentManager)1 Toolbar (android.support.v7.widget.Toolbar)1 DialogAction (com.afollestad.materialdialogs.DialogAction)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 UserListener (com.naman14.timber.lastfmapi.callbacks.UserListener)1 UserLoginQuery (com.naman14.timber.lastfmapi.models.UserLoginQuery)1 StyleSelectorFragment (com.naman14.timber.subfragments.StyleSelectorFragment)1