Merge branch 'master' into androidx

# Conflicts:
#	News-Android-App/build.gradle
This commit is contained in:
David Luhmer 2019-04-04 16:16:07 -03:00
commit 0914892f76
6 changed files with 6 additions and 244 deletions

View file

@ -163,7 +163,7 @@ dependencies {
implementation 'com.squareup.retrofit2:retrofit:2.5.0' implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0' implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.okhttp3:okhttp:3.14.0' implementation 'com.squareup.okhttp3:okhttp:3.12.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0' implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0'
implementation 'com.nbsp:library:1.02' // MaterialFilePicker implementation 'com.nbsp:library:1.02' // MaterialFilePicker

View file

@ -35,6 +35,7 @@ import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.Subscribe;
import java.io.File; import java.io.File;
import java.lang.reflect.Proxy;
import javax.inject.Inject; import javax.inject.Inject;
@ -56,7 +57,6 @@ import de.luhmer.owncloudnewsreader.interfaces.IPlayPausePodcastClicked;
import de.luhmer.owncloudnewsreader.model.MediaItem; import de.luhmer.owncloudnewsreader.model.MediaItem;
import de.luhmer.owncloudnewsreader.model.PodcastItem; import de.luhmer.owncloudnewsreader.model.PodcastItem;
import de.luhmer.owncloudnewsreader.notification.NextcloudNotificationManager; import de.luhmer.owncloudnewsreader.notification.NextcloudNotificationManager;
import de.luhmer.owncloudnewsreader.reader.nextcloud.API_SSO;
import de.luhmer.owncloudnewsreader.services.PodcastDownloadService; import de.luhmer.owncloudnewsreader.services.PodcastDownloadService;
import de.luhmer.owncloudnewsreader.services.PodcastPlaybackService; import de.luhmer.owncloudnewsreader.services.PodcastPlaybackService;
import de.luhmer.owncloudnewsreader.services.podcast.PlaybackService; import de.luhmer.owncloudnewsreader.services.podcast.PlaybackService;
@ -110,21 +110,10 @@ public class PodcastFragmentActivity extends AppCompatActivity implements IPlayP
((NewsReaderApplication) getApplication()).getAppComponent().injectActivity(this); ((NewsReaderApplication) getApplication()).getAppComponent().injectActivity(this);
if (mApi.getAPI() instanceof API_SSO) { if (mApi.getAPI() instanceof Proxy) { // Single Sign On
VersionCheckHelper.verifyMinVersion(this, MIN_NEXTCLOUD_FILES_APP_VERSION_CODE); VersionCheckHelper.verifyMinVersion(this, MIN_NEXTCLOUD_FILES_APP_VERSION_CODE);
} }
//Delete all pinned/stored SSL Certificates
/*
final ArrayList<String> aliases = Collections.list(mMTM.getCertificates());
for(int i = 0; i < aliases.size(); i++) {
try {
mMTM.deleteCertificate(aliases.get(i));
} catch (KeyStoreException e) {
e.printStackTrace();
}
}*/
//mPostDelayHandler.delayTimer();
mPostDelayHandler.stopRunningPostDelayHandler(); mPostDelayHandler.stopRunningPostDelayHandler();
} }

View file

@ -19,11 +19,11 @@ import de.luhmer.owncloudnewsreader.SettingsActivity;
import de.luhmer.owncloudnewsreader.helper.GsonConfig; import de.luhmer.owncloudnewsreader.helper.GsonConfig;
import de.luhmer.owncloudnewsreader.reader.OkHttpImageDownloader; import de.luhmer.owncloudnewsreader.reader.OkHttpImageDownloader;
import de.luhmer.owncloudnewsreader.reader.nextcloud.API; import de.luhmer.owncloudnewsreader.reader.nextcloud.API;
import de.luhmer.owncloudnewsreader.reader.nextcloud.API_SSO;
import de.luhmer.owncloudnewsreader.ssl.MemorizingTrustManager; import de.luhmer.owncloudnewsreader.ssl.MemorizingTrustManager;
import de.luhmer.owncloudnewsreader.ssl.OkHttpSSLClient; import de.luhmer.owncloudnewsreader.ssl.OkHttpSSLClient;
import okhttp3.HttpUrl; import okhttp3.HttpUrl;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import retrofit2.NextcloudRetrofitApiBuilder;
import retrofit2.Retrofit; import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.converter.gson.GsonConverterFactory;
@ -94,7 +94,7 @@ public class ApiProvider {
try { try {
SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(context); SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(context);
NextcloudAPI nextcloudAPI = new NextcloudAPI(context, ssoAccount, GsonConfig.GetGson(), callback); NextcloudAPI nextcloudAPI = new NextcloudAPI(context, ssoAccount, GsonConfig.GetGson(), callback);
mApi = new API_SSO(nextcloudAPI); mApi = new NextcloudRetrofitApiBuilder(nextcloudAPI, API.mApiEndpoint).create(API.class);
} catch (SSOException e) { } catch (SSOException e) {
callback.onError(e); callback.onError(e);
} }

View file

@ -31,6 +31,7 @@ import retrofit2.http.Streaming;
public interface API { public interface API {
String mApiEndpoint = "/index.php/apps/news/api/v1-2/";
/** Since 6.0.5 **/ /** Since 6.0.5 **/
@GET("user") @GET("user")

View file

@ -1,228 +0,0 @@
package de.luhmer.owncloudnewsreader.reader.nextcloud;
import com.google.gson.reflect.TypeToken;
import com.nextcloud.android.sso.aidl.NextcloudRequest;
import com.nextcloud.android.sso.api.NextcloudAPI;
import com.nextcloud.android.sso.helper.Okhttp3Helper;
import com.nextcloud.android.sso.helper.ReactivexHelper;
import com.nextcloud.android.sso.helper.Retrofit2Helper;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import de.luhmer.owncloudnewsreader.database.model.Feed;
import de.luhmer.owncloudnewsreader.database.model.Folder;
import de.luhmer.owncloudnewsreader.database.model.RssItem;
import de.luhmer.owncloudnewsreader.helper.GsonConfig;
import de.luhmer.owncloudnewsreader.model.NextcloudNewsVersion;
import de.luhmer.owncloudnewsreader.model.NextcloudStatus;
import de.luhmer.owncloudnewsreader.model.UserInfo;
import io.reactivex.Completable;
import io.reactivex.Observable;
import okhttp3.ResponseBody;
import retrofit2.Call;
public class API_SSO implements API {
private static final String mApiEndpoint = "/index.php/apps/news/api/v1-2/";
private NextcloudAPI nextcloudAPI;
public API_SSO(NextcloudAPI nextcloudAPI) {
this.nextcloudAPI = nextcloudAPI;
}
public NextcloudAPI getNextcloudAPI() {
return nextcloudAPI;
}
@Override
public Observable<UserInfo> user() {
final Type type = UserInfo.class;
NextcloudRequest request = new NextcloudRequest.Builder()
.setMethod("GET")
.setUrl(mApiEndpoint + "user")
.build();
return nextcloudAPI.performRequestObservable(type, request);
}
@Override
public Observable<NextcloudStatus> status() {
Type type = NextcloudStatus.class;
NextcloudRequest request = new NextcloudRequest.Builder()
.setMethod("GET")
.setUrl(mApiEndpoint + "status")
.build();
return nextcloudAPI.performRequestObservable(type, request);
}
@Override
public Observable<NextcloudNewsVersion> version() {
Type type = NextcloudNewsVersion.class;
NextcloudRequest request = new NextcloudRequest.Builder()
.setMethod("GET")
.setUrl(mApiEndpoint + "version")
.build();
return nextcloudAPI.performRequestObservable(type, request);
}
@Override
public Observable<List<Folder>> folders() {
Type type = new TypeToken<List<Folder>>() {}.getType();
NextcloudRequest request = new NextcloudRequest.Builder()
.setMethod("GET")
.setUrl(mApiEndpoint + "folders")
.build();
return nextcloudAPI.performRequestObservable(type, request);
}
@Override
public Observable<List<Feed>> feeds() {
Type type = new TypeToken<List<Feed>>() {}.getType();
NextcloudRequest request = new NextcloudRequest.Builder()
.setMethod("GET")
.setUrl(mApiEndpoint + "feeds")
.build();
return nextcloudAPI.performRequestObservable(type, request);
}
@Override
public Call<List<Folder>> createFolder(Map<String, Object> folderMap) {
String body = GsonConfig.GetGson().toJson(folderMap);
NextcloudRequest request = new NextcloudRequest.Builder()
.setMethod("POST")
.setUrl(mApiEndpoint + "folders")
.setRequestBody(body)
.build();
return Retrofit2Helper.WrapInCall(nextcloudAPI, request, Folder.class);
}
@Override
public Call<List<Feed>> createFeed(Map<String, Object> feedMap) {
Type feedListType = new TypeToken<List<Feed>>() {}.getType();
String body = GsonConfig.GetGson().toJson(feedMap);
NextcloudRequest request = new NextcloudRequest.Builder()
.setMethod("POST")
.setUrl(mApiEndpoint + "feeds")
.setRequestBody(body)
.build();
return Retrofit2Helper.WrapInCall(nextcloudAPI, request, feedListType);
}
@Override
public Completable renameFeed(long feedId, Map<String, String> feedTitleMap) {
String body = GsonConfig.GetGson().toJson(feedTitleMap);
final NextcloudRequest request = new NextcloudRequest.Builder()
.setMethod("PUT")
.setUrl(mApiEndpoint + "feeds/" + feedId + "/rename")
.setRequestBody(body)
.build();
return ReactivexHelper.wrapInCompletable(nextcloudAPI, request);
}
@Override
public Completable moveFeed(long feedId, Map<String, Long> folderIdMap) {
String body = GsonConfig.GetGson().toJson(folderIdMap);
final NextcloudRequest request = new NextcloudRequest.Builder()
.setMethod("PUT")
.setUrl(mApiEndpoint + "feeds/" + feedId + "/move")
.setRequestBody(body)
.build();
return ReactivexHelper.wrapInCompletable(nextcloudAPI, request);
}
@Override
public Completable deleteFeed(long feedId) {
final NextcloudRequest request = new NextcloudRequest.Builder()
.setMethod("DELETE")
.setUrl(mApiEndpoint + "feeds/" + feedId)
.build();
return ReactivexHelper.wrapInCompletable(nextcloudAPI, request);
}
@Override
public Call<List<RssItem>> items(long batchSize, long offset, int type, long id, boolean getRead, boolean oldestFirst) {
HashMap<String, String> parameters = new HashMap<>();
parameters.put("batchSize", String.valueOf(batchSize));
parameters.put("offset", String.valueOf(offset));
parameters.put("type", String.valueOf(type));
parameters.put("id", String.valueOf(id));
parameters.put("getRead", String.valueOf(getRead));
parameters.put("oldestFirst", String.valueOf(oldestFirst));
Type resType = new TypeToken<List<RssItem>>() {}.getType();
NextcloudRequest request = new NextcloudRequest.Builder()
.setParameter(parameters)
.setMethod("GET")
.setUrl(mApiEndpoint + "items")
.build();
return Retrofit2Helper.WrapInCall(nextcloudAPI, request, resType);
}
@Override
public Observable<ResponseBody> updatedItems(long lastModified, int type, long id) {
HashMap<String, String> parameters = new HashMap<>();
parameters.put("lastModified", String.valueOf(lastModified));
parameters.put("type", String.valueOf(type));
parameters.put("id", String.valueOf(id));
final NextcloudRequest request = new NextcloudRequest.Builder()
.setMethod("GET")
.setUrl(mApiEndpoint + "items/updated")
.setParameter(parameters)
.build();
return Observable.just(Okhttp3Helper.getResponseBodyFromRequest(nextcloudAPI, request));
}
// https://github.com/owncloud/news/wiki/Items-1.2#mark-multiple-items-as-read
@Override
public Call<Void> markItemsRead(ItemIds items) {
String body = GsonConfig.GetGson().toJson(items);
return markItems("items/read/multiple", body);
}
// https://github.com/owncloud/news/wiki/Items-1.2#mark-multiple-items-as-read
@Override
public Call<Void> markItemsUnread(ItemIds items) {
String body = GsonConfig.GetGson().toJson(items);
return markItems("items/unread/multiple", body);
}
// https://github.com/owncloud/news/wiki/Items-1.2#mark-multiple-items-as-read
@Override
public Call<Void> markItemsStarred(ItemMap itemMap) {
String body = GsonConfig.GetGson().toJson(itemMap);
return markItems("items/star/multiple", body);
}
// https://github.com/owncloud/news/wiki/Items-1.2#mark-multiple-items-as-read
@Override
public Call<Void> markItemsUnstarred(ItemMap itemMap) {
String body = GsonConfig.GetGson().toJson(itemMap);
return markItems("items/unstar/multiple", body);
}
private Call<Void> markItems(String endpoint, String body) {
NextcloudRequest request = new NextcloudRequest.Builder()
.setMethod("PUT")
.setUrl(mApiEndpoint + endpoint)
.setRequestBody(body)
.build();
try {
nextcloudAPI.performRequest(Void.class, request);
return Retrofit2Helper.wrapVoidCall(true);
} catch (Exception e) {
e.printStackTrace();
}
return Retrofit2Helper.wrapVoidCall(false);
}
}