diff --git a/app/src/main/java/com/ubergeek42/WeechatAndroid/WeechatActivity.kt b/app/src/main/java/com/ubergeek42/WeechatAndroid/WeechatActivity.kt index 6f9c07da..472212d8 100644 --- a/app/src/main/java/com/ubergeek42/WeechatAndroid/WeechatActivity.kt +++ b/app/src/main/java/com/ubergeek42/WeechatAndroid/WeechatActivity.kt @@ -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() @@ -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) } diff --git a/app/src/main/java/com/ubergeek42/WeechatAndroid/fragments/BufferListFragment.kt b/app/src/main/java/com/ubergeek42/WeechatAndroid/fragments/BufferListFragment.kt index cb965033..8c931c92 100644 --- a/app/src/main/java/com/ubergeek42/WeechatAndroid/fragments/BufferListFragment.kt +++ b/app/src/main/java/com/ubergeek42/WeechatAndroid/fragments/BufferListFragment.kt @@ -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 @@ -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 { @@ -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() @@ -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 diff --git a/app/src/main/java/com/ubergeek42/WeechatAndroid/relay/BufferList.kt b/app/src/main/java/com/ubergeek42/WeechatAndroid/relay/BufferList.kt index 44881f96..c16baad7 100644 --- a/app/src/main/java/com/ubergeek42/WeechatAndroid/relay/BufferList.kt +++ b/app/src/main/java/com/ubergeek42/WeechatAndroid/relay/BufferList.kt @@ -61,8 +61,6 @@ object BufferList { return buffers.firstOrNull { it.pointer == pointer } } - val totalHotMessageCount get() = buffers.sumOf { it.hotCount } - /////////////////////////////////////////////////////////////////////////////////////// handlers private val handlers = ConcurrentHashMap()