add get telegram dialog and improve ui

This commit is contained in:
Chumva 2018-07-05 19:09:01 +03:00
parent 5089aea3f4
commit 981143cacd
10 changed files with 382 additions and 158 deletions

View file

@ -3,20 +3,20 @@
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="@color/ctrl_active_light" />
<corners android:radius="@dimen/dialog_button_radius" />
<solid android:color="@color/dialog_continue_btn_active_bg" />
<corners android:radius="@dimen/dialog_continue_button_radius" />
</shape>
</item>
<item android:state_enabled="false">
<shape android:shape="rectangle">
<solid android:color="@color/ctrl_light" />
<corners android:radius="@dimen/dialog_button_radius" />
<corners android:radius="@dimen/dialog_continue_button_radius" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/ctrl_active_light" />
<corners android:radius="@dimen/dialog_button_radius" />
<solid android:color="@color/dialog_continue_btn_non_active_bg" />
<corners android:radius="@dimen/dialog_continue_button_radius" />
</shape>
</item>

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="@color/dialog_continue_btn_active_bg" />
<corners android:radius="@dimen/dialog_continue_button_radius" />
</shape>
</item>
<item android:state_enabled="false">
<shape android:shape="rectangle">
<solid android:color="@color/ctrl_light" />
<corners android:radius="@dimen/dialog_continue_button_radius" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/dialog_continue_btn_active_bg" />
<corners android:radius="@dimen/dialog_continue_button_radius" />
</shape>
</item>
</selector>

View file

@ -1,10 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="#f0f0f0" />
<corners android:radius="@dimen/dialog_button_radius" />
</shape>
</item>
<item android:state_enabled="false">
<shape android:shape="rectangle">
<solid android:color="@color/ctrl_light" />
<corners android:radius="@dimen/dialog_button_radius" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<corners android:radius="2dp" />
<solid android:color="@null" />
<corners android:radius="@dimen/dialog_button_radius" />
<stroke android:width="1dp" android:color="#f0f0f0" />
</shape>
</item>
</selector>

View file

@ -11,7 +11,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:visibility="visible">
android:visibility="visible"
tools:visibility="gone">
<FrameLayout
android:layout_width="match_parent"
@ -56,7 +57,7 @@
<Button
android:id="@+id/welcome_continue_button"
style="@style/DialogActionButtonActive"
style="@style/DialogActionButtonActive.Welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -115,19 +116,6 @@
</LinearLayout>
<TextView
android:id="@+id/login_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/content_padding_standard"
android:layout_marginEnd="@dimen/dialog_welcome_padding_horizontal"
android:layout_marginLeft="@dimen/dialog_padding_horizontal"
android:layout_marginRight="@dimen/dialog_welcome_padding_horizontal"
android:layout_marginStart="@dimen/dialog_padding_horizontal"
android:layout_marginTop="@dimen/content_padding_standard"
android:textColor="@color/app_bar_title_light"
android:textSize="@dimen/descr_text_size"
tools:text="@string/authorization_already_registered_in_telegram" />
<ScrollView
android:layout_width="match_parent"
@ -138,164 +126,234 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/dialog_welcome_padding_horizontal"
android:layout_marginLeft="@dimen/dialog_welcome_padding_horizontal"
android:layout_marginRight="@dimen/dialog_welcome_padding_horizontal"
android:layout_marginStart="@dimen/dialog_welcome_padding_horizontal"
android:layout_marginTop="@dimen/content_padding_standard"
android:orientation="vertical">
<LinearLayout
android:id="@+id/no_telegram"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dialog_padding_vertical"
android:background="@drawable/no_telegram_btn_bg"
android:gravity="center_vertical"
android:visibility="gone"
tools:visibility="visible">
<TextView
android:id="@+id/no_telegram_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/content_padding_standard"
android:layout_marginLeft="@dimen/content_padding_standard"
android:layout_marginRight="@dimen/content_padding_standard"
android:layout_marginTop="@dimen/content_padding_standard"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="2"
android:text="@string/do_not_have_telegram"
android:textColor="?attr/ctrl_active_color"
android:textSize="@dimen/descr_text_size"
android:textStyle="bold" />
<ImageView
android:id="@+id/no_telegram_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/content_padding_standard"
android:layout_marginRight="@dimen/content_padding_standard"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/do_not_have_telegram"
android:scaleType="centerInside"
android:src="@drawable/ic_arrow_forward"
android:tint="?attr/icon_color"
tools:tint="@color/icon_light" />
</LinearLayout>
<net.osmand.telegram.ui.views.TextViewEx
android:id="@+id/login_input_type_descr"
<TextView
android:id="@+id/login_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/content_padding_standard"
android:layout_marginEnd="@dimen/content_padding_standard"
android:layout_marginLeft="@dimen/content_padding_standard"
android:layout_marginRight="@dimen/content_padding_standard"
android:layout_marginStart="@dimen/content_padding_standard"
android:text="@string/enter_phone_number"
android:layout_marginEnd="@dimen/dialog_welcome_padding_horizontal"
android:layout_marginLeft="@dimen/dialog_padding_horizontal"
android:layout_marginRight="@dimen/dialog_welcome_padding_horizontal"
android:layout_marginStart="@dimen/dialog_padding_horizontal"
android:layout_marginTop="@dimen/content_padding_standard"
android:textColor="@color/app_bar_title_light"
android:textSize="@dimen/title_text_size"
android:textStyle="bold" />
android:textSize="@dimen/descr_text_size"
tools:text="@string/authorization_already_registered_in_telegram" />
<LinearLayout
android:id="@+id/enter_phone_number_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="visible">
android:layout_marginEnd="@dimen/dialog_welcome_padding_horizontal"
android:layout_marginLeft="@dimen/dialog_welcome_padding_horizontal"
android:layout_marginRight="@dimen/dialog_welcome_padding_horizontal"
android:layout_marginStart="@dimen/dialog_welcome_padding_horizontal"
android:layout_marginTop="@dimen/content_padding_standard"
android:orientation="vertical">
<studio.carbonylgroup.textfieldboxes.TextFieldBoxes
<LinearLayout
android:id="@+id/no_telegram"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hasClearButton="true">
android:layout_marginBottom="@dimen/dialog_padding_vertical"
android:background="@drawable/no_telegram_btn_bg"
android:gravity="center_vertical"
android:visibility="gone"
tools:visibility="gone">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:id="@+id/phone_number_edit_text"
android:layout_width="match_parent"
<TextView
android:id="@+id/no_telegram_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/phone_number_title"
android:inputType="phone" />
android:layout_marginBottom="@dimen/content_padding_standard"
android:layout_marginLeft="@dimen/content_padding_standard"
android:layout_marginRight="@dimen/content_padding_standard"
android:layout_marginTop="@dimen/content_padding_standard"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="2"
android:text="@string/do_not_have_telegram"
android:textColor="?attr/ctrl_active_color"
android:textSize="@dimen/descr_text_size"
android:textStyle="bold" />
</studio.carbonylgroup.textfieldboxes.TextFieldBoxes>
<ImageView
android:id="@+id/no_telegram_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/content_padding_standard"
android:layout_marginRight="@dimen/content_padding_standard"
android:contentDescription="@string/do_not_have_telegram"
android:scaleType="centerInside"
android:src="@drawable/ic_arrow_forward"
android:tint="?attr/icon_color"
tools:tint="@color/icon_light" />
<TextView
android:id="@+id/phone_number_format"
</LinearLayout>
<net.osmand.telegram.ui.views.TextViewEx
android:id="@+id/login_input_type_descr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/content_padding_standard"
android:layout_marginEnd="@dimen/content_padding_standard"
android:layout_marginLeft="@dimen/content_padding_standard"
android:layout_marginRight="@dimen/content_padding_standard"
android:layout_marginTop="@dimen/content_padding_standard"
android:text="@string/phone_number_descr"
android:textSize="@dimen/descr_text_size" />
android:layout_marginStart="@dimen/content_padding_standard"
android:text="@string/enter_phone_number"
android:textColor="@color/app_bar_title_light"
android:textSize="@dimen/title_text_size"
android:textStyle="bold"
tools:visibility="visible" />
</LinearLayout>
<LinearLayout
android:id="@+id/enter_code_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/content_padding_standard"
android:visibility="gone">
<studio.carbonylgroup.textfieldboxes.TextFieldBoxes
<LinearLayout
android:id="@+id/enter_phone_number_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hasClearButton="true"
app:labelText="@string/authentication_code">
android:orientation="vertical"
android:visibility="visible"
tools:visibility="visible">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:id="@+id/code_edit_text"
<studio.carbonylgroup.textfieldboxes.TextFieldBoxes
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
tools:text="123456" />
app:hasClearButton="true">
</studio.carbonylgroup.textfieldboxes.TextFieldBoxes>
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:id="@+id/phone_number_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/phone_number_title"
android:inputType="phone" />
</LinearLayout>
</studio.carbonylgroup.textfieldboxes.TextFieldBoxes>
<LinearLayout
android:id="@+id/enter_password_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/content_padding_standard"
android:visibility="gone">
<TextView
android:id="@+id/phone_number_format"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/content_padding_standard"
android:layout_marginLeft="@dimen/content_padding_standard"
android:layout_marginRight="@dimen/content_padding_standard"
android:layout_marginTop="@dimen/content_padding_standard"
android:text="@string/phone_number_descr"
android:textSize="@dimen/descr_text_size" />
<studio.carbonylgroup.textfieldboxes.TextFieldBoxes
</LinearLayout>
<LinearLayout
android:id="@+id/enter_code_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hasClearButton="true"
app:labelText="@string/shared_string_password">
android:orientation="vertical"
android:paddingBottom="@dimen/content_padding_standard"
android:visibility="gone">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:id="@+id/password_edit_text"
<studio.carbonylgroup.textfieldboxes.TextFieldBoxes
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
tools:text="12345678" />
app:hasClearButton="true"
app:labelText="@string/authentication_code">
</studio.carbonylgroup.textfieldboxes.TextFieldBoxes>
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:id="@+id/code_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
tools:text="123456" />
</LinearLayout>
</studio.carbonylgroup.textfieldboxes.TextFieldBoxes>
<LinearLayout
android:id="@+id/progress_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
</LinearLayout>
<ProgressBar
android:layout_width="@dimen/progress_bar_size_small"
android:layout_height="@dimen/progress_bar_size_small" />
<LinearLayout
android:id="@+id/enter_password_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/content_padding_standard"
android:visibility="gone">
<studio.carbonylgroup.textfieldboxes.TextFieldBoxes
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hasClearButton="true"
app:labelText="@string/shared_string_password">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:id="@+id/password_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
tools:text="12345678" />
</studio.carbonylgroup.textfieldboxes.TextFieldBoxes>
</LinearLayout>
<LinearLayout
android:id="@+id/get_telegram_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/content_padding_standard"
android:visibility="gone"
tools:visibility="gone">
<TextView
android:id="@+id/get_telegram_description_first"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/content_padding_standard"
android:layout_marginEnd="@dimen/content_padding_standard"
android:layout_marginLeft="@dimen/content_padding_standard"
android:layout_marginRight="@dimen/content_padding_standard"
android:layout_marginStart="@dimen/content_padding_standard"
android:textColor="@color/app_bar_title_light"
android:textSize="@dimen/descr_text_size"
tools:text="@string/get_telegram_description_second" />
<ImageView
android:id="@+id/google_play_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/content_padding_standard"
android:layout_marginEnd="@dimen/content_padding_standard"
android:layout_marginLeft="@dimen/content_padding_standard"
android:layout_marginRight="@dimen/content_padding_standard"
android:layout_marginStart="@dimen/content_padding_standard"
android:src="@drawable/google_play_badge" />
<TextView
android:id="@+id/get_telegram_description_second"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/content_padding_standard"
android:layout_marginEnd="@dimen/content_padding_standard"
android:layout_marginLeft="@dimen/content_padding_standard"
android:layout_marginRight="@dimen/content_padding_standard"
android:layout_marginStart="@dimen/content_padding_standard"
android:textColor="@color/app_bar_title_light"
android:textSize="@dimen/descr_text_size"
tools:text="@string/get_telegram_description_third" />
</LinearLayout>
<LinearLayout
android:id="@+id/progress_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
<ProgressBar
android:layout_width="@dimen/progress_bar_size_small"
android:layout_height="@dimen/progress_bar_size_small" />
</LinearLayout>
</LinearLayout>

View file

@ -36,4 +36,7 @@
<color name="app_bar_title_light">#333333</color>
<color name="dialog_continue_btn_active_bg">#5959ff</color>
<color name="dialog_continue_btn_non_active_bg">#f0f0f0</color>
</resources>

View file

@ -18,6 +18,7 @@
<dimen name="dialog_button_height">36dp</dimen>
<dimen name="dialog_button_radius">2dp</dimen>
<dimen name="dialog_continue_button_radius">4dp</dimen>
<dimen name="dialog_button_bottom_padding">40dp</dimen>
<dimen name="dialog_welcome_title_bottom_padding">96dp</dimen>
<dimen name="dialog_welcome_title_top_padding">120dp</dimen>
@ -55,6 +56,7 @@
<dimen name="title_login_text_size">20sp</dimen>
<dimen name="title_welcome_text_size">32sp</dimen>
<dimen name="descr_text_size">16sp</dimen>
<dimen name="continue_btn_text_size">14sp</dimen>
<dimen name="list_item_title_text_size">16sp</dimen>
<dimen name="list_item_description_text_size">12sp</dimen>

View file

@ -1,4 +1,8 @@
<resources>
<string name="get_telegram_title">Registration in Telegram</string>
<string name="get_telegram_description_first">You need an account in Telegram to use the capabilities of OsmAnd Location Sharing.</string>
<string name="get_telegram_description_second">If you want to continue, please install the Telegram from Google Play and register your account.</string>
<string name="get_telegram_description_third">After creating an account, you can use this application.</string>
<string name="shared_string_all">All</string>
<string name="shared_string_off">Off</string>
<string name="authorization_already_registered_in_telegram">You need an already registered account and phone number in Telegram</string>

View file

@ -32,6 +32,9 @@
<style name="AppTheme.NoActionbar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.NoActionbar.Translucent">
<item name="android:windowTranslucentStatus">true</item>
</style>
@ -45,7 +48,13 @@
<item name="android:paddingBottom">8dp</item>
<item name="android:textColor">@color/white</item>
<item name="android:textAllCaps">false</item>
<item name="android:textSize">@dimen/continue_btn_text_size</item>
<item name="android:background">@drawable/btn_round_blue</item>
<item name="android:letterSpacing">0.07</item>
</style>
<style name="DialogActionButtonActive.Welcome">
<item name="android:background">@drawable/btn_round_purple</item>
</style>
<style name="DialogActionButton">

View file

@ -10,19 +10,19 @@ import android.support.v4.app.FragmentManager
import android.support.v7.widget.AppCompatImageView
import android.text.Html
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.view.inputmethod.EditorInfo
import android.widget.Button
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.*
import net.osmand.PlatformUtil
import net.osmand.telegram.R
import net.osmand.telegram.utils.AndroidUtils
import studio.carbonylgroup.textfieldboxes.ExtendedEditText
import android.content.Intent
import android.graphics.Rect
import android.net.Uri
import android.view.*
import android.view.ViewGroup
import android.text.Editable
import android.text.TextWatcher
class LoginDialogFragment : DialogFragment() {
@ -35,10 +35,15 @@ class LoginDialogFragment : DialogFragment() {
private const val LOGIN_DIALOG_TYPE_PARAM_KEY = "login_dialog_type_param"
private const val SHOW_PROGRESS_PARAM_KEY = "show_progress_param"
private const val SHOW_WELCOME_DIALOG_PARAM_KEY = "show_welcome_dialog_param"
private const val TELEGRAM_PLAY_MARKET_LINK = "market://details?id=org.telegram.messenger"
private const val TELEGRAM_NO_PLAY_MARKET_LINK = "https://play.google.com/store/apps/details?id=org.telegram.messenger"
private const val SOFT_KEYBOARD_MIN_DETECTION_SIZE = 0.15
var welcomeDialogShown = false
private set
private var softKeyboardShown: Boolean = false
fun showWelcomeDialog(fragmentManager: FragmentManager) {
welcomeDialogShown = true
showDialog(fragmentManager, welcomeDialog = true)
@ -101,12 +106,14 @@ class LoginDialogFragment : DialogFragment() {
ENTER_CODE(R.id.enter_code_layout, R.id.code_edit_text,
R.string.enter_code, R.string.authentication_code_descr, R.string.enter_authentication_code),
ENTER_PASSWORD(R.id.enter_password_layout, R.id.password_edit_text,
R.string.enter_password, R.string.password_descr, R.string.enter_password);
R.string.enter_password, R.string.password_descr, R.string.enter_password),
GET_TELEGRAM(R.id.get_telegram_layout, 0,
R.string.get_telegram_title, R.string.get_telegram_description_first, 0);
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(DialogFragment.STYLE_NO_FRAME, R.style.AppTheme_NoActionbar)
setStyle(DialogFragment.STYLE_NO_FRAME, R.style.AppTheme_NoActionbar_Translucent)
val activity = requireActivity()
val window = activity.window
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
@ -124,6 +131,31 @@ class LoginDialogFragment : DialogFragment() {
}
val view = inflater.inflate(R.layout.login_dialog, container)
buildDialog(view)
view.viewTreeObserver.addOnGlobalLayoutListener {
val r = Rect()
view.getWindowVisibleDisplayFrame(r)
val screenHeight = view.rootView.height
val keypadHeight = screenHeight - r.bottom
val softKeyboardVisible = keypadHeight > screenHeight * SOFT_KEYBOARD_MIN_DETECTION_SIZE
if (!softKeyboardShown && softKeyboardVisible) {
softKeyboardShown = softKeyboardVisible
val continueButton = view?.findViewById<Button>(R.id.continue_button)
if (continueButton?.layoutParams is ViewGroup.MarginLayoutParams) {
val p = continueButton.layoutParams as ViewGroup.MarginLayoutParams
p.setMargins(p.leftMargin, p.topMargin, p.rightMargin, AndroidUtils.dpToPx(context!!, 16F))
continueButton.requestLayout()
}
} else if (softKeyboardShown && !softKeyboardVisible) {
softKeyboardShown = softKeyboardVisible
val continueButton = view?.findViewById<Button>(R.id.continue_button)
if (continueButton?.layoutParams is ViewGroup.MarginLayoutParams) {
val p = continueButton.layoutParams as ViewGroup.MarginLayoutParams
p.setMargins(p.leftMargin, p.topMargin, p.rightMargin, AndroidUtils.dpToPx(context!!, 40F))
continueButton.requestLayout()
}
}
softKeyboardShown = softKeyboardVisible
}
return view
}
@ -186,11 +218,15 @@ class LoginDialogFragment : DialogFragment() {
val titleView: TextView? = view.findViewById(R.id.login_title)
val descriptionView: TextView? = view.findViewById(R.id.login_description)
val inputTypeDescriptionView: TextView? = view.findViewById(R.id.login_input_type_descr)
val inputTypeDescription = getText(t.inputTypeDescriptionId).toString() + ":"
if (t.inputTypeDescriptionId != 0) {
val inputTypeDescription = getText(t.inputTypeDescriptionId).toString() + ":"
inputTypeDescriptionView?.text = inputTypeDescription
} else {
inputTypeDescriptionView?.visibility = View.GONE
}
titleView?.text = getText(t.titleId)
descriptionView?.text = getText(t.descriptionId)
inputTypeDescriptionView?.text = inputTypeDescription
layout.visibility = View.VISIBLE
val editText: ExtendedEditText? = layout.findViewById(t.editorId)
@ -207,22 +243,59 @@ class LoginDialogFragment : DialogFragment() {
AndroidUtils.softKeyboardDelayed(editText)
focusRequested = true
}
editText.addTextChangedListener(object : TextWatcher {
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun afterTextChanged(s: Editable) {
val continueButton: Button? = view.findViewById(R.id.continue_button)
if (s.isEmpty()) {
continueButton?.setBackgroundResource(R.drawable.btn_round_blue)
// continueButton?.set()
} else {
continueButton?.setBackgroundResource(R.drawable.btn_round_purple)
// continueButton?.setTextColor(R.color.secondary_text_light)
}
}
})
}
val noTelegramViewContainer: LinearLayout? = view.findViewById(R.id.no_telegram)
if (loginDialogActiveType == LoginDialogType.ENTER_PHONE_NUMBER) {
val noTelegramAccountTitleView: TextView? = view.findViewById(R.id.no_telegram_title)
val noTelegramAccountButton: ImageView? = view.findViewById(R.id.no_telegram_button)
val phoneNumberFormatHintView: TextView? = view.findViewById(R.id.phone_number_format)
noTelegramAccountTitleView?.text = getText(R.string.do_not_have_telegram)
phoneNumberFormatHintView?.text = getText(R.string.phone_number_descr)
noTelegramAccountButton?.setImageResource(R.drawable.ic_arrow_forward)
view.findViewById<TextView>(R.id.no_telegram_title)?.text = getText(R.string.do_not_have_telegram)
view.findViewById<TextView>(R.id.phone_number_format)?.text = getText(R.string.phone_number_descr)
view.findViewById<ImageView>(R.id.no_telegram_button)?.setImageResource(R.drawable.ic_arrow_forward)
noTelegramViewContainer?.setOnClickListener {
val focusedView = dialog.currentFocus
if (focusedView != null && softKeyboardShown) {
AndroidUtils.hideSoftKeyboard(activity!!, focusedView)
}
updateDialog(LoginDialogType.GET_TELEGRAM, false)
}
noTelegramViewContainer?.visibility = View.VISIBLE
} else {
noTelegramViewContainer?.visibility = View.GONE
}
val getTelegramViewContainer: LinearLayout? = view.findViewById(R.id.get_telegram_layout)
if (loginDialogActiveType == LoginDialogType.GET_TELEGRAM) {
view.findViewById<TextView>(R.id.get_telegram_description_first)?.text = getText(R.string.get_telegram_description_second)
view.findViewById<TextView>(R.id.get_telegram_description_second)?.text = getText(R.string.get_telegram_description_third)
val getTelegramButton: ImageView? = view.findViewById(R.id.google_play_button)
getTelegramButton?.setImageResource(R.drawable.google_play_badge)
getTelegramButton?.setOnClickListener {
try {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(TELEGRAM_PLAY_MARKET_LINK)))
} catch (anfe: android.content.ActivityNotFoundException) {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(TELEGRAM_NO_PLAY_MARKET_LINK)))
}
}
view.findViewById<Button>(R.id.continue_button).visibility = View.GONE
getTelegramViewContainer?.visibility = View.VISIBLE
} else {
getTelegramViewContainer?.visibility = View.GONE
view.findViewById<Button>(R.id.continue_button).visibility = View.VISIBLE
}
}
}
else -> layout?.visibility = View.GONE
@ -261,6 +334,10 @@ class LoginDialogFragment : DialogFragment() {
cancelButton?.setOnClickListener {
if (loginDialogActiveType == LoginDialogType.ENTER_PHONE_NUMBER) {
showWelcomeDialog = true
val focusedView = dialog.currentFocus
if (focusedView != null && softKeyboardShown) {
AndroidUtils.hideSoftKeyboard(activity!!, focusedView)
}
buildDialog(view)
} else {
showProgress()

View file

@ -4,12 +4,15 @@ import android.Manifest
import android.app.Activity
import android.content.Context
import android.content.pm.PackageManager
import android.content.res.ColorStateList
import android.content.res.Configuration
import android.net.Uri
import android.os.Build
import android.support.annotation.AttrRes
import android.support.annotation.ColorInt
import android.support.annotation.ColorRes
import android.support.v4.app.ActivityCompat
import android.support.v4.content.ContextCompat
import android.support.v4.content.FileProvider
import android.util.TypedValue
import android.util.TypedValue.COMPLEX_UNIT_DIP
@ -45,6 +48,37 @@ object AndroidUtils {
}
}
fun createCheckedColorStateList(ctx: Context, @ColorRes normal: Int, @ColorRes checked: Int): ColorStateList {
return createCheckedColorStateList(ctx, false, normal, checked, 0, 0)
}
fun createCheckedColorStateList(ctx: Context, night: Boolean,
@ColorRes lightNormal: Int, @ColorRes lightChecked: Int,
@ColorRes darkNormal: Int, @ColorRes darkChecked: Int): ColorStateList {
return createColorStateList(ctx, night, android.R.attr.state_checked,
lightNormal, lightChecked, darkNormal, darkChecked)
}
fun createPressedColorStateList(ctx: Context, @ColorRes normal: Int, @ColorRes pressed: Int): ColorStateList {
return createPressedColorStateList(ctx, false, normal, pressed, 0, 0)
}
fun createPressedColorStateList(ctx: Context, night: Boolean,
@ColorRes lightNormal: Int, @ColorRes lightPressed: Int,
@ColorRes darkNormal: Int, @ColorRes darkPressed: Int): ColorStateList {
return createColorStateList(ctx, night, android.R.attr.state_pressed,
lightNormal, lightPressed, darkNormal, darkPressed)
}
private fun createColorStateList(ctx: Context, night: Boolean, state: Int,
@ColorRes lightNormal: Int, @ColorRes lightState: Int,
@ColorRes darkNormal: Int, @ColorRes darkState: Int): ColorStateList {
return ColorStateList(
arrayOf(intArrayOf(state), intArrayOf()),
intArrayOf(ContextCompat.getColor(ctx, if (night) darkState else lightState), ContextCompat.getColor(ctx, if (night) darkNormal else lightNormal))
)
}
fun isLocationPermissionAvailable(context: Context): Boolean {
return ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
}