Merge branch 'bug4997'

This commit is contained in:
Robert Benedikt committed 2021-02-11 13:49:36 +01:00
commit 56888391c2
8 files changed
+115 -83

No files matched your search

@@ -23,7 +23,7 @@
<booleanAttribute key="org.eclipse.jdt.debug.ui.CONSIDER_INHERITED_MAIN" value="true"/>
<booleanAttribute key="org.eclipse.jdt.debug.ui.INCLUDE_EXTERNAL_JARS" value="true"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry containerPath=&quot;org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8&quot; javaProject=&quot;com.sap.sse.gwt&quot; path=&quot;1&quot; type=&quot;4&quot;/&gt;&#13;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/com.sap.sse.gwt/src&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/>
@@ -25,7 +25,7 @@
</listAttribute>
<booleanAttribute key="org.eclipse.jdt.debug.ui.CONSIDER_INHERITED_MAIN" value="true"/>
<booleanAttribute key="org.eclipse.jdt.debug.ui.INCLUDE_EXTERNAL_JARS" value="true"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;runtimeClasspathEntry containerPath=&quot;org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8&quot; javaProject=&quot;com.sap.sailing.gwt.ui&quot; path=&quot;1&quot; type=&quot;4&quot;/&gt;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/com.sap.sailing.gwt.ui/src/main/resources&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#10;"/>
@@ -26,7 +26,7 @@
</listAttribute>
<booleanAttribute key="org.eclipse.jdt.debug.ui.CONSIDER_INHERITED_MAIN" value="true"/>
<booleanAttribute key="org.eclipse.jdt.debug.ui.INCLUDE_EXTERNAL_JARS" value="true"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;runtimeClasspathEntry containerPath=&quot;org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8&quot; javaProject=&quot;com.sap.sailing.gwt.ui&quot; path=&quot;1&quot; type=&quot;4&quot;/&gt;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/com.sap.sailing.gwt.ui/src/main/resources&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#10;"/>
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/sap_gray_black_30"
@@ -14,7 +13,7 @@
android:textColor="?attr/black"
android:textIsSelectable="false"
android:textSize="22sp"
android:visibility="gone"/>
android:visibility="gone" />
<ListView
android:id="@android:id/list"
@@ -22,5 +21,5 @@
android:layout_height="0dp"
android:layout_weight="1"
android:divider="@null"
android:drawSelectorOnTop="true"/>
android:drawSelectorOnTop="true" />
</LinearLayout>
@@ -116,6 +116,7 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
private int branchPriority = NO_PRIORITY;
private final ItemSelectedListener<EventBase> eventSelectionListener = (sender, event) -> {
final Serializable previousSelectedEventId = mSelectedEventId;
final Serializable eventId = selectEvent(event);
// FIXME: its weird to have this button setup in here
@@ -127,13 +128,14 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
if (loginListViews != null) {
loginListViews.closeAll();
}
addCourseAreaListFragment(eventId);
if (mSelectedCourseAreaUUID == null && branchCourseAreaUuid == null) {
// send intent to open the course area selection list
Intent intent = new Intent(AppConstants.ACTION_TOGGLE);
intent.putExtra(AppConstants.EXTRA_DEFAULT, AppConstants.ACTION_TOGGLE_AREA);
BroadcastManager.getInstance(LoginActivity.this).addIntent(intent);
if (previousSelectedEventId != mSelectedEventId) {
addCourseAreaListFragment(eventId);
if (branchCourseAreaUuid == null || !mSelectedEventId.toString().equals(branchEventId)) {
// send intent to open the course area selection list
Intent intent = new Intent(AppConstants.ACTION_TOGGLE);
intent.putExtra(AppConstants.EXTRA_DEFAULT, AppConstants.ACTION_TOGGLE_AREA);
BroadcastManager.getInstance(LoginActivity.this).addIntent(intent);
}
}
};
private final ItemSelectedListener<CourseArea> courseAreaSelectionListener = (sender, courseArea) -> {
@@ -149,8 +151,7 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
loginListViews.closeAll();
}
addAreaPositionListFragment();
if (positionName == null && branchPriority == NO_PRIORITY) {
if (branchPriority == NO_PRIORITY) {
// send intent to open the position selection list
Intent intent = new Intent(AppConstants.ACTION_TOGGLE);
intent.putExtra(AppConstants.EXTRA_DEFAULT, AppConstants.ACTION_TOGGLE_POSITION);
@@ -186,20 +187,14 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
private Serializable selectEvent(EventBase event) {
final Serializable eventId = event.getId();
ExLog.i(LoginActivity.this, LogEvent.EVENT_SELECTED, eventId.toString());
mSelectedEventId = eventId;
eventName = event.getName();
// TODO: explicitly set the header text of the fragment to this name
selectEvent(eventId);
loginListViews.getEventContainer().setHeaderText(eventName);
return eventId;
}
// FIXME / DEPRECATED: only use the above setter for the whole event object
@Deprecated
private void selectEvent(Serializable eventId) {
mSelectedEventId = eventId;
ExLog.i(LoginActivity.this, LogEvent.EVENT_SELECTED, eventId.toString());
}
private void resetEvent() {
mSelectedEventId = null;
eventName = null;
@@ -246,11 +241,10 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
loginListViews.getPositionContainer().setHeaderText("");
}
private void addEventListFragment(boolean force) {
ExLog.i(this, TAG, "addEventListFragment(" + force + ")");
private void addEventListFragment() {
resetEvent();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.event_fragment, EventListFragment.newInstance(force, branchEventId));
transaction.replace(R.id.event_fragment, EventListFragment.newInstance(branchEventId));
transaction.commitAllowingStateLoss();
}
@@ -363,10 +357,6 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
return;
}
branchEventId = null;
branchCourseAreaUuid = null;
branchPriority = NO_PRIORITY;
//Non-branch link
if (!referringParams.optBoolean(Clicked_Branch_Link.getKey())) {
handleLegacyStart();
@@ -472,6 +462,9 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
if (Intent.ACTION_VIEW.equals(action)) {
final Uri uri = getIntent().getData();
if (uri != null && TextUtils.equals(uri.getPath(), "/apps/com.sap.sailing.racecommittee.app.apk")) {
branchEventId = null;
branchCourseAreaUuid = null;
branchPriority = NO_PRIORITY;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.app_name);
if (QRHelper.with(this).saveData(getIntent().getDataString())) {
@@ -513,6 +506,7 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
private void setupDataManager() {
showProgressSpinner();
dataManager.getDataStore().reset();
String deviceConfigurationName = AppPreferences.on(getApplicationContext()).getDeviceConfigurationName();
UUID deviceConfigurationUuid = AppPreferences.on(getApplicationContext()).getDeviceConfigurationUuid();
LoaderCallbacks<?> configurationLoader = dataManager.createConfigurationLoader(deviceConfigurationName,
@@ -641,10 +635,13 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
*/
private void resetData(boolean force) {
if (force) {
if (loginListViews != null) {
loginListViews.closeAll();
}
setupDataManager();
}
slideUpBackdrop(() -> addEventListFragment(force));
slideUpBackdrop(this::addEventListFragment);
}
private class IntentReceiver extends BroadcastReceiver {
@@ -1,8 +1,6 @@
package com.sap.sailing.racecommittee.app.ui.fragments.dialogs;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
@@ -24,20 +22,17 @@ public abstract class AttachedDialogFragment extends LoggableDialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return createDialog(new AlertDialog.Builder(requireContext())
.setNegativeButton(getNegativeButtonLabel(), new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
onNegativeButton();
}
}).setPositiveButton(getPositiveButtonLabel(), new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
onPositiveButton();
}
})).create();
.setNegativeButton(getNegativeButtonLabel(), (dialog, which) -> onNegativeButton())
.setPositiveButton(getPositiveButtonLabel(), (dialog, which) -> onPositiveButton()))
.create();
}
protected void onNegativeButton() {
if (getListenerHost() != null) {
getListenerHost().getListener().onDialogNegativeButton(this);
final DialogListenerHost.DialogResultListener listener = getListenerHost().getListener();
if (listener != null) {
listener.onDialogNegativeButton(this);
}
} else {
ExLog.w(getActivity(), TAG, "Dialog host was null.");
}
@@ -45,7 +40,10 @@ public abstract class AttachedDialogFragment extends LoggableDialogFragment {
protected void onPositiveButton() {
if (getListenerHost() != null && getListenerHost().getListener() != null) {
getListenerHost().getListener().onDialogPositiveButton(this);
final DialogListenerHost.DialogResultListener listener = getListenerHost().getListener();
if (listener != null) {
listener.onDialogPositiveButton(this);
}
} else {
ExLog.w(getActivity(), TAG, "Dialog host was null.");
}
@@ -10,10 +10,15 @@ import com.sap.sailing.domain.base.EventBase;
import com.sap.sailing.racecommittee.app.AppConstants;
import com.sap.sailing.racecommittee.app.data.ReadonlyDataManager;
import com.sap.sailing.racecommittee.app.data.loaders.DataLoaderResult;
import com.sap.sailing.racecommittee.app.ui.comparators.NaturalNamedComparator;
import com.sap.sailing.racecommittee.app.ui.fragments.lists.selection.EventSelectedListenerHost;
import com.sap.sailing.racecommittee.app.ui.fragments.lists.selection.ItemSelectedListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.UUID;
public class EventListFragment extends NamedListFragment<EventBase> {
@@ -21,10 +26,9 @@ public class EventListFragment extends NamedListFragment<EventBase> {
//Only used in conjunction with a given ID in arguments
private boolean loadMore;
public static EventListFragment newInstance(boolean forceLoad, @Nullable final String id) {
public static EventListFragment newInstance(@Nullable final String id) {
final EventListFragment fragment = new EventListFragment();
final Bundle args = new Bundle();
args.putBoolean(AppConstants.ACTION_EXTRA_FORCED, forceLoad);
if (!TextUtils.isEmpty(id)) {
args.putString(AppConstants.EXTRA_EVENT_ID, id);
}
@@ -61,11 +65,37 @@ public class EventListFragment extends NamedListFragment<EventBase> {
@Override
public void onLoadSucceeded(Collection<EventBase> data, boolean isCached) {
super.onLoadSucceeded(data, isCached);
final List<EventBase> list = new ArrayList<>(data.size());
list.addAll(data);
final Comparator<EventBase> namedComparator = new NaturalNamedComparator<>();
Collections.sort(list, (event, anotherEvent) -> {
if (event.getEndDate() != null) {
if (anotherEvent.getEndDate() != null) {
return event.getEndDate().compareTo(anotherEvent.getEndDate());
}
return -1;
}
if (event.getStartDate() != null) {
if (anotherEvent.getStartDate() != null) {
return event.getStartDate().compareTo(anotherEvent.getStartDate());
}
return -1;
}
if (anotherEvent.getStartDate() != null || anotherEvent.getEndDate() != null) {
return 1;
}
final int value = namedComparator.compare(event, anotherEvent);
if (value != 0) {
return value;
}
return event.getId().toString().compareToIgnoreCase(anotherEvent.getId().toString());
});
Collections.reverse(list);
super.onLoadSucceeded(list, isCached);
final Bundle arguments = getArguments();
if (arguments != null && mSelectedIndex == -1) {
final String id = arguments.getString(AppConstants.EXTRA_EVENT_ID);
for (EventBase event : data) {
for (EventBase event : list) {
if (event.getId().toString().equals(id)) {
selectItem(event, !loadMore);
break;
@@ -76,9 +106,8 @@ public class EventListFragment extends NamedListFragment<EventBase> {
public void onExpanded() {
final Bundle arguments = getArguments();
if (arguments != null && arguments.containsKey(AppConstants.EXTRA_EVENT_ID)) {
if (arguments != null && arguments.containsKey(AppConstants.EXTRA_EVENT_ID) && !loadMore) {
loadMore = true;
arguments.putBoolean(AppConstants.ACTION_EXTRA_FORCED, true);
showProgressBar(true);
restartLoader().forceLoad();
}
@@ -16,7 +16,6 @@ import android.widget.ListView;
import com.sap.sailing.android.shared.data.http.UnauthorizedException;
import com.sap.sailing.domain.base.EventBase;
import com.sap.sailing.racecommittee.app.AppConstants;
import com.sap.sailing.racecommittee.app.R;
import com.sap.sailing.racecommittee.app.data.OnlineDataManager;
import com.sap.sailing.racecommittee.app.data.ReadonlyDataManager;
@@ -24,7 +23,6 @@ import com.sap.sailing.racecommittee.app.data.clients.LoadClient;
import com.sap.sailing.racecommittee.app.data.loaders.DataLoaderResult;
import com.sap.sailing.racecommittee.app.ui.adapters.checked.CheckedItem;
import com.sap.sailing.racecommittee.app.ui.adapters.checked.CheckedItemAdapter;
import com.sap.sailing.racecommittee.app.ui.comparators.NaturalNamedComparator;
import com.sap.sailing.racecommittee.app.ui.fragments.dialogs.DialogListenerHost;
import com.sap.sailing.racecommittee.app.ui.fragments.dialogs.FragmentAttachedDialogFragment;
import com.sap.sailing.racecommittee.app.ui.fragments.dialogs.LoadFailedDialog;
@@ -34,7 +32,6 @@ import com.sap.sse.common.Named;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
@@ -93,7 +90,7 @@ public abstract class NamedListFragment<T extends Named> extends LoggableListFra
@Override
public void onResume() {
super.onResume();
loadItems();
initLoader();
}
@Override
@@ -139,14 +136,13 @@ public abstract class NamedListFragment<T extends Named> extends LoggableListFra
public void onLoadSucceeded(Collection<T> data, boolean isCached) {
namedList.clear();
checkedItems.clear();
if (isForceLoad() && !isCached) {
if (!isCached) {
listAdapter.setCheckedPosition(-1);
mSelectedIndex = -1;
}
// TODO: Quickfix for 2889
if (data != null) {
namedList.addAll(data);
Collections.sort(namedList, new NaturalNamedComparator<>());
for (Named named : namedList) {
CheckedItem item = new CheckedItem();
item.setText(named.getName());
@@ -156,7 +152,7 @@ public abstract class NamedListFragment<T extends Named> extends LoggableListFra
listAdapter.notifyDataSetChanged();
}
if (!isForceLoad() || !isCached) {
if (!isCached) {
showProgressBar(false);
}
}
@@ -164,24 +160,46 @@ public abstract class NamedListFragment<T extends Named> extends LoggableListFra
private String getEventSubText(Named named) {
String subText = null;
if (named instanceof EventBase) {
EventBase eventBase = (EventBase) named;
final EventBase eventBase = (EventBase) named;
String dateString;
if (eventBase.getStartDate() != null && eventBase.getEndDate() != null) {
Locale locale = getResources().getConfiguration().locale;
Calendar startDate = Calendar.getInstance();
final Locale locale = getResources().getConfiguration().locale;
final int currentYear = Calendar.getInstance().get(Calendar.YEAR);
final Calendar startDate = Calendar.getInstance();
startDate.setTime(eventBase.getStartDate().asDate());
Calendar endDate = Calendar.getInstance();
final Calendar endDate = Calendar.getInstance();
endDate.setTime(eventBase.getEndDate().asDate());
String start = String.format("%s %s", startDate.getDisplayName(Calendar.MONTH, Calendar.LONG, locale),
startDate.get(Calendar.DATE));
String end = "";
if (startDate.get(Calendar.MONTH) != endDate.get(Calendar.MONTH)) {
end = endDate.getDisplayName(Calendar.MONTH, Calendar.LONG, locale);
final int startYear = startDate.get(Calendar.YEAR);
String start;
if (startYear == currentYear) {
start = String.format(
"%s %s",
startDate.getDisplayName(Calendar.MONTH, Calendar.LONG, locale),
startDate.get(Calendar.DATE)
);
} else {
start = String.format(
"%s %s %s",
startYear,
startDate.getDisplayName(Calendar.MONTH, Calendar.LONG, locale),
startDate.get(Calendar.DATE)
);
}
if (startDate.get(Calendar.MONTH) != endDate.get(Calendar.MONTH)
|| startDate.get(Calendar.DATE) != endDate.get(Calendar.DATE)) {
end += " " + endDate.get(Calendar.DATE);
final StringBuilder builder = new StringBuilder();
if (startYear != endDate.get(Calendar.YEAR)) {
builder.append(endDate.get(Calendar.YEAR))
.append(" ")
.append(endDate.getDisplayName(Calendar.MONTH, Calendar.LONG, locale))
.append(" ")
.append(endDate.get(Calendar.DATE));
} else if (startDate.get(Calendar.MONTH) != endDate.get(Calendar.MONTH)) {
builder.append(endDate.getDisplayName(Calendar.MONTH, Calendar.LONG, locale))
.append(" ")
.append(endDate.get(Calendar.DATE));
} else if (startDate.get(Calendar.DATE) != endDate.get(Calendar.DATE)) {
builder.append(endDate.get(Calendar.DATE));
}
final String end = builder.toString();
dateString = String.format("%s %s %s", start, (!TextUtils.isEmpty(end.trim())) ? "-" : "", end.trim());
subText = String.format("%s%s %s", eventBase.getVenue().getName().trim(),
(!TextUtils.isEmpty(dateString) ? ", " : ""),
@@ -203,17 +221,6 @@ public abstract class NamedListFragment<T extends Named> extends LoggableListFra
return getLoaderManager().restartLoader(0, null, createLoaderCallbacks(getDataManager()));
}
private void loadItems() {
final Loader<DataLoaderResult<Collection<T>>> loader = initLoader();
if (isForceLoad()) {
loader.forceLoad();
}
}
private boolean isForceLoad() {
return getArguments() != null && getArguments().getBoolean(AppConstants.ACTION_EXTRA_FORCED);
}
private void showLoadFailedDialog(String message) {
FragmentManager manager = getFragmentManager();
FragmentAttachedDialogFragment dialog = LoadFailedDialog.create(message);
@@ -234,9 +241,11 @@ public abstract class NamedListFragment<T extends Named> extends LoggableListFra
listAdapter.notifyDataSetChanged();
mSelectedIndex = position;
getListView().setSelection(position);
if (mSelectedIndex >= 0) {
getListView().setSelection(mSelectedIndex);
}
if (notify) {
listener.itemSelected(this, eventBase);
}
}
}
}