Skip to content

Commit

Permalink
Splitting versions for mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinSchildhorn committed Nov 15, 2024
1 parent 6ea15ab commit f7a799b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import shared

struct ContentView: View {

let common: SampleMobile
let common: SampleIOS

init() {
let filePath = NSHomeDirectory() + "/Documents/"
let fileName = "KermitSampleLogs"
ContentView.createLoggingFile(withName: fileName, atPath: filePath)

self.common = SampleMobile(filePathString: filePath, logFileName: fileName)
self.common = SampleIOS(filePathString: filePath, logFileName: fileName)
}

private static func createLoggingFile(withName name:String, atPath filePath: String){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import android.view.View
import androidx.fragment.app.Fragment
import co.touchlab.KermitSample.databinding.FragmentFirstBinding
import co.touchlab.kermit.Logger
import co.touchlab.kermitsample.SampleMobile
import co.touchlab.kermitsample.SampleAndroid

/**
* A simple [Fragment] subclass as the default destination in the navigation.
Expand All @@ -25,7 +25,7 @@ class FirstFragment : Fragment(R.layout.fragment_first) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Logger.withTag("FirstFragment").v("First fragment loaded")
val sample = SampleMobile(context?.filesDir?.path ?: "")
val sample = SampleAndroid(context?.filesDir?.path ?: "")
val binding = FragmentFirstBinding.bind(view)
binding.btnClickCount.setOnClickListener { sample.onClickI() }
binding.btnException.setOnClickListener { sample.logException() }
Expand Down
23 changes: 6 additions & 17 deletions samples/sample/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,13 @@ kotlin {

implementation("co.touchlab:kermit-test:${KERMIT_VERSION}")
}
val mobileMain by creating {
dependsOn(commonMain.get())
dependencies {
implementation("co.touchlab:kermit-io:${KERMIT_VERSION}")
}
androidMain.dependencies {
implementation("co.touchlab:kermit-io:${KERMIT_VERSION}")
}
androidMain {
dependsOn(mobileMain)
}
iosMain {
dependsOn(mobileMain)
iosX64Main.get().dependsOn(this)
iosArm64Main.get().dependsOn(this)
iosSimulatorArm64Main.get().dependsOn(this)
dependencies {
// Only if you want to talk to Kermit from Swift
api("co.touchlab:kermit-simple:${KERMIT_VERSION}")
}
iosMain.dependencies {
// Only if you want to talk to Kermit from Swift
api("co.touchlab:kermit-simple:${KERMIT_VERSION}")
implementation("co.touchlab:kermit-io:${KERMIT_VERSION}")
}
}
cocoapods {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2024 Touchlab
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

package co.touchlab.kermitsample

import co.touchlab.kermit.Logger
import co.touchlab.kermit.io.RollingFileLogWriter
import co.touchlab.kermit.io.RollingFileLogWriterConfig
import kotlinx.io.files.Path

class SampleAndroid(filePathString: String, logFileName: String = "KermitSampleLogs") : SampleCommon() {
init {
Logger.addLogWriter(
RollingFileLogWriter(
config = RollingFileLogWriterConfig(
logFileName = logFileName,
logFilePath = Path(filePathString),
)
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import co.touchlab.kermit.io.RollingFileLogWriter
import co.touchlab.kermit.io.RollingFileLogWriterConfig
import kotlinx.io.files.Path

class SampleMobile(filePathString: String, logFileName: String = "KermitSampleLogs") : SampleCommon() {
class SampleIOS(filePathString: String, logFileName: String = "KermitSampleLogs") : SampleCommon() {
init {
Logger.addLogWriter(
RollingFileLogWriter(
Expand Down

0 comments on commit f7a799b

Please sign in to comment.