diff --git a/android/res/color/color_timepicker_tab.xml b/android/res/color/color_timepicker_tab.xml deleted file mode 100644 index dbb832244a..0000000000 --- a/android/res/color/color_timepicker_tab.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/android/res/layout/fragment_timetable_picker.xml b/android/res/layout/fragment_timetable_picker.xml index c704595b09..df2e1922ec 100644 --- a/android/res/layout/fragment_timetable_picker.xml +++ b/android/res/layout/fragment_timetable_picker.xml @@ -12,7 +12,7 @@ android:layout_width="match_parent" android:layout_height="@dimen/height_block_base" android:elevation="@dimen/appbar_elevation" - android:background="@android:color/white" + android:background="?android:windowBackground" app:tabGravity="fill" app:tabIndicatorColor="?colorAccent" app:tabMode="fixed" @@ -22,5 +22,5 @@ android:id="@+id/picker" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="@android:color/white"/> + android:background="?android:windowBackground"/> \ No newline at end of file diff --git a/android/res/layout/tab_timepicker.xml b/android/res/layout/tab_timepicker.xml index 23da60db86..b0598da056 100644 --- a/android/res/layout/tab_timepicker.xml +++ b/android/res/layout/tab_timepicker.xml @@ -4,6 +4,5 @@ xmlns:tools="http://schemas.android.com/tools" style="@style/MwmWidget.Tab" android:textAppearance="@style/MwmTextAppearance.Body3" - android:textColor="@color/color_timepicker_tab" tools:drawableLeft="@drawable/ic_menu_open" tools:text="Some tab"/> diff --git a/android/res/values/themes-base.xml b/android/res/values/themes-base.xml index ddd2256645..ce0cd00b8f 100644 --- a/android/res/values/themes-base.xml +++ b/android/res/values/themes-base.xml @@ -86,7 +86,7 @@ @color/bg_window_night @drawable/card_frame_night @color/bg_cards_night - @style/MwmTheme.DialogFragment.Fullscreen + @style/MwmTheme.DialogFragment.Fullscreen.Night @color/bg_statusbar_night @color/bg_primary_night diff --git a/android/src/com/mapswithme/maps/editor/HoursMinutesPickerFragment.java b/android/src/com/mapswithme/maps/editor/HoursMinutesPickerFragment.java index 46a052b54e..a729c4f677 100644 --- a/android/src/com/mapswithme/maps/editor/HoursMinutesPickerFragment.java +++ b/android/src/com/mapswithme/maps/editor/HoursMinutesPickerFragment.java @@ -4,6 +4,7 @@ import android.annotation.SuppressLint; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; +import android.content.res.ColorStateList; import android.os.Bundle; import android.support.annotation.IntRange; import android.support.annotation.NonNull; @@ -14,12 +15,14 @@ import android.support.v7.app.AlertDialog; import android.text.format.DateFormat; import android.view.LayoutInflater; import android.view.View; +import android.widget.Button; import android.widget.TextView; import android.widget.TimePicker; import com.mapswithme.maps.R; import com.mapswithme.maps.base.BaseMwmDialogFragment; import com.mapswithme.maps.editor.data.HoursMinutes; +import com.mapswithme.util.ThemeUtils; public class HoursMinutesPickerFragment extends BaseMwmDialogFragment { @@ -39,6 +42,7 @@ public class HoursMinutesPickerFragment extends BaseMwmDialogFragment private TabLayout mTabs; private int mId; + private Button mOkButton; public interface OnPickListener { @@ -64,25 +68,45 @@ public class HoursMinutesPickerFragment extends BaseMwmDialogFragment { readArgs(); final View root = createView(); - refreshPicker(); //noinspection ConstantConditions mTabs.getTabAt(mSelectedTab).select(); + final int theme = ThemeUtils.isNightTheme() ? R.style.MwmMain_DialogFragment_TimePicker_Night + : R.style.MwmMain_DialogFragment_TimePicker; + final AlertDialog dialog = new AlertDialog.Builder(getActivity(), theme) + .setView(root) + .setNegativeButton(android.R.string.cancel, null) + .setPositiveButton(android.R.string.ok, null) + .setCancelable(true) + .create(); - return new AlertDialog.Builder(getActivity(), R.style.MwmMain_DialogFragment_TimePicker) - .setView(root) - .setNegativeButton(android.R.string.cancel, null) - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() - { - @Override - public void onClick(DialogInterface dialog, int which) - { - saveHoursMinutes(mPicker.getCurrentHour(), mPicker.getCurrentMinute()); - if (getParentFragment() instanceof OnPickListener) - ((OnPickListener) getParentFragment()).onHoursMinutesPicked(mFrom, mTo, mId); - } - }) - .setCancelable(true) - .create(); + dialog.setOnShowListener(new DialogInterface.OnShowListener() + { + @Override + public void onShow(DialogInterface dialogInterface) + { + mOkButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE); + mOkButton.setOnClickListener(new View.OnClickListener() + { + @Override + public void onClick(View v) + { + if (mSelectedTab == TAB_FROM) + { + //noinspection ConstantConditions + mTabs.getTabAt(TAB_TO).select(); + return; + } + + dismiss(); + if (getParentFragment() instanceof OnPickListener) + ((OnPickListener) getParentFragment()).onHoursMinutesPicked(mFrom, mTo, mId); + } + }); + refreshPicker(); + } + }); + + return dialog; } private void readArgs() @@ -104,24 +128,29 @@ public class HoursMinutesPickerFragment extends BaseMwmDialogFragment TextView tabView = (TextView) inflater.inflate(R.layout.tab_timepicker, mTabs, false); // TODO @yunik add translations tabView.setText("From"); + final ColorStateList textColor = getResources().getColorStateList(ThemeUtils.isNightTheme() ? R.color.tab_text_night + : R.color.tab_text); + tabView.setTextColor(textColor); mTabs.addTab(mTabs.newTab().setCustomView(tabView), true); tabView = (TextView) inflater.inflate(R.layout.tab_timepicker, mTabs, false); tabView.setText("To"); + tabView.setTextColor(textColor); mTabs.addTab(mTabs.newTab().setCustomView(tabView), true); mTabs.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { + if (!isInit()) + return; + + saveHoursMinutes(); mSelectedTab = tab.getPosition(); refreshPicker(); } @Override - public void onTabUnselected(TabLayout.Tab tab) - { - saveHoursMinutes(mPicker.getCurrentHour(), mPicker.getCurrentMinute()); - } + public void onTabUnselected(TabLayout.Tab tab) {} @Override public void onTabReselected(TabLayout.Tab tab) {} @@ -129,30 +158,42 @@ public class HoursMinutesPickerFragment extends BaseMwmDialogFragment mPicker = (TimePicker) root.findViewById(R.id.picker); mPicker.setIs24HourView(DateFormat.is24HourFormat(getActivity())); - mPicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() - { - @Override - public void onTimeChanged(TimePicker view, int hourOfDay, int minute) - { - saveHoursMinutes(hourOfDay, minute); - } - }); - return root; } - private void saveHoursMinutes(int hourOfDay, int minute) + private void saveHoursMinutes() { + final HoursMinutes hoursMinutes = new HoursMinutes(mPicker.getCurrentHour(), mPicker.getCurrentMinute()); if (mSelectedTab == TAB_FROM) - mFrom = new HoursMinutes(hourOfDay, minute); + mFrom = hoursMinutes; else - mTo = new HoursMinutes(hourOfDay, minute); + mTo = hoursMinutes; + } + + private boolean isInit() + { + return mOkButton != null && mPicker != null; } private void refreshPicker() { - final HoursMinutes hoursMinutes = mSelectedTab == TAB_FROM ? mFrom : mTo; + if (!isInit()) + return; + + HoursMinutes hoursMinutes; + int okBtnRes; + if (mSelectedTab == TAB_FROM) + { + hoursMinutes = mFrom; + okBtnRes = R.string.whats_new_next_button; + } + else + { + hoursMinutes = mTo; + okBtnRes = R.string.ok; + } mPicker.setCurrentMinute((int) hoursMinutes.minutes); mPicker.setCurrentHour((int) hoursMinutes.hours); + mOkButton.setText(okBtnRes); } }