/**
 * 录像查询 Helper
 * 从 EZPlayBackListActivity 拆分出来，负责录像列表查询、Tab切换、列表展示、空状态、SD卡封面获取等逻辑
 */
package com.videogo.ui.playback.helper;

import android.graphics.Bitmap;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.videogo.openapi.EZConstants;
import com.videogo.openapi.EzvizAPI;
import com.videogo.openapi.bean.resp.CloudPartInfoFile;
import com.videogo.ui.common.EZBusinessTool;
import com.videogo.ui.playback.EZPlayBackListActivity;
import com.videogo.ui.playback.RemoteListContant;
import com.videogo.ui.playback.RemoteListUtil;
import com.videogo.ui.playback.bean.ClickedListItem;
import com.videogo.ui.playback.querylist.QueryCloudRecordFilesAsyncTask;
import com.videogo.ui.playback.querylist.QueryDeviceRecordFilesAsyncTask;
import com.videogo.ui.playback.querylist.QueryPlayBackListTaskCallback;
import com.videogo.ui.playback.querylist.QuerySDKCloudRecordFilesAsyncTask;
import com.videogo.ui.playback.querylist.RecordRecyclerAdapter;
import com.videogo.util.Utils;
import com.videogo.widget.CheckTextButton;
import com.videogo.widget.loading.LoadingTextView;
import com.videogo.widget.toprightmenu.EZMenuItem;
import com.videogo.widget.toprightmenu.EZTopRightMenu;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import ezviz.ezopensdk.R;

/**
 * 录像查询 Helper
 * 管理录像列表查询（云存储/云录制/SD卡）、Tab切换、查询结果展示、空状态、SD卡封面获取
 * <p>
 * 直接持有 Activity 引用，生命周期与 Activity 一致
 */
public class RecordQueryHelper implements QueryPlayBackListTaskCallback {

    private static final String TAG = "RecordQueryHelper";

    // 云存储RecyclerView & 适配器
    private RecyclerView mRecyclerViewForCloud;
    private RecordRecyclerAdapter mCloudRecordsAdapter;
    // 云录制RecyclerView & 适配器
    private RecyclerView mRecyclerViewForSDKCloud;
    private RecordRecyclerAdapter mSDKCloudRecordsAdapter;
    // SD卡录像RecyclerView & 适配器
    private RecyclerView mRecyclerViewForLocal;
    private RecordRecyclerAdapter mDeviceRecordsAdapter;
    // 列表查询task(云存储)
    private QueryCloudRecordFilesAsyncTask queryCloudRecordFilesAsyncTask;
    // 列表查询task(云录制)
    private QuerySDKCloudRecordFilesAsyncTask querySDKCloudRecordFilesAsyncTask;
    // 列表查询task(本地)
    private QueryDeviceRecordFilesAsyncTask queryDeviceRecordFilesAsyncTask;
    // 录像列表区域，没有录像时需要展示的组件
    private LoadingTextView recordLoadingBar;// 录像列表加载进度圈
    private LinearLayout mNovideoImgCloud;// 没有云存储数据
    private LinearLayout mNovideoImgSDKCloud;// 没有云录制数据
    private LinearLayout mNoVideoImgLocal;// 没有SD卡数据
    // Tab区域
    private FrameLayout mTabContentMainFrame;// 所有录像列表父区域
    private RelativeLayout mContentTabCloudRl;// 云存储录像列表显示区域
    private RelativeLayout mContentTabSDKCloudRl;// 云录制录像列表显示区域
    private RelativeLayout mContentTabDeviceRl;// SD卡录像列表显示区域
    // 云存储、SDK云录制、SD卡录像 Tab按钮
    private CheckTextButton mCheckBtnCloud;
    private CheckTextButton mCheckBtnSDKCloud;
    private CheckTextButton mCheckBtnDevice;
    // 右上角录像类型选择按钮
    private EZTopRightMenu mTopRightMenu;
    private List<EZMenuItem> menuItems;
    private EZConstants.EZVideoRecordType recordType = EZConstants.EZVideoRecordType.EZ_VIDEO_RECORD_TYPE_ALL;

    private final EZPlayBackListActivity mActivity;// Activity 引用

    public RecordQueryHelper(EZPlayBackListActivity activity) {
        this.mActivity = activity;
        initView();
    }

    /**
     * 初始化录像查询相关视图
     */
    private void initView() {
        mContentTabCloudRl = (RelativeLayout) mActivity.findViewById(R.id.content_tab_cloud_root);
        mContentTabSDKCloudRl = (RelativeLayout) mActivity.findViewById(R.id.content_tab_sdkcloud_root);
        mContentTabDeviceRl = (RelativeLayout) mActivity.findViewById(R.id.content_tab_device_root);
        mCheckBtnCloud = (CheckTextButton) mActivity.findViewById(R.id.pb_search_tab_btn_cloud);
        mCheckBtnSDKCloud = (CheckTextButton) mActivity.findViewById(R.id.pb_search_tab_btn_sdkcloud);
        mCheckBtnDevice = (CheckTextButton) mActivity.findViewById(R.id.pb_search_tab_btn_device);
        mTabContentMainFrame = (FrameLayout) mActivity.findViewById(R.id.ez_tab_content_frame);

        mCheckBtnCloud.setToggleEnable(false);
        mCheckBtnSDKCloud.setToggleEnable(false);
        mCheckBtnDevice.setToggleEnable(false);
        mCheckBtnCloud.setChecked(true);

        mRecyclerViewForCloud = (RecyclerView) mActivity.findViewById(R.id.recyclerView_cloud);
        mRecyclerViewForCloud.setLayoutManager(new GridLayoutManager(mActivity, 3));
        mRecyclerViewForCloud.addItemDecoration(new RecordRecyclerAdapter.GridSpacingItemDecoration(3, Utils.dip2px(mActivity, 5)));
        mRecyclerViewForSDKCloud = (RecyclerView) mActivity.findViewById(R.id.recyclerView_sdkcloud);
        mRecyclerViewForSDKCloud.setLayoutManager(new GridLayoutManager(mActivity, 3));
        mRecyclerViewForSDKCloud.addItemDecoration(new RecordRecyclerAdapter.GridSpacingItemDecoration(3, Utils.dip2px(mActivity, 5)));
        mRecyclerViewForLocal = (RecyclerView) mActivity.findViewById(R.id.recyclerView_device);
        mRecyclerViewForLocal.setLayoutManager(new GridLayoutManager(mActivity, 3));
        mRecyclerViewForLocal.addItemDecoration(new RecordRecyclerAdapter.GridSpacingItemDecoration(3, Utils.dip2px(mActivity, 5)));

        mNovideoImgCloud = (LinearLayout) mActivity.findViewById(R.id.novideo_img_cloud);
        mNovideoImgSDKCloud = (LinearLayout) mActivity.findViewById(R.id.novideo_img_sdkcloud);
        mNoVideoImgLocal = (LinearLayout) mActivity.findViewById(R.id.novideo_img_device);
        recordLoadingBar = (LoadingTextView) mActivity.findViewById(R.id.record_loadingTextView);
        recordLoadingBar.setText(R.string.loading_text_default);

        // Tab 切换监听
        mCheckBtnCloud.setOnClickListener(v -> {
            mActivity.mRecordType = RemoteListContant.TYPE_CLOUD;
            if (!mCheckBtnCloud.isChecked()) {
                // 切换Tab时停止当前回放
                mActivity.stopCurrentPlayback();
                resetRecordCheckBtns();
                mCheckBtnCloud.setChecked(true);
                mContentTabCloudRl.setVisibility(View.VISIBLE);
                mActivity.mDownloadHelper.setDownloadBtnVisibility(View.VISIBLE);
                mActivity.mPortraitTitleBar.setButtonDrawable(mActivity.mTitleBarHelper.rightButton, mActivity.getResources().getDrawable(R.drawable.common_title_extension));
                mActivity.mTitleBarHelper.rightButton.setVisibility(EzvizAPI.getInstance().isUsingGlobalSDK() ? View.VISIBLE : View.GONE);
                startQueryCloudRecordFiles();
            }
        });
        mCheckBtnSDKCloud.setOnClickListener(v -> {
            mActivity.mRecordType = RemoteListContant.TYPE_SDKCLOUD;
            if (!mCheckBtnSDKCloud.isChecked()) {
                // 切换Tab时停止当前回放
                mActivity.stopCurrentPlayback();
                resetRecordCheckBtns();
                mCheckBtnSDKCloud.setChecked(true);
                mContentTabSDKCloudRl.setVisibility(View.VISIBLE);
                mActivity.mDownloadHelper.setDownloadBtnVisibility(View.GONE);
                mActivity.mPortraitTitleBar.setButtonDrawable(mActivity.mTitleBarHelper.rightButton, mActivity.getResources().getDrawable(R.drawable.common_title_extension));
                mActivity.mTitleBarHelper.rightButton.setVisibility(View.GONE);
                startQuerySDKCloudRecordFiles();
            }
        });
        mCheckBtnDevice.setOnClickListener(v -> {
            mActivity.mRecordType = RemoteListContant.TYPE_LOCAL;
            if (!mCheckBtnDevice.isChecked()) {
                // 切换Tab时停止当前回放
                mActivity.stopCurrentPlayback();
                resetRecordCheckBtns();
                mCheckBtnDevice.setChecked(true);
                mContentTabDeviceRl.setVisibility(View.VISIBLE);
                mActivity.mDownloadHelper.setDownloadBtnVisibility(EZBusinessTool.isSupportSDRecordDownload(mActivity.mDeviceInfo, mActivity.mCameraInfo) ? View.VISIBLE : View.GONE);
                mActivity.mPortraitTitleBar.setButtonDrawable(mActivity.mTitleBarHelper.rightButton, mActivity.getResources().getDrawable(R.drawable.ic_header_grid));
                mActivity.mTitleBarHelper.rightButton.setVisibility(View.VISIBLE);
                startQueryDeviceRecordFiles();
            }
        });
    }

    // region --- 公开方法 ---

    /**
     * 停止所有查询任务
     */
    public void stopQueryTask() {
        if (queryCloudRecordFilesAsyncTask != null) {
            queryCloudRecordFilesAsyncTask.cancel(true);
            queryCloudRecordFilesAsyncTask.setAbort(true);
            queryCloudRecordFilesAsyncTask = null;
        }
        if (querySDKCloudRecordFilesAsyncTask != null) {
            querySDKCloudRecordFilesAsyncTask.cancel(true);
            querySDKCloudRecordFilesAsyncTask.setAbort(true);
            querySDKCloudRecordFilesAsyncTask = null;
        }
        if (queryDeviceRecordFilesAsyncTask != null) {
            queryDeviceRecordFilesAsyncTask.cancel(true);
            queryDeviceRecordFilesAsyncTask.setAbort(true);
            queryDeviceRecordFilesAsyncTask = null;
        }
    }

    /**
     * 开始查询云存储录像
     */
    public void startQueryCloudRecordFiles() {
        if (mActivity.queryDate != null) {
            mActivity.mPortraitTitleBar.setTitle(RemoteListUtil.converToMonthAndDay(mActivity.queryDate));
        }
        mRecyclerViewForCloud.setVisibility(View.GONE);
        stopQueryTask();
        mCloudRecordsAdapter = null;
        queryCloudRecordFilesAsyncTask = new QueryCloudRecordFilesAsyncTask(mActivity.mCameraInfo.getDeviceSerial(),
                mActivity.mCameraInfo.getCameraNo(), this);
        recordLoadingBar.setVisibility(View.VISIBLE);
        showTab(R.id.record_loadingTextView);
        queryCloudRecordFilesAsyncTask.setSearchDate(mActivity.queryDate);
        queryCloudRecordFilesAsyncTask.execute();
    }

    /**
     * 开始查询云录制录像
     */
    public void startQuerySDKCloudRecordFiles() {
        mRecyclerViewForSDKCloud.setVisibility(View.GONE);
        stopQueryTask();
        mSDKCloudRecordsAdapter = null;
        querySDKCloudRecordFilesAsyncTask = new QuerySDKCloudRecordFilesAsyncTask(mActivity.mCameraInfo.getDeviceSerial(),
                mActivity.mCameraInfo.getCameraNo(), this);
        recordLoadingBar.setVisibility(View.VISIBLE);
        showTab(R.id.record_loadingTextView);
        querySDKCloudRecordFilesAsyncTask.setSearchDate(mActivity.queryDate);
        querySDKCloudRecordFilesAsyncTask.execute();
    }

    /**
     * 开始查询SD卡录像
     */
    public void startQueryDeviceRecordFiles() {
        int cloudTotal = 100000;
        mRecyclerViewForLocal.setVisibility(View.GONE);
        stopQueryTask();
        queryDeviceRecordFilesAsyncTask = new QueryDeviceRecordFilesAsyncTask(mActivity.mCameraInfo.getDeviceSerial(),
                mActivity.mCameraInfo.getCameraNo(), recordType, this);
        recordLoadingBar.setVisibility(View.VISIBLE);
        showTab(R.id.record_loadingTextView);
        queryDeviceRecordFilesAsyncTask.setQueryDate(mActivity.queryDate);
        queryDeviceRecordFilesAsyncTask.execute(String.valueOf(cloudTotal));
    }

    /**
     * 日期变更后重新查询
     */
    public void onDateChanged() {
        if (mActivity.queryDate != null) {
            mActivity.mPortraitTitleBar.setTitle(RemoteListUtil.converToMonthAndDay(mActivity.queryDate));
        }
        switch (mActivity.mRecordType) {
            case RemoteListContant.TYPE_CLOUD:
                mSDKCloudRecordsAdapter = null;
                mDeviceRecordsAdapter = null;
                startQueryCloudRecordFiles();
                break;
            case RemoteListContant.TYPE_SDKCLOUD:
                mCloudRecordsAdapter = null;
                mDeviceRecordsAdapter = null;
                startQuerySDKCloudRecordFiles();
                break;
            case RemoteListContant.TYPE_LOCAL:
                mCloudRecordsAdapter = null;
                mSDKCloudRecordsAdapter = null;
                startQueryDeviceRecordFiles();
                break;
            default:
                // do nothing
                break;
        }
    }

    /**
     * 获取当前录像类型对应的适配器
     */
    public RecordRecyclerAdapter getCurrentAdapter() {
        if (mActivity.mRecordType == RemoteListContant.TYPE_CLOUD) return mCloudRecordsAdapter;
        if (mActivity.mRecordType == RemoteListContant.TYPE_SDKCLOUD) return mSDKCloudRecordsAdapter;
        if (mActivity.mRecordType == RemoteListContant.TYPE_LOCAL) return mDeviceRecordsAdapter;
        return null;
    }

    /**
     * 获取指定录像类型适配器的数据
     */
    public List<CloudPartInfoFile> getAdapterData(int recordType) {
        RecordRecyclerAdapter adapter = null;
        if (recordType == RemoteListContant.TYPE_CLOUD) adapter = mCloudRecordsAdapter;
        else if (recordType == RemoteListContant.TYPE_SDKCLOUD) adapter = mSDKCloudRecordsAdapter;
        else if (recordType == RemoteListContant.TYPE_LOCAL) adapter = mDeviceRecordsAdapter;
        return adapter != null ? adapter.getData() : null;
    }

    /**
     * 更新适配器的选中位置
     */
    public void updateAdapterSelection(int position) {
        if (mActivity.mRecordType == RemoteListContant.TYPE_CLOUD && mCloudRecordsAdapter != null) {
            mCloudRecordsAdapter.setSelectedPosition(position);
            mRecyclerViewForCloud.scrollToPosition(position);
        } else if (mActivity.mRecordType == RemoteListContant.TYPE_SDKCLOUD && mSDKCloudRecordsAdapter != null) {
            mSDKCloudRecordsAdapter.setSelectedPosition(position);
            mRecyclerViewForSDKCloud.scrollToPosition(position);
        } else if (mActivity.mRecordType == RemoteListContant.TYPE_LOCAL && mDeviceRecordsAdapter != null) {
            mDeviceRecordsAdapter.setSelectedPosition(position);
            mRecyclerViewForLocal.scrollToPosition(position);
        }
    }

    /**
     * 右上角录像类型菜单点击
     */
    public void showTopRightMenu(Button rightButton) {
        if (mCheckBtnCloud.isChecked()) {
            if (EzvizAPI.getInstance().isUsingGlobalSDK()) {
                com.videogo.ui.playback.EZAbroadCloudServiceExAct.launch(mActivity, mActivity.mCameraInfo.getDeviceSerial(),
                        mActivity.mCameraInfo.getCameraNo());
            }
        } else {
            if (menuItems == null) {
                menuItems = new ArrayList<>();
                menuItems.add(new EZMenuItem(R.mipmap.videogo_icon, "全部"));
                menuItems.add(new EZMenuItem(R.mipmap.videogo_icon, "定时"));
                menuItems.add(new EZMenuItem(R.mipmap.videogo_icon, "事件"));
            }
            if (mTopRightMenu == null) {
                mTopRightMenu = new EZTopRightMenu(mActivity);
                mTopRightMenu.setWidth(450)
                        .showIcon(false)
                        .dimBackground(true)
                        .needAnimationStyle(true)
                        .setAnimationStyle(R.style.TRM_ANIM_STYLE)
                        .addMenuList(menuItems).setOnMenuItemClickListener(position -> {
                            if (position == 1) {
                                recordType = EZConstants.EZVideoRecordType.EZ_VIDEO_RECORD_TYPE_CMR;
                            } else if (position == 2) {
                                recordType = EZConstants.EZVideoRecordType.EZ_VIDEO_RECORD_TYPE_Event;
                            } else {
                                recordType = EZConstants.EZVideoRecordType.EZ_VIDEO_RECORD_TYPE_ALL;
                            }
                            startQueryDeviceRecordFiles();
                        });
            }
            mTopRightMenu.showAsDropDown(rightButton, -300, 10);
        }
    }

    /**
     * 云存储Tab是否选中（供SD卡封面回调拦截判断）
     */
    public boolean isCloudTabChecked() {
        return mCheckBtnCloud.isChecked();
    }

    /**
     * 清空云存储适配器数据（页面 finish 时调用）
     */
    public void clearCloudAdapterData() {
        if (mCloudRecordsAdapter != null) {
            mCloudRecordsAdapter.setData(null);
        }
    }

    /**
     * 横屏时云存储RecyclerView可见性控制
     */
    public void setCloudRecyclerVisibility(int visibility) {
        mRecyclerViewForCloud.setVisibility(visibility);
    }

    // endregion

    // region --- QueryPlayBackListTaskCallback 查询回调 ---

    @Override
    public void queryHasNoData(int type) {
        if (type == RemoteListContant.TYPE_CLOUD) {
            showTab(R.id.novideo_img_cloud);
        } else if (type == RemoteListContant.TYPE_SDKCLOUD) {
            showTab(R.id.novideo_img_sdkcloud);
        } else if (type == RemoteListContant.TYPE_LOCAL) {
            showTab(R.id.novideo_img_device);
        }
        mActivity.mLoadingStateHelper.setLoadingSuccess();
    }

    @Override
    public void querySuccessFromCloud(List<CloudPartInfoFile> cloudPartInfoFile) {
        mActivity.findViewById(R.id.display_layout).setVisibility(View.VISIBLE);
        recordLoadingBar.setVisibility(View.GONE);
        mRecyclerViewForCloud.setVisibility(View.VISIBLE);
        showTab(R.id.content_tab_cloud_root);

        mCloudRecordsAdapter = new RecordRecyclerAdapter(mActivity);
        mCloudRecordsAdapter.setRecordType(RemoteListContant.TYPE_CLOUD);
        mCloudRecordsAdapter.setDeviceSerial(mActivity.mCameraInfo.getDeviceSerial());
        mCloudRecordsAdapter.setOnRecordItemClickListener(mActivity);
        mCloudRecordsAdapter.setData(cloudPartInfoFile);
        mRecyclerViewForCloud.setAdapter(mCloudRecordsAdapter);

        doPlayback(cloudPartInfoFile, RemoteListContant.TYPE_CLOUD);
    }

    @Override
    public void querySuccessFromSDKCloud(List<CloudPartInfoFile> cloudPartInfoFile) {
        recordLoadingBar.setVisibility(View.GONE);
        mRecyclerViewForSDKCloud.setVisibility(View.VISIBLE);
        showTab(R.id.content_tab_sdkcloud_root);

        mSDKCloudRecordsAdapter = new RecordRecyclerAdapter(mActivity);
        mSDKCloudRecordsAdapter.setRecordType(RemoteListContant.TYPE_SDKCLOUD);
        mSDKCloudRecordsAdapter.setDeviceSerial(mActivity.mCameraInfo.getDeviceSerial());
        mSDKCloudRecordsAdapter.setOnRecordItemClickListener(mActivity);
        mSDKCloudRecordsAdapter.setData(cloudPartInfoFile);
        mRecyclerViewForSDKCloud.setAdapter(mSDKCloudRecordsAdapter);

        doPlayback(cloudPartInfoFile, RemoteListContant.TYPE_SDKCLOUD);
    }

    @Override
    public void querySuccessFromDevice(List<CloudPartInfoFile> cloudPartInfoFile) {
        recordLoadingBar.setVisibility(View.GONE);
        showTab(R.id.content_tab_device_root);
        mRecyclerViewForLocal.setVisibility(View.VISIBLE);

        if (mDeviceRecordsAdapter != null) {
            // 追加数据并刷新
            mDeviceRecordsAdapter.setData(cloudPartInfoFile);
            int scrollTo = cloudPartInfoFile.size() - 1;
            if (scrollTo > 0) {
                mRecyclerViewForLocal.scrollToPosition(scrollTo);
            }
        } else {
            mDeviceRecordsAdapter = new RecordRecyclerAdapter(mActivity);
            mDeviceRecordsAdapter.setRecordType(RemoteListContant.TYPE_LOCAL);
            mDeviceRecordsAdapter.setDeviceSerial(mActivity.mCameraInfo.getDeviceSerial());
            mDeviceRecordsAdapter.setOnRecordItemClickListener(mActivity);
            mDeviceRecordsAdapter.setData(cloudPartInfoFile);
            mRecyclerViewForLocal.setAdapter(mDeviceRecordsAdapter);
        }
        doPlayback(cloudPartInfoFile, RemoteListContant.TYPE_LOCAL);
        // 国内 & 支持SD卡录像封面，请求封面
        mActivity.mRecordCoverHelper.requestRecordCovers(cloudPartInfoFile, (seq, bitmap) -> {
            // 以下情况做拦截，否则会将SD卡录像封面显示在云存储录像上或者数组越界崩溃
            if (mCheckBtnCloud.isChecked() || seq > cloudPartInfoFile.size() - 1) {
                return;
            }
            // 将获取到的图片赋值给列表中的对象，并局部刷新RecyclerView
            CloudPartInfoFile cloudFile = cloudPartInfoFile.get(seq);
            cloudFile.setBitmap(bitmap);
            // RecyclerView支持局部刷新，直接刷新对应位置的item
            mActivity.runOnUiThread(() -> {
                if (mDeviceRecordsAdapter != null) {
                    mDeviceRecordsAdapter.notifyItemChanged(seq);
                }
            });
        });
    }

    // endregion

    // region --- 私有方法 ---

    /**
     * 录像类型选中状态重置
     */
    private void resetRecordCheckBtns() {
        mCheckBtnCloud.setChecked(false);
        mCheckBtnSDKCloud.setChecked(false);
        mCheckBtnDevice.setChecked(false);
        mContentTabCloudRl.setVisibility(View.GONE);
        mContentTabSDKCloudRl.setVisibility(View.GONE);
        mContentTabDeviceRl.setVisibility(View.GONE);
    }

    /**
     * 根据id对视图进行显示/隐藏
     */
    private void showTab(int id) {
        if (id == R.id.novideo_img_cloud) {
            mNovideoImgCloud.setVisibility(View.VISIBLE);
            recordLoadingBar.setVisibility(View.GONE);
            mTabContentMainFrame.setVisibility(View.VISIBLE);
        } else if (id == R.id.novideo_img_sdkcloud) {
            mNovideoImgSDKCloud.setVisibility(View.VISIBLE);
            recordLoadingBar.setVisibility(View.GONE);
            mTabContentMainFrame.setVisibility(View.VISIBLE);
        } else if (id == R.id.novideo_img_device) {
            mNoVideoImgLocal.setVisibility(View.VISIBLE);
            mRecyclerViewForLocal.setVisibility(View.GONE);
            recordLoadingBar.setVisibility(View.GONE);
            mTabContentMainFrame.setVisibility(View.VISIBLE);
        } else if (id == R.id.record_loadingTextView) {
            mNovideoImgCloud.setVisibility(View.GONE);
            recordLoadingBar.setVisibility(View.VISIBLE);
            mTabContentMainFrame.setVisibility(View.GONE);
        } else if (id == R.id.content_tab_cloud_root) {
            mNovideoImgCloud.setVisibility(View.GONE);
            recordLoadingBar.setVisibility(View.GONE);
            mTabContentMainFrame.setVisibility(View.VISIBLE);
        } else if (id == R.id.content_tab_sdkcloud_root) {
            mNovideoImgSDKCloud.setVisibility(View.GONE);
            recordLoadingBar.setVisibility(View.GONE);
            mTabContentMainFrame.setVisibility(View.VISIBLE);
        } else if (id == R.id.content_tab_device_root) {
            mNoVideoImgLocal.setVisibility(View.GONE);
            recordLoadingBar.setVisibility(View.GONE);
            mTabContentMainFrame.setVisibility(View.VISIBLE);
        }
    }

    /**
     * 查询完成自动播放第一条录像
     */
    private void doPlayback(List<CloudPartInfoFile> cloudPartInfoFile, int playbackType) {
        if (cloudPartInfoFile != null && !cloudPartInfoFile.isEmpty()) {
            CloudPartInfoFile file = cloudPartInfoFile.get(0);
            ClickedListItem clickedListItem = new ClickedListItem(0, playbackType, file.getStartMillis(),
                    file.getEndMillis(), 0);
            mActivity.onRecordItemClick(cloudPartInfoFile.get(0), clickedListItem);
        }
    }

    // endregion
}
