SettingsDialogFragment in progress

This commit is contained in:
Alex Sytnyk 2018-08-08 19:17:00 +03:00
parent a75a8e3bda
commit fea565192d
6 changed files with 368 additions and 2 deletions

View file

@ -1,8 +1,108 @@
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/card_bg_color">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/action_bar_height">
<net.osmand.telegram.ui.views.TextViewEx
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:text="@string/shared_string_settings"
android:textColor="@color/app_bar_title_light"
android:textSize="@dimen/title_text_size"
app:typeface="@string/font_roboto_mono_bold"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/list_item_divider"/>
<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="@dimen/list_header_height"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:paddingLeft="@dimen/content_padding_standard"
android:paddingRight="@dimen/content_padding_standard"
android:text="@string/gps_and_location"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/list_item_title_text_size"
app:typeface="@string/font_roboto_medium"/>
<LinearLayout
android:id="@+id/gps_and_loc_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
</LinearLayout>
<include layout="@layout/list_item_divider"/>
<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="@dimen/list_header_height"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:paddingLeft="@dimen/content_padding_standard"
android:paddingRight="@dimen/content_padding_standard"
android:text="@string/osmand_connect"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/list_item_title_text_size"
app:typeface="@string/font_roboto_medium"/>
<LinearLayout
android:id="@+id/osmand_connect_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
</LinearLayout>
<include layout="@layout/card_bottom_divider"/>
</LinearLayout>
</ScrollView>
</LinearLayout>

View file

@ -0,0 +1,59 @@
<?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:layout_marginBottom="@dimen/list_item_bottom_margin"
android:background="?attr/selectableItemBackground"
android:paddingLeft="@dimen/content_padding_standard"
android:paddingRight="@dimen/content_padding_standard"
tools:background="@color/card_bg_light">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/content_padding_big"
android:layout_marginRight="@dimen/content_padding_big"
tools:src="@drawable/ic_action_live_now"
tools:tint="@color/icon_light"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/content_padding_standard"
android:layout_marginRight="@dimen/content_padding_standard"
android:layout_weight="1"
android:orientation="vertical">
<net.osmand.telegram.ui.views.TextViewEx
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/title_text_size"
app:typeface="@string/font_roboto_regular"
tools:text="Some title"/>
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/descr_text_size"
tools:text="Some long description"/>
</LinearLayout>
<net.osmand.telegram.ui.views.TextViewEx
android:id="@+id/value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="?attr/ctrl_active_color"
app:typeface="@string/font_roboto_medium"
tools:text="Value"/>
</LinearLayout>

View file

@ -0,0 +1,46 @@
<?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:layout_marginBottom="@dimen/list_item_bottom_margin"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:paddingLeft="@dimen/content_padding_standard"
android:paddingRight="@dimen/content_padding_standard"
tools:background="@color/card_bg_light">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/content_padding_big"
android:layout_marginRight="@dimen/content_padding_big"
tools:src="@drawable/ic_action_live_now"
tools:tint="@color/icon_light"/>
<net.osmand.telegram.ui.views.TextViewEx
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/content_padding_standard"
android:layout_marginRight="@dimen/content_padding_standard"
android:layout_weight="1"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/title_text_size"
app:typeface="@string/font_roboto_regular"
tools:text="Some title"/>
<RadioButton
android:id="@+id/radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<include
layout="@layout/primary_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

View file

@ -23,6 +23,8 @@
<dimen name="dialog_welcome_title_bottom_padding">70dp</dimen>
<dimen name="dialog_welcome_title_top_margin">85dp</dimen>
<dimen name="list_header_height">48dp</dimen>
<dimen name="list_item_height">56dp</dimen>
<dimen name="list_item_height_min">48dp</dimen>

View file

@ -1,4 +1,12 @@
<resources>
<string name="osmand_connect">OsmAnd connect</string>
<string name="location_history_desc">Hide contacts that are not updated their location after the specified period of time.</string>
<string name="location_history">Location history</string>
<string name="stale_location_desc">Time when contact last time sent an update to its location.</string>
<string name="stale_location">Stale location</string>
<string name="send_my_location_desc">Set minimum interval for location sharing.</string>
<string name="send_my_location">Send my location</string>
<string name="gps_and_location">GPS &amp; location</string>
<string name="open_osmand">Open OsmAnd</string>
<string name="shared_string_live">Live</string>
<string name="shared_string_bot">Bot</string>

View file

@ -1,15 +1,37 @@
package net.osmand.telegram.ui
import android.os.Bundle
import android.support.annotation.DrawableRes
import android.support.annotation.StringRes
import android.support.v4.app.DialogFragment
import android.support.v4.app.FragmentManager
import android.support.v7.widget.ListPopupWindow
import android.support.v7.widget.Toolbar
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import net.osmand.telegram.R
import net.osmand.telegram.TelegramApplication
import net.osmand.telegram.helpers.OsmandAidlHelper
import net.osmand.telegram.utils.AndroidUtils
import net.osmand.telegram.utils.OsmandFormatter
class SettingsDialogFragment : DialogFragment() {
private val app: TelegramApplication
get() = activity?.application as TelegramApplication
private val uiUtils get() = app.uiUtils
private val telegramHelper get() = app.telegramHelper
private val settings get() = app.settings
private val gpsAndLocPrefs = listOf(SendMyLocPref(), StaleLocPref(), LocHistoryPref())
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(android.support.v4.app.DialogFragment.STYLE_NO_FRAME, R.style.AppTheme_NoActionbar)
@ -17,10 +39,139 @@ class SettingsDialogFragment : DialogFragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
parent: ViewGroup?,
savedInstanceState: Bundle?
): View {
return inflater.inflate(R.layout.fragement_settings_dialog, container)
val mainView = inflater.inflate(R.layout.fragement_settings_dialog, parent)
mainView.findViewById<Toolbar>(R.id.toolbar).apply {
navigationIcon = uiUtils.getThemedIcon(R.drawable.ic_arrow_back)
setNavigationOnClickListener { dismiss() }
}
var container = mainView.findViewById<ViewGroup>(R.id.gps_and_loc_container)
for (pref in gpsAndLocPrefs) {
inflater.inflate(R.layout.item_with_desc_and_right_value, container, false).apply {
findViewById<ImageView>(R.id.icon).setImageDrawable(uiUtils.getThemedIcon(pref.iconId))
findViewById<TextView>(R.id.title).setText(pref.titleId)
findViewById<TextView>(R.id.description).setText(pref.descriptionId)
val valueView = findViewById<TextView>(R.id.value)
valueView.text = pref.getCurrentValue()
setOnClickListener {
showPopupMenu(pref, valueView)
}
container.addView(this)
}
}
container = mainView.findViewById(R.id.osmand_connect_container)
for (appConn in AppConnect.values()) {
inflater.inflate(R.layout.item_with_rb_and_btn, container, false).apply {
findViewById<ImageView>(R.id.icon).setImageDrawable(uiUtils.getThemedIcon(appConn.iconId))
findViewById<TextView>(R.id.title).text = appConn.title
// FIXME
container.addView(this)
}
}
return mainView
}
private fun showPopupMenu(pref: DurationPref, valueView: TextView) {
val menuList = pref.getMenuItems()
val ctx = valueView.context
ListPopupWindow(ctx).apply {
isModal = true
anchorView = valueView
setContentWidth(AndroidUtils.getPopupMenuWidth(ctx, menuList))
setDropDownGravity(Gravity.END or Gravity.TOP)
setAdapter(ArrayAdapter(ctx, R.layout.popup_list_text_item, menuList))
setOnItemClickListener { _, _, position, _ ->
pref.setCurrentValue(position)
valueView.text = pref.getCurrentValue()
dismiss()
}
show()
}
}
// FIXME
private inner class SendMyLocPref : DurationPref(
R.drawable.ic_action_share_location,
R.string.send_my_location,
R.string.send_my_location_desc,
listOf(30 * 60, 60 * 60, 90 * 60)
) {
override fun getCurrentValue() = OsmandFormatter.getFormattedDuration(app, values[0])
override fun setCurrentValue(index: Int) {
val value = OsmandFormatter.getFormattedDuration(app, values[index])
Toast.makeText(context, value, Toast.LENGTH_SHORT).show()
}
}
// FIXME
private inner class StaleLocPref : DurationPref(
R.drawable.ic_action_share_location,
R.string.stale_location,
R.string.stale_location_desc,
listOf(30 * 60, 60 * 60, 90 * 60)
) {
override fun getCurrentValue() = OsmandFormatter.getFormattedDuration(app, values[0])
override fun setCurrentValue(index: Int) {
val value = OsmandFormatter.getFormattedDuration(app, values[index])
Toast.makeText(context, value, Toast.LENGTH_SHORT).show()
}
}
// FIXME
private inner class LocHistoryPref : DurationPref(
R.drawable.ic_action_time_span,
R.string.location_history,
R.string.location_history_desc,
listOf(30 * 60, 60 * 60, 90 * 60)
) {
override fun getCurrentValue() = OsmandFormatter.getFormattedDuration(app, values[0])
override fun setCurrentValue(index: Int) {
val value = OsmandFormatter.getFormattedDuration(app, values[index])
Toast.makeText(context, value, Toast.LENGTH_SHORT).show()
}
}
private abstract inner class DurationPref(
@DrawableRes val iconId: Int,
@StringRes val titleId: Int,
@StringRes val descriptionId: Int,
val values: List<Int>
) {
abstract fun getCurrentValue(): String
abstract fun setCurrentValue(index: Int)
fun getMenuItems() = values.map { OsmandFormatter.getFormattedDuration(app, it) }
}
private enum class AppConnect(
@DrawableRes val iconId: Int,
val title: String,
val appPackage: String
) {
OSMAND_PLUS(
R.drawable.ic_action_osmand_plus,
"OsmAnd+",
OsmandAidlHelper.OSMAND_PLUS_PACKAGE_NAME
),
OSMAND_FREE(
R.drawable.ic_action_osmand_free,
"OsmAnd",
OsmandAidlHelper.OSMAND_FREE_PACKAGE_NAME
)
}
companion object {