set factor fragment

This commit is contained in:
Peter Siegmund
2016-04-14 10:16:14 +02:00
parent 938affccea
commit 3dfe219137
11 changed files with 210 additions and 27 deletions
@@ -1,45 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/sap_gray_black_30">
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/sap_gray_black_30">
<com.sap.sailing.racecommittee.app.ui.layouts.HeaderLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:headerText="@string/gate_start_pathfinder" />
app:headerText="@string/race_factor"/>
<RelativeLayout
android:id="@+id/path_finder"
android:id="@+id/button_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center_vertical">
<Button
android:id="@+id/set_path_finder"
android:id="@+id/set_column_factor"
style="?attr/button"
android:layout_width="@dimen/default_button_width"
android:layout_height="@dimen/default_button_height"
android:layout_centerInParent="true"
android:layout_margin="@dimen/unscheduled_confirm_button_margin"
android:enabled="false"
android:text="@string/gate_start_set_pathfinder"
android:textSize="@dimen/textSize_18" />
android:text="@string/set_column_factor"
android:textSize="@dimen/textSize_18"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/path_finder"
android:layout_above="@id/button_bar"
android:layout_below="@id/header">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerInParent="true"
android:layout_margin="@dimen/default_margin_twice">
<com.sap.sailing.racecommittee.app.ui.layouts.FloatLabelLayout
@@ -49,15 +48,18 @@
app:floatLabelTextAppearance="?attr/floatLabel">
<EditText
android:id="@+id/pathfinder_nat"
android:id="@+id/column_factor"
style="?attr/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_gravity="center_vertical"
android:hint="@string/gate_start_nationality"
android:inputType="textCapCharacters"
android:hint="@string/race_factor"
android:inputType="numberDecimal"
android:textAppearance="?attr/textNormal"
android:textColor="?attr/white" />
android:textColor="?attr/white"/>
</com.sap.sailing.racecommittee.app.ui.layouts.FloatLabelLayout>
</RelativeLayout>
</RelativeLayout>
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/button_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center_vertical"
android:background="?attr/sap_gray_black_30">
<Button
android:id="@+id/set_column_factor"
style="?attr/buttonSolidNormal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="@dimen/unscheduled_confirm_button_margin"
android:text="@string/set_column_factor"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/button_bar"
android:background="?attr/sap_gray_black_30">
<com.sap.sailing.racecommittee.app.ui.layouts.FloatLabelLayout
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:floatLabelPaddingLeft="@dimen/float_label_padding"
app:floatLabelTextAppearance="?attr/floatLabel">
<EditText
android:id="@+id/column_factor"
style="?attr/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:hint="@string/race_factor"
android:inputType="numberDecimal"
android:textAppearance="?attr/textNormal"
android:textColor="?attr/white"/>
</com.sap.sailing.racecommittee.app.ui.layouts.FloatLabelLayout>
</RelativeLayout>
</RelativeLayout>
@@ -508,5 +508,7 @@
<string name="abort_hint">Welche laufenden Rennen möchten Sie abbrechen?</string>
<string name="abort_dismiss">Verwerfen</string>
<string name="explicit_factor">x %1$s</string>
<string name="set_column_factor">Setze Faktor</string>
<string name="set_factor_error">Beim Setzen des Faktors ist ein Fehler aufgetreten: %s</string>
</resources>
@@ -14,6 +14,7 @@
<item name="race_panel_time" type="layout">@layout/race_panel_time_xlarge</item>
<item name="race_positioning" type="layout">@layout/race_tracking_list_normal</item>
<item name="race_schedule_button" type="layout">@layout/race_schedule_button_xlarge</item>
<item name="race_column_factor" type="layout">@layout/race_column_factor_normal</item>
<item name="race_schedule_procedure_pathfinder" type="layout">@layout/race_schedule_procedure_pathfinder_xlarge</item>
<item name="race_schedule_procedure_timing" type="layout">@layout/race_schedule_procedure_timing_xlarge</item>
<item name="toolbar" type="layout">@layout/toolbar_xlarge</item>
@@ -10,6 +10,7 @@
<item name="login_listviews_button" type="layout">@layout/login_listviews_button_normal</item>
<item name="photo_list_button" type="layout">@layout/photo_list_button_normal</item>
<item name="photo_list_item" type="layout">@layout/photo_list_item_normal</item>
<item name="race_column_factor" type="layout">@layout/race_column_factor_normal</item>
<item name="race_finished" type="layout">@layout/race_finished_normal</item>
<item name="race_finished_buttons" type="layout">@layout/race_finished_buttons_hor</item>
<item name="race_finished_desc" type="layout">@layout/race_finished_desc_hor</item>
@@ -535,5 +535,7 @@
<string name="abort_hint">Which running races do you want to abort?</string>
<string name="abort_dismiss">Dismiss</string>
<string name="race_factor_format" translatable="false">x #.####</string>
<string name="set_column_factor">Set Factor</string>
<string name="set_factor_error">There was an error while setting the factor: %s</string>
</resources>
@@ -71,6 +71,7 @@ public class AppConstants {
// clears all toggle buttons
public final static String INTENT_ACTION_CLEAR_TOGGLE = PACKAGE_NAME + ".action.toggle.clear";
public final static String INTENT_ACTION_UPDATE_SCREEN = PACKAGE_NAME + ".action.update.screen";
public final static String INTENT_ACTION_SHOW_MAIN_CONTENT = PACKAGE_NAME + ".action.show.main";
public final static String INTENT_ACTION_SHOW_SUMMARY_CONTENT = PACKAGE_NAME + ".action.show.summary";
@@ -29,7 +29,6 @@ import com.sap.sailing.domain.base.configuration.DeviceConfiguration;
import com.sap.sailing.domain.base.configuration.DeviceConfigurationIdentifier;
import com.sap.sailing.domain.base.configuration.RegattaConfiguration;
import com.sap.sailing.domain.base.impl.RaceColumnFactorImpl;
import com.sap.sailing.domain.common.impl.RaceColumnConstants;
import com.sap.sailing.domain.common.racelog.RaceLogServletConstants;
import com.sap.sailing.racecommittee.app.AppConstants;
import com.sap.sailing.racecommittee.app.AppPreferences;
@@ -333,7 +332,7 @@ public class OnlineDataManager extends DataManager {
List<Util.Pair<String, Object>> params = new ArrayList<>();
if (args.getString(RACE_COLUMN) != null) {
params.add(new Util.Pair<String, Object>(RaceColumnConstants.RACE_COLUMNS, args.getString(RACE_COLUMN)));
params.add(new Util.Pair<String, Object>(RaceLogServletConstants.PARAMS_RACE_COLUMN_NAME, args.getString(RACE_COLUMN)));
}
URL url = UrlHelper.generateUrl(preferences.getServerBaseURL(), "/sailingserver/api/v1/leaderboards/" + args.getString(LEADERBOARD) + "/racecolumnfactors", params);
return new OnlineDataLoader<>(context, url, parser, handler);
@@ -141,6 +141,7 @@ public class SetupPanelFragment extends BasePanelFragment {
IntentFilter filter = new IntentFilter();
filter.addAction(AppConstants.INTENT_ACTION_TOGGLE);
filter.addAction(AppConstants.INTENT_ACTION_CLEAR_TOGGLE);
filter.addAction(AppConstants.INTENT_ACTION_UPDATE_SCREEN);
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mReceiver, filter);
sendIntent(AppConstants.INTENT_ACTION_CLEAR_TOGGLE);
@@ -203,7 +204,11 @@ public class SetupPanelFragment extends BasePanelFragment {
if (mButtonFactor != null) {
mButtonFactor.setVisibility(preferences.isRaceFactorChangeAllow() ? View.VISIBLE : View.GONE);
mButtonFactor.setPanelText(mFactorFormat.format(getRace().getExplicitFactor()));
if (getRace().getExplicitFactor() != null) {
mButtonFactor.setPanelText(mFactorFormat.format(getRace().getExplicitFactor()));
} else {
mButtonFactor.setPanelText(null);
}
}
if (mButtonCourse != null) {
@@ -557,7 +562,7 @@ public class SetupPanelFragment extends BasePanelFragment {
break;
case LEVEL_TOGGLED:
// replaceFragment(RaceFactorFragment.newInstance(BaseFragment.START_MODE_PLANNED));
replaceFragment(RaceFactorFragment.newInstance(BaseFragment.START_MODE_PLANNED));
break;
default:
@@ -657,6 +662,10 @@ public class SetupPanelFragment extends BasePanelFragment {
}
}
}
if (AppConstants.INTENT_ACTION_UPDATE_SCREEN.equals(action)) {
refreshPanel();
}
}
}
}
@@ -106,7 +106,6 @@ public class MainScheduleFragment extends BaseFragment implements View.OnClickLi
initStartTime();
initStartMode();
initFactor();
initCourse();
initWind();
lastTick = MillisecondsTimePoint.now().minus(2000);
@@ -1,16 +1,42 @@
package com.sap.sailing.racecommittee.app.ui.fragments.raceinfo;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;
import org.json.JSONObject;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import com.sap.sailing.android.shared.data.http.HttpJsonPostRequest;
import com.sap.sailing.android.shared.logging.ExLog;
import com.sap.sailing.android.shared.util.AppUtils;
import com.sap.sailing.android.shared.util.BroadcastManager;
import com.sap.sailing.android.shared.util.NetworkHelper;
import com.sap.sailing.android.shared.util.ViewHelper;
import com.sap.sailing.domain.common.impl.RaceColumnConstants;
import com.sap.sailing.domain.common.racelog.RaceLogServletConstants;
import com.sap.sailing.racecommittee.app.AppConstants;
import com.sap.sailing.racecommittee.app.R;
import com.sap.sailing.racecommittee.app.ui.layouts.HeaderLayout;
public class RaceFactorFragment extends BaseFragment {
public class RaceFactorFragment extends BaseFragment implements View.OnClickListener {
private static final String TAG = RaceFactorFragment.class.getName();
private HeaderLayout mHeader;
private EditText mFactor;
public static RaceFactorFragment newInstance(@START_MODE_VALUES int startMode) {
RaceFactorFragment fragment = new RaceFactorFragment();
@@ -22,11 +48,11 @@ public class RaceFactorFragment extends BaseFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View layout = LayoutInflater.from(getActivity()).inflate(R.layout.race_schedule_procedure_pathfinder, container, false);
final View layout = LayoutInflater.from(getActivity()).inflate(R.layout.race_column_factor, container, false);
HeaderLayout header = ViewHelper.get(layout, R.id.header);
if (header != null) {
header.setHeaderOnClickListener(new View.OnClickListener() {
mHeader = ViewHelper.get(layout, R.id.header);
if (mHeader != null) {
mHeader.setHeaderOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
goHome();
@@ -34,6 +60,97 @@ public class RaceFactorFragment extends BaseFragment {
});
}
mFactor = ViewHelper.get(layout, R.id.column_factor);
Button button = ViewHelper.get(layout, R.id.set_column_factor);
if (button != null) {
button.setOnClickListener(this);
}
return layout;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (getView() != null && getArguments() != null) {
switch (getArguments().getInt(START_MODE, START_MODE_PRESETUP)) {
case START_MODE_PLANNED:
if (AppUtils.with(getActivity()).isLand()) {
mHeader.setVisibility(View.GONE);
}
break;
default:
break;
}
}
if (mFactor != null) {
DecimalFormat format = new DecimalFormat("#.####", new DecimalFormatSymbols(Locale.US));
String explicitFactor = null;
if (getRace().getExplicitFactor() != null) {
explicitFactor = format.format(getRace().getExplicitFactor());
}
mFactor.setText(explicitFactor);
}
}
@Override
public void onClick(final View v) {
v.setEnabled(false);
final String factor = mFactor.getText().toString();
Uri.Builder uri = Uri.parse(preferences.getServerBaseURL()).buildUpon();
uri.appendPath("sailingserver");
uri.appendPath("api");
uri.appendPath("v1");
uri.appendPath("leaderboards");
uri.appendPath(getRace().getRaceGroup().getName());
uri.appendPath("racecolumnfactors");
uri.appendQueryParameter(RaceLogServletConstants.PARAMS_RACE_COLUMN_NAME, getRace().getName());
uri.appendQueryParameter(RaceColumnConstants.EXPLICIT_FACTOR, factor);
if (preferences.isSendingActive()) {
try {
final HttpJsonPostRequest request = new HttpJsonPostRequest(getActivity(), new URL(uri.toString()));
NetworkHelper.getInstance(getActivity()).executeHttpJsonRequestAsync(request, new NetworkHelper.NetworkHelperSuccessListener() {
@Override
public void performAction(JSONObject response) {
updateData(v, factor);
}
}, new NetworkHelper.NetworkHelperFailureListener() {
@Override
public void performAction(NetworkHelper.NetworkHelperError e) {
v.setEnabled(true);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppTheme_AlertDialog);
builder.setTitle(R.string.race_factor);
builder.setMessage(getActivity().getString(R.string.set_factor_error, e.getMessage()));
builder.setPositiveButton(android.R.string.ok, null);
ExLog.e(getActivity(), TAG, e.getMessage());
}
});
} catch (MalformedURLException e) {
ExLog.e(getActivity(), TAG, e.getMessage());
}
} else {
updateData(v, factor);
}
}
private void updateData(View v, String factor) {
v.setEnabled(true);
if (!TextUtils.isEmpty(factor)) {
getRace().setExplicitFactor(Double.parseDouble(factor));
}
if (isAdded()) {
BroadcastManager.getInstance(getActivity()).addIntent(new Intent(AppConstants.INTENT_ACTION_CLEAR_TOGGLE));
BroadcastManager.getInstance(getActivity()).addIntent(new Intent(AppConstants.INTENT_ACTION_SHOW_MAIN_CONTENT));
BroadcastManager.getInstance(getActivity()).addIntent(new Intent(AppConstants.INTENT_ACTION_UPDATE_SCREEN));
}
}
}