mirror of
https://github.com/readrops/Readrops.git
synced 2025-01-30 10:25:05 +01:00
Add mark item read/unread request
This commit is contained in:
parent
d618957d24
commit
75e9323177
@ -36,6 +36,7 @@ import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.SecondaryDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
|
||||
import com.readrops.app.R;
|
||||
import com.readrops.app.adapters.MainItemListAdapter;
|
||||
import com.readrops.app.database.entities.Account;
|
||||
import com.readrops.app.database.entities.Feed;
|
||||
import com.readrops.app.database.entities.Folder;
|
||||
@ -46,7 +47,6 @@ import com.readrops.app.utils.GlideApp;
|
||||
import com.readrops.app.utils.SharedPreferencesManager;
|
||||
import com.readrops.app.utils.Utils;
|
||||
import com.readrops.app.viewmodels.MainViewModel;
|
||||
import com.readrops.app.adapters.MainItemListAdapter;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
@ -269,8 +269,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
|
||||
intent.putExtra(ItemActivity.IMAGE_URL, itemWithFeed.getItem().getImageLink());
|
||||
startActivityForResult(intent, ITEM_REQUEST);
|
||||
|
||||
viewModel.setItemReadState(itemWithFeed.getItem().getId(), true,
|
||||
!itemWithFeed.getItem().isReadChanged())
|
||||
viewModel.setItemReadState(itemWithFeed, true)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnError(throwable -> Utils.showSnackbar(rootLayout, throwable.getMessage()))
|
||||
@ -385,8 +384,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
|
||||
if (i == ItemTouchHelper.LEFT) { // set item read state
|
||||
ItemWithFeed itemWithFeed = adapter.getItemWithFeed(viewHolder.getAdapterPosition());
|
||||
|
||||
viewModel.setItemReadState(itemWithFeed.getItem().getId(), !itemWithFeed.getItem().isRead(),
|
||||
!itemWithFeed.getItem().isReadChanged())
|
||||
viewModel.setItemReadState(itemWithFeed, !itemWithFeed.getItem().isRead())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnError(throwable -> Utils.showSnackbar(rootLayout, throwable.getMessage()))
|
||||
|
@ -8,8 +8,8 @@ import com.readrops.app.viewmodels.MainViewModel;
|
||||
|
||||
public class ItemsListQueryBuilder {
|
||||
|
||||
private String [] columns = {"Item.id", "title", "clean_description", "image_link", "pub_date", "read",
|
||||
"read_changed", "read_it_later", "Feed.name", "text_color", "background_color", "icon_url", "read_time",
|
||||
private String[] columns = {"Item.id", "title", "clean_description", "image_link", "pub_date", "read",
|
||||
"read_changed", "read_it_later", "Feed.name", "text_color", "background_color", "icon_url", "read_time", "Item.remoteId",
|
||||
"Feed.id as feedId", "Feed.account_id", "Folder.id as folder_id", "Folder.name as folder_name"};
|
||||
|
||||
private String SELECT_ALL_JOIN = "Item INNER JOIN Feed on Item.feed_id = Feed.id " +
|
||||
@ -69,7 +69,6 @@ public class ItemsListQueryBuilder {
|
||||
else
|
||||
queryBuilder.orderBy(ORDER_BY_DESC);
|
||||
|
||||
|
||||
return queryBuilder.create();
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ import androidx.room.Ignore;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
import com.readrops.app.R;
|
||||
import com.readrops.readropslibrary.services.freshrss.FreshRSSCredentials;
|
||||
import com.readrops.readropslibrary.services.nextcloudnews.NextNewsCredentials;
|
||||
|
||||
@Entity
|
||||
@ -38,6 +39,7 @@ public class Account implements Parcelable {
|
||||
private boolean currentAccount;
|
||||
|
||||
private String token;
|
||||
private String writeToken; // TODO : see if there is a better solution to store specific service account fields
|
||||
|
||||
@Ignore
|
||||
private String login;
|
||||
@ -167,6 +169,14 @@ public class Account implements Parcelable {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public String getWriteToken() {
|
||||
return writeToken;
|
||||
}
|
||||
|
||||
public void setWriteToken(String writeToken) {
|
||||
this.writeToken = writeToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
@ -238,6 +248,10 @@ public class Account implements Parcelable {
|
||||
return new NextNewsCredentials(login, password, url);
|
||||
}
|
||||
|
||||
public FreshRSSCredentials toFreshRSSCredentials() {
|
||||
return new FreshRSSCredentials(token, url);
|
||||
}
|
||||
|
||||
public boolean isLocal() {
|
||||
return accountType == AccountType.LOCAL;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import com.readrops.app.database.entities.Account;
|
||||
import com.readrops.app.database.entities.Feed;
|
||||
import com.readrops.app.database.entities.Folder;
|
||||
import com.readrops.app.database.entities.Item;
|
||||
import com.readrops.app.database.pojo.ItemWithFeed;
|
||||
import com.readrops.app.utils.FeedInsertionResult;
|
||||
import com.readrops.app.utils.FeedMatcher;
|
||||
import com.readrops.app.utils.ItemMatcher;
|
||||
@ -58,7 +59,7 @@ public class FreshRSSRepository extends ARepository {
|
||||
|
||||
@Override
|
||||
public Observable<Feed> sync(List<Feed> feeds, Account account) {
|
||||
FreshRSSAPI api = new FreshRSSAPI(new FreshRSSCredentials(account.getToken(), account.getUrl()));
|
||||
FreshRSSAPI api = new FreshRSSAPI(account.toFreshRSSCredentials());
|
||||
|
||||
FreshRSSSyncData syncData = new FreshRSSSyncData();
|
||||
SyncType syncType;
|
||||
@ -112,6 +113,20 @@ public class FreshRSSRepository extends ARepository {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Completable markItemReadUnread(ItemWithFeed itemWithFeed, Boolean read, Account account) {
|
||||
FreshRSSAPI api = new FreshRSSAPI(account.toFreshRSSCredentials());
|
||||
|
||||
if (account.getWriteToken() == null) {
|
||||
return api.getWriteToken()
|
||||
.flatMapCompletable(writeToken -> api.
|
||||
markItemReadUnread(read, itemWithFeed.getItem().getRemoteId(), writeToken));
|
||||
} else {
|
||||
return api.markItemReadUnread(read, itemWithFeed.getItem().getRemoteId(), account.getWriteToken());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private List<Feed> insertFeeds(List<FreshRSSFeed> freshRSSFeeds, Account account) {
|
||||
List<Feed> feeds = new ArrayList<>();
|
||||
|
||||
|
@ -46,6 +46,7 @@ public final class ItemMatcher {
|
||||
|
||||
newItem.setLink(item.getAlternate().get(0).getHref());
|
||||
newItem.setFeedId(feedId);
|
||||
newItem.setRemoteId(item.getId());
|
||||
|
||||
return newItem;
|
||||
}
|
||||
|
@ -250,19 +250,25 @@ public class MainViewModel extends AndroidViewModel {
|
||||
|
||||
//region Item read state
|
||||
|
||||
public Completable setItemReadState(int itemId, boolean read, boolean readChanged) {
|
||||
return Completable.create(emitter -> {
|
||||
db.itemDao().setReadState(itemId, read ? 1 : 0, readChanged ? 1 : 0);
|
||||
public Completable setItemReadState(ItemWithFeed item, boolean read) {
|
||||
Completable completable = Completable.create(emitter -> {
|
||||
db.itemDao().setReadState(item.getItem().getId(), read ? 1 : 0, !item.getItem().isReadChanged() ? 1 : 0);
|
||||
emitter.onComplete();
|
||||
});
|
||||
|
||||
// TODO : temporary until a better idea comes out
|
||||
if (currentAccount.getAccountType() == Account.AccountType.FRESHRSS) {
|
||||
return completable.andThen(((FreshRSSRepository) repository).
|
||||
markItemReadUnread(item, read, currentAccount));
|
||||
} else
|
||||
return completable;
|
||||
}
|
||||
|
||||
public Completable setItemsReadState(List<ItemWithFeed> items, boolean read) {
|
||||
List<Completable> completableList = new ArrayList<>();
|
||||
|
||||
for (ItemWithFeed itemWithFeed : items) {
|
||||
completableList.add(setItemReadState(itemWithFeed.getItem().getId(), read,
|
||||
!itemWithFeed.getItem().isReadChanged()));
|
||||
completableList.add(setItemReadState(itemWithFeed, read));
|
||||
}
|
||||
|
||||
return Completable.concat(completableList);
|
||||
|
@ -12,6 +12,7 @@ import com.readrops.readropslibrary.services.freshrss.json.FreshRSSUserInfo;
|
||||
import java.io.StringReader;
|
||||
import java.util.Properties;
|
||||
|
||||
import io.reactivex.Completable;
|
||||
import io.reactivex.Single;
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.RequestBody;
|
||||
@ -45,6 +46,11 @@ public class FreshRSSAPI extends API<FreshRSSService> {
|
||||
});
|
||||
}
|
||||
|
||||
public Single<String> getWriteToken() {
|
||||
return api.getWriteToken()
|
||||
.flatMap(responseBody -> Single.just(responseBody.string()));
|
||||
}
|
||||
|
||||
public Single<FreshRSSUserInfo> getUserInfo() {
|
||||
return api.getUserInfo();
|
||||
}
|
||||
@ -90,6 +96,13 @@ public class FreshRSSAPI extends API<FreshRSSService> {
|
||||
return api.getItems(excludeTarget, max, lastModified);
|
||||
}
|
||||
|
||||
public Completable markItemReadUnread(Boolean read, String itemId, String token) {
|
||||
if (read)
|
||||
return api.setItemReadState(token, EXCLUDE_ITEMS.EXCLUDE_READ_ITEMS.value, null, itemId);
|
||||
else
|
||||
return api.setItemReadState(token, null, EXCLUDE_ITEMS.EXCLUDE_READ_ITEMS.value, itemId);
|
||||
}
|
||||
|
||||
public enum EXCLUDE_ITEMS {
|
||||
EXCLUDE_READ_ITEMS("user/-/state/com.google/read");
|
||||
|
||||
|
@ -5,10 +5,13 @@ import com.readrops.readropslibrary.services.freshrss.json.FreshRSSFolders;
|
||||
import com.readrops.readropslibrary.services.freshrss.json.FreshRSSItems;
|
||||
import com.readrops.readropslibrary.services.freshrss.json.FreshRSSUserInfo;
|
||||
|
||||
import io.reactivex.Completable;
|
||||
import io.reactivex.Single;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.Query;
|
||||
@ -20,6 +23,9 @@ public interface FreshRSSService {
|
||||
@POST("accounts/ClientLogin")
|
||||
Single<ResponseBody> login(@Body RequestBody body);
|
||||
|
||||
@GET("reader/api/0/token")
|
||||
Single<ResponseBody> getWriteToken();
|
||||
|
||||
@GET("reader/api/0/user-info")
|
||||
Single<FreshRSSUserInfo> getUserInfo();
|
||||
|
||||
@ -31,4 +37,8 @@ public interface FreshRSSService {
|
||||
|
||||
@GET("reader/api/0/tag/list?output=json")
|
||||
Single<FreshRSSFolders> getFolders();
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("reader/api/0/edit-tag")
|
||||
Completable setItemReadState(@Field("T") String token, @Field("a") String readAction, @Field("r") String unreadAction, @Field("i") String itemId);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user