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.LocationItem
|
||||
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.utils.AndroidUtils
|
||||
import net.osmand.telegram.utils.OsmandFormatter
|
||||
|
@ -60,7 +62,6 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
private var locationUiUpdateAllowed: Boolean = true
|
||||
|
||||
private var sortBy = SORT_BY_GROUP
|
||||
private var sortByGroup = sortBy == SORT_BY_GROUP
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
|
@ -69,7 +70,6 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
): View? {
|
||||
savedInstanceState?.getString(CURRENT_SORT_TYPE_KEY)?.also {
|
||||
sortBy = valueOf(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)
|
||||
|
@ -144,7 +144,6 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
val newSortBy = data.extras.getString(SORT_BY_KEY, "")
|
||||
if (!newSortBy.isNullOrEmpty()) {
|
||||
sortBy = valueOf(newSortBy)
|
||||
sortByGroup = sortBy == SORT_BY_GROUP
|
||||
updateSortBtn()
|
||||
updateList()
|
||||
}
|
||||
|
@ -287,19 +286,17 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
val res = mutableListOf<ListItem>()
|
||||
for ((id, messages) in telegramHelper.getMessagesByChatIds(settings.locHistoryTime)) {
|
||||
telegramHelper.getChat(id)?.also { chat ->
|
||||
if (sortByGroup) {
|
||||
if (sortBy.isSortByGroup()) {
|
||||
res.add(TelegramUiHelper.chatToChatItem(telegramHelper, chat, messages))
|
||||
}
|
||||
val type = chat.type
|
||||
if (type is TdApi.ChatTypeBasicGroup || type is TdApi.ChatTypeSupergroup) {
|
||||
res.addAll(convertToListItems(chat, messages))
|
||||
} else if (type is TdApi.ChatTypePrivate) {
|
||||
if (telegramHelper.isOsmAndBot(type.userId)) {
|
||||
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))
|
||||
when {
|
||||
telegramHelper.isOsmAndBot(type.userId) -> res.addAll(convertToListItems(chat, messages))
|
||||
messages.firstOrNull { it.viaBotUserId != 0 } != null -> res.addAll(convertToListItems(chat, messages, true))
|
||||
!sortBy.isSortByGroup() -> res.add(TelegramUiHelper.chatToChatItem(telegramHelper, chat, messages))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -331,7 +328,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
messages: List<TdApi.Message>,
|
||||
addOnlyViaBotMessages: Boolean = false
|
||||
): List<ListItem> {
|
||||
return if (sortByGroup) {
|
||||
return if (sortBy.isSortByGroup()) {
|
||||
convertToLocationItems(chat, messages, addOnlyViaBotMessages)
|
||||
} else {
|
||||
convertToChatItems(chat, messages, addOnlyViaBotMessages)
|
||||
|
@ -399,15 +396,15 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
when (sortBy) {
|
||||
SortByBottomSheet.SortType.SORT_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 -> {
|
||||
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 -> {
|
||||
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
|
||||
|
@ -459,7 +456,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
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
|
||||
if (canBeOpenedOnMap) {
|
||||
openOnMapView?.setOnClickListener {
|
||||
|
@ -487,10 +484,10 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
holder.bottomShadow?.visibility = if (lastItem) View.VISIBLE else View.GONE
|
||||
|
||||
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 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) {
|
||||
holder.groupDescrContainer?.visibility = View.VISIBLE
|
||||
|
@ -505,7 +502,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
holder.showOnMapRow?.setOnClickListener { showPopupMenu(holder, chatId) }
|
||||
holder.showOnMapState?.text = menuList[stateTextInd]
|
||||
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) {
|
||||
holder.description?.text = OsmandFormatter.getListItemLiveTimeDescr(app, item.lastUpdated, lastResponseStr)
|
||||
}
|
||||
|
@ -516,9 +513,9 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
|||
private fun getChatItemDescription(item: ChatItem): String {
|
||||
return when {
|
||||
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 -> {
|
||||
if (sortByGroup) {
|
||||
if (sortBy.isSortByGroup()) {
|
||||
val live = getString(R.string.shared_string_live)
|
||||
val all = getString(R.string.shared_string_all)
|
||||
val liveStr = "$live ${item.liveMembersCount}"
|
||||
|
|
|
@ -19,10 +19,6 @@ import net.osmand.telegram.TelegramApplication
|
|||
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() {
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?) = BottomSheetDialog(context!!)
|
||||
|
@ -32,42 +28,11 @@ class SortByBottomSheet : DialogFragment() {
|
|||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
val mainView = inflater.inflate(R.layout.bottom_sheet_sort_by, container, false)
|
||||
val intent = Intent()
|
||||
val app = activity?.application as TelegramApplication
|
||||
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()) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
mainView.findViewById<View>(R.id.scroll_view_container).setOnClickListener { dismiss() }
|
||||
|
||||
BottomSheetBehavior.from(mainView.findViewById<View>(R.id.scroll_view))
|
||||
.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
|
||||
|
@ -81,6 +46,39 @@ class SortByBottomSheet : DialogFragment() {
|
|||
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 {
|
||||
setText(R.string.shared_string_cancel)
|
||||
setOnClickListener { dismiss() }
|
||||
|
@ -93,6 +91,9 @@ class SortByBottomSheet : DialogFragment() {
|
|||
|
||||
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"
|
||||
|
||||
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_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);
|
||||
|
||||
fun isSortByGroup() = this == SORT_BY_GROUP
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue