package com.mjsheng.myappstore;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.mjsheng.myappstore.activity.AppStoreActivity;
import com.mjsheng.myappstore.comm.CommonDatas;
import com.mjsheng.myappstore.server.MyDownloadService;
import com.mjsheng.myappstore.utils.MySQLData;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        //        setContentView(R.layout.activity_main);
        //        init();
        //        initView();
        init();
        enterAppstore("6");


    }


    private void init() {
        startService(new Intent(MainActivity.this, MyDownloadService.class));
    }

    private void initView() {
        Button btn_babySystem = (Button) findViewById(R.id.btn_babySystem);
        btn_babySystem.setOnClickListener(this);
        Button btn_primarySystem = (Button) findViewById(R.id.btn_primarySystem);
        btn_primarySystem.setOnClickListener(this);
        Button btn_middleSystem = (Button) findViewById(R.id.btn_middleSystem);
        btn_middleSystem.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_babySystem:
                enterAppstore("3");
                break;
            case R.id.btn_primarySystem:
                enterAppstore("6");
                break;
            case R.id.btn_middleSystem:
                enterAppstore("10");
                break;
        }
    }

    private void enterAppstore(String system) {
        MySQLData.SetData(this, CommonDatas.SP_BABY_AGE_KEY, system);
        Intent appstore = new Intent(this, AppStoreActivity.class);
        appstore.putExtra("ageSystem", system);
        startActivity(appstore);
        finish();
    }





}
