package com.bxj.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import com.alibaba.sdk.android.feedback.impl.FeedbackAPI;
import com.bxj.App;
import com.bxj.AppConstants;
import com.bxj.AppPreferences;
import com.bxj.R;
import com.bxj.activity.SettingActivity;
import com.bxj.common.BaseActivity;
import com.bxj.common.BaseFragment;
import com.bxj.utils.LogUtil;
import com.bxj.utils.StatServiceUtil;
import com.qihoo.updatesdk.lib.UpdateHelper;

/**
 * 1 在设置页面添加清除缓存功能 2 添加设置页面
 *
 * @author SunZhuo
 */
public class SlidingMenuRight extends BaseFragment implements OnClickListener{
    private TextView tv_download;
    private TextView tv_setting;
    private ImageView iv_setting_night;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_slidingright, null);
        view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.MATCH_PARENT));
        tv_download = (TextView) view.findViewById(R.id.tv_download);
        tv_setting = (TextView) view.findViewById(R.id.tv_setting);
        iv_setting_night = (ImageView) view.findViewById(R.id.iv_setting_night);
        tv_download.setOnClickListener(this);
        tv_setting.setOnClickListener(this);
        view.findViewById(R.id.feedback).setOnClickListener(this);
        view.findViewById(R.id.check_update).setOnClickListener(this);
        view.findViewById(R.id.setting_night).setOnClickListener(this);
        initBtn();
        return view;
    }

    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_setting:
                toSetting();
                break;
            case R.id.setting_night:
                clickNightMode();
                break;
            case R.id.check_update:
                checkUpdate();
                break;
            case R.id.feedback:
                settingFeedback();
                break;
            default:
                break;
        }
    }

    private void checkUpdate() {
        showProgressDialog("正在检查更新...");
        StatServiceUtil.trackEvent("检查更新");
        UpdateHelper.getInstance().manualUpdate(App.getContext().getPackageName());
    }

    /**
     * 意见反馈的点击事件
     */
    private void settingFeedback() {
        FeedbackAPI.openFeedbackActivity();
    }

    /**
     * 点击夜间模式的点击事件
     */
    private void clickNightMode() {
        AppConstants.SETTING_MODE_NIGHT = !AppConstants.SETTING_MODE_NIGHT;
        initBtn();
        AppPreferences.setSettingModeNight(AppConstants.SETTING_MODE_NIGHT);
        ((BaseActivity) getActivity()).setTheme();
        AppConstants.isNeedRestore = true;
        getActivity().finish();
        getActivity().overridePendingTransition(0, 0);
        Intent intent = getActivity().getIntent();
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        getActivity().startActivity(intent);
        if (AppConstants.SETTING_MODE_NIGHT) {
            LogUtil.s("夜间模式-开");
            StatServiceUtil.trackEvent("夜间模式-开");
        } else {
            StatServiceUtil.trackEvent("夜间模式-关");
        }
    }

    private void initBtn() {
        if (AppConstants.SETTING_MODE_NIGHT) {
            iv_setting_night.setBackgroundResource(R.drawable.setting_open);
        } else {
            iv_setting_night.setBackgroundResource(R.drawable.setting_close);
        }
    }

    /**
     * 跳转到设置界面
     */
    private void toSetting() {
        startActivity(new Intent(mContext, SettingActivity.class));
    }

}

@@ -714,66 +714,8 @@
 r;%0A%0A
-/**%0A * 1 %E5%9C%A8%E8%AE%BE%E7%BD%AE%E9%A1%B5%E9%9D%A2%E6%B7%BB%E5%8A%A0%E6%B8%85%E9%99%A4%E7%BC%93%E5%AD%98%E5%8A%9F%E8%83%BD 2 %E6%B7%BB%E5%8A%A0%E8%AE%BE%E7%BD%AE%E9%A1%B5%E9%9D%A2%0A *%0A * @author SunZhuo%0A */%0A
 publ
@@ -793,42 +793,8 @@
 er%7B%0A
-    private TextView tv_download;%0A
     
@@ -1208,78 +1208,8 @@
 ));%0A
-        tv_download = (TextView) view.findViewById(R.id.tv_download);%0A
     
@@ -1357,54 +1357,8 @@
 t);%0A
-        tv_download.setOnClickListener(this);%0A
     
@@ -1768,26 +1768,73 @@
         
-toSetting(
+startActivity(new Intent(mContext, SettingActivity.class)
 );%0A     
@@ -2083,31 +2083,24 @@
         
-setting
 Feedback
 ();%0A    
@@ -2091,16 +2091,40 @@
 Feedback
+API.openFeedbackActivity
 ();%0A    
@@ -2416,164 +2416,8 @@
  %7D%0A%0A
-    /**%0A     * %E6%84%8F%E8%A7%81%E5%8F%8D%E9%A6%88%E7%9A%84%E7%82%B9%E5%87%BB%E4%BA%8B%E4%BB%B6%0A     */%0A    private void settingFeedback() %7B%0A        FeedbackAPI.openFeedbackActivity();%0A    %7D%0A%0A    /**%0A     * %E7%82%B9%E5%87%BB%E5%A4%9C%E9%97%B4%E6%A8%A1%E5%BC%8F%E7%9A%84%E7%82%B9%E5%87%BB%E4%BA%8B%E4%BB%B6%0A     */%0A
     
@@ -3419,16 +3419,16 @@
 close);%0A
+
         
@@ -3440,143 +3440,6 @@
  %7D%0A%0A
-    /**%0A     * %E8%B7%B3%E8%BD%AC%E5%88%B0%E8%AE%BE%E7%BD%AE%E7%95%8C%E9%9D%A2%0A     */%0A    private void toSetting() %7B%0A        startActivity(new Intent(mContext, SettingActivity.class));%0A    %7D%0A%0A
 %7D%0A

refactor code