package moe.dangoreader.activity;

import android.app.FragmentManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.widget.Toolbar;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import moe.dangoreader.BootReceiver;
import moe.dangoreader.R;

public class SettingsActivity extends PreferenceActivity {

    private AppCompatDelegate mDelegate;

    @Override
    public void onCreate(final Bundle savedInstanceState) {
        getDelegate().installViewFactory();
        getDelegate().onCreate(savedInstanceState);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);

        Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar_preferences);
        setSupportActionBar(mToolbar);
        getSupportActionBar().setTitle(R.string.title_settings);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });

        FragmentManager fm = getFragmentManager();
        SettingsFragment preferenceFragment = (SettingsFragment) fm.findFragmentById(R.id.preference_fragment);

        // If the Fragment is non-null, then it is currently being retained across a configuration change.
        if (preferenceFragment == null) {
            preferenceFragment = new SettingsFragment();
            getFragmentManager().beginTransaction().replace(R.id.preference_fragment, new SettingsFragment()).commit();
            fm.executePendingTransactions();
        }

        // Listen for changes to the settings
        PreferenceManager
                .getDefaultSharedPreferences(this)
                .registerOnSharedPreferenceChangeListener(new SharedPreferences.OnSharedPreferenceChangeListener() {
            @Override
            public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
                if (key.equals(getString(R.string.PREF_KEY_CHECK_FOR_UPDATES))) {
                    BootReceiver.RefreshService.toggle(SettingsActivity.this);
                }
            }
        });

        preferenceFragment.findPreference(getString(R.string.PREF_WEBSITE))
                .setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        // Launch our website
                        String url = "http://www.mango.moe";
                        Intent i = new Intent(Intent.ACTION_VIEW);
                        i.setData(Uri.parse(url));
                        startActivity(i);
                        return false;
                    }
                });

        preferenceFragment.findPreference(getString(R.string.PREF_MANGAEDEN))
                .setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        // Launch mangaeden.com
                        String url = "http://www.mangaeden.com/en/";
                        Intent i = new Intent(Intent.ACTION_VIEW);
                        i.setData(Uri.parse(url));
                        startActivity(i);
                        return false;
                    }
                });

        preferenceFragment.findPreference(getString(R.string.PREF_EMAIL))
                .setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        // Compose an email to the developers
                        Intent i = new Intent(Intent.ACTION_SEND);
                        i.setType("message/rfc822");
                        i.putExtra(Intent.EXTRA_EMAIL, new String[]{
                                "clarence.iyan@gmail.com",
                                "akrolsmir@gmail.com",
                                "xu.will94@gmail.com",
                                "michelle.ragsac@gmail.com"
                        });
                        i.putExtra(Intent.EXTRA_SUBJECT, "DangoReader");
                        try {
                            startActivity(Intent.createChooser(i, "Send mail..."));
                        } catch (android.content.ActivityNotFoundException ex) {
                            Toast.makeText(SettingsActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
                        }
                        return false;
                    }
                });
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        getDelegate().onPostCreate(savedInstanceState);
    }

    public ActionBar getSupportActionBar() {
        return getDelegate().getSupportActionBar();
    }

    public void setSupportActionBar(@Nullable Toolbar toolbar) {
        getDelegate().setSupportActionBar(toolbar);
    }

    @NonNull
    @Override
    public MenuInflater getMenuInflater() {
        return getDelegate().getMenuInflater();
    }

    @Override
    public void setContentView(@LayoutRes int layoutResID) {
        getDelegate().setContentView(layoutResID);
    }

    @Override
    public void setContentView(View view) {
        getDelegate().setContentView(view);
    }

    @Override
    public void setContentView(View view, ViewGroup.LayoutParams params) {
        getDelegate().setContentView(view, params);
    }

    @Override
    public void addContentView(View view, ViewGroup.LayoutParams params) {
        getDelegate().addContentView(view, params);
    }

    @Override
    protected void onPostResume() {
        super.onPostResume();
        getDelegate().onPostResume();
    }

    @Override
    protected void onTitleChanged(CharSequence title, int color) {
        super.onTitleChanged(title, color);
        getDelegate().setTitle(title);
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        getDelegate().onConfigurationChanged(newConfig);
    }

    @Override
    protected void onStop() {
        super.onStop();
        getDelegate().onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        getDelegate().onDestroy();
    }

    public void invalidateOptionsMenu() {
        getDelegate().invalidateOptionsMenu();
    }

    private AppCompatDelegate getDelegate() {
        if (mDelegate == null) {
            mDelegate = AppCompatDelegate.create(this, null);
        }
        return mDelegate;
    }

    /**
     * Dedicated PreferenceFragment. Should only be created by SettingsActivity class.
     */
    public static class SettingsFragment extends PreferenceFragment {
        @Override
        public void onCreate(final Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.xml.preferences);
        }
    }
}

@@ -3155,13 +3155,19 @@
 www.
-m
+d
 ango
+reader
 .moe
@@ -4614,23 +4614,24 @@
 ence
-.iyan@gmail.com
+@dangoreader.moe
 %22,%0A 
@@ -4667,26 +4667,29 @@
   %22a
-krolsmir@gmail.com
+ustin@dangoreader.moe
 %22,%0A 
@@ -4724,27 +4724,28 @@
    %22
-xu.
 will
-94@gmail.com
+@dangoreader.moe
 %22,%0A 
@@ -4788,26 +4788,154 @@
 elle
-.ragsac@gmail.com%22
+@dangoreader.moe%22,%0A                                %22shawn@dangoreader.moe%22,%0A                                %22akrolsmir@gmail.com%22, // Just in case
 %0A   

Update domain names