Skip to content

Commit

Permalink
Merge branch 'hotfix/5.2.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
ccomeaux committed Jun 2, 2016
2 parents 8135e47 + e771024 commit e98e400
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 30 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Release Notes
=============

Version 5.2.7
-------------
* No more RetrofitError when modifying your collection (we hope!)
* Bug fixes

Version 5.2.6
-------------
* Improvements to syncing logic (it won't completely fix the syncing problems, but it's a start!
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ android {
applicationId "com.boardgamegeek"
minSdkVersion 9
targetSdkVersion 23
versionCode 58
versionName "5.2.6"
versionCode 59
versionName "5.2.7"
buildConfigField "String", "BRANCH", "\"" + getBranchName() + "\""
}
buildTypes {
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/java/com/boardgamegeek/io/Adapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ public void intercept(RequestFacade request) {
.setEndpoint("https://www.boardgamegeek.com/")
.setRequestInterceptor(requestInterceptor)
.setClient(new OkClient(client));
if (DEBUG) {
builder.setLog(new AndroidLog("BGG-retrofit")).setLogLevel(LogLevel.FULL);
}
builder.setLog(new AndroidLog("BGG-retrofit")).setLogLevel(DEBUG ? LogLevel.HEADERS : LogLevel.FULL);

return builder;
}
Expand All @@ -75,7 +73,7 @@ private static Builder addAuth(final Context context, Builder builder) {
AccountManager accountManager = AccountManager.get(context);
final Account account = Authenticator.getAccount(accountManager);
try {
final String authToken = accountManager.blockingGetAuthToken(account, Authenticator.AUTH_TOKEN_TYPE, true);
final String authToken = (account == null) ? "" : accountManager.blockingGetAuthToken(account, Authenticator.AUTH_TOKEN_TYPE, true);
requestInterceptor = new RequestInterceptor() {
@Override
public void intercept(RequestFacade request) {
Expand Down
27 changes: 7 additions & 20 deletions app/src/main/java/com/boardgamegeek/sorter/PlaysDateSorter.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,23 @@
import android.content.Context;
import android.database.Cursor;
import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.boardgamegeek.R;
import com.boardgamegeek.provider.BggContract.Plays;
import com.boardgamegeek.util.DateTimeUtils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;

import timber.log.Timber;

public class PlaysDateSorter extends PlaysSorter {
private final SimpleDateFormat formatter = new SimpleDateFormat("MMMM", Locale.getDefault());
private final GregorianCalendar calendar = new GregorianCalendar();
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("MMMM yyyy", Locale.getDefault());

public PlaysDateSorter(@NonNull Context context) {
super(context);
orderByClause = Plays.DEFAULT_SORT;
descriptionId = R.string.menu_plays_sort_date;

// account for leap years
calendar.set(Calendar.YEAR, 2012);
calendar.set(Calendar.DAY_OF_MONTH, 1);
}

@Override
Expand All @@ -42,18 +35,12 @@ public String[] getColumns() {
@NonNull
@Override
public String getHeaderText(@NonNull Cursor cursor) {
String date = getYearAndMonth(cursor);
int month = Integer.parseInt(date.substring(5, 7));
calendar.set(Calendar.MONTH, month - 1);
return formatter.format(calendar.getTime()) + " " + date.substring(0, 4);
}

private String getYearAndMonth(@NonNull Cursor cursor) {
String date = getString(cursor, Plays.DATE);
Timber.w("Attempting to parse date %s", date);
if (TextUtils.isEmpty(date)) {
return "1969-01";
long millis = DateTimeUtils.getMillisFromApiDate(date, 0);
if (millis == 0) {
Timber.w("This isn't a date in the expected format: " + date);
return date;
}
return date.substring(0, 7);
return DATE_FORMAT.format(millis);
}
}
4 changes: 4 additions & 0 deletions app/src/main/java/com/boardgamegeek/ui/PlaysFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,10 @@ public void onDestroyActionMode(ActionMode mode) {

@Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
if (!isAdded()) {
return;
}

if (checked) {
mSelectedPlaysPositions.add(position);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private boolean hasTwoDecimalPoints(String text) {
}

private double parseDouble(String text) {
if (TextUtils.isEmpty(text) || ".".equals(text)) {
if (TextUtils.isEmpty(text) || ".".equals(text) || "-".equals(text)) {
return 0.0;
}
if (text.endsWith(".")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected void log(int priority, String tag, String message, Throwable t) {

Crashlytics.getInstance().core.log(priority, tag, message);

if (t != null) {
if (t != null && priority == Log.ERROR) {
Crashlytics.getInstance().core.logException(t);
}
}
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/com/boardgamegeek/util/DateTimeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.Calendar;
import java.util.Locale;

import timber.log.Timber;

public class DateTimeUtils {
public static final long UNPARSED_DATE = -2;
public static final long UNKNOWN_DATE = -1;
Expand Down Expand Up @@ -88,6 +90,23 @@ public static String formatDateForApi(int year, int month, int day) {
return String.format("%04d", year) + "-" + String.format("%02d", month + 1) + "-" + String.format("%02d", day);
}

public static long getMillisFromApiDate(String date, long defaultMillis) {
if (TextUtils.isEmpty(date)) {
return defaultMillis;
}
String[] parts = date.split("-");
if (parts.length != 3) {
return defaultMillis;
}
Calendar calendar = Calendar.getInstance();
try {
calendar.set(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]) - 1, Integer.parseInt(parts[2]));
} catch (Exception e) {
Timber.w(e, "Couldn't get a date from the API: " + date);
}
return calendar.getTimeInMillis();
}

/**
* Formats a date for use in the API (<code>yyyy-mm-dd</code>)
*/
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/java/com/boardgamegeek/util/PaletteUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ public static Palette.Swatch getDarkSwatch(Palette palette) {
return swatch;
}

return palette.getSwatches().get(0);
if (palette.getSwatches().size() > 0) {
return palette.getSwatches().get(0);
}

return new Palette.Swatch(Color.BLACK, 0);
}

/**
Expand All @@ -132,6 +136,10 @@ public static Palette.Swatch getHeaderSwatch(Palette palette) {
return swatch;
}

return palette.getSwatches().get(0);
if (palette.getSwatches().size() > 0) {
return palette.getSwatches().get(0);
}

return new Palette.Swatch(Color.BLACK, 0);
}
}

0 comments on commit e98e400

Please sign in to comment.