Skip to content

Commit

Permalink
Merge branch 'fix-13.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Apr 17, 2014
2 parents de3d946 + e90de32 commit e8c73cd
Show file tree
Hide file tree
Showing 21 changed files with 160 additions and 109 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Changelog

All dates are in the European Central timezone.

Version 13.0.1 *(2014-04-17)*
-----------------------------

* Bugfixes based on past crash reports.

Version 13 *(2014-04-16)*
-----------------------------

Expand Down
2 changes: 2 additions & 0 deletions SeriesGuide/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@
<!-- Services -->
<service android:name="com.battlelancer.seriesguide.service.TraktFlagService" >
</service>
<service android:name="com.battlelancer.seriesguide.util.LatestEpisodeUpdateService">
</service>

<!-- Notification service -->
<service android:name="com.battlelancer.seriesguide.service.NotificationService" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,9 @@ public RemoteViews getViewAt(int position) {
// file, and set the text based on the position.
RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.appwidget_row);

if (mDataCursor.isClosed()) {
if (mDataCursor.isClosed() || !mDataCursor.moveToPosition(position)) {
return rv;
}
// position will always range from 0 to getCount() - 1.
mDataCursor.moveToPosition(position);

// episode description
int seasonNumber = mDataCursor.getInt(isShowQuery ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public List<GetGlueObject> loadInBackground() {
GetGlueObjects results = getglue.searchService().searchTvShows(mQuery);
return results.objects;
} catch (RetrofitError e) {
Timber.e(e, "Search failed");
Timber.e(e, "GetGlue search failed");
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Show loadInBackground() {
try {
return TheTVDB.getShow(getContext(), mShowTvdbId);
} catch (TvdbException e) {
Timber.e("Downloading TVDb show failed", e);
Timber.e(e, "Downloading TVDb show failed");
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ private void stop() {
@Override
public void onSuccess() {
running = false;
mQueue.remove();
if (mQueue.size() > 0) {
mQueue.remove();
}
executeNext();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ private static UpdateResult getTraktActivity(Context context, Trakt trakt,
try {
DBUtils.applyInSmallBatches(context, batch);
} catch (OperationApplicationException e) {
Timber.e("Applying trakt activity failed", e);
Timber.e(e, "Applying trakt activity failed");
return UpdateResult.INCOMPLETE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public void onCheckinEpisode(int episodeTvdbId) {

private void onFlagEpisodeWatched(AdapterContextMenuInfo info, boolean isWatched) {
Cursor item = (Cursor) mAdapter.getItem(info.position);
if (item == null) {
if (item == null || !item.moveToPosition(info.position)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import com.battlelancer.seriesguide.util.DBUtils;
import com.battlelancer.seriesguide.util.EpisodeTools;
import com.battlelancer.seriesguide.util.ImageProvider;
import com.battlelancer.seriesguide.util.LatestEpisodeUpdateService;
import com.battlelancer.seriesguide.util.RemoveShowWorkerFragment;
import com.battlelancer.seriesguide.util.TaskManager;
import com.battlelancer.seriesguide.util.Utils;
Expand Down Expand Up @@ -325,7 +326,9 @@ protected void onNewIntent(Intent intent) {
@Override
protected void onResume() {
super.onResume();
Utils.updateLatestEpisodes(this);

startService(new Intent(this, LatestEpisodeUpdateService.class));

if (mSavedState != null) {
restoreLocalState(mSavedState);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.battlelancer.seriesguide.util.DBUtils;
import com.battlelancer.seriesguide.util.FlagTask.FlagTaskCompletedEvent;
import com.battlelancer.seriesguide.util.ImageProvider;
import com.battlelancer.seriesguide.util.LatestEpisodeUpdateService;
import com.battlelancer.seriesguide.util.ShowTools;
import com.battlelancer.seriesguide.util.TimeTools;
import com.battlelancer.seriesguide.util.Utils;
Expand Down Expand Up @@ -716,7 +717,9 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin

public void onEvent(FlagTaskCompletedEvent event) {
if (isAdded()) {
Utils.updateLatestEpisode(getActivity(), event.mType.getShowTvdbId());
getActivity().startService(new Intent(getActivity(), LatestEpisodeUpdateService.class)
.putExtra(LatestEpisodeUpdateService.InitBundle.SHOW_TVDB_ID,
event.mType.getShowTvdbId()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ public List<UserProfile> loadInBackground() {
final UserService userService = manager.userService();
List<UserProfile> friends = userService
.friends(TraktCredentials.get(getContext()).getUsername());

if (friends == null) {
Timber.e("Loading friends activity failed, was null");
return friendsActivity;
}
for (UserProfile friend : friends) {
// get the detailed profile
UserProfile profile = userService.profile(friend.username);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ protected List<SearchResult> doInBackground(String... params) {
try {
results = TheTVDB.searchShow(query, mContext);
} catch (TvdbException e) {
Timber.e("Searching show failed", e);
Timber.e(e, "Searching show failed");
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void onClick(View v) {
try {
DBUtils.applyInSmallBatches(getActivity(), batch);
} catch (OperationApplicationException e) {
Timber.e("Applying list changes failed", e);
Timber.e(e, "Applying list changes failed");
}

getActivity().getContentResolver().notifyChange(ListItems.CONTENT_WITH_DETAILS_URI,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ public class ImageProvider {

private ImageCache mCache;

private File mCacheDir;

private Context mContext;

private OnSharedPreferenceChangeListener mListener;
Expand All @@ -86,9 +84,8 @@ public ImageProvider(Context context) {
final int maxCacheSizeBytes = (am.getMemoryClass() * 1024 * 1024) / 8;
mCache = new ImageCache(maxCacheSizeBytes);

mCacheDir = mContext.getExternalFilesDir(null);
Timber.d("Init cache with size: " + maxCacheSizeBytes + " bytes, cache directory: "
+ mCacheDir);
+ mContext.getExternalFilesDir(null));

// listen to trim or low memory callbacks so we can shrink our memory
// footprint
Expand Down Expand Up @@ -229,7 +226,7 @@ public Bitmap getImage(String imagePath, boolean loadThumbnail) {
private Bitmap getImageFromExternalStorage(final String imagePath) {
// try to get image from disk
final File imageFile = getImageFile(imagePath);
if (imageFile.exists() && AndroidUtils.isExtStorageAvailable()) {
if (imageFile != null && imageFile.exists()) {
// disk cache hit
final Bitmap result = BitmapFactory.decodeFile(imageFile.getAbsolutePath());
if (result == null) {
Expand All @@ -256,7 +253,9 @@ public void storeImage(String imagePath, Bitmap bitmap, boolean createThumbnail)
createDirectories();

final File imageFile = getImageFile(imagePath);

if (imageFile == null) {
return;
}
try {
imageFile.createNewFile();
FileOutputStream ostream = new FileOutputStream(imageFile);
Expand All @@ -266,7 +265,7 @@ public void storeImage(String imagePath, Bitmap bitmap, boolean createThumbnail)
ostream.close();
}
} catch (IOException e) {
Timber.e(e, "Saving image to disk failed");
Timber.e(e, "Saving image to disk failed " + imageFile);
}

// create a thumbnail, too, if requested
Expand All @@ -290,45 +289,67 @@ public void storeImage(String imagePath, Bitmap bitmap, boolean createThumbnail)
* Remove the given image and a potentially existing thumbnail from the external storage cache.
*/
public void removeImage(String imagePath) {
File image = getImageFile(imagePath);
File thumbnail = getImageFile(imagePath + THUMB_SUFFIX);
try {
getImageFile(imagePath).delete();
getImageFile(imagePath + THUMB_SUFFIX).delete();
if (image != null) {
image.delete();
}
if (thumbnail != null) {
thumbnail.delete();
}
} catch (SecurityException e) {
Timber.e(e, "removeImage: failed");
Timber.e(e, "removeImage: failed " + image + " " + thumbnail);
}
}

public boolean exists(String imagePath) {
return getImageFile(imagePath).exists();
File file = getImageFile(imagePath);
return file != null && file.exists();
}

public File getImageFile(String imagePath) {
return new File(mCacheDir,
Integer.toHexString(imagePath.hashCode()) + "." + IMAGE_FORMAT.name());
/**
* Returns a path for the given image on external storage or null if {@link
* Context#getExternalFilesDir(String)} returns null (e.g. external storage is currently not
* available).
*/
private File getImageFile(String imagePath) {
File path = mContext.getExternalFilesDir(null);
if (path != null) {
return new File(path,
Integer.toHexString(imagePath.hashCode()) + "." + IMAGE_FORMAT.name());
}
return null;
}

private void createDirectories() {
mCacheDir.mkdirs();
File path = mContext.getExternalFilesDir(null);
if (path != null) {
path.mkdirs();
}

final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
updateNoMediaFile(prefs);
}

private void updateNoMediaFile(SharedPreferences prefs) {
final File noMediaFile = new File(mCacheDir, ".nomedia");
File path = mContext.getExternalFilesDir(null);
if (path == null) {
Timber.w("Could not create .nomedia file, external storage not available");
return;
}

final File noMediaFile = new File(path, ".nomedia");
if (prefs.getBoolean(SeriesGuidePreferences.KEY_HIDEIMAGES, true)) {
try {
boolean created = noMediaFile.createNewFile();
if (created) {
Timber.d("Created .nomedia file");
}
Timber.d("Created .nomedia file: " + created);
} catch (IOException e) {
Timber.w("Could not create .nomedia file");
Timber.w(e, "Could not create .nomedia file");
}
} else {
noMediaFile.delete();
Timber.d("Deleting .nomedia file");
Timber.d("Deleted .nomedia file");
}
}

Expand All @@ -344,7 +365,13 @@ public void clearCache() {
* Clear all files in cache directory.
*/
public void clearExternalStorageCache() {
final File[] files = mCacheDir.listFiles();
File path = mContext.getExternalFilesDir(null);
if (path == null) {
Timber.w("Could not clear cache, external storage not available");
return;
}

final File[] files = path.listFiles();
if (files != null) {
for (File file : files) {
file.delete();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2014 Uwe Trottmann
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.battlelancer.seriesguide.util;

import android.app.IntentService;
import android.content.Intent;
import android.database.Cursor;
import com.battlelancer.seriesguide.provider.SeriesGuideContract;
import com.battlelancer.seriesguide.settings.DisplaySettings;
import java.util.HashSet;

/**
* Updates the latest episode value for a given show or all shows.
*/
public class LatestEpisodeUpdateService extends IntentService {

public interface InitBundle {
/** TVDb id of the show to update or 0 to update all shows. */
String SHOW_TVDB_ID = "show_tvdbid";
}

public LatestEpisodeUpdateService() {
super("LatestEpisodeUpdateService");
}

@Override
protected void onHandleIntent(Intent intent) {
int showTvdbId = intent.getIntExtra(InitBundle.SHOW_TVDB_ID, 0);

boolean isNoReleasedEpisodes = DisplaySettings.isNoReleasedEpisodes(
getApplicationContext());
boolean isNoSpecials = DisplaySettings.isHidingSpecials(getApplicationContext());

if (showTvdbId > 0) {
// update single show
DBUtils.updateLatestEpisode(getApplicationContext(), showTvdbId, isNoReleasedEpisodes,
isNoSpecials);
} else {
// update all shows
HashSet<Integer> shows = ShowTools.getShowTvdbIdsAsSet(getApplicationContext());
for (int tvdbId : shows) {
DBUtils.updateLatestEpisode(getApplicationContext(), tvdbId,
isNoReleasedEpisodes, isNoSpecials);
}
}

// Show adapter gets notified by ContentProvider
// Lists adapter needs to be notified manually
getContentResolver().notifyChange(SeriesGuideContract.ListItems.CONTENT_WITH_DETAILS_URI,
null);
}
}
Loading

0 comments on commit e8c73cd

Please sign in to comment.