mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-27 06:17:27 +00:00
saving course UUID between screen rotations
This commit is contained in:
1 parent
f1652ca0e5
commit
4e6cc2fdda
2 files changed
+81
-92
No files matched your search
+30
-60
@@ -2,6 +2,7 @@ package com.sap.sailing.racecommittee.app.ui.activities;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentTransaction;
|
||||
@@ -9,10 +10,10 @@ import android.app.LoaderManager.LoaderCallbacks;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.PersistableBundle;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -44,7 +45,9 @@ import com.sap.sailing.racecommittee.app.utils.autoupdate.AutoUpdater;
|
||||
|
||||
|
||||
public class LoginActivity extends BaseActivity implements EventSelectedListenerHost, CourseAreaSelectedListenerHost, PositionSelectedListenerHost {
|
||||
private final static String CourseAreaListFragmentTag = "CourseAreaListFragmentTag";
|
||||
|
||||
|
||||
private final static String CourseAreaListFragmentTag = "CourseAreaListFragmentTag";
|
||||
private final static String AreaPositionListFragmentTag = "AreaPositionListFragmentTag";
|
||||
|
||||
private final static String TAG = LoginActivity.class.getName();
|
||||
@@ -64,10 +67,10 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
|
||||
final Serializable eventId = event.getId();
|
||||
ExLog.i(LoginActivity.this, LogEvent.EVENT_SELECTED, eventId.toString());
|
||||
|
||||
setProgressBarIndeterminateVisibility(true);
|
||||
//setProgressBarIndeterminateVisibility(true);
|
||||
final ProgressDialog progressDialog = new ProgressDialog(LoginActivity.this);
|
||||
progressDialog.setMessage(getString(R.string.loading_configuration));
|
||||
progressDialog.setCancelable(false);
|
||||
//progressDialog.setCancelable(false);
|
||||
progressDialog.setIndeterminate(true);
|
||||
progressDialog.show();
|
||||
|
||||
@@ -131,6 +134,7 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
|
||||
private Serializable mSelectedEvent;
|
||||
|
||||
private final int RQS_GooglePlayServices = 1;
|
||||
private UUID mSelectedCourseAreaUUID;
|
||||
|
||||
public LoginActivity() {
|
||||
// mLoginDialog = new LoginDialog();
|
||||
@@ -176,52 +180,6 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
|
||||
}
|
||||
|
||||
|
||||
// @Override
|
||||
// public DialogResultListener getListener() {
|
||||
// return new DialogResultListener() {
|
||||
//
|
||||
// @Override
|
||||
// public void onDialogNegativeButton(AttachedDialogFragment dialog) {
|
||||
// /* nothing here... */
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onDialogPositiveButton(AttachedDialogFragment dialog) {
|
||||
// // We have to take the passed instance, LoginActivity.this might be a new instance!
|
||||
// LoginDialog localLoginDialog = (LoginDialog) dialog;
|
||||
// switch (localLoginDialog.getSelectedLoginType()) {
|
||||
// case OFFICER:
|
||||
// ExLog.i(LoginActivity.this, TAG, "Communication with backend is active.");
|
||||
// preferences.setSendingActive(true);
|
||||
// break;
|
||||
// case VIEWER:
|
||||
// ExLog.i(LoginActivity.this, TAG, "Communication with backend is inactive.");
|
||||
// preferences.setSendingActive(false);
|
||||
// break;
|
||||
// default:
|
||||
// ExLog.i(LoginActivity.this, TAG, "An invalid log type, e.g. NONE, was selected");
|
||||
// Toast.makeText(LoginActivity.this, getString(R.string.please_select_a_login_type),
|
||||
// Toast.LENGTH_LONG).show();
|
||||
// return;
|
||||
// }
|
||||
// preferences.setAuthor(localLoginDialog.getAuthor());
|
||||
//
|
||||
// if (mSelectedCourseArea == null) {
|
||||
// Toast.makeText(LoginActivity.this, "The selected course area was lost.", Toast.LENGTH_LONG).show();
|
||||
// ExLog.e(LoginActivity.this, TAG,
|
||||
// "Course area reference was not set - cannot start racing activity.");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// Intent message = new Intent(LoginActivity.this, RacingActivity.class);
|
||||
// message.putExtra(AppConstants.COURSE_AREA_UUID_KEY, mSelectedCourseArea.getId());
|
||||
// message.putExtra(AppConstants.EventIdTag, mSelectedEvent);
|
||||
// fadeActivity(message);
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
@@ -244,11 +202,30 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
|
||||
if (savedInstanceState == null) {
|
||||
ExLog.i(this, TAG, "Seems to be first start. Creating event fragment.");
|
||||
addEventListFragment();
|
||||
} else {
|
||||
long uuidMost = savedInstanceState.getLong("courseUUIDMost", -1);
|
||||
long uuidLeast = savedInstanceState.getLong("courseUUIDLeast", -1);
|
||||
if ( uuidMost != -1 && uuidLeast != -1 ){
|
||||
mSelectedCourseAreaUUID = new UUID(uuidMost, uuidLeast);
|
||||
}
|
||||
}
|
||||
|
||||
new AutoUpdater(this).notifyAfterUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState,
|
||||
PersistableBundle outPersistentState) {
|
||||
if ( mSelectedCourseAreaUUID != null ) {
|
||||
outState.putLong("courseUUIDMost", mSelectedCourseAreaUUID.getMostSignificantBits());
|
||||
outState.putLong("courseUUIDLeast", mSelectedCourseAreaUUID.getLeastSignificantBits());
|
||||
|
||||
}
|
||||
|
||||
super.onSaveInstanceState(outState, outPersistentState);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean onReset() {
|
||||
Fragment courseAreaFragment = getFragmentManager().findFragmentByTag(CourseAreaListFragmentTag);
|
||||
@@ -272,6 +249,7 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
|
||||
|
||||
private void selectCourseArea(CourseArea courseArea) {
|
||||
mSelectedCourseArea = courseArea;
|
||||
mSelectedCourseAreaUUID = courseArea.getId();
|
||||
showAreaPositionListFragment();
|
||||
//mLoginDialog.show(getFragmentManager(), "LoginDialog");
|
||||
}
|
||||
@@ -297,26 +275,18 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
|
||||
addAreaPositionListFragment();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// public interface AreaPosition extends Named, WithID, IsManagedBySharedDomainFactory {
|
||||
// UUID getId();
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
public void onPositionSelected(LoginType type) {
|
||||
|
||||
if (mSelectedCourseArea == null) {
|
||||
if (mSelectedCourseAreaUUID == null) {
|
||||
Toast.makeText(LoginActivity.this, "The selected course area was lost.", Toast.LENGTH_LONG).show();
|
||||
ExLog.e(LoginActivity.this, TAG,
|
||||
"Course area reference was not set - cannot start racing activity.");
|
||||
return;
|
||||
}
|
||||
|
||||
Intent message = new Intent(LoginActivity.this, RacingActivity.class);
|
||||
message.putExtra(AppConstants.COURSE_AREA_UUID_KEY, mSelectedCourseArea.getId());
|
||||
message.putExtra(AppConstants.COURSE_AREA_UUID_KEY, mSelectedCourseAreaUUID );
|
||||
message.putExtra(AppConstants.EventIdTag, mSelectedEvent);
|
||||
fadeActivity(message);
|
||||
}
|
||||
|
||||
+51
-32
@@ -17,7 +17,6 @@ import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.sap.sailing.racecommittee.app.AppPreferences;
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
import com.sap.sailing.racecommittee.app.data.OnlineDataManager;
|
||||
import com.sap.sailing.racecommittee.app.data.ReadonlyDataManager;
|
||||
@@ -32,16 +31,18 @@ import com.sap.sailing.racecommittee.app.ui.fragments.dialogs.LoadFailedDialog;
|
||||
import com.sap.sailing.racecommittee.app.ui.fragments.lists.selection.ItemSelectedListener;
|
||||
import com.sap.sse.common.Named;
|
||||
|
||||
public abstract class NamedListFragment<T extends Named> extends LoggableListFragment implements LoadClient<Collection<T>>,
|
||||
DialogListenerHost {
|
||||
public abstract class NamedListFragment<T extends Named> extends LoggableListFragment implements LoadClient<Collection<T>> {
|
||||
|
||||
//private static String TAG = NamedListFragment.class.getName();
|
||||
|
||||
private ItemSelectedListener<T> listener;
|
||||
|
||||
|
||||
private ItemSelectedListener<T> listener;
|
||||
private NamedArrayAdapter<T> listAdapter;
|
||||
private TextView txt_header;
|
||||
|
||||
private View lastSelected;
|
||||
private int mSelectedIndex = -1;
|
||||
|
||||
protected ArrayList<T> namedList;
|
||||
|
||||
@@ -53,12 +54,12 @@ public abstract class NamedListFragment<T extends Named> extends LoggableListFra
|
||||
return new NamedArrayAdapter<T>(context, items);
|
||||
}
|
||||
|
||||
|
||||
/*@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.list_fragment, container, false);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
this.listener = attachListener(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View v = super.onCreateView(inflater, container, savedInstanceState);
|
||||
@@ -68,15 +69,12 @@ public abstract class NamedListFragment<T extends Named> extends LoggableListFra
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
this.listener = attachListener(activity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected abstract LoaderCallbacks<DataLoaderResult<Collection<T>>> createLoaderCallbacks(ReadonlyDataManager manager);
|
||||
|
||||
@Override
|
||||
// @SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
@@ -84,15 +82,34 @@ public abstract class NamedListFragment<T extends Named> extends LoggableListFra
|
||||
|
||||
namedList = new ArrayList<T>();
|
||||
listAdapter = createAdapter(getActivity(), namedList);
|
||||
if (savedInstanceState != null){
|
||||
mSelectedIndex = savedInstanceState.getInt("position", -1);
|
||||
if ( mSelectedIndex >= 0 ){
|
||||
listAdapter.setSelected(mSelectedIndex);
|
||||
|
||||
}
|
||||
}
|
||||
this.getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
|
||||
this.setListAdapter(listAdapter);
|
||||
getListView().setDivider(null);
|
||||
|
||||
showProgressBar(true);
|
||||
loadItems();
|
||||
|
||||
|
||||
// if ( mSelectedIndex >= 0 ){
|
||||
// listener.itemSelected(this,(T) getListView().getItemAtPosition(mSelectedIndex));
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putInt("position", mSelectedIndex);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
|
||||
private void loadItems() {
|
||||
setListShown(false);
|
||||
getLoaderManager().restartLoader(0, null, createLoaderCallbacks(OnlineDataManager.create(getActivity())));
|
||||
@@ -104,6 +121,8 @@ public abstract class NamedListFragment<T extends Named> extends LoggableListFra
|
||||
listAdapter.setSelected(position);
|
||||
setStyleClicked(v);
|
||||
|
||||
mSelectedIndex = position;
|
||||
|
||||
// this unchecked cast here seems unavoidable.
|
||||
// even SDK example code does it...
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -185,19 +204,19 @@ public abstract class NamedListFragment<T extends Named> extends LoggableListFra
|
||||
manager.beginTransaction().add(dialog, "failedDialog").commitAllowingStateLoss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DialogResultListener getListener() {
|
||||
return new DialogResultListener() {
|
||||
|
||||
@Override
|
||||
public void onDialogPositiveButton(AttachedDialogFragment dialog) {
|
||||
loadItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialogNegativeButton(AttachedDialogFragment dialog) {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
// @Override
|
||||
// public DialogResultListener getListener() {
|
||||
// return new DialogResultListener() {
|
||||
//
|
||||
// @Override
|
||||
// public void onDialogPositiveButton(AttachedDialogFragment dialog) {
|
||||
// loadItems();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onDialogNegativeButton(AttachedDialogFragment dialog) {
|
||||
//
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
}
|
||||
Reference in new issue
Block a user