Refactored Login screen

This commit is contained in:
crimean 2018-06-18 00:08:29 +03:00
parent 36b9fe3927
commit 46b1bba997
19 changed files with 703 additions and 377 deletions

View file

@ -5,6 +5,7 @@ apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
sourceSets {
main {
@ -124,8 +125,13 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:customtabs:27.1.1'
implementation 'com.android.support:support-annotations:27.1.1'
implementation 'commons-logging:commons-logging-api:1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.vividsolutions:jts-core:1.14.0'
implementation("com.github.HITGIF:TextFieldBoxes:1.4.4") {
exclude group: 'com.android.support'
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

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/ctrl_active_color_light" />
<corners android:radius="@dimen/dialog_button_radius" />
</shape>
</item>
<item android:state_enabled="false">
<shape android:shape="rectangle">
<solid android:color="@color/ctrl_color_light" />
<corners android:radius="@dimen/dialog_button_radius" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/ctrl_color_light" />
<corners android:radius="@dimen/dialog_button_radius" />
</shape>
</item>
</selector>

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/ctrl_active_color_light" />
<corners android:radius="@dimen/dialog_button_radius" />
</shape>
</item>
<item android:state_enabled="false">
<shape android:shape="rectangle">
<solid android:color="@color/ctrl_color_light" />
<corners android:radius="@dimen/dialog_button_radius" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/ctrl_active_color_light" />
<corners android:radius="@dimen/dialog_button_radius" />
</shape>
</item>
</selector>

View file

@ -1,14 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/groups_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
app:itemBackground="?attr/bg_color"
app:menu="@menu/bottom_navigation_menu"
tools:itemIconTint="@color/ctrl_active_color_light"
tools:itemTextColor="@color/ctrl_active_color_light"
tools:visibility="visible" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>

View file

@ -7,7 +7,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/dialogTitleBackgroundColor"
android:background="?attr/ctrl_active_color"
android:orientation="vertical"
android:gravity="center_horizontal">

View file

@ -1,109 +1,211 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:paddingBottom="@dimen/dialog_padding_vertical"
android:paddingLeft="@dimen/dialog_padding_horizontal"
android:paddingRight="@dimen/dialog_padding_horizontal"
android:paddingTop="@dimen/dialog_padding_vertical">
android:orientation="vertical">
<LinearLayout
android:id="@+id/welcome_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/dialog_padding_horizontal_edit"
android:layout_marginRight="@dimen/dialog_padding_horizontal_edit"
android:layout_marginTop="@dimen/dialog_padding_vertical"
android:orientation="vertical"
android:visibility="visible">
<TextView
android:id="@+id/welcome_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/shared_string_welcome"
android:textColor="?android:attr/textColorPrimary"
android:textSize="@dimen/title_text_size"
android:textStyle="bold" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="@dimen/dialog_padding_vertical"
android:layout_weight="1"
android:fillViewport="true">
<TextView
android:id="@+id/welcome_descr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/descr_text_size"
tools:text="@string/welcome_descr" />
</ScrollView>
<Button
android:id="@+id/welcome_continue_button"
style="@style/DialogActionButtonActive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="@dimen/dialog_padding_vertical"
android:layout_marginLeft="@dimen/content_padding_standard"
android:layout_marginRight="@dimen/content_padding_standard"
android:layout_marginTop="@dimen/content_padding_standard"
android:text="@string/shared_string_continue" />
</LinearLayout>
<LinearLayout
android:id="@+id/login_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:gravity="center_vertical"
android:minHeight="@dimen/action_bar_height"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatImageView
android:id="@+id/back_button"
android:layout_width="@dimen/dialog_button_height"
android:layout_height="@dimen/dialog_button_height"
android:layout_marginEnd="@dimen/content_padding_standard"
android:layout_marginLeft="@dimen/content_padding_half"
android:layout_marginRight="@dimen/content_padding_standard"
android:layout_marginStart="@dimen/content_padding_half"
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleType="centerInside"
android:src="@drawable/ic_arrow_back"
android:tint="?attr/icon_color" />
<TextView
android:id="@+id/login_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/content_padding_standard"
android:layout_marginRight="@dimen/content_padding_standard"
android:textColor="?attr/ctrl_active_color"
android:textSize="@dimen/title_text_size"
android:textStyle="bold"
tools:text="@string/shared_string_authorization" />
</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_padding_horizontal"
android:layout_marginLeft="@dimen/dialog_padding_horizontal"
android:layout_marginRight="@dimen/dialog_padding_horizontal"
android:layout_marginStart="@dimen/dialog_padding_horizontal"
android:layout_marginTop="@dimen/content_padding_standard"
android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/descr_text_size"
tools:text="@string/shared_string_authorization_descr" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:gravity="center"
android:text="@string/login_to_telegram"
android:textSize="@dimen/dialog_title_text_size"
android:textStyle="bold" />
android:layout_weight="1"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="0.6"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/dialog_padding_horizontal_edit"
android:layout_marginLeft="@dimen/dialog_padding_horizontal_edit"
android:layout_marginRight="@dimen/dialog_padding_horizontal_edit"
android:layout_marginStart="@dimen/dialog_padding_horizontal_edit"
android:layout_marginTop="@dimen/content_padding_standard"
android:orientation="vertical">
<LinearLayout
android:id="@+id/enterPhoneNumberLayout"
android:id="@+id/enter_phone_number_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="visible">
<TextView
<studio.carbonylgroup.textfieldboxes.TextFieldBoxes
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/phone_number_title" />
app:hasClearButton="true"
app:labelText="@string/phone_number_title">
<EditText
android:id="@+id/phoneNumberEditText"
<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"
android:text="@string/plus"
tools:text="+380661234567" />
</studio.carbonylgroup.textfieldboxes.TextFieldBoxes>
</LinearLayout>
<LinearLayout
android:id="@+id/enterCodeLayout"
android:id="@+id/enter_code_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<TextView
<studio.carbonylgroup.textfieldboxes.TextFieldBoxes
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/authentication_code" />
app:hasClearButton="true"
app:labelText="@string/authentication_code">
<EditText
android:id="@+id/codeEditText"
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:id="@+id/code_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/authentication_code"
android:inputType="number"
tools:text="123456" />
</studio.carbonylgroup.textfieldboxes.TextFieldBoxes>
</LinearLayout>
<LinearLayout
android:id="@+id/enterPasswordLayout"
android:id="@+id/enter_password_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<TextView
<studio.carbonylgroup.textfieldboxes.TextFieldBoxes
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/shared_string_password" />
app:hasClearButton="true"
app:labelText="@string/shared_string_password">
<EditText
android:id="@+id/passwordEditText"
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:id="@+id/password_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/shared_string_password"
android:inputType="textPassword"
tools:text="12345678" />
</studio.carbonylgroup.textfieldboxes.TextFieldBoxes>
</LinearLayout>
<LinearLayout
android:id="@+id/progressLayout"
android:id="@+id/progress_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:visibility="visible">
android:visibility="gone">
<ProgressBar
android:layout_width="@dimen/progress_bar_size_small"
@ -113,31 +215,20 @@
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:gravity="bottom"
android:orientation="horizontal">
</ScrollView>
<Button
android:id="@+id/calcelButton"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:id="@+id/continue_button"
style="@style/DialogActionButtonActive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/shared_string_cancel" />
<Button
android:id="@+id/continueButton"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center"
android:layout_marginBottom="@dimen/dialog_padding_vertical"
android:layout_marginLeft="@dimen/content_padding_standard"
android:layout_marginRight="@dimen/content_padding_standard"
android:layout_marginTop="@dimen/content_padding_standard"
android:text="@string/shared_string_continue" />
</LinearLayout>
</LinearLayout>
</ScrollView>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_my_location"
android:icon="@drawable/ic_action_polygom_dark"
android:title="@string/my_location"/>
<item
android:id="@+id/action_live_now"
android:icon="@drawable/ic_action_view"
android:title="@string/live_now"/>
</menu>

View file

@ -3,5 +3,7 @@
<declare-styleable name="AppTheme">
<attr name="bg_color" format="reference" />
<attr name="icon_color" format="reference" />
<attr name="ctrl_active_color" format="reference" />
<attr name="ctrl_color" format="reference" />
</declare-styleable>
</resources>

View file

@ -1,16 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="white_color">#fff</color>
<color name="bg_color_light">#fff</color>
<color name="bg_color_dark">#333b40</color>
<color name="icon_color_light">#ccc</color>
<color name="icon_color_dark">#ff4f4f4f</color>
<color name="bg_color_dark">#222526</color>
<color name="icon_color_light">#727272</color>
<color name="icon_color_dark">#727272</color>
<color name="osmand_orange">#ff8f00</color>
<color name="dialogTitleBackgroundColor">#2f7af5</color>
<color name="ctrl_active_color_light">#237bff</color>
<color name="ctrl_active_color_dark">#d28521</color>
<color name="ctrl_color_light">#f0f0f0</color>
<color name="ctrl_color_dark">#17191a</color>
<color name="primary_text_color_light">#212121</color>
<color name="primary_text_color_dark">#cccccc</color>
<color name="secondary_text_color_light">#727272</color>
<color name="secondary_text_color_dark">#727272</color>
<color name="description_text_color_light">#b3b3b3</color>
<color name="description_text_color_dark">#4d4d4d</color>
<color name="divider_color_light">#f0f0f0</color>
<color name="divider_color_dark">#2d3133</color>
</resources>

View file

@ -5,6 +5,13 @@
<dimen name="progress_bar_size_small">32dp</dimen>
<dimen name="dialog_title_text_size">22sp</dimen>
<dimen name="dialog_padding_vertical">24dp</dimen>
<dimen name="dialog_padding_horizontal">48dp</dimen>
<dimen name="dialog_padding_horizontal">60dp</dimen>
<dimen name="dialog_padding_horizontal_edit">44dp</dimen>
<dimen name="list_item_height_min">48dp</dimen>
<dimen name="dialog_button_height">36dp</dimen>
<dimen name="dialog_button_radius">2dp</dimen>
<dimen name="title_text_size">18sp</dimen>
<dimen name="descr_text_size">16sp</dimen>
<dimen name="action_bar_height">60dp</dimen>
</resources>

View file

@ -1,9 +1,13 @@
<resources>
<string name="app_name">OsmAnd Telegram</string>
<string name="phone_number_title">Phone number in the international format</string>
<string name="phone_number_title">Phone number</string>
<string name="phone_number_descr">Phone number in the international format</string>
<string name="shared_string_password">Password</string>
<string name="enter_code">Enter code</string>
<string name="authentication_code">Authentication code</string>
<string name="login_to_telegram">Login to telegram</string>
<string name="authentication_code_descr">You have been sent a code by Telegram. It will be used by OsmAnd to login into your account.</string>
<string name="enter_password">Enter password</string>
<string name="password_descr">Please enter your Telegram account\'s password to finish authorization</string>
<string name="shared_string_login">Login</string>
<string name="shared_string_logout">Logout</string>
<string name="not_logged_in">You are not logged in</string>
@ -33,6 +37,9 @@
<string name="install_osmand">Install OsmAnd</string>
<string name="show_users_on_map">Show users on map</string>
<string name="active_chats">Active chats</string>
<string name="shared_string_authorization">Authorization</string>
<string name="shared_string_authorization_descr">Please enter the phone number of your Telegram account in the international format</string>
<string name="shared_string_welcome">Welcome</string>
<string name="yard">yd</string>
<string name="foot">ft</string>
@ -59,6 +66,10 @@
<string name="si_mi_meters">Miles/meters</string>
<string name="shared_string_hour_short">h</string>
<string name="shared_string_minute_short">min</string>
<string name="plus">+</string>
<string name="welcome_descr"><![CDATA[<b>OsmAnd Location Sharing</b> allows you to share your location and see locations of other people in the OsmAnd.<br/><br/>The application works on base of Telegram API. To use this app you must have a Telegram account.]]></string>
<string name="my_location">My location</string>
<string name="live_now">Live now</string>
</resources>

View file

@ -2,13 +2,23 @@
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/bg_color_light</item>
<item name="android:colorBackground">@color/bg_color_light</item>
<item name="colorControlNormal">@color/primary_text_color_light</item>
<item name="colorControlActivated">@color/ctrl_active_color_light</item>
<item name="android:windowLightStatusBar">true</item>
<item name="colorPrimary">@color/ctrl_active_color_light</item>
<item name="colorPrimaryDark">@color/bg_color_light</item>
<item name="colorAccent">@color/ctrl_active_color_light</item>
<item name="android:textColorPrimary">@color/primary_text_color_light</item>
<item name="android:textColorSecondary">@color/secondary_text_color_light</item>
<item name="android:textColorTertiary">@color/description_text_color_light</item>
<item name="bg_color">@color/bg_color_light</item>
<item name="icon_color">@color/icon_color_light</item>
<item name="ctrl_active_color">@color/ctrl_active_color_light</item>
<item name="ctrl_color">@color/ctrl_color_light</item>
</style>
<style name="AppTheme.NoActionbar">
@ -16,4 +26,30 @@
<item name="windowNoTitle">true</item>
</style>
<style name="DialogActionButtonActive">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:minHeight">@dimen/dialog_button_height</item>
<item name="android:paddingLeft">16dp</item>
<item name="android:paddingRight">16dp</item>
<item name="android:paddingTop">8dp</item>
<item name="android:paddingBottom">8dp</item>
<item name="android:textColor">@color/white_color</item>
<item name="android:textAllCaps">false</item>
<item name="android:background">@drawable/btn_round_blue</item>
</style>
<style name="DialogActionButton">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:minHeight">@dimen/dialog_button_height</item>
<item name="android:paddingLeft">16dp</item>
<item name="android:paddingRight">16dp</item>
<item name="android:paddingTop">8dp</item>
<item name="android:paddingBottom">8dp</item>
<item name="android:textColor">@color/secondary_text_color_light</item>
<item name="android:textAllCaps">false</item>
<item name="android:background">@drawable/btn_round</item>
</style>
</resources>

View file

@ -1,18 +1,25 @@
package net.osmand.telegram
import android.app.Dialog
import android.content.DialogInterface
import android.os.Build
import android.os.Bundle
import android.support.annotation.StringRes
import android.support.v4.app.DialogFragment
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.EditText
import net.osmand.telegram.utils.AndroidUtils
import android.widget.TextView
import net.osmand.PlatformUtil
import net.osmand.telegram.utils.AndroidUtils
import studio.carbonylgroup.textfieldboxes.ExtendedEditText
class LoginDialogFragment : DialogFragment() {
@ -22,24 +29,44 @@ class LoginDialogFragment : DialogFragment() {
private const val TAG = "LoginDialogFragment"
private val LOG = PlatformUtil.getLog(LoginDialogFragment::class.java)
private const val ENTER_PHONE_NUMBER_PARAM_KEY: String = "enter_phone_number_param_key"
private const val ENTER_CODE_PARAM_KEY = "enter_code_param_key"
private const val ENTER_PASSWORD_PARAM_KEY = "enter_password_param_key"
private const val SHOW_PROGRESS_PARAM_KEY = "show_progress_param_key"
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"
fun showDialog(fragmentManager: FragmentManager, vararg loginDialogType: LoginDialogType) {
var welcomeDialogShown = false
private set
fun showWelcomeDialog(fragmentManager: FragmentManager) {
welcomeDialogShown = true
showDialog(fragmentManager, welcomeDialog = true)
}
fun showDialog(fragmentManager: FragmentManager, loginDialogType: LoginDialogType? = null, welcomeDialog: Boolean = false) {
try {
/*
mapActivity.getSupportFragmentManager().beginTransaction()
.setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim)
.add(R.id.fragmentContainer, fragment, TAG)
.addToBackStack(TAG).commitAllowingStateLoss()
*/
var fragment = getFragment(fragmentManager)
if (fragment == null) {
fragment = LoginDialogFragment()
val args = Bundle()
for (t in loginDialogType) {
args.putBoolean(t.paramKey, true)
if (loginDialogType != null) {
args.putString(LOGIN_DIALOG_TYPE_PARAM_KEY, loginDialogType.name)
}
args.putBoolean(SHOW_WELCOME_DIALOG_PARAM_KEY, welcomeDialog)
fragment.arguments = args
fragment.show(fragmentManager, TAG)
} else {
fragment.updateDialog(*loginDialogType)
var showWelcomeDialog = welcomeDialog
if (fragment.showWelcomeDialog) {
showWelcomeDialog = fragment.showWelcomeDialog
}
fragment.updateDialog(loginDialogType, showWelcomeDialog)
}
} catch (e: RuntimeException) {
LOG.error(e)
@ -57,15 +84,20 @@ class LoginDialogFragment : DialogFragment() {
}
}
private var loginDialogActiveTypes: Set<LoginDialogType>? = null
private var loginDialogActiveType: LoginDialogType? = null
private var showWelcomeDialog = false
private var showProgress = false
private var dismissedManually = false
enum class LoginDialogType(val paramKey: String, val viewId: Int, val editorId: Int) {
ENTER_PHONE_NUMBER(ENTER_PHONE_NUMBER_PARAM_KEY, R.id.enterPhoneNumberLayout, R.id.phoneNumberEditText),
ENTER_CODE(ENTER_CODE_PARAM_KEY, R.id.enterCodeLayout, R.id.codeEditText),
ENTER_PASSWORD(ENTER_PASSWORD_PARAM_KEY, R.id.enterPasswordLayout, R.id.passwordEditText),
SHOW_PROGRESS(SHOW_PROGRESS_PARAM_KEY, R.id.progressLayout, 0);
enum class LoginDialogType(val viewId: Int, val editorId: Int,
@StringRes val titleId: Int, @StringRes val descriptionId: Int) {
ENTER_PHONE_NUMBER(R.id.enter_phone_number_layout, R.id.phone_number_edit_text,
R.string.shared_string_authorization, R.string.shared_string_authorization_descr),
ENTER_CODE(R.id.enter_code_layout, R.id.code_edit_text,
R.string.enter_code, R.string.authentication_code_descr),
ENTER_PASSWORD(R.id.enter_password_layout, R.id.password_edit_text,
R.string.enter_password, R.string.password_descr);
}
override fun onCreate(savedInstanceState: Bundle?) {
@ -77,25 +109,30 @@ class LoginDialogFragment : DialogFragment() {
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val loginDialogActiveTypes: MutableSet<LoginDialogType> = HashSet()
val args = savedInstanceState ?: arguments
if (args != null) {
for (t in LoginDialogType.values()) {
if (args.getBoolean(t.paramKey, false)) {
loginDialogActiveTypes.add(t)
val loginDialogTypeParam = args.getString(LOGIN_DIALOG_TYPE_PARAM_KEY)
if (loginDialogTypeParam != null) {
loginDialogActiveType = LoginDialogType.valueOf(loginDialogTypeParam)
}
showProgress = args.getBoolean(SHOW_PROGRESS_PARAM_KEY, false)
showWelcomeDialog = args.getBoolean(SHOW_WELCOME_DIALOG_PARAM_KEY, false)
}
}
this.loginDialogActiveTypes = loginDialogActiveTypes
val view = inflater.inflate(R.layout.login_dialog, container)
buildDialog(view)
return view
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return object : Dialog(requireActivity(), theme) {
override fun onBackPressed() {
if (!dismissedManually) {
activity?.finish()
}
}
}
}
override fun onDismiss(dialog: DialogInterface?) {
super.onDismiss(dialog)
if (!dismissedManually) {
@ -103,22 +140,46 @@ class LoginDialogFragment : DialogFragment() {
}
}
@Suppress("DEPRECATION")
private fun buildDialog(view: View?) {
val loginDialogActiveTypes = this.loginDialogActiveTypes
var hasProgress = false
if (showWelcomeDialog) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
view?.findViewById<TextView>(R.id.welcome_descr)?.text = Html.fromHtml(getString(R.string.welcome_descr), android.text.Html.FROM_HTML_MODE_LEGACY)
} else {
view?.findViewById<TextView>(R.id.welcome_descr)?.text = Html.fromHtml(getString(R.string.welcome_descr))
}
val continueButton = view?.findViewById<Button>(R.id.welcome_continue_button)
continueButton?.setOnClickListener {
showWelcomeDialog = false
if (loginDialogActiveType == null) {
loginDialogActiveType = LoginDialogType.ENTER_PHONE_NUMBER
showProgress = true
}
buildDialog(view)
}
view?.findViewById<View>(R.id.login_layout)?.visibility = View.GONE
view?.findViewById<View>(R.id.welcome_layout)?.visibility = View.VISIBLE
} else {
view?.findViewById<View>(R.id.login_layout)?.visibility = View.VISIBLE
view?.findViewById<View>(R.id.welcome_layout)?.visibility = View.GONE
}
val loginDialogActiveType = this.loginDialogActiveType
var focusRequested = false
for (t in LoginDialogType.values()) {
val layout: View? = view?.findViewById(t.viewId)
val contains = loginDialogActiveTypes?.contains(t) ?: false
val contains = t == loginDialogActiveType && !showProgress
when {
contains -> {
if (t == LoginDialogType.SHOW_PROGRESS) {
hasProgress = true
}
if (layout != null) {
val titleView: TextView? = view.findViewById(R.id.login_title)
val descriptionView: TextView? = view.findViewById(R.id.login_description)
titleView?.text = getText(t.titleId)
descriptionView?.text = getText(t.descriptionId)
layout.visibility = View.VISIBLE
val editText: EditText? = layout.findViewById(t.editorId)
if (editText != null) {
val editText: ExtendedEditText? = layout.findViewById(t.editorId)
if (editText != null && !showWelcomeDialog) {
editText.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
applyAuthParam(t, editText.text.toString())
@ -127,7 +188,7 @@ class LoginDialogFragment : DialogFragment() {
false
}
if (!focusRequested) {
editText.requestFocus()
editText.setSelection(editText.length())
AndroidUtils.softKeyboardDelayed(editText)
focusRequested = true
}
@ -136,30 +197,39 @@ class LoginDialogFragment : DialogFragment() {
}
else -> layout?.visibility = View.GONE
}
val progressView: View? = view?.findViewById(R.id.progress_layout)
if (showProgress) {
progressView?.visibility = View.VISIBLE
} else {
progressView?.visibility = View.GONE
}
val continueButton: Button? = view?.findViewById(R.id.continueButton)
}
val continueButton: Button? = view?.findViewById(R.id.continue_button)
if (continueButton != null) {
continueButton.isEnabled = !hasProgress
if (hasProgress) {
continueButton.isEnabled = !showProgress
if (showProgress) {
continueButton.setOnClickListener(null)
} else {
continueButton.setOnClickListener {
for (t in LoginDialogType.values()) {
val layout: View? = view.findViewById(t.viewId)
val contains = loginDialogActiveTypes?.contains(t) ?: false
val contains = t == loginDialogActiveType
if (contains && layout != null) {
val editText: EditText? = layout.findViewById(t.editorId)
if (editText != null) {
applyAuthParam(t, editText.text.toString())
val editText: ExtendedEditText? = layout.findViewById(t.editorId)
val text = editText?.text.toString()
if (!TextUtils.isEmpty(text) && text.length > 1) {
applyAuthParam(t, text)
}
}
}
}
}
}
val cancelButton: Button? = view?.findViewById(R.id.calcelButton)
val cancelButton: AppCompatImageView? = view?.findViewById(R.id.back_button)
cancelButton?.visibility = if (loginDialogActiveType == LoginDialogType.ENTER_PHONE_NUMBER) View.INVISIBLE else View.VISIBLE
cancelButton?.setOnClickListener {
dismiss()
showProgress()
getMainActivity()?.loginTelegram()
}
}
@ -169,12 +239,12 @@ class LoginDialogFragment : DialogFragment() {
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
val loginDialogActiveTypes = this.loginDialogActiveTypes
if (loginDialogActiveTypes != null) {
for (t in loginDialogActiveTypes) {
outState.putBoolean(t.paramKey, true)
}
val loginDialogActiveType = this.loginDialogActiveType
if (loginDialogActiveType != null) {
outState.putString(LOGIN_DIALOG_TYPE_PARAM_KEY, loginDialogActiveType.name)
}
outState.putBoolean(SHOW_PROGRESS_PARAM_KEY, showProgress)
outState.putBoolean(SHOW_WELCOME_DIALOG_PARAM_KEY, showWelcomeDialog)
}
private fun getMainActivity(): MainActivity? {
@ -186,13 +256,15 @@ class LoginDialogFragment : DialogFragment() {
}
}
fun updateDialog(vararg loginDialogType: LoginDialogType) {
val loginDialogActiveTypes: MutableSet<LoginDialogType> = HashSet()
for (t in loginDialogType) {
loginDialogActiveTypes.add(t)
private fun updateDialog(loginDialogType: LoginDialogType? = null, welcomeDialog: Boolean = false) {
this.loginDialogActiveType = loginDialogType
showProgress = false
showWelcomeDialog = welcomeDialog
buildDialog(view)
}
this.loginDialogActiveTypes = loginDialogActiveTypes
fun showProgress() {
showProgress = true
buildDialog(view)
}
}

View file

@ -66,7 +66,10 @@ class MainActivity : AppCompatActivity(), TelegramListener {
// specify an viewAdapter (see also next example)
adapter = chatViewAdapter
}
if (!LoginDialogFragment.welcomeDialogShown) {
LoginDialogFragment.showWelcomeDialog(supportFragmentManager)
}
telegramAuthorizationRequestHandler = telegramHelper.setTelegramAuthorizationRequestHandler(object : TelegramAuthorizationRequestListener {
@ -132,9 +135,7 @@ class MainActivity : AppCompatActivity(), TelegramListener {
runOnUi {
val fm = supportFragmentManager
when (newTelegramAuthorizationState) {
TelegramAuthorizationState.READY,
TelegramAuthorizationState.CLOSED,
TelegramAuthorizationState.UNKNOWN -> LoginDialogFragment.dismiss(fm)
TelegramAuthorizationState.READY -> LoginDialogFragment.dismiss(fm)
else -> Unit
}
invalidateOptionsMenu()
@ -216,6 +217,13 @@ class MainActivity : AppCompatActivity(), TelegramListener {
}
}
fun loginTelegram() {
if (telegramHelper.getTelegramAuthorizationState() != TelegramAuthorizationState.CLOSED) {
telegramHelper.logout()
}
telegramHelper.init()
}
fun logoutTelegram(silent: Boolean = false) {
if (telegramHelper.getTelegramAuthorizationState() == TelegramAuthorizationState.READY) {
telegramHelper.logout()
@ -241,7 +249,7 @@ class MainActivity : AppCompatActivity(), TelegramListener {
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
return when (item?.itemId) {
LOGIN_MENU_ID -> {
telegramHelper.init()
loginTelegram()
true
}
LOGOUT_MENU_ID -> {
@ -312,12 +320,11 @@ class MainActivity : AppCompatActivity(), TelegramListener {
}
fun applyAuthParam(loginDialogFragment: LoginDialogFragment?, loginDialogType: LoginDialogType, text: String) {
loginDialogFragment?.updateDialog(LoginDialogType.SHOW_PROGRESS)
loginDialogFragment?.showProgress()
when (loginDialogType) {
LoginDialogType.ENTER_PHONE_NUMBER -> telegramAuthorizationRequestHandler?.applyAuthenticationParameter(TelegramAuthenticationParameterType.PHONE_NUMBER, text)
LoginDialogType.ENTER_CODE -> telegramAuthorizationRequestHandler?.applyAuthenticationParameter(TelegramAuthenticationParameterType.CODE, text)
LoginDialogType.ENTER_PASSWORD -> telegramAuthorizationRequestHandler?.applyAuthenticationParameter(TelegramAuthenticationParameterType.PASSWORD, text)
else -> Unit
}
}
@ -351,11 +358,11 @@ class MainActivity : AppCompatActivity(), TelegramListener {
val builder = AlertDialog.Builder(requireContext())
builder.setView(R.layout.install_osmand_dialog)
.setNegativeButton("Cancel", null)
.setPositiveButton("Install", { _, _ ->
.setPositiveButton("Install") { _, _ ->
val intent = Intent()
intent.data = Uri.parse("market://details?id=net.osmand.plus")
startActivity(intent)
})
}
return builder.create()
}
}

View file

@ -25,6 +25,7 @@ object AndroidUtils {
fun softKeyboardDelayed(view: View) {
view.post {
view.requestFocus()
if (!isHardwareKeyboardAvailable(view.context)) {
val imm = view.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?
imm?.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)