Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
meikpiep committed Dec 31, 2024
1 parent 16ca516 commit a9bfe2d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ import com.journeyapps.barcodescanner.ScanContract
import com.journeyapps.barcodescanner.ScanOptions
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.coroutines.launch
import kotlinx.serialization.json.Json
import org.koin.android.ext.android.inject
import org.piepmeyer.gauguin.R
import org.piepmeyer.gauguin.databinding.ActivityMainBinding
import org.piepmeyer.gauguin.game.Game
import org.piepmeyer.gauguin.game.GameLifecycle
import org.piepmeyer.gauguin.game.save.SavedGrid
import org.piepmeyer.gauguin.options.NumeralSystem
import org.piepmeyer.gauguin.preferences.ApplicationPreferences
import org.piepmeyer.gauguin.ui.ActivityUtils
import org.piepmeyer.gauguin.ui.MainDialogs
import org.piepmeyer.gauguin.ui.newgame.NewGameActivity
import java.io.ByteArrayInputStream
import java.util.zip.GZIPInputStream

private val logger = KotlinLogging.logger {}

Expand Down Expand Up @@ -66,6 +70,16 @@ class MainActivity : AppCompatActivity() {
"Scanned: " + it.contents,
Toast.LENGTH_LONG,
).show()

val content =
GZIPInputStream(ByteArrayInputStream(it.rawBytes))
.bufferedReader()
.use { it.readText() }

println(content.length)
val savedGrid = Json.decodeFromString<SavedGrid>(content)

gameLifecycle.startNewGame(savedGrid.toGrid())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ class MainNavigationViewService(
scanOptions.setOrientationLocked(false)
scanOptions.setBarcodeImageEnabled(false)
scanOptions.setPrompt("Test")
scanOptions

mainActivity.barcodeLauncher.launch(scanOptions)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ class ShareGameActivity : AppCompatActivity() {
println("${serializedGrid.length}")

val bos = ByteArrayOutputStream()
GZIPOutputStream(bos).bufferedWriter(Charsets.UTF_8).use { it.write(serializedGrid) }
GZIPOutputStream(bos).bufferedWriter().use { it.write(serializedGrid) }

val compressedGrid = String(bos.toByteArray())

println("${compressedGrid.length}")

try {
val barcodeEncoder = BarcodeEncoder()
val bitmap = barcodeEncoder.encodeBitmap(compressedGrid, BarcodeFormat.QR_CODE, 400, 400)
val bitmap = barcodeEncoder.encodeBitmap(compressedGrid, BarcodeFormat.QR_CODE, 800, 800)
binding.qrCode.setImageBitmap(bitmap)
} catch (e: Exception) {
}
Expand Down
1 change: 0 additions & 1 deletion gauguin-app/src/main/res/layout/activity_sharegame.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
android:id="@+id/qrCode"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="64dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
Expand Down

0 comments on commit a9bfe2d

Please sign in to comment.