stream-chat-android icon indicating copy to clipboard operation
stream-chat-android copied to clipboard

Feature Request: Provide custom listener for ChannelHeaderView back button

Open josheroff-livly opened this issue 7 years ago • 2 comments

The ChannelHeaderView has a back button that finishes the activity when pressed:

binding.tvBack.setOnClickListener(view ->{
      if(viewModel.isThread())
          viewModel.initThread();
      else
          ((Activity) getContext()).finish();
});

(ChannelHeaderView, lines: 96-101, v. 1.10.0)

My current use case calls for the Stream hierarchy of custom views to be in Fragments (the entry point being a tab within a BottomNavigationView), so it'd be nice to have this back button hook into the NavigationController of my Fragment instead. This way, my backstack will be able to coexist with the Stream custom views.

If the consumer were able to provide a click listener for the back button, that would satisfy the backstack use case.

josheroff-livly avatar Sep 23 '19 20:09 josheroff-livly

Missed a method in the ChannelHeaderView, that's my mistake.

setHeaderOptionsClickListener was right there.

josheroff-livly avatar Sep 23 '19 21:09 josheroff-livly

@josheroff-livly This doesn't look like the problem is solved. I think he meant the back arrow, which would be the binding.tvBack and not binding.tvOption which the setHeaderOptionsClicklistener is handling.

My simple fix

val backArrow = channelHeader.findViewById<TextView>(R.id.tv_back)
backArrow.setOnClickListener { onBackPress() }

While this works, for some reason the last visible message isn't marked as read, how to do this? My work around

channel.lastState.setReadDateOfChannelLastMessage(thisUser, Date())

I believe there has to be easier ways to handle this, if we even have to handle it ourself

Chikrix avatar Oct 14 '19 11:10 Chikrix