Skip to content
This repository has been archived by the owner on Oct 18, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/0.3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
bvolkmer committed Oct 3, 2018
2 parents 1f881d2 + 143e8ab commit c85438e
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 54 deletions.
4 changes: 1 addition & 3 deletions android/src/main/java/de/x4fyr/paiman/app/ui/controller.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class OverviewControllerAndroidAdapter(private val webViewService: WebViewServic
override fun openPainting(id: String) = super.openPainting(id)

@JavascriptInterface
override fun addPainting(title: String?) = super.addPainting(title)
override fun addPainting(title: String?, month: String?, year: String?) = super.addPainting(title, month, year)

@JavascriptInterface
override fun selectImage() = super.selectImage()
Expand All @@ -63,6 +63,4 @@ class OverviewControllerAndroidAdapter(private val webViewService: WebViewServic
/** Adapter for [EntryController] to make functions available as javascript interface */
class EntryControllerAndroidAdapter(webViewService: WebViewService, mainViewController: OverviewController): EntryController(webViewService, mainViewController) {

@JavascriptInterface
override fun openNext() = super.openNext()
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ group 'de.de.x4fyr'

ext.major_version = 0
ext.minor_version = 3
ext.revision_number = 1
ext.revision_number = 2
version "$major_version.$minor_version.$revision_number"
println("version: $version")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ class MainServiceImpl(private var paintingCRUDAdapter: PaintingCRUDAdapter,
wip: Set<InputStream>,
reference: Set<InputStream>,
sellingInfo: SellingInformation?,
tags: Set<String>): SavedPainting {
tags: Set<String>,
date: LocalDate): SavedPainting {
val newPainting = UnsavedPainting(
title = title,
wip = setOf(),
references = setOf(),
sellingInfo = sellingInfo,
tags = tags, mainPicture = dummyPicture)
tags = tags, mainPicture = dummyPicture, finished = true, finishingDate = date)
val savedPainting = paintingCRUDAdapter.create(newPainting) ?: throw ServiceException(
"Could not create " +
"painting")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ interface PaintingService {
*/
@Throws(ServiceException::class)
suspend fun composeNewPainting(title: String,
mainPicture: InputStream,
wip: Set<InputStream> = setOf(),
reference: Set<InputStream> = setOf(),
sellingInfo: SellingInformation? = null,
tags: Set<String> = setOf()): SavedPainting
mainPicture: InputStream,
wip: Set<InputStream> = setOf(),
reference: Set<InputStream> = setOf(),
sellingInfo: SellingInformation? = null,
tags: Set<String> = setOf(),
date: LocalDate): SavedPainting

/** Change a SavedPainting determined by the given id and probably changed properties */
@Throws(ServiceException::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,7 @@ open class EntryController(private val webViewService: WebViewService,

override suspend fun loadView() {
webViewService.loadHtml(html, this)
}

/** Callback: Open next view
*
* unused because only used in ui via js
* open to allow adding annotations that be might be use on some platforms for javascript injection
*/
@Suppress("unused")
open fun openNext() {
println("Callback: openNext()")
launch(CommonPool) {
launch {
mainViewController.loadView()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import de.x4fyr.paiman.app.services.PictureSelectorService
import de.x4fyr.paiman.app.services.WebViewService
import de.x4fyr.paiman.app.ui.Controller
import de.x4fyr.paiman.app.ui.views.paintingDetail.PaintingDetailFactory
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.launch
import kotlinx.coroutines.experimental.*

/** Overview Controller */
open class OverviewController(private val webViewService: WebViewService,
Expand Down Expand Up @@ -42,19 +41,33 @@ open class OverviewController(private val webViewService: WebViewService,
}
}

open fun addPainting(title: String?) {
open fun addPainting(title: String?, month: String?, year: String?) {
println("Callback: addPainting($title)")
if (title.isNullOrBlank()) {
webViewService.showError("Title missing or invalid")
} else if (model.addPaintingModel.image == null) {
webViewService.showError("Image missing")
} else launch(CommonPool) {
model.addPaintingModel.title = title
val newId = model.saveNewPainting()
if (newId != null) {
paintingDetailFactory.createPaintingDetailController(newId, this@OverviewController).loadView()
} else {
println("Error: Tried to save unfinished painting")
} else if (month.isNullOrBlank()) {
webViewService.showError("Month invalid")
} else if (year.isNullOrBlank()) {
webViewService.showError("Year invalid")
} else {
val monthInt = month!!.toIntOrNull()
val yearInt = year!!.toIntOrNull()
if (monthInt == null || monthInt < 1 || monthInt > 12) {
webViewService.showError("Month invalid")
} else if (yearInt == null) {
webViewService.showError("Year invalid")
} else launch(CommonPool) {
model.addPaintingModel.title = title
model.addPaintingModel.month = monthInt
model.addPaintingModel.year = yearInt
val newId = model.saveNewPainting()
if (newId != null) {
paintingDetailFactory.createPaintingDetailController(newId, this@OverviewController).loadView()
} else {
println("Error: Tried to save unfinished painting")
}
}
}
}
Expand All @@ -64,7 +77,7 @@ open class OverviewController(private val webViewService: WebViewService,
launch(CommonPool) {
pictureSelectorService.pickPicture {
if (it != null) {
val jpegData = model.addPaintingModel.setImage(it)
val jpegData = model.addPaintingModel.setImage(it)
println("selected image")
webViewService.executeJS("addDialogSetPicture('$jpegData')")
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import de.x4fyr.paiman.lib.domain.SavedPainting
import de.x4fyr.paiman.lib.services.PaintingService
import de.x4fyr.paiman.lib.services.QueryService
import kotlinx.coroutines.experimental.*
import org.threeten.bp.LocalDate
import java.io.ByteArrayInputStream
import java.io.InputStream
import java.util.*
Expand Down Expand Up @@ -61,7 +62,7 @@ open class OverviewModel(private val paintingService: PaintingService,
var base64Image: String)

/** Holder for "add painting" dialog */
data class AddPaintingModel(var title: String? = null, var image: ByteArrayInputStream? = null, private val base64Encoder: Base64Encoder) {
data class AddPaintingModel(var title: String? = null, var month: Int? = null, var year: Int? = null, var image: ByteArrayInputStream? = null, private val base64Encoder: Base64Encoder) {

fun setImage(inputStream: InputStream): String {
val dataString: String
Expand All @@ -85,8 +86,10 @@ open class OverviewModel(private val paintingService: PaintingService,
internal suspend fun saveNewPainting(): String? {
val title = addPaintingModel.title
val image = addPaintingModel.image
return if (title != null && !title.isNullOrBlank() && image != null) {
paintingService.composeNewPainting(title, image).id
val month = addPaintingModel.month
val year = addPaintingModel.year
return if (title != null && !title.isNullOrBlank() && image != null && month != null && year != null) {
paintingService.composeNewPainting(title, image, date = LocalDate.of(year, month, 1 )).id
} else {
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,18 @@ open class PaintingDetailModel(private val paintingService: PaintingService, val
private data class Holder(
val title: String,
val mainImage: String,
val month: Int,
val year: Int,
val tags: Array<String>,
val wips: Array<String>,
val refs: Array<String>
)

private suspend fun createHolder(painting: Painting): Holder = Holder(painting.title,
base64Encoder.jpegDataString(paintingService.getPictureStream(painting.mainPicture)),
painting.tags.toTypedArray().sortedArrayDescending(), //Reversed order because items are prepended
wips.await().toTypedArray(),
refs.await().toTypedArray())
private suspend fun createHolder(painting: Painting): Holder = Holder(title = painting.title,
mainImage = base64Encoder.jpegDataString(paintingService.getPictureStream(painting.mainPicture)),
month = painting.finishingDate!!.monthValue,
year = painting.finishingDate!!.year,
tags = painting.tags.toTypedArray().sortedArrayDescending(), //Reversed order because items are prepended
wips = wips.await().toTypedArray(),
refs = refs.await().toTypedArray())
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

document.getElementById("title").textContent = painting.title;
document.getElementById("mainImage").src = painting.mainImage;
document.getElementById("finishingDate").textContent = painting.year + "-" + painting.month;

var tagsP = document.getElementById("tags");
tagsP.childNodes.forEach(function (value) {
Expand Down Expand Up @@ -158,6 +159,9 @@
<ons-row>
<img id="mainImage" style="max-width: 100%; width: auto; height: auto;"/>
</ons-row>
<ons-row>
<p id="finishingDate"></p>
</ons-row>
<ons-row>
<p id="tags">
<ons-button onClick="showDialog('addTagDialog')">
Expand Down
38 changes: 29 additions & 9 deletions ui/src/main/resources/assets/de/x4fyr/paiman/ui/html/overview.htm
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@

function addDialogAdd() {
var titleInput = document.getElementById("addDialogTitle");
if (titleInput) {
if (controller.addPainting(titleInput.value)) {
var monthInput = document.getElementById("addDialogMonth");
var yearInput = document.getElementById("addDialogYear");
if (titleInput && monthInput && yearInput) {
if (controller.addPainting(titleInput.value, monthInput.value, yearInput.value)) {
addDialogHide()
} else {
//TODO: Add error handling/hinting
Expand Down Expand Up @@ -122,21 +124,39 @@
<ons-dialog id="addDialog" cancelable>
<div class="paddedDialog">
<ons-row>
<h2>Add Painting</h2>
<ons-col>
<h2>Add Painting</h2>
</ons-col>
</ons-row>
<ons-row>
<ons-input id="addDialogTitle" modifiers="underbar" placeholder="Title" float></ons-input>
<ons-col>
<ons-input id="addDialogTitle" modifiers="underbar" placeholder="Title" float></ons-input>
</ons-col>
</ons-row>
<ons-row>
<ons-button onClick="controller.selectImage()" modifier="quiet">Set image</ons-button>
<ons-col>
<ons-input id="addDialogMonth" modifiers="underbar" type="number" placeholder="month" min="1"
max="12" value="1" float></ons-input>
</ons-col>
<ons-col>
<ons-input id="addDialogYear" modifiers="underbar" type="number" placeholder="year" min="1900"
max="2100" value="2018" float></ons-input>
</ons-col>
</ons-row>
<ons-row>
<img id="addDialogImage" style="max-width: 100%"/>
<ons-col>
<ons-button onClick="controller.selectImage()" modifier="quiet">Set image</ons-button>
</ons-col>
</ons-row>
<ons-row>
<ons-button id="addDialogAdd" onClick="addDialogAdd()">
Add
</ons-button>
<ons-col>
<img id="addDialogImage" style="max-width: 100%"/>
</ons-col>
</ons-row>
<ons-row>
<ons-col>
<ons-button id="addDialogAdd" onClick="addDialogAdd()">Add</ons-button>
</ons-col>
</ons-row>
</div>
</ons-dialog>
Expand Down
5 changes: 1 addition & 4 deletions ui/src/main/resources/assets/de/x4fyr/paiman/ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@
<ons-page>
<ons-toolbar>
<div class="center">
PaiMan
Paiman
</div>
</ons-toolbar>
<h1>Loading</h1>
<ons-progress-circular indetminate> </ons-progress-circular>
<ons-button onClick="controller.openNext()">
Next
</ons-button>
</ons-page>

</body>
Expand Down

0 comments on commit c85438e

Please sign in to comment.