Add for each account type a config to better manage what they can/can't do

This commit is contained in:
Shinokuni 2019-08-21 21:53:18 +02:00
parent c26e7cff47
commit c271d0b584
4 changed files with 73 additions and 12 deletions

View File

@ -80,7 +80,9 @@ public class ManageFeedsFoldersActivity extends AppCompatActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.feeds_menu, menu);
if (account.getAccountType().getAccountConfig().isFolderCreation())
getMenuInflater().inflate(R.menu.feeds_menu, menu);
return super.onCreateOptionsMenu(menu);
}

View File

@ -0,0 +1,55 @@
package com.readrops.app.database;
public class AccountConfig {
public static final AccountConfig LOCAL = new AccountConfigBuilder()
.setFeedUrlEditable(true)
.setFolderCreation(true)
.build();
public static final AccountConfig NEXTNEWS = new AccountConfigBuilder()
.setFeedUrlEditable(false)
.setFolderCreation(true)
.build();
public static final AccountConfig FRESHRSS = new AccountConfigBuilder()
.setFeedUrlEditable(false)
.setFolderCreation(false)
.build();
private boolean feedUrlEditable;
public boolean isFeedUrlEditable() {
return feedUrlEditable;
}
public boolean isFolderCreation() {
return folderCreation;
}
private boolean folderCreation;
public AccountConfig(boolean feedUrlEditable, boolean folderCreation) {
this.feedUrlEditable = feedUrlEditable;
this.folderCreation = folderCreation;
}
public static class AccountConfigBuilder {
private boolean feedUrlEditable;
private boolean folderCreation;
public AccountConfigBuilder setFeedUrlEditable(boolean feedUrlEditable) {
this.feedUrlEditable = feedUrlEditable;
return this;
}
public AccountConfigBuilder setFolderCreation(boolean folderCreation) {
this.folderCreation = folderCreation;
return this;
}
public AccountConfig build() {
return new AccountConfig(feedUrlEditable, folderCreation);
}
}
}

View File

@ -12,6 +12,7 @@ import androidx.room.Ignore;
import androidx.room.PrimaryKey;
import com.readrops.app.R;
import com.readrops.app.database.AccountConfig;
import com.readrops.readropslibrary.services.Credentials;
import com.readrops.readropslibrary.services.freshrss.FreshRSSCredentials;
import com.readrops.readropslibrary.services.nextcloudnews.NextNewsCredentials;
@ -201,15 +202,14 @@ public class Account implements Parcelable {
}
public enum AccountType implements Parcelable {
LOCAL(R.drawable.ic_readrops, R.string.local_account),
NEXTCLOUD_NEWS(R.drawable.ic_nextcloud_news, R.string.nextcloud_news),
FEEDLY(R.drawable.ic_feedly, R.string.feedly),
FRESHRSS(R.drawable.ic_freshrss, R.string.freshrss);
LOCAL(R.drawable.ic_readrops, R.string.local_account, AccountConfig.LOCAL),
NEXTCLOUD_NEWS(R.drawable.ic_nextcloud_news, R.string.nextcloud_news, AccountConfig.NEXTNEWS),
FEEDLY(R.drawable.ic_feedly, R.string.feedly, null),
FRESHRSS(R.drawable.ic_freshrss, R.string.freshrss, AccountConfig.FRESHRSS);
private @DrawableRes
int iconRes;
private @StringRes
int name;
private @DrawableRes int iconRes;
private @StringRes int name;
private AccountConfig accountConfig;
@Override
public void writeToParcel(Parcel dest, int flags) {
@ -243,9 +243,14 @@ public class Account implements Parcelable {
return name;
}
AccountType(@DrawableRes int iconRes, @StringRes int name) {
public AccountConfig getAccountConfig() {
return accountConfig;
}
AccountType(@DrawableRes int iconRes, @StringRes int name, AccountConfig accountConfig) {
this.iconRes = iconRes;
this.name = name;
this.accountConfig = accountConfig;
}
}

View File

@ -98,8 +98,7 @@ public class EditFeedDialog extends DialogFragment implements AdapterView.OnItem
feedUrl = v.findViewById(R.id.edit_feed_url_edit_text);
folder = v.findViewById(R.id.edit_feed_folder_spinner);
//TODO : this is temporary and should be changed when other service APIs are implemented
if (account.is(Account.AccountType.NEXTCLOUD_NEWS))
if (!account.getAccountType().getAccountConfig().isFeedUrlEditable())
feedUrl.setEnabled(false);
feedName.setText(feedWithFolder.getFeed().getName());