Skip to content

Commit 21c88db

Browse files
authored
Merge pull request #34 from GetStream/update_for_ui_components
Update for UI components
2 parents a4ba435 + 129e1d7 commit 21c88db

34 files changed

+574
-520
lines changed

build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
3-
ext.kotlin_version = "1.4.10"
3+
ext.kotlin_version = '1.4.10'
44
repositories {
55
google()
66
jcenter()
7+
maven { url "https://jitpack.io" }
78
}
89
dependencies {
910
classpath "com.android.tools.build:gradle:4.1.0"
@@ -15,6 +16,7 @@ allprojects {
1516
repositories {
1617
google()
1718
jcenter()
19+
maven { url "https://jitpack.io" }
1820
}
1921
}
2022

samplejava/build.gradle

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,21 @@ android {
2727
targetCompatibility JavaVersion.VERSION_1_8
2828
}
2929

30+
buildFeatures {
31+
viewBinding true
32+
}
33+
3034
packagingOptions {
3135
exclude 'META-INF/*.kotlin_module'
3236
}
3337
}
3438

3539
dependencies {
36-
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.4.10"
37-
implementation "io.getstream:stream-chat-android:4.4.5"
38-
implementation "io.coil-kt:coil:1.0.0"
40+
implementation "io.getstream:stream-chat-android-ui-components:4.5.3"
41+
implementation 'io.coil-kt:coil:1.1.1'
3942

40-
implementation "androidx.lifecycle:lifecycle-viewmodel:2.3.0-beta01"
43+
implementation "androidx.recyclerview:recyclerview:1.1.0"
4144
implementation "androidx.appcompat:appcompat:1.2.0"
4245
implementation "androidx.constraintlayout:constraintlayout:2.0.4"
43-
implementation 'androidx.activity:activity-ktx:1.1.0'
46+
implementation "com.google.android.material:material:1.3.0"
4447
}

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

Lines changed: 0 additions & 51 deletions
This file was deleted.

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@
99
import androidx.appcompat.app.AppCompatActivity;
1010
import androidx.lifecycle.ViewModelProvider;
1111

12-
import com.getstream.sdk.chat.view.ChannelHeaderView;
13-
import com.getstream.sdk.chat.view.MessageListView;
14-
import com.getstream.sdk.chat.view.messageinput.MessageInputView;
12+
import com.example.chattutorialjava.databinding.ActivityChannelBinding;
1513
import com.getstream.sdk.chat.viewmodel.ChannelHeaderViewModel;
16-
import com.getstream.sdk.chat.viewmodel.ChannelHeaderViewModelBinding;
1714
import com.getstream.sdk.chat.viewmodel.MessageInputViewModel;
18-
import com.getstream.sdk.chat.viewmodel.MessageInputViewModelBinding;
1915
import com.getstream.sdk.chat.viewmodel.factory.ChannelViewModelFactory;
2016
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel;
2117
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel.Mode.Normal;
2218
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel.Mode.Thread;
2319
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel.State.NavigateUp;
24-
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModelBinding;
2520

2621
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;
2726
import kotlin.Unit;
2827

2928
public class ChannelActivity extends AppCompatActivity {
@@ -39,30 +38,29 @@ public static Intent newIntent(Context context, Channel channel) {
3938
@Override
4039
protected void onCreate(@Nullable Bundle savedInstanceState) {
4140
super.onCreate(savedInstanceState);
42-
setContentView(R.layout.activity_channel);
41+
42+
// Step 0 - inflate binding
43+
ActivityChannelBinding binding = ActivityChannelBinding.inflate(getLayoutInflater());
44+
setContentView(binding.getRoot());
45+
4346
String cid = getIntent().getStringExtra(CID_KEY);
4447
if (cid == null) {
4548
throw new IllegalStateException("Specifying a channel id is required when starting ChannelActivity");
4649
}
4750

48-
// Step 0 - Get View references
49-
MessageListView messageListView = findViewById(R.id.messageListView);
50-
ChannelHeaderView channelHeaderView = findViewById(R.id.channelHeaderView);
51-
MessageInputView messageInputView = findViewById(R.id.messageInputView);
52-
5351
// Step 1 - Create 3 separate ViewModels for the views so it's easy to customize one of the components
5452
ChannelViewModelFactory factory = new ChannelViewModelFactory(cid);
5553
ViewModelProvider provider = new ViewModelProvider(this, factory);
5654
ChannelHeaderViewModel channelHeaderViewModel = provider.get(ChannelHeaderViewModel.class);
5755
MessageListViewModel messageListViewModel = provider.get(MessageListViewModel.class);
5856
MessageInputViewModel messageInputViewModel = provider.get(MessageInputViewModel.class);
5957

60-
// TODO set custom AttachmentViewHolderFactory
58+
// TODO set custom Imgur attachment View Holder Factory
6159

6260
// Step 2 - Bind the view and ViewModels, they are loosely coupled so it's easy to customize
63-
ChannelHeaderViewModelBinding.bind(channelHeaderViewModel, channelHeaderView, this);
64-
MessageListViewModelBinding.bind(messageListViewModel, messageListView, this);
65-
MessageInputViewModelBinding.bind(messageInputViewModel, messageInputView, this);
61+
ChannelHeaderViewModelBinding.bind(channelHeaderViewModel, binding.messagesHeaderView, this);
62+
MessageListViewModelBinding.bind(messageListViewModel, binding.messageListView, this);
63+
MessageInputViewModelBinding.bind(messageInputViewModel, binding.messageInputView, this);
6664

6765
// Step 3 - Let the message input know when we open a thread
6866
messageListViewModel.getMode().observe(this, mode -> {
@@ -72,10 +70,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
7270
messageInputViewModel.resetThread();
7371
}
7472
});
73+
7574
// Step 4 - Let the message input know when we are editing a message
76-
messageListView.setOnMessageEditHandler(message -> {
75+
binding.messageListView.setMessageEditHandler(message -> {
7776
messageInputViewModel.getEditMessage().postValue(message);
78-
return Unit.INSTANCE;
7977
});
8078

8179
// Step 5 - Handle navigate up state
@@ -86,14 +84,16 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
8684
});
8785

8886
// Step 6 - Handle back button behaviour correctly when you're in a thread
89-
channelHeaderView.setOnBackClick(() -> {
87+
MessagesHeaderView.OnClickListener backHandler = () -> {
9088
messageListViewModel.onEvent(MessageListViewModel.Event.BackButtonPressed.INSTANCE);
91-
return Unit.INSTANCE;
92-
});
89+
};
90+
91+
binding.messagesHeaderView.setBackButtonClickListener(backHandler);
92+
9393
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
9494
@Override
9595
public void handleOnBackPressed() {
96-
channelHeaderView.getOnBackClick().invoke();
96+
backHandler.onClick();
9797
}
9898
});
9999
}

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

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@
99
import androidx.appcompat.app.AppCompatActivity;
1010
import androidx.lifecycle.ViewModelProvider;
1111

12-
import com.getstream.sdk.chat.view.ChannelHeaderView;
13-
import com.getstream.sdk.chat.view.MessageListView;
14-
import com.getstream.sdk.chat.view.messageinput.MessageInputView;
12+
import com.example.chattutorialjava.databinding.ActivityChannel2Binding;
1513
import com.getstream.sdk.chat.viewmodel.ChannelHeaderViewModel;
16-
import com.getstream.sdk.chat.viewmodel.ChannelHeaderViewModelBinding;
1714
import com.getstream.sdk.chat.viewmodel.MessageInputViewModel;
18-
import com.getstream.sdk.chat.viewmodel.MessageInputViewModelBinding;
1915
import com.getstream.sdk.chat.viewmodel.factory.ChannelViewModelFactory;
2016
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel;
2117
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel.Mode.Normal;
2218
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel.Mode.Thread;
2319
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel.State.NavigateUp;
24-
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModelBinding;
2520

2621
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;
2726
import kotlin.Unit;
2827

2928
public class ChannelActivity2 extends AppCompatActivity {
@@ -39,17 +38,16 @@ public static Intent newIntent(Context context, Channel channel) {
3938
@Override
4039
protected void onCreate(@Nullable Bundle savedInstanceState) {
4140
super.onCreate(savedInstanceState);
42-
setContentView(R.layout.activity_channel_2);
41+
42+
// Step 0 - inflate binding
43+
ActivityChannel2Binding binding = ActivityChannel2Binding.inflate(getLayoutInflater());
44+
setContentView(binding.getRoot());
45+
4346
String cid = getIntent().getStringExtra(CID_KEY);
4447
if (cid == null) {
4548
throw new IllegalStateException("Specifying a channel id is required when starting ChannelActivity2");
4649
}
4750

48-
// Step 0 - Get View references
49-
MessageListView messageListView = findViewById(R.id.messageListView);
50-
ChannelHeaderView channelHeaderView = findViewById(R.id.channelHeaderView);
51-
MessageInputView messageInputView = findViewById(R.id.messageInputView);
52-
5351
// Step 1 - Create 3 separate ViewModels for the views so it's easy to customize one of the components
5452
ChannelViewModelFactory factory = new ChannelViewModelFactory(cid);
5553
ViewModelProvider provider = new ViewModelProvider(this, factory);
@@ -58,12 +56,12 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
5856
MessageInputViewModel messageInputViewModel = provider.get(MessageInputViewModel.class);
5957

6058
// Set custom AttachmentViewHolderFactory
61-
messageListView.setAttachmentViewHolderFactory(new MyAttachmentViewHolderFactory());
59+
binding.messageListView.setMessageViewHolderFactory(new ImgurAttachmentViewHolderFactory());
6260

6361
// Step 2 - Bind the view and ViewModels, they are loosely coupled so it's easy to customize
64-
ChannelHeaderViewModelBinding.bind(channelHeaderViewModel, channelHeaderView, this);
65-
MessageListViewModelBinding.bind(messageListViewModel, messageListView, this);
66-
MessageInputViewModelBinding.bind(messageInputViewModel, messageInputView, this);
62+
ChannelHeaderViewModelBinding.bind(channelHeaderViewModel, binding.messagesHeaderView, this);
63+
MessageListViewModelBinding.bind(messageListViewModel, binding.messageListView, this);
64+
MessageInputViewModelBinding.bind(messageInputViewModel, binding.messageInputView, this);
6765

6866
// Step 3 - Let the message input know when we open a thread
6967
messageListViewModel.getMode().observe(this, mode -> {
@@ -82,20 +80,21 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
8280
});
8381

8482
// Step 5 - Let the message input know when we are editing a message
85-
messageListView.setOnMessageEditHandler(message -> {
83+
binding.messageListView.setMessageEditHandler(message -> {
8684
messageInputViewModel.getEditMessage().postValue(message);
87-
return Unit.INSTANCE;
8885
});
8986

9087
// Step 6 - Handle back button behaviour correctly when you're in a thread
91-
channelHeaderView.setOnBackClick(() -> {
88+
MessagesHeaderView.OnClickListener backHandler = () -> {
9289
messageListViewModel.onEvent(MessageListViewModel.Event.BackButtonPressed.INSTANCE);
93-
return Unit.INSTANCE;
94-
});
90+
};
91+
92+
binding.messagesHeaderView.setBackButtonClickListener(backHandler);
93+
9594
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
9695
@Override
9796
public void handleOnBackPressed() {
98-
channelHeaderView.getOnBackClick().invoke();
97+
backHandler.onClick();
9998
}
10099
});
101100

0 commit comments

Comments
 (0)