Skip to content

Commit

Permalink
rel to cgeo#16250: enhance handling of asynchronous events, make dial…
Browse files Browse the repository at this point in the history
…ogs visually more like activities
  • Loading branch information
eddiemuc committed Oct 20, 2024
1 parent 82f53c8 commit 50cd6f5
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@
import cgeo.geocaching.utils.Log;
import cgeo.geocaching.utils.MapMarkerUtils;
import cgeo.geocaching.utils.functions.Func1;
import cgeo.geocaching.wherigo.WherigoDialogManager;
import cgeo.geocaching.wherigo.WherigoGame;
import cgeo.geocaching.wherigo.WherigoThingDialogProvider;
import cgeo.geocaching.wherigo.WherigoUtils;
import static cgeo.geocaching.filters.gui.GeocacheFilterActivity.EXTRA_FILTER_CONTEXT;
import static cgeo.geocaching.settings.Settings.MAPROTATION_AUTO_LOWPOWER;
import static cgeo.geocaching.settings.Settings.MAPROTATION_AUTO_PRECISE;
Expand Down Expand Up @@ -1119,7 +1118,7 @@ private void handleTap(final MapSelectableItem item, final Geopoint touchedPoint
MapMarkerUtils.addHighlighting(routeItem.getWaypoint(), getResources(), nonClickableItemsLayer);
}
} else if (item.getData() instanceof Zone) {
WherigoDialogManager.get().display(new WherigoThingDialogProvider(item.getData()));
WherigoUtils.displayThing(this, item.getData(), false);
} else if (item.getData() instanceof String) {
GeoItemTestLayer.handleTapTest(clickableItemsLayer, this, touchedPoint, item.getData().toString(), isLongTap);
}
Expand Down
16 changes: 2 additions & 14 deletions main/src/main/java/cgeo/geocaching/wherigo/WherigoActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,7 @@ public final void onCreate(final Bundle savedInstanceState) {
setThemeAndContentView(binding);

binding.wherigoThingTypeList.setModel(wherigoThingTypeModel);
wherigoThingTypeModel.addSingleSelectListener(type -> {
final List<EventTable> things = type.getThingsForUserDisplay();
if (things.isEmpty()) {
return;
}
if (things.size() == 1) {
WherigoDialogManager.displayDirect(this, new WherigoThingDialogProvider(things.get(0)));
} else {
WherigoDialogManager.displayDirect(this, new WherigoThingListDialogProvider(type));
}
});
wherigoThingTypeModel.addSingleSelectListener(type -> WherigoUtils.chooseAndDisplayThing(this, type));

refreshGui();

Expand All @@ -121,9 +111,7 @@ public final void onCreate(final Bundle savedInstanceState) {
binding.saveGame.setOnClickListener(v -> saveGame());
binding.stopGame.setOnClickListener(v -> stopGame());
binding.download.setOnClickListener(v -> manualCartridgeDownload());
binding.reportProblem.setOnClickListener(v -> {
WherigoDialogManager.get().display(new WherigoErrorDialogProvider());
});
binding.reportProblem.setOnClickListener(v -> WherigoDialogManager.get().display(new WherigoErrorDialogProvider()));

binding.map.setOnClickListener(v -> showOnMap());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ public WherigoCartridgeDialogProvider(final WherigoCartridgeInfo cartridgeInfo)

@Override
public Dialog createDialog(final Activity activity, final Consumer<Boolean> resultSetter) {
final AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.style.cgeo_fullScreen);
final AlertDialog dialog = WherigoUtils.createFullscreenDialog(activity, cartridgeFile.name);
binding = WherigoCartridgeDetailsBinding.inflate(LayoutInflater.from(activity));
final AlertDialog dialog = builder.create();
dialog.setTitle(cartridgeFile.name);
dialog.setView(binding.getRoot());

final List<WherigoSavegameInfo> saveGames = cartridgeInfo.getLoadableSavegames();
Expand Down
43 changes: 31 additions & 12 deletions main/src/main/java/cgeo/geocaching/wherigo/WherigoGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,31 +314,44 @@ public void pushInput(final EventTable input) {
WherigoDialogManager.get().display(new WherigoInputDialogProvider(input));
}

/**
* From OpenWIG doku:
* Shows a specified screen
* <p>
* The screen specified by screenId should be made visible.
* If a dialog or an input is open, it must be closed before
* showing the screen.
* @param screenId the screen to be shown
* @param details if screenId is DETAILSCREEN, details of this object will be displayed
*/
@Override
public void showScreen(final int screenId, final EventTable eventTable) {
Log.iForce(LOG_PRAEFIX + "showScreen:" + screenId + ":" + eventTable);
public void showScreen(final int screenId, final EventTable details) {
Log.iForce(LOG_PRAEFIX + "showScreen:" + screenId + ":" + details);

switch (screenId) {
case MAINSCREEN:
case INVENTORYSCREEN:
case ITEMSCREEN:
case LOCATIONSCREEN:
case TASKSCREEN:
WherigoDialogManager.get().clear();
final Activity currentActivity = CgeoApplication.getInstance().getCurrentForegroundActivity();
if (currentActivity instanceof WherigoActivity) {
return;
}
if (currentActivity != null && !openOnlyInWherigo()) {
WherigoActivity.start(currentActivity, false);
//don't open the screens here, just issue a toast advising user to check
final WherigoThingType type = WherigoThingType.getByWherigoScreenId(screenId);
if (type == null) {
ActivityMixin.showApplicationToast(LocalizationUtils.getString(R.string.wherigo_toast_check_game));
} else {
ActivityMixin.showApplicationToast(LocalizationUtils.getString(R.string.wherigo_toast_check_things, type.toUserDisplayableString()));
}
break;
case INVENTORYSCREEN:
case ITEMSCREEN:
case LOCATIONSCREEN:
case TASKSCREEN:
WherigoDialogManager.get().display(new WherigoThingListDialogProvider(WherigoThingType.getByWherigoScreenId(screenId)));
break;
case DETAILSCREEN:
WherigoDialogManager.get().display(new WherigoThingDialogProvider(eventTable));
WherigoUtils.displayThing(null, details, true);
break;
default:
Log.w(LOG_PRAEFIX + "showDialog called with unknown screenId: " + screenId + " [" + eventTable + "]");
Log.w(LOG_PRAEFIX + "showDialog called with unknown screenId: " + screenId + " [" + details + "]");
// do nothing
break;
}
Expand Down Expand Up @@ -367,6 +380,12 @@ public void unblock() {
WherigoSaveFileHandler.get().loadSaveFinished(); // Ends a running SAVE
}

/**
* From OpenWIG Doku:
* Issues a command
* <p>
* This function should issue a command (SaveClose, DriveTo, StopSound, Alert).
*/
@Override
public void command(final String cmd) {
Log.iForce(LOG_PRAEFIX + "command:" + cmd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import cgeo.geocaching.ui.TextParam;
import cgeo.geocaching.utils.CommonUtils;
import cgeo.geocaching.utils.EditUtils;
import cgeo.geocaching.utils.LocalizationUtils;

import android.app.Activity;
import android.app.AlertDialog;
Expand Down Expand Up @@ -66,9 +67,9 @@ public Dialog createDialog(final Activity activity, final Consumer<Boolean> resu

final WherigoGame game = WherigoGame.get();

final AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.style.cgeo_fullScreenDialog);
final AlertDialog dialog = WherigoUtils.createFullscreenDialog(activity, LocalizationUtils.getString(R.string.wherigo_player));

binding = WherigoThingDetailsBinding.inflate(LayoutInflater.from(activity));
final AlertDialog dialog = builder.create();
dialog.setView(binding.getRoot());
binding.description.setText(game.toDisplayText((String) input.table.rawget("Text")));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ public class WherigoPushDialogProvider implements IWherigoDialogProvider {

@Override
public Dialog createDialog(final Activity activity, final Consumer<Boolean> resultSetter) {
final AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.style.cgeo_fullScreenDialog);
final AlertDialog dialog = WherigoUtils.createFullscreenDialog(activity, LocalizationUtils.getString(R.string.wherigo_player));
binding = WherigoThingDetailsBinding.inflate(LayoutInflater.from(activity));
final AlertDialog dialog = builder.create();
dialog.setView(binding.getRoot());

refreshGui();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import cgeo.geocaching.maps.DefaultMap;
import cgeo.geocaching.ui.ImageParam;
import cgeo.geocaching.ui.TextParam;
import cgeo.geocaching.utils.Log;

import android.app.Activity;
import android.app.AlertDialog;
Expand All @@ -20,6 +21,7 @@
import java.util.function.Consumer;

import cz.matejcik.openwig.Action;
import cz.matejcik.openwig.Engine;
import cz.matejcik.openwig.EventTable;
import cz.matejcik.openwig.Media;
import cz.matejcik.openwig.Thing;
Expand Down Expand Up @@ -56,16 +58,20 @@ public WherigoThingDialogProvider(final EventTable et) {

@Override
public Dialog createDialog(final Activity activity, final Consumer<Boolean> resultSetter) {
final AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.style.cgeo_fullScreen);
final AlertDialog dialog = WherigoUtils.createFullscreenDialog(activity, eventTable.name);
binding = WherigoThingDetailsBinding.inflate(LayoutInflater.from(activity));
final AlertDialog dialog = builder.create();
dialog.setTitle(eventTable.name);
dialog.setView(binding.getRoot());

weakActivity = new WeakReference<>(activity);
weakDialog = new WeakReference<>(dialog);

refreshGui();

if (eventTable.hasEvent("OnClick")) {
Log.iForce("Wherigo: item has 'OnClick': " + eventTable);
Engine.callEvent(eventTable, "OnClick", null);
}

return dialog;
}

Expand Down

This file was deleted.

Loading

0 comments on commit 50cd6f5

Please sign in to comment.