Add DisableSharingBottomSheet and related stuff

This commit is contained in:
Alex Sytnyk 2018-08-30 19:06:59 +03:00
parent 72f5be448a
commit 491b628d90
5 changed files with 191 additions and 13 deletions

View file

@ -0,0 +1,86 @@
<?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/disable_all_sharing"
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:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/list_item_description_text_size"
app:firstBaselineToTopHeight="28sp"
app:lastBaselineToBottomHeight="16sp"
app:typeface="@string/font_roboto_regular"
tools:text="@string/disable_all_sharing_desc"/>
</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>

View file

@ -186,6 +186,7 @@
android:id="@+id/stop_all_sharing_row"
android:layout_width="match_parent"
android:layout_height="@dimen/action_bar_height"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:paddingLeft="@dimen/content_padding_standard"
android:paddingRight="@dimen/content_padding_standard">
@ -207,7 +208,10 @@
<Switch
android:id="@+id/stop_all_sharing_switcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:focusable="false"/>
</LinearLayout>

View file

@ -1,4 +1,7 @@
<resources>
<string name="disable_all_sharing_desc">It will disable sharing your location to all selected chats (%1$d).</string>
<string name="disable_all_sharing">Disable all sharing</string>
<string name="turn_off_all">Turn off all</string>
<string name="shared_string_exit">Exit</string>
<string name="time_ago">ago</string>
<string name="last_response">Last response</string>

View file

@ -0,0 +1,81 @@
package net.osmand.telegram.ui
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.TextView
import net.osmand.telegram.R
import net.osmand.telegram.ui.views.BottomSheetDialog
class DisableSharingBottomSheet : DialogFragment() {
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_disable_sharing, 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) {}
})
mainView.findViewById<TextView>(R.id.description).text =
getString(R.string.disable_all_sharing_desc, arguments?.getInt(CHATS_COUNT_KEY, -1))
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.turn_off_all)
setOnClickListener {
targetFragment?.also { target ->
target.onActivityResult(targetRequestCode, SHARING_DISABLED_REQUEST_CODE, null)
}
dismiss()
}
}
return mainView
}
companion object {
const val SHARING_DISABLED_REQUEST_CODE = 1
private const val TAG = "DisableSharingBottomSheet"
private const val CHATS_COUNT_KEY = "chats_count"
fun showInstance(fm: FragmentManager, target: Fragment, chatsCount: Int): Boolean {
return try {
DisableSharingBottomSheet().apply {
arguments = Bundle().apply { putInt(CHATS_COUNT_KEY, chatsCount) }
setTargetFragment(target, SHARING_DISABLED_REQUEST_CODE)
show(fm, TAG)
}
true
} catch (e: RuntimeException) {
false
}
}
}
}

View file

@ -178,17 +178,14 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
})
}
stopSharingSwitcher = mainView.findViewById<Switch>(R.id.stop_all_sharing_switcher).apply {
isChecked = sharingMode
setOnCheckedChangeListener { _, isChecked ->
if (!isChecked) {
sharingMode = isChecked
activity.stopSharingLocation()
updateContent()
}
mainView.findViewById<View>(R.id.stop_all_sharing_row).setOnClickListener {
fragmentManager?.also { fm ->
DisableSharingBottomSheet.showInstance(fm, this, adapter.chats.size)
}
}
stopSharingSwitcher = mainView.findViewById(R.id.stop_all_sharing_switcher)
startSharingBtn = mainView.findViewById<View>(R.id.start_sharing_btn).apply {
visibility = if (sharingMode) View.VISIBLE else View.GONE
setOnClickListener {
@ -221,11 +218,18 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == SetTimeDialogFragment.LOCATION_SHARED_REQUEST_CODE) {
when (requestCode) {
SetTimeDialogFragment.LOCATION_SHARED_REQUEST_CODE -> {
sharingMode = settings.hasAnyChatToShareLocation()
clearSelection()
updateContent()
}
DisableSharingBottomSheet.SHARING_DISABLED_REQUEST_CODE -> {
sharingMode = false
(activity as MainActivity).stopSharingLocation()
updateContent()
}
}
}
override fun onTelegramStatusChanged(