package fr.ydelouis.selfoss.sync;

import android.accounts.Account;
import android.content.ContentResolver;
import android.os.Bundle;

import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EBean;

import fr.ydelouis.selfoss.account.SelfossAccount;

@EBean
public class SyncManager {

	private static final String AUTHORITY = "fr.ydelouis.selfoss";

	public static void setPeriodicSync(SelfossAccount selfossAccount) {
		Account account = selfossAccount.getAccount();
		if (account != null) {
			ContentResolver.setSyncAutomatically(account, AUTHORITY, selfossAccount.getSyncPeriod().isAutomatic());
			ContentResolver.addPeriodicSync(account, AUTHORITY, new Bundle(), selfossAccount.getSyncPeriod().getTime());
		}
	}

	@Bean protected SelfossAccount selfossAccount;

	public void requestSync() {
		Account account = selfossAccount.getAccount();
		if (account != null) {
			Bundle extras = new Bundle();
			extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
			extras.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
			ContentResolver.requestSync(account, AUTHORITY, extras);
		}
	}

	public boolean isActive() {
		return ContentResolver.isSyncActive(selfossAccount.getAccount(), AUTHORITY);
	}

}

@@ -1163,16 +1163,112 @@
 e() %7B%0A%09%09
+  Account account = selfossAccount.getAccount();%0A          if (account != null) %7B%0A              
 return C
@@ -1299,35 +1299,15 @@
 ive(
-selfossAccount.getA
+a
 ccount
-()
 , AU
@@ -1316,14 +1316,73 @@
 ORITY);%0A
+          %7D else %7B%0A              return false;%0A          %7D%0A
 %09%7D%0A%0A%7D%0A

fix startup crash on L preview