forked from organicmaps/organicmaps-tmp
[android] fix to exclude corruption of advanced opening hours (simple mode is disabled for advanced opening hours).
This commit is contained in:
parent
ac786cbafe
commit
8f79ba4244
9 changed files with 139 additions and 37 deletions
|
@ -2,7 +2,8 @@
|
|||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/fragment_container"
|
||||
|
|
|
@ -71,12 +71,10 @@
|
|||
|
||||
<style name="MwmTheme.EditorActivity">
|
||||
<item name="android:timePickerStyle" tools:targetApi="lollipop">@style/MwmWidget.Editor.TimePicker</item>
|
||||
<item name="android:windowSoftInputMode">stateUnspecified|adjustResize</item>
|
||||
</style>
|
||||
|
||||
<style name="MwmTheme.Night.EditorActivity">
|
||||
<item name="android:timePickerStyle" tools:targetApi="lollipop">@style/MwmWidget.Editor.TimePicker</item>
|
||||
<item name="android:windowSoftInputMode">stateUnspecified|adjustResize</item>
|
||||
</style>
|
||||
|
||||
<style name="MwmTheme.DialogFragment.TitleStyle" parent="Base.DialogWindowTitle.AppCompat">
|
||||
|
|
|
@ -4,6 +4,8 @@ import android.os.Bundle;
|
|||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -13,21 +15,22 @@ import android.widget.TextView;
|
|||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmFragment;
|
||||
import com.mapswithme.maps.editor.data.Timetable;
|
||||
import com.mapswithme.util.Constants;
|
||||
import com.mapswithme.util.Graphics;
|
||||
import com.mapswithme.util.InputUtils;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
public class AdvancedTimetableFragment extends BaseMwmFragment
|
||||
implements View.OnClickListener,
|
||||
TimetableProvider
|
||||
implements View.OnClickListener, TimetableProvider
|
||||
{
|
||||
private boolean mIsExampleShown;
|
||||
private EditText mInput;
|
||||
private WebView mExample;
|
||||
private TextView mExamplesTitle;
|
||||
@Nullable
|
||||
private String mInitTimetables;
|
||||
private TextView mExamplesTitle;
|
||||
@Nullable
|
||||
TimetableChangedListener mListener;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
|
@ -60,6 +63,7 @@ public class AdvancedTimetableFragment extends BaseMwmFragment
|
|||
mExample.loadUrl(Constants.Url.OPENING_HOURS_MANUAL);
|
||||
mExamplesTitle = (TextView) view.findViewById(R.id.tv__examples_title);
|
||||
setExampleDrawables(R.drawable.ic_type_text, R.drawable.ic_expand_more);
|
||||
setTextChangedListener(mInput, mListener);
|
||||
}
|
||||
|
||||
private void showExample(boolean show)
|
||||
|
@ -93,6 +97,7 @@ public class AdvancedTimetableFragment extends BaseMwmFragment
|
|||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getTimetables()
|
||||
{
|
||||
|
@ -108,7 +113,39 @@ public class AdvancedTimetableFragment extends BaseMwmFragment
|
|||
|
||||
private void refreshTimetables()
|
||||
{
|
||||
if (mInput != null && mInitTimetables != null)
|
||||
mInput.setText(mInitTimetables);
|
||||
if (mInput == null || mInitTimetables == null)
|
||||
return;
|
||||
|
||||
mInput.setText(mInitTimetables);
|
||||
mInput.requestFocus();
|
||||
InputUtils.showKeyboard(mInput);
|
||||
}
|
||||
|
||||
void setTimetableChangedListener(@NonNull TimetableChangedListener listener)
|
||||
{
|
||||
mListener = listener;
|
||||
setTextChangedListener(mInput, mListener);
|
||||
}
|
||||
|
||||
private static void setTextChangedListener(@Nullable EditText input,
|
||||
@Nullable TimetableChangedListener listener)
|
||||
{
|
||||
if (input == null || listener == null)
|
||||
return;
|
||||
|
||||
input.addTextChangedListener(new TextWatcher()
|
||||
{
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s)
|
||||
{
|
||||
listener.onTimetableChanged(s.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,12 @@ package com.mapswithme.maps.editor;
|
|||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.StyleRes;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmFragmentActivity;
|
||||
import com.mapswithme.util.ThemeUtils;
|
||||
|
||||
public class EditorActivity extends BaseMwmFragmentActivity
|
||||
{
|
||||
|
@ -22,4 +25,17 @@ public class EditorActivity extends BaseMwmFragmentActivity
|
|||
final Intent intent = new Intent(activity, EditorActivity.class);
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@StyleRes
|
||||
public int getThemeResourceId(@NonNull String theme)
|
||||
{
|
||||
if (ThemeUtils.isDefaultTheme(theme))
|
||||
return R.style.MwmTheme_EditorActivity;
|
||||
|
||||
if (ThemeUtils.isNightTheme(theme))
|
||||
return R.style.MwmTheme_Night_EditorActivity;
|
||||
|
||||
throw new IllegalArgumentException("Attempt to apply unsupported theme: " + theme);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -337,16 +337,19 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
|
|||
|
||||
private void refreshOpeningTime()
|
||||
{
|
||||
final Timetable[] timetables = OpeningHours.nativeTimetablesFromString(Editor.nativeGetOpeningHours());
|
||||
if (timetables == null)
|
||||
final String openingHours = Editor.nativeGetOpeningHours();
|
||||
if (TextUtils.isEmpty(openingHours) || !OpeningHours.nativeIsTimetableStringValid(openingHours))
|
||||
{
|
||||
UiUtils.show(mEmptyOpeningHours);
|
||||
UiUtils.hide(mOpeningHours, mEditOpeningHours);
|
||||
}
|
||||
else
|
||||
{
|
||||
final Timetable[] timetables = OpeningHours.nativeTimetablesFromString(openingHours);
|
||||
String content = timetables == null ? openingHours
|
||||
: TimeFormatUtils.formatTimetables(timetables);
|
||||
UiUtils.hide(mEmptyOpeningHours);
|
||||
UiUtils.setTextAndShow(mOpeningHours, TimeFormatUtils.formatTimetables(timetables));
|
||||
UiUtils.setTextAndShow(mOpeningHours, content);
|
||||
UiUtils.show(mEditOpeningHours);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,6 +66,7 @@ class SimpleTimetableAdapter extends RecyclerView.Adapter<SimpleTimetableAdapter
|
|||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getTimetables()
|
||||
{
|
||||
|
|
|
@ -47,6 +47,7 @@ public class SimpleTimetableFragment extends BaseMwmRecyclerFragment<SimpleTimet
|
|||
super.onViewCreated(view, savedInstanceState);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getTimetables()
|
||||
{
|
||||
|
@ -54,7 +55,7 @@ public class SimpleTimetableFragment extends BaseMwmRecyclerFragment<SimpleTimet
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setTimetables(String timetables)
|
||||
public void setTimetables(@Nullable String timetables)
|
||||
{
|
||||
mInitTimetables = timetables;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package com.mapswithme.maps.editor;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
interface TimetableChangedListener
|
||||
{
|
||||
void onTimetableChanged(@Nullable String timetable);
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package com.mapswithme.maps.editor;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
@ -11,13 +12,16 @@ import android.text.TextUtils;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmFragment;
|
||||
import com.mapswithme.maps.base.OnBackPressListener;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
public class TimetableContainerFragment extends BaseMwmFragment implements OnBackPressListener
|
||||
public class TimetableContainerFragment extends BaseMwmFragment implements OnBackPressListener,
|
||||
TimetableChangedListener
|
||||
{
|
||||
public static final String EXTRA_TIME = "Time";
|
||||
|
||||
|
@ -36,12 +40,27 @@ public class TimetableContainerFragment extends BaseMwmFragment implements OnBac
|
|||
String getFragmentClassname() { return AdvancedTimetableFragment.class.getName(); }
|
||||
@StringRes
|
||||
int getSwitchButtonLabel() { return R.string.editor_time_simple; }
|
||||
|
||||
void setTimetableChangedListener(@NonNull Fragment fragment,
|
||||
@NonNull TimetableChangedListener listener)
|
||||
{
|
||||
((AdvancedTimetableFragment) fragment).setTimetableChangedListener(listener);
|
||||
}
|
||||
};
|
||||
|
||||
@NonNull
|
||||
abstract String getFragmentClassname();
|
||||
@StringRes
|
||||
abstract int getSwitchButtonLabel();
|
||||
void setTimetableChangedListener(@NonNull Fragment fragment,
|
||||
@NonNull TimetableChangedListener listener)
|
||||
{
|
||||
}
|
||||
@NonNull
|
||||
static TimetableProvider getTimetableProvider(@NonNull Fragment fragment)
|
||||
{
|
||||
return (TimetableProvider) fragment;
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -67,13 +86,22 @@ public class TimetableContainerFragment extends BaseMwmFragment implements OnBac
|
|||
{
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
||||
|
||||
initViews(view);
|
||||
mMode = Mode.ADVANCED;
|
||||
switchMode();
|
||||
|
||||
final Bundle args = getArguments();
|
||||
if (args != null && mTimetableProvider != null && !TextUtils.isEmpty(args.getString(EXTRA_TIME)))
|
||||
mTimetableProvider.setTimetables(args.getString(EXTRA_TIME));
|
||||
String time = null;
|
||||
if (args != null)
|
||||
time = args.getString(EXTRA_TIME);
|
||||
|
||||
// Show Simple fragment when opening hours can be represented by UI.
|
||||
if (TextUtils.isEmpty(time) || OpeningHours.nativeTimetablesFromString(time) != null)
|
||||
setMode(Mode.SIMPLE, time);
|
||||
else
|
||||
setMode(Mode.ADVANCED, time);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -85,10 +113,12 @@ public class TimetableContainerFragment extends BaseMwmFragment implements OnBac
|
|||
return mTimetableProvider.getTimetables();
|
||||
}
|
||||
|
||||
private void initViews(View root)
|
||||
@Override
|
||||
public void onTimetableChanged(@Nullable String timetable)
|
||||
{
|
||||
mSwitchMode = root.findViewById(R.id.tv__mode_switch);
|
||||
mSwitchMode.setOnClickListener(v -> switchMode());
|
||||
UiUtils.showIf(TextUtils.isEmpty(timetable)
|
||||
|| OpeningHours.nativeTimetablesFromString(timetable) != null,
|
||||
mSwitchMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -97,24 +127,18 @@ public class TimetableContainerFragment extends BaseMwmFragment implements OnBac
|
|||
return false;
|
||||
}
|
||||
|
||||
private void switchMode()
|
||||
private void initViews(@NonNull View root)
|
||||
{
|
||||
switch (mMode)
|
||||
{
|
||||
case SIMPLE:
|
||||
setMode(Mode.ADVANCED);
|
||||
break;
|
||||
case ADVANCED:
|
||||
setMode(Mode.SIMPLE);
|
||||
break;
|
||||
}
|
||||
mSwitchMode = root.findViewById(R.id.tv__mode_switch);
|
||||
mSwitchMode.setOnClickListener(v -> switchMode());
|
||||
}
|
||||
|
||||
private void setMode(Mode mode)
|
||||
private void switchMode()
|
||||
{
|
||||
final String filledTimetables = mTimetableProvider != null ? mTimetableProvider.getTimetables()
|
||||
: OpeningHours.nativeTimetablesToString(OpeningHours.nativeGetDefaultTimetables());
|
||||
if (!OpeningHours.nativeIsTimetableStringValid(filledTimetables))
|
||||
: null;
|
||||
|
||||
if (filledTimetables != null && !OpeningHours.nativeIsTimetableStringValid(filledTimetables))
|
||||
{
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity == null)
|
||||
|
@ -127,6 +151,19 @@ public class TimetableContainerFragment extends BaseMwmFragment implements OnBac
|
|||
return;
|
||||
}
|
||||
|
||||
switch (mMode)
|
||||
{
|
||||
case SIMPLE:
|
||||
setMode(Mode.ADVANCED, filledTimetables);
|
||||
break;
|
||||
case ADVANCED:
|
||||
setMode(Mode.SIMPLE, filledTimetables);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void setMode(@NonNull Mode mode, @Nullable String timetables)
|
||||
{
|
||||
mMode = mode;
|
||||
mSwitchMode.setText(mMode.getSwitchButtonLabel());
|
||||
|
||||
|
@ -134,8 +171,8 @@ public class TimetableContainerFragment extends BaseMwmFragment implements OnBac
|
|||
mFragments[mMode.ordinal()] = Fragment.instantiate(getActivity(), mMode.getFragmentClassname());
|
||||
Fragment fragment = mFragments[mMode.ordinal()];
|
||||
getChildFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment).commit();
|
||||
|
||||
mTimetableProvider = (TimetableProvider) fragment;
|
||||
mTimetableProvider.setTimetables(filledTimetables);
|
||||
mMode.setTimetableChangedListener(fragment, this);
|
||||
mTimetableProvider = Mode.getTimetableProvider(fragment);
|
||||
mTimetableProvider.setTimetables(timetables);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue