Created
April 11, 2020 16:57
-
-
Save 5ALEKSEY/307609278a57a2faffaa63b1fea0b55b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface IPasswordsRepository { | |
fun getAllPasswords(): Flowable<List<PasswordRepoEntity>> | |
fun getPasswordById(passwordId: Long): Single<PasswordRepoEntity> | |
fun deletePasswordsByIds(passwordIds: List<Long>): Single<Boolean> | |
fun addNewPasswords(passwordRepoEntities: List<PasswordRepoEntity>): Single<Boolean> | |
fun updatePasswords(passwordRepoEntities: List<PasswordRepoEntity>): Single<Boolean> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity(tableName = PasswordDBEntity.PASSWORD_TABLE_NAME) | |
data class PasswordDBEntity( | |
@PrimaryKey(autoGenerate = true) | |
@ColumnInfo(name = COLUMN_PASSWORD_ID) | |
var passwordIdValue: Long?, | |
@ColumnInfo(name = COLUMN_PASSWORD_NAME) | |
var passwordNameValue: String, | |
@ColumnInfo(name = COLUMN_PASSWORD_AVATAR_PATH) | |
var passwordAvatarPathValue: String, | |
@ColumnInfo(name = COLUMN_PASSWORD_CONTENT) | |
var passwordContentValue: String | |
) : PasswordRepoEntity { | |
@Ignore | |
constructor(passwordId: Long) : this(passwordId, "", "", "") | |
@Ignore | |
constructor(passwordName: String, passwordContent: String, avatarPath: String?) | |
: this(null, passwordName, avatarPath ?: "", passwordContent) | |
companion object { | |
const val PASSWORD_TABLE_NAME = "Passwords" | |
// column names | |
const val COLUMN_PASSWORD_ID = "password_id" // autogenerated primary key | |
const val COLUMN_PASSWORD_NAME = "password_name" // password alias | |
const val COLUMN_PASSWORD_AVATAR_PATH = "password_avatar_path" // url of password picture | |
const val COLUMN_PASSWORD_CONTENT = "password_content" // url of password picture | |
} | |
override fun getPasswordId(): Long? = passwordIdValue | |
override fun getPasswordName(): String = passwordNameValue | |
override fun getPasswordAvatarPath(): String = passwordAvatarPathValue | |
override fun getPasswordContent(): String = passwordContentValue | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface PasswordRepoEntity { | |
fun getPasswordId(): Long? | |
fun getPasswordName(): String | |
fun getPasswordAvatarPath(): String | |
fun getPasswordContent(): String | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Dao | |
interface PasswordsDAO { | |
@Query("SELECT * FROM " + PasswordDBEntity.PASSWORD_TABLE_NAME) | |
fun getAllPasswords(): Flowable<List<PasswordDBEntity>> | |
.............. | |
.............. | |
.............. | |
.............. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PasswordsRepositoryImpl @Inject constructor( | |
private val passwordsLocalStore: PSDatabase | |
) : IPasswordsRepository { | |
override fun getAllPasswords(): Flowable<List<PasswordRepoEntity>> = | |
passwordsLocalStore.getPasswordsDao() | |
.getAllPasswords() | |
.subscribeOn(Schedulers.io()) | |
............... | |
............... | |
............... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment