Skip to content

Commit

Permalink
floating button and progressbar for data refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
Janl1 committed Nov 22, 2020
1 parent 5f48a2d commit 316ff65
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -66,6 +69,8 @@ public class VehicleFragment extends Fragment implements OnMapReadyCallback {
GoogleMap googleMap;

SwipeRefreshLayout swipeRefreshLayout;
FloatingActionButton refreshFloatingButton;
ProgressBar progressBar;

TextView tvBatteryValue;
TextView tvBatteryText;
Expand Down Expand Up @@ -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());
Expand All @@ -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;
Expand Down Expand Up @@ -184,7 +192,7 @@ public void onMapReady(GoogleMap googleMap) {

private void loadBulkData(SwipeRefreshLayout swipeRefreshLayout)
{
// swipeRefreshLayout.setRefreshing(true);
showLoadingSpinner();
Call<Bulk> bulkCall = apiInterface.getBulkInformation("Bearer " + prefs.getString(Vars.PREF_AUTH_ACCESSTOKEN, ""), vehicle.id);
bulkCall.enqueue(new Callback<Bulk>() {
@Override
Expand Down Expand Up @@ -223,18 +231,18 @@ public void onResponse(@NotNull Call<Bulk> call, @NotNull Response<Bulk> 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<Bulk> call, @NotNull Throwable t) {
Dialog.showErrorMessage(getActivity().getApplicationContext(), "Laden der Fahrzeuginformation", t.getMessage()).show();
// swipeRefreshLayout.setRefreshing(false);
hideLoadingSpinner();
}
});

Expand Down Expand Up @@ -297,4 +305,14 @@ public void onFailure(@NotNull Call<Location> call, @NotNull Throwable t) {
}
});
}

private void showLoadingSpinner()
{
progressBar.setVisibility(View.VISIBLE);
}

private void hideLoadingSpinner()
{
progressBar.setVisibility(View.INVISIBLE);
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_baseline_refresh_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z"/>
</vector>
29 changes: 28 additions & 1 deletion app/src/main/res/layout/fragment_vehicle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<ProgressBar
android:id="@+id/progressBar"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:indeterminate="true"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@+id/cardViewMap"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.cardview.widget.CardView
android:id="@+id/cardViewMap"
android:layout_width="match_parent"
Expand Down Expand Up @@ -249,7 +263,6 @@
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
app:layout_constraintBottom_toBottomOf="parent"
Expand All @@ -265,12 +278,26 @@
android:id="@+id/tripList"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/refreshFloatingButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:clickable="true"
android:src="@drawable/ic_baseline_refresh_24"
app:backgroundTint="@color/colorPrimaryDark"
app:layout_constraintBottom_toBottomOf="@+id/cardViewTrips"
app:layout_constraintEnd_toEndOf="@+id/cardViewTrips" />
</androidx.constraintlayout.widget.ConstraintLayout>


Expand Down

0 comments on commit 316ff65

Please sign in to comment.