9
9
import android .location .LocationManager ;
10
10
import android .os .Bundle ;
11
11
import android .os .Looper ;
12
+ import android .view .View ;
12
13
import android .view .WindowManager ;
14
+ import android .widget .ProgressBar ;
13
15
import android .widget .TextView ;
14
- import android .widget .Toast ;
15
16
16
17
import androidx .appcompat .app .AppCompatActivity ;
17
18
import androidx .core .app .ActivityCompat ;
@@ -45,6 +46,7 @@ public class MainActivity extends AppCompatActivity {
45
46
private HourlyAdapter hourlyAdapter ;
46
47
private LocationRequest locationRequest ;
47
48
private LocationCallback locationCallback ;
49
+ private ProgressBar progressBar ;
48
50
private TextView locationTxt , pressureTxt , windTxt , precipitationTxt , CurrentDay , humidityTxt , sunriseTxt , sunsetTxt , FeelLikeTxt , currentWeatherTxt ;
49
51
50
52
@ Override
@@ -76,6 +78,7 @@ private void buildAlertMessageNoGps() {
76
78
.setPositiveButton (getString (R .string .okay ), (dialog , id ) -> startActivityForResult (new Intent (android .provider .Settings .ACTION_LOCATION_SOURCE_SETTINGS ), 333 ));
77
79
final AlertDialog alert = builder .create ();
78
80
alert .show ();
81
+ _GetCurrentUserPermission ();
79
82
}
80
83
81
84
private void _view () {
@@ -90,6 +93,7 @@ private void _view() {
90
93
currentWeatherTxt = findViewById (R .id .currentWeatherTxt );
91
94
FeelLikeTxt = findViewById (R .id .FeelLikeTxt );
92
95
CurrentDay = findViewById (R .id .CurrentDay );
96
+ progressBar = findViewById (R .id .progressBar );
93
97
findViewById (R .id .textView2 ).setOnClickListener (v -> startActivity (new Intent (getApplicationContext (), Next7Days .class )));
94
98
}
95
99
@@ -173,6 +177,7 @@ private void _FindUserLocation() {
173
177
fusedLocationProviderClient .getLastLocation ()
174
178
.addOnFailureListener (Throwable ::printStackTrace )
175
179
.addOnSuccessListener (location -> {if (location != null ) {
180
+ progressBar .setVisibility (View .VISIBLE );
176
181
String MyLocation = UserUtils .getAddressFromLocation (getApplicationContext (), location );
177
182
locationTxt .setText (MyLocation );
178
183
String APP_ID = "ae82f77ec5397be4e9eca95799584087" ;
@@ -182,7 +187,8 @@ private void _FindUserLocation() {
182
187
APP_ID );
183
188
postViewModel .getCurrentDailyForecastsMutableLiveData ().observe (this , currentTemp -> {
184
189
try {
185
- sunsetTxt .setText (new StringBuilder ().append (UserUtils .getDateHHMMFromNumber (currentTemp .getSunset ())).append (" pm" ));
190
+ progressBar .setVisibility (View .GONE );
191
+ sunsetTxt .setText (new StringBuilder ().append (UserUtils .getDateHHMMFromNumber (currentTemp .getSunset ())).append (" h" ));
186
192
sunriseTxt .setText (new StringBuilder ().append (UserUtils .getDateHHMMFromNumber (currentTemp .getSunrise ())).append (" am" ));
187
193
currentWeatherTxt .setText (new StringBuilder ().append (UserUtils .getDegreeToCelsius (currentTemp .getTemp ())).append (" °C" ));
188
194
FeelLikeTxt .setText (new StringBuilder ().append ("Feels like " ).append (UserUtils .getDegreeToCelsius (currentTemp .getFeels_like ())).append (" °C" ));
0 commit comments