Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realmの導入 #31

Merged
merged 18 commits into from
Oct 11, 2015
Merged

Realmの導入 #31

merged 18 commits into from
Oct 11, 2015

Conversation

Reyurnible
Copy link
Owner

WHAT

TranslatedHistoryの部分に対して、Realmでログを保存できるようにした

Information

Realmのバージョン:0.83.0
Kotlin対応のものも同時に入れた

compile 'io.realm:realm-android:0.83.0'
kapt 'io.realm:realm-android:0.83.0'

Realmのクラス

@RealmClass
public open class TranslatedHistory(
        public open var projectId: Int = -1,
        public open var createdAt: Date = Date(),
        public open var successful: Boolean = false,
        public open var text: String = "",
        public open var translatedText: String = ""
) : RealmObject() {

}

public inline fun TranslatedHistory.toTranslatedText(): TranslatedText =
        TranslatedText(
                this.successful,
                this.text,
                this.translatedText,
                ArrayList<Word>()
        )

// Realmのオブジェクトが後にできて、できた依存関係なのでこちらに拡張関数として書く
public inline fun TranslatedText.toTranslatedHistory(projectId: Int): TranslatedHistory =
        TranslatedHistory(
                projectId,
                Date(),
                this.successful,
                this.text,
                this.translatedText
        )

Tips

Realmはメソッドにgetter / setterしか持てないが、inline fun (拡張関数)で入れてやることで、メソッドを持たせられるようになる。
また、依存関係は新たに追加されたrealmのオブジェクト側に全部持たせることとした。

ISSUE

#26

Reyurnible added a commit that referenced this pull request Oct 11, 2015
@Reyurnible Reyurnible merged commit b01fcec into master Oct 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant