Skip to content

Commit

Permalink
Merge pull request #16 from hotwired/rename-classes
Browse files Browse the repository at this point in the history
Rename `Turbo*` classes
  • Loading branch information
jayohms authored Mar 20, 2024
2 parents 678b23c + c18088a commit 57fac49
Show file tree
Hide file tree
Showing 74 changed files with 451 additions and 451 deletions.
2 changes: 1 addition & 1 deletion core/proguard-consumer-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# The custom rule file must be defined using the 'consumerProguardFiles' property in your
# build.gradle.kts file.

-keepclassmembers class dev.hotwire.core.turbo.session.TurboSession {
-keepclassmembers class dev.hotwire.core.turbo.session.Session {
@android.webkit.JavascriptInterface <methods>;
}
-keepclassmembers class dev.hotwire.core.bridge.Bridge {
Expand Down
2 changes: 1 addition & 1 deletion core/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
-keepclassmembers class dev.hotwire.core.turbo.session.TurboSession {
-keepclassmembers class dev.hotwire.core.turbo.session.Session {
@android.webkit.JavascriptInterface <methods>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import androidx.lifecycle.LifecycleOwner
import dev.hotwire.core.config.Hotwire
import dev.hotwire.core.logging.logEvent
import dev.hotwire.core.logging.logWarning
import dev.hotwire.core.turbo.nav.TurboNavDestination
import dev.hotwire.core.turbo.nav.HotwireNavDestination

@Suppress("unused")
class BridgeDelegate(
val location: String,
val destination: TurboNavDestination
val destination: HotwireNavDestination
) : DefaultLifecycleObserver {
internal var bridge: Bridge? = null
private var destinationIsActive: Boolean = false
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/kotlin/dev/hotwire/core/config/Hotwire.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import dev.hotwire.core.navigation.fragments.HotwireWebFragment
import dev.hotwire.core.navigation.routing.AppNavigationRoute
import dev.hotwire.core.navigation.routing.BrowserRoute
import dev.hotwire.core.navigation.routing.Router
import dev.hotwire.core.turbo.config.TurboPathConfiguration
import dev.hotwire.core.turbo.config.PathConfiguration
import kotlin.reflect.KClass

object Hotwire {
Expand Down Expand Up @@ -39,13 +39,13 @@ object Hotwire {
/**
* The path configuration that defines your navigation rules.
*/
val pathConfiguration = TurboPathConfiguration()
val pathConfiguration = PathConfiguration()

/**
* Loads the [TurboPathConfiguration] JSON file(s) from the provided location to
* Loads the [PathConfiguration] JSON file(s) from the provided location to
* configure navigation rules.
*/
fun loadPathConfiguration(context: Context, location: TurboPathConfiguration.Location) {
fun loadPathConfiguration(context: Context, location: PathConfiguration.Location) {
pathConfiguration.load(context, location)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dev.hotwire.core.config

import android.webkit.WebView
import dev.hotwire.core.bridge.StradaJsonConverter
import dev.hotwire.core.turbo.config.TurboPathConfiguration
import dev.hotwire.core.turbo.http.TurboHttpClient

class HotwireConfig internal constructor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import android.os.Bundle
import android.view.View
import dev.hotwire.core.bridge.BridgeDelegate
import dev.hotwire.core.turbo.fragments.TurboWebBottomSheetDialogFragment
import dev.hotwire.core.turbo.nav.TurboNavGraphDestination
import dev.hotwire.core.turbo.nav.HotwireDestination
import dev.hotwire.core.turbo.views.TurboWebView

@TurboNavGraphDestination(uri = "turbo://fragment/web/modal/sheet")
@HotwireDestination(uri = "turbo://fragment/web/modal/sheet")
open class HotwireWebBottomSheetFragment : TurboWebBottomSheetDialogFragment() {
private val bridgeDelegate by lazy {
BridgeDelegate(location = location, destination = this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import android.os.Bundle
import android.view.View
import dev.hotwire.core.bridge.BridgeDelegate
import dev.hotwire.core.turbo.fragments.TurboWebFragment
import dev.hotwire.core.turbo.nav.TurboNavGraphDestination
import dev.hotwire.core.turbo.nav.HotwireDestination
import dev.hotwire.core.turbo.views.TurboWebView

@TurboNavGraphDestination(uri = "turbo://fragment/web")
@HotwireDestination(uri = "turbo://fragment/web")
open class HotwireWebFragment : TurboWebFragment() {
private val bridgeDelegate by lazy {
BridgeDelegate(location = location, destination = this)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.hotwire.core.turbo.activities

import dev.hotwire.core.turbo.delegates.HotwireActivityDelegate
import dev.hotwire.core.turbo.session.SessionNavHostFragment

/**
* Interface that should be implemented by any Activity using Turbo. Ensures that the
* Activity provides a [HotwireActivityDelegate] so the framework can initialize the
* [SessionNavHostFragment] hosted in your Activity's layout resource.
*/
interface HotwireActivity {
var delegate: HotwireActivityDelegate
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.net.Uri
import androidx.core.net.toUri
import com.google.gson.annotations.SerializedName
import dev.hotwire.core.config.Hotwire
import dev.hotwire.core.turbo.nav.TurboNavGraphDestination
import dev.hotwire.core.turbo.nav.HotwireDestination
import dev.hotwire.core.turbo.nav.TurboNavPresentation
import dev.hotwire.core.turbo.nav.TurboNavPresentationContext
import dev.hotwire.core.turbo.nav.TurboNavQueryStringPresentation
Expand All @@ -16,20 +16,20 @@ import java.net.URL
* Provides the ability to load, parse, and retrieve url path
* properties from the app's JSON configuration file.
*/
class TurboPathConfiguration {
private val cachedProperties: HashMap<String, TurboPathConfigurationProperties> = hashMapOf()
class PathConfiguration {
private val cachedProperties: HashMap<String, PathConfigurationProperties> = hashMapOf()

internal var loader: TurboPathConfigurationLoader? = null
internal var loader: PathConfigurationLoader? = null

@SerializedName("rules")
internal var rules: List<TurboPathConfigurationRule> = emptyList()
internal var rules: List<PathConfigurationRule> = emptyList()

/**
* Gets the top-level settings specified in the app's path configuration.
* The settings are map of key/value `String` items.
*/
@SerializedName("settings")
var settings: TurboPathConfigurationSettings = TurboPathConfigurationSettings()
var settings: PathConfigurationSettings = PathConfigurationSettings()
private set

/**
Expand Down Expand Up @@ -62,7 +62,7 @@ class TurboPathConfiguration {
*/
internal fun load(context: Context, location: Location) {
if (loader == null) {
loader = TurboPathConfigurationLoader(context.applicationContext)
loader = PathConfigurationLoader(context.applicationContext)
}

loader?.load(location) {
Expand All @@ -81,10 +81,10 @@ class TurboPathConfiguration {
* regex rules.
* @return The map of key/value `String` properties
*/
fun properties(location: String): TurboPathConfigurationProperties {
fun properties(location: String): PathConfigurationProperties {
cachedProperties[location]?.let { return it }

val properties = TurboPathConfigurationProperties()
val properties = PathConfigurationProperties()
val path = path(location)

for (rule in rules) {
Expand All @@ -106,45 +106,45 @@ class TurboPathConfiguration {
}
}

typealias TurboPathConfigurationProperties = HashMap<String, String>
typealias TurboPathConfigurationSettings = HashMap<String, String>
typealias PathConfigurationProperties = HashMap<String, String>
typealias PathConfigurationSettings = HashMap<String, String>

val TurboPathConfigurationProperties.presentation: TurboNavPresentation
val PathConfigurationProperties.presentation: TurboNavPresentation
@SuppressLint("DefaultLocale") get() = try {
val value = get("presentation") ?: "default"
TurboNavPresentation.valueOf(value.uppercase())
} catch (e: IllegalArgumentException) {
TurboNavPresentation.DEFAULT
}

val TurboPathConfigurationProperties.queryStringPresentation: TurboNavQueryStringPresentation
val PathConfigurationProperties.queryStringPresentation: TurboNavQueryStringPresentation
@SuppressLint("DefaultLocale") get() = try {
val value = get("query_string_presentation") ?: "default"
TurboNavQueryStringPresentation.valueOf(value.uppercase())
} catch (e: IllegalArgumentException) {
TurboNavQueryStringPresentation.DEFAULT
}

val TurboPathConfigurationProperties.context: TurboNavPresentationContext
val PathConfigurationProperties.context: TurboNavPresentationContext
@SuppressLint("DefaultLocale") get() = try {
val value = get("context") ?: "default"
TurboNavPresentationContext.valueOf(value.uppercase())
} catch (e: IllegalArgumentException) {
TurboNavPresentationContext.DEFAULT
}

val TurboPathConfigurationProperties.uri: Uri
val PathConfigurationProperties.uri: Uri
get() = get("uri")?.toUri() ?:
TurboNavGraphDestination.from(Hotwire.defaultFragmentDestination).uri.toUri()
HotwireDestination.from(Hotwire.defaultFragmentDestination).uri.toUri()

val TurboPathConfigurationProperties.fallbackUri: Uri?
val PathConfigurationProperties.fallbackUri: Uri?
get() = get("fallback_uri")?.toUri()

val TurboPathConfigurationProperties.title: String?
val PathConfigurationProperties.title: String?
get() = get("title")

val TurboPathConfigurationProperties.pullToRefreshEnabled: Boolean
val PathConfigurationProperties.pullToRefreshEnabled: Boolean
get() = get("pull_to_refresh_enabled")?.toBoolean() ?: false

val TurboPathConfigurationSettings.screenshotsEnabled: Boolean
val PathConfigurationSettings.screenshotsEnabled: Boolean
get() = get("screenshots_enabled")?.toBoolean() ?: true
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext

internal class TurboPathConfigurationLoader(val context: Context) : CoroutineScope {
internal var repository = TurboPathConfigurationRepository()
internal class PathConfigurationLoader(val context: Context) : CoroutineScope {
internal var repository = PathConfigurationRepository()

override val coroutineContext: CoroutineContext
get() = dispatcherProvider.io + Job()

fun load(location: TurboPathConfiguration.Location, onCompletion: (TurboPathConfiguration) -> Unit) {
fun load(location: PathConfiguration.Location, onCompletion: (PathConfiguration) -> Unit) {
location.assetFilePath?.let {
loadBundledAssetConfiguration(it, onCompletion)
}
Expand All @@ -27,7 +27,7 @@ internal class TurboPathConfigurationLoader(val context: Context) : CoroutineSco
}
}

private fun downloadRemoteConfiguration(url: String, onCompletion: (TurboPathConfiguration) -> Unit) {
private fun downloadRemoteConfiguration(url: String, onCompletion: (PathConfiguration) -> Unit) {
// Always load the previously cached version first, if available
loadCachedConfigurationForUrl(url, onCompletion)

Expand All @@ -42,15 +42,15 @@ internal class TurboPathConfigurationLoader(val context: Context) : CoroutineSco
}
}

private fun loadBundledAssetConfiguration(filePath: String, onCompletion: (TurboPathConfiguration) -> Unit) {
private fun loadBundledAssetConfiguration(filePath: String, onCompletion: (PathConfiguration) -> Unit) {
val json = repository.getBundledConfiguration(context, filePath)
load(json)?.let {
logEvent("bundledPathConfigurationLoaded", filePath)
onCompletion(it)
}
}

private fun loadCachedConfigurationForUrl(url: String, onCompletion: (TurboPathConfiguration) -> Unit) {
private fun loadCachedConfigurationForUrl(url: String, onCompletion: (PathConfiguration) -> Unit) {
repository.getCachedConfigurationForUrl(context, url)?.let { json ->
load(json)?.let {
logEvent("cachedPathConfigurationLoaded", url)
Expand All @@ -59,12 +59,12 @@ internal class TurboPathConfigurationLoader(val context: Context) : CoroutineSco
}
}

private fun cacheConfigurationForUrl(url: String, pathConfiguration: TurboPathConfiguration) {
private fun cacheConfigurationForUrl(url: String, pathConfiguration: PathConfiguration) {
repository.cacheConfigurationForUrl(context, url, pathConfiguration)
}

private fun load(json: String) = try {
json.toObject(object : TypeToken<TurboPathConfiguration>() {})
json.toObject(object : TypeToken<PathConfiguration>() {})
} catch(e: Exception) {
logError("pathConfiguredFailedToParse", e)
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import dev.hotwire.core.turbo.util.toJson
import kotlinx.coroutines.withContext
import okhttp3.Request

internal class TurboPathConfigurationRepository {
internal class PathConfigurationRepository {
private val cacheFile = "turbo"

suspend fun getRemoteConfiguration(url: String): String? {
Expand All @@ -29,7 +29,7 @@ internal class TurboPathConfigurationRepository {
return prefs(context).getString(url, null)
}

fun cacheConfigurationForUrl(context: Context, url: String, pathConfiguration: TurboPathConfiguration) {
fun cacheConfigurationForUrl(context: Context, url: String, pathConfiguration: PathConfiguration) {
prefs(context).edit {
putString(url, pathConfiguration.toJson())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import dev.hotwire.core.BuildConfig
import dev.hotwire.core.logging.logError
import java.util.regex.PatternSyntaxException

internal data class TurboPathConfigurationRule(
internal data class PathConfigurationRule(
@SerializedName("patterns") val patterns: List<String>,
@SerializedName("properties") val properties: TurboPathConfigurationProperties
@SerializedName("properties") val properties: PathConfigurationProperties
) {

fun matches(path: String): Boolean {
Expand Down
Loading

0 comments on commit 57fac49

Please sign in to comment.