package com.averi.worldscribe.activities;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.widget.Spinner;

import com.averi.worldscribe.R;
import com.averi.worldscribe.adapters.AppThemeArrayAdapter;

public class SettingsActivity extends AppCompatActivity {

    private Spinner appThemeSpinner;

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

        appThemeSpinner = (Spinner) findViewById(R.id.themeSelector);

        setAppBar();
        populateAppThemeSpinner();
    }

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

    /**
     * Setup this Activity's app bar.
     */
    private void setAppBar() {
        Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
        assert myToolbar != null;
        myToolbar.setTitle(R.string.settingsTitle);
        setSupportActionBar(myToolbar);
    }

    /**
     * Populate the App Theme spinner with all available app themes.
     */
    private void populateAppThemeSpinner() {
        Integer allThemes[] = {R.style.AppTheme, R.style.SunsetOrange, R.style.EnchantedGreen,
            R.style.UbePurple, R.style.LovelyRed};
        AppThemeArrayAdapter adapter = new AppThemeArrayAdapter(this, allThemes);
        appThemeSpinner.setAdapter(adapter);
    }

}

@@ -36,16 +36,89 @@
 ities;%0A%0A
+import android.content.Intent;%0Aimport android.content.SharedPreferences;%0A
 import a
@@ -252,16 +252,46 @@
 w.Menu;%0A
+import android.view.MenuItem;%0A
 import a
@@ -410,66 +410,345 @@
 er;%0A
-%0Apublic class SettingsActivity extends AppCompatActivity %7B
+import com.averi.worldscribe.utilities.AppPreferences;%0A%0Apublic class SettingsActivity extends ThemedActivity %7B%0A%0A    public static final int SKY_BLUE = 0;%0A    public static final int SUNSET_ORANGE = 1;%0A    public static final int ENCHANTED_GREEN = 2;%0A    public static final int UBE_PURPLE = 3;%0A    public static final int LOVELY_RED = 4;
 %0A%0A  
@@ -1262,32 +1262,362 @@
 u(menu);%0A    %7D%0A%0A
+    @Override%0A    public boolean onOptionsItemSelected(MenuItem item) %7B%0A        switch (item.getItemId()) %7B%0A            case R.id.saveEditItem:%0A                saveAppSettings();%0A                finish();%0A                return true;%0A            default:%0A                return super.onOptionsItemSelected(item);%0A        %7D%0A    %7D%0A%0A
     /**%0A     * S
@@ -2297,10 +2297,1087 @@
 %0A    %7D%0A%0A
+    /**%0A     * Saves the app settings that are set in this Activity.%0A     */%0A    private void saveAppSettings() %7B%0A        SharedPreferences preferences = getSharedPreferences(AppPreferences.PREFERENCES_FILE_NAME,%0A                MODE_PRIVATE);%0A        preferences.edit().putInt(AppPreferences.APP_THEME, getSelectedAppTheme()).apply();%0A    %7D%0A%0A    /**%0A     * @return The ID of the theme selected by the user.%0A     */%0A    private int getSelectedAppTheme() %7B%0A        int themeID;%0A%0A        switch (appThemeSpinner.getSelectedItemPosition()) %7B%0A            case SKY_BLUE:%0A            default:%0A                themeID = R.style.AppTheme;%0A                break;%0A            case SUNSET_ORANGE:%0A                themeID = R.style.SunsetOrange;%0A                break;%0A            case ENCHANTED_GREEN:%0A                themeID = R.style.EnchantedGreen;%0A                break;%0A            case UBE_PURPLE:%0A                themeID = R.style.UbePurple;%0A                break;%0A            case LOVELY_RED:%0A                themeID = R.style.LovelyRed;%0A        %7D%0A%0A        return themeID;%0A    %7D%0A%0A
 %7D%0A

Save selected theme in SettingsActivity