Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.youversion.reactnativesdk

import com.youversion.platform.core.YouVersionPlatformConfiguration
import com.youversion.reactnativesdk.api.BibleReferenceRecord
import com.youversion.reactnativesdk.api.YVPBibleApi
import com.youversion.reactnativesdk.api.YVPHighlightsApi
import com.youversion.reactnativesdk.api.YVPLanguagesApi
import com.youversion.reactnativesdk.api.YVPVotdApi
import expo.modules.kotlin.modules.Module
import expo.modules.kotlin.modules.ModuleDefinition
Expand Down Expand Up @@ -33,5 +37,63 @@ class RNYouVersionPlatformModule : Module() {
dayOfYear = dayOfYear
)
}

AsyncFunction("languages") Coroutine { country: String? ->
return@Coroutine YVPLanguagesApi.languages(
country = country
)
}

AsyncFunction("versions") Coroutine { languageTag: String? ->
return@Coroutine YVPBibleApi.versions(
languageTag = languageTag
)
}

AsyncFunction("version") Coroutine { versionId: Int ->
return@Coroutine YVPBibleApi.version(
versionId = versionId
)
}

AsyncFunction("chapter") Coroutine { bibleReference: BibleReferenceRecord ->
val context = appContext.reactContext
?: throw IllegalStateException("ReactContext is not available yet")

return@Coroutine YVPBibleApi.chapter(
bibleReference = bibleReference,
context = context
)
}

AsyncFunction("createHighlight") Coroutine { bibleId: Int, passageId: String, color: String ->
return@Coroutine YVPHighlightsApi.createHighlight(
bibleId = bibleId,
passageId = passageId,
color = color
)
}

AsyncFunction("getHighlights") Coroutine { bibleId: Int, passageId: String ->
return@Coroutine YVPHighlightsApi.getHighlights(
bibleId = bibleId,
passageId = passageId,
)
}

AsyncFunction("updateHighlight") Coroutine { bibleId: Int, passageId: String, color: String ->
return@Coroutine YVPHighlightsApi.updateHighlight(
bibleId = bibleId,
passageId = passageId,
color = color
)
}

AsyncFunction("deleteHighlight") Coroutine { bibleId: Int, passageId: String ->
return@Coroutine YVPHighlightsApi.deleteHighlight(
bibleId = bibleId,
passageId = passageId
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.youversion.reactnativesdk.api

import android.content.Context
import com.youversion.platform.core.api.YouVersionApi
import com.youversion.platform.core.bibles.domain.BibleReference
import com.youversion.platform.core.bibles.domain.BibleVersionRepository

object YVPBibleApi {
suspend fun versions(languageTag: String?): List<BibleVersionRecord> {
val response = YouVersionApi.bible.versions(languageTag)
val records = response.map { BibleVersionRecord(it) }
return records
}

suspend fun version(versionId: Int): BibleVersionRecord {
val response = YouVersionApi.bible.version(versionId)
val record = BibleVersionRecord(response)
return record
}

suspend fun chapter(bibleReference: BibleReferenceRecord, context: Context): String {
val response = BibleVersionRepository(context).chapter(
reference = BibleReference(
versionId = bibleReference.versionId,
bookUSFM = bibleReference.bookUSFM,
chapter = bibleReference.chapter,
)
)

return response
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.youversion.reactnativesdk.api

import com.youversion.platform.core.api.YouVersionApi

object YVPHighlightsApi {
suspend fun createHighlight(bibleId: Int, passageId: String, color: String): Boolean {
val response = YouVersionApi.highlights.createHighlight(
versionId = bibleId,
passageId = passageId,
color = color
)

return response
}

suspend fun getHighlights(bibleId: Int, passageId: String): List<HighlightRecord> {
val response = YouVersionApi.highlights.highlights(
versionId = bibleId,
passageId = passageId
)

val records = response.map { HighlightRecord(it) }
return records
}

suspend fun updateHighlight(bibleId: Int, passageId: String, color: String): Boolean {
val response = YouVersionApi.highlights.updateHighlight(
versionId = bibleId,
passageId = passageId,
color = color
)

return response
}

suspend fun deleteHighlight(bibleId: Int, passageId: String): Boolean {
val response = YouVersionApi.highlights.deleteHighlight(
versionId = bibleId,
passageId = passageId,
)

return response
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.youversion.reactnativesdk.api

import com.youversion.platform.core.api.YouVersionApi

object YVPLanguagesApi {
suspend fun languages(country: String?): List<LanguageRecord> {
val response = YouVersionApi.language.languages(country)
val records = response.map { LanguageRecord(it) }
return records
}
}
168 changes: 168 additions & 0 deletions android/src/main/java/com/youversion/reactnativesdk/api/YVPRecords.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.youversion.reactnativesdk.api

import com.youversion.platform.core.bibles.models.BibleBook
import com.youversion.platform.core.bibles.models.BibleChapter
import com.youversion.platform.core.bibles.models.BibleVersion
import com.youversion.platform.core.highlights.models.Highlight
import com.youversion.platform.core.languages.models.Language
import com.youversion.platform.core.votd.models.YouVersionVerseOfTheDay
import expo.modules.kotlin.records.Field
import expo.modules.kotlin.records.Record
Expand All @@ -15,3 +20,166 @@ data class YouVersionVerseOfTheDayRecord(
day = votd.day
)
}

data class LanguageRecord(
@Field
val id: String,
@Field
val language: String,
@Field
val script: String?,
@Field
val scriptName: String?,
@Field
val aliases: List<String>,
@Field
val displayNames: Map<String, String>,
@Field
val scripts: List<String>,
@Field
val variants: List<String>,
@Field
val countries: List<String>,
@Field
val textDirection: String,
@Field
val defaultBibleVersionId: Int?

) : Record {
constructor(language: Language) : this(
id = language.id,
language = language.language,
script = language.script,
scriptName = language.scriptName,
aliases = language.aliases,
displayNames = language.displayNames,
scripts = language.scripts,
variants = language.variants,
countries = language.countries,
textDirection = language.textDirection,
defaultBibleVersionId = language.defaultBibleVersionId
)
}

data class BibleVersionRecord(
@Field
val id: Int,
@Field
val abbreviation: String?,
@Field
val copyrightLong: String?,
@Field
val copyrightShort: String?,
@Field
val languageTag: String?,
@Field
val localizedAbbreviation: String?,
@Field
val localizedTitle: String?,
@Field
val readerFooter: String?,
@Field
val readerFooterUrl: String?,
@Field
val title: String?,
@Field
val bookCodes: List<String>?,
@Field
val books: List<BibleBookRecord>?,
@Field
val textDirection: String?
) : Record {
constructor(bibleVersion: BibleVersion) : this(
id = bibleVersion.id,
abbreviation = bibleVersion.abbreviation,
copyrightLong = bibleVersion.copyrightLong,
copyrightShort = bibleVersion.copyrightShort,
languageTag = bibleVersion.languageTag,
localizedAbbreviation = bibleVersion.localizedAbbreviation,
localizedTitle = bibleVersion.localizedTitle,
readerFooter = bibleVersion.readerFooter,
readerFooterUrl = bibleVersion.readerFooterUrl,
title = bibleVersion.title,
bookCodes = bibleVersion.bookCodes,
books = bibleVersion.books?.map { BibleBookRecord(it) },
textDirection = bibleVersion.textDirection
)
}

data class BibleBookRecord(
@Field
val usfm: String?,
@Field
val title: String?,
@Field
val abbreviation: String?,
@Field
val canon: String?,
@Field
val chapters: List<BibleChapterRecord>?
) : Record {
constructor(bibleBook: BibleBook) : this(
usfm = bibleBook.usfm,
title = bibleBook.title,
abbreviation = bibleBook.abbreviation,
canon = bibleBook.canon,
chapters = bibleBook.chapters?.map { BibleChapterRecord(it) }
)
}

data class BibleChapterRecord(
@Field
val id: String?,
@Field
val bookUSFM: String?,
@Field
val isCanonical: Boolean?,
@Field
val passageId: String?,
@Field
val title: String?
) : Record {
constructor(bibleChapter: BibleChapter) : this(
id = bibleChapter.id,
bookUSFM = bibleChapter.bookUSFM,
isCanonical = bibleChapter.isCanonical,
passageId = bibleChapter.passageId,
title = bibleChapter.title
)
}

data class BibleReferenceRecord(
@Field
val versionId: Int,
@Field
val bookUSFM: String,
@Field
val chapter: Int,
) : Record

data class HighlightRecord(
@Field
val id: String?,
@Field
val bibleId: Int,
@Field
val passageId: String,
@Field
val color: String,
@Field
val userId: String?,
@Field
val createTime: String?,
@Field
val updateTime: String?
) : Record {
constructor(highlight: Highlight) : this(
id = highlight.id,
bibleId = highlight.versionId,
passageId = highlight.passageId,
color = highlight.color,
userId = highlight.userId,
createTime = highlight.createTime,
updateTime = highlight.updateTime
)
}
8 changes: 4 additions & 4 deletions src/api/bible.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Module } from "../native";
import { BibleReference, BibleVersion } from "../types";
import { BibleReferenceBase, BibleVersion } from "../types";

export const BibleAPI = {
/**
* Retrieves a list of Bible versions available for a specified language code (like "en").
* Retrieves a list of Bible versions available for a specified language tag (like "eng").
*
* @param languageTag - An optional language code per BCP 47 for filtering available Bible versions. If `nil`
* the function returns versions for all languages.
Expand All @@ -26,10 +26,10 @@ export const BibleAPI = {
/**
* Retrieves the content of a single Bible chapter from the server as an HTML string.
*
* @param bibleReference - A {@link BibleReference} object specifying the reference to retrieve.
* @param bibleReference - A {@link BibleReferenceBase} object specifying the reference to retrieve.
* @returns The chapter content as an HTML string.
*/
getChapter(bibleReference: BibleReference): Promise<string> {
getChapter(bibleReference: BibleReferenceBase): Promise<string> {
return Module.chapter(bibleReference);
},
};
4 changes: 2 additions & 2 deletions src/native.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NativeModule, requireNativeModule } from "expo";

import {
BibleReference,
BibleReferenceBase,
BibleVersion,
HighlightResponse,
LanguageOverview,
Expand Down Expand Up @@ -48,7 +48,7 @@ declare class RNYouVersionPlatformModule extends NativeModule {

version(versionId: number): Promise<BibleVersion>;

chapter(bibleReference: BibleReference): Promise<string>;
chapter(bibleReference: BibleReferenceBase): Promise<string>;

getAccessToken(): string | null;
}
Expand Down
Loading