| | |
| | | package com.moral.yunfushao.fragment; |
| | | |
| | | import android.content.Intent; |
| | | import android.support.v7.widget.SwitchCompat; |
| | | import android.view.View; |
| | | import android.widget.Button; |
| | | import android.widget.RelativeLayout; |
| | | |
| | | import com.bigkoo.pickerview.OptionsPickerView; |
| | | import com.lzy.okgo.cache.CacheMode; |
| | | import com.moral.andbrickslib.utils.ActivityManager; |
| | | import com.moral.yunfushao.MainActivity; |
| | | import com.moral.yunfushao.MainApp; |
| | | import com.moral.yunfushao.R; |
| | | import com.moral.yunfushao.activity.LoginActivity; |
| | | import com.moral.yunfushao.activity.VoiceSetActivity; |
| | | import com.moral.yunfushao.base.BaseFragment; |
| | | import com.moral.yunfushao.common.API; |
| | | import com.moral.yunfushao.httputils.HttpCallBack; |
| | | import com.moral.yunfushao.httputils.HttpUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 设置界面 |
| | |
| | | |
| | | public class FragmentSettings extends BaseFragment { |
| | | private RelativeLayout rl_setvoice,rl_refresh; |
| | | |
| | | private Button bt_sure; |
| | | private SwitchCompat sc_open; |
| | | private int refreshIndex=0; |
| | | @Override |
| | | protected int getLayoutId() { |
| | | return R.layout.fragment_setting_layout; |
| | |
| | | protected void initViews() { |
| | | rl_setvoice = findView(R.id.rl_setvoice); |
| | | rl_refresh = findView(R.id.rl_refresh); |
| | | bt_sure = findView(R.id.bt_sure); |
| | | sc_open = findView(R.id.sc_open); |
| | | } |
| | | |
| | | @Override |
| | | protected void initListener() { |
| | | rl_setvoice.setOnClickListener(this); |
| | | rl_refresh.setOnClickListener(this); |
| | | bt_sure.setOnClickListener(this); |
| | | sc_open.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View view) { |
| | | if(sc_open.isChecked()){ |
| | | update("is_open_upload","1"); |
| | | }else{ |
| | | update("is_open_upload","0"); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | |
| | | timeList.add("10s"); |
| | | timeList.add("20s"); |
| | | timeList.add("30s"); |
| | | int open = MainApp.theApp.sharedPreferencesUtil.getLoginInfo().getIs_open_upload(); |
| | | if(open == 0){ |
| | | sc_open.setChecked(false); |
| | | }else{ |
| | | sc_open.setChecked(true); |
| | | } |
| | | int refresh = MainApp.theApp.sharedPreferencesUtil.getLoginInfo().getRefresh_frequency(); |
| | | if(refresh == 10){ |
| | | refreshIndex = 0; |
| | | }else if(refresh == 20){ |
| | | refreshIndex = 1; |
| | | }else if(refresh == 30){ |
| | | refreshIndex = 2; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | break; |
| | | case R.id.rl_refresh: |
| | | initDialog(); |
| | | break; |
| | | case R.id.bt_sure: |
| | | MainApp.theApp.sharedPreferencesUtil.exitLogin(); |
| | | Intent intent1 = new Intent(); |
| | | intent1.setClass(getActivity(), LoginActivity.class); |
| | | startActivity(intent1); |
| | | ActivityManager.getActivityManager().finishActivity(MainActivity.class); |
| | | break; |
| | | } |
| | | |
| | |
| | | OptionsPickerView<String> sexView = new OptionsPickerView.Builder(getActivity(), new OptionsPickerView.OnOptionsSelectListener() { |
| | | @Override |
| | | public void onOptionsSelect(int options1, int options2, int options3, View v) { |
| | | |
| | | refreshIndex = options1; |
| | | update("refresh_frequency",(options1+1)*10+""); |
| | | } |
| | | }).setOutSideCancelable(true).build(); |
| | | sexView.setSelectOptions(refreshIndex); |
| | | sexView.setPicker(timeList); |
| | | sexView.show(); |
| | | } |
| | | |
| | | /** |
| | | * 字段名称,目前仅支持修改['refresh_frequency', 'video', 'is_open_upload'] |
| | | * @param field |
| | | * @param value |
| | | */ |
| | | private void update(final String field, final String value) { |
| | | Map<String, String> params = new HashMap<>(); |
| | | params.put("user_id", MainApp.userId); |
| | | params.put("field", field); |
| | | params.put("value", value); |
| | | String url = API.UPDATEUSERINFO; |
| | | HttpUtils.doPost(url, params, CacheMode.DEFAULT, true, new HttpCallBack() { |
| | | @Override |
| | | public void onSuccess(String res, String msg) { |
| | | mToatUtils.showSingletonToast(msg); |
| | | if("refresh_frequency".equals(field)){ |
| | | MainApp.theApp.sharedPreferencesUtil.setRefreh(Integer.parseInt(value)); |
| | | }else if("is_open_upload".equals(field)){ |
| | | MainApp.theApp.sharedPreferencesUtil.setUpload(Integer.parseInt(value)); |
| | | } |
| | | |
| | | if (progressDialog.isShowing()) { |
| | | progressDialog.dismiss(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void showLoadingDialog() { |
| | | progressDialog.setTitleText("提交中..."); |
| | | progressDialog.show(); |
| | | } |
| | | |
| | | @Override |
| | | public void onFail(int errno,String s) { |
| | | mToatUtils.showSingletonToast(s); |
| | | if (progressDialog.isShowing()) { |
| | | progressDialog.dismiss(); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | } |