Search in sources :

Example 1 with ChangeCityEvent

use of com.xiecc.seeWeather.modules.main.domain.ChangeCityEvent in project SeeWeather by xcc3641.

the class SettingFragment method showIconDialog.

private void showIconDialog() {
    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View dialogLayout = inflater.inflate(R.layout.dialog_icon, (ViewGroup) getActivity().findViewById(R.id.dialog_root));
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setView(dialogLayout);
    final AlertDialog alertDialog = builder.create();
    LinearLayout layoutTypeOne = (LinearLayout) dialogLayout.findViewById(R.id.layout_one);
    layoutTypeOne.setClickable(true);
    RadioButton radioTypeOne = (RadioButton) dialogLayout.findViewById(R.id.radio_one);
    LinearLayout layoutTypeTwo = (LinearLayout) dialogLayout.findViewById(R.id.layout_two);
    layoutTypeTwo.setClickable(true);
    RadioButton radioTypeTwo = (RadioButton) dialogLayout.findViewById(R.id.radio_two);
    TextView done = (TextView) dialogLayout.findViewById(R.id.done);
    radioTypeOne.setClickable(false);
    radioTypeTwo.setClickable(false);
    alertDialog.show();
    switch(mSharedPreferenceUtil.getIconType()) {
        case 0:
            radioTypeOne.setChecked(true);
            radioTypeTwo.setChecked(false);
            break;
        case 1:
            radioTypeOne.setChecked(false);
            radioTypeTwo.setChecked(true);
            break;
    }
    layoutTypeOne.setOnClickListener(v -> {
        radioTypeOne.setChecked(true);
        radioTypeTwo.setChecked(false);
    });
    layoutTypeTwo.setOnClickListener(v -> {
        radioTypeOne.setChecked(false);
        radioTypeTwo.setChecked(true);
    });
    done.setOnClickListener(v -> {
        mSharedPreferenceUtil.setIconType(radioTypeOne.isChecked() ? 0 : 1);
        String[] iconsText = getResources().getStringArray(R.array.icons);
        mChangeIcons.setSummary(radioTypeOne.isChecked() ? iconsText[0] : iconsText[1]);
        alertDialog.dismiss();
        Snackbar.make(getView(), "切换成功,重启应用生效", Snackbar.LENGTH_INDEFINITE).setAction("重启", v1 -> {
            Intent intent = new Intent(getActivity(), MainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            getActivity().startActivity(intent);
            getActivity().finish();
            RxBus.getDefault().post(new ChangeCityEvent());
        }).show();
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Context(android.content.Context) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) SharedPreferenceUtil(com.xiecc.seeWeather.common.utils.SharedPreferenceUtil) RadioButton(android.widget.RadioButton) Watcher(com.hugo.watcher.Watcher) R(com.xiecc.seeWeather.R) BaseApplication(com.xiecc.seeWeather.base.BaseApplication) C(com.xiecc.seeWeather.common.C) Intent(android.content.Intent) CheckBoxPreference(android.preference.CheckBoxPreference) SeekBar(android.widget.SeekBar) Locale(java.util.Locale) RxUtil(com.xiecc.seeWeather.common.utils.RxUtil) ImageLoader(com.xiecc.seeWeather.component.ImageLoader) View(android.view.View) Settings(android.provider.Settings) Observable(io.reactivex.Observable) Build(android.os.Build) RxBus(com.xiecc.seeWeather.component.RxBus) AutoUpdateService(com.xiecc.seeWeather.modules.service.AutoUpdateService) LayoutInflater(android.view.LayoutInflater) ChangeCityEvent(com.xiecc.seeWeather.modules.main.domain.ChangeCityEvent) MainActivity(com.xiecc.seeWeather.modules.main.ui.MainActivity) ViewGroup(android.view.ViewGroup) File(java.io.File) AlertDialog(android.support.v7.app.AlertDialog) TextView(android.widget.TextView) FileUtil(com.xiecc.seeWeather.common.utils.FileUtil) Preference(android.preference.Preference) PreferenceFragment(android.preference.PreferenceFragment) Notification(android.app.Notification) Snackbar(android.support.design.widget.Snackbar) FileSizeUtil(com.xiecc.seeWeather.common.utils.FileSizeUtil) Intent(android.content.Intent) RadioButton(android.widget.RadioButton) MainActivity(com.xiecc.seeWeather.modules.main.ui.MainActivity) ChangeCityEvent(com.xiecc.seeWeather.modules.main.domain.ChangeCityEvent) View(android.view.View) TextView(android.widget.TextView) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 2 with ChangeCityEvent

use of com.xiecc.seeWeather.modules.main.domain.ChangeCityEvent in project SeeWeather by xcc3641.

the class ChoiceCityActivity method initRecyclerView.

private void initRecyclerView() {
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mRecyclerView.setHasFixedSize(true);
    mAdapter = new CityAdapter(this, dataList);
    mRecyclerView.setAdapter(mAdapter);
    mAdapter.setOnItemClickListener((view, pos) -> {
        if (currentLevel == LEVEL_PROVINCE) {
            selectedProvince = provincesList.get(pos);
            mRecyclerView.smoothScrollToPosition(0);
            queryCities();
        } else if (currentLevel == LEVEL_CITY) {
            String city = Util.replaceCity(cityList.get(pos).mCityName);
            if (isChecked) {
                OrmLite.getInstance().save(new CityORM(city));
                RxBus.getDefault().post(new MultiUpdateEvent());
            } else {
                SharedPreferenceUtil.getInstance().setCityName(city);
                RxBus.getDefault().post(new ChangeCityEvent());
            }
            quit();
        }
    });
}
Also used : CityORM(com.xiecc.seeWeather.modules.main.domain.CityORM) MultiUpdateEvent(com.xiecc.seeWeather.modules.main.domain.MultiUpdateEvent) CityAdapter(com.xiecc.seeWeather.modules.city.adapter.CityAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ChangeCityEvent(com.xiecc.seeWeather.modules.main.domain.ChangeCityEvent)

Aggregations

ChangeCityEvent (com.xiecc.seeWeather.modules.main.domain.ChangeCityEvent)2 Notification (android.app.Notification)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 CheckBoxPreference (android.preference.CheckBoxPreference)1 Preference (android.preference.Preference)1 PreferenceFragment (android.preference.PreferenceFragment)1 Settings (android.provider.Settings)1 Snackbar (android.support.design.widget.Snackbar)1 AlertDialog (android.support.v7.app.AlertDialog)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 LinearLayout (android.widget.LinearLayout)1 RadioButton (android.widget.RadioButton)1 SeekBar (android.widget.SeekBar)1 TextView (android.widget.TextView)1