Skip to content

Commit

Permalink
#17 in progress - various changes required for Play release
Browse files Browse the repository at this point in the history
  • Loading branch information
mjureczko committed Sep 7, 2024
1 parent 614796b commit 4ef03e3
Show file tree
Hide file tree
Showing 23 changed files with 178 additions and 197 deletions.
15 changes: 10 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ plugins {
}

android {
compileSdkVersion 33
compileSdkVersion 34
defaultConfig {
applicationId "pl.marianjureczko.poszukiwacz"
minSdkVersion 23
targetSdkVersion 33
versionCode 1
versionName "1.0"
targetSdkVersion 34
versionCode 3
versionName "0.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
manifestPlaceholders = [facebookToken: FACEBOOK_TOKEN]
}
Expand All @@ -32,7 +32,7 @@ android {
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
resValue "string", "main_ad", "ca-app-pub-6283649742373707/7715917886"
resValue "string", "searching_ad", "ca-app-pub-6283649742373707/9491764484"
Expand Down Expand Up @@ -136,6 +136,11 @@ dependencies {
implementation 'org.apache.commons:commons-math3:3.6.1'
implementation 'com.google.android.gms:play-services-location:21.1.0'

// required for minifyEnabled true
implementation "org.conscrypt:conscrypt-android:2.5.2"
implementation "org.bouncycastle:bcpkix-jdk15to18:1.70"
implementation "org.openjsse:openjsse:1.1.7"

testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.8.2'
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.8.2'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.8.2'
Expand Down
2 changes: 2 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

-verbose
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ReportFooterTest : ReportAbstractTest() {
canvas.drawColor(Color.WHITE)

//when
footer.draw(canvas, 0f)
footer.draw(context.resources, canvas, 0f)

//then
//save to hava a reference in case of failing test
Expand Down
2 changes: 1 addition & 1 deletion app/src/custom/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<string name="custom_lead3">W trakcie zabawy należy odszukać ukryte skarby reprezentowane przez kody QR. Będą przypominać ten widoczny poniżej:</string>
<string name="custom_lead4">Aby poznać kryjące się za kodem QR tajemnice należy go zeskanować naciskając na:</string>
<string name="custom_lead5">Gra będzie nam pomagać podając ile kroków w linii prostej pozostało do skarbu oraz wskazując czy trzeba pójść na północ, południe, wschód czy zachód. Kierunki trzeba jednak odnaleźć samodzielnie. Nie przejmuj się tym gdyż pod tymi przyciskami będziesz mógł znaleźć podpowiedzi:</string>
<string name="custom_lead6">Do odnalezienia jest kilka skarbów. Ten aktualnie poszukiway można zmienić przyciskiem:</string>
<string name="custom_lead6">Do odnalezienia jest kilka skarbów. Ten aktualnie poszukiwany można zmienić przyciskiem:</string>

</resources>
Binary file modified app/src/kalinowice/assets/kalinowice_04.mp4
Binary file not shown.
21 changes: 2 additions & 19 deletions app/src/main/java/pl/marianjureczko/poszukiwacz/App.kt
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
package pl.marianjureczko.poszukiwacz

import android.app.Application
import android.content.Context
import android.content.res.Resources
import dagger.hilt.android.HiltAndroidApp
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors

@HiltAndroidApp
class App : Application() {

// TODO Why not use LocalContext.current instead? Decide once code covered with tests
init { App.app = this }

companion object {
//TODO: debug (sending route over Bluetotth when more than one device is paired) with pool of size 1
val executorService: ExecutorService = Executors.newFixedThreadPool(3)
private lateinit var res: Resources
private lateinit var app: App
fun getAppContext(): Context = app.applicationContext
fun getResources() = res
}

override fun onCreate() {
super.onCreate()
res = super.getResources();
// //TODO: debug (sending route over Bluetotth when more than one device is paired) with pool of size 1
// val executorService: ExecutorService = Executors.newFixedThreadPool(3)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavController
import pl.marianjureczko.poszukiwacz.App
import pl.marianjureczko.poszukiwacz.R
import pl.marianjureczko.poszukiwacz.activity.searching.n.CommemorativeSharedState
import pl.marianjureczko.poszukiwacz.activity.searching.n.CommemorativeSharedViewModel
Expand Down Expand Up @@ -130,16 +130,17 @@ private fun DoPhotoButton(
) {
val successMsg = stringResource(R.string.photo_replaced)
val failureMsg = stringResource(R.string.photo_not_replaced)
val context = LocalContext.current
val cameraLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.TakePicture(),
onResult = { success ->
if (success) {
Toast.makeText(App.getAppContext(), successMsg, Toast.LENGTH_SHORT).show()
Toast.makeText(context, successMsg, Toast.LENGTH_SHORT).show()
sharedViewModel.handleDoCommemorativePhotoResult(
sharedState.route.treasures.find { it.id == localState.treasureDesId }!!
)()
} else {
Toast.makeText(App.getAppContext(), failureMsg, Toast.LENGTH_SHORT).show()
Toast.makeText(context, failureMsg, Toast.LENGTH_SHORT).show()
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.navigation.NavHostController
import pl.marianjureczko.poszukiwacz.App
import pl.marianjureczko.poszukiwacz.R
import pl.marianjureczko.poszukiwacz.activity.main.FACEBOOK_PATH

Expand All @@ -21,7 +20,7 @@ object FacebookHelper {
if (isFacebookInstalled(context)) {
navController.navigate(FACEBOOK_PATH)
} else {
Toast.makeText(App.getAppContext(), noFacebookErrorMsg, Toast.LENGTH_LONG).show()
Toast.makeText(context, noFacebookErrorMsg, Toast.LENGTH_LONG).show()
}
}
return goToFacebook
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package pl.marianjureczko.poszukiwacz.activity.facebook.n

import android.content.res.Resources
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import pl.marianjureczko.poszukiwacz.App

class IconHelper() {

Expand All @@ -12,8 +12,8 @@ class IconHelper() {
* Is intended to scale down, for scaling up more computation costly interpolation should be used (filter parameter).
* @param desiredHeight in pixels
*/
fun loadIcon(resource: Int, desiredHeight: Int): Bitmap {
val rawIcon: Bitmap = BitmapFactory.decodeResource(App.getResources(), resource)
fun loadIcon(resources: Resources, resource: Int, desiredHeight: Int): Bitmap {
val rawIcon: Bitmap = BitmapFactory.decodeResource(resources, resource)
val desiredScale = desiredHeight.toFloat() / rawIcon.height.toFloat()
val desiredWidth = desiredScale * rawIcon.width.toFloat()
return Bitmap.createScaledBitmap(rawIcon, desiredWidth.toInt(), desiredHeight, false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package pl.marianjureczko.poszukiwacz.activity.facebook.n

import android.content.res.Resources
import android.graphics.Canvas
import android.graphics.Paint
import pl.marianjureczko.poszukiwacz.R

class ReportFooter() : ReportPart {
override fun height(): Float = 100.0f

fun draw(canvas: Canvas, currentTop: Float) {
val footerImg = IconHelper.loadIcon(R.drawable.facebook_report_footer, 41)
fun draw(resources: Resources, canvas: Canvas, currentTop: Float) {
val footerImg = IconHelper.loadIcon(resources, R.drawable.facebook_report_footer, 41)
val x = (ReportCommons.REPORT_WIDTH.toFloat() - footerImg.width) / 2
canvas.drawBitmap(footerImg, x, currentTop + 50f, Paint())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pl.marianjureczko.poszukiwacz.activity.facebook.n

import android.content.Context
import android.content.res.Resources
import android.graphics.Bitmap
import android.graphics.Canvas
import androidx.core.content.res.ResourcesCompat
Expand Down Expand Up @@ -44,7 +45,7 @@ class ReportGenerator {
val bitmap = Bitmap.createBitmap(ReportCommons.REPORT_WIDTH, height.toInt(), Bitmap.Config.ARGB_8888)

val canvas = Canvas(bitmap)
createBackground(canvas, height)
createBackground(context.resources, canvas, height)

var currentTop = 0f
title.draw(context, canvas)
Expand All @@ -65,19 +66,19 @@ class ReportGenerator {
mapSummary.draw(context, canvas, currentTop)
currentTop += mapSummary.height()

footer.draw(canvas, currentTop)
footer.draw(context.resources, canvas, currentTop)

return bitmap
}

private fun createBackground(canvas: Canvas, height: Float) {
private fun createBackground(resources: Resources, canvas: Canvas, height: Float) {
val backgroundHeight = 1127
val background = IconHelper.loadIcon(R.drawable.background, backgroundHeight)
val background = IconHelper.loadIcon(resources, R.drawable.background, backgroundHeight)
canvas.drawBitmap(background, 0f, 0f, null)
if (height > backgroundHeight) {
val partHeight = 138
val background1 = IconHelper.loadIcon(R.drawable.background_1, partHeight)
val background2 = IconHelper.loadIcon(R.drawable.background_2, partHeight)
val background1 = IconHelper.loadIcon(resources, R.drawable.background_1, partHeight)
val background2 = IconHelper.loadIcon(resources, R.drawable.background_2, partHeight)
val parts = mutableListOf(background1, background2)
var currentY = backgroundHeight.toFloat()
while (currentY < height) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pl.marianjureczko.poszukiwacz.activity.facebook.n

import android.content.Context
import android.content.res.Resources
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Color
Expand Down Expand Up @@ -45,7 +46,7 @@ class ReportMap(
snapshotter.start { snapshot ->
snapshot?.bitmap()?.let { bitmap ->
val mapCanvas = Canvas(bitmap)
drawChests(model.route, snapshot, model.progress, mapCanvas)
drawChests(context.resources, model.route, snapshot, model.progress, mapCanvas)
if (showRouteSelected()) {
drawRoute(snapshot, mapCanvas)
}
Expand Down Expand Up @@ -113,9 +114,9 @@ class ReportMap(
return snapshotter
}

private fun drawChests(route: Route, snapshot: MapSnapshotInterface, progress: TreasuresProgress, canvas: Canvas) {
val closedChest = IconHelper.loadIcon(R.drawable.chest_closed_small, 41)
val openedChest = IconHelper.loadIcon(R.drawable.chest_very_small, 41)
private fun drawChests(resources: Resources, route: Route, snapshot: MapSnapshotInterface, progress: TreasuresProgress, canvas: Canvas) {
val closedChest = IconHelper.loadIcon(resources, R.drawable.chest_closed_small, 41)
val openedChest = IconHelper.loadIcon(resources, R.drawable.chest_very_small, 41)
route.treasures.forEach { t ->
val xy = snapshot.screenCoordinate(Point.fromLngLat(t.longitude, t.latitude))
val chestToDraw = if (progress.collectedTreasuresDescriptionId.contains(t.id)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ class ReportSummary(
val textY = currentTop + 50
var x = ReportCommons.REPORT_MARGIN
canvas.drawText(summaryText, x, textY, textPaint)
val gold = IconHelper.loadIcon(R.drawable.gold, 40)
val gold = IconHelper.loadIcon(context.resources, R.drawable.gold, 40)
x += summarySize
canvas.drawBitmap(gold, x, currentTop + 20, null)

val diamonds = "${model.progress.diamonds}"
val diamondsSize = textPaint.measureText(diamonds)
x += gold.width + 20
canvas.drawText(diamonds, x, textY, textPaint)
val diamond = IconHelper.loadIcon(R.drawable.diamond, 50)
val diamond = IconHelper.loadIcon(context.resources, R.drawable.diamond, 50)
x += diamondsSize
canvas.drawBitmap(diamond, x, currentTop + 10, null)

val rubies = "${model.progress.rubies}"
val rubiesSize = textPaint.measureText(rubies)
x += diamond.width + 20
canvas.drawText(rubies, x, textY, textPaint)
val ruby = IconHelper.loadIcon(R.drawable.ruby, 50)
val ruby = IconHelper.loadIcon(context.resources, R.drawable.ruby, 50)
x += rubiesSize
canvas.drawBitmap(ruby, x, currentTop + 10, null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.viewinterop.AndroidView
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavController
import com.mapbox.bindgen.Value
import com.mapbox.maps.MapView
import com.mapbox.maps.Style
import pl.marianjureczko.poszukiwacz.App
import pl.marianjureczko.poszukiwacz.R
import pl.marianjureczko.poszukiwacz.model.Route
import pl.marianjureczko.poszukiwacz.shared.GoToFacebook
Expand Down Expand Up @@ -44,9 +44,10 @@ fun MapScreenBody() {

@Composable
fun MapboxMap(route: Route) {
val mapView = MapView(App.getAppContext())
val context = LocalContext.current
val mapView = MapView(context)

MapHelper.renderTreasures(route, mapView)
MapHelper.renderTreasures(context, route, mapView)
mapView.getMapboxMap().loadStyleUri(Style.MAPBOX_STREETS) { style -> hideRoads(style) }

AndroidView({ mapView }, Modifier.fillMaxSize())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ class MapViewModel @Inject constructor(
}

private fun loadRoute(routeName: String): Route {
// return Route(
// "Kalinowice", mutableListOf(
// TreasureDescription(
// 1, 25.1, 26.1, "g01abc", null, null
// )
// )
// )
return storageHelper.loadRoute(routeName)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package pl.marianjureczko.poszukiwacz.shared

import android.content.Context
import android.content.res.Resources
import android.graphics.BitmapFactory
import com.mapbox.geojson.Point
import com.mapbox.maps.CameraOptions
Expand All @@ -15,7 +17,6 @@ import com.mapbox.maps.plugin.annotation.generated.PointAnnotationOptions
import com.mapbox.maps.plugin.annotation.generated.createPointAnnotationManager
import com.mapbox.maps.viewannotation.ViewAnnotationManager
import com.mapbox.maps.viewannotation.viewAnnotationOptions
import pl.marianjureczko.poszukiwacz.App
import pl.marianjureczko.poszukiwacz.R
import pl.marianjureczko.poszukiwacz.databinding.TreasureOnMapViewBinding
import pl.marianjureczko.poszukiwacz.model.Route
Expand All @@ -25,8 +26,8 @@ class MapHelper {

private val TAG = javaClass.simpleName

private class TreasureOnMapHelper(mapView: MapView) {
private val iconBitmap = BitmapFactory.decodeResource(App.getResources(), R.drawable.chest_closed_small)
private class TreasureOnMapHelper(resources: Resources, mapView: MapView) {
private val iconBitmap = BitmapFactory.decodeResource(resources, R.drawable.chest_closed_small)
private val pointAnnotationManager = mapView.annotations.createPointAnnotationManager()
private val viewAnnotationManager = mapView.viewAnnotationManager

Expand All @@ -43,24 +44,19 @@ class MapHelper {
}

companion object {
fun renderTreasures(route: Route, mapView: MapView) {
fun renderTreasures(context: Context, route: Route, mapView: MapView) {
mapView.getMapboxMap().loadStyleUri(Style.OUTDOORS)
val cameraPosition = CameraOptions.Builder()
.center(LocationHelper(route).center())
.build()
mapView.getMapboxMap().setCamera(cameraPosition)

val treasureOnMapHelper = TreasureOnMapHelper(mapView)
val treasureOnMapHelper = TreasureOnMapHelper(context.resources, mapView)
route.treasures.forEach {
treasureOnMapHelper.addTreasure(it)
}
}

fun addTreasureToMap(treasure: TreasureDescription, mapView: MapView) {
val treasureOnMapHelper = TreasureOnMapHelper(mapView)
treasureOnMapHelper.addTreasure(treasure)
}

fun positionMapOnTreasures(route: Route, mapView: MapView, tightness: Double) {
val mapboxMap: MapboxMap = mapView.getMapboxMap()
val locationHelper = LocationHelper(route)
Expand Down
Loading

0 comments on commit 4ef03e3

Please sign in to comment.