Skip to content

Commit

Permalink
Fix formatting and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Feb 9, 2024
1 parent e8e302e commit 0fb805a
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package net.mullvad.mullvadvpn.lib.map

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.*
import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
Expand All @@ -21,4 +19,4 @@ class ExampleInstrumentedTest {
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("net.mullvad.mullvadvpn.lib.map.test", appContext.packageName)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
package net.mullvad.mullvadvpn.lib.map

import android.util.Log
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.EaseInOut
import androidx.compose.animation.core.keyframes
import androidx.compose.animation.core.tween
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.viewinterop.AndroidView
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import kotlinx.coroutines.launch
import net.mullvad.mullvadvpn.lib.map.data.CameraPosition
import net.mullvad.mullvadvpn.lib.map.data.MapConfig
import net.mullvad.mullvadvpn.lib.map.data.MapViewState
import net.mullvad.mullvadvpn.lib.map.data.Marker
import net.mullvad.mullvadvpn.lib.map.data.MarkerType
import net.mullvad.mullvadvpn.lib.map.internal.MapGLSurfaceView
import net.mullvad.mullvadvpn.model.LatLng
import net.mullvad.mullvadvpn.model.Latitude
import net.mullvad.mullvadvpn.model.Longitude

@Composable
fun Map(
Expand All @@ -42,7 +34,6 @@ fun Map(
Map(modifier = modifier, mapViewState = mapViewState)
}


@Composable
internal fun Map(modifier: Modifier = Modifier, mapViewState: MapViewState) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ data class GlobeColors(
val landColorArray = landColor.toFloatArray()
val oceanColorArray = oceanColor.toFloatArray()
val contourColorArray = contourColor.toFloatArray()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ data class LocationMarkerColors(
val ringBorderColor: Color = Color.White,
val shadowColor: Color = Color.Black.copy(alpha = 0.55f),
val perimeterColors: Color = centerColor.copy(alpha = 0.4f)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ data class MapConfig(
LocationMarkerColors(centerColor = Color(0.267f, 0.678f, 0.302f)),
val unsecureMarkerColor: LocationMarkerColors =
LocationMarkerColors(centerColor = Color(0.89f, 0.251f, 0.224f))
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ package net.mullvad.mullvadvpn.lib.map.data

import net.mullvad.mullvadvpn.model.LatLng

class MapViewState(
val locationMarker: Marker?,
val cameraPosition: CameraPosition
)
class MapViewState(val locationMarker: Marker?, val cameraPosition: CameraPosition)

data class CameraPosition(
val latLng: LatLng,
val zoom: Float,
val bias: Float
)
data class CameraPosition(val latLng: LatLng, val zoom: Float, val bias: Float)
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,14 @@ internal fun initIndexBuffer(dataBuffer: Buffer): IndexBufferWithLength {
dataBuffer,
GLES20.GL_STATIC_DRAW
)
return IndexBufferWithLength(indexBuffer = buffer[0], length = dataBuffer.capacity() / Float.SIZE_BYTES)
return IndexBufferWithLength(
indexBuffer = buffer[0],
length = dataBuffer.capacity() / Float.SIZE_BYTES
)
}

internal fun newIdentityMatrix(): FloatArray = FloatArray(MATRIX_SIZE).apply { Matrix.setIdentityM(this, 0) }
internal fun newIdentityMatrix(): FloatArray =
FloatArray(MATRIX_SIZE).apply { Matrix.setIdentityM(this, 0) }

internal fun Color.toFloatArray(): FloatArray {
return floatArrayOf(red, green, blue, alpha)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package net.mullvad.mullvadvpn.lib.map.internal

internal class IndexBufferWithLength(val indexBuffer: Int, val length: Int)
internal class IndexBufferWithLength(val indexBuffer: Int, val length: Int)
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ internal class MapGLSurfaceView(context: Context, mapConfig: MapConfig) : GLSurf
requestRender()
}
}

Original file line number Diff line number Diff line change
@@ -1,14 +1 @@
package net.mullvad.mullvadvpn.lib.map.internal

import android.util.Log
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.viewinterop.AndroidView
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import net.mullvad.mullvadvpn.lib.map.data.MapConfig
import net.mullvad.mullvadvpn.lib.map.data.MapViewState

Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package net.mullvad.mullvadvpn.lib.map.internal.shapes
import android.content.res.Resources
import android.opengl.GLES20
import android.opengl.Matrix
import java.nio.ByteBuffer
import net.mullvad.mullvadvpn.lib.map.R
import net.mullvad.mullvadvpn.lib.map.data.GlobeColors
import net.mullvad.mullvadvpn.lib.map.internal.IndexBufferWithLength
import net.mullvad.mullvadvpn.lib.map.internal.VERTEX_COMPONENT_SIZE
import net.mullvad.mullvadvpn.lib.map.internal.initArrayBuffer
import net.mullvad.mullvadvpn.lib.map.internal.initIndexBuffer
import net.mullvad.mullvadvpn.lib.map.internal.initShaderProgram
import java.nio.ByteBuffer

class Globe(resources: Resources) {
private val vertexShaderCode =
Expand Down Expand Up @@ -42,7 +42,12 @@ class Globe(resources: Resources) {
private val uniformLocation: UniformLocation

private data class AttribLocations(val vertexPosition: Int)
private data class UniformLocation(val color: Int, val projectionMatrix: Int, val modelViewMatrix: Int)

private data class UniformLocation(
val color: Int,
val projectionMatrix: Int,
val modelViewMatrix: Int
)

private val landIndices: IndexBufferWithLength
private val landContour: IndexBufferWithLength
Expand All @@ -57,8 +62,7 @@ class Globe(resources: Resources) {
val landVertByteBuffer = ByteBuffer.wrap(landVertByteArray)
landVertexBuffer = initArrayBuffer(landVertByteBuffer)

val landTriangleIndicesStream =
resources.openRawResource(R.raw.land_triangle_indices)
val landTriangleIndicesStream = resources.openRawResource(R.raw.land_triangle_indices)
val landTriangleIndicesByteArray = landTriangleIndicesStream.use { it.readBytes() }
val landTriangleIndicesBuffer = ByteBuffer.wrap(landTriangleIndicesByteArray)
landIndices = initIndexBuffer(landTriangleIndicesBuffer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package net.mullvad.mullvadvpn.lib.map.internal.shapes
import android.opengl.GLES20
import android.opengl.Matrix
import androidx.compose.ui.graphics.Color
import java.nio.FloatBuffer
import kotlin.math.cos
import kotlin.math.sin
import net.mullvad.mullvadvpn.lib.map.data.LocationMarkerColors
import net.mullvad.mullvadvpn.lib.map.internal.COLOR_COMPONENT_SIZE
import net.mullvad.mullvadvpn.lib.map.internal.VERTEX_COMPONENT_SIZE
import net.mullvad.mullvadvpn.lib.map.internal.initArrayBuffer
import net.mullvad.mullvadvpn.lib.map.internal.initShaderProgram
import net.mullvad.mullvadvpn.lib.map.internal.toFloatArray
import net.mullvad.mullvadvpn.model.LatLng
import java.nio.FloatBuffer
import kotlin.math.cos
import kotlin.math.sin

internal class LocationMarker(val colors: LocationMarkerColors) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ data class LatLng(val latitude: Latitude, val longitude: Longitude) {
LatLng(latitude - other.latitude, longitude - other.longitude)
}


const val COMPLETE_ANGLE = 360f
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ value class Latitude(val value: Float) {
private const val MAX_LATITUDE_VALUE: Float = COMPLETE_ANGLE / 4 // 90
private val LATITUDE_RANGE = MIN_LATITUDE_VALUE..MAX_LATITUDE_VALUE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ value class Longitude(val value: Float) {
}
}
}
}
}

0 comments on commit 0fb805a

Please sign in to comment.