Skip to content

Commit

Permalink
Remove react-native; rewrite main screen in (native) swift
Browse files Browse the repository at this point in the history
  • Loading branch information
iSoron committed Mar 31, 2019
1 parent a546f6d commit 8544c5d
Show file tree
Hide file tree
Showing 148 changed files with 2,000 additions and 8,892 deletions.
Binary file added core/assets/main/fonts/Roboto-Bold.ttf
Binary file not shown.
Binary file added core/assets/main/fonts/Roboto-Regular.ttf
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/assets/test/components/Ring/draw1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 18 additions & 12 deletions core/src/commonMain/kotlin/org/isoron/uhabits/Backend.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@

package org.isoron.uhabits

import org.isoron.uhabits.gui.*
import org.isoron.uhabits.models.*
import org.isoron.uhabits.utils.*

class Backend(var databaseOpener: DatabaseOpener,
var fileOpener: FileOpener,
var log: Log) {

var database: Database
var habitsRepository: HabitRepository
var habits = mutableMapOf<Int, Habit>()
class Backend(databaseOpener: DatabaseOpener,
fileOpener: FileOpener,
log: Log) {

private var database: Database
private var habitsRepository: HabitRepository
private var habits = mutableMapOf<Int, Habit>()
var theme: Theme = LightTheme()

init {
val dbFile = fileOpener.openUserFile("uhabits.db")
Expand All @@ -39,11 +42,14 @@ class Backend(var databaseOpener: DatabaseOpener,
}

fun getHabitList(): List<Map<String, *>> {
return habits.values.sortedBy { h -> h.position }.map { h ->
mapOf("key" to h.id.toString(),
"name" to h.name,
"color" to h.color.paletteIndex)
}
return habits.values
.filter { h -> !h.isArchived }
.sortedBy { h -> h.position }
.map { h ->
mapOf("key" to h.id.toString(),
"name" to h.name,
"color" to h.color.index)
}
}

fun createHabit(name: String) {
Expand All @@ -52,7 +58,7 @@ class Backend(var databaseOpener: DatabaseOpener,
name = name,
description = "",
frequency = Frequency(1, 1),
color = Color(3),
color = PaletteColor(3),
isArchived = false,
position = habits.size,
unit = "",
Expand Down
45 changes: 45 additions & 0 deletions core/src/commonMain/kotlin/org/isoron/uhabits/gui/Canvas.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2016-2019 Álinson Santos Xavier <[email protected]>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.isoron.uhabits.gui

enum class Font {
REGULAR,
BOLD,
FONT_AWESOME
}

interface Canvas {
fun setColor(color: Color)
fun drawLine(x1: Double, y1: Double, x2: Double, y2: Double)
fun drawText(text: String, x: Double, y: Double)
fun fillRect(x: Double, y: Double, width: Double, height: Double)
fun drawRect(x: Double, y: Double, width: Double, height: Double)
fun getHeight(): Double
fun getWidth(): Double
fun setFont(font: Font)
fun setTextSize(size: Double)
fun setStrokeWidth(size: Double)
fun fillArc(centerX: Double,
centerY: Double,
radius: Double,
startAngle: Double,
swipeAngle: Double)
fun fillCircle(centerX: Double, centerY: Double, radius: Double)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,13 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import {
NativeEventEmitter,
DeviceEventEmitter,
NativeModules,
Platform,
} from 'react-native';
package org.isoron.uhabits.gui

const { CoreModule } = NativeModules;
data class PaletteColor(val index: Int)

let emitter = DeviceEventEmitter;
if (Platform.OS === 'ios') {
emitter = new NativeEventEmitter(CoreModule);
class Color(val argb: Int) {
val alpha = 1.0
val red = ((argb shr 16) and 0xFF) / 255.0
val green = ((argb shr 8 ) and 0xFF) / 255.0
val blue = ((argb shr 0 ) and 0xFF) / 255.0
}

export const Emitter = emitter;
export const Backend = NativeModules.CoreModule;
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.isoron.uhabits.models
package org.isoron.uhabits.gui

class Timestamp(val unixTime: Long)
class FontAwesome {
companion object {
val CHECK = "\uf00c"
val TIMES = "\uf00d"
}
}
68 changes: 68 additions & 0 deletions core/src/commonMain/kotlin/org/isoron/uhabits/gui/Themes.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (C) 2016-2019 Álinson Santos Xavier <[email protected]>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.isoron.uhabits.gui

abstract class Theme {
val toolbarColor = Color(0xffffff)

val lowContrastTextColor = Color(0xe0e0e0)
val mediumContrastTextColor = Color(0x808080)
val highContrastTextColor = Color(0x202020)

val cardBackgroundColor = Color(0xFFFFFF)
val appBackgroundColor = Color(0xf4f4f4)
val toolbarBackgroundColor = Color(0xf4f4f4)
val statusBarBackgroundColor = Color(0x333333)

val headerBackgroundColor = Color(0xeeeeee)
val headerBorderColor = Color(0xcccccc)
val headerTextColor = mediumContrastTextColor

val itemBackgroundColor = Color(0xffffff)

fun color(paletteIndex: Int): Color {
return when (paletteIndex) {
0 -> Color(0xD32F2F)
1 -> Color(0x512DA8)
2 -> Color(0xF57C00)
3 -> Color(0xFF8F00)
4 -> Color(0xF9A825)
5 -> Color(0xAFB42B)
6 -> Color(0x7CB342)
7 -> Color(0x388E3C)
8 -> Color(0x00897B)
9 -> Color(0x00ACC1)
10 -> Color(0x039BE5)
11 -> Color(0x1976D2)
12 -> Color(0x303F9F)
13 -> Color(0x5E35B1)
14 -> Color(0x8E24AA)
15 -> Color(0xD81B60)
16 -> Color(0x5D4037)
else -> Color(0x000000)
}
}

val checkmarkButtonSize = 48.0
val smallTextSize = 12.0
val regularTextSize = 17.0
}

class LightTheme : Theme()
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2016-2019 Álinson Santos Xavier <[email protected]>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.isoron.uhabits.gui.components.HabitList

import org.isoron.uhabits.gui.*
import org.isoron.uhabits.gui.components.*

class CheckmarkButton(private val value: Int,
private val color: Color,
private val theme: Theme) : Component {
override fun draw(canvas: Canvas) {
canvas.setFont(Font.FONT_AWESOME)
canvas.setTextSize(theme.smallTextSize * 1.5)
canvas.setColor(when (value) {
2 -> color
else -> theme.lowContrastTextColor
})
val text = when (value) {
0 -> FontAwesome.TIMES
else -> FontAwesome.CHECK
}
canvas.drawText(text, canvas.getWidth() / 2.0, canvas.getHeight() / 2.0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.isoron.uhabits.models
package org.isoron.uhabits.gui.components

data class Color(val paletteIndex: Int)
import org.isoron.uhabits.gui.*

interface Component {
fun draw(canvas: Canvas)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2016-2019 Álinson Santos Xavier <[email protected]>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.isoron.uhabits.gui.components.HabitList

import org.isoron.uhabits.gui.*
import org.isoron.uhabits.gui.components.*
import org.isoron.uhabits.utils.*

class HabitListHeader(private val today: LocalDate,
private val nButtons: Int,
private val theme: Theme,
private val fmt: LocalDateFormatter,
private val calc: LocalDateCalculator) : Component {

override fun draw(canvas: Canvas) {
val width = canvas.getWidth()
val height = canvas.getHeight()
val buttonSize = theme.checkmarkButtonSize
canvas.setColor(theme.headerBackgroundColor)
canvas.fillRect(0.0, 0.0, width, height)

canvas.setColor(theme.headerBorderColor)
canvas.setStrokeWidth(0.5)
canvas.drawLine(0.0, height - 0.5, width, height - 0.5)

canvas.setColor(theme.headerTextColor)
canvas.setFont(Font.BOLD)
canvas.setTextSize(theme.smallTextSize)

repeat(nButtons) { index ->
val date = calc.minusDays(today, nButtons - index - 1)
val name = fmt.shortWeekdayName(date).toUpperCase()
val number = date.day.toString()

val x = width - (index + 1) * buttonSize + buttonSize / 2
val y = height / 2
canvas.drawText(name, x, y - theme.smallTextSize * 0.6)
canvas.drawText(number, x, y + theme.smallTextSize * 0.6)
}
}
}
Loading

0 comments on commit 8544c5d

Please sign in to comment.