package org.edublogs.android.ui.prefs;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import org.edublogs.android.R;
import org.edublogs.android.WordPress;
import org.edublogs.android.lockmanager.AppLockManager;
import org.edublogs.android.util.DeviceUtils;


public class AboutActivity extends Activity implements OnClickListener {

    private static final String URL_TOS = "http://edublogs.org/terms-of-service";
    private static final String URL_AUTOMATTIC = "http://edublogs.org";
    private static final String URL_PRIVACY_POLICY = "/privacy-policy";

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.about);

        if (DeviceUtils.getInstance().isBlackBerry()) {
            TextView appTitle = (TextView) findViewById(R.id.about_first_line);
            appTitle.setText(getString(R.string.app_title_blackberry));
        }

        TextView version = (TextView) findViewById(R.id.about_version);
        version.setText(getString(R.string.version) + " "
                + WordPress.versionName);

        Button tos = (Button) findViewById(R.id.about_tos);
        tos.setOnClickListener(this);

        Button pp = (Button) findViewById(R.id.about_privacy);
        pp.setOnClickListener(this);
    }


    public void onClick(View v) {
        Uri uri;
        int id = v.getId();
        if (id == R.id.about_url) {
            uri = Uri.parse(URL_AUTOMATTIC);
        } else if (id == R.id.about_tos) {
            uri = Uri.parse(URL_TOS);
        } else if (id == R.id.about_privacy) {
            uri = Uri.parse(URL_AUTOMATTIC + URL_PRIVACY_POLICY);
        } else {
            return;
        }
        AppLockManager.getInstance().setExtendedTimeout();
        startActivity(new Intent(Intent.ACTION_VIEW, uri));
    }
}
