Merge branch 'master' of ssh://github.com/osmandapp/Osmand into UiImprovements
# Conflicts: # OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt
This commit is contained in:
commit
85a01ba2c7
4 changed files with 57 additions and 258 deletions
|
@ -1,60 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:descendantFocusability="blocksDescendants"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/card_bg_color"
|
||||
android:minHeight="@dimen/list_item_height_min"
|
||||
android:orientation="horizontal"
|
||||
android:paddingBottom="@dimen/content_padding_half"
|
||||
android:paddingLeft="@dimen/content_padding_standard"
|
||||
android:paddingStart="@dimen/content_padding_standard"
|
||||
android:paddingTop="@dimen/content_padding_half">
|
||||
|
||||
<android.support.v7.widget.AppCompatImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:scaleType="centerInside"
|
||||
android:src="@drawable/img_group_picture"
|
||||
android:visibility="visible" />
|
||||
|
||||
<android.support.v7.widget.AppCompatTextView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="@dimen/content_padding_half"
|
||||
android:layout_marginStart="@dimen/content_padding_half"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical"
|
||||
tools:text="Group name" />
|
||||
|
||||
<android.support.v7.widget.SwitchCompat
|
||||
android:id="@+id/share_location_switch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginEnd="@dimen/content_padding_half"
|
||||
android:layout_marginLeft="@dimen/content_padding_standard"
|
||||
android:layout_marginRight="@dimen/content_padding_half"
|
||||
android:layout_marginStart="@dimen/content_padding_standard"
|
||||
android:focusableInTouchMode="true" />
|
||||
|
||||
<android.support.v7.widget.SwitchCompat
|
||||
android:id="@+id/show_on_map_switch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
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:focusableInTouchMode="true" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -1,22 +1,18 @@
|
|||
package net.osmand.telegram.ui
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Dialog
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.support.design.widget.BottomNavigationView
|
||||
import android.support.v4.app.*
|
||||
import android.support.v4.app.DialogFragment
|
||||
import android.support.v4.app.Fragment
|
||||
import android.support.v4.app.FragmentManager
|
||||
import android.support.v4.app.FragmentPagerAdapter
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.support.v7.widget.AppCompatImageView
|
||||
import android.support.v7.widget.AppCompatTextView
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.support.v7.widget.SwitchCompat
|
||||
import android.view.*
|
||||
import android.view.View
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
|
@ -34,10 +30,6 @@ import java.lang.ref.WeakReference
|
|||
|
||||
private const val PERMISSION_REQUEST_LOCATION = 1
|
||||
|
||||
private const val LOGIN_MENU_ID = 0
|
||||
private const val LOGOUT_MENU_ID = 1
|
||||
private const val PROGRESS_MENU_ID = 2
|
||||
|
||||
private const val MY_LOCATION_TAB_POS = 0
|
||||
private const val LIVE_NOW_TAB_POS = 1
|
||||
|
||||
|
@ -151,9 +143,6 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
|||
super.onResume()
|
||||
paused = false
|
||||
|
||||
invalidateOptionsMenu()
|
||||
updateTitle()
|
||||
|
||||
app.locationProvider.checkIfLastKnownLocationIsValid()
|
||||
|
||||
if (AndroidUtils.isLocationPermissionAvailable(this)) {
|
||||
|
@ -196,8 +185,6 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
|||
TelegramAuthorizationState.READY -> LoginDialogFragment.dismiss(fm)
|
||||
else -> Unit
|
||||
}
|
||||
invalidateOptionsMenu()
|
||||
updateTitle()
|
||||
|
||||
listeners.forEach {
|
||||
it.get()?.onTelegramStatusChanged(prevTelegramAuthorizationState, newTelegramAuthorizationState)
|
||||
|
@ -269,18 +256,6 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
|||
telegramHelper.init()
|
||||
}
|
||||
|
||||
fun logoutTelegram(silent: Boolean = false) {
|
||||
if (telegramHelper.getTelegramAuthorizationState() == TelegramAuthorizationState.READY) {
|
||||
telegramHelper.logout()
|
||||
} else {
|
||||
invalidateOptionsMenu()
|
||||
updateTitle()
|
||||
if (!silent) {
|
||||
Toast.makeText(this, R.string.not_logged_in, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun closeTelegram() {
|
||||
telegramHelper.close()
|
||||
}
|
||||
|
@ -291,71 +266,6 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
|||
}
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
|
||||
return when (item?.itemId) {
|
||||
LOGIN_MENU_ID -> {
|
||||
loginTelegram()
|
||||
true
|
||||
}
|
||||
LOGOUT_MENU_ID -> {
|
||||
logoutTelegram()
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
if (menu != null) {
|
||||
menu.clear()
|
||||
when (telegramHelper.getTelegramAuthorizationState()) {
|
||||
TelegramAuthorizationState.UNKNOWN,
|
||||
TelegramAuthorizationState.WAIT_PARAMETERS,
|
||||
TelegramAuthorizationState.WAIT_PHONE_NUMBER,
|
||||
TelegramAuthorizationState.WAIT_CODE,
|
||||
TelegramAuthorizationState.WAIT_PASSWORD,
|
||||
TelegramAuthorizationState.LOGGING_OUT,
|
||||
TelegramAuthorizationState.CLOSING -> createProgressMenuItem(menu)
|
||||
TelegramAuthorizationState.READY -> createMenuItem(menu, LOGOUT_MENU_ID, R.string.shared_string_logout,
|
||||
MenuItem.SHOW_AS_ACTION_WITH_TEXT or MenuItem.SHOW_AS_ACTION_ALWAYS)
|
||||
TelegramAuthorizationState.CLOSED -> createMenuItem(menu, LOGIN_MENU_ID, R.string.shared_string_login,
|
||||
MenuItem.SHOW_AS_ACTION_WITH_TEXT or MenuItem.SHOW_AS_ACTION_ALWAYS)
|
||||
}
|
||||
}
|
||||
return super.onCreateOptionsMenu(menu)
|
||||
}
|
||||
|
||||
private fun createMenuItem(m: Menu, id: Int, titleRes: Int, menuItemType: Int): MenuItem {
|
||||
val menuItem = m.add(0, id, 0, titleRes)
|
||||
menuItem.setOnMenuItemClickListener { item -> onOptionsItemSelected(item) }
|
||||
menuItem.setShowAsAction(menuItemType)
|
||||
return menuItem
|
||||
}
|
||||
|
||||
private fun createProgressMenuItem(m: Menu): MenuItem {
|
||||
|
||||
val menuItem = m.add(0, PROGRESS_MENU_ID, 0, "")
|
||||
menuItem.actionView = layoutInflater.inflate(R.layout.action_progress_bar, null)
|
||||
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
|
||||
return menuItem
|
||||
}
|
||||
|
||||
private fun updateTitle() {
|
||||
title = when (telegramHelper.getTelegramAuthorizationState()) {
|
||||
|
||||
TelegramAuthorizationState.UNKNOWN,
|
||||
TelegramAuthorizationState.WAIT_PHONE_NUMBER,
|
||||
TelegramAuthorizationState.WAIT_CODE,
|
||||
TelegramAuthorizationState.WAIT_PASSWORD,
|
||||
TelegramAuthorizationState.READY,
|
||||
TelegramAuthorizationState.CLOSED -> getString(R.string.app_name)
|
||||
|
||||
TelegramAuthorizationState.WAIT_PARAMETERS -> getString(R.string.initialization) + "..."
|
||||
TelegramAuthorizationState.LOGGING_OUT -> getString(R.string.logging_out) + "..."
|
||||
TelegramAuthorizationState.CLOSING -> getString(R.string.closing) + "..."
|
||||
}
|
||||
}
|
||||
|
||||
private fun showLoginDialog(telegramAuthenticationParameterType: TelegramAuthenticationParameterType) {
|
||||
when (telegramAuthenticationParameterType) {
|
||||
TelegramAuthenticationParameterType.PHONE_NUMBER -> LoginDialogFragment.showDialog(supportFragmentManager, LoginDialogType.ENTER_PHONE_NUMBER)
|
||||
|
@ -396,7 +306,7 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
|||
}
|
||||
}
|
||||
|
||||
fun showOsmandMissingDialog() {
|
||||
private fun showOsmandMissingDialog() {
|
||||
OsmandMissingDialogFragment().show(supportFragmentManager, null)
|
||||
}
|
||||
|
||||
|
@ -423,90 +333,4 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
|||
|
||||
override fun getCount() = fragments.size
|
||||
}
|
||||
|
||||
inner class ChatsAdapter :
|
||||
RecyclerView.Adapter<ChatsAdapter.ViewHolder>() {
|
||||
|
||||
var chats: List<TdApi.Chat> = emptyList()
|
||||
set(value) {
|
||||
field = value
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
inner class ViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
|
||||
val icon: AppCompatImageView? = view.findViewById(R.id.icon)
|
||||
val groupName: AppCompatTextView? = view.findViewById(R.id.name)
|
||||
val shareLocationSwitch: SwitchCompat? = view.findViewById(R.id.share_location_switch)
|
||||
val showOnMapSwitch: SwitchCompat? = view.findViewById(R.id.show_on_map_switch)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val view = LayoutInflater.from(parent.context).inflate(R.layout.chat_list_item, parent, false)
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val chat = chats[position]
|
||||
val chatId = chat.id
|
||||
holder.groupName?.text = chat.title
|
||||
|
||||
var drawable: Drawable? = null
|
||||
var bitmap: Bitmap? = null
|
||||
val chatPhoto = chat.photo?.small
|
||||
if (chatPhoto != null && chatPhoto.local.path.isNotEmpty()) {
|
||||
bitmap = app.uiUtils.getCircleBitmap(chatPhoto.local.path)
|
||||
}
|
||||
if (bitmap == null) {
|
||||
drawable = app.uiUtils.getThemedIcon(R.drawable.ic_group)
|
||||
}
|
||||
if (bitmap != null) {
|
||||
holder.icon?.setImageBitmap(bitmap)
|
||||
} else {
|
||||
holder.icon?.setImageDrawable(drawable)
|
||||
}
|
||||
holder.shareLocationSwitch?.setOnCheckedChangeListener(null)
|
||||
holder.shareLocationSwitch?.isChecked = settings.isSharingLocationToChat(chatId)
|
||||
holder.shareLocationSwitch?.setOnCheckedChangeListener { view, isChecked ->
|
||||
settings.shareLocationToChat(chatId, isChecked)
|
||||
if (settings.hasAnyChatToShareLocation()) {
|
||||
if (!AndroidUtils.isLocationPermissionAvailable(view.context)) {
|
||||
if (isChecked) {
|
||||
AndroidUtils.requestLocationPermission(this@MainActivity)
|
||||
}
|
||||
} else {
|
||||
app.shareLocationHelper.startSharingLocation()
|
||||
}
|
||||
} else {
|
||||
app.shareLocationHelper.stopSharingLocation()
|
||||
}
|
||||
}
|
||||
|
||||
holder.showOnMapSwitch?.setOnCheckedChangeListener(null)
|
||||
holder.showOnMapSwitch?.isChecked = settings.isShowingChatOnMap(chatId)
|
||||
holder.showOnMapSwitch?.setOnCheckedChangeListener { _, isChecked ->
|
||||
settings.showChatOnMap(chatId, isChecked)
|
||||
if (settings.hasAnyChatToShowOnMap()) {
|
||||
if (osmandAidlHelper.isOsmandNotInstalled()) {
|
||||
if (isChecked) {
|
||||
showOsmandMissingDialog()
|
||||
}
|
||||
} else {
|
||||
if (isChecked) {
|
||||
app.showLocationHelper.showChatMessages(chatId)
|
||||
} else {
|
||||
app.showLocationHelper.hideChatMessages(chatId)
|
||||
}
|
||||
app.showLocationHelper.startShowingLocation()
|
||||
}
|
||||
} else {
|
||||
app.showLocationHelper.stopShowingLocation()
|
||||
if (!isChecked) {
|
||||
app.showLocationHelper.hideChatMessages(chatId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount() = chats.size
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.osmand.telegram.ui
|
||||
|
||||
import android.animation.*
|
||||
import android.content.Intent
|
||||
import android.graphics.Paint
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.os.Build
|
||||
|
@ -156,6 +157,13 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
outState.putLongArray(SELECTED_CHATS_KEY, selectedChats.toLongArray())
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (requestCode == SetTimeDialogFragment.LOCATION_SHARED_REQUEST_CODE) {
|
||||
clearSelection()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onTelegramStatusChanged(
|
||||
prevTelegramAuthorizationState: TelegramHelper.TelegramAuthorizationState,
|
||||
newTelegramAuthorizationState: TelegramHelper.TelegramAuthorizationState
|
||||
|
@ -195,12 +203,15 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
}
|
||||
|
||||
fun onPrimaryBtnClick() {
|
||||
activity?.supportFragmentManager?.also {
|
||||
SetTimeDialogFragment.showInstance(it, selectedChats)
|
||||
}
|
||||
val fm = fragmentManager ?: return
|
||||
SetTimeDialogFragment.showInstance(fm, selectedChats, this)
|
||||
}
|
||||
|
||||
fun onSecondaryBtnClick() {
|
||||
clearSelection()
|
||||
}
|
||||
|
||||
private fun clearSelection() {
|
||||
selectedChats.clear()
|
||||
adapter.notifyDataSetChanged()
|
||||
actionButtonsListener?.switchButtonsVisibility(false)
|
||||
|
@ -345,10 +356,17 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
val chat = chats[position]
|
||||
val lastItem = position == itemCount - 1
|
||||
val placeholderId: Int = if (telegramHelper.isGroup(chat)) R.drawable.img_group_picture else R.drawable.img_user_picture
|
||||
val live = app.settings.isSharingLocationToChat(chat.id)
|
||||
|
||||
TelegramUiHelper.setupPhoto(app, holder.icon, chat.photo?.small?.local?.path, placeholderId, false)
|
||||
holder.title?.text = chat.title
|
||||
holder.description?.text = "Some description" // FIXME
|
||||
if (live) {
|
||||
holder.checkBox?.visibility = View.GONE
|
||||
holder.textInArea?.visibility = View.VISIBLE
|
||||
holder.textInArea?.text = getString(R.string.shared_string_live)
|
||||
} else {
|
||||
holder.textInArea?.visibility = View.GONE
|
||||
holder.checkBox?.apply {
|
||||
visibility = View.VISIBLE
|
||||
setOnCheckedChangeListener(null)
|
||||
|
@ -362,13 +380,22 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
actionButtonsListener?.switchButtonsVisibility(selectedChats.isNotEmpty())
|
||||
}
|
||||
}
|
||||
}
|
||||
holder.bottomShadow?.visibility = if (lastItem) View.VISIBLE else View.GONE
|
||||
holder.itemView.setOnClickListener {
|
||||
if (live) {
|
||||
app.settings.shareLocationToChat(chat.id, false)
|
||||
if (!app.settings.hasAnyChatToShareLocation()) {
|
||||
app.shareLocationHelper.stopSharingLocation()
|
||||
}
|
||||
notifyItemChanged(position)
|
||||
} else {
|
||||
holder.checkBox?.apply {
|
||||
isChecked = !isChecked
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount() = chats.size
|
||||
|
||||
|
@ -376,6 +403,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
val icon: ImageView? = view.findViewById(R.id.icon)
|
||||
val title: TextView? = view.findViewById(R.id.title)
|
||||
val description: TextView? = view.findViewById(R.id.description)
|
||||
val textInArea: TextView? = view.findViewById(R.id.text_in_area)
|
||||
val checkBox: CheckBox? = view.findViewById(R.id.check_box)
|
||||
val bottomShadow: View? = view.findViewById(R.id.bottom_shadow)
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.telegram.ui
|
|||
import android.app.TimePickerDialog
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.DialogFragment
|
||||
import android.support.v4.app.Fragment
|
||||
import android.support.v4.app.FragmentManager
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import android.support.v7.widget.RecyclerView
|
||||
|
@ -84,6 +85,9 @@ class SetTimeDialogFragment : DialogFragment() {
|
|||
settings.shareLocationToChat(chatId, true, livePeriod)
|
||||
}
|
||||
app.shareLocationHelper.startSharingLocation()
|
||||
targetFragment?.also {
|
||||
it.onActivityResult(targetRequestCode, LOCATION_SHARED_REQUEST_CODE, null)
|
||||
}
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
@ -236,12 +240,14 @@ class SetTimeDialogFragment : DialogFragment() {
|
|||
|
||||
companion object {
|
||||
|
||||
const val LOCATION_SHARED_REQUEST_CODE = 0
|
||||
|
||||
private const val TAG = "SetTimeDialogFragment"
|
||||
private const val CHATS_KEY = "chats_key"
|
||||
private const val DEFAULT_VISIBLE_TIME_SECONDS = 60 * 60L // 1 hour
|
||||
private const val NO_VALUE = -1L
|
||||
|
||||
fun showInstance(fm: FragmentManager, chatIds: Set<Long>): Boolean {
|
||||
fun showInstance(fm: FragmentManager, chatIds: Set<Long>, target: Fragment): Boolean {
|
||||
return try {
|
||||
val chats = mutableListOf<Long>()
|
||||
for (id in chatIds) {
|
||||
|
@ -250,6 +256,7 @@ class SetTimeDialogFragment : DialogFragment() {
|
|||
}
|
||||
SetTimeDialogFragment().apply {
|
||||
arguments = Bundle().apply { putLongArray(CHATS_KEY, chats.toLongArray()) }
|
||||
setTargetFragment(target, LOCATION_SHARED_REQUEST_CODE)
|
||||
show(fm, TAG)
|
||||
}
|
||||
true
|
||||
|
|
Loading…
Reference in a new issue