Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Dzieniak committed Nov 12, 2019
2 parents b715ae2 + 0f5de6f commit d10d47b
Showing 1 changed file with 35 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package ${package};
import android.content.Context
import co.windly.ktxaccount.runtime.scheme.BaseAccountScheme
<#list descriptorList as descriptor>
import co.windly.ktxaccount.sample.kotlindagger.utility.account.AccountDefinitionConstants.Companion.DEFAULT_${descriptor.fieldNameUpperCase}
import co.windly.ktxaccount.sample.kotlindagger.utility.account.AccountDefinitionConstants.Companion.KEY_${descriptor.fieldNameUpperCase}
import ${package}.AccountDefinitionConstants.Companion.DEFAULT_${descriptor.fieldNameUpperCase}
import ${package}.AccountDefinitionConstants.Companion.KEY_${descriptor.fieldNameUpperCase}
</#list>
import io.reactivex.BackpressureStrategy.LATEST
import io.reactivex.Completable
Expand All @@ -24,9 +24,13 @@ abstract class ${schemeClassName}(context: Context) : BaseAccountScheme(context)

open fun clear(name: String) {
<#list descriptorList as descriptor>

// Clear value under "${descriptor.propertyName}" property and emit default value to it's subject.
remove${descriptor.fieldName?cap_first}(name)
<#if descriptor.enableReactive>
.also { retrieve${descriptor.fieldName?cap_first}Subject(name).onNext(DEFAULT_${descriptor.fieldNameUpperCase}) }
<#if descriptor.enableReactive>.also {
retrieve${descriptor.fieldName?cap_first}Subject(name)
.onNext(DEFAULT_${descriptor.fieldNameUpperCase})
}
</#if>
</#list>
}
Expand All @@ -42,45 +46,39 @@ abstract class ${schemeClassName}(context: Context) : BaseAccountScheme(context)

//region Account

override fun saveAccount(name: String): Completable {
return super.saveAccount(name)
.andThen(Completable.fromAction {
<#list descriptorList as descriptor>

// Initialize "${descriptor.propertyName}" property subject if not yet initialized.
if (${descriptor.fieldName}Subject == null) {
${descriptor.fieldName}Subject = BehaviorSubject.createDefault(get${descriptor.fieldName?cap_first}(name))
}
override fun saveAccount(name: String): Completable =
super
.saveAccount(name)
.andThen(initializeSubjects(name))

// Otherwise emit persisted "${descriptor.propertyName}" property to already existing subject.
else {
${descriptor.fieldName}Subject?.onNext(get${descriptor.fieldName?cap_first}(name))
}
</#list>
})
}
override fun saveAccount(name: String, password: String): Completable =
super
.saveAccount(name, password)
.andThen(initializeSubjects(name))

override fun saveAccount(name: String, password: String): Completable {
return super.saveAccount(name, password)
.andThen(Completable.fromAction {
<#list descriptorList as descriptor>
private fun initializeSubjects(name: String): Completable = Completable.fromAction {
<#list descriptorList as descriptor>

// Initialize "${descriptor.propertyName}" property subject if not yet initialized.
if (${descriptor.fieldName}Subject == null) {
${descriptor.fieldName}Subject = BehaviorSubject.createDefault(get${descriptor.fieldName?cap_first}(name))
}
// Initialize "${descriptor.propertyName}" property subject if not yet initialized.
if (${descriptor.fieldName}Subject == null) {
${descriptor.fieldName}Subject = BehaviorSubject.createDefault(get${descriptor.fieldName?cap_first}(name))
}

// Otherwise emit persisted "${descriptor.propertyName}" property to already existing subject.
else {
${descriptor.fieldName}Subject?.onNext(get${descriptor.fieldName?cap_first}(name))
}
</#list>
})
// Otherwise emit persisted "${descriptor.propertyName}" property to already existing subject.
else {
${descriptor.fieldName}Subject?.onNext(get${descriptor.fieldName?cap_first}(name))
}
</#list>
}

override fun removeAccount(name: String): Completable {
return super.removeAccount(name)
.also {
override fun removeAccount(name: String): Completable =
super
.removeAccount(name)
.andThen(clearSubjects())

private fun clearSubjects(): Completable =
Completable
.fromAction {
<#list descriptorList as descriptor>

// Tear down "${descriptor.propertyName}" property subject.
Expand All @@ -89,7 +87,6 @@ abstract class ${schemeClassName}(context: Context) : BaseAccountScheme(context)
}
</#list>
}
}

//endregion
<#list descriptorList as descriptor>
Expand Down

0 comments on commit d10d47b

Please sign in to comment.