package community.peers.internetradio.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.method.LinkMovementMethod;
import android.view.MenuItem;
import android.widget.TextView;

import community.peers.internetradio.BuildConfig;
import community.peers.internetradio.R;

public class AboutActivity extends AppCompatActivity {

    TextView about_text;
    TextView about_usage;
    TextView about_thanks;
    TextView about_license;
    TextView about_maintainers;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);

        /**
         * Display back button.
         * Set whether home should be displayed as an "up" affordance.
         * Set this to true if selecting "home" returns up by a single
         * level in your UI rather than back to the top level or front
         * page.
         */
        //this.getSupportActionBar().setHomeButtonEnabled(true);
        this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        this.setTitle(getString(R.string.about_title));

        // Get references to layout elements
        about_text = (TextView) findViewById(R.id.about_text);
        about_usage = (TextView) findViewById(R.id.about_usage_text);
        about_thanks = (TextView) findViewById(R.id.about_thanks_text);
        about_license = (TextView) findViewById(R.id.about_license_text);
        about_maintainers = (TextView) findViewById(R.id.about_maintainers_text);

        // Append version name to the about page
        about_text.append ("\n\n" + getString (R.string.about_version) +
                           " " + BuildConfig.VERSION_NAME);

        /**
         * Allow clickable links.
         * This is required for <a href="">Name</a> links.
         */
        about_text.setMovementMethod(LinkMovementMethod.getInstance());
        about_usage.setMovementMethod(LinkMovementMethod.getInstance());
        about_thanks.setMovementMethod(LinkMovementMethod.getInstance());
    }

    /**
     * Catch tap on action bar items.
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            // Respond to the action bar's Up/Home button
            case android.R.id.home:
                // Destroy Activity (and return to parent)
                this.finish();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
