Merge pull request #6870 from osmandapp/TrackerSearchImprovements

Tracker search UI improvements
This commit is contained in:
Alexey 2019-04-26 12:14:09 +03:00 committed by GitHub
commit 73a91757ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 89 additions and 25 deletions

View file

@ -5,6 +5,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"> android:orientation="vertical">
<android.support.design.widget.AppBarLayout <android.support.design.widget.AppBarLayout

View file

@ -2,6 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"> android:orientation="vertical">
<android.support.design.widget.AppBarLayout <android.support.design.widget.AppBarLayout

View file

@ -217,17 +217,23 @@ class LoginDialogFragment : BaseDialogFragment() {
welcomeImage?.visibility = View.GONE welcomeImage?.visibility = View.GONE
} }
val continueButton = view?.findViewById<Button>(R.id.welcome_continue_button) view?.findViewById<Button>(R.id.welcome_continue_button)?.apply {
continueButton?.setOnClickListener { val params = layoutParams as ViewGroup.MarginLayoutParams
showWelcomeDialog = false val bottomMargin = AndroidUtils.getNavBarHeight(context) + resources.getDimensionPixelSize(R.dimen.dialog_button_bottom_padding)
if (!privacyPolicyAgreed) { params.apply {
loginDialogActiveType = LoginDialogType.PRIVACY_POLICY setMargins(leftMargin, topMargin, rightMargin, bottomMargin)
showProgress = false }
} else if (loginDialogActiveType == null) { setOnClickListener {
loginDialogActiveType = LoginDialogType.ENTER_PHONE_NUMBER showWelcomeDialog = false
showProgress = true if (!privacyPolicyAgreed) {
loginDialogActiveType = LoginDialogType.PRIVACY_POLICY
showProgress = false
} else if (loginDialogActiveType == null) {
loginDialogActiveType = LoginDialogType.ENTER_PHONE_NUMBER
showProgress = true
}
buildDialog(view)
} }
buildDialog(view)
} }
view?.findViewById<View>(R.id.login_layout)?.visibility = View.GONE view?.findViewById<View>(R.id.login_layout)?.visibility = View.GONE
view?.findViewById<View>(R.id.welcome_layout)?.visibility = View.VISIBLE view?.findViewById<View>(R.id.welcome_layout)?.visibility = View.VISIBLE

View file

@ -2,9 +2,11 @@ package net.osmand.telegram.ui
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Intent import android.content.Intent
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.support.v4.app.Fragment import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager import android.support.v4.app.FragmentManager
import android.support.v4.content.ContextCompat
import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView import android.support.v7.widget.RecyclerView
import android.support.v7.widget.Toolbar import android.support.v7.widget.Toolbar
@ -64,14 +66,14 @@ class SearchDialogFragment : BaseDialogFragment(), TelegramHelper.TelegramSearch
): View { ): View {
val mainView = inflater.inflate(R.layout.fragment_search_dialog, parent) val mainView = inflater.inflate(R.layout.fragment_search_dialog, parent)
val appBarLayout = mainView.findViewById<View>(R.id.app_bar_layout)
AndroidUtils.addStatusBarPadding19v(context!!, appBarLayout)
mainView.findViewById<Toolbar>(R.id.toolbar).apply { mainView.findViewById<Toolbar>(R.id.toolbar).apply {
navigationIcon = uiUtils.getThemedIcon(R.drawable.ic_arrow_back) navigationIcon = uiUtils.getThemedIcon(R.drawable.ic_arrow_back)
setNavigationOnClickListener { dismiss() } setNavigationOnClickListener { dismiss() }
} }
val window = dialog.window
if (window != null && Build.VERSION.SDK_INT >= 21) {
window.statusBarColor = ContextCompat.getColor(app, R.color.card_bg_light)
}
searchEditText = mainView.findViewById<EditText>(R.id.searchEditText).apply { searchEditText = mainView.findViewById<EditText>(R.id.searchEditText).apply {
addTextChangedListener(object : TextWatcher { addTextChangedListener(object : TextWatcher {
@ -104,7 +106,11 @@ class SearchDialogFragment : BaseDialogFragment(), TelegramHelper.TelegramSearch
addOnScrollListener(object : RecyclerView.OnScrollListener() { addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState) super.onScrollStateChanged(recyclerView, newState)
locationUiUpdateAllowed = newState == RecyclerView.SCROLL_STATE_IDLE val scrolling = newState != RecyclerView.SCROLL_STATE_IDLE
locationUiUpdateAllowed = !scrolling
if (scrolling) {
hideKeyboard()
}
} }
}) })
} }
@ -127,6 +133,13 @@ class SearchDialogFragment : BaseDialogFragment(), TelegramHelper.TelegramSearch
return mainView return mainView
} }
private fun hideKeyboard() {
val mainActivity = activity
if (mainActivity != null && searchEditText.hasFocus()) {
AndroidUtils.hideSoftKeyboard(mainActivity, searchEditText)
}
}
private fun clearSearchedItems() { private fun clearSearchedItems() {
searchedChatsIds.clear() searchedChatsIds.clear()
searchedPublicChatsIds.clear() searchedPublicChatsIds.clear()
@ -200,7 +213,7 @@ class SearchDialogFragment : BaseDialogFragment(), TelegramHelper.TelegramSearch
private fun updateLocationUi() { private fun updateLocationUi() {
if (locationUiUpdateAllowed) { if (locationUiUpdateAllowed) {
app.runInUIThread { updateList() } app.runInUIThread { adapter.notifyDataSetChanged() }
} }
} }
@ -211,9 +224,28 @@ class SearchDialogFragment : BaseDialogFragment(), TelegramHelper.TelegramSearch
val users: MutableList<TdApi.User> = mutableListOf() val users: MutableList<TdApi.User> = mutableListOf()
val currentUserId = telegramHelper.getCurrentUserId() val currentUserId = telegramHelper.getCurrentUserId()
searchedChatsIds.forEach { selectedChats.forEach {
val chat = telegramHelper.getChat(it) val chat = telegramHelper.getChat(it)
if (chat != null) { if (chat != null) {
if (!telegramHelper.isChannel(chat) && telegramHelper.getUserIdFromChatType(chat.type) != currentUserId) {
items.add(chat)
}
} else {
telegramHelper.requestChat(it)
}
}
selectedUsers.forEach {
val user = telegramHelper.getUser(it.toInt())
if (user != null) {
if (user.id != currentUserId)
items.add(user)
} else {
telegramHelper.requestUser(it.toInt())
}
}
searchedChatsIds.forEach {
val chat = telegramHelper.getChat(it)
if (chat != null && !selectedChats.contains(it)) {
if (!telegramHelper.isChannel(chat) && telegramHelper.getUserIdFromChatType(chat.type) != currentUserId) { if (!telegramHelper.isChannel(chat) && telegramHelper.getUserIdFromChatType(chat.type) != currentUserId) {
chats.add(chat) chats.add(chat)
} }
@ -225,7 +257,7 @@ class SearchDialogFragment : BaseDialogFragment(), TelegramHelper.TelegramSearch
searchedContactsIds.forEach { userId -> searchedContactsIds.forEach { userId ->
val user = telegramHelper.getUser(userId) val user = telegramHelper.getUser(userId)
if (user != null) { if (user != null && !selectedUsers.contains(userId.toLong())) {
if (user.id != currentUserId && !chats.any { telegramHelper.getUserIdFromChatType(it.type) == user.id }) if (user.id != currentUserId && !chats.any { telegramHelper.getUserIdFromChatType(it.type) == user.id })
users.add(user) users.add(user)
} else { } else {
@ -236,9 +268,8 @@ class SearchDialogFragment : BaseDialogFragment(), TelegramHelper.TelegramSearch
searchedPublicChatsIds.forEach { searchedPublicChatsIds.forEach {
val chat = telegramHelper.getChat(it) val chat = telegramHelper.getChat(it)
if (chat != null) { if (chat != null && !selectedChats.contains(it) && !searchedChatsIds.contains(it)) {
if (!telegramHelper.isChannel(chat) && !chats.contains(chat) if (!telegramHelper.isChannel(chat) && telegramHelper.getUserIdFromChatType(chat.type) != currentUserId) {
&& telegramHelper.getUserIdFromChatType(chat.type) != currentUserId) {
publicChats.add(chat) publicChats.add(chat)
} }
} else { } else {
@ -370,6 +401,9 @@ class SearchDialogFragment : BaseDialogFragment(), TelegramHelper.TelegramSearch
} else { } else {
selectedUsers.remove(itemId) selectedUsers.remove(itemId)
} }
if (!(searchedChatsIds.contains(itemId) || searchedPublicChatsIds.contains(itemId) || searchedContactsIds.contains(itemId.toInt()))) {
updateList()
}
} }
switchButtonsVisibility(selectedChats.isNotEmpty() || selectedUsers.isNotEmpty()) switchButtonsVisibility(selectedChats.isNotEmpty() || selectedUsers.isNotEmpty())
} }

View file

@ -5,6 +5,7 @@ import android.graphics.drawable.Drawable
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.support.v4.app.FragmentManager import android.support.v4.app.FragmentManager
import android.support.v4.content.ContextCompat
import android.support.v7.widget.ListPopupWindow import android.support.v7.widget.ListPopupWindow
import android.support.v7.widget.Toolbar import android.support.v7.widget.Toolbar
import android.text.SpannableStringBuilder import android.text.SpannableStringBuilder
@ -39,14 +40,14 @@ class SettingsDialogFragment : BaseDialogFragment() {
): View { ): View {
val mainView = inflater.inflate(R.layout.fragement_settings_dialog, parent) val mainView = inflater.inflate(R.layout.fragement_settings_dialog, parent)
val appBarLayout = mainView.findViewById<View>(R.id.app_bar_layout)
AndroidUtils.addStatusBarPadding19v(context!!, appBarLayout)
mainView.findViewById<Toolbar>(R.id.toolbar).apply { mainView.findViewById<Toolbar>(R.id.toolbar).apply {
navigationIcon = uiUtils.getThemedIcon(R.drawable.ic_arrow_back) navigationIcon = uiUtils.getThemedIcon(R.drawable.ic_arrow_back)
setNavigationOnClickListener { dismiss() } setNavigationOnClickListener { dismiss() }
} }
val window = dialog.window
if (window != null && Build.VERSION.SDK_INT >= 21) {
window.statusBarColor = ContextCompat.getColor(app, R.color.card_bg_light)
}
var container = mainView.findViewById<ViewGroup>(R.id.gps_and_loc_container) var container = mainView.findViewById<ViewGroup>(R.id.gps_and_loc_container)
for (pref in settings.gpsAndLocPrefs) { for (pref in settings.gpsAndLocPrefs) {
inflater.inflate(R.layout.item_with_desc_and_right_value, container, false).apply { inflater.inflate(R.layout.item_with_desc_and_right_value, container, false).apply {

View file

@ -106,6 +106,27 @@ object AndroidUtils {
} }
} }
fun getNavBarHeight(ctx: Context): Int {
if (!hasNavBar(ctx)) {
return 0
}
val landscape = ctx.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
val isSmartphone = ctx.resources.configuration.smallestScreenWidthDp < 600
if (isSmartphone && landscape) {
return 0
}
val name = if (landscape) "navigation_bar_height_landscape" else "navigation_bar_height"
val id = ctx.resources.getIdentifier(name, "dimen", "android")
return if (id > 0) {
ctx.resources.getDimensionPixelSize(id)
} else 0
}
fun hasNavBar(ctx: Context): Boolean {
val id = ctx.resources.getIdentifier("config_showNavigationBar", "bool", "android")
return id > 0 && ctx.resources.getBoolean(id)
}
fun enterToTransparentFullScreen(activity: Activity) { fun enterToTransparentFullScreen(activity: Activity) {
if (Build.VERSION.SDK_INT >= 23) { if (Build.VERSION.SDK_INT >= 23) {
val window = activity.window val window = activity.window