Fix group icon and add colorStateList
This commit is contained in:
parent
ba473df31f
commit
b355b56c6c
5 changed files with 113 additions and 25 deletions
|
@ -32,7 +32,7 @@
|
|||
android:paddingLeft="@dimen/content_padding_standard"
|
||||
android:paddingRight="@dimen/content_padding_standard"
|
||||
android:text="@string/shared_string_sort_by"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:textSize="@dimen/list_item_title_text_size"
|
||||
app:firstBaselineToTopHeight="28sp"
|
||||
app:typeface="@string/font_roboto_medium" />
|
||||
|
|
|
@ -196,7 +196,12 @@ object TelegramUiHelper {
|
|||
chatTitle = chat.title
|
||||
name = TelegramUiHelper.getUserName(user)
|
||||
latLon = LatLon(content.location.latitude, content.location.longitude)
|
||||
photoPath = chat.photo?.small?.local?.path
|
||||
if (helper.isGroup(chat)) {
|
||||
photoPath = helper.getUserPhotoPath(user)
|
||||
groupPhotoPath = chat.photo?.small?.local?.path
|
||||
} else {
|
||||
photoPath = chat.photo?.small?.local?.path
|
||||
}
|
||||
grayscalePhotoPath = helper.getUserGreyPhotoPath(user)
|
||||
placeholderId = R.drawable.img_user_picture
|
||||
userId = message.senderUserId
|
||||
|
@ -236,6 +241,8 @@ object TelegramUiHelper {
|
|||
|
||||
class ChatItem : ListItem() {
|
||||
|
||||
var groupPhotoPath: String? = null
|
||||
internal set
|
||||
var privateChat: Boolean = false
|
||||
internal set
|
||||
var chatWithBot: Boolean = false
|
||||
|
|
|
@ -38,6 +38,8 @@ import org.drinkless.td.libcore.telegram.TdApi
|
|||
private const val CHAT_VIEW_TYPE = 0
|
||||
private const val LOCATION_ITEM_VIEW_TYPE = 1
|
||||
|
||||
private const val SORT_TYPE = "sort_type"
|
||||
|
||||
class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessagesListener,
|
||||
FullInfoUpdatesListener, TelegramLocationListener, TelegramCompassListener {
|
||||
|
||||
|
@ -66,6 +68,10 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
savedInstanceState?.getInt(SORT_TYPE)?.also {
|
||||
sortBy = it
|
||||
sortByGroup = sortBy == SORT_BY_GROUP
|
||||
}
|
||||
val mainView = inflater.inflate(R.layout.fragment_live_now_tab, container, false)
|
||||
val appBarLayout = mainView.findViewById<View>(R.id.app_bar_layout)
|
||||
AndroidUtils.addStatusBarPadding19v(context!!, appBarLayout)
|
||||
|
@ -148,6 +154,11 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
}
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putInt(SORT_TYPE, sortBy)
|
||||
}
|
||||
|
||||
override fun onTelegramStatusChanged(
|
||||
prevTelegramAuthorizationState: TelegramAuthorizationState,
|
||||
newTelegramAuthorizationState: TelegramAuthorizationState
|
||||
|
@ -288,6 +299,8 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
res.addAll(convertToListItems(chat, messages))
|
||||
} else if (messages.firstOrNull { it.viaBotUserId != 0 } != null) {
|
||||
res.addAll(convertToListItems(chat, messages, true))
|
||||
} else if(!sortByGroup){
|
||||
res.add(TelegramUiHelper.chatToChatItem(telegramHelper, chat, messages))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -441,7 +454,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
val openOnMapView = holder.getOpenOnMapClickView()
|
||||
|
||||
val staleLocation = System.currentTimeMillis() / 1000 - item.lastUpdated > settings.staleLocTime
|
||||
if (staleLocation) {
|
||||
if (staleLocation && item.userId != 0) {
|
||||
TelegramUiHelper.setupPhoto(app, holder.icon, item.grayscalePhotoPath, item.placeholderId, false)
|
||||
} else {
|
||||
TelegramUiHelper.setupPhoto(app, holder.icon, item.photoPath, R.drawable.img_user_picture_active, false)
|
||||
|
@ -483,7 +496,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
if (groupDescrRowVisible) {
|
||||
holder.groupDescrContainer?.visibility = View.VISIBLE
|
||||
holder.groupTitle?.text = item.getVisibleName()
|
||||
TelegramUiHelper.setupPhoto(app, holder.groupImage, item.photoPath, item.placeholderId, false)
|
||||
TelegramUiHelper.setupPhoto(app, holder.groupImage, item.groupPhotoPath, item.placeholderId, false)
|
||||
} else {
|
||||
holder.groupDescrContainer?.visibility = View.GONE
|
||||
}
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
package net.osmand.telegram.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.support.annotation.DrawableRes
|
||||
import android.support.design.widget.BottomSheetBehavior
|
||||
import android.support.v4.app.DialogFragment
|
||||
import android.support.v4.app.Fragment
|
||||
|
@ -14,6 +19,7 @@ import android.widget.TextView
|
|||
import net.osmand.telegram.R
|
||||
import net.osmand.telegram.TelegramApplication
|
||||
import net.osmand.telegram.ui.views.BottomSheetDialog
|
||||
import net.osmand.telegram.utils.AndroidUtils
|
||||
|
||||
|
||||
const val SORT_BY_GROUP = 0
|
||||
|
@ -37,13 +43,11 @@ class SortByBottomSheet : DialogFragment() {
|
|||
val itemsCont = mainView.findViewById<ViewGroup>(R.id.items_container)
|
||||
|
||||
inflater.inflate(R.layout.item_with_rb_and_btn, itemsCont, false).apply {
|
||||
findViewById<ImageView>(R.id.icon).setImageDrawable(
|
||||
app.uiUtils.getIcon(
|
||||
R.drawable.ic_action_sort_by_distance,
|
||||
R.color.ctrl_active_light
|
||||
)
|
||||
)
|
||||
findViewById<TextView>(R.id.title).text = getText(R.string.shared_string_distance)
|
||||
findViewById<ImageView>(R.id.icon).setImageDrawable(getSelectedIcon(app, R.drawable.ic_action_sort_by_distance))
|
||||
findViewById<TextView>(R.id.title).apply {
|
||||
text = getText(R.string.shared_string_distance)
|
||||
setTextColor(getTextColorStateList(context))
|
||||
}
|
||||
findViewById<View>(R.id.primary_btn_container).visibility = View.GONE
|
||||
findViewById<View>(R.id.radio_button).visibility = View.GONE
|
||||
setOnClickListener {
|
||||
|
@ -57,13 +61,11 @@ class SortByBottomSheet : DialogFragment() {
|
|||
}
|
||||
|
||||
inflater.inflate(R.layout.item_with_rb_and_btn, itemsCont, false).apply {
|
||||
findViewById<ImageView>(R.id.icon).setImageDrawable(
|
||||
app.uiUtils.getIcon(
|
||||
R.drawable.ic_action_sort_by_name,
|
||||
R.color.ctrl_active_light
|
||||
)
|
||||
)
|
||||
findViewById<TextView>(R.id.title).text = getText(R.string.shared_string_name)
|
||||
findViewById<ImageView>(R.id.icon).setImageDrawable(getSelectedIcon(app, R.drawable.ic_action_sort_by_name))
|
||||
findViewById<TextView>(R.id.title).apply {
|
||||
text = getText(R.string.shared_string_name)
|
||||
setTextColor(getTextColorStateList(context))
|
||||
}
|
||||
findViewById<View>(R.id.primary_btn_container).visibility = View.GONE
|
||||
findViewById<View>(R.id.radio_button).visibility = View.GONE
|
||||
setOnClickListener {
|
||||
|
@ -77,13 +79,11 @@ class SortByBottomSheet : DialogFragment() {
|
|||
}
|
||||
|
||||
inflater.inflate(R.layout.item_with_rb_and_btn, itemsCont, false).apply {
|
||||
findViewById<ImageView>(R.id.icon).setImageDrawable(
|
||||
app.uiUtils.getIcon(
|
||||
R.drawable.ic_action_sort_by_group,
|
||||
R.color.ctrl_active_light
|
||||
)
|
||||
)
|
||||
findViewById<TextView>(R.id.title).text = getText(R.string.shared_string_group)
|
||||
findViewById<ImageView>(R.id.icon).setImageDrawable(getSelectedIcon(app, R.drawable.ic_action_sort_by_group))
|
||||
findViewById<TextView>(R.id.title).apply {
|
||||
text = getText(R.string.shared_string_group)
|
||||
setTextColor(getTextColorStateList(context))
|
||||
}
|
||||
findViewById<View>(R.id.primary_btn_container).visibility = View.GONE
|
||||
findViewById<View>(R.id.radio_button).visibility = View.GONE
|
||||
setOnClickListener {
|
||||
|
@ -116,6 +116,25 @@ class SortByBottomSheet : DialogFragment() {
|
|||
return mainView
|
||||
}
|
||||
|
||||
private fun getTextColorStateList(context: Context): ColorStateList {
|
||||
return AndroidUtils.createPressedColorStateList(
|
||||
context,
|
||||
R.color.primary_text_light,
|
||||
R.color.ctrl_active_light
|
||||
)
|
||||
}
|
||||
|
||||
private fun getSelectedIcon(app: TelegramApplication, @DrawableRes id: Int): Drawable? {
|
||||
val normal = app.uiUtils.getThemedIcon(id)
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
val active = app.uiUtils.getActiveIcon(id)
|
||||
if (normal != null && active != null) {
|
||||
return AndroidUtils.createPressedStateListDrawable(normal, active)
|
||||
}
|
||||
}
|
||||
return normal
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
const val SORT_BY_REQUEST_CODE = 3
|
||||
|
|
|
@ -6,14 +6,19 @@ import android.content.ContentResolver
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.ColorStateList
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.graphics.drawable.StateListDrawable
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.support.annotation.AttrRes
|
||||
import android.support.annotation.ColorInt
|
||||
import android.support.annotation.ColorRes
|
||||
import android.support.v4.app.ActivityCompat
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.support.v4.content.FileProvider
|
||||
import android.util.TypedValue
|
||||
import android.util.TypedValue.COMPLEX_UNIT_DIP
|
||||
|
@ -140,6 +145,50 @@ object AndroidUtils {
|
|||
)
|
||||
}
|
||||
|
||||
fun createPressedColorStateList(ctx: Context, @ColorRes normal: Int, @ColorRes pressed: Int): ColorStateList {
|
||||
return createPressedColorStateList(ctx, false, normal, pressed, 0, 0)
|
||||
}
|
||||
|
||||
fun createPressedColorStateList(
|
||||
ctx: Context, night: Boolean,
|
||||
@ColorRes lightNormal: Int, @ColorRes lightPressed: Int,
|
||||
@ColorRes darkNormal: Int, @ColorRes darkPressed: Int
|
||||
): ColorStateList {
|
||||
return createColorStateList(
|
||||
ctx, night, android.R.attr.state_pressed,
|
||||
lightNormal, lightPressed, darkNormal, darkPressed
|
||||
)
|
||||
}
|
||||
|
||||
private fun createColorStateList(
|
||||
ctx: Context, night: Boolean, state: Int,
|
||||
@ColorRes lightNormal: Int, @ColorRes lightState: Int,
|
||||
@ColorRes darkNormal: Int, @ColorRes darkState: Int
|
||||
): ColorStateList {
|
||||
return ColorStateList(
|
||||
arrayOf(intArrayOf(state), intArrayOf()),
|
||||
intArrayOf(
|
||||
ContextCompat.getColor(ctx, if (night) darkState else lightState),
|
||||
ContextCompat.getColor(ctx, if (night) darkNormal else lightNormal)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun createPressedStateListDrawable(normal: Drawable, pressed: Drawable): StateListDrawable {
|
||||
return createStateListDrawable(normal, pressed, android.R.attr.state_pressed)
|
||||
}
|
||||
|
||||
private fun createStateListDrawable(
|
||||
normal: Drawable,
|
||||
stateDrawable: Drawable,
|
||||
state: Int
|
||||
): StateListDrawable {
|
||||
val res = StateListDrawable()
|
||||
res.addState(intArrayOf(state), stateDrawable)
|
||||
res.addState(intArrayOf(), normal)
|
||||
return res
|
||||
}
|
||||
|
||||
fun isAppInstalled(ctx: Context, appPackage: String): Boolean {
|
||||
if (appPackage.isEmpty()) {
|
||||
return false
|
||||
|
|
Loading…
Reference in a new issue