/*
 * Nextcloud SingleSignOn
 *
 * @author David Luhmer
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.nextcloud.android.sso.helper;

import android.content.Context;
import android.content.SharedPreferences;

import com.nextcloud.android.sso.AccountImporter;
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException;
import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException;
import com.nextcloud.android.sso.model.SingleSignOnAccount;

public final class SingleAccountHelper {

    private static final String PREF_SINGLE_ACCOUNT_STRING = "PREF_ACCOUNT_STRING";

    private SingleAccountHelper() {
    }

    private static String getCurrentAccountName(Context context) throws NoCurrentAccountSelectedException {
        SharedPreferences mPrefs = AccountImporter.getSharedPreferences(context);
        String accountName = mPrefs.getString(PREF_SINGLE_ACCOUNT_STRING, null);
        if (accountName == null) {
            throw new NoCurrentAccountSelectedException();
        }
        return accountName;
    }

    public static SingleSignOnAccount getCurrentSingleSignOnAccount(Context context)
            throws NextcloudFilesAppAccountNotFoundException, NoCurrentAccountSelectedException {
        return AccountImporter.getSingleSignOnAccount(context, getCurrentAccountName(context));
    }

    public static void setCurrentAccount(Context context, String accountName) {
        SharedPreferences mPrefs = AccountImporter.getSharedPreferences(context);
        mPrefs.edit().putString(PREF_SINGLE_ACCOUNT_STRING, accountName).commit();
    }
}

@@ -2215,10 +2215,704 @@
 ;%0A    %7D%0A
+    %0A    public static void registerSharedPreferenceChangeListener(Context context, %0A                                                                SharedPreferences.OnSharedPreferenceChangeListener listener) %7B%0A        AccountImporter.getSharedPreferences(context)%0A                .registerOnSharedPreferenceChangeListener(listener);%0A    %7D%0A    %0A    public static void unregisterSharedPreferenceChangeListener(Context context,%0A                                                                SharedPreferences.OnSharedPreferenceChangeListener listener) %7B%0A        AccountImporter.getSharedPreferences(context)%0A                .unregisterOnSharedPreferenceChangeListener(listener);%0A        %0A    %7D%0A
 %7D%0A

add change listener