Fix FreshRSS and Nextcloud News authentications

This commit is contained in:
Shinokuni 2020-10-16 12:36:24 +02:00
parent 950c8506ad
commit 725cb291ef
5 changed files with 22 additions and 20 deletions

View File

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

View File

@ -59,26 +59,20 @@ public class AddAccountActivity extends AppCompatActivity {
if (forwardResult || accountToEdit != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
try {
if (accountToEdit != null) {
viewModel.setAccountType(accountToEdit.getAccountType());
editAccount = true;
fillFields();
} else {
viewModel.setAccountType(accountType);
if (accountToEdit != null) {
viewModel.setAccountType(accountToEdit.getAccountType());
editAccount = true;
fillFields();
} else {
viewModel.setAccountType(accountType);
binding.providerImage.setImageResource(accountType.getIconRes());
binding.providerName.setText(accountType.getName());
binding.addAccountName.setText(accountType.getName());
if (accountType == AccountType.FRESHRSS) {
binding.addAccountPasswordLayout.setHelperText(getString(R.string.password_helper));
}
binding.providerImage.setImageResource(accountType.getIconRes());
binding.providerName.setText(accountType.getName());
binding.addAccountName.setText(accountType.getName());
if (accountType == AccountType.FRESHRSS) {
binding.addAccountPasswordLayout.setHelperText(getString(R.string.password_helper));
}
} catch (Exception e) {
// TODO : see how to handle this exception
e.printStackTrace();
}
}
public void createAccount(View view) {

View File

@ -47,6 +47,10 @@ public abstract class ARepository {
this.database = database;
this.account = account;
setCredentials(account);
}
protected void setCredentials(@Nullable Account account) {
KoinJavaComponent.get(AuthInterceptor.class)
.setCredentials(account != null && !account.isLocal() ? Credentials.toCredentials(account) : null);
}

View File

@ -33,7 +33,7 @@ public class FreshRSSRepository extends ARepository {
private static final String TAG = FreshRSSRepository.class.getSimpleName();
private FreshRSSDataSource dataSource;
private final FreshRSSDataSource dataSource;
public FreshRSSRepository(FreshRSSDataSource dataSource, Database database, @NonNull Context context, @Nullable Account account) {
super(database, context, account);
@ -43,9 +43,12 @@ public class FreshRSSRepository extends ARepository {
@Override
public Single<Boolean> login(Account account, boolean insert) {
setCredentials(account);
return dataSource.login(account.getLogin(), account.getPassword())
.flatMap(token -> {
account.setToken(token);
setCredentials(account);
return dataSource.getWriteToken();
})

View File

@ -37,7 +37,7 @@ public class NextNewsRepository extends ARepository {
private static final String TAG = NextNewsRepository.class.getSimpleName();
private NextNewsDataSource dataSource;
private final NextNewsDataSource dataSource;
public NextNewsRepository(NextNewsDataSource dataSource, Database database, @NonNull Context context, @Nullable Account account) {
super(database, context, account);
@ -47,6 +47,7 @@ public class NextNewsRepository extends ARepository {
@Override
public Single<Boolean> login(Account account, boolean insert) {
setCredentials(account);
return Single.<NextNewsUser>create(emitter -> {
NextNewsUser user = dataSource.login();