This commit is contained in:
TheBrokenRail 2024-02-17 21:11:04 -05:00
parent c401d5e472
commit ba486ab5d6
19 changed files with 86 additions and 21 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -45,6 +45,9 @@ class ListAdapter extends TaskAdapter<ListData> {
Intent intent = new Intent(category.getContext(), MenuActivity.class); Intent intent = new Intent(category.getContext(), MenuActivity.class);
intent.putExtra(MenuActivity.ID_EXTRA, location.id); intent.putExtra(MenuActivity.ID_EXTRA, location.id);
intent.putExtra(MenuActivity.NAME_EXTRA, location.name); intent.putExtra(MenuActivity.NAME_EXTRA, location.name);
intent.putExtra(MenuActivity.LATITUDE_EXTRA, location.address.lat);
intent.putExtra(MenuActivity.LONGITUDE_EXTRA, location.address.lon);
intent.putExtra(MenuActivity.STREET_EXTRA, location.address.street);
category.getContext().startActivity(intent); category.getContext().startActivity(intent);
}); });
} }

View File

@ -23,13 +23,13 @@ class ListTask extends Task<ListData> {
Info info = new Info(); Info info = new Info();
connection.send(info, infoResponse -> { connection.send(info, infoResponse -> {
// Load Locations // Load Locations
AllLocations allLocations = new AllLocations(Constants.PLATFORM, infoResponse.site.id, true, false, true); AllLocations allLocations = new AllLocations(Constants.PLATFORM, infoResponse.site.id, false, true);
connection.send(allLocations, allLocationsResponse -> { connection.send(allLocations, allLocationsResponse -> {
// Success // Success
ListData data = new ListData(infoResponse.site.id); ListData data = new ListData(infoResponse.site.id);
// Find Active Locations // Find Active Locations
for (AllLocations.Response.Building building : allLocationsResponse.buildings) { for (AllLocations.Response.Building building : allLocationsResponse.buildings) {
if (building.active) { if (building.show_menus) {
// Found Active Building // Found Active Building
Category<AllLocations.Response.Location> category = new Category<>(building.name); Category<AllLocations.Response.Location> category = new Category<>(building.name);
for (AllLocations.Response.Location location : building.locations) { for (AllLocations.Response.Location location : building.locations) {

View File

@ -1,6 +1,9 @@
package com.thebrokenrail.mtudining.activity.menu; package com.thebrokenrail.mtudining.activity.menu;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import androidx.activity.EdgeToEdge; import androidx.activity.EdgeToEdge;
@ -15,6 +18,9 @@ import com.google.android.material.appbar.MaterialToolbar;
import com.thebrokenrail.mtudining.R; import com.thebrokenrail.mtudining.R;
import com.thebrokenrail.mtudining.util.EdgeToEdgeUtil; import com.thebrokenrail.mtudining.util.EdgeToEdgeUtil;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Date; import java.util.Date;
import java.util.Objects; import java.util.Objects;
@ -24,10 +30,17 @@ import java.util.Objects;
public class MenuActivity extends AppCompatActivity { public class MenuActivity extends AppCompatActivity {
public static final String NAME_EXTRA = "mtu_name"; public static final String NAME_EXTRA = "mtu_name";
public static final String ID_EXTRA = "mtu_id"; public static final String ID_EXTRA = "mtu_id";
public static final String LATITUDE_EXTRA = "mtu_lat";
public static final String LONGITUDE_EXTRA = "lon_lat";
public static final String STREET_EXTRA = "lon_lat";
private MenuViewModel viewModel; private MenuViewModel viewModel;
private MenuAdapter adapter; private MenuAdapter adapter;
private double latitude;
private double longitude;
private String street;
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -51,6 +64,9 @@ public class MenuActivity extends AppCompatActivity {
if (!viewModel.task.isSetup()) { if (!viewModel.task.isSetup()) {
viewModel.task.setup(id, new Date()); viewModel.task.setup(id, new Date());
} }
latitude = getIntent().getDoubleExtra(LATITUDE_EXTRA, 0);
longitude = getIntent().getDoubleExtra(LONGITUDE_EXTRA, 0);
street = getIntent().getStringExtra(STREET_EXTRA);
// Setup RecyclerView // Setup RecyclerView
adapter = new MenuAdapter(viewModel.task); adapter = new MenuAdapter(viewModel.task);
@ -75,6 +91,18 @@ public class MenuActivity extends AppCompatActivity {
if (item.getItemId() == android.R.id.home) { if (item.getItemId() == android.R.id.home) {
getOnBackPressedDispatcher().onBackPressed(); getOnBackPressedDispatcher().onBackPressed();
return true; return true;
} else if (item.getItemId() == R.id.menu_map) {
// Open Map
String encodedStreet;
try {
encodedStreet = URLEncoder.encode(street, StandardCharsets.UTF_8.toString());
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
Uri gmmIntentUri = Uri.parse("geo:" + latitude + ',' + longitude + "?q=" + encodedStreet);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
startActivity(mapIntent);
return true;
} else { } else {
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@ -88,4 +116,10 @@ public class MenuActivity extends AppCompatActivity {
viewModel.task.setup(null, newDate); viewModel.task.setup(null, newDate);
viewModel.task.start(); viewModel.task.start();
} }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_toolbar, menu);
return true;
}
} }

View File

@ -8,21 +8,26 @@ import java.util.List;
public class AllLocations implements Method<AllLocations.Response> { public class AllLocations implements Method<AllLocations.Response> {
private final int platform; private final int platform;
private final String siteId; private final String siteId;
private final boolean forMenus;
private final boolean withAddress; private final boolean withAddress;
private final boolean withBuildings; private final boolean withBuildings;
public AllLocations(int platform, String siteId, boolean forMenus, boolean withAddress, boolean withBuildings) { // These values slightly change what type of date is returned.
// for_menus=true includes some locations that for_map=true does not.
// While for_map=true includes location data, which for_menus=true does not.
// However, none of the for_menus=true locations actually have any menus.
private static final boolean FOR_MENUS = false;
private static final boolean FOR_MAP = true;
public AllLocations(int platform, String siteId, boolean withAddress, boolean withBuildings) {
this.platform = platform; this.platform = platform;
this.siteId = siteId; this.siteId = siteId;
this.forMenus = forMenus;
this.withAddress = withAddress; this.withAddress = withAddress;
this.withBuildings = withBuildings; this.withBuildings = withBuildings;
} }
@Override @Override
public String getPath() { public String getPath() {
return "/locations/all_locations?platform=" + platform + "&site_id=" + siteId + "&for_menus=" + forMenus + "&with_address=" + withAddress + "&with_buildings=" + withBuildings; return "/locations/all_locations?platform=" + platform + "&site_id=" + siteId + "&for_menus=" + FOR_MENUS + "&for_map=" + FOR_MAP + "&with_address=" + withAddress + "&with_buildings=" + withBuildings;
} }
@Override @Override
@ -34,15 +39,21 @@ public class AllLocations implements Method<AllLocations.Response> {
public static class Building { public static class Building {
public String id; public String id;
public String name; public String name;
public boolean active;
public boolean show_menus; public boolean show_menus;
public List<Location> locations; public List<Location> locations;
} }
public List<Building> buildings; public List<Building> buildings;
public static class Location implements Category.Named { public static class Location implements Category.Named {
public static class Address {
public double lat;
public double lon;
public String street;
}
public String id; public String id;
public String name; public String name;
public boolean active; public boolean active;
public Address address;
@Override @Override
public String getName() { public String getName() {

View File

@ -1,19 +1,14 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" <vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp" android:width="108dp"
android:height="108dp" android:height="108dp"
android:viewportWidth="396.85" android:viewportWidth="674.58"
android:viewportHeight="396.85"> android:viewportHeight="674.58">
<group android:scaleX="1.0043478"
android:scaleY="1.0043478"
android:translateX="-0.8627174"
android:translateY="-0.8627174">
<group android:scaleX="0.42777777" <group android:scaleX="0.42777777"
android:scaleY="0.42777777" android:scaleY="0.42777777"
android:translateX="113.5432" android:translateX="193.00484"
android:translateY="113.5432"> android:translateY="193.00484">
<path <path
android:pathData="m392.07,74c-6.38,-6.38 -16.7,-6.38 -23.07,-0L304.56,138.43 293.02,126.9 357.46,62.46c6.38,-6.38 6.38,-16.69 -0,-23.07 -6.38,-6.38 -16.69,-6.38 -23.07,0L269.95,103.83 258.42,92.29 322.85,27.85c6.37,-6.38 6.37,-16.7 -0,-23.07 -6.38,-6.38 -16.7,-6.38 -23.07,-0l-64.44,64.44 -10.55,10.55 -29.13,29.13c-17.11,17.11 -17.11,44.85 0,61.96l2.56,2.56 -181.79,145.43c-9.72,7.78 -15.67,19.34 -16.37,31.78 -0.69,12.45 3.96,24.59 12.77,33.4 8.81,8.81 20.95,13.45 33.4,12.77 12.44,-0.7 24,-6.65 31.78,-16.37L223.44,198.63l2.56,2.56c17.11,17.11 44.85,17.11 61.96,0l29.13,-29.13 10.55,-10.55 64.44,-64.44c6.37,-6.38 6.37,-16.7 -0,-23.07z" android:pathData="M351.43,266.58 L521.14,96.87c8.01,-8.01 17.44,-12.02 28.28,-12.02 10.84,0 20.27,4.01 28.28,12.02 8.01,8.01 12.02,17.44 12.02,28.28 0,10.84 -4.01,20.27 -12.02,28.28l-169.71,169.71 28.28,28.28 169.71,-169.71c8.01,-8.01 17.44,-12.02 28.28,-12.02 10.84,0 20.27,4.01 28.28,12.02 8.01,8.01 12.02,17.44 12.02,28.28 0,10.84 -4.01,20.27 -12.02,28.28l-169.71,169.71c-26.4,26.4 -57.63,41.37 -93.69,44.9 -36.06,3.54 -69.41,-3.42 -100.06,-20.86L68.59,662.56c-8.01,8.01 -17.44,12.02 -28.28,12.02 -10.84,0 -20.27,-4.01 -28.28,-12.02C4.01,654.55 0,645.12 0,634.27c-0,-10.84 4.01,-20.27 12.02,-28.28L242.54,375.47c-17.44,-30.64 -24.4,-63.99 -20.86,-100.06 3.54,-36.06 18.5,-67.29 44.9,-93.69L436.28,12.02C444.3,4.01 453.73,0 464.57,0c10.84,0 20.27,4.01 28.28,12.02 8.01,8.01 12.02,17.44 12.02,28.28 0,10.84 -4.01,20.27 -12.02,28.28L323.15,238.29Z"
android:fillColor="#ffcd00"/> android:fillColor="#ffcd00"/>
</group> </group>
</group>
</vector> </vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M12,2C8.13,2 5,5.13 5,9c0,5.25 7,13 7,13s7,-7.75 7,-13c0,-3.87 -3.13,-7 -7,-7zM12,11.5c-1.38,0 -2.5,-1.12 -2.5,-2.5s1.12,-2.5 2.5,-2.5 2.5,1.12 2.5,2.5 -1.12,2.5 -2.5,2.5z"/>
</vector>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_map"
android:icon="@drawable/location_on"
android:title="@string/open_map"
app:showAsAction="ifRoom" />
</menu>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 822 B

After

Width:  |  Height:  |  Size: 882 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 580 B

After

Width:  |  Height:  |  Size: 604 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

@ -11,4 +11,5 @@
<string name="ingredients">Ingredients:\u0020</string> <string name="ingredients">Ingredients:\u0020</string>
<string name="portion">Portion:\u0020</string> <string name="portion">Portion:\u0020</string>
<string name="nutrients">Nutrients:</string> <string name="nutrients">Nutrients:</string>
<string name="open_map">Open Map</string>
</resources> </resources>