Remove unnecessary variable
This commit is contained in:
parent
6f1974ea60
commit
33a287ca9f
3 changed files with 63 additions and 63 deletions
|
@ -29,6 +29,8 @@ import net.osmand.telegram.helpers.TelegramUiHelper.ChatItem
|
||||||
import net.osmand.telegram.helpers.TelegramUiHelper.ListItem
|
import net.osmand.telegram.helpers.TelegramUiHelper.ListItem
|
||||||
import net.osmand.telegram.helpers.TelegramUiHelper.LocationItem
|
import net.osmand.telegram.helpers.TelegramUiHelper.LocationItem
|
||||||
import net.osmand.telegram.ui.LiveNowTabFragment.LiveNowListAdapter.BaseViewHolder
|
import net.osmand.telegram.ui.LiveNowTabFragment.LiveNowListAdapter.BaseViewHolder
|
||||||
|
import net.osmand.telegram.ui.SortByBottomSheet.Companion.CURRENT_SORT_TYPE_KEY
|
||||||
|
import net.osmand.telegram.ui.SortByBottomSheet.Companion.SORT_BY_KEY
|
||||||
import net.osmand.telegram.ui.SortByBottomSheet.SortType.*
|
import net.osmand.telegram.ui.SortByBottomSheet.SortType.*
|
||||||
import net.osmand.telegram.utils.AndroidUtils
|
import net.osmand.telegram.utils.AndroidUtils
|
||||||
import net.osmand.telegram.utils.OsmandFormatter
|
import net.osmand.telegram.utils.OsmandFormatter
|
||||||
|
@ -60,7 +62,6 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
private var locationUiUpdateAllowed: Boolean = true
|
private var locationUiUpdateAllowed: Boolean = true
|
||||||
|
|
||||||
private var sortBy = SORT_BY_GROUP
|
private var sortBy = SORT_BY_GROUP
|
||||||
private var sortByGroup = sortBy == SORT_BY_GROUP
|
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
|
@ -69,7 +70,6 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
): View? {
|
): View? {
|
||||||
savedInstanceState?.getString(CURRENT_SORT_TYPE_KEY)?.also {
|
savedInstanceState?.getString(CURRENT_SORT_TYPE_KEY)?.also {
|
||||||
sortBy = valueOf(it)
|
sortBy = valueOf(it)
|
||||||
sortByGroup = sortBy == SORT_BY_GROUP
|
|
||||||
}
|
}
|
||||||
val mainView = inflater.inflate(R.layout.fragment_live_now_tab, container, false)
|
val mainView = inflater.inflate(R.layout.fragment_live_now_tab, container, false)
|
||||||
val appBarLayout = mainView.findViewById<View>(R.id.app_bar_layout)
|
val appBarLayout = mainView.findViewById<View>(R.id.app_bar_layout)
|
||||||
|
@ -144,7 +144,6 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
val newSortBy = data.extras.getString(SORT_BY_KEY, "")
|
val newSortBy = data.extras.getString(SORT_BY_KEY, "")
|
||||||
if (!newSortBy.isNullOrEmpty()) {
|
if (!newSortBy.isNullOrEmpty()) {
|
||||||
sortBy = valueOf(newSortBy)
|
sortBy = valueOf(newSortBy)
|
||||||
sortByGroup = sortBy == SORT_BY_GROUP
|
|
||||||
updateSortBtn()
|
updateSortBtn()
|
||||||
updateList()
|
updateList()
|
||||||
}
|
}
|
||||||
|
@ -287,19 +286,17 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
val res = mutableListOf<ListItem>()
|
val res = mutableListOf<ListItem>()
|
||||||
for ((id, messages) in telegramHelper.getMessagesByChatIds(settings.locHistoryTime)) {
|
for ((id, messages) in telegramHelper.getMessagesByChatIds(settings.locHistoryTime)) {
|
||||||
telegramHelper.getChat(id)?.also { chat ->
|
telegramHelper.getChat(id)?.also { chat ->
|
||||||
if (sortByGroup) {
|
if (sortBy.isSortByGroup()) {
|
||||||
res.add(TelegramUiHelper.chatToChatItem(telegramHelper, chat, messages))
|
res.add(TelegramUiHelper.chatToChatItem(telegramHelper, chat, messages))
|
||||||
}
|
}
|
||||||
val type = chat.type
|
val type = chat.type
|
||||||
if (type is TdApi.ChatTypeBasicGroup || type is TdApi.ChatTypeSupergroup) {
|
if (type is TdApi.ChatTypeBasicGroup || type is TdApi.ChatTypeSupergroup) {
|
||||||
res.addAll(convertToListItems(chat, messages))
|
res.addAll(convertToListItems(chat, messages))
|
||||||
} else if (type is TdApi.ChatTypePrivate) {
|
} else if (type is TdApi.ChatTypePrivate) {
|
||||||
if (telegramHelper.isOsmAndBot(type.userId)) {
|
when {
|
||||||
res.addAll(convertToListItems(chat, messages))
|
telegramHelper.isOsmAndBot(type.userId) -> res.addAll(convertToListItems(chat, messages))
|
||||||
} else if (messages.firstOrNull { it.viaBotUserId != 0 } != null) {
|
messages.firstOrNull { it.viaBotUserId != 0 } != null -> res.addAll(convertToListItems(chat, messages, true))
|
||||||
res.addAll(convertToListItems(chat, messages, true))
|
!sortBy.isSortByGroup() -> res.add(TelegramUiHelper.chatToChatItem(telegramHelper, chat, messages))
|
||||||
} else if(!sortByGroup){
|
|
||||||
res.add(TelegramUiHelper.chatToChatItem(telegramHelper, chat, messages))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,7 +328,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
messages: List<TdApi.Message>,
|
messages: List<TdApi.Message>,
|
||||||
addOnlyViaBotMessages: Boolean = false
|
addOnlyViaBotMessages: Boolean = false
|
||||||
): List<ListItem> {
|
): List<ListItem> {
|
||||||
return if (sortByGroup) {
|
return if (sortBy.isSortByGroup()) {
|
||||||
convertToLocationItems(chat, messages, addOnlyViaBotMessages)
|
convertToLocationItems(chat, messages, addOnlyViaBotMessages)
|
||||||
} else {
|
} else {
|
||||||
convertToChatItems(chat, messages, addOnlyViaBotMessages)
|
convertToChatItems(chat, messages, addOnlyViaBotMessages)
|
||||||
|
@ -399,15 +396,15 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
when (sortBy) {
|
when (sortBy) {
|
||||||
SortByBottomSheet.SortType.SORT_BY_NAME -> {
|
SortByBottomSheet.SortType.SORT_BY_NAME -> {
|
||||||
text = getString(R.string.by_name)
|
text = getString(R.string.by_name)
|
||||||
icon = app.uiUtils.getIcon(R.drawable.ic_action_sort_by_name, R.color.ctrl_active_light)
|
icon = app.uiUtils.getActiveIcon(sortBy.iconId)
|
||||||
}
|
}
|
||||||
SortByBottomSheet.SortType.SORT_BY_DISTANCE -> {
|
SortByBottomSheet.SortType.SORT_BY_DISTANCE -> {
|
||||||
text = getString(R.string.by_distance)
|
text = getString(R.string.by_distance)
|
||||||
icon = app.uiUtils.getIcon(R.drawable.ic_action_sort_by_distance, R.color.ctrl_active_light)
|
icon = app.uiUtils.getActiveIcon(sortBy.iconId)
|
||||||
}
|
}
|
||||||
SortByBottomSheet.SortType.SORT_BY_GROUP -> {
|
SortByBottomSheet.SortType.SORT_BY_GROUP -> {
|
||||||
text = getString(R.string.by_group)
|
text = getString(R.string.by_group)
|
||||||
icon = app.uiUtils.getIcon(R.drawable.ic_action_sort_by_group, R.color.ctrl_active_light)
|
icon = app.uiUtils.getActiveIcon(sortBy.iconId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sortByBtn.text = text
|
sortByBtn.text = text
|
||||||
|
@ -459,7 +456,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
TelegramUiHelper.setupPhoto(app, holder.icon, item.photoPath, R.drawable.img_user_picture_active, false)
|
TelegramUiHelper.setupPhoto(app, holder.icon, item.photoPath, R.drawable.img_user_picture_active, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.title?.text = if (sortByGroup) item.getVisibleName() else item.name
|
holder.title?.text = if (sortBy.isSortByGroup()) item.getVisibleName() else item.name
|
||||||
openOnMapView?.isEnabled = canBeOpenedOnMap
|
openOnMapView?.isEnabled = canBeOpenedOnMap
|
||||||
if (canBeOpenedOnMap) {
|
if (canBeOpenedOnMap) {
|
||||||
openOnMapView?.setOnClickListener {
|
openOnMapView?.setOnClickListener {
|
||||||
|
@ -487,10 +484,10 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
holder.bottomShadow?.visibility = if (lastItem) View.VISIBLE else View.GONE
|
holder.bottomShadow?.visibility = if (lastItem) View.VISIBLE else View.GONE
|
||||||
|
|
||||||
if (item is ChatItem && holder is ChatViewHolder) {
|
if (item is ChatItem && holder is ChatViewHolder) {
|
||||||
val nextIsLocation = !lastItem && (items[position + 1] is LocationItem || !sortByGroup)
|
val nextIsLocation = !lastItem && (items[position + 1] is LocationItem || !sortBy.isSortByGroup())
|
||||||
val chatId = item.chatId
|
val chatId = item.chatId
|
||||||
val stateTextInd = if (settings.isShowingChatOnMap(chatId)) 1 else 0
|
val stateTextInd = if (settings.isShowingChatOnMap(chatId)) 1 else 0
|
||||||
val groupDescrRowVisible = !sortByGroup && (!item.privateChat || item.chatWithBot)
|
val groupDescrRowVisible = !sortBy.isSortByGroup() && (!item.privateChat || item.chatWithBot)
|
||||||
|
|
||||||
if (groupDescrRowVisible) {
|
if (groupDescrRowVisible) {
|
||||||
holder.groupDescrContainer?.visibility = View.VISIBLE
|
holder.groupDescrContainer?.visibility = View.VISIBLE
|
||||||
|
@ -505,7 +502,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
holder.showOnMapRow?.setOnClickListener { showPopupMenu(holder, chatId) }
|
holder.showOnMapRow?.setOnClickListener { showPopupMenu(holder, chatId) }
|
||||||
holder.showOnMapState?.text = menuList[stateTextInd]
|
holder.showOnMapState?.text = menuList[stateTextInd]
|
||||||
holder.bottomDivider?.visibility = if (nextIsLocation) View.VISIBLE else View.GONE
|
holder.bottomDivider?.visibility = if (nextIsLocation) View.VISIBLE else View.GONE
|
||||||
holder.topDivider?.visibility = if (!sortByGroup && position != 0) View.GONE else View.VISIBLE
|
holder.topDivider?.visibility = if (!sortBy.isSortByGroup() && position != 0) View.GONE else View.VISIBLE
|
||||||
} else if (item is LocationItem && holder is ContactViewHolder) {
|
} else if (item is LocationItem && holder is ContactViewHolder) {
|
||||||
holder.description?.text = OsmandFormatter.getListItemLiveTimeDescr(app, item.lastUpdated, lastResponseStr)
|
holder.description?.text = OsmandFormatter.getListItemLiveTimeDescr(app, item.lastUpdated, lastResponseStr)
|
||||||
}
|
}
|
||||||
|
@ -516,9 +513,9 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
private fun getChatItemDescription(item: ChatItem): String {
|
private fun getChatItemDescription(item: ChatItem): String {
|
||||||
return when {
|
return when {
|
||||||
item.chatWithBot -> getString(R.string.shared_string_bot)
|
item.chatWithBot -> getString(R.string.shared_string_bot)
|
||||||
item.privateChat -> { OsmandFormatter.getListItemLiveTimeDescr(app, item.lastUpdated, lastResponseStr) }
|
item.privateChat -> OsmandFormatter.getListItemLiveTimeDescr(app, item.lastUpdated, lastResponseStr)
|
||||||
else -> {
|
else -> {
|
||||||
if (sortByGroup) {
|
if (sortBy.isSortByGroup()) {
|
||||||
val live = getString(R.string.shared_string_live)
|
val live = getString(R.string.shared_string_live)
|
||||||
val all = getString(R.string.shared_string_all)
|
val all = getString(R.string.shared_string_all)
|
||||||
val liveStr = "$live ${item.liveMembersCount}"
|
val liveStr = "$live ${item.liveMembersCount}"
|
||||||
|
|
|
@ -19,10 +19,6 @@ import net.osmand.telegram.TelegramApplication
|
||||||
import net.osmand.telegram.ui.views.BottomSheetDialog
|
import net.osmand.telegram.ui.views.BottomSheetDialog
|
||||||
|
|
||||||
|
|
||||||
const val SORT_BY_KEY = "sort_by_key"
|
|
||||||
|
|
||||||
const val CURRENT_SORT_TYPE_KEY = "current_sort_type_key"
|
|
||||||
|
|
||||||
class SortByBottomSheet : DialogFragment() {
|
class SortByBottomSheet : DialogFragment() {
|
||||||
|
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?) = BottomSheetDialog(context!!)
|
override fun onCreateDialog(savedInstanceState: Bundle?) = BottomSheetDialog(context!!)
|
||||||
|
@ -32,42 +28,11 @@ class SortByBottomSheet : DialogFragment() {
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View? {
|
): View? {
|
||||||
val mainView = inflater.inflate(R.layout.bottom_sheet_sort_by, container, false)
|
|
||||||
val intent = Intent()
|
|
||||||
val app = activity?.application as TelegramApplication
|
val app = activity?.application as TelegramApplication
|
||||||
val currentSortType = arguments?.getString(CURRENT_SORT_TYPE_KEY)
|
val currentSortType = arguments?.getString(CURRENT_SORT_TYPE_KEY)
|
||||||
val itemsCont = mainView.findViewById<ViewGroup>(R.id.items_container)
|
val mainView = inflater.inflate(R.layout.bottom_sheet_sort_by, container, false)
|
||||||
|
|
||||||
for (sortType in SortType.values()) {
|
mainView.findViewById<View>(R.id.scroll_view_container).setOnClickListener { dismiss() }
|
||||||
inflater.inflate(R.layout.item_with_rb_and_btn, itemsCont, false).apply {
|
|
||||||
val isCurrentSortType = sortType.name == currentSortType
|
|
||||||
val image = if (isCurrentSortType) {
|
|
||||||
app.uiUtils.getActiveIcon(sortType.iconId)
|
|
||||||
} else {
|
|
||||||
app.uiUtils.getThemedIcon(sortType.iconId)
|
|
||||||
}
|
|
||||||
findViewById<ImageView>(R.id.icon).setImageDrawable(image)
|
|
||||||
findViewById<TextView>(R.id.title)?.apply {
|
|
||||||
text = getText(sortType.titleId)
|
|
||||||
setTextColor(
|
|
||||||
ContextCompat.getColor(
|
|
||||||
app,
|
|
||||||
if (isCurrentSortType) R.color.ctrl_active_light else R.color.primary_text_light
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
findViewById<View>(R.id.primary_btn_container).visibility = View.GONE
|
|
||||||
findViewById<View>(R.id.radio_button).visibility = View.GONE
|
|
||||||
setOnClickListener {
|
|
||||||
intent.putExtra(SORT_BY_KEY, sortType.name)
|
|
||||||
targetFragment?.also { target ->
|
|
||||||
target.onActivityResult(targetRequestCode, SORT_BY_REQUEST_CODE, intent)
|
|
||||||
}
|
|
||||||
dismiss()
|
|
||||||
}
|
|
||||||
itemsCont.addView(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BottomSheetBehavior.from(mainView.findViewById<View>(R.id.scroll_view))
|
BottomSheetBehavior.from(mainView.findViewById<View>(R.id.scroll_view))
|
||||||
.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
|
.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
|
||||||
|
@ -81,6 +46,39 @@ class SortByBottomSheet : DialogFragment() {
|
||||||
override fun onSlide(bottomSheet: View, slideOffset: Float) {}
|
override fun onSlide(bottomSheet: View, slideOffset: Float) {}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
val itemsCont = mainView.findViewById<ViewGroup>(R.id.items_container)
|
||||||
|
for (sortType in SortType.values()) {
|
||||||
|
inflater.inflate(R.layout.item_with_rb_and_btn, itemsCont, false).apply {
|
||||||
|
val currentType = sortType.name == currentSortType
|
||||||
|
val image = if (currentType) {
|
||||||
|
app.uiUtils.getActiveIcon(sortType.iconId)
|
||||||
|
} else {
|
||||||
|
app.uiUtils.getThemedIcon(sortType.iconId)
|
||||||
|
}
|
||||||
|
findViewById<ImageView>(R.id.icon).setImageDrawable(image)
|
||||||
|
findViewById<TextView>(R.id.title)?.apply {
|
||||||
|
text = getText(sortType.titleId)
|
||||||
|
val color = ContextCompat.getColor(
|
||||||
|
app,
|
||||||
|
if (currentType) R.color.ctrl_active_light else R.color.primary_text_light
|
||||||
|
)
|
||||||
|
setTextColor(color)
|
||||||
|
}
|
||||||
|
findViewById<View>(R.id.primary_btn_container).visibility = View.GONE
|
||||||
|
findViewById<View>(R.id.radio_button).visibility = View.GONE
|
||||||
|
setOnClickListener {
|
||||||
|
val intent = Intent()
|
||||||
|
intent.putExtra(SORT_BY_KEY, sortType.name)
|
||||||
|
targetFragment?.also { target ->
|
||||||
|
target.onActivityResult(targetRequestCode, SORT_BY_REQUEST_CODE, intent)
|
||||||
|
}
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
itemsCont.addView(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mainView.findViewById<TextView>(R.id.secondary_btn).apply {
|
mainView.findViewById<TextView>(R.id.secondary_btn).apply {
|
||||||
setText(R.string.shared_string_cancel)
|
setText(R.string.shared_string_cancel)
|
||||||
setOnClickListener { dismiss() }
|
setOnClickListener { dismiss() }
|
||||||
|
@ -93,6 +91,9 @@ class SortByBottomSheet : DialogFragment() {
|
||||||
|
|
||||||
const val SORT_BY_REQUEST_CODE = 3
|
const val SORT_BY_REQUEST_CODE = 3
|
||||||
|
|
||||||
|
const val SORT_BY_KEY = "sort_by_key"
|
||||||
|
const val CURRENT_SORT_TYPE_KEY = "current_sort_type_key"
|
||||||
|
|
||||||
private const val TAG = "SortByBottomSheet"
|
private const val TAG = "SortByBottomSheet"
|
||||||
|
|
||||||
fun showInstance(
|
fun showInstance(
|
||||||
|
@ -119,5 +120,7 @@ class SortByBottomSheet : DialogFragment() {
|
||||||
SORT_BY_GROUP(R.drawable.ic_action_sort_by_group, R.string.shared_string_group),
|
SORT_BY_GROUP(R.drawable.ic_action_sort_by_group, R.string.shared_string_group),
|
||||||
SORT_BY_NAME(R.drawable.ic_action_sort_by_name, R.string.shared_string_name),
|
SORT_BY_NAME(R.drawable.ic_action_sort_by_name, R.string.shared_string_name),
|
||||||
SORT_BY_DISTANCE(R.drawable.ic_action_sort_by_distance, R.string.shared_string_distance);
|
SORT_BY_DISTANCE(R.drawable.ic_action_sort_by_distance, R.string.shared_string_distance);
|
||||||
|
|
||||||
|
fun isSortByGroup() = this == SORT_BY_GROUP
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue