package com.sheep.gamegroup.view.activity;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.sheep.gamegroup.util.ActionUtil;
import com.sheep.gamegroup.util.Jump2View;
import com.sheep.gamegroup.util.TestUtil;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.jiuyan.samllsheep.utils.G;

/**
 * Created by realicing on 2018/5/10.
 * realicing@sina.com
 */
public class MiddleSchemeAct extends Activity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_activity);
        checkScheme(getIntent());
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        checkScheme(intent);
    }

    private void checkScheme(Intent intent) {
        String action;
        if (intent == null || (action = intent.getAction()) == null)
            return;
        switch (action) {
            case Intent.ACTION_VIEW:
                Uri uri = intent.getData();
                String game_id = "";
                if (uri != null) {
                    // 完整的url信息
                    if (TestUtil.isTest())
                        G.showToast(uri.toString());
                    game_id = uri.getQueryParameter("game_id");
//                    LogUtil.println("ActMain", "checkScheme","url: " + url);
//                    // scheme部分
//                    String scheme = uri.getScheme();
//                    LogUtil.println("ActMain", "checkScheme","scheme: " + scheme);
//                    // host部分
//                    String host = uri.getHost();
//                    LogUtil.println("ActMain", "checkScheme","host: " + host);
//                    //port部分
//                    int port = uri.getPort();
//                    LogUtil.println("ActMain", "checkScheme","host: " + port);
//                    // 访问路劲
//                    String path = uri.getPath();
//                    LogUtil.println("ActMain", "checkScheme","path: " + path);
//                    List<String> pathSegments = uri.getPathSegments();
//                    LogUtil.println("ActMain", "checkScheme","pathSegments:", JSON.toJSONString(pathSegments));
//                    // Query部分
//                    String query = uri.getQuery();
//                    LogUtil.println("ActMain", "checkScheme","query: " + query);
//                    //获取指定参数值
//                    String code = uri.getQueryParameter("code");
//                    LogUtil.println("ActMain", "checkScheme","code: " + code);
//                    if(TextUtils.equals(code, "0")){
//                        finish();
//                    }
                    /**
                     * sheep://small.kfzs.com/xmy?game_id=1385&code=976873
                     * ActMain checkScheme url: sheep://kfzs:8888/xmy?code=976873
                     * ActMain checkScheme scheme: sheep
                     * ActMain checkScheme host: kfzs
                     * ActMain checkScheme host: 8888
                     * ActMain checkScheme path: /xmy
                     * ActMain checkScheme pathSegments: ["xmy"]
                     * ActMain checkScheme query: code=976873
                     * ActMain checkScheme code: 976873
                     */
                }
                ActionUtil.getInstance().addNextAction(SHOW_DIALOG_GAME_OR_GIFT_TASK, game_id);
                Jump2View.getInstance().newTaskTopStartAct(this, SplashAct.class, null);
                finish();
                break;
        }
    }

    //展示会长推广弹出框的key
    public static final String SHOW_DIALOG_GAME_OR_GIFT_TASK = "show_dialog_game_or_gift_task";
}
