mirror of
https://github.com/readrops/Readrops.git
synced 2025-02-02 03:36:52 +01:00
Migrate AccountConfig and AccountType to kotlin
This commit is contained in:
parent
1654d32211
commit
80404bb648
@ -79,7 +79,7 @@ public class AccountTypeListActivity extends AppCompatActivity {
|
||||
startActivity(intent);
|
||||
finish();
|
||||
} else {
|
||||
Account account = new Account(null, getString(AccountType.LOCAL.getName()), AccountType.LOCAL);
|
||||
Account account = new Account(null, getString(AccountType.LOCAL.getTypeName()), AccountType.LOCAL);
|
||||
account.setCurrentAccount(true);
|
||||
|
||||
viewModel.insert(account)
|
||||
@ -150,7 +150,7 @@ public class AccountTypeListActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void parseOPMLFile(Uri uri, MaterialDialog dialog) {
|
||||
Account account = new Account(null, getString(AccountType.LOCAL.getName()), AccountType.LOCAL);
|
||||
Account account = new Account(null, getString(AccountType.LOCAL.getTypeName()), AccountType.LOCAL);
|
||||
account.setCurrentAccount(true);
|
||||
|
||||
viewModel.insert(account)
|
||||
|
@ -33,7 +33,7 @@ public class AccountTypeListAdapter extends RecyclerView.Adapter<AccountTypeList
|
||||
public void onBindViewHolder(@NonNull AccountTypeViewHolder holder, int position) {
|
||||
AccountType accountType = accountTypes.get(position);
|
||||
|
||||
holder.binding.accountTypeName.setText(accountType.getName());
|
||||
holder.binding.accountTypeName.setText(accountType.getTypeName());
|
||||
holder.binding.accountTypeLogo.setImageResource(accountType.getIconRes());
|
||||
|
||||
holder.binding.getRoot().setOnClickListener(v -> listener.onItemClick(accountType));
|
||||
|
@ -65,8 +65,8 @@ public class AddAccountActivity extends AppCompatActivity {
|
||||
fillFields();
|
||||
} else {
|
||||
binding.providerImage.setImageResource(accountType.getIconRes());
|
||||
binding.providerName.setText(accountType.getName());
|
||||
binding.addAccountName.setText(accountType.getName());
|
||||
binding.providerName.setText(accountType.getTypeName());
|
||||
binding.addAccountName.setText(accountType.getTypeName());
|
||||
|
||||
if (accountType == AccountType.FRESHRSS) {
|
||||
binding.addAccountPasswordLayout.setHelperText(getString(R.string.password_helper));
|
||||
@ -178,7 +178,7 @@ public class AddAccountActivity extends AppCompatActivity {
|
||||
|
||||
private void fillFields() {
|
||||
binding.providerImage.setImageResource(accountToEdit.getAccountType().getIconRes());
|
||||
binding.providerName.setText(accountToEdit.getAccountType().getName());
|
||||
binding.providerName.setText(accountToEdit.getAccountType().getTypeName());
|
||||
|
||||
binding.addAccountUrl.setText(accountToEdit.getUrl());
|
||||
binding.addAccountName.setText(accountToEdit.getAccountName());
|
||||
|
@ -44,7 +44,7 @@ public class AccountArrayAdapter extends ArrayAdapter<Account> {
|
||||
TextView accountName = convertView.findViewById(R.id.account_type_name);
|
||||
|
||||
accountIcon.setImageResource(account.getAccountType().getIconRes());
|
||||
accountName.setText(account.getAccountType().getName());
|
||||
accountName.setText(account.getAccountType().getTypeName());
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public class ItemViewModel extends ViewModel {
|
||||
|
||||
public LiveData<ItemWithFeed> getItemById(int id) {
|
||||
return database.itemDao().getItemById(ItemSelectionQueryBuilder.buildQuery(id,
|
||||
account.getConfig().useSeparateState()));
|
||||
account.getConfig().getUseSeparateState()));
|
||||
}
|
||||
|
||||
public Completable setStarState(Item item) {
|
||||
|
@ -70,7 +70,7 @@ public class MainViewModel extends ViewModel {
|
||||
}
|
||||
|
||||
DataSource.Factory<Integer, ItemWithFeed> items;
|
||||
items = database.itemDao().selectAll(ItemsQueryBuilder.buildItemsQuery(queryFilters, currentAccount.getConfig().useSeparateState()));
|
||||
items = database.itemDao().selectAll(ItemsQueryBuilder.buildItemsQuery(queryFilters, currentAccount.getConfig().getUseSeparateState()));
|
||||
|
||||
lastFetch = new LivePagedListBuilder<>(new RoomFactoryWrapper<>(items),
|
||||
new PagedList.Config.Builder()
|
||||
|
@ -115,7 +115,7 @@ public abstract class ARepository {
|
||||
}
|
||||
|
||||
public Completable setItemReadState(Item item) {
|
||||
if (account.getConfig().useSeparateState()) {
|
||||
if (account.getConfig().getUseSeparateState()) {
|
||||
return database.itemStateChangesDao().upsertItemReadStateChange(item, account.getId(), true)
|
||||
.andThen(database.itemStateDao().upsertItemReadState(new ItemState(0, item.isRead(),
|
||||
item.isStarred(), item.getRemoteId(), account.getId())));
|
||||
@ -145,7 +145,7 @@ public abstract class ARepository {
|
||||
}
|
||||
|
||||
public Completable setItemStarState(Item item) {
|
||||
if (account.getConfig().useSeparateState()) {
|
||||
if (account.getConfig().getUseSeparateState()) {
|
||||
return database.itemStateChangesDao().upsertItemStarStateChange(item, account.getId(), true)
|
||||
.andThen(database.itemStateDao().upsertItemStarState(new ItemState(0, item.isRead(),
|
||||
item.isStarred(), item.getRemoteId(), account.getId())));
|
||||
|
@ -28,7 +28,7 @@ data class Account(
|
||||
this(url = accountUrl, accountName = accountName, accountType = accountType)
|
||||
|
||||
val config: AccountConfig
|
||||
get() = accountType!!.accountConfig
|
||||
get() = accountType!!.accountConfig!!
|
||||
|
||||
val isLocal
|
||||
get() = accountType == AccountType.LOCAL
|
||||
|
@ -1,90 +0,0 @@
|
||||
package com.readrops.db.entities.account;
|
||||
|
||||
public class AccountConfig {
|
||||
|
||||
public static final AccountConfig LOCAL = new AccountConfigBuilder()
|
||||
.setFeedUrlEditable(true)
|
||||
.setFolderCreation(true)
|
||||
.setNoFolderCase(false)
|
||||
.setUseSeparateState(false)
|
||||
.build();
|
||||
|
||||
public static final AccountConfig NEXTCLOUD_NEWS = new AccountConfigBuilder()
|
||||
.setFeedUrlEditable(false)
|
||||
.setFolderCreation(true)
|
||||
.setNoFolderCase(false)
|
||||
.setUseSeparateState(false)
|
||||
.build();
|
||||
|
||||
public static final AccountConfig FRESHRSS = new AccountConfigBuilder()
|
||||
.setFeedUrlEditable(false)
|
||||
.setFolderCreation(false)
|
||||
.setNoFolderCase(true)
|
||||
.setUseSeparateState(true)
|
||||
.build();
|
||||
|
||||
private final boolean feedUrlEditable;
|
||||
|
||||
private final boolean folderCreation;
|
||||
|
||||
private final boolean noFolderCase;
|
||||
|
||||
/*
|
||||
Let knows if it uses ItemState table to synchronize state
|
||||
*/
|
||||
private final boolean useSeparateState;
|
||||
|
||||
public boolean isFeedUrlEditable() {
|
||||
return feedUrlEditable;
|
||||
}
|
||||
|
||||
public boolean isFolderCreation() {
|
||||
return folderCreation;
|
||||
}
|
||||
|
||||
public boolean isNoFolderCase() {
|
||||
return noFolderCase;
|
||||
}
|
||||
|
||||
public boolean useSeparateState() {
|
||||
return useSeparateState;
|
||||
}
|
||||
|
||||
public AccountConfig(AccountConfigBuilder builder) {
|
||||
this.feedUrlEditable = builder.feedUrlEditable;
|
||||
this.folderCreation = builder.folderCreation;
|
||||
this.noFolderCase = builder.noFolderCase;
|
||||
this.useSeparateState = builder.useSeparateState;
|
||||
}
|
||||
|
||||
public static class AccountConfigBuilder {
|
||||
private boolean feedUrlEditable;
|
||||
private boolean folderCreation;
|
||||
private boolean noFolderCase;
|
||||
private boolean useSeparateState;
|
||||
|
||||
public AccountConfigBuilder setFeedUrlEditable(boolean feedUrlEditable) {
|
||||
this.feedUrlEditable = feedUrlEditable;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AccountConfigBuilder setFolderCreation(boolean folderCreation) {
|
||||
this.folderCreation = folderCreation;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AccountConfigBuilder setNoFolderCase(boolean noFolderCase) {
|
||||
this.noFolderCase = noFolderCase;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AccountConfigBuilder setUseSeparateState(boolean useSeparateState) {
|
||||
this.useSeparateState = useSeparateState;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AccountConfig build() {
|
||||
return new AccountConfig(this);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.readrops.db.entities.account
|
||||
|
||||
import android.os.Parcelable
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
data class AccountConfig(
|
||||
val isFeedUrlEditable: Boolean, // Enables or disables feed url modification in management screen
|
||||
val isFolderCreation: Boolean, // Enables or disables folder creation in management screen
|
||||
val isNoFolderCase: Boolean, // Add a "No folder" option when modifying a feed's folder
|
||||
val useSeparateState: Boolean, // Let knows if it uses ItemState table to synchronize state
|
||||
) : Parcelable {
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val LOCAL = AccountConfig(
|
||||
isFeedUrlEditable = true,
|
||||
isFolderCreation = true,
|
||||
isNoFolderCase = false,
|
||||
useSeparateState = false,
|
||||
)
|
||||
|
||||
@JvmField
|
||||
val NEXTCLOUD_NEWS = AccountConfig(
|
||||
isFeedUrlEditable = false,
|
||||
isFolderCreation = true,
|
||||
isNoFolderCase = false,
|
||||
useSeparateState = false,
|
||||
)
|
||||
|
||||
@JvmField
|
||||
val FRESHRSS = AccountConfig(
|
||||
isFeedUrlEditable = false,
|
||||
isFolderCreation = false,
|
||||
isNoFolderCase = true,
|
||||
useSeparateState = true,
|
||||
)
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
package com.readrops.db.entities.account;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import com.readrops.db.R;
|
||||
|
||||
|
||||
public enum AccountType implements Parcelable {
|
||||
LOCAL(R.mipmap.ic_launcher, R.string.local_account, AccountConfig.LOCAL),
|
||||
NEXTCLOUD_NEWS(R.drawable.ic_nextcloud_news, R.string.nextcloud_news, AccountConfig.NEXTCLOUD_NEWS),
|
||||
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 AccountConfig accountConfig;
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static final Creator<AccountType> CREATOR = new Creator<AccountType>() {
|
||||
@Override
|
||||
public AccountType createFromParcel(Parcel in) {
|
||||
return AccountType.values()[in.readInt()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccountType[] newArray(int size) {
|
||||
return new AccountType[size];
|
||||
}
|
||||
};
|
||||
|
||||
public @DrawableRes
|
||||
int getIconRes() {
|
||||
return iconRes;
|
||||
}
|
||||
|
||||
public @StringRes
|
||||
int getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public AccountConfig getAccountConfig() {
|
||||
return accountConfig;
|
||||
}
|
||||
|
||||
AccountType(@DrawableRes int iconRes, @StringRes int name, AccountConfig accountConfig) {
|
||||
this.iconRes = iconRes;
|
||||
this.name = name;
|
||||
this.accountConfig = accountConfig;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.readrops.db.entities.account
|
||||
|
||||
import android.os.Parcelable
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StringRes
|
||||
import com.readrops.db.R
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
enum class AccountType(@DrawableRes val iconRes: Int,
|
||||
@StringRes val typeName: Int,
|
||||
val accountConfig: AccountConfig?) : Parcelable {
|
||||
LOCAL(R.mipmap.ic_launcher, R.string.local_account, AccountConfig.LOCAL),
|
||||
NEXTCLOUD_NEWS(R.drawable.ic_nextcloud_news, R.string.nextcloud_news, AccountConfig.NEXTCLOUD_NEWS),
|
||||
FEEDLY(R.drawable.ic_feedly, R.string.feedly, null),
|
||||
FRESHRSS(R.drawable.ic_freshrss, R.string.freshrss, AccountConfig.FRESHRSS);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user