package com.nguyenmanhtuan.benhandientu;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.HashMap;
import java.util.Locale;

import com.nguyenmanhtuan.utils.DatabaseHandler;

public class RegisteredActivity extends Activity {
    private Locale  myLocale;
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_registered);
        
        DatabaseHandler db = new DatabaseHandler(getApplicationContext());
        
        HashMap<String, String> user = new HashMap<String, String>();
        user = db.getUserDetails();
        
        /**
         * Displays the registration details in Text view
         **/
        
        final TextView fname = (TextView) findViewById(R.id.fname);
        final TextView lname = (TextView) findViewById(R.id.lname);
        final TextView uname = (TextView) findViewById(R.id.uname);
        final TextView email = (TextView) findViewById(R.id.email);
        final TextView address = (TextView) findViewById(R.id.tvadd);
        final TextView phonenumber = (TextView) findViewById(R.id.tvphone);
        final TextView birthyear = (TextView) findViewById(R.id.tvBirthyear);
        final TextView created_at = (TextView) findViewById(R.id.regat);
        fname.setText(user.get("fname"));
        lname.setText(user.get("lname"));
        uname.setText(user.get("uname"));
        email.setText(user.get("email"));
        address.setText(user.get("address"));
        phonenumber.setText(user.get("phonenumber"));
        birthyear.setText(user.get("birthyear"));
        created_at.setText(user.get("created_at"));
        
        Button login = (Button) findViewById(R.id.login);
        login.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent myIntent = new Intent(view.getContext(), LoginActivity.class);
                startActivityForResult(myIntent, 0);
                finish();
            }
            
        });
        
    }
    public void setLocale(String lang) {
        myLocale = new Locale(lang);
        Resources res = getResources();
        DisplayMetrics dm = res.getDisplayMetrics();
        Configuration conf = res.getConfiguration();
        conf.locale = myLocale;
        res.updateConfiguration(conf, dm);
        Intent refresh = new Intent(this, RegisteredActivity.class);
        startActivity(refresh);
    }
}
