Skip to content

Commit 3ad9f64

Browse files
authored
Merge pull request #37 from GetStream/task/updateTutorial
Update tutorial to match new package structure
2 parents e537d66 + 572de40 commit 3ad9f64

27 files changed

+159
-167
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The sample apps consist of two screens:
2121
Each module contains multiple `ChannelActivity` implementations, which correspond to the steps of the tutorial. You can easily swap them by changing the `setOnChannelClickListener` located in `MainActivity`:
2222

2323
```kotlin
24-
channelsView.setOnChannelClickListener { channel ->
24+
channelListView.setOnChannelClickListener { channel ->
2525
// open the channel activity
2626
startActivity(ChannelActivity.newIntent(this, channel))
2727
}
@@ -31,5 +31,5 @@ Currently, you can choose from four different `ChannelActivity` implementations:
3131
<!-- TODO: Add links when the new version of the Android Tutorial is published -->
3232
* `ChannelActivity` - a basic _Message List_ implementation
3333
* `ChannelActivity2` - includes a new _MessageListView_ style and custom attachment type
34-
* `ChannelActivity3` - includes a custom _Channel Header_ component created with the [LiveData&Offline](https://github.com/GetStream/stream-chat-android-livedata) library
35-
* `ChannelActivity4` - includes a custom _Channel Header_ component created with the [Low-Level Client](https://github.com/GetStream/stream-chat-android-client) library
34+
* `ChannelActivity3` - includes a custom _Typing Header_ component created with the [LiveData&Offline](https://github.com/GetStream/stream-chat-android-livedata) library
35+
* `ChannelActivity4` - includes a custom _Typing Header_ component created with the [Low-Level Client](https://github.com/GetStream/stream-chat-android-client) library

samplejava/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ android {
3535

3636
dependencies {
3737
// Add new dependencies
38-
implementation "io.getstream:stream-chat-android-ui-components:4.5.3"
38+
implementation "io.getstream:stream-chat-android-ui-components:4.5.4"
3939
implementation 'io.coil-kt:coil:1.1.1'
4040

4141
implementation 'androidx.appcompat:appcompat:1.2.0'

samplejava/src/main/java/com/example/chattutorialjava/ChannelActivity.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@
1010
import androidx.lifecycle.ViewModelProvider;
1111

1212
import com.example.chattutorialjava.databinding.ActivityChannelBinding;
13-
import com.getstream.sdk.chat.viewmodel.ChannelHeaderViewModel;
1413
import com.getstream.sdk.chat.viewmodel.MessageInputViewModel;
15-
import com.getstream.sdk.chat.viewmodel.factory.ChannelViewModelFactory;
1614
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel;
1715
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel.Mode.Normal;
1816
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel.Mode.Thread;
1917
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel.State.NavigateUp;
2018

2119
import io.getstream.chat.android.client.models.Channel;
22-
import io.getstream.chat.android.ui.messages.header.ChannelHeaderViewModelBinding;
23-
import io.getstream.chat.android.ui.messages.header.MessagesHeaderView;
24-
import io.getstream.chat.android.ui.messages.view.MessageListViewModelBinding;
25-
import io.getstream.chat.android.ui.textinput.MessageInputViewModelBinding;
26-
import kotlin.Unit;
20+
import io.getstream.chat.android.ui.message.input.MessageInputViewModelBinding;
21+
import io.getstream.chat.android.ui.message.list.header.MessageListHeaderView;
22+
import io.getstream.chat.android.ui.message.list.header.viewmodel.MessageListHeaderViewModel;
23+
import io.getstream.chat.android.ui.message.list.header.viewmodel.MessageListHeaderViewModelBinding;
24+
import io.getstream.chat.android.ui.message.list.viewmodel.factory.MessageListViewModelFactory;
25+
import io.getstream.chat.android.ui.message.view.MessageListViewModelBinding;
2726

2827
public class ChannelActivity extends AppCompatActivity {
2928

@@ -49,16 +48,16 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
4948
}
5049

5150
// Step 1 - Create 3 separate ViewModels for the views so it's easy to customize one of the components
52-
ChannelViewModelFactory factory = new ChannelViewModelFactory(cid);
51+
MessageListViewModelFactory factory = new MessageListViewModelFactory(cid);
5352
ViewModelProvider provider = new ViewModelProvider(this, factory);
54-
ChannelHeaderViewModel channelHeaderViewModel = provider.get(ChannelHeaderViewModel.class);
53+
MessageListHeaderViewModel channelHeaderViewModel = provider.get(MessageListHeaderViewModel.class);
5554
MessageListViewModel messageListViewModel = provider.get(MessageListViewModel.class);
5655
MessageInputViewModel messageInputViewModel = provider.get(MessageInputViewModel.class);
5756

5857
// TODO set custom Imgur attachment View Holder Factory
5958

6059
// Step 2 - Bind the view and ViewModels, they are loosely coupled so it's easy to customize
61-
ChannelHeaderViewModelBinding.bind(channelHeaderViewModel, binding.messagesHeaderView, this);
60+
MessageListHeaderViewModelBinding.bind(channelHeaderViewModel, binding.messageListHeaderView, this);
6261
MessageListViewModelBinding.bind(messageListViewModel, binding.messageListView, this);
6362
MessageInputViewModelBinding.bind(messageInputViewModel, binding.messageInputView, this);
6463

@@ -84,11 +83,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
8483
});
8584

8685
// Step 6 - Handle back button behaviour correctly when you're in a thread
87-
MessagesHeaderView.OnClickListener backHandler = () -> {
86+
MessageListHeaderView.OnClickListener backHandler = () -> {
8887
messageListViewModel.onEvent(MessageListViewModel.Event.BackButtonPressed.INSTANCE);
8988
};
9089

91-
binding.messagesHeaderView.setBackButtonClickListener(backHandler);
90+
binding.messageListHeaderView.setBackButtonClickListener(backHandler);
9291

9392
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
9493
@Override

samplejava/src/main/java/com/example/chattutorialjava/ChannelActivity2.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@
1010
import androidx.lifecycle.ViewModelProvider;
1111

1212
import com.example.chattutorialjava.databinding.ActivityChannel2Binding;
13-
import com.getstream.sdk.chat.viewmodel.ChannelHeaderViewModel;
1413
import com.getstream.sdk.chat.viewmodel.MessageInputViewModel;
15-
import com.getstream.sdk.chat.viewmodel.factory.ChannelViewModelFactory;
1614
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel;
1715
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel.Mode.Normal;
1816
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel.Mode.Thread;
1917
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel.State.NavigateUp;
2018

2119
import io.getstream.chat.android.client.models.Channel;
22-
import io.getstream.chat.android.ui.messages.header.ChannelHeaderViewModelBinding;
23-
import io.getstream.chat.android.ui.messages.header.MessagesHeaderView;
24-
import io.getstream.chat.android.ui.messages.view.MessageListViewModelBinding;
25-
import io.getstream.chat.android.ui.textinput.MessageInputViewModelBinding;
26-
import kotlin.Unit;
20+
import io.getstream.chat.android.ui.message.input.MessageInputViewModelBinding;
21+
import io.getstream.chat.android.ui.message.list.header.MessageListHeaderView;
22+
import io.getstream.chat.android.ui.message.list.header.viewmodel.MessageListHeaderViewModel;
23+
import io.getstream.chat.android.ui.message.list.header.viewmodel.MessageListHeaderViewModelBinding;
24+
import io.getstream.chat.android.ui.message.list.viewmodel.factory.MessageListViewModelFactory;
25+
import io.getstream.chat.android.ui.message.view.MessageListViewModelBinding;
2726

2827
public class ChannelActivity2 extends AppCompatActivity {
2928

@@ -49,17 +48,17 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
4948
}
5049

5150
// Step 1 - Create 3 separate ViewModels for the views so it's easy to customize one of the components
52-
ChannelViewModelFactory factory = new ChannelViewModelFactory(cid);
51+
MessageListViewModelFactory factory = new MessageListViewModelFactory(cid);
5352
ViewModelProvider provider = new ViewModelProvider(this, factory);
54-
ChannelHeaderViewModel channelHeaderViewModel = provider.get(ChannelHeaderViewModel.class);
53+
MessageListHeaderViewModel channelHeaderViewModel = provider.get(MessageListHeaderViewModel.class);
5554
MessageListViewModel messageListViewModel = provider.get(MessageListViewModel.class);
5655
MessageInputViewModel messageInputViewModel = provider.get(MessageInputViewModel.class);
5756

58-
// Set custom AttachmentViewHolderFactory
57+
// Set view holder factory for Imgur attachments
5958
binding.messageListView.setMessageViewHolderFactory(new ImgurAttachmentViewHolderFactory());
6059

6160
// Step 2 - Bind the view and ViewModels, they are loosely coupled so it's easy to customize
62-
ChannelHeaderViewModelBinding.bind(channelHeaderViewModel, binding.messagesHeaderView, this);
61+
MessageListHeaderViewModelBinding.bind(channelHeaderViewModel, binding.messageListHeaderView, this);
6362
MessageListViewModelBinding.bind(messageListViewModel, binding.messageListView, this);
6463
MessageInputViewModelBinding.bind(messageInputViewModel, binding.messageInputView, this);
6564

@@ -85,19 +84,17 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
8584
});
8685

8786
// Step 6 - Handle back button behaviour correctly when you're in a thread
88-
MessagesHeaderView.OnClickListener backHandler = () -> {
87+
MessageListHeaderView.OnClickListener backHandler = () -> {
8988
messageListViewModel.onEvent(MessageListViewModel.Event.BackButtonPressed.INSTANCE);
9089
};
9190

92-
binding.messagesHeaderView.setBackButtonClickListener(backHandler);
91+
binding.messageListHeaderView.setBackButtonClickListener(backHandler);
9392

9493
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
9594
@Override
9695
public void handleOnBackPressed() {
9796
backHandler.onClick();
9897
}
9998
});
100-
101-
10299
}
103100
}

samplejava/src/main/java/com/example/chattutorialjava/ChannelActivity3.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
import androidx.lifecycle.ViewModelProvider;
1313

1414
import com.example.chattutorialjava.databinding.ActivityChannel3Binding;
15-
import com.getstream.sdk.chat.viewmodel.ChannelHeaderViewModel;
1615
import com.getstream.sdk.chat.viewmodel.MessageInputViewModel;
17-
import com.getstream.sdk.chat.viewmodel.factory.ChannelViewModelFactory;
1816
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel;
1917
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel.Mode.Normal;
2018
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel.Mode.Thread;
@@ -27,10 +25,12 @@
2725
import io.getstream.chat.android.client.models.User;
2826
import io.getstream.chat.android.livedata.ChatDomain;
2927
import io.getstream.chat.android.livedata.controller.ChannelController;
30-
import io.getstream.chat.android.ui.messages.header.ChannelHeaderViewModelBinding;
31-
import io.getstream.chat.android.ui.messages.header.MessagesHeaderView;
32-
import io.getstream.chat.android.ui.messages.view.MessageListViewModelBinding;
33-
import io.getstream.chat.android.ui.textinput.MessageInputViewModelBinding;
28+
import io.getstream.chat.android.ui.message.input.MessageInputViewModelBinding;
29+
import io.getstream.chat.android.ui.message.list.header.MessageListHeaderView;
30+
import io.getstream.chat.android.ui.message.list.header.viewmodel.MessageListHeaderViewModel;
31+
import io.getstream.chat.android.ui.message.list.header.viewmodel.MessageListHeaderViewModelBinding;
32+
import io.getstream.chat.android.ui.message.list.viewmodel.factory.MessageListViewModelFactory;
33+
import io.getstream.chat.android.ui.message.view.MessageListViewModelBinding;
3434

3535
public class ChannelActivity3 extends AppCompatActivity {
3636

@@ -56,17 +56,17 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
5656
}
5757

5858
// Step 1 - Create 3 separate ViewModels for the views so it's easy to customize one of the components
59-
ChannelViewModelFactory factory = new ChannelViewModelFactory(cid);
59+
MessageListViewModelFactory factory = new MessageListViewModelFactory(cid);
6060
ViewModelProvider provider = new ViewModelProvider(this, factory);
61-
ChannelHeaderViewModel channelHeaderViewModel = provider.get(ChannelHeaderViewModel.class);
61+
MessageListHeaderViewModel channelHeaderViewModel = provider.get(MessageListHeaderViewModel.class);
6262
MessageListViewModel messageListViewModel = provider.get(MessageListViewModel.class);
6363
MessageInputViewModel messageInputViewModel = provider.get(MessageInputViewModel.class);
6464

6565
// Set custom AttachmentViewHolderFactory
6666
binding.messageListView.setMessageViewHolderFactory(new ImgurAttachmentViewHolderFactory());
6767

6868
// Step 2 - Bind the view and ViewModels, they are loosely coupled so it's easy to customize
69-
ChannelHeaderViewModelBinding.bind(channelHeaderViewModel, binding.messagesHeaderView, this);
69+
MessageListHeaderViewModelBinding.bind(channelHeaderViewModel, binding.messageListHeaderView, this);
7070
MessageListViewModelBinding.bind(messageListViewModel, binding.messageListView, this);
7171
MessageInputViewModelBinding.bind(messageInputViewModel, binding.messageInputView, this);
7272

@@ -92,10 +92,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
9292
});
9393

9494
// Step 6 - Handle back button behaviour correctly when you're in a thread
95-
MessagesHeaderView.OnClickListener backHandler = () -> {
95+
MessageListHeaderView.OnClickListener backHandler = () -> {
9696
messageListViewModel.onEvent(MessageListViewModel.Event.BackButtonPressed.INSTANCE);
9797
};
98-
binding.messagesHeaderView.setBackButtonClickListener(backHandler);
98+
binding.messageListHeaderView.setBackButtonClickListener(backHandler);
9999
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
100100
@Override
101101
public void handleOnBackPressed() {

samplejava/src/main/java/com/example/chattutorialjava/ChannelActivity4.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
import androidx.lifecycle.ViewModelProvider;
1313

1414
import com.example.chattutorialjava.databinding.ActivityChannel4Binding;
15-
import com.getstream.sdk.chat.viewmodel.ChannelHeaderViewModel;
1615
import com.getstream.sdk.chat.viewmodel.MessageInputViewModel;
17-
import com.getstream.sdk.chat.viewmodel.factory.ChannelViewModelFactory;
1816
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel;
1917
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel.Mode.Normal;
2018
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel.Mode.Thread;
@@ -28,10 +26,12 @@
2826
import io.getstream.chat.android.client.events.TypingStopEvent;
2927
import io.getstream.chat.android.client.models.Channel;
3028
import io.getstream.chat.android.client.models.User;
31-
import io.getstream.chat.android.ui.messages.header.ChannelHeaderViewModelBinding;
32-
import io.getstream.chat.android.ui.messages.header.MessagesHeaderView;
33-
import io.getstream.chat.android.ui.messages.view.MessageListViewModelBinding;
34-
import io.getstream.chat.android.ui.textinput.MessageInputViewModelBinding;
29+
import io.getstream.chat.android.ui.message.input.MessageInputViewModelBinding;
30+
import io.getstream.chat.android.ui.message.list.header.MessageListHeaderView;
31+
import io.getstream.chat.android.ui.message.list.header.viewmodel.MessageListHeaderViewModel;
32+
import io.getstream.chat.android.ui.message.list.header.viewmodel.MessageListHeaderViewModelBinding;
33+
import io.getstream.chat.android.ui.message.list.viewmodel.factory.MessageListViewModelFactory;
34+
import io.getstream.chat.android.ui.message.view.MessageListViewModelBinding;
3535

3636
public class ChannelActivity4 extends AppCompatActivity {
3737

@@ -57,17 +57,17 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
5757
}
5858

5959
// Step 1 - Create 3 separate ViewModels for the views so it's easy to customize one of the components
60-
ChannelViewModelFactory factory = new ChannelViewModelFactory(cid);
60+
MessageListViewModelFactory factory = new MessageListViewModelFactory(cid);
6161
ViewModelProvider provider = new ViewModelProvider(this, factory);
62-
ChannelHeaderViewModel channelHeaderViewModel = provider.get(ChannelHeaderViewModel.class);
62+
MessageListHeaderViewModel channelHeaderViewModel = provider.get(MessageListHeaderViewModel.class);
6363
MessageListViewModel messageListViewModel = provider.get(MessageListViewModel.class);
6464
MessageInputViewModel messageInputViewModel = provider.get(MessageInputViewModel.class);
6565

6666
// Set custom AttachmentViewHolderFactory
6767
binding.messageListView.setMessageViewHolderFactory(new ImgurAttachmentViewHolderFactory());
6868

6969
// Step 2 - Bind the view and ViewModels, they are loosely coupled so it's easy to customize
70-
ChannelHeaderViewModelBinding.bind(channelHeaderViewModel, binding.messagesHeaderView, this);
70+
MessageListHeaderViewModelBinding.bind(channelHeaderViewModel, binding.messageListHeaderView, this);
7171
MessageListViewModelBinding.bind(messageListViewModel, binding.messageListView, this);
7272
MessageInputViewModelBinding.bind(messageInputViewModel, binding.messageInputView, this);
7373

@@ -93,11 +93,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
9393
});
9494

9595
// Step 6 - Handle back button behaviour correctly when you're in a thread
96-
MessagesHeaderView.OnClickListener backHandler = () -> {
96+
MessageListHeaderView.OnClickListener backHandler = () -> {
9797
messageListViewModel.onEvent(MessageListViewModel.Event.BackButtonPressed.INSTANCE);
9898
};
9999

100-
binding.messagesHeaderView.setBackButtonClickListener(backHandler);
100+
binding.messageListHeaderView.setBackButtonClickListener(backHandler);
101101

102102
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
103103
@Override

samplejava/src/main/java/com/example/chattutorialjava/ImgurAttachmentViewHolder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import coil.Coil;
2020
import coil.request.ImageRequest;
2121
import io.getstream.chat.android.client.models.Attachment;
22-
import io.getstream.chat.android.ui.messages.adapter.BaseMessageItemViewHolder;
23-
import io.getstream.chat.android.ui.messages.adapter.MessageListItemPayloadDiff;
22+
import io.getstream.chat.android.ui.message.list.adapter.BaseMessageItemViewHolder;
23+
import io.getstream.chat.android.ui.message.list.adapter.MessageListItemPayloadDiff;
2424

2525
class ImgurAttachmentViewHolder extends BaseMessageItemViewHolder<MessageListItem.MessageItem> {
2626

samplejava/src/main/java/com/example/chattutorialjava/ImgurAttachmentViewHolderFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
import io.getstream.chat.android.client.models.Attachment;
1212
import io.getstream.chat.android.client.models.Message;
13-
import io.getstream.chat.android.ui.messages.adapter.BaseMessageItemViewHolder;
14-
import io.getstream.chat.android.ui.messages.adapter.MessageListItemViewHolderFactory;
13+
import io.getstream.chat.android.ui.message.list.adapter.BaseMessageItemViewHolder;
14+
import io.getstream.chat.android.ui.message.list.adapter.MessageListItemViewHolderFactory;
1515

1616
class ImgurAttachmentViewHolderFactory extends MessageListItemViewHolderFactory {
1717

0 commit comments

Comments
 (0)