Add an abstraction level for credentials to support multiple authorization field values

This commit is contained in:
Shinokuni 2019-08-09 19:58:11 +02:00
parent 5df094ca30
commit 2b08ae9c96
5 changed files with 35 additions and 30 deletions

View File

@ -12,7 +12,7 @@ import androidx.room.Ignore;
import androidx.room.PrimaryKey;
import com.readrops.app.R;
import com.readrops.readropslibrary.services.nextcloudnews.Credentials;
import com.readrops.readropslibrary.services.nextcloudnews.NextNewsCredentials;
@Entity
public class Account implements Parcelable {
@ -224,8 +224,8 @@ public class Account implements Parcelable {
}
}
public Credentials toCredentials() {
return new Credentials(login, password, url);
public NextNewsCredentials toNextNewsCredentials() {
return new NextNewsCredentials(login, password, url);
}
public boolean isLocal() {

View File

@ -0,0 +1,21 @@
package com.readrops.readropslibrary.services;
public abstract class Credentials {
private 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;
}
}

View File

@ -1,25 +0,0 @@
package com.readrops.readropslibrary.services.nextcloudnews;
public class Credentials {
private String base64;
private String url;
public Credentials(String login, String password, String url) {
this.base64 = okhttp3.Credentials.basic(login, password);
this.url = url;
}
public String getBase64() {
return base64;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}

View File

@ -6,7 +6,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.readrops.readropslibrary.services.API;
import com.readrops.readropslibrary.services.Credentials;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFeed;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFeeds;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolder;
@ -29,7 +28,7 @@ public class NextNewsAPI extends API<NextNewsService> {
private static final String TAG = NextNewsAPI.class.getSimpleName();
public NextNewsAPI(Credentials credentials) {
public NextNewsAPI(NextNewsCredentials credentials) {
super(credentials, NextNewsService.class, NextNewsService.END_POINT);
}

View File

@ -0,0 +1,10 @@
package com.readrops.readropslibrary.services.nextcloudnews;
import com.readrops.readropslibrary.services.Credentials;
public class NextNewsCredentials extends Credentials {
public NextNewsCredentials(String login, String password, String url) {
super(okhttp3.Credentials.basic(login, password), url);
}
}