Add local device for sharing to telegram and remove unnecessary dialog
This commit is contained in:
parent
06e80d514d
commit
a061640579
5 changed files with 13 additions and 229 deletions
|
@ -1,111 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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="wrap_content"
|
||||
android:orientation="vertical"
|
||||
tools:layout_gravity="bottom">
|
||||
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
android:id="@+id/scroll_view_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<android.support.v4.widget.NestedScrollView
|
||||
android:id="@+id/scroll_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:behavior_hideable="true"
|
||||
app:behavior_peekHeight="@dimen/bottom_sheet_peek_height"
|
||||
app:layout_behavior="@string/bottom_sheet_behavior">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/card_bg_color"
|
||||
android:orientation="vertical">
|
||||
|
||||
<net.osmand.telegram.ui.views.TextViewEx
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="@dimen/content_padding_standard"
|
||||
android:paddingRight="@dimen/content_padding_standard"
|
||||
android:text="@string/logout_from_osmand_telegram"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/list_item_title_text_size"
|
||||
app:firstBaselineToTopHeight="28sp"
|
||||
app:typeface="@string/font_roboto_medium" />
|
||||
|
||||
<net.osmand.telegram.ui.views.TextViewEx
|
||||
android:id="@+id/description"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="@dimen/content_padding_standard"
|
||||
android:paddingRight="@dimen/content_padding_standard"
|
||||
android:text="@string/add_device_descr"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:textSize="@dimen/list_item_description_text_size"
|
||||
app:firstBaselineToTopHeight="28sp"
|
||||
app:lastBaselineToBottomHeight="16sp"
|
||||
app:typeface="@string/font_roboto_regular" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/enter_device_id_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:visibility="visible"
|
||||
tools:visibility="visible">
|
||||
|
||||
<studio.carbonylgroup.textfieldboxes.TextFieldBoxes
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:hasClearButton="true">
|
||||
|
||||
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
|
||||
android:id="@+id/device_id_edit_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/device_id"
|
||||
android:inputType="text" />
|
||||
|
||||
</studio.carbonylgroup.textfieldboxes.TextFieldBoxes>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/buttons_bottom_bar_height"
|
||||
android:background="?attr/card_bg_color"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingLeft="@dimen/content_padding_half"
|
||||
android:paddingRight="@dimen/content_padding_half">
|
||||
|
||||
<include
|
||||
layout="@layout/secondary_btn"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<View
|
||||
android:layout_width="@dimen/content_padding_half"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<include
|
||||
layout="@layout/primary_btn"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -134,6 +134,7 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
}
|
||||
|
||||
fun updateShareDevicesIds(list: List<DeviceBot>) {
|
||||
shareDevicesIds.clear()
|
||||
list.forEach {
|
||||
shareDevicesIds[it.externalId] = it.deviceName
|
||||
}
|
||||
|
@ -179,10 +180,6 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
hiddenOnMapChats = hiddenChats.toHashSet()
|
||||
}
|
||||
|
||||
fun addSharingDevice(deviceId: String) {
|
||||
shareDevicesIds[deviceId] = deviceId
|
||||
}
|
||||
|
||||
fun getShareLocationChats() = ArrayList(shareLocationChats)
|
||||
|
||||
fun getShowOnMapChats() = getLiveNowChats().minus(hiddenOnMapChats)
|
||||
|
|
|
@ -41,14 +41,13 @@ class ShareLocationHelper(private val app: TelegramApplication) {
|
|||
if (location != null && app.isInternetConnectionAvailable) {
|
||||
val chatLivePeriods = app.settings.getChatLivePeriods()
|
||||
if (chatLivePeriods.isNotEmpty()) {
|
||||
if (app.settings.currentSharingMode == null) {
|
||||
val user = app.telegramHelper.getCurrentUser()
|
||||
if (user != null && app.settings.currentSharingMode == TelegramUiHelper.getUserName(user)) {
|
||||
app.telegramHelper.sendLiveLocationMessage(chatLivePeriods, location.latitude, location.longitude)
|
||||
} else {
|
||||
chatLivePeriods.forEach { (chatId, livePeriod) ->
|
||||
val deviceId = app.settings.currentSharingMode
|
||||
val url = "https://live.osmand.net/device/$deviceId/send?lat=${location.latitude}&lon=${location.longitude}"
|
||||
AndroidNetworkUtils.sendRequestAsync(url, null)
|
||||
}
|
||||
val deviceId = app.settings.currentSharingMode
|
||||
val url = "https://live.osmand.net/device/$deviceId/send?lat=${location.latitude}&lon=${location.longitude}"
|
||||
AndroidNetworkUtils.sendRequestAsync(url, null)
|
||||
}
|
||||
}
|
||||
lastLocationMessageSentTime = System.currentTimeMillis()
|
||||
|
|
|
@ -1,91 +0,0 @@
|
|||
package net.osmand.telegram.ui
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.design.widget.BottomSheetBehavior
|
||||
import android.support.v4.app.DialogFragment
|
||||
import android.support.v4.app.Fragment
|
||||
import android.support.v4.app.FragmentManager
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.EditText
|
||||
import android.widget.TextView
|
||||
import net.osmand.telegram.R
|
||||
import net.osmand.telegram.TelegramApplication
|
||||
import net.osmand.telegram.ui.views.BottomSheetDialog
|
||||
|
||||
|
||||
class AddDeviceBottomSheet : DialogFragment() {
|
||||
private lateinit var editText: EditText
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?) = BottomSheetDialog(context!!)
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
val mainView = inflater.inflate(R.layout.bottom_sheet_add_device, container, false)
|
||||
|
||||
mainView.findViewById<View>(R.id.scroll_view_container).setOnClickListener { dismiss() }
|
||||
|
||||
BottomSheetBehavior.from(mainView.findViewById<View>(R.id.scroll_view))
|
||||
.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
|
||||
|
||||
override fun onStateChanged(bottomSheet: View, newState: Int) {
|
||||
if (newState == BottomSheetBehavior.STATE_HIDDEN) {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSlide(bottomSheet: View, slideOffset: Float) {}
|
||||
})
|
||||
|
||||
editText = mainView.findViewById<EditText>(R.id.device_id_edit_text)
|
||||
|
||||
mainView.findViewById<TextView>(R.id.secondary_btn).apply {
|
||||
setText(R.string.shared_string_cancel)
|
||||
setOnClickListener { dismiss() }
|
||||
}
|
||||
|
||||
mainView.findViewById<TextView>(R.id.primary_btn).apply {
|
||||
setText(R.string.shared_string_save)
|
||||
setOnClickListener {
|
||||
val app = activity?.application as TelegramApplication
|
||||
val settings = app.settings
|
||||
val newDeviceId = editText.text.toString()
|
||||
settings.addSharingDevice(newDeviceId)
|
||||
targetFragment?.also { target ->
|
||||
val intent = Intent()
|
||||
intent.putExtra(NEW_DEVICE_ID, newDeviceId)
|
||||
target.onActivityResult(targetRequestCode, ADD_DEVICE_REQUEST_CODE, intent)
|
||||
}
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return mainView
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
const val ADD_DEVICE_REQUEST_CODE = 5
|
||||
const val NEW_DEVICE_ID = "NEW_DEVICE_ID"
|
||||
|
||||
private const val TAG = "AddDeviceBottomSheet"
|
||||
|
||||
fun showInstance(fm: FragmentManager, target: Fragment): Boolean {
|
||||
return try {
|
||||
AddDeviceBottomSheet().apply {
|
||||
setTargetFragment(target, ADD_DEVICE_REQUEST_CODE)
|
||||
show(fm, TAG)
|
||||
}
|
||||
true
|
||||
} catch (e: RuntimeException) {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -94,6 +94,12 @@ class SettingsDialogFragment : BaseDialogFragment() {
|
|||
|
||||
container = mainView.findViewById(R.id.share_as_container)
|
||||
val user = telegramHelper.getCurrentUser()
|
||||
if (user != null) {
|
||||
val name = TelegramUiHelper.getUserName(user)
|
||||
if (!settings.shareDevicesIds.containsKey(name)) {
|
||||
settings.shareDevicesIds[name] = name
|
||||
}
|
||||
}
|
||||
settings.shareDevicesIds.forEach {
|
||||
val title = it.key
|
||||
inflater.inflate(R.layout.item_with_rb_and_btn, container, false).apply {
|
||||
|
@ -104,11 +110,7 @@ class SettingsDialogFragment : BaseDialogFragment() {
|
|||
isChecked = title == settings.currentSharingMode
|
||||
}
|
||||
setOnClickListener {
|
||||
if (user != null && TelegramUiHelper.getUserName(user) == title) {
|
||||
settings.currentSharingMode = null
|
||||
} else {
|
||||
settings.currentSharingMode = title
|
||||
}
|
||||
settings.currentSharingMode = title
|
||||
updateSelectedSharingMode()
|
||||
}
|
||||
tag = title
|
||||
|
@ -116,13 +118,6 @@ class SettingsDialogFragment : BaseDialogFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
mainView.findViewById<TextView>(R.id.add_device).setOnClickListener {
|
||||
val fm = fragmentManager
|
||||
if (fm != null) {
|
||||
AddDeviceBottomSheet.showInstance(fm, this)
|
||||
}
|
||||
}
|
||||
|
||||
if (user != null) {
|
||||
TelegramUiHelper.setupPhoto(
|
||||
app,
|
||||
|
@ -159,11 +154,6 @@ class SettingsDialogFragment : BaseDialogFragment() {
|
|||
logoutTelegram()
|
||||
dismiss()
|
||||
}
|
||||
AddDeviceBottomSheet.ADD_DEVICE_REQUEST_CODE -> {
|
||||
if (data != null && data.hasExtra(AddDeviceBottomSheet.NEW_DEVICE_ID)) {
|
||||
addNewSharingDevice(data.getStringExtra(AddDeviceBottomSheet.NEW_DEVICE_ID))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue