package com.gh.gamecenter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;

import com.gh.common.util.DirectUtils;
import com.gh.common.util.NewFlatLogUtils;
import com.gh.gamecenter.common.base.activity.ToolBarActivity;
import com.gh.gamecenter.common.base.fragment.BaseFragment_TabLayout;
import com.gh.gamecenter.common.constant.EntranceConsts;
import com.gh.gamecenter.common.utils.ExtensionsKt;
import com.gh.gamecenter.download.DownloadFragment;
import com.gh.vspace.VHelper;

/**
 * 下载更新管理页面
 *
 * @author 黄壮华
 */
public class DownloadManagerActivity extends ToolBarActivity {

    public static final int INDEX_DOWNLOAD = 0;
    public static final int INDEX_UPDATE = 1;

    public static final String TAG = "DownloadManagerActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ExtensionsKt.updateStatusBarColor(this, R.color.background_white, R.color.background_white);
        if (VHelper.isVGameOn()) {
            setToolbarMenu(R.menu.menu_download_manager);
        }
    }

    @Override
    protected Intent provideNormalIntent() {
        return getTargetIntent(this, DownloadManagerActivity.class, DownloadFragment.class);
    }

    public static Intent getDownloadMangerIntent(Context context, String url, String entrance) {
        Bundle bundle = new Bundle();
        bundle.putString(EntranceConsts.KEY_URL, url);
        bundle.putString(EntranceConsts.KEY_ENTRANCE, entrance);
        return getTargetIntent(context, DownloadManagerActivity.class, DownloadFragment.class, bundle);
    }

    public static Intent getDownloadMangerIntent(Context context, String entrance) {
        Bundle bundle = new Bundle();
        bundle.putString(EntranceConsts.KEY_ENTRANCE, entrance);
        return getTargetIntent(context, DownloadManagerActivity.class, DownloadFragment.class, bundle);
    }

    /**
     * 根据packageName检查是否可以更新/插件化 如果可以则自动下载
     */
    public static Intent getDownloadMangerIntent(Context context, String packageName, int position, String entrance) {
        Bundle bundle = new Bundle();
        bundle.putString(EntranceConsts.KEY_ENTRANCE, entrance);
        bundle.putInt(BaseFragment_TabLayout.PAGE_INDEX, position);
        bundle.putString(EntranceConsts.KEY_PACKAGENAME, packageName);
        return getTargetIntent(context, DownloadManagerActivity.class, DownloadFragment.class, bundle);
    }

    @Override
    public boolean onMenuItemClick(MenuItem item) {
        NewFlatLogUtils.logHaloFunManageShow("下载管理");
        DirectUtils.directToVGameDownload(this, false);
        return true;
    }

    @Override
    protected void onDarkModeChanged() {
        super.onDarkModeChanged();
        ExtensionsKt.updateStatusBarColor(this, R.color.background_white, R.color.background_white);
    }
}