Skip to content

Commit

Permalink
Merge pull request #27 from Softeq/feature/new-release
Browse files Browse the repository at this point in the history
Add changes for new release
  • Loading branch information
vadimpylsky authored Dec 18, 2018
2 parents ca7c4c5 + d677a46 commit 0b603c6
Show file tree
Hide file tree
Showing 53 changed files with 787 additions and 403 deletions.
42 changes: 42 additions & 0 deletions Softeq.XToolkit.Chat.Droid/Listeners/LoadMoreScrollListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Developed by Softeq Development Corporation
// http://www.softeq.com

using System;
using Android.Support.V7.Widget;
using Softeq.XToolkit.Common;

namespace Softeq.XToolkit.Chat.Droid.Listeners
{
public class LoadMoreScrollListener : RecyclerView.OnScrollListener
{
private const int VisibleThreshold = 5;

private readonly TaskReference _onScrolled;

private bool _isBusy;

public LoadMoreScrollListener(TaskReference onScrolled)
{
_onScrolled = onScrolled ?? throw new ArgumentNullException(nameof(onScrolled));
}

public override async void OnScrolled(RecyclerView recyclerView, int dx, int dy)
{
base.OnScrolled(recyclerView, dx, dy);

var linearLayoutManager = (LinearLayoutManager)recyclerView.GetLayoutManager();

var totalItemCount = linearLayoutManager.ItemCount;
var lastVisibleItem = linearLayoutManager.FindLastVisibleItemPosition();

if (!_isBusy && totalItemCount <= (lastVisibleItem + VisibleThreshold))
{
_isBusy = true;

await _onScrolled.RunAsync();

_isBusy = false;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_toRightOf="@+id/iv_chat_photo"
android:maxLines="1"
android:inputType="text"
android:hint="Group Name"
android:textSize="20sp" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:maxLines="1"
android:inputType="text"
android:hint="Search" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_toLeftOf="@+id/date_time_text_view"
android:background="@android:color/holo_green_light"
android:background="@color/chat_unreaded_color"
android:visibility="gone" />

<TextView
Expand Down
3 changes: 2 additions & 1 deletion Softeq.XToolkit.Chat.Droid/Softeq.XToolkit.Chat.Droid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<Version>27.0.2.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.FFImageLoading.Transformations">
<Version>2.4.3.840</Version>
<Version>2.4.4.859</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -94,6 +94,7 @@
<Compile Include="Views\AddContactsDialogFragment.cs" />
<Compile Include="ViewHolders\SelectedContactViewHolder.cs" />
<Compile Include="ViewHolders\FilteredItemViewHolder.cs" />
<Compile Include="Listeners\LoadMoreScrollListener.cs" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\layout\activity_chat_details.xml" />
Expand Down
4 changes: 4 additions & 0 deletions Softeq.XToolkit.Chat.Droid/StyleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public interface IChatDroidStyle
int UnderlinedBg { get; }
int CheckedIcon { get; }
int UnCheckedIcon { get; }
int UnreadMessagesCountColor { get; }
int UnreadMutedMessagesCountColor { get; }
}

public abstract class ChatDroidStyleBase : IChatDroidStyle
Expand All @@ -62,5 +64,7 @@ public abstract class ChatDroidStyleBase : IChatDroidStyle
public abstract int UnderlinedBg { get; }
public abstract int CheckedIcon { get; }
public abstract int UnCheckedIcon { get; }
public abstract int UnreadMessagesCountColor { get; }
public abstract int UnreadMutedMessagesCountColor { get; }
}
}
25 changes: 17 additions & 8 deletions Softeq.XToolkit.Chat.Droid/ViewHolders/ChatViewHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
using Android.Graphics.Drawables;
using Android.Views;
using Android.Widget;
using Android.Support.V4.Content;
using FFImageLoading.Cross;
using FFImageLoading.Transformations;
using FFImageLoading.Work;
using Softeq.XToolkit.Bindings;
using Softeq.XToolkit.Chat.Models;
using Softeq.XToolkit.Chat.ViewModels;
using Softeq.XToolkit.Common;
using Softeq.XToolkit.Common.Command;
using Softeq.XToolkit.Common.Droid.Converters;
using Softeq.XToolkit.WhiteLabel.Droid.Controls;
using Softeq.XToolkit.WhiteLabel.Droid.Extensions;

namespace Softeq.XToolkit.Chat.Droid.ViewHolders
{
public class ChatViewHolder : BindableViewHolder<ChatSummaryViewModel>
{
private const string UnreadMessagesCountColor = "#5bc6c9";
private const string UnreadMutedMessagesCountColor = "#b4b4b4";
//TODO: move this to resources
private const string ChatStatusDefaultColor = "#dedede";

private readonly WeakAction<ChatSummaryViewModel> _selectChatAction;
Expand Down Expand Up @@ -71,8 +71,12 @@ public override void BindViewModel(ChatSummaryViewModel viewModel)
ChatPhotoImageView.LoadImageWithTextPlaceholder(
_viewModelRef.Target.ChatPhotoUrl,
_viewModelRef.Target.ChatName,
StyleHelper.Style.ChatAvatarStyles,
(TaskParameter x) => x.Transform(new CircleTransformation()));
new AvatarPlaceholderDrawable.AvatarStyles
{
BackgroundHexColors = StyleHelper.Style.ChatAvatarStyles.BackgroundHexColors,
Size = new System.Drawing.Size(45, 45)
},
x => x.Transform(new CircleTransformation()));
}));

Bindings.Add(this.SetBinding(() => _viewModelRef.Target.UnreadMessageCount).WhenSourceChanges(() =>
Expand All @@ -88,8 +92,13 @@ public override void BindViewModel(ChatSummaryViewModel viewModel)
{
if (UnreadMessageCountTextView != null)
{
var color = _viewModelRef.Target.IsMuted ? UnreadMutedMessagesCountColor : UnreadMessagesCountColor;
UnreadMessageCountTextView.Background = CreateBackgroundWithCornerRadius(Color.ParseColor(color), 56f);
var colorResId = _viewModelRef.Target.IsMuted
? StyleHelper.Style.UnreadMutedMessagesCountColor
: StyleHelper.Style.UnreadMessagesCountColor;
var color = ContextCompat.GetColor(UnreadMessageCountTextView.Context, colorResId);
UnreadMessageCountTextView.Background = CreateBackgroundWithCornerRadius(color, 56f);
}
}));

Expand All @@ -115,7 +124,7 @@ public override void BindViewModel(ChatSummaryViewModel viewModel)
}

// TODO: move to XToolkit.Common
private static Drawable CreateBackgroundWithCornerRadius(Color color, float radius)
private static Drawable CreateBackgroundWithCornerRadius(int color, float radius)
{
var drawable = new GradientDrawable();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ public override void BindViewModel(ChatMessageViewModel viewModel)
SenderPhotoImageView.LoadImageWithTextPlaceholder(
_viewModelRef.Target.SenderPhotoUrl,
_viewModelRef.Target.SenderName,
StyleHelper.Style.ChatAvatarStyles,
new WhiteLabel.Droid.Controls.AvatarPlaceholderDrawable.AvatarStyles {
BackgroundHexColors = StyleHelper.Style.ChatAvatarStyles.BackgroundHexColors,
Size = new System.Drawing.Size(35, 35)
},
(TaskParameter x) => x.Transform(new CircleTransformation()));
}

Expand Down
84 changes: 52 additions & 32 deletions Softeq.XToolkit.Chat.Droid/Views/AddContactsDialogFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using Softeq.XToolkit.Common.Command;
using Softeq.XToolkit.WhiteLabel.Droid.Controls;
using Softeq.XToolkit.WhiteLabel.Droid.Dialogs;
using Softeq.XToolkit.Chat.Droid.Listeners;
using Softeq.XToolkit.Common;

namespace Softeq.XToolkit.Chat.Droid.Views
{
Expand All @@ -37,19 +39,51 @@ public override void OnViewCreated(View view, Bundle savedInstanceState)

View.SetBackgroundResource(StyleHelper.Style.ContentColor);

_navigationBarView = View.FindViewById<NavigationBarView>(Resource.Id.dialog_select_members_nav_bar);
_navigationBarView.SetLeftButton(StyleHelper.Style.NavigationBarBackButtonIcon, new RelayCommand(Close));
_navigationBarView.SetRightButton(ViewModel.Resources.Done, ViewModel.DoneCommand);
_navigationBarView.SetTitle(ViewModel.Title);
_navigationBarView.SetBackground(StyleHelper.Style.ContentColor);
InitNavigationBarView(view);

var searchContainer = View.FindViewById<View>(Resource.Id.dialog_select_members_serch_container);
searchContainer.SetBackgroundResource(StyleHelper.Style.UnderlinedBg);

_editText = View.FindViewById<EditText>(Resource.Id.dialog_select_members_serch_text);
_editText.Hint = ViewModel.Resources.Search;

_addedMembers = View.FindViewById<RecyclerView>(Resource.Id.dialog_select_members_added_members);
InitSelectedRecyclerView(view);
InitFilteredRecyclerView(view);
}

protected override void DoAttachBindings()
{
base.DoAttachBindings();

Bindings.Add(this.SetBinding(() => ViewModel.ContactNameSearchQuery, () => _editText.Text, BindingMode.TwoWay));
Bindings.Add(this.SetBinding(() => ViewModel.HasSelectedContacts).WhenSourceChanges(() =>
{
_addedMembers.Visibility = ViewModel.HasSelectedContacts
? ViewStates.Visible
: ViewStates.Gone;
}));
}

public override void OnDestroy()
{
base.OnDestroy();

_filteredAdapter.Dispose();
_selectedAdapter.Dispose();
}

private void InitNavigationBarView(View view)
{
_navigationBarView = view.FindViewById<NavigationBarView>(Resource.Id.dialog_select_members_nav_bar);
_navigationBarView.SetLeftButton(StyleHelper.Style.NavigationBarBackButtonIcon, new RelayCommand(Close));
_navigationBarView.SetRightButton(ViewModel.Resources.Done, ViewModel.DoneCommand);
_navigationBarView.SetTitle(ViewModel.Title);
_navigationBarView.SetBackground(StyleHelper.Style.ContentColor);
}

private void InitSelectedRecyclerView(View view)
{
_addedMembers = view.FindViewById<RecyclerView>(Resource.Id.dialog_select_members_added_members);
_addedMembers.SetLayoutManager(new LinearLayoutManager(Context, LinearLayoutManager.Horizontal, false));
_selectedAdapter = new ObservableRecyclerViewAdapter<ChatUserViewModel>(
ViewModel.SelectedContacts,
Expand All @@ -62,14 +96,17 @@ public override void OnViewCreated(View view, Bundle savedInstanceState)
{
var viewHolder = (SelectedContactViewHolder)holder;
viewHolder.Bind(item);
});
});
_addedMembers.SetAdapter(_selectedAdapter);
}

_filteredMembers = View.FindViewById<RecyclerView>(Resource.Id.dialog_select_members_filtered_members);
private void InitFilteredRecyclerView(View view)
{
_filteredMembers = view.FindViewById<RecyclerView>(Resource.Id.dialog_select_members_filtered_members);
_filteredMembers.SetLayoutManager(new LinearLayoutManager(Context));
_filteredMembers.AddItemDecoration(new DividerItemDecoration(Context, DividerItemDecoration.Vertical));
_filteredAdapter = new ObservableRecyclerViewAdapter<ChatUserViewModel>(
ViewModel.FoundContacts,
ViewModel.PaginationViewModel.Items,
(parent, i) =>
{
var v = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.view_holder_member_filter_item, parent, false);
Expand All @@ -81,32 +118,15 @@ public override void OnViewCreated(View view, Bundle savedInstanceState)
viewHolder.Bind(item);
});
_filteredMembers.SetAdapter(_filteredAdapter);
}

protected override void DoAttachBindings()
{
base.DoAttachBindings();

this.SetBinding(() => ViewModel.ContactNameSearchQuery, () => _editText.Text, BindingMode.TwoWay);
this.SetBinding(() => ViewModel.HasSelectedContacts).WhenSourceChanges(() =>
{
_addedMembers.Visibility = ViewModel.HasSelectedContacts
? ViewStates.Visible
: ViewStates.Gone;
});
}

public override void OnDestroy()
{
base.OnDestroy();
_filteredMembers.AddOnScrollListener(new LoadMoreScrollListener(new TaskReference(async () =>
{
await ViewModel.PaginationViewModel.LoadNextPageAsync();
})));
}

_filteredAdapter.Dispose();
_selectedAdapter.Dispose();
}

private void Close()
{
ViewModel.DialogComponent.CloseCommand.Execute(false);
}
}
}
}
6 changes: 5 additions & 1 deletion Softeq.XToolkit.Chat.Droid/Views/ChatDetailsActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ protected override void DoAttachBindings()
_chatPhotoImageView.LoadImageWithTextPlaceholder(
ViewModel.Summary.AvatarUrl,
ViewModel.Summary.Name,
StyleHelper.Style.ChatAvatarStyles,
new AvatarPlaceholderDrawable.AvatarStyles
{
BackgroundHexColors = StyleHelper.Style.ChatAvatarStyles.BackgroundHexColors,
Size = new System.Drawing.Size(64, 64)
},
x => x.Transform(new CircleTransformation()));
});
}));
Expand Down
38 changes: 20 additions & 18 deletions Softeq.XToolkit.Chat.Droid/Views/ChatMessagesActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class ChatMessagesActivity : ActivityBase<ChatMessagesViewModel>
private ImageButton _editingMessageCloseButton;
private ImageButton _scrollDownImageButton;
private ContextMenuComponent _contextMenuComponent;
private bool _shouldSendStateMessageToChat;
//private bool _shouldSendStateMessageToChat;
private bool _isAdapterSourceInitialized;
private bool _isAutoScrollToFooterEnabled = true;
private ImagePicker _imagePicker;
Expand Down Expand Up @@ -113,10 +113,10 @@ protected override void OnCreate(Bundle savedInstanceState)

protected override void OnPause()
{
if (_shouldSendStateMessageToChat)
{
Messenger.Default.Send(new ChatInBackgroundMessage());
}
//if (_shouldSendStateMessageToChat)
//{
// Messenger.Default.Send(new ChatInBackgroundMessage());
//}

KeyboardService.HideSoftKeyboard(_messageEditText);

Expand All @@ -127,22 +127,23 @@ protected override void OnResume()
{
base.OnResume();

if (_shouldSendStateMessageToChat)
{
Messenger.Default.Send(new ChatInForegroundMessage());
}
else
{
_shouldSendStateMessageToChat = true;
}
// TODO YP: think about disconnecting when app in background
//if (_shouldSendStateMessageToChat)
//{
// Messenger.Default.Send(new ChatInForegroundMessage());
//}
//else
//{
// _shouldSendStateMessageToChat = true;
//}
}

public override void OnBackPressed()
{
_shouldSendStateMessageToChat = false;
//public override void OnBackPressed()
//{
// _shouldSendStateMessageToChat = false;

base.OnBackPressed();
}
// base.OnBackPressed();
//}

protected override void OnDestroy()
{
Expand Down Expand Up @@ -301,6 +302,7 @@ private void CloseEditImageContainer()
{
_editImageContainer.Visibility = ViewStates.Gone;
_previewImageKey = null;
_imagePicker.ViewModel.ImageCacheKey = null;
_imagePreview.SetImageDrawable(null);
});
}
Expand Down
Loading

0 comments on commit 0b603c6

Please sign in to comment.