Skip to content

Commit 38c4c6b

Browse files
committed
Fix NRE
1 parent 8e02311 commit 38c4c6b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

AndroidXamarinChat/Extensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ public static void SendMessage(this ServerEventsClient client, PostRawToChannel
6969
client.ServiceClient.Post(request);
7070
}
7171

72-
public static void UpdateUserProfile(this ServerEventConnect connectMsg,TextView txtUser, ImageView imgProfile)
72+
public static void UpdateUserProfile(this ServerEventConnect connectMsg, MainActivity activity)
7373
{
74+
var txtUser = activity.FindViewById<TextView>(Resource.Id.txtUserName);
75+
var imgProfile = activity.FindViewById<ImageView>(Resource.Id.imgProfile);
76+
7477
Application.SynchronizationContext.Post(_ => { txtUser.Text = connectMsg.DisplayName; }, null);
7578
connectMsg.ProfileUrl.GetImageBitmap()
7679
.ContinueWith(

AndroidXamarinChat/MainActivity.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,16 @@ protected override void OnCreate(Bundle bundle)
7272
var messageHistoryAdapter = new MessageListViewAdapter(this, new List<ChatMessage>(), () => this.subscriberList);
7373
messageHistoryList.Adapter = messageHistoryAdapter;
7474

75-
var txtUser = FindViewById<TextView>(Resource.Id.txtUserName);
76-
var imgProfile = FindViewById<ImageView>(Resource.Id.imgProfile);
77-
var channels = new[] {"home"};
75+
var channels = new[] {"home"};
7876
cmdReceiver = new ChatCommandHandler (this, messageHistoryAdapter, "home");
77+
var activity = this;
7978

8079
client = new ServerEventsClient(BaseUrl, channels)
8180
{
8281
OnConnect = connectMsg =>
8382
{
8483
client.UpdateChatHistory(cmdReceiver).ConfigureAwait(false);
85-
connectMsg.UpdateUserProfile(txtUser, imgProfile);
84+
connectMsg.UpdateUserProfile(activity);
8685
},
8786
OnCommand = command =>
8887
{

0 commit comments

Comments
 (0)