Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] Image caching #343

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
fbcf6b0
add setting to download images to device
Strubbl Nov 4, 2016
9a53ce2
check for cached images in ReadArticleActivity and replace image path…
Strubbl Nov 4, 2016
40161cb
move image caching helper functions from ReadArticleActivity to stati…
Strubbl Nov 4, 2016
4d52cfd
increase minSdkVersion to 19, so that we can use getExternalFilesDirs…
Strubbl Nov 4, 2016
bd8faf5
request persmission to write on external storage
Strubbl Nov 4, 2016
f1850fe
implement stupid image download when processing feeds and download on…
Strubbl Nov 4, 2016
879074c
fix spaces
Strubbl Nov 4, 2016
a8dda4c
fix external storage path in ReadArticleActivity, also fix for correc…
Strubbl Nov 4, 2016
2a831ad
fix replacing of cached images in article view
Strubbl Nov 4, 2016
f9f30c2
minSdkVersion 11 again
di72nn Nov 6, 2016
4dd24a7
avoid nullpointer exception
Strubbl Nov 6, 2016
8063af5
article view: fix image replacement when there is more than one image…
Strubbl Nov 6, 2016
52b99d4
remove responsive image parameters to not interfere with original ima…
Strubbl Nov 6, 2016
608e14d
avoid null pointer in case of suspicious image file extension
Strubbl Nov 6, 2016
4c98dab
Add facilities to handle work with different priorities
di72nn Nov 7, 2016
e4990cd
Move Image Fetcher invocation to BGService
di72nn Nov 7, 2016
4915c1c
Use ContextCompat.getExternalFilesDirs()
di72nn Nov 14, 2016
cae8da3
close response to avoid warning about leaked resources
Strubbl Dec 7, 2016
2e02cd8
add more debug info in case image download times out
Strubbl Dec 7, 2016
c83a018
Merge branch 'master' into image-caching
Strubbl Dec 19, 2016
ec38286
use List instead of LazyList when querying for article not having ima…
Strubbl Dec 7, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ android {
}

greendao {
schemaVersion 5
schemaVersion 6
daoPackage 'fr.gaulupeau.apps.Poche.data.dao'
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:name="fr.gaulupeau.apps.Poche.App"
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/fr/gaulupeau/apps/Poche/data/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,14 @@ public void setAutoDownloadNewArticlesEnabled(boolean value) {
setBoolean(R.string.pref_key_autoDlNew_enabled, value);
}

public boolean isImageCacheEnabled() {
return getBoolean(R.string.pref_key_imageCache_enabled, false);
}

public void setImageCacheEnabled(boolean value) {
setBoolean(R.string.pref_key_imageCache_enabled, value);
}

public boolean isFirstRun() {
return getBoolean(R.string.pref_key_internal_firstRun, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,20 @@ public class Article {
@Property(nameInDb = "article_progress")
private Double articleProgress;

@Property(nameInDb = "images_downloaded")
private Boolean imagesDownloaded;

@Generated(hash = 742516792)
public Article() {}

public Article(Long id) {
this.id = id;
}

@Generated(hash = 1900630499)
public Article(Long id, Integer articleId, String content, String author, String title,
String url, Boolean favorite, Boolean archive, Date updateDate,
Double articleProgress) {
@Generated(hash = 1635440040)
public Article(Long id, Integer articleId, String content, String author,
String title, String url, Boolean favorite, Boolean archive,
Date updateDate, Double articleProgress, Boolean imagesDownloaded) {
this.id = id;
this.articleId = articleId;
this.content = content;
Expand All @@ -62,6 +65,7 @@ public Article(Long id, Integer articleId, String content, String author, String
this.archive = archive;
this.updateDate = updateDate;
this.articleProgress = articleProgress;
this.imagesDownloaded = imagesDownloaded;
}

public Long getId() {
Expand Down Expand Up @@ -144,4 +148,12 @@ public void setArticleProgress(Double articleProgress) {
this.articleProgress = articleProgress;
}

public Boolean getImagesDownloaded() {
return imagesDownloaded;
}

public void setImagesDownloaded(Boolean imagesDownloaded) {
this.imagesDownloaded = imagesDownloaded;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public class EventProcessor {

private static final int NOTIFICATION_ID_OTHER = 0;
private static final int NOTIFICATION_ID_UPDATE_FEEDS_ONGOING = 1;
private static final int NOTIFICATION_ID_SYNC_QUEUE_ONGOING = 2;
private static final int NOTIFICATION_ID_FETCH_IMAGES_ONGOING = 2;
private static final int NOTIFICATION_ID_SYNC_QUEUE_ONGOING = 3;

private Context context;
private Settings settings;
Expand Down Expand Up @@ -171,13 +172,49 @@ public void onUpdateFeedsFinishedEvent(UpdateFeedsFinishedEvent event) {

getNotificationManager().cancel(TAG, NOTIFICATION_ID_UPDATE_FEEDS_ONGOING);

if(event.getResult().isSuccess() && !getSettings().isFirstSyncDone()) {
getSettings().setFirstSyncDone(true);
Settings settings = getSettings();

if(event.getResult().isSuccess()) {
if(!getSettings().isFirstSyncDone()) {
settings.setFirstSyncDone(true);
}

if(settings.isImageCacheEnabled()) {
ServiceHelper.fetchImages(getContext());
}
}

emptyOperationID();
}

@Subscribe(sticky = true)
public void onFetchImagesStartedEvent(FetchImagesStartedEvent event) {
Log.d(TAG, "onFetchImagesStartedEvent() started");

setOperationID(event);

Context context = getContext();

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_action_refresh)
.setContentTitle(context.getString(R.string.notification_downloadingImages))
.setOngoing(true);

getNotificationManager().notify(TAG, NOTIFICATION_ID_FETCH_IMAGES_ONGOING,
notificationBuilder.setProgress(0, 0, true).build());
}

@Subscribe
public void onFetchImagesFinishedEvent(FetchImagesFinishedEvent event) {
Log.d(TAG, "onFetchImagesFinishedEvent() started");

checkOperationID(event);

getNotificationManager().cancel(TAG, NOTIFICATION_ID_FETCH_IMAGES_ONGOING);

emptyOperationID();
}

@Subscribe(sticky = true)
public void onSyncQueueStartedEvent(SyncQueueStartedEvent event) {
Log.d(TAG, "onSyncQueueStartedEvent() started");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package fr.gaulupeau.apps.Poche.events;

import fr.gaulupeau.apps.Poche.service.ActionRequest;

public class FetchImagesFinishedEvent extends BackgroundOperationEvent {

public FetchImagesFinishedEvent(ActionRequest request) {
super(request);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package fr.gaulupeau.apps.Poche.events;

import fr.gaulupeau.apps.Poche.service.ActionRequest;

public class FetchImagesStartedEvent extends BackgroundOperationEvent {

public FetchImagesStartedEvent(ActionRequest request) {
super(request);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ private void processFeed(ArticleDao articleDao, InputStream is,
continue;
}

if(updateType == UpdateType.Fast && latestID != null && latestID >= id) break;
if(updateType == UpdateType.Fast && latestID != null && latestID >= id) {
Log.d(TAG, "processFeed(): update type fast, everything up to date");
break;
}

Article article = articleDao.queryBuilder()
.where(ArticleDao.Properties.ArticleId.eq(id)).build().unique();
Expand Down Expand Up @@ -307,6 +310,7 @@ private void processFeed(ArticleDao articleDao, InputStream is,
article.setArchive(feedType == FeedType.Archive);
article.setFavorite(feedType == FeedType.Favorite);
}
article.setImagesDownloaded(false);

if(event != null) {
ArticlesChangedEvent.ChangeType changeType = existing
Expand Down
Loading