Skip to content

Commit be12ea7

Browse files
committed
add new screen for clouds
1 parent a24c87d commit be12ea7

File tree

5 files changed

+47
-60
lines changed

5 files changed

+47
-60
lines changed

.idea/deploymentTargetDropDown.xml

-17
This file was deleted.

.idea/gradle.xml

+2-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/example/skycast/MainActivity.kt

+38-25
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import java.text.SimpleDateFormat
1414
import java.util.Date
1515
import java.util.Locale
1616
import java.util.concurrent.locks.Condition
17+
import java.util.Calendar
1718

1819
//
1920

@@ -54,23 +55,28 @@ class MainActivity : AppCompatActivity() {
5455
.baseUrl("https://api.openweathermap.org/data/2.5/")
5556
.build()
5657
.create(ApiInterface::class.java)
57-
val response = retrofit.getWeatherData(cityName , "3be41e2a359cb318dc3b06d237a9e1ee" , "metric")
58-
response.enqueue(object : Callback<WeatherApp>{
58+
val response = retrofit.getWeatherData(cityName, "3be41e2a359cb318dc3b06d237a9e1ee", "metric")
59+
response.enqueue(object : Callback<WeatherApp> {
5960
override fun onResponse(call: Call<WeatherApp>, response: Response<WeatherApp>) {
6061
if (response.isSuccessful) {
6162
val responseBody = response.body()
6263
if (responseBody != null) {
64+
65+
val sunRise = responseBody.sys.sunrise.toLong()
66+
val sunSet = responseBody.sys.sunset.toLong()
67+
val condition = responseBody.weather.firstOrNull()?.main ?: "unknown"
68+
changesImagesAcoddingToWearther(condition, sunRise, sunSet)
69+
70+
// Now, you can use these variables throughout the function
6371
val temperature = responseBody.main.temp.toString()
6472
val humidity = responseBody.main.humidity
6573
val windSpeed = responseBody.wind.speed
66-
val sunRise = responseBody.sys.sunrise.toLong()
6774
val seaLevel = responseBody.main.pressure
68-
val condition = responseBody.weather.firstOrNull()?.main?:"unknown"
69-
val sunSet = responseBody.sys.sunset.toLong()
7075
val maxTem = responseBody.main.temp_max
7176
val minTem = responseBody.main.temp_min
7277

7378

79+
7480
Log.d("WeatherApp", "Temperature: $temperature")
7581
binding.temperature.text = "$temperature°C"
7682
binding.weather.text = condition
@@ -86,7 +92,7 @@ class MainActivity : AppCompatActivity() {
8692
binding.date.text= date()
8793
binding.cityname.text ="$cityName"
8894

89-
changesImagesAcoddingToWearther(condition)
95+
changesImagesAcoddingToWearther(condition ?: "unknown", sunRise, sunSet)
9096

9197
} else {
9298
Log.e("WeatherApp", "Response body is null")
@@ -104,51 +110,58 @@ class MainActivity : AppCompatActivity() {
104110
})
105111
}
106112

107-
private fun changesImagesAcoddingToWearther(condition: String) {
108-
when(condition){
113+
private fun changesImagesAcoddingToWearther(condition: String, sunrise: Long, sunset: Long) {
114+
val currentTime = System.currentTimeMillis() / 1000 // Convert to seconds
115+
val isNight = currentTime < sunrise || currentTime > sunset
109116

110-
"Clear Sky" , "Sunny" , "Clear" ->{
117+
when {
118+
isNight -> {
119+
binding.root.setBackgroundResource(R.drawable.night_scr)
120+
binding.lottieAnimationView.setAnimation(R.raw.moon)
121+
}
122+
condition in arrayOf("Clear Sky", "Sunny", "Clear") -> {
111123
binding.root.setBackgroundResource(R.drawable.sunny_background)
112124
binding.lottieAnimationView.setAnimation(R.raw.sun)
113125
}
114-
//all are type of cloude , i cAN also use all in one
115-
"Clouds" ->{
126+
condition == "Clouds" -> {
116127
binding.root.setBackgroundResource(R.drawable.colud_background)
117128
binding.lottieAnimationView.setAnimation(R.raw.cloud)
118129
}
119-
"Haze" , "Mist" ->{
130+
condition in arrayOf("Haze", "Mist") -> {
120131
binding.root.setBackgroundResource(R.drawable.haze_scr)
121132
binding.lottieAnimationView.setAnimation(R.raw.cloud)
122133
}
123-
"Pertly Clouds" ->{
134+
condition == "Pertly Clouds" -> {
124135
binding.root.setBackgroundResource(R.drawable.pertly_clouds)
125136
binding.lottieAnimationView.setAnimation(R.raw.cloud)
126137
}
127-
"Overcast" ->{
138+
condition == "Thunderstorm" -> {
139+
binding.root.setBackgroundResource(R.drawable.thunderstormphoto)
140+
binding.lottieAnimationView.setAnimation(R.raw.thunderstorm)
141+
}
142+
condition == "Overcast" -> {
128143
binding.root.setBackgroundResource(R.drawable.overcast_clouds)
129144
binding.lottieAnimationView.setAnimation(R.raw.cloud)
130145
}
131-
"Foggy" ->{
146+
condition == "Foggy" -> {
132147
binding.root.setBackgroundResource(R.drawable.foggy_scr)
133148
binding.lottieAnimationView.setAnimation(R.raw.cloud)
134149
}
135-
//after that rain will start
136-
137-
138-
"Light Rain" , "Drizzle" , " Moderate Rain" , "Showers" , "Heavy Rain" ,"Thunderstorm" -> {
150+
condition in arrayOf(
151+
"Light Rain", "Drizzle", "Moderate Rain",
152+
"Showers", "Heavy Rain", "Thunderstorm"
153+
) -> {
139154
binding.root.setBackgroundResource(R.drawable.rain_background)
140155
binding.lottieAnimationView.setAnimation(R.raw.rain)
141156
}
142-
"Light Snow" , "Moderate Snow","Heavy Snow" , " Blizzard" -> {
143-
binding.root.setBackgroundResource(R.drawable.rain_background)
144-
binding.lottieAnimationView.setAnimation(R.raw.rain)
145-
157+
condition in arrayOf("Light Snow", "Moderate Snow", "Heavy Snow", "Blizzard") -> {
158+
binding.root.setBackgroundResource(R.drawable.snow_background)
159+
binding.lottieAnimationView.setAnimation(R.raw.snow)
146160
}
147-
else ->{
161+
else -> {
148162
binding.root.setBackgroundResource(R.drawable.sunny_background)
149163
binding.lottieAnimationView.setAnimation(R.raw.sun)
150164
}
151-
152165
}
153166
binding.lottieAnimationView.playAnimation()
154167
}

app/src/main/res/layout/activity_main.xml

+6-14
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
<SearchView
2828
android:id="@+id/searchView"
29-
android:layout_width="395dp"
29+
android:layout_width="380dp"
3030
android:layout_height="wrap_content"
3131
android:layout_marginStart="16dp"
3232
android:layout_marginTop="16dp"
@@ -124,11 +124,11 @@
124124

125125
<TextView
126126
android:id="@+id/day"
127-
android:layout_width="103dp"
128-
android:layout_height="33dp"
127+
android:layout_width="120dp"
128+
android:layout_height="30dp"
129129
android:layout_marginTop="4dp"
130130
android:fontFamily="@font/merriweathersans_bold"
131-
android:text="Sunday"
131+
android:text="Wednesday "
132132
android:textColor="@color/black"
133133
android:textSize="20sp"
134134
app:layout_constraintEnd_toEndOf="@+id/mintam"
@@ -381,15 +381,7 @@
381381

382382
</FrameLayout>
383383

384-
<TextView
385-
android:id="@+id/textView13"
386-
android:layout_width="wrap_content"
387-
android:layout_height="wrap_content"
388-
android:text="Desing By Aakib"
389-
app:layout_constraintBottom_toBottomOf="parent"
390-
android:textColor="@color/black"
391-
app:layout_constraintEnd_toEndOf="parent"
392-
app:layout_constraintStart_toStartOf="parent"
393-
app:layout_constraintTop_toBottomOf="@+id/frameLayout" />
384+
385+
394386

395387
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/layout/activity_splas.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7-
android:background="@drawable/spl_scer_tow"
7+
android:background="@drawable/night_scr"
88
tools:context=".splasActivity">
99

1010
<ImageView

0 commit comments

Comments
 (0)