mirror of https://github.com/readrops/Readrops.git
Merge branch 'master' into develop
This commit is contained in:
commit
03d5ca7ca6
|
@ -1,3 +1,7 @@
|
||||||
|
# v1.3.1
|
||||||
|
- FreshRSS : Fix items being fav unintentionally
|
||||||
|
- FreshRSS : Fix 401 error when synchronising for the second time
|
||||||
|
|
||||||
# v1.3.0
|
# v1.3.0
|
||||||
- New local RSS parser, much reliable
|
- New local RSS parser, much reliable
|
||||||
- New external navigator view for items (Custom tabs)
|
- New external navigator view for items (Custom tabs)
|
||||||
|
|
|
@ -9,6 +9,7 @@ class SyncResult(var items: List<Item> = mutableListOf(),
|
||||||
var feeds: List<Feed> = listOf(),
|
var feeds: List<Feed> = listOf(),
|
||||||
var folders: List<Folder> = listOf(),
|
var folders: List<Folder> = listOf(),
|
||||||
var unreadIds: List<String>? = null,
|
var unreadIds: List<String>? = null,
|
||||||
|
var readIds: List<String>? = null,
|
||||||
var starredIds: List<String>? = null,
|
var starredIds: List<String>? = null,
|
||||||
var isError: Boolean = false
|
var isError: Boolean = false
|
||||||
)
|
)
|
||||||
|
|
|
@ -12,6 +12,7 @@ import com.readrops.db.entities.Item;
|
||||||
|
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@ -22,10 +23,11 @@ import okhttp3.RequestBody;
|
||||||
|
|
||||||
public class FreshRSSDataSource {
|
public class FreshRSSDataSource {
|
||||||
|
|
||||||
private static final int MAX_ITEMS = 5000;
|
private static final int MAX_ITEMS = 2500;
|
||||||
private static final int MAX_STARRED_ITEMS = 1000;
|
private static final int MAX_STARRED_ITEMS = 1000;
|
||||||
|
|
||||||
public static final String GOOGLE_READ = "user/-/state/com.google/read";
|
public static final String GOOGLE_READ = "user/-/state/com.google/read";
|
||||||
|
public static final String GOOGLE_UNREAD = "user/-/state/com.google/unread";
|
||||||
public static final String GOOGLE_STARRED = "user/-/state/com.google/starred";
|
public static final String GOOGLE_STARRED = "user/-/state/com.google/starred";
|
||||||
public static final String GOOGLE_READING_LIST = "user/-/state/com.google/reading-list";
|
public static final String GOOGLE_READING_LIST = "user/-/state/com.google/reading-list";
|
||||||
|
|
||||||
|
@ -88,46 +90,32 @@ public class FreshRSSDataSource {
|
||||||
* @return the result of the synchronization
|
* @return the result of the synchronization
|
||||||
*/
|
*/
|
||||||
public Single<SyncResult> sync(@NonNull SyncType syncType, @NonNull FreshRSSSyncData syncData, @NonNull String writeToken) {
|
public Single<SyncResult> sync(@NonNull SyncType syncType, @NonNull FreshRSSSyncData syncData, @NonNull String writeToken) {
|
||||||
SyncResult syncResult = new SyncResult();
|
|
||||||
|
|
||||||
return setItemsReadState(syncData, writeToken)
|
|
||||||
.andThen(setItemsStarState(syncData, writeToken))
|
|
||||||
.andThen(getFolders()
|
|
||||||
.flatMap(freshRSSFolders -> {
|
|
||||||
syncResult.setFolders(freshRSSFolders);
|
|
||||||
|
|
||||||
return getFeeds();
|
|
||||||
})
|
|
||||||
.flatMap(freshRSSFeeds -> {
|
|
||||||
syncResult.setFeeds(freshRSSFeeds);
|
|
||||||
|
|
||||||
if (syncType == SyncType.INITIAL_SYNC) {
|
if (syncType == SyncType.INITIAL_SYNC) {
|
||||||
return getItems(Arrays.asList(GOOGLE_READ, GOOGLE_STARRED), MAX_ITEMS, null);
|
return Single.zip(setItemsReadState(syncData, writeToken).toSingleDefault(""),
|
||||||
|
setItemsStarState(syncData, writeToken).toSingleDefault(""),
|
||||||
|
getFolders(),
|
||||||
|
getFeeds(),
|
||||||
|
getItems(Arrays.asList(GOOGLE_READ, GOOGLE_STARRED), MAX_ITEMS, null),
|
||||||
|
getItemsIds(GOOGLE_READ, GOOGLE_READING_LIST, MAX_ITEMS), // unread items ids
|
||||||
|
getItemsIds(null, GOOGLE_STARRED, MAX_STARRED_ITEMS), // starred items ids
|
||||||
|
getStarredItems(MAX_STARRED_ITEMS),
|
||||||
|
(readState, starState, folders, feeds, items, unreadItemsIds, starredItemsIds, starredItems) ->
|
||||||
|
new SyncResult(items, starredItems, feeds, folders, unreadItemsIds, Collections.emptyList(), starredItemsIds, false)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return getItems(null, MAX_ITEMS, syncData.getLastModified());
|
return Single.zip(setItemsReadState(syncData, writeToken).toSingleDefault(""),
|
||||||
|
setItemsStarState(syncData, writeToken).toSingleDefault(""),
|
||||||
|
getFolders(),
|
||||||
|
getFeeds(),
|
||||||
|
getItems(null, MAX_ITEMS, syncData.getLastModified()),
|
||||||
|
getItemsIds(GOOGLE_READ, GOOGLE_READING_LIST, MAX_ITEMS), // unread items ids
|
||||||
|
getItemsIds(GOOGLE_UNREAD, GOOGLE_READING_LIST, MAX_ITEMS), // read items ids
|
||||||
|
getItemsIds(null, GOOGLE_STARRED, MAX_STARRED_ITEMS), // starred items ids
|
||||||
|
(readState, starState, folders, feeds, items, unreadItemsIds, readItemsIds, starredItemsIds) ->
|
||||||
|
new SyncResult(items, Collections.emptyList(), feeds, folders, unreadItemsIds, readItemsIds, starredItemsIds, false)
|
||||||
|
|
||||||
|
);
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.flatMap(freshRSSItems -> {
|
|
||||||
syncResult.setItems(freshRSSItems);
|
|
||||||
|
|
||||||
return getItemsIds(GOOGLE_READ, GOOGLE_READING_LIST, MAX_ITEMS);
|
|
||||||
}).flatMap(unreadItemsIds -> {
|
|
||||||
syncResult.setUnreadIds(unreadItemsIds);
|
|
||||||
|
|
||||||
return getItemsIds(null, GOOGLE_STARRED, MAX_STARRED_ITEMS);
|
|
||||||
}).flatMap(starredItemsIds -> {
|
|
||||||
syncResult.setStarredIds(starredItemsIds);
|
|
||||||
|
|
||||||
if (syncType == SyncType.INITIAL_SYNC) {
|
|
||||||
return getStarredItems(MAX_STARRED_ITEMS).flatMap(starredItems -> {
|
|
||||||
syncResult.setStarredItems(starredItems);
|
|
||||||
|
|
||||||
return Single.just(syncResult);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return Single.just(syncResult);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -183,7 +171,7 @@ public class FreshRSSDataSource {
|
||||||
* @param token token for modifications
|
* @param token token for modifications
|
||||||
* @return Completable
|
* @return Completable
|
||||||
*/
|
*/
|
||||||
public Completable markItemsReadUnread(boolean read, @NonNull List<String> itemIds, @NonNull String token) {
|
public Completable setItemsReadState(boolean read, @NonNull List<String> itemIds, @NonNull String token) {
|
||||||
if (read) {
|
if (read) {
|
||||||
return api.setItemsState(token, GOOGLE_READ, null, itemIds);
|
return api.setItemsState(token, GOOGLE_READ, null, itemIds);
|
||||||
} else {
|
} else {
|
||||||
|
@ -199,7 +187,7 @@ public class FreshRSSDataSource {
|
||||||
* @param token token for modifications
|
* @param token token for modifications
|
||||||
* @return Completable
|
* @return Completable
|
||||||
*/
|
*/
|
||||||
public Completable markItemsStarredUnstarred(boolean starred, @NonNull List<String> itemIds, @NonNull String token) {
|
public Completable setItemsStarState(boolean starred, @NonNull List<String> itemIds, @NonNull String token) {
|
||||||
if (starred) {
|
if (starred) {
|
||||||
return api.setItemsState(token, GOOGLE_STARRED, null, itemIds);
|
return api.setItemsState(token, GOOGLE_STARRED, null, itemIds);
|
||||||
} else {
|
} else {
|
||||||
|
@ -288,14 +276,14 @@ public class FreshRSSDataSource {
|
||||||
if (syncData.getReadItemsIds().isEmpty()) {
|
if (syncData.getReadItemsIds().isEmpty()) {
|
||||||
readItemsCompletable = Completable.complete();
|
readItemsCompletable = Completable.complete();
|
||||||
} else {
|
} else {
|
||||||
readItemsCompletable = markItemsReadUnread(true, syncData.getReadItemsIds(), token);
|
readItemsCompletable = setItemsReadState(true, syncData.getReadItemsIds(), token);
|
||||||
}
|
}
|
||||||
|
|
||||||
Completable unreadItemsCompletable;
|
Completable unreadItemsCompletable;
|
||||||
if (syncData.getUnreadItemsIds().isEmpty()) {
|
if (syncData.getUnreadItemsIds().isEmpty()) {
|
||||||
unreadItemsCompletable = Completable.complete();
|
unreadItemsCompletable = Completable.complete();
|
||||||
} else {
|
} else {
|
||||||
unreadItemsCompletable = markItemsReadUnread(false, syncData.getUnreadItemsIds(), token);
|
unreadItemsCompletable = setItemsReadState(false, syncData.getUnreadItemsIds(), token);
|
||||||
}
|
}
|
||||||
|
|
||||||
return readItemsCompletable.concatWith(unreadItemsCompletable);
|
return readItemsCompletable.concatWith(unreadItemsCompletable);
|
||||||
|
@ -313,14 +301,14 @@ public class FreshRSSDataSource {
|
||||||
if (syncData.getStarredItemsIds().isEmpty()) {
|
if (syncData.getStarredItemsIds().isEmpty()) {
|
||||||
starredItemsCompletable = Completable.complete();
|
starredItemsCompletable = Completable.complete();
|
||||||
} else {
|
} else {
|
||||||
starredItemsCompletable = markItemsStarredUnstarred(true, syncData.getStarredItemsIds(), token);
|
starredItemsCompletable = setItemsStarState(true, syncData.getStarredItemsIds(), token);
|
||||||
}
|
}
|
||||||
|
|
||||||
Completable unstarredItemsCompletable;
|
Completable unstarredItemsCompletable;
|
||||||
if (syncData.getUnstarredItemsIds().isEmpty()) {
|
if (syncData.getUnstarredItemsIds().isEmpty()) {
|
||||||
unstarredItemsCompletable = Completable.complete();
|
unstarredItemsCompletable = Completable.complete();
|
||||||
} else {
|
} else {
|
||||||
unstarredItemsCompletable = markItemsStarredUnstarred(false, syncData.getUnstarredItemsIds(), token);
|
unstarredItemsCompletable = setItemsStarState(false, syncData.getUnstarredItemsIds(), token);
|
||||||
}
|
}
|
||||||
|
|
||||||
return starredItemsCompletable.concatWith(unstarredItemsCompletable);
|
return starredItemsCompletable.concatWith(unstarredItemsCompletable);
|
||||||
|
|
|
@ -11,8 +11,8 @@ android {
|
||||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||||
buildToolsVersion rootProject.ext.buildToolsVersion
|
buildToolsVersion rootProject.ext.buildToolsVersion
|
||||||
|
|
||||||
versionCode 13
|
versionCode 14
|
||||||
versionName "1.3.0"
|
versionName "1.3.1"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
testOptions {
|
testOptions {
|
||||||
|
|
|
@ -133,7 +133,7 @@ public class FreshRSSRepository extends ARepository {
|
||||||
insertItems(syncResult.getStarredItems(), true);
|
insertItems(syncResult.getStarredItems(), true);
|
||||||
logger.addSplit("starred items insertion");
|
logger.addSplit("starred items insertion");
|
||||||
|
|
||||||
insertItemsIds(syncResult.getUnreadIds(), syncResult.getStarredIds());
|
insertItemsIds(syncResult.getUnreadIds(), syncResult.getReadIds(), syncResult.getStarredIds());
|
||||||
logger.addSplit("insert and update items ids");
|
logger.addSplit("insert and update items ids");
|
||||||
|
|
||||||
account.setLastModified(newLastModified);
|
account.setLastModified(newLastModified);
|
||||||
|
@ -269,7 +269,7 @@ public class FreshRSSRepository extends ARepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertItemsIds(List<String> unreadIds, List<String> starredIds) {
|
private void insertItemsIds(List<String> unreadIds, List<String> readIds, List<String> starredIds) {
|
||||||
database.itemStateDao().deleteItemsStates(account.getId());
|
database.itemStateDao().deleteItemsStates(account.getId());
|
||||||
|
|
||||||
database.itemStateDao().insertItemStates(unreadIds.stream().map(id -> {
|
database.itemStateDao().insertItemStates(unreadIds.stream().map(id -> {
|
||||||
|
@ -282,6 +282,16 @@ public class FreshRSSRepository extends ARepository {
|
||||||
}
|
}
|
||||||
).collect(Collectors.toList()));
|
).collect(Collectors.toList()));
|
||||||
|
|
||||||
|
database.itemStateDao().insertItemStates(readIds.stream().map(id -> {
|
||||||
|
boolean starred = starredIds.stream().filter(starredId -> starredId.equals(id)).count() == 1;
|
||||||
|
if (starred) {
|
||||||
|
starredIds.remove(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ItemState(0, true, starred, id, account.getId());
|
||||||
|
}
|
||||||
|
).collect(Collectors.toList()));
|
||||||
|
|
||||||
// insert starred items ids which are read
|
// insert starred items ids which are read
|
||||||
if (!starredIds.isEmpty()) {
|
if (!starredIds.isEmpty()) {
|
||||||
database.itemStateDao().insertItemStates(starredIds.stream().map(id ->
|
database.itemStateDao().insertItemStates(starredIds.stream().map(id ->
|
||||||
|
|
|
@ -15,7 +15,6 @@ import androidx.annotation.ColorInt;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
import com.readrops.api.utils.AuthInterceptor;
|
|
||||||
|
|
||||||
import org.koin.java.KoinJavaComponent;
|
import org.koin.java.KoinJavaComponent;
|
||||||
|
|
||||||
|
@ -37,7 +36,6 @@ public final class Utils {
|
||||||
public static Bitmap getImageFromUrl(String url) {
|
public static Bitmap getImageFromUrl(String url) {
|
||||||
try {
|
try {
|
||||||
Request request = new Request.Builder().url(url).build();
|
Request request = new Request.Builder().url(url).build();
|
||||||
KoinJavaComponent.<AuthInterceptor>get(AuthInterceptor.class).setCredentials(null);
|
|
||||||
|
|
||||||
Response response = KoinJavaComponent.<OkHttpClient>get(OkHttpClient.class).newCall(request).execute();
|
Response response = KoinJavaComponent.<OkHttpClient>get(OkHttpClient.class).newCall(request).execute();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
<ul>
|
||||||
|
<li>FreshRSS : Fix items being fav unintentionally</li>
|
||||||
|
<li>FreshRSS : Fix 401 error when synchronising for the second time</li>
|
||||||
|
</ul>
|
Loading…
Reference in New Issue