mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-10 14:20:55 +00:00
# merged more ui code into new app
This commit is contained in:
1 parent
816c46d437
commit
46dee69b84
18 files changed
+348
-125
No files matched your search
-6
@@ -14,12 +14,6 @@ public class CourseAreaJsonSerializer implements JsonSerializer<CourseArea> {
|
||||
JSONObject result = new JSONObject();
|
||||
|
||||
result.put(FIELD_NAME, object.getName());
|
||||
/*JSONArray races = new JSONArray();
|
||||
for (RaceDefinition race : object.getRaces())
|
||||
{
|
||||
races.add(race.getId().toString());
|
||||
}
|
||||
result.put(FIELD_RACES, races);*/
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,9 @@
|
||||
android:allowBackup="true"
|
||||
android:hardwareAccelerated="true" >
|
||||
|
||||
<activity android:name=".activities.LoginActivity">
|
||||
<activity
|
||||
android:name=".ui.activities.LoginActivity"
|
||||
android:screenOrientation="landscape">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
<string name="flag_golf">Gate start</string>
|
||||
<string name="flag_foxtrott">Fixed line start</string>
|
||||
<string name="label_login_events">Select an event:</string>
|
||||
<string name="label_login_course">Select a course area:</string>
|
||||
<string name="label_login_course_area">Select a course area:</string>
|
||||
<string name="please_pick_a_time">Please schedule the start time to</string>
|
||||
<string name="select_raceStartType">Select a race starting mode</string>
|
||||
<string name="time_until_start">Time to start (with time selected above)</string>
|
||||
@@ -82,7 +82,7 @@
|
||||
<string name="settings_category_general">General Settings</string>
|
||||
<string name="settings_category_race">Race Settings</string>
|
||||
<string name="settings_general_manageareas_header">Managed Course Areas</string>
|
||||
<string name="settings_general_manageareas_description">Enter course area names managed by you (comma-seperated)</string>
|
||||
<string name="settings_general_manageareas_description">Enter course area names managed by you (comma-separated)</string>
|
||||
<string name="settings_general_manageareas_default">Alpha</string>
|
||||
<string name="settings_advanced_service_header">Webservice URL</string>
|
||||
<string name="settings_advanced_service_description">Select the JSON Webservice URL</string>
|
||||
|
||||
+12
-4
@@ -21,10 +21,14 @@ import com.sap.sailing.server.gateway.deserialization.impl.VenueJsonDeserializer
|
||||
*/
|
||||
public class DataManager implements ReadonlyDataManager {
|
||||
|
||||
public static ReadonlyDataManager create(Context context, DataStore dataStore) {
|
||||
return new DataManager(context, dataStore);
|
||||
}
|
||||
|
||||
private Context context;
|
||||
private DataStore dataStore;
|
||||
|
||||
public DataManager(Context context, DataStore dataStore) {
|
||||
private DataManager(Context context, DataStore dataStore) {
|
||||
this.context = context;
|
||||
this.dataStore = dataStore;
|
||||
}
|
||||
@@ -33,9 +37,13 @@ public class DataManager implements ReadonlyDataManager {
|
||||
return context;
|
||||
}
|
||||
|
||||
public void getEvents(LoadClient<Collection<Event>> client) {
|
||||
public DataStore getDataStore() {
|
||||
return dataStore;
|
||||
}
|
||||
|
||||
public void loadEvents(LoadClient<Collection<Event>> client) {
|
||||
if (dataStore.getEvents().isEmpty()) {
|
||||
loadEvents(client);
|
||||
reloadEvents(client);
|
||||
} else {
|
||||
client.onLoadSucceded(dataStore.getEvents());
|
||||
}
|
||||
@@ -49,7 +57,7 @@ public class DataManager implements ReadonlyDataManager {
|
||||
}
|
||||
}
|
||||
|
||||
protected void loadEvents(LoadClient<Collection<Event>> client) {
|
||||
protected void reloadEvents(LoadClient<Collection<Event>> client) {
|
||||
DataParser<Collection<Event>> parser = new EventsDataParser(
|
||||
new EventJsonDeserializer(
|
||||
new VenueJsonDeserializer(
|
||||
|
||||
+6
@@ -3,6 +3,7 @@ package com.sap.sailing.racecommittee.app.data;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
import com.sap.sailing.domain.base.CourseArea;
|
||||
import com.sap.sailing.domain.base.Event;
|
||||
|
||||
public interface DataStore {
|
||||
@@ -12,4 +13,9 @@ public interface DataStore {
|
||||
public boolean hasEvent(Serializable id);
|
||||
public void addEvent(Event event);
|
||||
|
||||
public Collection<CourseArea> getCourseAreas(Event event);
|
||||
public CourseArea getCourseArea(Event event, String name);
|
||||
public boolean hasCourseArea(Event event, String name);
|
||||
public void addCourseArea(Event event, CourseArea courseArea);
|
||||
|
||||
}
|
||||
+51
@@ -4,7 +4,9 @@ import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.sap.sailing.domain.base.CourseArea;
|
||||
import com.sap.sailing.domain.base.Event;
|
||||
import com.sap.sailing.racecommittee.app.utils.CollectionUtils;
|
||||
|
||||
public enum InMemoryDataStore implements DataStore {
|
||||
INSTANCE;
|
||||
@@ -14,6 +16,12 @@ public enum InMemoryDataStore implements DataStore {
|
||||
private InMemoryDataStore() {
|
||||
this.eventsById = new HashMap<Serializable, Event>();
|
||||
}
|
||||
|
||||
/*
|
||||
* * * * * *
|
||||
* EVENTS *
|
||||
* * * * * *
|
||||
*/
|
||||
|
||||
public Collection<Event> getEvents() {
|
||||
return eventsById.values();
|
||||
@@ -30,4 +38,47 @@ public enum InMemoryDataStore implements DataStore {
|
||||
public void addEvent(Event event) {
|
||||
eventsById.put(event.getId(), event);
|
||||
}
|
||||
|
||||
/*
|
||||
* * * * * * * *
|
||||
* COURSE AREA *
|
||||
* * * * * * * *
|
||||
*/
|
||||
|
||||
public Collection<CourseArea> getCourseAreas(Event event) {
|
||||
if (event.getVenue() != null) {
|
||||
return CollectionUtils.newArrayList(event.getVenue().getCourseAreas());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public CourseArea getCourseArea(Event event, String name) {
|
||||
Collection<CourseArea> courseAreas = getCourseAreas(event);
|
||||
if (courseAreas != null) {
|
||||
for (CourseArea courseArea : courseAreas) {
|
||||
if (courseArea.getName().equals(name)) {
|
||||
return courseArea;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasCourseArea(Event event, String name) {
|
||||
Collection<CourseArea> courseAreas = getCourseAreas(event);
|
||||
if (courseAreas != null) {
|
||||
for (CourseArea courseArea : courseAreas) {
|
||||
if (courseArea.getName().equals(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addCourseArea(Event event, CourseArea courseArea) {
|
||||
if (event.getVenue() != null) {
|
||||
event.getVenue().addCourseArea(courseArea);
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -6,5 +6,7 @@ import com.sap.sailing.domain.base.Event;
|
||||
import com.sap.sailing.racecommittee.app.data.clients.LoadClient;
|
||||
|
||||
public interface ReadonlyDataManager {
|
||||
public void getEvents(LoadClient<Collection<Event>> client);
|
||||
public DataStore getDataStore();
|
||||
|
||||
public void loadEvents(LoadClient<Collection<Event>> client);
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.sap.sailing.racecommittee.app.activities;
|
||||
package com.sap.sailing.racecommittee.app.ui.activities;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
+36
-58
@@ -1,11 +1,11 @@
|
||||
package com.sap.sailing.racecommittee.app.activities;
|
||||
package com.sap.sailing.racecommittee.app.ui.activities;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.os.Bundle;
|
||||
@@ -17,16 +17,15 @@ import com.sap.sailing.domain.base.CourseArea;
|
||||
import com.sap.sailing.domain.base.Event;
|
||||
import com.sap.sailing.racecommittee.app.AppConstants;
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
import com.sap.sailing.racecommittee.app.data.DataManager;
|
||||
import com.sap.sailing.racecommittee.app.data.InMemoryDataStore;
|
||||
import com.sap.sailing.racecommittee.app.data.ReadonlyDataManager;
|
||||
import com.sap.sailing.racecommittee.app.data.clients.LoadClient;
|
||||
import com.sap.sailing.racecommittee.app.fragments.list.NamedListFragment.ItemSelectedListener;
|
||||
import com.sap.sailing.racecommittee.app.logging.ExLog;
|
||||
import com.sap.sailing.racecommittee.app.ui.fragments.list.EventListFragment;
|
||||
import com.sap.sailing.racecommittee.app.ui.fragments.list.selection.CourseAreaSelectedListenerHost;
|
||||
import com.sap.sailing.racecommittee.app.ui.fragments.list.selection.EventSelectedListenerHost;
|
||||
import com.sap.sailing.racecommittee.app.ui.fragments.list.selection.ItemSelectedListener;
|
||||
|
||||
public class LoginActivity extends TwoPaneActivity {
|
||||
public class LoginActivity extends TwoPaneActivity implements EventSelectedListenerHost, CourseAreaSelectedListenerHost {
|
||||
|
||||
private final static String TAG ="LoginActivity";
|
||||
private final static String TAG = LoginActivity.class.getName();
|
||||
|
||||
private enum LoginType {
|
||||
OFFICER, VIEWER;
|
||||
@@ -111,41 +110,24 @@ public class LoginActivity extends TwoPaneActivity {
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
private void addEventListFragment() {
|
||||
|
||||
ReadonlyDataManager dataManager = new DataManager(
|
||||
this,
|
||||
InMemoryDataStore.INSTANCE);
|
||||
dataManager.getEvents(new LoadClient<Collection<Event>>() {
|
||||
public void onLoadSucceded(Collection<Event> data) {
|
||||
Toast.makeText(LoginActivity.this, "Success", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
public void onLoadFailed(Exception reason) {
|
||||
Toast.makeText(LoginActivity.this, "Fail", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
|
||||
/*FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
||||
private void addEventListFragment() {
|
||||
FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
||||
transaction.add(R.id.leftContainer, new EventListFragment());
|
||||
transaction.setTransition(FragmentTransaction.TRANSIT_NONE);
|
||||
transaction.commit();*/
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
/*private void addCourseListFragment(Serializable eventId) {
|
||||
Fragment fragment = new CourseAreaListFragment();
|
||||
private void addCourseAreaListFragment(Serializable eventId) {
|
||||
Bundle args = new Bundle();
|
||||
args.putSerializable(AppConstants.EventIdTag, eventId);
|
||||
|
||||
/*Fragment fragment = new CourseAreaListFragment();
|
||||
fragment.setArguments(args);
|
||||
FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
||||
transaction.setCustomAnimations(R.animator.slide_in, R.animator.slide_out);
|
||||
transaction.replace(R.id.rightContainer, fragment);
|
||||
transaction.commit();
|
||||
ExLog.i("LoginActivity", "CourseFragment created.");
|
||||
}*/
|
||||
|
||||
public ItemSelectedListener<Event> getEventSelectionListener() {
|
||||
return eventSelectionListener;
|
||||
ExLog.i("LoginActivity", "CourseFragment created.");*/
|
||||
}
|
||||
|
||||
private ItemSelectedListener<Event> eventSelectionListener = new ItemSelectedListener<Event>() {
|
||||
@@ -153,35 +135,39 @@ public class LoginActivity extends TwoPaneActivity {
|
||||
public void itemSelected(Fragment sender, Event event) {
|
||||
Serializable eventId = event.getId();
|
||||
ExLog.i(ExLog.EVENT_SELECTED, eventId.toString(), getBaseContext());
|
||||
showCourseListFragment(eventId);
|
||||
showCourseAreaListFragment(eventId);
|
||||
}
|
||||
};
|
||||
|
||||
public ItemSelectedListener<Event> getEventSelectionListener() {
|
||||
return eventSelectionListener;
|
||||
}
|
||||
|
||||
private void showCourseListFragment(Serializable eventId) {
|
||||
private void showCourseAreaListFragment(Serializable eventId) {
|
||||
Toast.makeText(LoginActivity.this, eventId.toString(), Toast.LENGTH_LONG).show();
|
||||
getRightLayout().setVisibility(View.VISIBLE);
|
||||
/*addCourseListFragment(eventId);*/
|
||||
addCourseAreaListFragment(eventId);
|
||||
}
|
||||
|
||||
public ItemSelectedListener<CourseArea> getCourseSelectionListener() {
|
||||
return courseSelectionListener;
|
||||
}
|
||||
|
||||
private ItemSelectedListener<CourseArea> courseSelectionListener = new ItemSelectedListener<CourseArea>() {
|
||||
private ItemSelectedListener<CourseArea> courseAreaSelectionListener = new ItemSelectedListener<CourseArea>() {
|
||||
|
||||
public void itemSelected(Fragment sender, CourseArea course) {
|
||||
ExLog.i(TAG, "Starting view for " + course.getName());
|
||||
ExLog.i(ExLog.COURSE_SELECTED, course.getName(), getBaseContext());
|
||||
selectCourse(course);
|
||||
public void itemSelected(Fragment sender, CourseArea courseArea) {
|
||||
ExLog.i(TAG, "Starting view for " + courseArea.getName());
|
||||
ExLog.i(ExLog.COURSE_SELECTED, courseArea.getName(), getBaseContext());
|
||||
selectCourseArea(courseArea);
|
||||
}
|
||||
};
|
||||
|
||||
public ItemSelectedListener<CourseArea> getCourseAreaSelectionListener() {
|
||||
return courseAreaSelectionListener;
|
||||
}
|
||||
|
||||
private void selectCourse(CourseArea course) {
|
||||
selectedCourse = course;
|
||||
private void selectCourseArea(CourseArea courseArea) {
|
||||
selectedCourse = courseArea;
|
||||
showDialog(DIALOG_LOGIN_TYPE);
|
||||
}
|
||||
|
||||
private void startRaceActivity(CourseArea course) {
|
||||
private void startRaceActivity(CourseArea courseArea) {
|
||||
|
||||
switch (selectedLoginType) {
|
||||
case OFFICER:
|
||||
@@ -197,24 +183,16 @@ public class LoginActivity extends TwoPaneActivity {
|
||||
return;
|
||||
}
|
||||
|
||||
if (course == null) {
|
||||
if (courseArea == null) {
|
||||
Toast.makeText(this, "The selected course was lost.", Toast.LENGTH_LONG).show();
|
||||
ExLog.e(TAG, "Course reference was not set - cannot start racing activity.");
|
||||
return;
|
||||
}
|
||||
|
||||
Toast.makeText(this, "Course " + course.getName(), Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(this, "Course area " + courseArea.getName(), Toast.LENGTH_LONG).show();
|
||||
/*Intent message = new Intent(this, RacingActivity.class);
|
||||
message.putExtra(AppConstants.COURSE_AREA_UUID_KEY, course.getId());
|
||||
fadeActivity(message);*/
|
||||
}
|
||||
|
||||
/*public void onLoadFailed(Exception reason) {
|
||||
Toast.makeText(this, "FAIL!", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
public void onEventsLoaded(Collection<Event> events) {
|
||||
Toast.makeText(this, "SUCCESS!", Toast.LENGTH_LONG).show();
|
||||
}*/
|
||||
|
||||
}
|
||||
+2
-4
@@ -1,4 +1,4 @@
|
||||
package com.sap.sailing.racecommittee.app.activities;
|
||||
package com.sap.sailing.racecommittee.app.ui.activities;
|
||||
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
|
||||
@@ -7,17 +7,15 @@ import android.view.View;
|
||||
|
||||
/**
|
||||
* A two-pane activity - saves the visibility state of the right pane.
|
||||
*
|
||||
*/
|
||||
public class TwoPaneActivity extends BaseActivity {
|
||||
|
||||
private final static String VisibilityTag = "RIGHTVISIBILITY";
|
||||
private final static String VisibilityTag = TwoPaneActivity.class.getName() + ".rightlayoutvisibility";
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
if (savedInstanceState != null) {
|
||||
// restore visibility property of course fragment container
|
||||
if (savedInstanceState.getBoolean(VisibilityTag)) {
|
||||
getRightLayout().setVisibility(View.VISIBLE);
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.sap.sailing.racecommittee.app.ui.adapters;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.sap.sailing.domain.common.Named;
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
|
||||
/**
|
||||
* @author D053502
|
||||
*
|
||||
*/
|
||||
public class NamedArrayAdapter<T extends Named> extends ArrayAdapter<T> {
|
||||
|
||||
public NamedArrayAdapter(Context context, int textViewResourceId, List<T> namedList) {
|
||||
super(context, textViewResourceId, namedList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View view = convertView;
|
||||
if (convertView == null) {
|
||||
|
||||
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
view = inflater.inflate(R.layout.welter_one_row_no_image, /* view group */ null);
|
||||
}
|
||||
|
||||
T item = getItem(position);
|
||||
TextView title = (TextView) view.findViewById(R.id.Welter_Cell_OneRowNoImage_txtTitle);
|
||||
title.setText(item.getName());
|
||||
title.setAlpha(isEnabled(position) ? 1.0f : 0.2f);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package com.sap.sailing.racecommittee.app.ui.fragments.list;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.sap.sailing.domain.base.CourseArea;
|
||||
import com.sap.sailing.racecommittee.app.AppConstants;
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
import com.sap.sailing.racecommittee.app.data.ReadonlyDataManager;
|
||||
import com.sap.sailing.racecommittee.app.ui.fragments.list.selection.CourseAreaSelectedListenerHost;
|
||||
import com.sap.sailing.racecommittee.app.ui.fragments.list.selection.EventSelectedListenerHost;
|
||||
import com.sap.sailing.racecommittee.app.ui.fragments.list.selection.ItemSelectedListener;
|
||||
|
||||
public class CourseAreaListFragment extends NamedListFragment<CourseArea> {
|
||||
|
||||
private Serializable parentEventId;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// retrieve event id from bundle
|
||||
this.parentEventId = getArguments().getSerializable(AppConstants.EventIdTag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
loadItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemSelectedListener<CourseArea> attachListener(Activity activity) {
|
||||
if (activity instanceof EventSelectedListenerHost) {
|
||||
CourseAreaSelectedListenerHost listener = (CourseAreaSelectedListenerHost) activity;
|
||||
return listener.getCourseAreaSelectionListener();
|
||||
}
|
||||
|
||||
throw new IllegalStateException(String.format(
|
||||
"%s cannot be attached to a instance of %s",
|
||||
CourseAreaListFragment.class.getName(),
|
||||
activity.getClass().getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getHeaderText() {
|
||||
return getString(R.string.label_login_course_area);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadItems(ReadonlyDataManager manager) {
|
||||
/// TODO: load course areas..
|
||||
}
|
||||
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.sap.sailing.racecommittee.app.ui.fragments.list;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import com.sap.sailing.domain.base.Event;
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
import com.sap.sailing.racecommittee.app.data.ReadonlyDataManager;
|
||||
import com.sap.sailing.racecommittee.app.ui.fragments.list.selection.EventSelectedListenerHost;
|
||||
import com.sap.sailing.racecommittee.app.ui.fragments.list.selection.ItemSelectedListener;
|
||||
|
||||
public class EventListFragment extends NamedListFragment<Event> {
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
loadItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemSelectedListener<Event> attachListener(Activity activity) {
|
||||
if (activity instanceof EventSelectedListenerHost) {
|
||||
EventSelectedListenerHost listener = (EventSelectedListenerHost) activity;
|
||||
return listener.getEventSelectionListener();
|
||||
}
|
||||
|
||||
throw new IllegalStateException(String.format(
|
||||
"%s cannot be attached to a instance of %s",
|
||||
EventListFragment.class.getName(),
|
||||
activity.getClass().getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getHeaderText() {
|
||||
return getString(R.string.label_login_events);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadItems(ReadonlyDataManager manager) {
|
||||
manager.loadEvents(this);
|
||||
}
|
||||
|
||||
}
|
||||
+49
-48
@@ -1,12 +1,10 @@
|
||||
package com.sap.sailing.racecommittee.app.fragments.list;
|
||||
package com.sap.sailing.racecommittee.app.ui.fragments.list;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Fragment;
|
||||
import android.app.ListFragment;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
@@ -16,25 +14,36 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.sap.sailing.domain.common.Named;
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
import com.sap.sailing.racecommittee.app.data.DataManager;
|
||||
import com.sap.sailing.racecommittee.app.data.InMemoryDataStore;
|
||||
import com.sap.sailing.racecommittee.app.data.ReadonlyDataManager;
|
||||
import com.sap.sailing.racecommittee.app.data.clients.LoadClient;
|
||||
import com.sap.sailing.racecommittee.app.ui.adapters.NamedArrayAdapter;
|
||||
import com.sap.sailing.racecommittee.app.ui.fragments.list.selection.ItemSelectedListener;
|
||||
|
||||
public abstract class NamedListFragment<T extends Named> extends ListFragment/* implements BaseLoadedListener<T>*/ {
|
||||
public abstract class NamedListFragment<T extends Named> extends ListFragment implements LoadClient<Collection<T>> {
|
||||
private ItemSelectedListener<T> listener;
|
||||
private NamedArrayAdapter<T> listAdapter;
|
||||
private ReadonlyDataManager dataManager;
|
||||
|
||||
public interface ItemSelectedListener<T> {
|
||||
public void itemSelected(Fragment sender, T event);
|
||||
}
|
||||
|
||||
/*private ItemSelectedListener<T> listener;
|
||||
private NamedAdapter<T> listAdapter;
|
||||
protected ArrayList<T> namedList;
|
||||
private ResourceManager resourceManager;
|
||||
|
||||
protected String getHeaderText() {
|
||||
return "Undefined";
|
||||
protected abstract ItemSelectedListener<T> attachListener(Activity activity);
|
||||
|
||||
protected abstract String getHeaderText();
|
||||
|
||||
protected abstract void loadItems(ReadonlyDataManager manager);
|
||||
|
||||
protected NamedArrayAdapter<T> createAdapter(Context context, int layoutId, ArrayList<T> items) {
|
||||
return new NamedArrayAdapter<T>(context, layoutId, items);
|
||||
}
|
||||
|
||||
abstract protected ItemSelectedListener<T> attachListener(Activity activity);
|
||||
protected void loadItems() {
|
||||
loadItems(dataManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
@@ -47,15 +56,26 @@ public abstract class NamedListFragment<T extends Named> extends ListFragment/*
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
addHeader();
|
||||
|
||||
namedList = new ArrayList<T>();
|
||||
listAdapter = createAdapter(getActivity(), android.R.layout.simple_list_item_single_choice, namedList);
|
||||
|
||||
this.getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
|
||||
this.setListAdapter(listAdapter);
|
||||
|
||||
getActivity().setProgressBarIndeterminateVisibility(true);
|
||||
resourceManager = new ResourceManager(getActivity());
|
||||
showProgressBar(true);
|
||||
dataManager = DataManager.create(getActivity(), InMemoryDataStore.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
super.onListItemClick(l, v, position, id);
|
||||
// this unchecked cast here seems unavoidable.
|
||||
// even SDK example code does it...
|
||||
@SuppressWarnings("unchecked")
|
||||
T item = (T) l.getItemAtPosition(position);
|
||||
listener.itemSelected(this, item);
|
||||
}
|
||||
|
||||
|
||||
private void addHeader() {
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
@@ -65,35 +85,13 @@ public abstract class NamedListFragment<T extends Named> extends ListFragment/*
|
||||
textText.setText(getHeaderText());
|
||||
}
|
||||
|
||||
protected NamedAdapter<T> createAdapter(Context context, int layoutId, ArrayList<T> items) {
|
||||
return new NamedAdapter<T>(context, layoutId, items);
|
||||
}
|
||||
|
||||
protected void loadItems() {
|
||||
loadItems(resourceManager);
|
||||
}
|
||||
|
||||
protected abstract void loadItems(ResourceManager manager);
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
super.onListItemClick(l, v, position, id);
|
||||
// this unchecked cast here seems unavoidable.
|
||||
// even sdk example code does it...
|
||||
@SuppressWarnings("unchecked")
|
||||
T item = (T) l.getItemAtPosition(position);
|
||||
listener.itemSelected(this, item);
|
||||
}
|
||||
|
||||
protected void onResourcesLoaded(Collection<T> aListOfNamed) {
|
||||
public void onLoadSucceded(Collection<T> data) {
|
||||
namedList.clear();
|
||||
namedList.addAll(aListOfNamed);
|
||||
Collections.sort(namedList, new NamedComparator());
|
||||
namedList.addAll(data);
|
||||
/// TODO: Collections.sort(namedList, new NamedComparator());
|
||||
listAdapter.notifyDataSetChanged();
|
||||
Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
activity.setProgressBarIndeterminateVisibility(false);
|
||||
}
|
||||
|
||||
showProgressBar(false);
|
||||
|
||||
// we set this here to ensure that the screen is initially
|
||||
// not covered with the following text while loading
|
||||
@@ -101,12 +99,15 @@ public abstract class NamedListFragment<T extends Named> extends ListFragment/*
|
||||
}
|
||||
|
||||
public void onLoadFailed(Exception reason) {
|
||||
showProgressBar(false);
|
||||
showLoadFailedDialog(reason.getMessage());
|
||||
}
|
||||
|
||||
private void showProgressBar(boolean visible) {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
activity.setProgressBarIndeterminateVisibility(false);
|
||||
activity.setProgressBarIndeterminateVisibility(visible);
|
||||
}
|
||||
//this.setEmptyText("Load failure.");
|
||||
showLoadFailedDialog(reason.getMessage());
|
||||
}
|
||||
|
||||
private void showLoadFailedDialog(String message) {
|
||||
@@ -127,5 +128,5 @@ public abstract class NamedListFragment<T extends Named> extends ListFragment/*
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}*/
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package com.sap.sailing.racecommittee.app.ui.fragments.list.selection;
|
||||
|
||||
import com.sap.sailing.domain.base.CourseArea;
|
||||
|
||||
public interface CourseAreaSelectedListenerHost {
|
||||
public ItemSelectedListener<CourseArea> getCourseAreaSelectionListener();
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package com.sap.sailing.racecommittee.app.ui.fragments.list.selection;
|
||||
|
||||
import com.sap.sailing.domain.base.Event;
|
||||
|
||||
public interface EventSelectedListenerHost {
|
||||
public ItemSelectedListener<Event> getEventSelectionListener();
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package com.sap.sailing.racecommittee.app.ui.fragments.list.selection;
|
||||
|
||||
import android.app.Fragment;
|
||||
|
||||
public interface ItemSelectedListener<T> {
|
||||
public void itemSelected(Fragment sender, T item);
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.sap.sailing.racecommittee.app.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class CollectionUtils {
|
||||
|
||||
public static <T> ArrayList<T> newArrayList(Iterable<T> iterable) {
|
||||
ArrayList<T> list = new ArrayList<T>();
|
||||
addAll(list, iterable.iterator());
|
||||
return list;
|
||||
}
|
||||
|
||||
public static <T> void addAll(Collection<T> collection, Iterator<T> iterator) {
|
||||
while (iterator.hasNext()) {
|
||||
collection.add(iterator.next());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user