From c40ab5711d9025a5e25a85b5b24be72cfa90e375 Mon Sep 17 00:00:00 2001
From: 陈奇 <1650699704@qq.com>
Date: Fri, 30 Nov 2018 11:34:33 +0800
Subject: [PATCH] [*]修改页面动画

---
 app/src/main/java/com/moral/yunfushao/fragment/FragmentSettings.java |  278 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 276 insertions(+), 2 deletions(-)

diff --git a/app/src/main/java/com/moral/yunfushao/fragment/FragmentSettings.java b/app/src/main/java/com/moral/yunfushao/fragment/FragmentSettings.java
index 6959678..2f6d26f 100644
--- a/app/src/main/java/com/moral/yunfushao/fragment/FragmentSettings.java
+++ b/app/src/main/java/com/moral/yunfushao/fragment/FragmentSettings.java
@@ -1,15 +1,42 @@
 package com.moral.yunfushao.fragment;
 
+import android.app.AlertDialog;
+import android.content.DialogInterface;
 import android.content.Intent;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.support.v7.widget.SwitchCompat;
 import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.ListView;
 import android.widget.RelativeLayout;
+import android.widget.TextView;
 
 import com.bigkoo.pickerview.OptionsPickerView;
+import com.lzy.okgo.cache.CacheMode;
+import com.moral.andbrickslib.utils.ActivityManager;
+import com.moral.andbrickslib.utils.FastJsonTools;
+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.TestActivity;
 import com.moral.yunfushao.activity.VoiceSetActivity;
 import com.moral.yunfushao.base.BaseFragment;
+import com.moral.yunfushao.common.API;
+import com.moral.yunfushao.common.AppConfig;
+import com.moral.yunfushao.httputils.HttpCallBack;
+import com.moral.yunfushao.httputils.HttpUtils;
+import com.moral.yunfushao.model.EventMessage;
+import com.moral.yunfushao.model.VoiceBean;
+
+import org.greenrobot.eventbus.EventBus;
 
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * ������������
@@ -17,7 +44,12 @@
  */
 
 public class FragmentSettings extends BaseFragment {
-    private RelativeLayout rl_setvoice,rl_refresh;
+    private TextView tv_version;
+    private RelativeLayout rl_setvoice, rl_refresh;
+    private Button bt_sure;
+    private Button bt_look, sc_male;
+    private SwitchCompat sc_open;
+    private int refreshIndex = 0;
 
     @Override
     protected int getLayoutId() {
@@ -28,12 +60,140 @@
     protected void initViews() {
         rl_setvoice = findView(R.id.rl_setvoice);
         rl_refresh = findView(R.id.rl_refresh);
+        bt_sure = findView(R.id.bt_sure);
+        bt_look = findView(R.id.bt_look);
+        sc_open = findView(R.id.sc_open);
+        sc_male = findView(R.id.sc_male);
+        tv_version = findView(R.id.tv_version);
+        tv_version.setText("������������V" + getVersion());
+        bt_look.setVisibility(View.GONE);
     }
 
     @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");
+                }
+            }
+        });
+
+        sc_male.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                chooseSoundCategory();
+            }
+        });
+
+        bt_look.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                Intent intent = new Intent(getActivity(), TestActivity.class);
+                startActivity(intent);
+            }
+        });
+    }
+
+    @Override
+    public void onResume() {
+        super.onResume();
+        switch (MainApp.theApp.sharedPreferencesUtil.getVoiceType()) {
+            case 0:
+                sc_male.setText("������");
+                break;
+            case 1:
+                sc_male.setText("������");
+                break;
+            case 2:
+                sc_male.setText("������");
+                break;
+            case 3:
+                sc_male.setText("���������");
+                break;
+        }
+    }
+
+    /**
+     * ���������������������
+     */
+    private void chooseSoundCategory() {
+        final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+        ListView listView = new ListView(getActivity());
+        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getActivity(),
+                android.R.layout.simple_expandable_list_item_1,
+                new String[]{"������", "������", "������"});
+        listView.setAdapter(arrayAdapter);
+        builder.setTitle("������������������!");
+        builder.setIcon(R.mipmap.icon_voice);
+        builder.setView(listView);
+        final AlertDialog alertDialog = builder.create();
+        alertDialog.show();
+        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+            @Override
+            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+                alertDialog.dismiss();
+                ejectTips(position);
+            }
+        });
+    }
+
+    /**
+     * ���������������������
+     */
+    private void ejectTips(final int position) {
+        final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+        builder.setTitle("���������������");
+
+        builder.setMessage("������������������������������������������������������������������������");
+        builder.setNegativeButton("������", new DialogInterface.OnClickListener() {
+            @Override
+            public void onClick(DialogInterface dialog, int which) {
+                dialog.dismiss();
+                setUpDefaultRingtone(position);
+            }
+        });
+        builder.setPositiveButton("������", new DialogInterface.OnClickListener() {
+            @Override
+            public void onClick(DialogInterface dialog, int which) {
+                dialog.dismiss();
+            }
+        });
+        final AlertDialog alertDialog = builder.create();
+        alertDialog.show();
+    }
+
+    private void setUpDefaultRingtone(int type) {
+        switch (type) {
+            case 0:
+                sc_male.setText("������");
+                MainApp.theApp.sharedPreferencesUtil.saveVoiceType(0);
+                AppConfig.voideUrl1 = "http://yfsapi.7drlb.com/video/boy/music.mp3";
+                AppConfig.voideUrl2 = "http://yfsapi.7drlb.com/video/boy/music1.mp3";
+                AppConfig.voideUrl3 = "http://yfsapi.7drlb.com/video/boy/music2.mp3";
+                break;
+            case 1:
+                sc_male.setText("������");
+                MainApp.theApp.sharedPreferencesUtil.saveVoiceType(1);
+                AppConfig.voideUrl1 = "http://yfsapi.7drlb.com/video/girl/music.mp3";
+                AppConfig.voideUrl2 = "http://yfsapi.7drlb.com/video/girl/music1.mp3";
+                AppConfig.voideUrl3 = "http://yfsapi.7drlb.com/video/girl/music2.mp3";
+                break;
+            case 2:
+                sc_male.setText("������");
+                MainApp.theApp.sharedPreferencesUtil.saveVoiceType(2);
+                AppConfig.voideUrl1 = null;
+                AppConfig.voideUrl2 = null;
+                AppConfig.voideUrl3 = null;
+                break;
+        }
+        reset();
     }
 
     @Override
@@ -41,6 +201,20 @@
         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
@@ -52,6 +226,13 @@
                 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;
         }
 
@@ -68,10 +249,103 @@
         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));
+                }
+                EventMessage event = new EventMessage();
+                event.setType(AppConfig.CHANGE_SETTING);
+                EventBus.getDefault().post(event);
+                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();
+                }
+            }
+        });
+    }
+
+    /**
+     * ���������������
+     *
+     * @return ������������������������
+     */
+    public String getVersion() {
+        try {
+            PackageManager manager = getActivity().getPackageManager();
+            PackageInfo info = manager.getPackageInfo(getActivity().getPackageName(), 0);
+            String version = info.versionName;
+            return version;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return "1.0";
+        }
+    }
+
+    private ArrayList<VoiceBean> voiceList = new ArrayList<>();
+
+    private void reset() {
+        voiceList.clear();
+        VoiceBean voiceBean = new VoiceBean();
+        voiceBean.setId(0);
+        voiceBean.setRes(AppConfig.voideUrl1);
+        voiceBean.setName("������������������");
+        voiceBean.setVoiceName("������");
+        voiceList.add(voiceBean);
+        voiceBean = new VoiceBean();
+        voiceBean.setId(1);
+        voiceBean.setRes(AppConfig.voideUrl2);
+        voiceBean.setName("������������������");
+        voiceBean.setVoiceName("������");
+        voiceList.add(voiceBean);
+        voiceBean = new VoiceBean();
+        voiceBean.setId(2);
+        voiceBean.setRes(AppConfig.voideUrl3);
+        voiceBean.setName("������������������");
+        voiceBean.setVoiceName("������");
+        voiceList.add(voiceBean);
+        MainApp.theApp.sharedPreferencesUtil.saveVideoList(FastJsonTools.toJson(voiceList));
+        EventMessage eventMessage = new EventMessage();
+        eventMessage.setType(AppConfig.SET_VOICE);
+        EventBus.getDefault().post(eventMessage);
+        mToatUtils.showSingleLongToast("������������������");
+    }
 }

--
Gitblit v1.8.0