/*
 * Copyright (c) 2015. Ncomz. All Rights Reserved
 */

package com.ntels.onecable.view;

import com.ntels.onecable.common.Constants;
import com.ntels.onecable.common.util.LogUtil;
import com.ntels.onecable.common.util.Util;

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

/**
 * <pre>
 * 1. ClassName :   AppStart
 * 2. FileName  :   AppStart.java
 * 3. Package   :   com.ntels.onecable.view
 * 4. Date      :   2016-11-28
 * 5. Author    :   aaron
 * 6. Comment   :   Initialize
 * </pre>
 */
public class AppStart extends Activity {

    private static final String TAG = AppStart.class.getSimpleName();

    /*공통*/
    private Activity mActivity;
    private Util mUtil = new Util();
    private String mType = "";

    @Override
    protected void onNewIntent(Intent saveIntent) {

        super.onNewIntent(saveIntent);
        if (getIntent() != null) {
            Uri uri = getIntent().getData();
            if (uri != null) {
                mType = mUtil.null2string(uri.getQueryParameter("type"));
                Intent intent = new Intent(mActivity, Intro.class);
                if (!"".equals(mType)) {
                    intent.putExtra(Constants.EXTRA_PUSH_TYPE_CODE, mType);
                } else {
                    intent.putExtra(Constants.EXTRA_PUSH_TYPE_CODE, "");
                }
                intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
                mUtil.callActivityNoAnim(mActivity, intent);
            }
        }
        onBackPressed();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        LogUtil.i(TAG, "AppStart::onCreate!!");
        mActivity = AppStart.this;

        if (getIntent() != null) {
            Uri uri = getIntent().getData();
            if (uri != null) {
                mType = mUtil.null2string(uri.getQueryParameter("type"));
                LogUtil.i(TAG, "Push type - " + mType);
                Intent intent = new Intent(mActivity, Intro.class);
                if (!"".equals(mType)) {
                    intent.putExtra(Constants.EXTRA_PUSH_TYPE_CODE, mType);
                } else {
                    intent.putExtra(Constants.EXTRA_PUSH_TYPE_CODE, "");
                }
                intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
                mUtil.callActivityNoAnim(mActivity, intent);
            }
        }

        onBackPressed();
    }
}
