Skip to content

Commit

Permalink
added splash screen
Browse files Browse the repository at this point in the history
  • Loading branch information
vens8 committed Feb 16, 2024
1 parent 00ba4d5 commit f693888
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 17 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Assignment1/JourneyTrack/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ dependencies {
implementation("androidx.compose.material:material:1.6.1")
implementation("androidx.compose.ui:ui-tooling:1.6.1")
implementation("androidx.compose.ui:ui-android:1.6.1")
implementation("com.github.bumptech.glide:glide:4.16.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
Expand Down
7 changes: 5 additions & 2 deletions Assignment1/JourneyTrack/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
android:theme="@style/Theme.JourneyTrack"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:name=".SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:exported="true">
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,18 @@ class MainActivity : AppCompatActivity() {
Stop("SARITA VIHAR", 5.1),
Stop("MOHAN ESTATE", 3.9),
Stop("TUGHLAKABAD STATION", 2.8),
Stop("BADARPUR BORDER", 1.6)
Stop("BADARPUR BORDER", 1.6),
Stop("SARAI", 2.1),
Stop("NHPC CHOWK", 3.5),
Stop("MEWALA MAHARAJAPUR", 6.7),
Stop("SECTOR-28", 4.2),
Stop("BADKAL MOR", 5.6),
Stop("OLD FARIDABAD", 2.9),
Stop("NEELAM CHOWK AJRONDA", 1.7),
Stop("BATA CHOWK", 3.3),
Stop("ESCORTS MUJESAR", 2.2),
Stop("SANT SURDAS", 6.1),
Stop("RAJA NAHAR SINGH", 4.4)
)
private var currentStop by mutableIntStateOf(0)
private var useLazyStops by mutableStateOf(false)
Expand All @@ -126,28 +137,31 @@ class MainActivity : AppCompatActivity() {

switchLists.setOnCheckedChangeListener { _, isChecked ->
currentStop = 0
progressState = 0f
useLazyStops = isChecked
updateProgressBar(if (useLazyStops) lazyStops.size else normalStops.size)
switchLists.text = if (useLazyStops) "Lazy Stops" else "Normal Stops"
displayStops()
}

btnNextStop.setOnClickListener {
val stops = if (useLazyStops) lazyStops else normalStops
if (currentStop < stops.size) {
Log.d("currentStop", "$currentStop")
Log.d("stops.size", "${stops.size}")
if (currentStop < stops.size - 1) {
currentStop++
updateProgressBar(stops.size)
displayStops()
if (currentStop == stops.size) {
if (currentStop == stops.size - 1) {
showToast("Yay! You have reached the final stop :)")
}
} else {
// Display a message when the user tries to click "Next Stop" after reaching the final stop
showToast("You are already at the final stop!")
showToast("You are already at the final stop! Reset by toggling stop lists.")
}
}

displayStops()
updateProgressBar(if (useLazyStops) lazyStops.size else normalStops.size)

val logoView = findViewById<ComposeView>(R.id.logo_view)
logoView.setContent {
Expand Down Expand Up @@ -179,8 +193,12 @@ class MainActivity : AppCompatActivity() {

@Composable
fun StopsList(stops: List<Stop>, isMiles: Boolean) {
var totalDistanceCovered = 0.0
var totalDistanceRemaining = 0.0
var totalDistanceCovered = calculateTotalDistanceCovered(stops, currentStop, isMiles)
var totalDistanceRemaining = calculateTotalDistanceRemaining(stops, currentStop, isMiles)
val unit = if (isMiles) "miles" else "km"
tvTotalDistanceCovered.text = "Total Distance Covered: ${totalDistanceCovered.round(2)} $unit"
tvTotalDistanceRemaining.text = "Total Distance Remaining: ${totalDistanceRemaining.round(2)} $unit"

val scrollState = rememberScrollState()

Box(
Expand All @@ -200,7 +218,6 @@ class MainActivity : AppCompatActivity() {
StopCard(stop, isMiles, isCurrentStop)
Divider(color = Color.LightGray, thickness = 0.5.dp)
// Update text views
val unit = if (isMiles) "miles" else "km"
tvTotalDistanceCovered.text = "Total Distance Covered: ${totalDistanceCovered.round(2)} $unit"
tvTotalDistanceRemaining.text = "Total Distance Remaining: ${totalDistanceRemaining.round(2)} $unit"
}
Expand All @@ -216,8 +233,12 @@ class MainActivity : AppCompatActivity() {

@Composable
fun LazyStopsList(stops: List<Stop>, isMiles: Boolean) {
var totalDistanceCovered = 0.0
var totalDistanceRemaining = 0.0
var totalDistanceCovered = calculateTotalDistanceCovered(stops, currentStop, isMiles)
var totalDistanceRemaining = calculateTotalDistanceRemaining(stops, currentStop, isMiles)
val unit = if (isMiles) "miles" else "km"
tvTotalDistanceCovered.text = "Total Distance Covered: ${totalDistanceCovered.round(2)} $unit"
tvTotalDistanceRemaining.text = "Total Distance Remaining: ${totalDistanceRemaining.round(2)} $unit"

val listState = rememberLazyListState()

LazyColumn(state = listState) {
Expand All @@ -231,7 +252,6 @@ class MainActivity : AppCompatActivity() {
StopCard(stop, isMiles, isCurrentStop)
Divider(color = Color.LightGray, thickness = 0.5.dp)
// Update text views
val unit = if (isMiles) "miles" else "km"
tvTotalDistanceCovered.text = "Total Distance Covered: ${totalDistanceCovered.round(2)} $unit"
tvTotalDistanceRemaining.text = "Total Distance Remaining: ${totalDistanceRemaining.round(2)} $unit"
}
Expand Down Expand Up @@ -285,15 +305,15 @@ class MainActivity : AppCompatActivity() {

private fun calculateTotalDistanceCovered(stops: List<Stop>, currentStop: Int, isMiles: Boolean): Double {
var totalDistance = 0.0
for (i in 0 until currentStop) {
for (i in 0..currentStop) {
totalDistance += if (isMiles) stops[i].distanceInMiles else stops[i].distanceInKm
}
return totalDistance
}

private fun calculateTotalDistanceRemaining(stops: List<Stop>, currentStop: Int, isMiles: Boolean): Double {
var totalDistance = 0.0
for (i in currentStop until stops.size) {
for (i in currentStop + 1 until stops.size) {
totalDistance += if (isMiles) stops[i].distanceInMiles else stops[i].distanceInKm
}
return totalDistance
Expand All @@ -316,7 +336,7 @@ class MainActivity : AppCompatActivity() {
}

private fun updateProgressBar(totalStops: Int) {
progressState = (currentStop.toFloat() / totalStops.toFloat())
progressState = ((currentStop.toFloat() + 1) / totalStops.toFloat())
}

private fun showToast(message: String) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example.journeytrack

import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions

class SplashActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)

val splashGif: ImageView = findViewById(R.id.splashGif)
Glide.with(this).load(R.drawable.journeytracksplash).transition(DrawableTransitionOptions.withCrossFade()).into(splashGif)

Handler(Looper.getMainLooper()).postDelayed({
val mainIntent = Intent(this, MainActivity::class.java)
startActivity(mainIntent)
finish()
}, 1500)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ImageView
android:id="@+id/splashGif"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/journeytracksplash"
android:contentDescription="@string/journeytracksplash" />

</RelativeLayout>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">JourneyTrack</string>
<string name="journeytracksplash">journeytracksplash</string>
</resources>

0 comments on commit f693888

Please sign in to comment.