Skip to content

Commit

Permalink
Improve UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp0002 committed Mar 16, 2024
1 parent e6af1ba commit c86ee61
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 40 deletions.
16 changes: 7 additions & 9 deletions app/src/main/java/de/raffaelhahn/xadgps_client/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,18 @@ public void setFromJson(JSONObject jsonObject) {
}
}

public String getDeviceInfoShort(Context context) {
String description = "";
public String[] getDeviceInfoShort(Context context) {
String[] description = new String[]{"?", ""};
if(isStop != null) {
if ("1".equalsIgnoreCase(isStop)) {
description = context.getString(R.string.device_parked);

if (StopTime != null) {
description += " (" + StopTime + ")";
description[0] = context.getString(R.string.device_parked);
if(StopTime != null) {
description[1] = StopTime;
}

} else {
description = context.getString(R.string.device_moving);
description[0] = context.getString(R.string.device_moving);
if (speed != null) {
description += " (" + speed + " km/h)";
description[1]= speed + " km/h";
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
Expand All @@ -26,14 +25,16 @@ public DevicesRecyclerAdapter(OnItemClickListener onItemClickListener){

public static class DeviceViewHolder extends RecyclerView.ViewHolder {
public final TextView deviceName;
public final TextView deviceItemDescription;
public final TextView deviceState;
public final TextView deviceDescription;

public DeviceViewHolder(View view) {
super(view);
// Define click listener for the ViewHolder's View

deviceName = view.findViewById(R.id.deviceItemName);
deviceItemDescription = view.findViewById(R.id.deviceItemDescription);
deviceState = view.findViewById(R.id.deviceItemState);
deviceDescription = view.findViewById(R.id.deviceItemDescription);
}
}

Expand All @@ -50,9 +51,15 @@ public DeviceViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
@Override
public void onBindViewHolder(DeviceViewHolder viewHolder, final int position) {
Device device = deviceList.get(position);
String[] deviceInfoShort = device.getDeviceInfoShort(viewHolder.itemView.getContext());
viewHolder.deviceName.setText(device.name);
String subDescription = deviceInfoShort[0];
if(!deviceInfoShort[1].isEmpty()) {
subDescription += " (" + deviceInfoShort[1] + ")";
}

viewHolder.deviceItemDescription.setText(device.getDeviceInfoShort(viewHolder.itemView.getContext()));
viewHolder.deviceState.setText(deviceInfoShort[0]);
viewHolder.deviceDescription.setText(deviceInfoShort[1]);
viewHolder.itemView.setOnClickListener(a -> listener.onItemClick(device));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
public class TrackingFragment extends Fragment implements DeviceListService.DeviceListUpdateListener {
public static final String ARG_PARAM_SHOW_DEVICE_ID = "paramShowDeviceId";
private static final int REQUEST_PERMISSIONS_REQUEST_CODE = 1;
private static final String LATEST_LAT_PREF_KEY = "myLatestLat";
private static final String LATEST_LON_PREF_KEY = "myLatestLon";

private String paramShowDeviceId;
private MapView map = null;
Expand Down Expand Up @@ -92,9 +94,9 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
map.setFlingEnabled(true);
map.setVerticalMapRepetitionEnabled(false);
map.setScrollableAreaLimitLatitude(MapView.getTileSystem().getMaxLatitude(), MapView.getTileSystem().getMinLatitude(), 0);
if(preferences.contains("myLatestLat") && preferences.contains("myLatestLon") && paramShowDeviceId == null){
if(preferences.contains(LATEST_LAT_PREF_KEY) && preferences.contains(LATEST_LON_PREF_KEY) && paramShowDeviceId == null){
mapController.setZoom(20.0);
mapController.setCenter(new GeoPoint(preferences.getFloat("myLatestLat", 0), preferences.getFloat("myLatestLon", 0)));
mapController.setCenter(new GeoPoint(preferences.getFloat(LATEST_LAT_PREF_KEY, 0), preferences.getFloat(LATEST_LON_PREF_KEY, 0)));
}
/*mRotationGestureOverlay = new RotationGestureOverlay(map);
mRotationGestureOverlay.setEnabled(true);
Expand All @@ -107,8 +109,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
mapController.setZoom(20.0);
mapController.setCenter(mLocationOverlay.getMyLocation());
}
editor.putFloat("myLatestLat", (float) mLocationOverlay.getMyLocation().getLatitude());
editor.putFloat("myLatestLon", (float) mLocationOverlay.getMyLocation().getLongitude());
editor.putFloat(LATEST_LAT_PREF_KEY, (float) mLocationOverlay.getMyLocation().getLatitude());
editor.putFloat(LATEST_LON_PREF_KEY, (float) mLocationOverlay.getMyLocation().getLongitude());
editor.apply();
});
}
Expand Down Expand Up @@ -183,12 +185,17 @@ public void onDeviceListUpdate(ArrayList<Device> deviceList) {
for (Device device : deviceList) {
double lon = Double.parseDouble(device.longitude);
double lat = Double.parseDouble(device.latitude);
String[] deviceInfoShort = device.getDeviceInfoShort(getContext());
String subDescription = deviceInfoShort[0];
if(!deviceInfoShort[1].isEmpty()) {
subDescription += " (" + deviceInfoShort[1] + ")";
}
if(getActivity() == null || getActivity().isDestroyed()) return;
Marker marker = new Marker(map);
marker.setPosition(new GeoPoint(lat, lon));
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
marker.setTitle(device.name);
marker.setSubDescription(device.getDeviceInfoShort(getContext()));
marker.setSubDescription(subDescription);
//marker.setIcon(getResources().getDrawable(R.drawable.router));
map.getOverlays().add(marker);
map.invalidate();
Expand Down
32 changes: 19 additions & 13 deletions app/src/main/res/layout/device_info_sheet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,37 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:orientation="vertical">

<TextView
android:id="@+id/deviceName"
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="DeviceName"
android:textAppearance="?attr/textAppearanceHeadlineLarge"
android:textColor="?attr/colorOnSurface" />
app:cardBackgroundColor="?attr/colorSecondaryContainer">

<TextView
android:id="@+id/deviceGroupName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:text="DeviceGroup"
android:textAppearance="?attr/textAppearanceLabelLarge"
android:textColor="?attr/colorOnSecondaryContainer" />

</androidx.cardview.widget.CardView>

<TextView
android:id="@+id/deviceGroupName"
android:id="@+id/deviceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:text="DeviceGroup"
android:textAppearance="?attr/textAppearanceHeadlineSmall"
android:textColor="?attr/colorOnSurface" />
android:text="DeviceName"
android:textAppearance="?attr/textAppearanceHeadlineLarge"
android:textColor="?attr/colorOnSurface"
android:textStyle="bold" />

<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="8dp"
android:stretchColumns="1">
Expand Down
44 changes: 35 additions & 9 deletions app/src/main/res/layout/device_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,55 @@
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="TextView"
android:textAppearance="?attr/textAppearanceListItem"
android:textAppearance="?attr/textAppearanceTitleLarge"
android:textColor="?attr/colorOnSurface"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="@+id/imageView"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/deviceItemDescription"
<androidx.cardview.widget.CardView
android:id="@+id/deviceItemStateWrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="16dp"
android:text="TextView"
android:textColor="?attr/colorOnSurface"
android:textAppearance="?attr/textAppearanceListItemSecondary"
android:layout_marginBottom="20dp"
app:cardBackgroundColor="?attr/colorTertiaryContainer"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/imageView"
app:layout_constraintTop_toBottomOf="@+id/deviceItemName" />
app:layout_constraintTop_toBottomOf="@+id/deviceItemName">

<TextView
android:id="@+id/deviceItemState"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:text="TextView"
android:textColor="?attr/colorOnTertiaryContainer"
android:textAppearance="?attr/textAppearanceListItemSecondary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/imageView"
app:layout_constraintTop_toBottomOf="@+id/deviceItemName" />

</androidx.cardview.widget.CardView>


<TextView
android:id="@+id/deviceItemDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="TextView"
android:textAppearance="?attr/textAppearanceListItemSecondary"
android:textColor="?attr/colorOnSurface"
app:layout_constraintBottom_toBottomOf="@+id/deviceItemStateWrapper"
app:layout_constraintStart_toEndOf="@+id/deviceItemStateWrapper"
app:layout_constraintTop_toTopOf="@+id/deviceItemStateWrapper" />

<com.google.android.material.divider.MaterialDivider
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/deviceItemDescription"/>
app:layout_constraintStart_toStartOf="@+id/deviceItemStateWrapper"/>
</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit c86ee61

Please sign in to comment.