Skip to content

Commit

Permalink
feat: shift business logic to module
Browse files Browse the repository at this point in the history
  • Loading branch information
adityastic committed Jan 3, 2020
1 parent f56a32d commit 9a940db
Show file tree
Hide file tree
Showing 36 changed files with 532 additions and 454 deletions.
98 changes: 56 additions & 42 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,60 @@
language: android
dist: trusty
sudo: true
jdk:
- oraclejdk8
android:
components:
- tools
- android-29
- build-tools-29.0.2
- platform-tools
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
cache:
bundler : true
directories:
- "${TRAVIS_BUILD_DIR}/gradle/caches/"
- "${TRAVIS_BUILD_DIR}/gradle/wrapper/dists/"
- "$HOME/.gradle/caches/"
- "$HOME/.gradle/wrapper/"
jobs:
include:
- stage: build android and ios-framework
language: android
dist: trusty
sudo: true
jdk:
- oraclejdk8
android:
components:
- tools
- android-29
- build-tools-29.0.2
- platform-tools
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
cache:
bundler : true
directories:
- "${TRAVIS_BUILD_DIR}/gradle/caches/"
- "${TRAVIS_BUILD_DIR}/gradle/wrapper/dists/"
- "$HOME/.gradle/caches/"
- "$HOME/.gradle/wrapper/"

install:
- bundle install
install:
- bundle install

before_script:
- bash scripts/prep-key.sh
- bash scripts/check-screenshots.sh
before_script:
- bash scripts/prep-key.sh
- bash scripts/check-screenshots.sh

script:
- ./gradlew spotlessCheck
- ./gradlew build --stacktrace
script:
- ./gradlew spotlessCheck
- ./gradlew build --stacktrace

deploy:
- provider: script
skip_cleanup: true
script: bash scripts/upload-apk.sh
on:
all_branches: true
condition: $TRAVIS_BRANCH =~ ^(master|development)$
repo: fossasia/badge-magic-android
- provider: script
skip_cleanup: true
script: bash scripts/upload-gh-pages.sh
on:
all_branches: true
repo: fossasia/badge-magic-android
deploy:
- provider: script
skip_cleanup: true
script: bash scripts/upload-apk.sh
on:
all_branches: true
condition: $TRAVIS_BRANCH =~ ^(master|development)$
repo: fossasia/badge-magic-android
- provider: script
skip_cleanup: true
script: bash scripts/upload-gh-pages.sh
on:
all_branches: true
repo: fossasia/badge-magic-android
- provider: script
skip_cleanup: true
script: bash scripts/upload-ios-framework.sh
on:
all_branches: true
repo: fossasia/badge-magic-android
- stage: build ios
os: osx
osx_image: xcode11.3
language: objective-c
script: echo "Hello IOS"
72 changes: 72 additions & 0 deletions BadgeMagicModule/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

plugins {
kotlin("multiplatform")
id("kotlinx-serialization")
}

val kt_serial = "0.14.0"
val klockVersion = "1.8.6"

kotlin {
//select iOS target platform depending on the Xcode environment variables
val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
::iosArm64
else
::iosX64

iOSTarget("ios") {
binaries {
framework {
baseName = "BadgeMagicModule"
}
}
}

jvm("android")

sourceSets["commonMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kt_serial")
implementation("com.soywiz.korlibs.klock:klock:$klockVersion")
}

sourceSets["androidMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kt_serial")
}

sourceSets["iosMain"].dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$kt_serial")
}
}

val packForXcode by tasks.creating(Sync::class) {
val targetDir = File(buildDir, "xcode-frameworks")

/// selecting the right configuration for the iOS
/// framework depending on the environment
/// variables set by Xcode build
val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
val framework = kotlin.targets
.getByName<KotlinNativeTarget>("ios")
.binaries.getFramework(mode)
inputs.property("mode", mode)
dependsOn(framework.linkTask)

from({ framework.outputDirectory })
into(targetDir)

/// generate a helpful ./gradlew wrapper with embedded Java path
doLast {
val gradlew = File(targetDir, "gradlew")
gradlew.writeText("#!/bin/bash\n"
+ "export 'JAVA_HOME=${System.getProperty("java.home")}'\n"
+ "cd '${rootProject.rootDir}'\n"
+ "./gradlew \$@\n")
gradlew.setExecutable(true)
}
}

tasks.getByName("build").dependsOn(packForXcode)
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.fossasia.badgemagic.data.fragments
package data

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import org.fossasia.badgemagic.data.device.model.Mode
import org.fossasia.badgemagic.data.device.model.Speed
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

const val CONF_HEX_STRINGS = "hex_strings"
const val CONF_SPEED = "speed"
Expand All @@ -12,23 +10,23 @@ const val CONF_FLASH = "flash"
const val CONF_MARQUEE = "marquee"
const val CONF_INVERTED = "inverted"

@JsonClass(generateAdapter = true)
@Serializable
class BadgeConfig {
@Json(name = CONF_HEX_STRINGS)
@SerialName(CONF_HEX_STRINGS)
var hexStrings: List<String> = mutableListOf()

@Json(name = CONF_SPEED)
@SerialName(CONF_SPEED)
var speed: Speed = Speed.ONE

@Json(name = CONF_MODE)
@SerialName(CONF_MODE)
var mode: Mode = Mode.LEFT

@Json(name = CONF_FLASH)
@SerialName(CONF_FLASH)
var isFlash: Boolean = false

@Json(name = CONF_MARQUEE)
@SerialName(CONF_MARQUEE)
var isMarquee: Boolean = false

@Json(name = CONF_INVERTED)
@SerialName(CONF_INVERTED)
var isInverted: Boolean = false
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package org.fossasia.badgemagic.data.fragments
package data

data class ConfigInfo(val badgeJSON: String, val fileName: String)
6 changes: 6 additions & 0 deletions BadgeMagicModule/src/commonMain/kotlin/data/DataToSend.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package data

import kotlinx.serialization.Serializable

@Serializable
data class DataToSend(val messages: List<Message>)
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package org.fossasia.badgemagic.data.device.model
package data

import kotlinx.serialization.Serializable

@Serializable
data class Message(val hexStrings: List<String>, val flash: Boolean = false, val marquee: Boolean = false, val speed: Speed = Speed.ONE, val mode: Mode = Mode.LEFT)
13 changes: 13 additions & 0 deletions BadgeMagicModule/src/commonMain/kotlin/data/Mode.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package data

enum class Mode(val hexValue: Byte) {
LEFT(0x00),
RIGHT(0x01),
UP(0x02),
DOWN(0x03),
FIXED(0x04),
SNOWFLAKE(0x05),
PICTURE(0x06),
ANIMATION(0x07),
LASER(0x08);
}
12 changes: 12 additions & 0 deletions BadgeMagicModule/src/commonMain/kotlin/data/Speed.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package data

enum class Speed(val hexValue: Byte) {
ONE(0x00),
TWO(0x10),
THREE(0x20),
FOUR(0x30),
FIVE(0x40),
SIX(0x50),
SEVEN(0x60),
EIGHT(0x70);
}
Loading

0 comments on commit 9a940db

Please sign in to comment.