diff --git a/app/src/main/java/de/janl1/betteropelapp/ui/main/VehicleFragment.java b/app/src/main/java/de/janl1/betteropelapp/ui/main/VehicleFragment.java index 7a25e3b..c011ad0 100644 --- a/app/src/main/java/de/janl1/betteropelapp/ui/main/VehicleFragment.java +++ b/app/src/main/java/de/janl1/betteropelapp/ui/main/VehicleFragment.java @@ -2,6 +2,7 @@ import android.Manifest; import android.annotation.SuppressLint; +import android.app.ProgressDialog; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.os.Bundle; @@ -10,6 +11,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ListView; +import android.widget.ProgressBar; import android.widget.TextView; import androidx.annotation.Nullable; @@ -29,6 +31,7 @@ import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; +import com.google.android.material.floatingactionbutton.FloatingActionButton; import org.jetbrains.annotations.NotNull; @@ -66,6 +69,8 @@ public class VehicleFragment extends Fragment implements OnMapReadyCallback { GoogleMap googleMap; SwipeRefreshLayout swipeRefreshLayout; + FloatingActionButton refreshFloatingButton; + ProgressBar progressBar; TextView tvBatteryValue; TextView tvBatteryText; @@ -115,6 +120,8 @@ public View onCreateView( tvConsumption = root.findViewById(R.id.textConsumptionValue); tvBatteryText = root.findViewById(R.id.textAkku); tripsList = root.findViewById(R.id.tripList); + refreshFloatingButton = root.findViewById(R.id.refreshFloatingButton); + progressBar = root.findViewById(R.id.progressBar); apiInterface = ApiClient.getClient().create(TronityApi.class); prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()); @@ -125,6 +132,7 @@ public View onCreateView( mapView.onCreate(savedInstanceState); mapView.getMapAsync(this); + refreshFloatingButton.setOnClickListener(v -> VehicleFragment.this.loadBulkData(swipeRefreshLayout)); // swipeRefreshLayout.setOnRefreshListener(() -> loadBulkData(swipeRefreshLayout)); return root; @@ -184,7 +192,7 @@ public void onMapReady(GoogleMap googleMap) { private void loadBulkData(SwipeRefreshLayout swipeRefreshLayout) { - // swipeRefreshLayout.setRefreshing(true); + showLoadingSpinner(); Call bulkCall = apiInterface.getBulkInformation("Bearer " + prefs.getString(Vars.PREF_AUTH_ACCESSTOKEN, ""), vehicle.id); bulkCall.enqueue(new Callback() { @Override @@ -223,18 +231,18 @@ public void onResponse(@NotNull Call call, @NotNull Response respons } } - // swipeRefreshLayout.setRefreshing(false); + hideLoadingSpinner(); } else { Dialog.showErrorMessage(getActivity().getApplicationContext(), "Laden der Fahrzeuginformation", response.code() + " " + response.message()).show(); - // swipeRefreshLayout.setRefreshing(false); + hideLoadingSpinner(); } } @Override public void onFailure(@NotNull Call call, @NotNull Throwable t) { Dialog.showErrorMessage(getActivity().getApplicationContext(), "Laden der Fahrzeuginformation", t.getMessage()).show(); - // swipeRefreshLayout.setRefreshing(false); + hideLoadingSpinner(); } }); @@ -297,4 +305,14 @@ public void onFailure(@NotNull Call call, @NotNull Throwable t) { } }); } + + private void showLoadingSpinner() + { + progressBar.setVisibility(View.VISIBLE); + } + + private void hideLoadingSpinner() + { + progressBar.setVisibility(View.INVISIBLE); + } } \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_baseline_refresh_24.xml b/app/src/main/res/drawable/ic_baseline_refresh_24.xml new file mode 100644 index 0000000..788bfdf --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_refresh_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/fragment_vehicle.xml b/app/src/main/res/layout/fragment_vehicle.xml index 7650b35..2fde15a 100644 --- a/app/src/main/res/layout/fragment_vehicle.xml +++ b/app/src/main/res/layout/fragment_vehicle.xml @@ -15,6 +15,20 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> + + + +