Skip to content

Commit

Permalink
Merge branch 'fix-7.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Aug 10, 2013
2 parents d6c2abc + bfd5e57 commit 1cb7ec7
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 59 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ Changelog

All dates are in the European Central timezone.

Version 7.1 *(2013-08-10)*
-----------------

* NOTICE Allow removal of SeriesGuide account from Android settings. If you experience random crashes, try removing and then adding the SeriesGuide account again.
* FIX Crash when disconnecting from trakt.
* FIX Crash when checking for in-app purchases (X subscription).
* FIX Only update a show once every 12 hours when accessing its overview page.

Version 7 *(2013-08-08)*
-----------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,15 @@

package com.battlelancer.seriesguide;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.annotation.SuppressLint;
import android.app.Application;
import android.content.ContentProvider;
import android.content.ContentResolver;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.StrictMode;
import android.os.StrictMode.ThreadPolicy;
import android.os.StrictMode.VmPolicy;
import android.preference.PreferenceManager;

import com.battlelancer.seriesguide.sync.SgAccountAuthenticator;
import com.battlelancer.seriesguide.ui.SeriesGuidePreferences;
import com.battlelancer.seriesguide.util.ImageProvider;
import com.battlelancer.seriesguide.util.Utils;
Expand Down Expand Up @@ -72,16 +67,6 @@ public void onCreate() {
// Set a context for Google Analytics
EasyTracker.getInstance().setContext(this);

// Set up a dummy account for syncing
AccountManager manager = AccountManager.get(this);
final Account account = SgAccountAuthenticator.getSyncAccount(this);
if (manager.addAccountExplicitly(account, null, null)) {
ContentResolver.setIsSyncable(account, CONTENT_AUTHORITY, 1);
ContentResolver.setSyncAutomatically(account, CONTENT_AUTHORITY, true);
// Sync daily by default
ContentResolver.addPeriodicSync(account, CONTENT_AUTHORITY, new Bundle(), 24 * 60 * 60);
}

// Enable StrictMode
enableStrictMode();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,10 @@ int queryPurchases(Inventory inv, String itemType) throws JSONException, RemoteE

do {
logDebug("Calling getPurchases with continuation token: " + continueToken);
if (!mSetupDone) {
logError("IabHelper was disposed before we would do something.");
return IABHELPER_BAD_RESPONSE;
}
Bundle ownedItems = mService.getPurchases(3, mContext.getPackageName(),
itemType, continueToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,30 @@
import android.accounts.AccountAuthenticatorResponse;
import android.accounts.AccountManager;
import android.accounts.NetworkErrorException;
import android.content.ContentResolver;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;

import com.battlelancer.seriesguide.SeriesGuideApplication;

public class SgAccountAuthenticator extends AbstractAccountAuthenticator {

public static final String ACCOUNT_NAME = "SeriesGuide Sync";
private static final String TAG = "SgAccountAuthenticator";
private Context mContext;

public static Account getSyncAccount(Context context) {
Account account = new Account(SgAccountAuthenticator.ACCOUNT_NAME, context.getPackageName());
return account;
}

public SgAccountAuthenticator(Context context) {
super(context);
mContext = 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 {
Log.d(TAG, "Setting up sync account");

// set up a dummy account for syncing
AccountManager manager = AccountManager.get(mContext);
final Account account = new Account(ACCOUNT_NAME, mContext.getPackageName());
manager.addAccountExplicitly(account, null, null);
ContentResolver.setIsSyncable(account, SeriesGuideApplication.CONTENT_AUTHORITY, 1);
ContentResolver.setSyncAutomatically(account, SeriesGuideApplication.CONTENT_AUTHORITY,
true);
SyncUtils.createSyncAccount(mContext);

Log.d(TAG, "Finished setting up sync account");

return null;
final Account account = SyncUtils.getSyncAccount(mContext);
Bundle bundle = new Bundle();
bundle.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type);
return bundle;
}

@Override
Expand All @@ -59,6 +38,11 @@ public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account
return null;
}

@Override
public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) {
throw new UnsupportedOperationException();
}

@Override
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account,
String authTokenType, Bundle options) throws NetworkErrorException {
Expand All @@ -79,14 +63,19 @@ public Bundle updateCredentials(AccountAuthenticatorResponse response, Account a
@Override
public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account,
String[] features) throws NetworkErrorException {
return null;
// This call is used to query whether the Authenticator supports
// specific features. We don't expect to get called, so we always
// return false (no) for any queries.
final Bundle result = new Bundle();
result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, false);
return result;
}

@Override
public Bundle getAccountRemovalAllowed(AccountAuthenticatorResponse response, Account account)
throws NetworkErrorException {
final Bundle result = new Bundle();
result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, false);
result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static void requestSync(Context context, int showTvdbId, boolean isUserRe
args.putBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_SETTINGS, true);
}

final Account account = SgAccountAuthenticator.getSyncAccount(context);
final Account account = SyncUtils.getSyncAccount(context);
ContentResolver.requestSync(account,
SeriesGuideApplication.CONTENT_AUTHORITY, args);

Expand All @@ -134,7 +134,7 @@ public static void requestSync(Context context, int showTvdbId, boolean isUserRe
* tickle.
*/
public static void setSyncAutomatically(Context context, boolean sync) {
final Account account = SgAccountAuthenticator.getSyncAccount(context);
final Account account = SyncUtils.getSyncAccount(context);
ContentResolver.setSyncAutomatically(account, SeriesGuideApplication.CONTENT_AUTHORITY,
sync);
}
Expand All @@ -143,7 +143,7 @@ public static void setSyncAutomatically(Context context, boolean sync) {
* Check if the provider should be synced when a network tickle is received.
*/
public static boolean isSyncAutomatically(Context context) {
return ContentResolver.getSyncAutomatically(SgAccountAuthenticator.getSyncAccount(context),
return ContentResolver.getSyncAutomatically(SyncUtils.getSyncAccount(context),
SeriesGuideApplication.CONTENT_AUTHORITY);
}

Expand All @@ -153,7 +153,7 @@ public static boolean isSyncAutomatically(Context context) {
*/
public static boolean isSyncActive(Context context, boolean displayWarning) {
boolean isSyncActive = ContentResolver.isSyncActive(
SgAccountAuthenticator.getSyncAccount(context),
SyncUtils.getSyncAccount(context),
SeriesGuideApplication.CONTENT_AUTHORITY);
if (isSyncActive) {
Toast.makeText(context, R.string.update_inprogress, Toast.LENGTH_LONG).show();
Expand Down
50 changes: 50 additions & 0 deletions SeriesGuide/src/com/battlelancer/seriesguide/sync/SyncUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

package com.battlelancer.seriesguide.sync;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.ContentResolver;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;

import com.battlelancer.seriesguide.SeriesGuideApplication;

public class SyncUtils {

private static final String TAG = "SyncUtils";

private static final String ACCOUNT_NAME = "SeriesGuide Sync";

private static final int SYNC_FREQUENCY = 24 * 60 * 60; // 1 day (in
// seconds)

public static void createSyncAccount(Context context) {
Log.d(TAG, "Setting up sync account");

// Create account, if it's missing. (Either first run, or user has
// deleted account.)
AccountManager manager = AccountManager.get(context);
final Account account = SyncUtils.getSyncAccount(context);
if (manager.addAccountExplicitly(account, null, null)) {
// Inform the system that this account supports sync
ContentResolver.setIsSyncable(account, SeriesGuideApplication.CONTENT_AUTHORITY, 1);
// Inform the system that this account is eligible for auto sync
// when the network is up
ContentResolver.setSyncAutomatically(account, SeriesGuideApplication.CONTENT_AUTHORITY,
true);
// Recommend a schedule for automatic synchronization. The system
// may modify this based
// on other scheduled syncs and network utilization.
ContentResolver.addPeriodicSync(account, SeriesGuideApplication.CONTENT_AUTHORITY,
new Bundle(), SYNC_FREQUENCY);
}

Log.d(TAG, "Finished setting up sync account");
}

public static Account getSyncAccount(Context context) {
return new Account(ACCOUNT_NAME, context.getPackageName());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.battlelancer.seriesguide.items.Series;
import com.battlelancer.seriesguide.sync.SgSyncAdapter;
import com.battlelancer.seriesguide.util.DBUtils;
import com.battlelancer.thetvdbapi.TheTVDB;
import com.google.analytics.tracking.android.EasyTracker;
import com.uwetrottmann.androidutils.AndroidUtils;
import com.uwetrottmann.seriesguide.R;
Expand Down Expand Up @@ -260,14 +261,18 @@ public boolean onOptionsItemSelected(MenuItem item) {
* Delayed request to sync the displayed show.
*/
private void onUpdateShow() {
final Context context = getApplicationContext();
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
SgSyncAdapter.requestSync(context, mShowId, false);
}
}, 1000);
final String showId = String.valueOf(mShowId);
boolean isTime = TheTVDB.isUpdateShow(showId, System.currentTimeMillis(), this);
if (isTime) {
final Context context = getApplicationContext();
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
SgSyncAdapter.requestSync(context, mShowId, false);
}
}, 1000);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.battlelancer.seriesguide.provider.SeriesContract.Shows;
import com.battlelancer.seriesguide.settings.AppSettings;
import com.battlelancer.seriesguide.sync.SgSyncAdapter;
import com.battlelancer.seriesguide.sync.SyncUtils;
import com.battlelancer.seriesguide.ui.FirstRunFragment.OnFirstRunDismissedListener;
import com.battlelancer.seriesguide.ui.dialogs.ChangesDialogFragment;
import com.battlelancer.seriesguide.util.CompatActionBarNavHandler;
Expand Down Expand Up @@ -91,6 +92,9 @@ public class ShowsActivity extends BaseTopShowsActivity implements CompatActionB
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getMenu().setContentView(R.layout.shows);

// Set up a sync account if needed
SyncUtils.createSyncAccount(this);

final SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ public static void clearTraktCredentials(Context context) {
editor.commit();

// remove from memory
ServiceUtils.sTraktServiceManagerWithAuthInstance.setAuthentication(null, null);
if (sTraktServiceManagerWithAuthInstance != null) {
sTraktServiceManagerWithAuthInstance.setAuthentication(null, null);
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions SeriesGuideFree/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.battlelancer.seriesguide"
android:installLocation="auto"
android:versionCode="170"
android:versionName="7" >
android:versionCode="171"
android:versionName="7.1" >

<uses-sdk
android:minSdkVersion="8"
Expand Down

0 comments on commit 1cb7ec7

Please sign in to comment.