aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-08-28 22:13:10 -0700
committerScott Jackson <daneren2005@gmail.com>2013-08-28 22:13:10 -0700
commit9e1706fc4e67eca6ba69c1a62f8c0f6fc6a76eba (patch)
treee9fc363fb9fb97f95e1444420611e4411becf5db /src
parent054f83744088381f99765bf2957ddbed19d8e61f (diff)
downloaddsub-9e1706fc4e67eca6ba69c1a62f8c0f6fc6a76eba.tar.gz
dsub-9e1706fc4e67eca6ba69c1a62f8c0f6fc6a76eba.tar.bz2
dsub-9e1706fc4e67eca6ba69c1a62f8c0f6fc6a76eba.zip
Start of custom SyncAdapters
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/activity/MainActivity.java13
-rw-r--r--src/github/daneren2005/dsub/service/sync/AuthenticatorService.java90
-rw-r--r--src/github/daneren2005/dsub/service/sync/StubProvider.java61
-rw-r--r--src/github/daneren2005/dsub/service/sync/SyncAdapter.java47
-rw-r--r--src/github/daneren2005/dsub/service/sync/SyncService.java48
-rw-r--r--src/github/daneren2005/dsub/util/Constants.java4
6 files changed, 263 insertions, 0 deletions
diff --git a/src/github/daneren2005/dsub/activity/MainActivity.java b/src/github/daneren2005/dsub/activity/MainActivity.java
index 8aa68b3d..042fde94 100644
--- a/src/github/daneren2005/dsub/activity/MainActivity.java
+++ b/src/github/daneren2005/dsub/activity/MainActivity.java
@@ -1,6 +1,9 @@
package github.daneren2005.dsub.activity;
+import android.accounts.Account;
+import android.accounts.AccountManager;
import android.app.AlertDialog;
+import android.content.ContentResolver;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.TypedArray;
@@ -61,6 +64,7 @@ public class MainActivity extends SubsonicActivity {
}
setContentView(R.layout.main);
loadSettings();
+ createAccount();
bottomBar = findViewById(R.id.bottom_bar);
bottomBar.setOnClickListener(new View.OnClickListener() {
@@ -307,6 +311,15 @@ public class MainActivity extends SubsonicActivity {
}
}
+ private void createAccount() {
+ AccountManager accountManager = (AccountManager) this.getSystemService(ACCOUNT_SERVICE);
+ Account account = new Account(Constants.SYNC_ACCOUNT_NAME, Constants.SYNC_ACCOUNT_TYPE);
+ accountManager.addAccountExplicitly(account, null, null);
+
+ // Make sync run every hour
+ ContentResolver.addPeriodicSync(account, Constants.SYNC_ACCOUNT_TYPE, new Bundle(), 1000L * 60L * 60L);
+ }
+
private void showInfoDialog() {
if (!infoDialogDisplayed) {
infoDialogDisplayed = true;
diff --git a/src/github/daneren2005/dsub/service/sync/AuthenticatorService.java b/src/github/daneren2005/dsub/service/sync/AuthenticatorService.java
new file mode 100644
index 00000000..ae12c88e
--- /dev/null
+++ b/src/github/daneren2005/dsub/service/sync/AuthenticatorService.java
@@ -0,0 +1,90 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic 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.
+
+ Subsonic 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 Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+
+package github.daneren2005.dsub.service.sync;
+
+import android.accounts.AbstractAccountAuthenticator;
+import android.accounts.Account;
+import android.accounts.AccountAuthenticatorResponse;
+import android.accounts.NetworkErrorException;
+import android.app.Service;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.IBinder;
+
+/**
+ * Created by Scott on 8/28/13.
+ */
+
+public class AuthenticatorService extends Service {
+ private SubsonicAuthenticator authenticator;
+
+ @Override
+ public void onCreate() {
+ authenticator = new SubsonicAuthenticator(this);
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return authenticator.getIBinder();
+
+ }
+
+ private class SubsonicAuthenticator extends AbstractAccountAuthenticator {
+ public SubsonicAuthenticator(Context context) {
+ super(context);
+ }
+
+ @Override
+ public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) {
+ return null;
+ }
+
+ @Override
+ public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException {
+ return null;
+ }
+
+ @Override
+ public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options) throws NetworkErrorException {
+ return null;
+ }
+
+ @Override
+ public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException {
+ return null;
+ }
+
+ @Override
+ public String getAuthTokenLabel(String authTokenType) {
+ return null;
+ }
+
+ @Override
+ public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException {
+ return null;
+ }
+
+ @Override
+ public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features) throws NetworkErrorException {
+ return null;
+ }
+ }
+}
diff --git a/src/github/daneren2005/dsub/service/sync/StubProvider.java b/src/github/daneren2005/dsub/service/sync/StubProvider.java
new file mode 100644
index 00000000..d04d8772
--- /dev/null
+++ b/src/github/daneren2005/dsub/service/sync/StubProvider.java
@@ -0,0 +1,61 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic 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.
+
+ Subsonic 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 Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+
+package github.daneren2005.dsub.service.sync;
+
+import android.content.ContentProvider;
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.net.Uri;
+
+/**
+ * Created by Scott on 8/28/13.
+ */
+
+public class StubProvider extends ContentProvider {
+ @Override
+ public boolean onCreate() {
+ return true;
+ }
+
+ @Override
+ public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
+ return null;
+ }
+
+ @Override
+ public String getType(Uri uri) {
+ return new String();
+ }
+
+ @Override
+ public Uri insert(Uri uri, ContentValues values) {
+ return null;
+ }
+
+ @Override
+ public int delete(Uri uri, String selection, String[] selectionArgs) {
+ return 0;
+ }
+
+ @Override
+ public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
+ return 0;
+ }
+}
diff --git a/src/github/daneren2005/dsub/service/sync/SyncAdapter.java b/src/github/daneren2005/dsub/service/sync/SyncAdapter.java
new file mode 100644
index 00000000..a063ad59
--- /dev/null
+++ b/src/github/daneren2005/dsub/service/sync/SyncAdapter.java
@@ -0,0 +1,47 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic 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.
+
+ Subsonic 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 Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+
+package github.daneren2005.dsub.service.sync;
+
+import android.accounts.Account;
+import android.annotation.TargetApi;
+import android.content.AbstractThreadedSyncAdapter;
+import android.content.ContentProviderClient;
+import android.content.Context;
+import android.content.SyncResult;
+import android.os.Bundle;
+
+/**
+ * Created by Scott on 8/28/13.
+ */
+
+public class SyncAdapter extends AbstractThreadedSyncAdapter {
+ public SyncAdapter(Context context, boolean autoInitialize) {
+ super(context, autoInitialize);
+ }
+ @TargetApi(14)
+ public SyncAdapter(Context context, boolean autoInitialize, boolean allowParallelSyncs) {
+ super(context, autoInitialize, allowParallelSyncs);
+ }
+
+ @Override
+ public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
+
+ }
+}
diff --git a/src/github/daneren2005/dsub/service/sync/SyncService.java b/src/github/daneren2005/dsub/service/sync/SyncService.java
new file mode 100644
index 00000000..aea6069f
--- /dev/null
+++ b/src/github/daneren2005/dsub/service/sync/SyncService.java
@@ -0,0 +1,48 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic 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.
+
+ Subsonic 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 Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+
+package github.daneren2005.dsub.service.sync;
+
+import android.app.Service;
+import android.content.Intent;
+import android.os.IBinder;
+
+/**
+ * Created by Scott on 8/28/13.
+ */
+
+public class SyncService extends Service {
+ private static SyncAdapter playlistSyncAdapter;
+ private static final Object syncLock = new Object();
+
+ @Override
+ public void onCreate() {
+ synchronized (syncLock) {
+ if(playlistSyncAdapter == null) {
+ playlistSyncAdapter = new SyncAdapter(getApplicationContext(), true);
+ }
+ }
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return playlistSyncAdapter.getSyncAdapterBinder();
+
+ }
+}
diff --git a/src/github/daneren2005/dsub/util/Constants.java b/src/github/daneren2005/dsub/util/Constants.java
index 41e13b2f..d1bd6958 100644
--- a/src/github/daneren2005/dsub/util/Constants.java
+++ b/src/github/daneren2005/dsub/util/Constants.java
@@ -140,6 +140,10 @@ public final class Constants {
public static final String OFFLINE_SYNC_NAME = "github.daneren2005.dsub.offline";
public static final String OFFLINE_SYNC_DEFAULT = "syncDefaults";
+ // Account prefs
+ public static final String SYNC_ACCOUNT_NAME = "Subsonic Account";
+ public static final String SYNC_ACCOUNT_TYPE = "subsonic.org";
+
// Number of free trial days for non-licensed servers.
public static final int FREE_TRIAL_DAYS = 30;