SettingsDialogFragment in progress

This commit is contained in:
Alex Sytnyk 2018-08-09 22:07:47 +03:00
parent 027678f6a3
commit a2200ea826
5 changed files with 219 additions and 16 deletions

View file

@ -2,6 +2,7 @@
<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="match_parent"
android:fitsSystemWindows="true"
@ -39,7 +40,8 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="vertical"
android:paddingBottom="@dimen/list_view_bottom_padding">
<include layout="@layout/list_item_divider"/>
@ -99,6 +101,130 @@
</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/shared_string_account"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/list_item_title_text_size"
app:typeface="@string/font_roboto_medium"/>
<LinearLayout
android:id="@+id/user_row"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/user_icon"
android:layout_width="@dimen/list_item_icon_size"
android:layout_height="@dimen/list_item_icon_size"
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:layout_marginTop="@dimen/image_button_padding"
tools:src="@drawable/img_user_picture"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/content_padding_standard"
android:layout_marginRight="@dimen/content_padding_standard"
android:orientation="vertical">
<net.osmand.telegram.ui.views.TextViewEx
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/list_item_title_text_size"
app:firstBaselineToTopHeight="25sp"
app:typeface="@string/font_roboto_regular"
tools:text="Some user name"/>
<net.osmand.telegram.ui.views.TextViewEx
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:text="@string/connected_account"
android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/list_item_description_text_size"
app:firstBaselineToTopHeight="20sp"
app:lastBaselineToBottomHeight="16sp"
app:typeface="@string/font_roboto_regular"/>
</LinearLayout>
</LinearLayout>
<net.osmand.telegram.ui.views.TextViewEx
android:id="@+id/logout_btn"
android:layout_width="match_parent"
android:layout_height="@dimen/list_header_height"
android:layout_gravity="center_vertical"
android:background="?attr/selectableItemBackground"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:paddingLeft="@dimen/dialog_padding_horizontal"
android:paddingRight="@dimen/dialog_padding_horizontal"
android:text="@string/shared_string_logout"
android:textColor="?attr/ctrl_active_color"
app:typeface="@string/font_roboto_medium"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/card_divider_color"/>
<LinearLayout
android:id="@+id/help_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:paddingLeft="@dimen/content_padding_standard"
android:paddingRight="@dimen/content_padding_standard">
<ImageView
android:id="@+id/help_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:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/logout_help_desc"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/list_item_title_text_size"
app:firstBaselineToTopHeight="25sp"
app:lastBaselineToBottomHeight="16sp"
app:typeface="@string/font_roboto_regular"/>
</LinearLayout>
</LinearLayout>
<include layout="@layout/card_bottom_divider"/>
</LinearLayout>

View file

@ -5,7 +5,6 @@
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"
@ -17,6 +16,7 @@
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/content_padding_big"
android:layout_marginRight="@dimen/content_padding_big"
android:layout_marginTop="@dimen/image_button_padding"
tools:src="@drawable/ic_action_live_now"
tools:tint="@color/icon_light"/>
@ -33,16 +33,20 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/title_text_size"
android:textSize="@dimen/list_item_title_text_size"
app:firstBaselineToTopHeight="25sp"
app:typeface="@string/font_roboto_regular"
tools:text="Some title"/>
<TextView
<net.osmand.telegram.ui.views.TextViewEx
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"
android:textSize="@dimen/list_item_description_text_size"
app:firstBaselineToTopHeight="20sp"
app:lastBaselineToBottomHeight="16sp"
app:typeface="@string/font_roboto_regular"
tools:text="Some long description"/>
</LinearLayout>

View file

@ -4,7 +4,7 @@
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_height="@dimen/list_item_height"
android:layout_marginBottom="@dimen/list_item_bottom_margin"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
@ -29,14 +29,18 @@
android:layout_marginRight="@dimen/content_padding_standard"
android:layout_weight="1"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/title_text_size"
android:textSize="@dimen/list_item_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"/>
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:focusable="false"
android:saveEnabled="false"/>
<include
layout="@layout/primary_btn"

View file

@ -1,4 +1,7 @@
<resources>
<string name="logout_help_desc">How to disconnect OsmAnd Location Sharing from Telegram</string>
<string name="connected_account">Connected account</string>
<string name="shared_string_account">Account</string>
<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>

View file

@ -11,13 +11,12 @@ 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 android.widget.*
import net.osmand.telegram.R
import net.osmand.telegram.TelegramApplication
import net.osmand.telegram.helpers.OsmandAidlHelper
import net.osmand.telegram.helpers.TelegramHelper
import net.osmand.telegram.helpers.TelegramUiHelper
import net.osmand.telegram.utils.AndroidUtils
import net.osmand.telegram.utils.OsmandFormatter
@ -66,13 +65,62 @@ class SettingsDialogFragment : DialogFragment() {
container = mainView.findViewById(R.id.osmand_connect_container)
for (appConn in AppConnect.values()) {
val pack = appConn.appPackage
val installed = AndroidUtils.isAppInstalled(context!!, pack)
inflater.inflate(R.layout.item_with_rb_and_btn, container, false).apply {
findViewById<ImageView>(R.id.icon).setImageDrawable(uiUtils.getThemedIcon(appConn.iconId))
findViewById<ImageView>(R.id.icon).setImageDrawable(uiUtils.getIcon(appConn.iconId))
findViewById<TextView>(R.id.title).text = appConn.title
// FIXME
if (installed) {
findViewById<View>(R.id.primary_btn).visibility = View.GONE
findViewById<RadioButton>(R.id.radio_button).visibility = View.VISIBLE
setOnClickListener {
// FIXME
updateSelectedAppConn()
}
} else {
findViewById<RadioButton>(R.id.radio_button).visibility = View.GONE
findViewById<TextView>(R.id.primary_btn).apply {
setText(R.string.shared_string_install)
setOnClickListener {
context?.also { ctx ->
startActivity(AndroidUtils.getPlayMarketIntent(ctx, pack))
}
}
}
setOnClickListener(null)
isClickable = false
}
tag = pack
container.addView(this)
}
}
updateSelectedAppConn()
val user = telegramHelper.getCurrentUser()
if (user != null) {
TelegramUiHelper.setupPhoto(
app,
mainView.findViewById(R.id.user_icon),
telegramHelper.getUserPhotoPath(user),
R.drawable.img_user_picture,
false
)
mainView.findViewById<TextView>(R.id.username).text = TelegramUiHelper.getUserName(user)
} else {
mainView.findViewById<View>(R.id.user_row).visibility = View.GONE
}
mainView.findViewById<View>(R.id.logout_btn).setOnClickListener {
logoutTelegram()
dismiss()
}
mainView.findViewById<ImageView>(R.id.help_icon)
.setImageDrawable(uiUtils.getActiveIcon(R.drawable.ic_action_share_location))
mainView.findViewById<View>(R.id.help_row).setOnClickListener {
// FIXME
Toast.makeText(context, "Logout help", Toast.LENGTH_SHORT).show()
}
return mainView
}
@ -95,6 +143,24 @@ class SettingsDialogFragment : DialogFragment() {
}
}
private fun updateSelectedAppConn() {
view?.findViewById<ViewGroup>(R.id.osmand_connect_container)?.apply {
for (i in 0..childCount) {
getChildAt(i).apply {
// FIXME
}
}
}
}
private fun logoutTelegram(silent: Boolean = false) {
if (telegramHelper.getTelegramAuthorizationState() == TelegramHelper.TelegramAuthorizationState.READY) {
telegramHelper.logout()
} else if (!silent) {
Toast.makeText(context, R.string.not_logged_in, Toast.LENGTH_SHORT).show()
}
}
// FIXME
private inner class SendMyLocPref : DurationPref(
R.drawable.ic_action_share_location,
@ -163,12 +229,12 @@ class SettingsDialogFragment : DialogFragment() {
val appPackage: String
) {
OSMAND_PLUS(
R.drawable.ic_action_osmand_plus,
R.drawable.ic_logo_osmand_plus,
"OsmAnd+",
OsmandAidlHelper.OSMAND_PLUS_PACKAGE_NAME
),
OSMAND_FREE(
R.drawable.ic_action_osmand_free,
R.drawable.ic_logo_osmand_free,
"OsmAnd",
OsmandAidlHelper.OSMAND_FREE_PACKAGE_NAME
)