WIP
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
package eu.konggdev.strikemaps.ui;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.view.View;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.google.common.collect.BiMap;
|
||||
import eu.konggdev.strikemaps.Component;
|
||||
import eu.konggdev.strikemaps.R;
|
||||
import eu.konggdev.strikemaps.app.AppController;
|
||||
import eu.konggdev.strikemaps.map.MapComponent;
|
||||
import eu.konggdev.strikemaps.ui.element.UIRegion;
|
||||
import eu.konggdev.strikemaps.ui.fragment.layout.FragmentLayoutControls;
|
||||
import eu.konggdev.strikemaps.ui.fragment.layout.content.main.FragmentLayoutContentSettings;
|
||||
import eu.konggdev.strikemaps.ui.screen.Screen;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class UIComponent implements Component {
|
||||
@NonNull AppController app;
|
||||
private Map<Integer, Screen> screens;
|
||||
private Integer currentScreen;
|
||||
|
||||
public UIComponent(AppController app, MapComponent map) {
|
||||
this.app = app;
|
||||
this.screens = Map.of(
|
||||
//Main screen
|
||||
R.layout.screen_main, new Screen(
|
||||
//App reference
|
||||
app,
|
||||
//Map view
|
||||
map.toFragment(), //FragmentLayoutContentMap
|
||||
//Main screen init regions definition
|
||||
Map.of(R.id.bottomUi, new UIRegion(new FragmentLayoutControls(app, R.id.bottomUi), R.id.bottomUi)), //TODO: Probably stop referencing layout 3(!) times everytime
|
||||
//Layout
|
||||
R.layout.screen_main //TODO: Define this for the Screen without duplicating the reference
|
||||
),
|
||||
//Settings screen
|
||||
R.layout.screen_settings, new Screen(
|
||||
app,
|
||||
//Settings
|
||||
new FragmentLayoutContentSettings(),
|
||||
/* No regions defined in settings
|
||||
Entire screen is just the main view */
|
||||
new HashMap<>(),
|
||||
//Layout
|
||||
R.layout.screen_settings
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public void swapScreen(Integer screen) {
|
||||
currentScreen = screen;
|
||||
getCurrentScreen().attachAll();
|
||||
}
|
||||
|
||||
public Screen getCurrentScreen() {
|
||||
return getScreen(currentScreen);
|
||||
}
|
||||
|
||||
public Screen getScreen(Integer screen) {
|
||||
return screens.get(screen);
|
||||
}
|
||||
|
||||
public void alert(AlertDialog dialog) {
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
public <T> void alert(AlertDialog dialog, Consumer<T> callback) {
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
public View inflateUi(int layout) {
|
||||
return app.getActivity().getLayoutInflater().inflate(layout, null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package eu.konggdev.strikemaps.ui.element;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import eu.konggdev.strikemaps.ui.fragment.layout.Layout;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
|
||||
public class UIRegion {
|
||||
private final ArrayDeque<Fragment> previousFragments = new ArrayDeque<>();
|
||||
|
||||
private Fragment stockFragment;
|
||||
private Fragment currentFragment;
|
||||
public Integer layoutId;
|
||||
|
||||
public UIRegion(@NonNull Fragment initFragment, Integer refLayoutId) {
|
||||
this.currentFragment = initFragment;
|
||||
this.stockFragment = initFragment;
|
||||
|
||||
this.layoutId = refLayoutId;
|
||||
}
|
||||
|
||||
public Fragment getFragment() {
|
||||
return currentFragment;
|
||||
}
|
||||
|
||||
public void setFragment(Fragment fragment) {
|
||||
previousFragments.add(currentFragment);
|
||||
currentFragment = fragment;
|
||||
}
|
||||
|
||||
public void overwriteStockFragment(Fragment fragment) {
|
||||
stockFragment = fragment;
|
||||
}
|
||||
|
||||
public void back() {
|
||||
if (!previousFragments.isEmpty()) {
|
||||
currentFragment = previousFragments.pop();
|
||||
} else {
|
||||
currentFragment = stockFragment;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package eu.konggdev.strikemaps.ui.element.item;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import eu.konggdev.strikemaps.R;
|
||||
import eu.konggdev.strikemaps.app.AppController;
|
||||
import eu.konggdev.strikemaps.helper.FileHelper;
|
||||
import eu.konggdev.strikemaps.map.MapComponent;
|
||||
import eu.konggdev.strikemaps.ui.UIComponent;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public class GenericItem implements UIItem {
|
||||
@NonNull public String name;
|
||||
public Bitmap image;
|
||||
public Runnable onClick;
|
||||
boolean hasImage;
|
||||
public GenericItem(String refName) {
|
||||
this.name = refName;
|
||||
hasImage = false;
|
||||
}
|
||||
public GenericItem(String refName, Runnable onClick) {
|
||||
this.name = refName;
|
||||
this.onClick = onClick;
|
||||
hasImage = false;
|
||||
}
|
||||
public GenericItem(String refName, Bitmap refImage) {
|
||||
this.name = refName;
|
||||
this.image = refImage;
|
||||
hasImage = true;
|
||||
}
|
||||
public GenericItem(String refName, Bitmap refImage, Runnable onClick) {
|
||||
this.name = refName;
|
||||
this.image = refImage;
|
||||
this.onClick = onClick;
|
||||
hasImage = true;
|
||||
}
|
||||
|
||||
//FIXME: Ugly glue static constructor
|
||||
public final static GenericItem fromStyle(String style, AppController app, MapComponent map) {
|
||||
try {
|
||||
JSONObject styleJson = new JSONObject(style);
|
||||
String name = "Unknown"; //Fallback name
|
||||
if (styleJson.has("name")) name = styleJson.getString("name");
|
||||
if (styleJson.has("icon")) {
|
||||
switch(styleJson.getString("icon").split("//")[0]) {
|
||||
//TODO: https
|
||||
case "assets:":
|
||||
Bitmap icon = BitmapFactory.decodeStream(FileHelper.openAssetStream("bundled/icon/" + styleJson.getString("icon").split("//")[1], app));
|
||||
return new GenericItem(name, icon, () -> map.setStyle(style));
|
||||
default:
|
||||
app.logcat("Unimplemented icon source requested in style: " + name);
|
||||
return new GenericItem(name, () -> map.setStyle(style));
|
||||
}
|
||||
}
|
||||
return new GenericItem(name, () -> map.setStyle(style));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return new GenericItem("Exception!", () -> map.setStyle(style));
|
||||
}
|
||||
}
|
||||
public View makeView(UIComponent spawner) {
|
||||
View v = spawner.inflateUi(R.layout.item_generic);
|
||||
//FIXME: These shouldn't be casted like that!
|
||||
((TextView) v.findViewById(R.id.name)).setText(name);
|
||||
if(image != null) ((ImageButton) v.findViewById(R.id.image)).setImageBitmap(image);
|
||||
if(onClick != null) v.findViewById(R.id.image).setOnClickListener(click(onClick));
|
||||
|
||||
return v;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package eu.konggdev.strikemaps.ui.element.item;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import eu.konggdev.strikemaps.ui.UIComponent;
|
||||
import org.maplibre.geojson.Feature;
|
||||
|
||||
import eu.konggdev.strikemaps.R;
|
||||
public class PreviewItem implements UIItem {
|
||||
public String name;
|
||||
public String type;
|
||||
public Bitmap image;
|
||||
boolean hasImage;
|
||||
public PreviewItem(String refName, String refType) {
|
||||
this.name = refName;
|
||||
this.type = refType;
|
||||
hasImage = false;
|
||||
}
|
||||
public PreviewItem(String refName, String refType, Bitmap refImage) {
|
||||
this.name = refName;
|
||||
this.type = refType;
|
||||
this.image = refImage;
|
||||
hasImage = true;
|
||||
}
|
||||
public static PreviewItem fromFeature(Feature feature) {
|
||||
return new PreviewItem(feature.getStringProperty("name"), feature.getStringProperty("class"));
|
||||
}
|
||||
public View makeView(UIComponent spawner) {
|
||||
View view = spawner.inflateUi(R.layout.item_preview);
|
||||
((TextView) view.findViewById(R.id.choiceName)).setText(name);
|
||||
((TextView) view.findViewById(R.id.type)).setText(type);
|
||||
return view;
|
||||
}
|
||||
public View makeView(UIComponent spawner, View.OnClickListener onClick) {
|
||||
View view = makeView(spawner);
|
||||
view.setOnClickListener(onClick);
|
||||
return view;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package eu.konggdev.strikemaps.ui.element.item;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import eu.konggdev.strikemaps.ui.UIComponent;
|
||||
|
||||
public interface UIItem {
|
||||
abstract View makeView(UIComponent spawner);
|
||||
|
||||
default View.OnClickListener click(Runnable action) {
|
||||
return v -> action.run();
|
||||
}
|
||||
|
||||
default View.OnLongClickListener longClick(Runnable action) { return v -> { action.run(); return true; };}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package eu.konggdev.strikemaps.ui.fragment;
|
||||
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import eu.konggdev.strikemaps.ui.element.UIRegion;
|
||||
|
||||
public interface ContainerFragment {
|
||||
abstract public Integer getRegion();
|
||||
|
||||
abstract public Fragment toFragment();
|
||||
|
||||
|
||||
//Helper methods (ugly)
|
||||
//FIXME
|
||||
default void setupButton(View view, int button, View.OnClickListener onClick) {
|
||||
view.findViewById(button)
|
||||
.setOnClickListener(onClick);
|
||||
}
|
||||
|
||||
default void setupButton(View view, int button, View.OnClickListener onClick, View.OnLongClickListener onLongClick) {
|
||||
View buttonView = view.findViewById(button);
|
||||
buttonView.setOnClickListener(onClick);
|
||||
buttonView.setOnLongClickListener(onLongClick);
|
||||
}
|
||||
|
||||
default void setupButton(View view, int button, View.OnLongClickListener onLongClick) {
|
||||
view.findViewById(button)
|
||||
.setOnLongClickListener(onLongClick);
|
||||
}
|
||||
|
||||
default View.OnClickListener click(Runnable action) {
|
||||
return v -> action.run();
|
||||
}
|
||||
|
||||
default View.OnLongClickListener longClick(Runnable action) { return v -> { action.run(); return true; };}
|
||||
|
||||
//TODO: Make animation less wonky
|
||||
default void setupDragHandle(View dragHandle, View layout, Runnable closeAction) {
|
||||
final float[] dY = new float[1];
|
||||
dragHandle.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
switch (event.getActionMasked()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
dY[0] = event.getRawY() - layout.getY();
|
||||
return true;
|
||||
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
float newY = event.getRawY() - dY[0];
|
||||
if (newY >= 0) {
|
||||
layout.setY(newY);
|
||||
}
|
||||
return true;
|
||||
|
||||
case MotionEvent.ACTION_UP:
|
||||
if (layout.getY() > layout.getHeight() / 4) {
|
||||
layout.animate()
|
||||
.scaleX(0f)
|
||||
.scaleY(0f)
|
||||
.alpha(0f)
|
||||
.setDuration(300)
|
||||
.withEndAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
layout.setVisibility(View.GONE);
|
||||
closeAction.run();
|
||||
layout.setScaleX(1f);
|
||||
layout.setScaleY(1f);
|
||||
layout.setAlpha(1f);
|
||||
layout.setY(0f);
|
||||
}
|
||||
})
|
||||
.start();
|
||||
} else {
|
||||
layout.animate()
|
||||
.translationY(0f)
|
||||
.setDuration(200)
|
||||
.start();
|
||||
}
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package eu.konggdev.strikemaps.ui.fragment;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
public class FragmentEmptyPlaceholder extends Fragment {
|
||||
//:)
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
package eu.konggdev.strikemaps.ui.fragment.layout;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import eu.konggdev.strikemaps.R;
|
||||
import eu.konggdev.strikemaps.app.AppController;
|
||||
import eu.konggdev.strikemaps.helper.UserPrefsHelper;
|
||||
import eu.konggdev.strikemaps.map.overlay.overlay.LocationOverlay;
|
||||
import eu.konggdev.strikemaps.ui.fragment.popup.FragmentMapChangePopup;
|
||||
|
||||
public class FragmentLayoutControls extends Fragment implements Layout {
|
||||
AppController app;
|
||||
View rootView;
|
||||
|
||||
private final Integer region;
|
||||
|
||||
// Action definitions
|
||||
//*//
|
||||
public void notImplemented() { //Should never be called in release
|
||||
Toast.makeText(requireContext(), "Not implemented yet\nWait for release", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
public void toggleLocationService() {
|
||||
if (ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
|
||||
} else {
|
||||
app.getMap().switchOverlay(new LocationOverlay(app));
|
||||
setupView();
|
||||
}
|
||||
}
|
||||
|
||||
public void zoomToLocation() {
|
||||
if(!app.getMap().hasOverlay(LocationOverlay.class)) {
|
||||
Toast.makeText(requireContext(), "Hold to enable location", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void attributtionDialog() {
|
||||
AlertDialog dialog = new AlertDialog.Builder(app.getActivity())
|
||||
.setTitle(app.getActivity().getString(R.string.attribution_title))
|
||||
.setMessage(app.getActivity().getString(R.string.shipped_attribution))
|
||||
.setPositiveButton("OK", null).show();
|
||||
}
|
||||
//*//
|
||||
|
||||
public FragmentLayoutControls(AppController app, Integer region) {
|
||||
super(R.layout.fragment_controls);
|
||||
this.app = app;
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment toFragment() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
this.rootView = view;
|
||||
|
||||
/* Restores location enabled status from user prefs,
|
||||
TODO: Should be moved out of UI code in the future */
|
||||
if(UserPrefsHelper.persistLocationEnabled(app.getPrefs()) && UserPrefsHelper.lastLocationEnabled(app.getPrefs()) && !app.getMap().hasOverlay(LocationOverlay.class))
|
||||
toggleLocationService();
|
||||
|
||||
this.setupView();
|
||||
}
|
||||
|
||||
public void setupView() {
|
||||
if (rootView == null) return;
|
||||
setupButton(rootView, R.id.layersButton, click(() -> app.getUi().getCurrentScreen().open(new FragmentMapChangePopup(app, R.id.bottomUi))));
|
||||
setupButton(rootView, R.id.attributionButton, click(this::attributtionDialog));
|
||||
setupButton(rootView, R.id.locationButton, click(this::zoomToLocation), longClick(this::toggleLocationService));
|
||||
|
||||
//TODO
|
||||
setupButton(rootView, R.id.placesButton, click(this::notImplemented));
|
||||
setupButton(rootView, R.id.placesButton, click(this::notImplemented));
|
||||
setupButton(rootView, R.id.routeButton, click(this::notImplemented));
|
||||
setupButton(rootView, R.id.modeButton, click(this::notImplemented));
|
||||
|
||||
TextView locationServiceStatusIndicator = rootView.findViewById(R.id.locationServiceStatusIndicator);
|
||||
if (app.getMap().hasOverlay(LocationOverlay.class)) {
|
||||
locationServiceStatusIndicator.setBackgroundColor(Color.parseColor("#00FF00")); //green
|
||||
} else {
|
||||
locationServiceStatusIndicator.setBackgroundColor(Color.parseColor("#FB0303")); //red
|
||||
}
|
||||
|
||||
if(UserPrefsHelper.persistLocationEnabled(app.getPrefs()))
|
||||
UserPrefsHelper.lastLocationEnabled(app.getPrefs(), app.getMap().hasOverlay(LocationOverlay.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
|
||||
switch (requestCode) {
|
||||
case 1:
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) toggleLocationService();
|
||||
else Toast.makeText(requireContext(), "You need to grant location permission", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package eu.konggdev.strikemaps.ui.fragment.layout;
|
||||
|
||||
|
||||
import eu.konggdev.strikemaps.ui.fragment.ContainerFragment;
|
||||
|
||||
public interface Layout extends ContainerFragment {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package eu.konggdev.strikemaps.ui.fragment.layout.content;
|
||||
|
||||
import eu.konggdev.strikemaps.ui.fragment.layout.Layout;
|
||||
|
||||
public interface ContentLayout extends Layout {
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package eu.konggdev.strikemaps.ui.fragment.layout.content.main;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import eu.konggdev.strikemaps.ui.element.UIRegion;
|
||||
|
||||
import eu.konggdev.strikemaps.R;
|
||||
|
||||
public class FragmentLayoutContentMap extends Fragment implements MainContentLayout {
|
||||
View mapView;
|
||||
|
||||
public FragmentLayoutContentMap(View refMapView) {
|
||||
super(R.layout.fragment_map);
|
||||
this.mapView = refMapView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment toFragment() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
LinearLayout layout = (LinearLayout) view;
|
||||
layout.addView(mapView);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package eu.konggdev.strikemaps.ui.fragment.layout.content.main;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
public class FragmentLayoutContentSettings implements MainContentLayout {
|
||||
@Override
|
||||
public Fragment toFragment() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package eu.konggdev.strikemaps.ui.fragment.layout.content.main;
|
||||
|
||||
import eu.konggdev.strikemaps.R;
|
||||
import eu.konggdev.strikemaps.ui.fragment.layout.content.ContentLayout;
|
||||
|
||||
public interface MainContentLayout extends ContentLayout {
|
||||
default Integer getRegion() {
|
||||
return R.id.mainContentView;
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package eu.konggdev.strikemaps.ui.fragment.popup;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import eu.konggdev.strikemaps.R;
|
||||
import eu.konggdev.strikemaps.app.AppController;
|
||||
import eu.konggdev.strikemaps.helper.FileHelper;
|
||||
import eu.konggdev.strikemaps.factory.AlertDialogFactory;
|
||||
import eu.konggdev.strikemaps.map.MapComponent;
|
||||
|
||||
import eu.konggdev.strikemaps.ui.UIComponent;
|
||||
import eu.konggdev.strikemaps.ui.element.item.GenericItem;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class FragmentMapChangePopup extends Fragment implements Popup {
|
||||
@NonNull AppController app;
|
||||
@NonNull MapComponent map;
|
||||
@NonNull UIComponent ui;
|
||||
|
||||
private final Integer region;
|
||||
|
||||
public FragmentMapChangePopup(AppController app, Integer region) {
|
||||
super(R.layout.popup_map_change);
|
||||
this.app = app;
|
||||
this.map = app.getMap();
|
||||
this.ui = app.getUi();
|
||||
this.region = region;
|
||||
}
|
||||
@Override
|
||||
public Integer getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment toFragment() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
|
||||
//FIXME
|
||||
setupButton(view, R.id.closeButton, click(() -> ui.getCurrentScreen().closePopup()));
|
||||
setupDragHandle(view, view, () -> ui.getCurrentScreen().closePopup());
|
||||
String[] stylePaths = ArrayUtils.addAll(FileHelper.getAssetFiles("bundled/style", ".style.json", app), FileHelper.getUserFiles("style", ".style.json", app));
|
||||
List<View> views = new ArrayList<>();
|
||||
LinearLayout stylesLayout = view.findViewById(R.id.stylesLayout);
|
||||
for(String i : stylePaths) {
|
||||
if(i.startsWith("/storage")) stylesLayout.addView(GenericItem.fromStyle(FileHelper.loadStringFromUserFile(i), app, map).makeView(ui));
|
||||
else stylesLayout.addView(GenericItem.fromStyle(FileHelper.loadStringFromAssetFile(i, app), app, map).makeView(ui));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package eu.konggdev.strikemaps.ui.fragment.popup;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import eu.konggdev.strikemaps.ui.fragment.ContainerFragment;
|
||||
|
||||
public interface Popup extends ContainerFragment {
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package eu.konggdev.strikemaps.ui.screen;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import eu.konggdev.strikemaps.R;
|
||||
import eu.konggdev.strikemaps.app.AppController;
|
||||
import eu.konggdev.strikemaps.ui.fragment.ContainerFragment;
|
||||
import eu.konggdev.strikemaps.ui.fragment.layout.content.main.MainContentLayout;
|
||||
import eu.konggdev.strikemaps.ui.fragment.popup.Popup;
|
||||
import eu.konggdev.strikemaps.ui.element.UIRegion;
|
||||
|
||||
public class Screen {
|
||||
@NonNull AppController app;
|
||||
public Screen(AppController app, MainContentLayout mainContent, Map<Integer, UIRegion> regions, Integer layout) {
|
||||
this.app = app;
|
||||
this.layout = layout;
|
||||
this.mainContent = mainContent;
|
||||
this.uiRegions = regions;
|
||||
}
|
||||
|
||||
private final Integer layout;
|
||||
|
||||
private MainContentLayout mainContent;
|
||||
|
||||
Map<Integer, UIRegion> uiRegions;
|
||||
public Integer popup;
|
||||
|
||||
public void open(ContainerFragment fragment) {
|
||||
if(fragment instanceof Popup && popup != null) return;
|
||||
|
||||
if(fragment instanceof Popup)
|
||||
popup = fragment.getRegion();
|
||||
|
||||
setFragment(uiRegions.get(fragment.getRegion()), fragment.toFragment());
|
||||
}
|
||||
|
||||
public void closePopup() {
|
||||
if(popup != null) {
|
||||
UIRegion popupRegion = uiRegions.get(popup);
|
||||
popupRegion.back();
|
||||
/* If newFragment is still a popup, assign the current popup value to the new fragment
|
||||
otherwise, set the current popup value to null */
|
||||
if(popupRegion.getFragment() instanceof Popup) {
|
||||
popup = popupRegion.layoutId;
|
||||
} else {
|
||||
popup = null;
|
||||
}
|
||||
setFragment(popupRegion, popupRegion.getFragment());
|
||||
}
|
||||
}
|
||||
|
||||
public void setFragment(UIRegion region, Fragment fragment) {
|
||||
if (region == null) return;
|
||||
|
||||
region.setFragment(fragment);
|
||||
fragmentTransaction(region.layoutId, fragment);
|
||||
}
|
||||
|
||||
public void fragmentTransaction(int layoutId, Fragment fragment) {
|
||||
app.getActivity().getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(layoutId, fragment)
|
||||
.commit();
|
||||
}
|
||||
|
||||
public void attachAll() {
|
||||
app.getActivity().setContentView(layout);
|
||||
fragmentTransaction(R.id.mainContentView, mainContent.toFragment());
|
||||
for (UIRegion region : uiRegions.values()) {
|
||||
setFragment(region, region.getFragment());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user