package com.didichuxing.doraemonkit.kit.parameter.frameInfo;

import android.os.Bundle;
import android.view.View;

import com.didichuxing.doraemonkit.R;
import com.didichuxing.doraemonkit.config.PerformanceInfoConfig;
import com.didichuxing.doraemonkit.constant.BundleKey;
import com.didichuxing.doraemonkit.kit.parameter.AbsParameterFragment;
import com.didichuxing.doraemonkit.kit.common.PerformanceDataManager;
import com.didichuxing.doraemonkit.kit.common.PerformanceFragment;
import com.didichuxing.doraemonkit.ui.realtime.datasource.DataSourceFactory;
import com.didichuxing.doraemonkit.ui.setting.SettingItem;
import com.didichuxing.doraemonkit.ui.setting.SettingItemAdapter;

import java.util.Collection;
import java.util.List;

/**
 * Created by wanglikun on 2018/9/13.
 */

public class FrameInfoFragment extends AbsParameterFragment {

    @Override
    protected int getTitle() {
        return R.string.dk_kit_frame_info_desc;
    }

    @Override
    protected Collection<SettingItem> getSettingItems(List<SettingItem> list) {
        list.add(new SettingItem(R.string.dk_frameinfo_detection_switch, false));
        list.add(new SettingItem(R.string.dk_item_cache_log, R.drawable.dk_more_icon));
        return list;
    }

    @Override
    protected SettingItemAdapter.OnSettingItemSwitchListener getItemSwitchListener() {
        return new SettingItemAdapter.OnSettingItemSwitchListener() {
            @Override
            public void onSettingItemSwitch(View view, SettingItem data, boolean on) {
                if (on) {
                    startMonitor();
                } else {
                    stopMonitor();
                }
//                PerformanceInfoConfig.setFPSOpen(getContext(), on);
            }
        };
    }

    @Override
    protected SettingItemAdapter.OnSettingItemClickListener getItemClickListener() {
        return new SettingItemAdapter.OnSettingItemClickListener() {
            @Override
            public void onSettingItemClick(View view, SettingItem data) {
                if (data.desc == R.string.dk_item_cache_log) {

                    Bundle bundle = new Bundle();
                    bundle.putInt(BundleKey.PERFORMANCE_TYPE, PerformanceFragment.FPS);
                    showContent(PerformanceFragment.class, bundle);
                }

            }
        };
    }

    private void startMonitor() {
        PerformanceDataManager.getInstance().startMonitorFrameInfo();
        openChartPage(R.string.dk_frameinfo_fps, DataSourceFactory.TYPE_FRAME);
    }

    private void stopMonitor() {
        PerformanceDataManager.getInstance().stopMonitorFrameInfo();
        closeChartPage();
    }

}
@@ -100,121 +100,104 @@
 oid.
-view.View;%0A%0Aimport com.didichuxing.doraemonkit.R;%0Aimport com.didichuxing.doraemonkit.config.PerformanceInfoConfig
+support.annotation.NonNull;%0Aimport android.support.annotation.Nullable;%0Aimport android.view.View
 ;%0Aim
@@ -233,26 +233,9 @@
 kit.
-constant.BundleKey
+R
 ;%0Aim
@@ -271,42 +271,26 @@
 kit.
-kit.parameter.AbsParameterFragment
+constant.BundleKey
 ;%0Aim
@@ -424,16 +424,87 @@
 agment;%0A
+import com.didichuxing.doraemonkit.kit.parameter.AbsParameterFragment;%0A
 import c
@@ -697,17 +697,16 @@
 dapter;%0A
-%0A
 import j
@@ -856,24 +856,278 @@
 Fragment %7B%0A%0A
+    @Override%0A    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) %7B%0A        super.onViewCreated(view, savedInstanceState);%0A        PerformanceDataManager.getInstance().init(getContext().getApplicationContext());%0A    %7D%0A%0A
     @Overrid
@@ -2940,8 +2940,9 @@
     %7D%0A%0A%7D
+%0A

修复帧率Fragment 不能保存数据问题