feat: integrate branch.io with quick link for Race Manager

This commit is contained in:
Robert Benedikt committed 2020-12-01 11:26:10 +01:00
1 parent 07aff38b05
commit 596ac69a93
9 files changed
+275 -161

No files matched your search

@@ -11,6 +11,14 @@ public class BranchIOConstants {
public static final String OPEN_REGATTA_2_APP_BRANCHIO_PATH = "checkinUrl";
public static final String OPEN_REGATTA_3_APP_BRANCHIO = "https://sailinsight30-app.sapsailing.com/publicInvite";
public static final String OPEN_REGATTA_3_APP_BRANCHIO_PATH = "checkinUrl";
public static final String RACEMANAGER_APP_BRANCH_QUICK_LINK = "https://racemanager-app.sapsailing.com/invite";
public static final String RACEMANAGER_APP_BRANCH_PARAM_SERVER_URL = "server_url";
public static final String RACEMANAGER_APP_BRANCH_PARAM_DEVICE_CONFIG_IDENTIFIER = "device_config_identifier";
public static final String RACEMANAGER_APP_BRANCH_PARAM_DEVICE_CONFIG_UUID = "device_config_uuid";
public static final String RACEMANAGER_APP_BRANCH_PARAM_TOKEN = "token";
public static final String RACEMANAGER_APP_BRANCH_PARAM_EVENT_ID = "event_id";
public static final String RACEMANAGER_APP_BRANCH_PARAM_COURSE_AREA_UUID = "course_area_uuid";
public static final String RACEMANAGER_APP_BRANCH_PARAM_PRIORITY = "priority";
private BranchIOConstants() {
}
@@ -36,7 +36,10 @@
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDH-Dwy5yFlyBa2-VUgiZ3qGGUO8M_0MPY" />
<activity android:name=".ui.activities.LoginActivity">
<activity
android:name=".ui.activities.LoginActivity"
android:configChanges="orientation"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@@ -18,6 +18,7 @@ public class AppConstants {
public final static String KEY_RACE_FLAG = "RACE_FLAG";
public final static String EXTRA_PRIORITY = "PRIORITY";
public final static String AUTHOR_TYPE_OFFICER_VESSEL = "Race Officer on Vessel";
public final static String AUTHOR_TYPE_SHORE_CONTROL = "Shore Control";
public final static String AUTHOR_TYPE_VIEWER = "Viewer";
@@ -8,11 +8,14 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
@@ -36,6 +39,7 @@ import com.sap.sailing.android.shared.util.ViewHelper;
import com.sap.sailing.domain.base.CourseArea;
import com.sap.sailing.domain.base.EventBase;
import com.sap.sailing.domain.base.configuration.DeviceConfiguration;
import com.sap.sailing.domain.common.BranchIOConstants;
import com.sap.sailing.racecommittee.app.AppConstants;
import com.sap.sailing.racecommittee.app.AppPreferences;
import com.sap.sailing.racecommittee.app.BuildConfig;
@@ -61,12 +65,19 @@ import com.sap.sailing.racecommittee.app.utils.QRHelper;
import com.sap.sailing.racecommittee.app.utils.StringHelper;
import com.sap.sailing.racecommittee.app.utils.autoupdate.AutoUpdater;
import org.json.JSONObject;
import java.io.FileNotFoundException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.UUID;
import io.branch.referral.Branch;
import io.branch.referral.BranchError;
import static io.branch.referral.Defines.Jsonkey.Clicked_Branch_Link;
public class LoginActivity extends BaseActivity implements EventSelectedListenerHost, CourseAreaSelectedListenerHost,
PositionSelectedListenerHost, DialogListenerHost.DialogResultListener {
@@ -75,7 +86,6 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
private final static String TAG = LoginActivity.class.getName();
private final PositionListFragment positionFragment;
private View backdrop;
private LoginListViews loginListViews = null;
@@ -93,8 +103,11 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
private ReadonlyDataManager dataManager;
private View progressSpinner;
private ItemSelectedListener<EventBase> eventSelectionListener = (sender, event) -> {
private String branchEventId;
private String branchCourseAreaUuid;
private int branchPriority = 0;
private final ItemSelectedListener<EventBase> eventSelectionListener = (sender, event, expanded) -> {
final Serializable eventId = selectEvent(event);
// FIXME: its weird to have this button setup in here
@@ -108,10 +121,12 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
}
addCourseAreaListFragment(eventId);
// 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 (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);
}
};
private final ItemSelectedListener<CourseArea> courseAreaSelectionListener = (sender, courseArea, expanded) -> {
ExLog.i(LoginActivity.this, TAG, "Starting view for " + courseArea.getName());
@@ -126,15 +141,14 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
loginListViews.closeAll();
}
addAreaPositionListFragment();
// send intent to open the position selection list
Intent intent = new Intent(AppConstants.ACTION_TOGGLE);
intent.putExtra(AppConstants.EXTRA_DEFAULT, AppConstants.ACTION_TOGGLE_POSITION);
BroadcastManager.getInstance(LoginActivity.this).addIntent(intent);
};
public LoginActivity() {
positionFragment = PositionListFragment.newInstance();
}
if (positionName == null && branchPriority == 0) {
// send intent to open the position selection list
Intent intent = new Intent(AppConstants.ACTION_TOGGLE);
intent.putExtra(AppConstants.EXTRA_DEFAULT, AppConstants.ACTION_TOGGLE_POSITION);
BroadcastManager.getInstance(LoginActivity.this).addIntent(intent);
}
};
private void setupSignInButton() {
sign_in = findViewById(R.id.login_submit);
@@ -208,6 +222,8 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
private void selectPosition(LoginType type) {
preferences.setLoginType(type);
final PositionListFragment positionFragment = (PositionListFragment) getSupportFragmentManager()
.findFragmentByTag(AreaPositionListFragmentTag);
positionName = positionFragment.getAuthor().getName();
String header = StringHelper.on(this).getAuthor(positionName);
loginListViews.getPositionContainer().setHeaderText(header);
@@ -222,39 +238,40 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
loginListViews.getPositionContainer().setHeaderText("");
}
private void addAreaPositionListFragment() {
resetPosition();
updateSignInButtonState();
if (getFragmentManager().findFragmentByTag(AreaPositionListFragmentTag) == null) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.position_fragment, positionFragment, AreaPositionListFragmentTag);
transaction.commitAllowingStateLoss();
}
private void addEventListFragment(boolean force) {
ExLog.i(this, TAG, "addEventListFragment(" + force + ")");
resetEvent();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.event_fragment, EventListFragment.newInstance(force, branchEventId));
transaction.commitAllowingStateLoss();
}
private void addCourseAreaListFragment(Serializable eventId) {
resetCourseArea();
updateSignInButtonState();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.area_fragment, CourseAreaListFragment.newInstance(eventId), CourseAreaListFragmentTag);
transaction.replace(R.id.area_fragment, CourseAreaListFragment.newInstance(eventId, branchCourseAreaUuid), CourseAreaListFragmentTag);
transaction.commitAllowingStateLoss();
}
private void addEventListFragment() {
resetEvent();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.event_fragment, EventListFragment.newInstance());
transaction.commitAllowingStateLoss();
}
public ItemSelectedListener<CourseArea> getCourseAreaSelectionListener() {
return courseAreaSelectionListener;
private void addAreaPositionListFragment() {
resetPosition();
updateSignInButtonState();
if (getFragmentManager().findFragmentByTag(AreaPositionListFragmentTag) == null) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.position_fragment, PositionListFragment.newInstance(branchPriority), AreaPositionListFragmentTag);
transaction.commitAllowingStateLoss();
}
}
public ItemSelectedListener<EventBase> getEventSelectionListener() {
return eventSelectionListener;
}
public ItemSelectedListener<CourseArea> getCourseAreaSelectionListener() {
return courseAreaSelectionListener;
}
private void updateSignInButtonState() {
if (sign_in == null) {
return;
@@ -281,17 +298,6 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
}
}
String action = getIntent().getAction();
if (Intent.ACTION_VIEW.equals(action)) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.app_name);
if (QRHelper.with(this).saveData(getIntent().getData().toString())) {
builder.setMessage(getString(R.string.server_deeplink_message, preferences.getServerBaseURL()));
}
builder.setPositiveButton(android.R.string.ok, null);
builder.show();
}
// This is required to reactivate the loader manager after configuration change (screen rotation)
getLoaderManager();
@@ -324,14 +330,109 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
backdrop = findViewById(R.id.login_view_backdrop);
if (!EulaHelper.with(this).isEulaAccepted()) {
EulaHelper.with(this).showEulaDialog(null);
}
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
int smallIcon = R.drawable.ic_boat_white_24dp;
CharSequence title = getText(R.string.app_name);
NotificationHelper.prepareNotificationWith(title, largeIcon, smallIcon);
onNewIntent(getIntent());
}
private final Branch.BranchReferralInitListener branchReferralInitListener = new Branch.BranchReferralInitListener() {
@Override
public void onInitFinished(@Nullable JSONObject referringParams, @Nullable BranchError error) {
branchEventId = null;
branchCourseAreaUuid = null;
branchPriority = 0;
if (error != null) {
ExLog.i(LoginActivity.this, "BRANCH SDK", error.getMessage());
handleLegacyStart();
return;
}
if (referringParams == null || referringParams.length() == 0) {
handleLegacyStart();
return;
}
if (!referringParams.optBoolean(Clicked_Branch_Link.getKey())) {
handleLegacyStart();
return;
}
ExLog.i(LoginActivity.this, "BRANCH SDK", referringParams.toString());
final String serverUrl = referringParams.optString(BranchIOConstants.RACEMANAGER_APP_BRANCH_PARAM_SERVER_URL, null);
final String identifier = referringParams.optString(BranchIOConstants.RACEMANAGER_APP_BRANCH_PARAM_DEVICE_CONFIG_IDENTIFIER, null);
final String configUuid = referringParams.optString(BranchIOConstants.RACEMANAGER_APP_BRANCH_PARAM_DEVICE_CONFIG_UUID, null);
final String token = referringParams.optString(BranchIOConstants.RACEMANAGER_APP_BRANCH_PARAM_TOKEN, null);
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this);
final SharedPreferences.Editor editor = preferences.edit();
editor.putString(getString(R.string.preference_server_url_key), serverUrl);
editor.putString(getString(R.string.preference_identifier_key), identifier);
editor.putString(getString(R.string.preference_config_uuid_key), configUuid);
editor.putString(getString(R.string.preference_access_token_key), token);
editor.apply();
branchEventId = referringParams.optString(BranchIOConstants.RACEMANAGER_APP_BRANCH_PARAM_EVENT_ID, null);
branchCourseAreaUuid = referringParams.optString(BranchIOConstants.RACEMANAGER_APP_BRANCH_PARAM_COURSE_AREA_UUID, null);
branchPriority = referringParams.optInt(BranchIOConstants.RACEMANAGER_APP_BRANCH_PARAM_PRIORITY);
BroadcastManager.getInstance(LoginActivity.this).addIntent(new Intent(AppConstants.ACTION_CHECK_LOGIN));
}
};
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
EulaHelper.with(this).showEulaDialogIfNotAccepted(() ->
Branch.getInstance().initSession(branchReferralInitListener, getIntent().getData(), LoginActivity.this)
);
}
@Override
public void onResume() {
super.onResume();
IntentFilter filter = new IntentFilter();
filter.addAction(AppConstants.ACTION_RESET);
filter.addAction(AppConstants.ACTION_VALID_DATA);
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filter);
int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(getApplicationContext());
if (!BuildConfig.DEBUG && resultCode != ConnectionResult.SUCCESS) {
GoogleApiAvailability.getInstance().getErrorDialog(this, resultCode, 1).show();
}
}
@Override
public void onPause() {
super.onPause();
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
}
@Override
public void onStop() {
super.onStop();
dismissProgressSpinner();
}
private void handleLegacyStart() {
String action = getIntent().getAction();
if (Intent.ACTION_VIEW.equals(action)) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.app_name);
if (QRHelper.with(this).saveData(getIntent().getDataString())) {
builder.setMessage(getString(R.string.server_deeplink_message, preferences.getServerBaseURL()));
} else {
builder.setMessage(getText(R.string.error_invalid_qr_code));
}
builder.setPositiveButton(android.R.string.ok, null);
builder.show();
}
BroadcastManager.getInstance(LoginActivity.this).addIntent(new Intent(AppConstants.ACTION_CHECK_LOGIN));
}
@Override
@@ -353,35 +454,6 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
updateSignInButtonState();
}
@Override
public void onResume() {
super.onResume();
IntentFilter filter = new IntentFilter();
filter.addAction(AppConstants.ACTION_RESET);
filter.addAction(AppConstants.ACTION_VALID_DATA);
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filter);
BroadcastManager.getInstance(this).addIntent(new Intent(AppConstants.ACTION_CHECK_LOGIN));
int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(getApplicationContext());
if (!BuildConfig.DEBUG && resultCode != ConnectionResult.SUCCESS) {
GoogleApiAvailability.getInstance().getErrorDialog(this, resultCode, 1).show();
}
}
@Override
public void onPause() {
super.onPause();
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
}
@Override
public void onStop() {
super.onStop();
dismissProgressSpinner();
}
private void setupDataManager() {
showProgressSpinner();
String deviceConfigurationName = AppPreferences.on(getApplicationContext()).getDeviceConfigurationName();
@@ -518,7 +590,7 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
slideUpBackdropDelayed();
}
addEventListFragment();
addEventListFragment(force);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.area_fragment, new Fragment());
@@ -313,6 +313,8 @@ public class LoginBackdrop extends Fragment implements BackPressListener {
return;
}
//TODO Distinguish between Branch and device configuration
if (resultCode == CommonStatusCodes.SUCCESS && data != null) {
Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject);
QRHelper.with(getActivity()).saveData(barcode.displayValue);
@@ -2,7 +2,9 @@ package com.sap.sailing.racecommittee.app.ui.fragments.lists;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.text.TextUtils;
import com.sap.sailing.domain.base.CourseArea;
import com.sap.sailing.racecommittee.app.AppConstants;
@@ -19,12 +21,15 @@ import java.util.List;
public class CourseAreaListFragment extends NamedListFragment<CourseArea> {
private Serializable parentEventId;
private Serializable eventId;
public static CourseAreaListFragment newInstance(Serializable eventId) {
CourseAreaListFragment fragment = new CourseAreaListFragment();
Bundle args = new Bundle();
public static CourseAreaListFragment newInstance(Serializable eventId, @Nullable String uuid) {
final CourseAreaListFragment fragment = new CourseAreaListFragment();
final Bundle args = new Bundle();
args.putSerializable(AppConstants.EXTRA_EVENT_ID, eventId);
if (!TextUtils.isEmpty(uuid)) {
args.putSerializable(AppConstants.EXTRA_COURSE_UUID, uuid);
}
fragment.setArguments(args);
return fragment;
}
@@ -32,7 +37,10 @@ public class CourseAreaListFragment extends NamedListFragment<CourseArea> {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
parentEventId = getArguments().getSerializable(AppConstants.EXTRA_EVENT_ID);
final Bundle args = getArguments();
if (args != null) {
eventId = getArguments().getSerializable(AppConstants.EXTRA_EVENT_ID);
}
}
@Override
@@ -49,7 +57,7 @@ public class CourseAreaListFragment extends NamedListFragment<CourseArea> {
@Override
protected LoaderCallbacks<DataLoaderResult<Collection<CourseArea>>> createLoaderCallbacks(
ReadonlyDataManager manager) {
return manager.createCourseAreasLoader(parentEventId, this);
return manager.createCourseAreasLoader(eventId, this);
}
@Override
@@ -68,6 +76,17 @@ public class CourseAreaListFragment extends NamedListFragment<CourseArea> {
}
}
}
final Bundle args = getArguments();
if (args != null && mSelectedIndex == -1) {
final String uuid = args.getString(AppConstants.EXTRA_COURSE_UUID);
for (CourseArea area : data) {
if (area.getId().toString().equals(uuid)) {
selectItem(area);
break;
}
}
}
}
@Override
@@ -1,26 +1,29 @@
package com.sap.sailing.racecommittee.app.ui.fragments.lists;
import java.util.Collection;
import com.sap.sailing.domain.base.EventBase;
import com.sap.sailing.racecommittee.app.data.ReadonlyDataManager;
import com.sap.sailing.racecommittee.app.data.loaders.DataLoaderResult;
import com.sap.sailing.racecommittee.app.ui.fragments.lists.selection.EventSelectedListenerHost;
import com.sap.sailing.racecommittee.app.ui.fragments.lists.selection.ItemSelectedListener;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.text.TextUtils;
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.fragments.lists.selection.EventSelectedListenerHost;
import com.sap.sailing.racecommittee.app.ui.fragments.lists.selection.ItemSelectedListener;
import java.util.Collection;
public class EventListFragment extends NamedListFragment<EventBase> {
private static final String PARAM_EVENT_ID = "EVENT_ID";
public static EventListFragment newInstance(@Nullable final String eventId) {
public static EventListFragment newInstance(boolean forceLoad, @Nullable final String id) {
final EventListFragment fragment = new EventListFragment();
final Bundle args = new Bundle();
args.putString(PARAM_EVENT_ID, eventId);
args.putBoolean(AppConstants.ACTION_EXTRA_FORCED, forceLoad);
if (!TextUtils.isEmpty(id)) {
args.putString(AppConstants.EXTRA_EVENT_ID, id);
}
fragment.setArguments(args);
return fragment;
}
@@ -52,10 +55,11 @@ public class EventListFragment extends NamedListFragment<EventBase> {
super.onLoadSucceeded(data, isCached);
final Bundle arguments = getArguments();
if (arguments != null && mSelectedIndex == -1) {
final String eventId = arguments.getString(PARAM_EVENT_ID);
for (EventBase eventBase : data) {
if (eventBase.getId().toString().equals(eventId)) {
selectEvent(eventBase);
final String id = arguments.getString(AppConstants.EXTRA_EVENT_ID);
for (EventBase event : data) {
if (event.getId().toString().equals(id)) {
selectItem(event);
break;
}
}
}
@@ -2,8 +2,11 @@ package com.sap.sailing.racecommittee.app.ui.fragments.lists;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.LayoutInflater;
@@ -13,6 +16,7 @@ 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;
@@ -46,11 +50,8 @@ public abstract class NamedListFragment<T extends Named> extends LoggableListFra
protected abstract ItemSelectedListener<T> attachListener(Activity activity);
protected abstract LoaderCallbacks<DataLoaderResult<Collection<T>>> createLoaderCallbacks(
ReadonlyDataManager manager);
private void loadItems() {
setupLoader();
}
ReadonlyDataManager manager
);
@Override
public void onActivityCreated(Bundle savedInstanceState) {
@@ -67,8 +68,6 @@ public abstract class NamedListFragment<T extends Named> extends LoggableListFra
}
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
setListAdapter(listAdapter);
showProgressBar(true);
}
@Override
@@ -82,6 +81,13 @@ public abstract class NamedListFragment<T extends Named> extends LoggableListFra
return inflater.inflate(R.layout.list_fragment, container, false);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
showProgressBar(true);
loadItems();
}
@Override
public void onListItemClick(ListView listView, View view, int position, long id) {
listAdapter.setCheckedPosition(position);
@@ -119,7 +125,9 @@ public abstract class NamedListFragment<T extends Named> extends LoggableListFra
public void onLoadSucceeded(Collection<T> data, boolean isCached) {
namedList.clear();
checkedItems.clear();
listAdapter.setCheckedPosition(-1);
if (isForceLoad() && !isCached) {
listAdapter.setCheckedPosition(-1);
}
// TODO: Quickfix for 2889
if (data != null) {
namedList.addAll(data);
@@ -133,7 +141,9 @@ public abstract class NamedListFragment<T extends Named> extends LoggableListFra
listAdapter.notifyDataSetChanged();
}
showProgressBar(false);
if (!isForceLoad() || !isCached) {
showProgressBar(false);
}
}
private String getEventSubText(Named named) {
@@ -142,7 +152,7 @@ public abstract class NamedListFragment<T extends Named> extends LoggableListFra
EventBase eventBase = (EventBase) named;
String dateString;
if (eventBase.getStartDate() != null && eventBase.getEndDate() != null) {
Locale locale = getActivity().getResources().getConfiguration().locale;
Locale locale = getResources().getConfiguration().locale;
Calendar startDate = Calendar.getInstance();
startDate.setTime(eventBase.getStartDate().asDate());
Calendar endDate = Calendar.getInstance();
@@ -166,12 +176,6 @@ public abstract class NamedListFragment<T extends Named> extends LoggableListFra
return subText;
}
@Override
public void onStart() {
super.onStart();
loadItems();
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putInt("position", mSelectedIndex);
@@ -179,9 +183,20 @@ public abstract class NamedListFragment<T extends Named> extends LoggableListFra
super.onSaveInstanceState(outState);
}
public void setupLoader() {
getLoaderManager().initLoader(0, null, createLoaderCallbacks(OnlineDataManager.create(getActivity())))
.forceLoad();
public Loader<DataLoaderResult<Collection<T>>> getLoader() {
return getLoaderManager().initLoader(0, null, createLoaderCallbacks(OnlineDataManager.create(getActivity())));
}
private void loadItems() {
if (isForceLoad()) {
getLoader().forceLoad();
} else {
getLoader().startLoading();
}
}
private boolean isForceLoad() {
return getArguments() != null && getArguments().getBoolean(AppConstants.ACTION_EXTRA_FORCED);
}
private void showLoadFailedDialog(String message) {
@@ -201,7 +216,7 @@ public abstract class NamedListFragment<T extends Named> extends LoggableListFra
}
}
protected void selectEvent(T eventBase) {
protected void selectItem(T eventBase) {
final int position = namedList.indexOf(eventBase);
listAdapter.setCheckedPosition(position);
@@ -22,23 +22,21 @@ import java.util.List;
public class PositionListFragment extends LoggableListFragment {
private static final int PRIORITY_OFFICER_VESSEL = 1;
private static final int PRIORITY_SHORE_CONTROL = 2;
private static final int PRIORITY_VIEWER = 3;
private LogEventAuthorImpl author;
private AppPreferences preferences;
private List<LoginTypeItem> values;
private final List<LoginTypeItem> values = new ArrayList<>();
private PositionSelectedListenerHost host;
public PositionListFragment() {
values = new ArrayList<>();
}
public static final String PARAM_POSITION = "POSITION";
public static PositionListFragment newInstance(String branchPosition) {
public static PositionListFragment newInstance(int priority) {
final PositionListFragment positionListFragment = new PositionListFragment();
final Bundle params = new Bundle();
params.putString(PARAM_POSITION, branchPosition);
positionListFragment.setArguments(params);
final Bundle args = new Bundle();
args.putInt(AppConstants.EXTRA_PRIORITY, priority);
positionListFragment.setArguments(args);
return positionListFragment;
}
@@ -49,22 +47,22 @@ public class PositionListFragment extends LoggableListFragment {
preferences = AppPreferences.on(getActivity());
values.clear();
values.add(new LoginTypeItem(1, getString(R.string.login_type_officer_on_vessel),
values.add(new LoginTypeItem(PRIORITY_OFFICER_VESSEL, getString(R.string.login_type_officer_on_vessel),
AppConstants.AUTHOR_TYPE_OFFICER_VESSEL, LoginType.OFFICER));
values.add(new LoginTypeItem(2, getString(R.string.login_type_shore_control),
values.add(new LoginTypeItem(PRIORITY_SHORE_CONTROL, getString(R.string.login_type_shore_control),
AppConstants.AUTHOR_TYPE_SHORE_CONTROL, LoginType.OFFICER));
// TODO define configuration to activate super user
// values.add(new LoginTypeItem(0, getString(R.string.login_type_superuser), AppConstants.AUTHOR_TYPE_SUPERUSER,
// LoginType.OFFICER));
if (preferences.isDemoAllowed()) {
values.add(new LoginTypeItem(3, getString(R.string.login_type_viewer), AppConstants.AUTHOR_TYPE_VIEWER,
values.add(new LoginTypeItem(PRIORITY_VIEWER, getString(R.string.login_type_viewer), AppConstants.AUTHOR_TYPE_VIEWER,
LoginType.VIEWER));
}
final List<CheckedItem> items = new ArrayList<>();
for (LoginTypeItem loginType : values) {
CheckedItem item = new CheckedItem();
item.setText(loginType.mLabel);
item.setText(loginType.label);
items.add(item);
}
@@ -75,20 +73,13 @@ public class PositionListFragment extends LoggableListFragment {
final Bundle args = getArguments();
if (args != null) {
String position = args.getString(PARAM_POSITION);
try {
LoginType loginType = LoginType.valueOf(position);
int index = 0;
int pos = -1;
for (LoginTypeItem loginTypeItem : values) {
if (loginTypeItem.mType == loginType) {
pos = index;
}
index += 1;
final int priority = args.getInt(AppConstants.EXTRA_PRIORITY);
for (int i = 0; i < values.size(); i++) {
final LoginTypeItem item = values.get(i);
if (item.priority == priority) {
positionSelected(i, adapter);
break;
}
positionSelected(pos, adapter);
} catch (Throwable e) {
e.printStackTrace();
}
}
return view;
@@ -107,9 +98,9 @@ public class PositionListFragment extends LoggableListFragment {
checkedItemAdapter.notifyDataSetChanged();
}
LoginTypeItem item = values.get(position);
LoginType selectedLoginType = item.mType;
author = new LogEventAuthorImpl(item.mName, item.mPrio);
preferences.setSendingActive(item.mType == LoginType.OFFICER);
LoginType selectedLoginType = item.type;
author = new LogEventAuthorImpl(item.name, item.priority);
preferences.setSendingActive(item.type == LoginType.OFFICER);
preferences.setAuthor(author);
ExLog.i(getActivity(), PositionListFragment.class.getName(),
"Logging in as: " + selectedLoginType + "->" + author);
@@ -124,17 +115,16 @@ public class PositionListFragment extends LoggableListFragment {
private static class LoginTypeItem {
private int mPrio;
private String mLabel;
private String mName;
private LoginType mType;
private final int priority;
private final String label;
private final String name;
private final LoginType type;
LoginTypeItem(int prio, String label, String name, LoginType type) {
mPrio = prio;
mLabel = label;
mName = name;
mType = type;
LoginTypeItem(int priority, String label, String name, LoginType type) {
this.priority = priority;
this.label = label;
this.name = name;
this.type = type;
}
}
}