Migrate java classes from services pacakge to Kotlin except data sources

This commit is contained in:
Shinokuni 2021-07-20 19:30:26 +02:00
parent 25ebc8305d
commit a5501b2524
16 changed files with 204 additions and 352 deletions

View File

@ -1,56 +0,0 @@
package com.readrops.api.services;
import com.readrops.api.services.freshrss.FreshRSSCredentials;
import com.readrops.api.services.freshrss.FreshRSSService;
import com.readrops.api.services.nextcloudnews.NextNewsCredentials;
import com.readrops.api.services.nextcloudnews.NextNewsService;
import com.readrops.db.entities.account.Account;
import com.readrops.db.entities.account.AccountType;
public abstract class Credentials {
private final String authorization;
private String url;
public Credentials(String authorization, String url) {
this.authorization = authorization;
this.url = url;
}
public String getAuthorization() {
return authorization;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public static Credentials toCredentials(Account account) {
String endPoint = getEndPoint(account.getAccountType());
switch (account.getAccountType()) {
case NEXTCLOUD_NEWS:
return new NextNewsCredentials(account.getLogin(), account.getPassword(), account.getUrl() + endPoint);
case FRESHRSS:
return new FreshRSSCredentials(account.getToken(), account.getUrl() + endPoint);
default:
throw new IllegalArgumentException("Unknown account type");
}
}
private static String getEndPoint(AccountType accountType) {
switch (accountType) {
case FRESHRSS:
return FreshRSSService.END_POINT;
case NEXTCLOUD_NEWS:
return NextNewsService.END_POINT;
default:
throw new IllegalArgumentException("Unknown account type");
}
}
}

View File

@ -0,0 +1,32 @@
package com.readrops.api.services
import com.readrops.api.services.freshrss.FreshRSSCredentials
import com.readrops.api.services.freshrss.FreshRSSService
import com.readrops.api.services.nextcloudnews.NextNewsCredentials
import com.readrops.api.services.nextcloudnews.NextNewsService
import com.readrops.db.entities.account.Account
import com.readrops.db.entities.account.AccountType
abstract class Credentials(val authorization: String?, val url: String) {
companion object {
@JvmStatic
fun toCredentials(account: Account): Credentials {
val endPoint = getEndPoint(account.accountType)
return when (account.accountType) {
AccountType.NEXTCLOUD_NEWS -> NextNewsCredentials(account.login, account.password, account.url + endPoint)
AccountType.FRESHRSS -> FreshRSSCredentials(account.token, account.url + endPoint)
else -> throw IllegalArgumentException("Unknown account type")
}
}
private fun getEndPoint(accountType: AccountType): String {
return when (accountType) {
AccountType.FRESHRSS -> FreshRSSService.END_POINT
AccountType.NEXTCLOUD_NEWS -> NextNewsService.END_POINT
else -> throw IllegalArgumentException("Unknown account type")
}
}
}
}

View File

@ -1,6 +0,0 @@
package com.readrops.api.services;
public enum SyncType {
INITIAL_SYNC,
CLASSIC_SYNC
}

View File

@ -0,0 +1,5 @@
package com.readrops.api.services
enum class SyncType {
INITIAL_SYNC, CLASSIC_SYNC
}

View File

@ -1,13 +0,0 @@
package com.readrops.api.services.freshrss;
import com.readrops.api.services.Credentials;
public class FreshRSSCredentials extends Credentials {
private static final String AUTH_PREFIX = "GoogleLogin auth=";
public FreshRSSCredentials(String token, String url) {
super(token != null ? AUTH_PREFIX + token : null, url);
}
}

View File

@ -0,0 +1,11 @@
package com.readrops.api.services.freshrss
import com.readrops.api.services.Credentials
class FreshRSSCredentials(token: String?, url: String) :
Credentials(token?.let { AUTH_PREFIX + it }, url) {
companion object {
private const val AUTH_PREFIX = "GoogleLogin auth="
}
}

View File

@ -1,72 +0,0 @@
package com.readrops.api.services.freshrss;
import com.readrops.api.services.freshrss.adapters.FreshRSSUserInfo;
import com.readrops.db.entities.Feed;
import com.readrops.db.entities.Folder;
import com.readrops.db.entities.Item;
import java.util.List;
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;
public interface FreshRSSService {
String END_POINT = "/api/greader.php/";
@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();
@GET("reader/api/0/subscription/list?output=json")
Single<List<Feed>> getFeeds();
@GET("reader/api/0/stream/contents/user/-/state/com.google/reading-list")
Single<List<Item>> getItems(@Query("xt") List<String> excludeTarget, @Query("n") int max, @Query("ot") Long lastModified);
@GET("reader/api/0/stream/contents/user/-/state/com.google/starred")
Single<List<Item>> getStarredItems(@Query("n") int max);
@GET("reader/api/0/stream/items/ids")
Single<List<String>> getItemsIds(@Query("xt") String excludeTarget, @Query("s") String includeTarget, @Query("n") int max);
@GET("reader/api/0/tag/list?output=json")
Single<List<Folder>> getFolders();
@FormUrlEncoded
@POST("reader/api/0/edit-tag")
Completable setItemsState(@Field("T") String token, @Field("a") String addAction, @Field("r") String removeAction, @Field("i") List<String> itemIds);
@FormUrlEncoded
@POST("reader/api/0/subscription/edit")
Completable createOrDeleteFeed(@Field("T") String token, @Field("s") String feedUrl, @Field("ac") String action);
@FormUrlEncoded
@POST("reader/api/0/subscription/edit")
Completable updateFeed(@Field("T") String token, @Field("s") String feedUrl, @Field("t") String title, @Field("a") String folderId, @Field("ac") String action);
@FormUrlEncoded
@POST("reader/api/0/edit-tag")
Completable createFolder(@Field("T") String token, @Field("a") String tagName);
@FormUrlEncoded
@POST("reader/api/0/rename-tag")
Completable updateFolder(@Field("T") String token, @Field("s") String folderId, @Field("dest") String newFolderId);
@FormUrlEncoded
@POST("reader/api/0/disable-tag")
Completable deleteFolder(@Field("T") String token, @Field("s") String folderId);
}

View File

@ -0,0 +1,70 @@
package com.readrops.api.services.freshrss
import com.readrops.api.services.freshrss.adapters.FreshRSSUserInfo
import com.readrops.db.entities.Feed
import com.readrops.db.entities.Folder
import com.readrops.db.entities.Item
import io.reactivex.Completable
import io.reactivex.Single
import okhttp3.RequestBody
import okhttp3.ResponseBody
import retrofit2.http.*
interface FreshRSSService {
@POST("accounts/ClientLogin")
fun login(@Body body: RequestBody?): Single<ResponseBody?>?
@get:GET("reader/api/0/token")
val writeToken: Single<ResponseBody>
@get:GET("reader/api/0/user-info")
val userInfo: Single<FreshRSSUserInfo>
@get:GET("reader/api/0/subscription/list?output=json")
val feeds: Single<List<Feed>>
@get:GET("reader/api/0/tag/list?output=json")
val folders: Single<List<Folder>>
@GET("reader/api/0/stream/contents/user/-/state/com.google/reading-list")
fun getItems(@Query("xt") excludeTarget: List<String>?, @Query("n") max: Int,
@Query("ot") lastModified: Long?): Single<List<Item>>
@GET("reader/api/0/stream/contents/user/-/state/com.google/starred")
fun getStarredItems(@Query("n") max: Int): Single<List<Item>>
@GET("reader/api/0/stream/items/ids")
fun getItemsIds(@Query("xt") excludeTarget: String?, @Query("s") includeTarget: String?,
@Query("n") max: Int): Single<List<String>>
@FormUrlEncoded
@POST("reader/api/0/edit-tag")
fun setItemsState(@Field("T") token: String, @Field("a") addAction: String?,
@Field("r") removeAction: String?, @Field("i") itemIds: List<String>): Completable
@FormUrlEncoded
@POST("reader/api/0/subscription/edit")
fun createOrDeleteFeed(@Field("T") token: String, @Field("s") feedUrl: String, @Field("ac") action: String): Completable
@FormUrlEncoded
@POST("reader/api/0/subscription/edit")
fun updateFeed(@Field("T") token: String, @Field("s") feedUrl: String, @Field("t") title: String,
@Field("a") folderId: String, @Field("ac") action: String): Completable
@FormUrlEncoded
@POST("reader/api/0/edit-tag")
fun createFolder(@Field("T") token: String, @Field("a") tagName: String): Completable
@FormUrlEncoded
@POST("reader/api/0/rename-tag")
fun updateFolder(@Field("T") token: String, @Field("s") folderId: String, @Field("dest") newFolderId: String): Completable
@FormUrlEncoded
@POST("reader/api/0/disable-tag")
fun deleteFolder(@Field("T") token: String, @Field("s") folderId: String): Completable
companion object {
const val END_POINT = "/api/greader.php/"
}
}

View File

@ -1,62 +0,0 @@
package com.readrops.api.services.freshrss;
import java.util.ArrayList;
import java.util.List;
public class FreshRSSSyncData {
private long lastModified;
private List<String> readItemsIds;
private List<String> unreadItemsIds;
private List<String> starredItemsIds;
private List<String> unstarredItemsIds;
public FreshRSSSyncData() {
readItemsIds = new ArrayList<>();
unreadItemsIds = new ArrayList<>();
}
public long getLastModified() {
return lastModified;
}
public void setLastModified(long lastModified) {
this.lastModified = lastModified;
}
public List<String> getReadItemsIds() {
return readItemsIds;
}
public void setReadItemsIds(List<String> readItemsIds) {
this.readItemsIds = readItemsIds;
}
public List<String> getUnreadItemsIds() {
return unreadItemsIds;
}
public void setUnreadItemsIds(List<String> unreadItemsIds) {
this.unreadItemsIds = unreadItemsIds;
}
public List<String> getStarredItemsIds() {
return starredItemsIds;
}
public void setStarredItemsIds(List<String> starredItemsIds) {
this.starredItemsIds = starredItemsIds;
}
public List<String> getUnstarredItemsIds() {
return unstarredItemsIds;
}
public void setUnstarredItemsIds(List<String> unstarredItemsIds) {
this.unstarredItemsIds = unstarredItemsIds;
}
}

View File

@ -0,0 +1,9 @@
package com.readrops.api.services.freshrss
data class FreshRSSSyncData(
var lastModified: Long = 0,
var readItemsIds: List<String> = listOf(),
var unreadItemsIds: List<String> = listOf(),
var starredItemsIds: List<String> = listOf(),
var unstarredItemsIds: List<String> = listOf(),
)

View File

@ -1,10 +0,0 @@
package com.readrops.api.services.nextcloudnews;
import com.readrops.api.services.Credentials;
public class NextNewsCredentials extends Credentials {
public NextNewsCredentials(String login, String password, String url) {
super(login != null && password != null ? okhttp3.Credentials.basic(login, password) : null, url);
}
}

View File

@ -0,0 +1,8 @@
package com.readrops.api.services.nextcloudnews
import com.readrops.api.services.Credentials
class NextNewsCredentials(login: String?, password: String?, url: String):
Credentials((login != null && password != null).let {
okhttp3.Credentials.basic(login!!, password!!)
}, url)

View File

@ -1,67 +0,0 @@
package com.readrops.api.services.nextcloudnews;
import com.readrops.db.entities.Feed;
import com.readrops.db.entities.Folder;
import com.readrops.db.entities.Item;
import java.util.List;
import java.util.Map;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Path;
import retrofit2.http.Query;
public interface NextNewsService {
String END_POINT = "/index.php/apps/news/api/v1-2/";
@GET("/ocs/v1.php/cloud/users/{userId}")
@Headers("OCS-APIRequest: true")
Call<ResponseBody> getUser(@Path("userId") String userId);
@GET("folders")
Call<List<Folder>> getFolders();
@GET("feeds")
Call<List<Feed>> getFeeds();
@GET("items")
Call<List<Item>> getItems(@Query("type") int type, @Query("getRead") boolean read, @Query("batchSize") int batchSize);
@GET("items/updated")
Call<List<Item>> getNewItems(@Query("lastModified") long lastModified, @Query("type") int type);
@PUT("items/{stateType}/multiple")
Call<ResponseBody> setReadState(@Path("stateType") String stateType, @Body Map<String, List<String>> itemIdsMap);
@PUT("items/{starType}/multiple")
Call<ResponseBody> setStarState(@Path("starType") String starType, @Body Map<String, List<Map<String, String>>> body);
@POST("feeds")
Call<List<Feed>> createFeed(@Query("url") String url, @Query("folderId") int folderId);
@DELETE("feeds/{feedId}")
Call<Void> deleteFeed(@Path("feedId") int feedId);
@PUT("feeds/{feedId}/move")
Call<ResponseBody> changeFeedFolder(@Path("feedId") int feedId, @Body Map<String, Integer> folderIdMap);
@PUT("feeds/{feedId}/rename")
Call<ResponseBody> renameFeed(@Path("feedId") int feedId, @Body Map<String, String> feedTitleMap);
@POST("folders")
Call<List<Folder>> createFolder(@Body Map<String, String> folderName);
@DELETE("folders/{folderId}")
Call<ResponseBody> deleteFolder(@Path("folderId") int folderId);
@PUT("folders/{folderId}")
Call<ResponseBody> renameFolder(@Path("folderId") int folderId, @Body Map<String, String> folderName);
}

View File

@ -0,0 +1,58 @@
package com.readrops.api.services.nextcloudnews
import com.readrops.db.entities.Feed
import com.readrops.db.entities.Folder
import com.readrops.db.entities.Item
import okhttp3.ResponseBody
import retrofit2.Call
import retrofit2.http.*
interface NextNewsService {
@GET("/ocs/v1.php/cloud/users/{userId}")
@Headers("OCS-APIRequest: true")
fun getUser(@Path("userId") userId: String): Call<ResponseBody>
@get:GET("folders")
val folders: Call<List<Folder>>
@get:GET("feeds")
val feeds: Call<List<Feed>>
@GET("items")
fun getItems(@Query("type") type: Int, @Query("getRead") read: Boolean, @Query("batchSize") batchSize: Int): Call<List<Item>>
@GET("items/updated")
fun getNewItems(@Query("lastModified") lastModified: Long, @Query("type") type: Int): Call<List<Item>>
@PUT("items/{stateType}/multiple")
fun setReadState(@Path("stateType") stateType: String, @Body itemIdsMap: Map<String, List<String>>): Call<ResponseBody>
@PUT("items/{starType}/multiple")
fun setStarState(@Path("starType") starType: String?, @Body body: Map<String?, List<Map<String, String>>>): Call<ResponseBody>
@POST("feeds")
fun createFeed(@Query("url") url: String, @Query("folderId") folderId: Int): Call<List<Feed>>
@DELETE("feeds/{feedId}")
fun deleteFeed(@Path("feedId") feedId: Int): Call<Void?>?
@PUT("feeds/{feedId}/move")
fun changeFeedFolder(@Path("feedId") feedId: Int, @Body folderIdMap: Map<String, Int>): Call<ResponseBody>
@PUT("feeds/{feedId}/rename")
fun renameFeed(@Path("feedId") feedId: Int, @Body feedTitleMap: Map<String, String>): Call<ResponseBody>
@POST("folders")
fun createFolder(@Body folderName: Map<String, String>): Call<List<Folder>>
@DELETE("folders/{folderId}")
fun deleteFolder(@Path("folderId") folderId: Int): Call<ResponseBody>
@PUT("folders/{folderId}")
fun renameFolder(@Path("folderId") folderId: Int, @Body folderName: Map<String, String>): Call<ResponseBody>
companion object {
const val END_POINT = "/index.php/apps/news/api/v1-2/"
}
}

View File

@ -1,66 +0,0 @@
package com.readrops.api.services.nextcloudnews;
import com.readrops.db.pojo.StarItem;
import java.util.ArrayList;
import java.util.List;
public class NextNewsSyncData {
private List<String> unreadItems;
private List<String> readItems;
private List<StarItem> starredItems;
private List<StarItem> unstarredItems;
private long lastModified;
public NextNewsSyncData() {
unreadItems = new ArrayList<>();
readItems = new ArrayList<>();
starredItems = new ArrayList<>();
unstarredItems = new ArrayList<>();
}
public List<String> getUnreadItems() {
return unreadItems;
}
public void setUnreadItems(List<String> unreadItems) {
this.unreadItems = unreadItems;
}
public List<String> getReadItems() {
return readItems;
}
public void setReadItems(List<String> readItems) {
this.readItems = readItems;
}
public List<StarItem> getStarredItems() {
return starredItems;
}
public void setStarredItems(List<StarItem> starredItems) {
this.starredItems = starredItems;
}
public List<StarItem> getUnstarredItems() {
return unstarredItems;
}
public void setUnstarredItems(List<StarItem> unstarredItems) {
this.unstarredItems = unstarredItems;
}
public long getLastModified() {
return lastModified;
}
public void setLastModified(long lastModified) {
this.lastModified = lastModified;
}
}

View File

@ -0,0 +1,11 @@
package com.readrops.api.services.nextcloudnews
import com.readrops.db.pojo.StarItem
data class NextNewsSyncData(
var lastModified: Long = 0,
var unreadItems: List<String> = listOf(),
var readItems: List<String> = listOf(),
var starredItems: List<StarItem> = listOf(),
var unstarredItems: List<StarItem> = listOf(),
)