Skip to content

Commit

Permalink
Streamline bell icon badge updates
Browse files Browse the repository at this point in the history
The code is spaghetti, sigh.
  • Loading branch information
oakkitten committed Dec 7, 2024
1 parent d75e02d commit a5ae9be
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ class WeechatActivity : AppCompatActivity(), CutePageChangeListener,
Network.get().register(this, null) // no callback, simply make sure that network info is correct while we are showing
EventBus.getDefault().register(this)
connectionState = EventBus.getDefault().getStickyEvent(StateChangedEvent::class.java).state
updateHotCount(BufferList.totalHotMessageCount)
started = true
P.storeThemeOrColorSchemeColors(this)
applyColorSchemeToViews()
Expand Down Expand Up @@ -497,6 +496,7 @@ class WeechatActivity : AppCompatActivity(), CutePageChangeListener,
uiMenu = menu
updateMenuItems()
makeMenuReflectConnectionStatus()
// `onCreateOptionsMenu` is called *after* onStart, when `updateHotCount` was already called
updateHotCount(hotNumber)
return super.onCreateOptionsMenu(menu)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import com.ubergeek42.WeechatAndroid.adapters.BufferListAdapter
import com.ubergeek42.WeechatAndroid.databinding.BufferlistBinding
import com.ubergeek42.WeechatAndroid.relay.BufferList
import com.ubergeek42.WeechatAndroid.relay.BufferListEye
import com.ubergeek42.WeechatAndroid.service.Events.StateChangedEvent
import com.ubergeek42.WeechatAndroid.service.P
import com.ubergeek42.WeechatAndroid.service.RelayService
import com.ubergeek42.WeechatAndroid.upload.main
import com.ubergeek42.WeechatAndroid.utils.afterTextChanged
import com.ubergeek42.WeechatAndroid.views.BufferListFragmentFullScreenController
Expand All @@ -29,8 +27,6 @@ import com.ubergeek42.WeechatAndroid.views.scrollCenteringWithoutAnimation
import com.ubergeek42.cats.Cat
import com.ubergeek42.cats.Kitty
import com.ubergeek42.cats.Root
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe

class BufferListFragment : Fragment(), BufferListEye {
companion object {
Expand Down Expand Up @@ -84,6 +80,7 @@ class BufferListFragment : Fragment(), BufferListEye {
ui.filterInput.text = null
}

// The below callback will be called on view restoration
ui.filterInput.afterTextChanged {
applyFilter()
adapter.onBuffersChanged()
Expand All @@ -94,26 +91,19 @@ class BufferListFragment : Fragment(), BufferListEye {

@MainThread @Cat override fun onStart() {
super.onStart()
EventBus.getDefault().register(this)
ui.filterInput.visibility = if (P.showBufferFilter) View.VISIBLE else View.GONE
applyColorSchemeToViews()
attachToBufferList()
}

@MainThread @Cat override fun onStop() {
super.onStop()
detachFromBufferList()
EventBus.getDefault().unregister(this)
}

////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////// event
////////////////////////////////////////////////////////////////////////////////////////////////

@Subscribe(sticky = true) @AnyThread @Cat fun onEvent(event: StateChangedEvent) {
if (event.state.contains(RelayService.STATE.LISTED)) attachToBufferList()
}

////////////////////////////////////////////////////////////////////////////////////// the juice
////////////////////////////////////////////////////////////////////////////////////////////////

@AnyThread private fun attachToBufferList() {
BufferList.bufferListEye = this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ object BufferList {
return buffers.firstOrNull { it.pointer == pointer }
}

val totalHotMessageCount get() = buffers.sumOf { it.hotCount }

/////////////////////////////////////////////////////////////////////////////////////// handlers

private val handlers = ConcurrentHashMap<String, HdataHandler>()
Expand Down

0 comments on commit a5ae9be

Please sign in to comment.