From ca112ce9779cafc622b0bd0c6256ea763d6ba83f Mon Sep 17 00:00:00 2001 From: Chumva Date: Thu, 6 Sep 2018 18:01:10 +0300 Subject: [PATCH] Add LogoutBottomSheet and improve login dialogs ui --- .../res/layout/bottom_sheet_logout.xml | 86 +++++++++++++++++++ .../res/layout/fragment_my_location_tab.xml | 4 +- OsmAnd-telegram/res/values/dimens.xml | 6 +- OsmAnd-telegram/res/values/strings.xml | 2 + .../osmand/telegram/ui/LoginDialogFragment.kt | 25 ++++-- .../osmand/telegram/ui/LogoutBottomSheet.kt | 79 +++++++++++++++++ .../telegram/ui/SettingsDialogFragment.kt | 17 +++- .../osmand/plus/osmedit/OsmEditingPlugin.java | 3 +- 8 files changed, 205 insertions(+), 17 deletions(-) create mode 100644 OsmAnd-telegram/res/layout/bottom_sheet_logout.xml create mode 100644 OsmAnd-telegram/src/net/osmand/telegram/ui/LogoutBottomSheet.kt diff --git a/OsmAnd-telegram/res/layout/bottom_sheet_logout.xml b/OsmAnd-telegram/res/layout/bottom_sheet_logout.xml new file mode 100644 index 0000000000..a8ede12784 --- /dev/null +++ b/OsmAnd-telegram/res/layout/bottom_sheet_logout.xml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml b/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml index 81d71d8bbb..edfe03a4c2 100644 --- a/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml +++ b/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml @@ -250,9 +250,9 @@ android:layout_height="wrap_content" android:layout_gravity="bottom|center_horizontal" android:background="@drawable/extended_fab_bg" - android:drawableLeft="@drawable/ic_group" + android:drawableLeft="@drawable/ic_action_share_location" android:drawablePadding="@dimen/content_padding_half" - android:drawableStart="@drawable/ic_group" + android:drawableStart="@drawable/ic_action_share_location" android:gravity="center" android:paddingLeft="32dp" android:paddingRight="32dp" diff --git a/OsmAnd-telegram/res/values/dimens.xml b/OsmAnd-telegram/res/values/dimens.xml index 319b6ff3cb..383a046ead 100644 --- a/OsmAnd-telegram/res/values/dimens.xml +++ b/OsmAnd-telegram/res/values/dimens.xml @@ -20,8 +20,8 @@ 36dp 4dp 40dp - 70dp - 85dp + 78dp + 89dp 48dp @@ -70,7 +70,7 @@ 22sp 18sp - 20sp + 22sp 32sp 16sp 14sp diff --git a/OsmAnd-telegram/res/values/strings.xml b/OsmAnd-telegram/res/values/strings.xml index 5969992d66..7bfb167654 100644 --- a/OsmAnd-telegram/res/values/strings.xml +++ b/OsmAnd-telegram/res/values/strings.xml @@ -1,4 +1,6 @@ + Are you sure you want to log out of OsmAnd Telegram? After that, you will not be able to send your position and see the locations of your contacts on the map in OsmAnd. + Logout from OsmAnd Telegram? Name By distance By name diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/LoginDialogFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/LoginDialogFragment.kt index dcf24d5f3b..dc53c85536 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/LoginDialogFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/LoginDialogFragment.kt @@ -327,16 +327,23 @@ class LoginDialogFragment : BaseDialogFragment() { val cancelButton: AppCompatImageView? = view?.findViewById(R.id.back_button) cancelButton?.visibility = if (showWelcomeDialog) View.INVISIBLE else View.VISIBLE cancelButton?.setOnClickListener { - if (loginDialogActiveType == LoginDialogType.ENTER_PHONE_NUMBER) { - showWelcomeDialog = true - val focusedView = dialog.currentFocus - if (focusedView != null) { - AndroidUtils.hideSoftKeyboard(activity!!, focusedView) + when (loginDialogActiveType) { + LoginDialogType.ENTER_PHONE_NUMBER -> { + showWelcomeDialog = true + val focusedView = dialog.currentFocus + if (focusedView != null) { + AndroidUtils.hideSoftKeyboard(activity!!, focusedView) + } + buildDialog(view) + } + LoginDialogType.GET_TELEGRAM -> { + this.loginDialogActiveType = LoginDialogType.ENTER_PHONE_NUMBER + buildDialog(view) + } + else -> { + showProgress() + getMainActivity()?.loginTelegram() } - buildDialog(view) - } else { - showProgress() - getMainActivity()?.loginTelegram() } } } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/LogoutBottomSheet.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/LogoutBottomSheet.kt new file mode 100644 index 0000000000..8e6acf2a4e --- /dev/null +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/LogoutBottomSheet.kt @@ -0,0 +1,79 @@ +package net.osmand.telegram.ui + +import android.os.Bundle +import android.support.design.widget.BottomSheetBehavior +import android.support.v4.app.DialogFragment +import android.support.v4.app.Fragment +import android.support.v4.app.FragmentManager +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import net.osmand.telegram.R +import net.osmand.telegram.ui.views.BottomSheetDialog + +class LogoutBottomSheet : DialogFragment() { + + override fun onCreateDialog(savedInstanceState: Bundle?) = BottomSheetDialog(context!!) + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + val mainView = inflater.inflate(R.layout.bottom_sheet_logout, container, false) + + mainView.findViewById(R.id.scroll_view_container).setOnClickListener { dismiss() } + + BottomSheetBehavior.from(mainView.findViewById(R.id.scroll_view)) + .setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { + + override fun onStateChanged(bottomSheet: View, newState: Int) { + if (newState == BottomSheetBehavior.STATE_HIDDEN) { + dismiss() + } + } + + override fun onSlide(bottomSheet: View, slideOffset: Float) {} + }) + + mainView.findViewById(R.id.description).text = + getString(R.string.logout_from_osmand_telegram_descr) + + mainView.findViewById(R.id.secondary_btn).apply { + setText(R.string.shared_string_cancel) + setOnClickListener { dismiss() } + } + + mainView.findViewById(R.id.primary_btn).apply { + setText(R.string.shared_string_logout) + setOnClickListener { + targetFragment?.also { target -> + target.onActivityResult(targetRequestCode, LOGOUT_REQUEST_CODE, null) + } + dismiss() + } + } + + return mainView + } + + companion object { + + const val LOGOUT_REQUEST_CODE = 4 + + private const val TAG = "DisableSharingBottomSheet" + + fun showInstance(fm: FragmentManager, target: Fragment): Boolean { + return try { + LogoutBottomSheet().apply { + setTargetFragment(target, LOGOUT_REQUEST_CODE) + show(fm, TAG) + } + true + } catch (e: RuntimeException) { + false + } + } + } +} \ No newline at end of file diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/SettingsDialogFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/SettingsDialogFragment.kt index c33dc5c49d..476e99ae57 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/SettingsDialogFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/SettingsDialogFragment.kt @@ -1,5 +1,6 @@ package net.osmand.telegram.ui +import android.content.Intent import android.os.Bundle import android.support.v4.app.FragmentManager import android.support.v7.widget.ListPopupWindow @@ -108,8 +109,10 @@ class SettingsDialogFragment : BaseDialogFragment() { } mainView.findViewById(R.id.logout_btn).setOnClickListener { - logoutTelegram() - dismiss() + fragmentManager?.also { fm -> + LogoutBottomSheet.showInstance(fm, this) + } + } mainView.findViewById(R.id.help_icon) @@ -121,6 +124,16 @@ class SettingsDialogFragment : BaseDialogFragment() { return mainView } + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + when (requestCode) { + LogoutBottomSheet.LOGOUT_REQUEST_CODE -> { + logoutTelegram() + dismiss() + } + } + } + private fun showPopupMenu(pref: DurationPref, valueView: TextView) { val menuList = pref.getMenuItems() val ctx = valueView.context diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index ceccf1ce82..dc1398d49e 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -223,7 +223,8 @@ public class OsmEditingPlugin extends OsmandPlugin { isEditable = !amenity.getType().isWiki() && poiType !=null && !poiType.isNotEditableOsm(); } else if (selectedObj instanceof MapObject) { Long objectId = ((MapObject) selectedObj).getId(); - isEditable = objectId != null && objectId > 0 && (objectId % 2 == 1 || (objectId >> 7) < Integer.MAX_VALUE); + isEditable = objectId != null && objectId > 0 && (objectId % 2 == MapObject.AMENITY_ID_RIGHT_SHIFT + || (objectId >> MapObject.NON_AMENITY_ID_RIGHT_SHIFT) < Integer.MAX_VALUE); } if (isEditable) { adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.poi_context_menu_modify, mapActivity)