Skip to content

Commit

Permalink
release: fix avatar, change toasts, add game info screen (#31)
Browse files Browse the repository at this point in the history
* fix: fix avatar, tap animation, remove download notif, show backend error msg

* fix: check internet connection

* fix: delete old models, display progress in map, change toasts

* feat: add game description dialog

* fix: change ar screen toast
  • Loading branch information
DonWick32 authored Sep 4, 2023
1 parent 1cc4459 commit 8510046
Show file tree
Hide file tree
Showing 20 changed files with 331 additions and 102 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
applicationId "edu.nitt.delta.orientation22"
minSdk 24
targetSdk 33
versionCode 7
versionName "1.0.0"
versionCode 8
versionName "1.0.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
22 changes: 12 additions & 10 deletions app/src/main/java/edu/nitt/delta/orientation22/ArActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ class ArActivity : ComponentActivity() {
mapStateViewModel.doAction(MapAction.GetCurrentLevel)

val glbUrl = intent.getStringExtra("glb")!!
val anchorHash = intent.getStringExtra("anchorHash")!!
val animatable = intent.getStringExtra("anchorHash")?:"false"
val scale = intent.getDoubleExtra("anchorScale", 0.5)
val currentLevel = intent.getIntExtra("level", 0)
Log.d("Resolve",anchorHash)
Log.d("Resolve",glbUrl)

val answer: String? = routeList.firstOrNull { it.position == currentLevel }?.answer
Expand All @@ -56,13 +55,12 @@ class ArActivity : ComponentActivity() {
followHitPosition = true,
instantAnchor = true
)

setUpEnvironment(currentLevel, scale)
setUpEnvironment(currentLevel, scale, animatable)
}, onClick = {
viewModel.doAction(ArAction.PostAnswer(currentLevel))
}, answer = answer ?: "",
onReset = {
Toast.makeText(this, "Reset", Toast.LENGTH_SHORT).show()
Toast.makeText(this, "AR Object has been reset.", Toast.LENGTH_SHORT).show()
viewModel.doAction(ArAction.ResetAnchor(cloudAnchorNode))
}, onBack = {
MainActivity.startDestination = NavigationRoutes.Map.route
Expand All @@ -75,22 +73,22 @@ class ArActivity : ComponentActivity() {
}
}

private fun setUpEnvironment( index: Int, scale: Double){
private fun setUpEnvironment(index: Int, scale: Double, animatable: String){
arSceneView.lightEstimationMode = LightEstimationMode.DISABLED
arSceneView.mainLight?.intensity = DEFAULT_LIGHT_INTENSITY
cloudAnchorNode.scale = Float3(scale.toFloat(), scale.toFloat(), scale.toFloat())

Log.d("Scale", scale.toFloat().toString())
Log.d("Resolve glb",index.toString())

Toast.makeText(applicationContext,"Scan the surroundings for flat surfaces.",Toast.LENGTH_SHORT).show()
Toast.makeText(applicationContext,"Scan the surroundings for flat surfaces.",Toast.LENGTH_LONG).show()

viewModel.doAction(
ArAction.LoadModel(
this,
lifecycle,
{ _, _ ->
tapModel()
tapModel(animatable)
},
arSceneView,
cloudAnchorNode,
Expand All @@ -99,7 +97,11 @@ class ArActivity : ComponentActivity() {
)
}

private fun tapModel(){
cloudAnchorNode.playAnimation(0,false)
private fun tapModel(animatable: String) {
try {
if (animatable == "true") {
cloudAnchorNode.playAnimation(0, false)
}
} catch (_: Exception){}
}
}
47 changes: 41 additions & 6 deletions app/src/main/java/edu/nitt/delta/orientation22/LiveActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,23 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.PressGestureScope
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.ClickableText
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Info
import androidx.compose.material3.Card
import androidx.compose.material3.FilledIconButton
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.input.pointer.pointerInput
Expand All @@ -38,10 +47,11 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.app.ActivityCompat
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import dagger.hilt.android.AndroidEntryPoint
import edu.nitt.delta.orientation22.compose.LoadingIcon
import edu.nitt.delta.orientation22.compose.getAnnotatedString
import edu.nitt.delta.orientation22.compose.screens.GameInfo
import edu.nitt.delta.orientation22.compose.toast
import edu.nitt.delta.orientation22.di.viewModel.actions.LoginAction
import edu.nitt.delta.orientation22.di.viewModel.actions.MapAction
import edu.nitt.delta.orientation22.di.viewModel.uiState.DownloadState
Expand All @@ -68,14 +78,15 @@ class LiveActivity : ComponentActivity() {
download = {
val routesData = mapStateViewModel.routeListData.value

Log.d("Download1", routesData.toString())
val urls = routesData.map { it.glbUrl }
Log.d("Download2", urls.toString())
Log.d("Download", urls.toString())
context.toast("Please wait ...")

loginStateViewModel.doAction(LoginAction.DownloadAssets(urls, context))
},
downloadState = loginStateViewModel.downloadState,
isDownloaded = loginStateViewModel.isAssetsDownloaded
isDownloaded = loginStateViewModel.isAssetsDownloaded,
error = loginStateViewModel.error,
)
}
}
Expand All @@ -87,7 +98,8 @@ fun LiveScreen(
isLive: Boolean,
download: PressGestureScope.(Offset) -> Unit,
downloadState: MutableState<DownloadState>,
isDownloaded: Boolean
isDownloaded: Boolean,
error: String?
) {

val configuration = LocalConfiguration.current
Expand All @@ -96,14 +108,15 @@ fun LiveScreen(
val annotatedString = LocalContext.current.getAnnotatedString(lightGreen)
val uriHandler = LocalUriHandler.current
val mContext = LocalContext.current
val showDialog = remember { mutableStateOf(false) }

val activity = mContext as Activity
ActivityCompat.requestPermissions(
activity, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), 23
)

if (downloadState.value == DownloadState.ERROR){
Toast.makeText(mContext, "Download failed. Check your network connection and try again.", Toast.LENGTH_SHORT).show()
Toast.makeText(mContext, error.toString(), Toast.LENGTH_SHORT).show()
downloadState.value = DownloadState.IDLE
}

Expand All @@ -119,6 +132,28 @@ fun LiveScreen(
.fillMaxWidth(),
contentScale = ContentScale.Crop
)

FilledIconButton(onClick = {
showDialog.value = true
},
modifier= Modifier.size(50.dp).offset(20.dp, 20.dp),
shape = CircleShape,
colors = IconButtonDefaults.iconButtonColors(containerColor = red)
) {
Icon(
Icons.Default.Info,
modifier = Modifier.scale(2f),
contentDescription = "Info Icon",
tint = black
)
}

if (showDialog.value){
GameInfo (
showDialog = showDialog.value,
onDismiss = { showDialog.value = false }
)
}
}
Column(

Expand Down
11 changes: 9 additions & 2 deletions app/src/main/java/edu/nitt/delta/orientation22/SplashActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import dagger.hilt.android.AndroidEntryPoint
import edu.nitt.delta.orientation22.compose.navigation.NavigationRoutes
import edu.nitt.delta.orientation22.compose.toast
import edu.nitt.delta.orientation22.di.viewModel.actions.LoginAction
import edu.nitt.delta.orientation22.di.viewModel.actions.MapAction
import edu.nitt.delta.orientation22.di.viewModel.uiState.LoginState
import edu.nitt.delta.orientation22.di.viewModel.uiState.LoginStateViewModel
import edu.nitt.delta.orientation22.di.viewModel.uiState.MapStateViewModel
import edu.nitt.delta.orientation22.ui.theme.Orientation22androidTheme
Expand All @@ -60,7 +62,6 @@ class SplashActivity : ComponentActivity() {
loginStateViewModel.doAction(LoginAction.IsLoggedIn)
loginStateViewModel.doAction(LoginAction.IsLive)
mapStateViewModel.doAction(MapAction.GetRoute)
loginStateViewModel.doAction(LoginAction.IsRegistered)
setContent {
Orientation22androidTheme {
// A surface container using the 'background' color from the theme
Expand Down Expand Up @@ -206,7 +207,13 @@ fun SetBackGround(
animationSpec = FloatTweenSpec(1000, 0, hesitateEasing)
)
if (loginStateViewModel.isLoggedIn) {
if (loginStateViewModel.isRegistered.value.isRegistered) {
loginStateViewModel.doAction(LoginAction.IsRegistered)
if (loginStateViewModel.uiState.value == LoginState.ERROR){
loginStateViewModel.uiState.value = LoginState.IDLE
mContext.toast("Connect to the internet and reload the app.")
val intent = Intent(mContext,LiveActivity::class.java)
mContext.startActivity(intent)
} else if (loginStateViewModel.isRegistered.value.isRegistered) {
val intent = Intent(mContext,LiveActivity::class.java)
mContext.startActivity(intent)
} else {
Expand Down
38 changes: 17 additions & 21 deletions app/src/main/java/edu/nitt/delta/orientation22/compose/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,6 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.app.ActivityCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.navigation.NavController
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.MultiplePermissionsState
import com.google.accompanist.permissions.PermissionState
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.maps.model.LatLng
import edu.nitt.delta.orientation22.ArActivity
import edu.nitt.delta.orientation22.compose.navigation.NavigationRoutes
import edu.nitt.delta.orientation22.ui.theme.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
Expand All @@ -61,18 +40,35 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog
import androidx.core.app.ActivityCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.navigation.NavController
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.MultiplePermissionsState
import com.google.accompanist.permissions.PermissionState
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.maps.model.LatLng
import edu.nitt.delta.orientation22.ArActivity
import edu.nitt.delta.orientation22.R
import edu.nitt.delta.orientation22.compose.navigation.NavigationRoutes
import edu.nitt.delta.orientation22.ui.theme.*
import kotlinx.coroutines.launch


fun Context.toast(message: CharSequence)
{
Toast.makeText(this,message,Toast.LENGTH_LONG).show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ fun ArScreen(
)
if (isPopUp.value) {
Dialog(onDismissRequest = { isPopUp.value = false }){
SubmitPopUp(isPopUp = isPopUp, onClick, answer = answer, isCorrect = isCorrect)
SubmitPopUp(isPopUp = isPopUp, onClick, answer = answer, isCorrect = isCorrect, onBack = onBack)
}
}
}

@Composable
fun SubmitPopUp(isPopUp : MutableState<Boolean>, onClick: () -> Unit, answer: String, isCorrect: MutableState<Boolean>) {
fun SubmitPopUp(isPopUp : MutableState<Boolean>, onClick: () -> Unit, answer: String, isCorrect: MutableState<Boolean>, onBack: () -> Unit) {
var text by remember { mutableStateOf("") }
val mContext = LocalContext.current
val screenHeight = LocalConfiguration.current.screenHeightDp
Expand Down Expand Up @@ -164,11 +164,12 @@ fun SubmitPopUp(isPopUp : MutableState<Boolean>, onClick: () -> Unit, answer: St
onClick = {
if (answer.equals(text, ignoreCase = true)){
isPopUp.value = false
mContext.toast("Congratulations!! You completed this level")
mContext.toast("Congratulations!! You've completed this level.")
if (!isCorrect.value){
onClick()
isCorrect.value = true
}
onBack()
}
else{
mContext.toast("Wrong code. Please check and try again!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ fun DAuthWebView(
appendQueryParameter("scope", "email+openid+profile+user")
appendQueryParameter("nonce", ClientCredentials.Nonce.param)
}.toString()
Log.v("url", url)
AndroidView(
modifier = Modifier.padding(paddingValues),
factory = {
Expand Down
Loading

0 comments on commit 8510046

Please sign in to comment.