package org.deke.risk.riskahead;

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

import org.deke.risk.riskahead.helper.AppConfig;
import org.deke.risk.riskahead.helper.SessionManager;

/**
 *
 * (C) Copyright 2016 RiskAhead (http://www.riskahead.net)
 * Developer & Contributor: Dennis Thießen (dennis.thiessen@riskahead.net)
 * Date of Release: 10.02.2016
 *
 */
public class StartActivity extends AppCompatActivity {

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

    Button btnLogin;
    Button btnRegister;

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

        Log.d(TAG,"RiskAhead started.");

        setContentView(R.layout.activity_start);

        btnLogin = (Button) findViewById(R.id.btn_start_login);
        btnRegister = (Button) findViewById(R.id.btn_start_register);

        SessionManager session = new SessionManager(getApplicationContext());
        if (session.isLoggedIn()) {
            Log.d(TAG,"User found in sharedPrefs and is therefore logged in. Continue to internal Area.");
            Intent intent = new Intent(StartActivity.this, MainActivity.class);
            startActivity(intent);
            finish();
        }
    }

    public void gotoLogin(View view) {
        Intent intent = new Intent(this, LoginActivity.class);
        intent.putExtra(AppConfig.EXTRA_MESSAGE, AppConfig.INTENT_LOGIN);
        startActivity(intent);
    }

    public void gotoRegister(View view) {
        Intent intent = new Intent(this, LoginActivity.class);
        intent.putExtra(AppConfig.EXTRA_MESSAGE, AppConfig.INTENT_REGISTER);
        startActivity(intent);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_common, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return super.onOptionsItemSelected(item);
    }

}
