diff --git a/app/build.gradle b/app/build.gradle index 20bf24dc..1cf9ec3e 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -57,9 +57,10 @@ dependencies { implementation 'com.github.bumptech.glide:glide:4.8.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0' //cometchat sdk - implementation 'com.cometchat:pro-android-chat-sdk:1.7.2' + implementation 'com.cometchat:pro-android-chat-sdk:1.8.3' - implementation'com.facebook.shimmer:shimmer:0.3.0' + implementation 'com.android.support:recyclerview-selection:28.0.0' + implementation'com.facebook.shimmer:shimmer:0.4.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index fe895674..134e3400 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -82,6 +82,7 @@ + \ No newline at end of file diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/CometChatActivity.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/CometChatActivity.java index 006e3803..ee7b13f9 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/CometChatActivity.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/CometChatActivity.java @@ -32,8 +32,7 @@ import java.util.HashMap; -public class CometChatActivity extends AppCompatActivity implements - ScrollHelper, CometChatActivityContract.CometChatActivityView,test { +public class CometChatActivity extends AppCompatActivity implements ScrollHelper, CometChatActivityContract.CometChatActivityView { private ViewPager mViewPager; //view pager @@ -271,20 +270,7 @@ public void setFab(boolean isExtended) { fabIconAnimator.setExtended(isExtended); } - - - @Override - public void x(String string) { - - } } -interface test{ - /** - * - * This methods take no parameter - * @param string - */ - void x(String string); -} + diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/GroupChatActivity.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/GroupChatActivity.java index 111e6a57..1b8e2162 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/GroupChatActivity.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/GroupChatActivity.java @@ -1,5 +1,6 @@ package com.inscripts.cometchatpulse.demo.Activity; +import android.app.SearchManager; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; @@ -16,6 +17,7 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.SearchView; import android.support.v7.widget.Toolbar; import android.text.Editable; import android.text.TextUtils; @@ -156,6 +158,10 @@ public class GroupChatActivity extends AppCompatActivity implements GroupChatAct private boolean isEditMessage; + private MenuItem searchItem; + + private SearchView searchView; + @Override protected void onCreate(Bundle savedInstanceState) { setTheme(R.style.AppTheme); @@ -456,6 +462,41 @@ protected void onStop() { @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.group_chat_menu, menu); + + + searchItem=menu.findItem(R.id.app_bar_search); + + SearchManager searchManager=((SearchManager)getSystemService(Context.SEARCH_SERVICE)); + + if (searchItem!=null){ + + searchView=((SearchView)searchItem.getActionView()); + + searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + @Override + public boolean onQueryTextSubmit(String s) { + return false; + } + + @Override + public boolean onQueryTextChange(String s) { + groupChatPresenter.searchMessage(s,groupId); + return false; + } + }); + + searchView.setOnCloseListener(new SearchView.OnCloseListener() { + @Override + public boolean onClose() { + groupChatPresenter.fetchPreviousMessage(groupId,30); + return false; + } + }); + } + + if (searchView!=null){ + searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); + } return super.onCreateOptionsMenu(menu); } @@ -710,6 +751,13 @@ public void setEditedMessage(BaseMessage baseMessage) { } } + @Override + public void setFilterList(List list) { + if (groupMessageAdapter!=null){ + groupMessageAdapter.setFilteredList(list); + } + } + @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/GroupDetailActivity.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/GroupDetailActivity.java index cabda062..1caf338f 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/GroupDetailActivity.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/GroupDetailActivity.java @@ -1,5 +1,6 @@ package com.inscripts.cometchatpulse.demo.Activity; +import android.content.Intent; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; import android.os.Bundle; @@ -14,6 +15,8 @@ import android.view.View; import android.widget.ImageView; import android.widget.TextView; + +import com.cometchat.pro.constants.CometChatConstants; import com.inscripts.cometchatpulse.demo.R; import com.inscripts.cometchatpulse.demo.Adapter.ViewPagerAdapter; import com.inscripts.cometchatpulse.demo.Contracts.GroupDetailActivityContract; @@ -52,8 +55,12 @@ public class GroupDetailActivity extends AppCompatActivity implements View.OnCli private TextView tvGroupDescription; + private TextView tvAddMembers; + private ViewPagerAdapter adapter; + private String scope; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -66,7 +73,7 @@ protected void onCreate(Bundle savedInstanceState) { private void initViewComponent() { Toolbar toolbar = findViewById(R.id.toolbar); -// + setSupportActionBar(toolbar); getSupportActionBar().setTitle(""); getSupportActionBar().setElevation(10); @@ -81,6 +88,9 @@ private void initViewComponent() { collapsingToolbar.setExpandedTitleGravity(Gravity.START | Gravity.BOTTOM); tvGroupDescription = findViewById(R.id.tv_group_description); + tvAddMembers=findViewById(R.id.addMember); + tvAddMembers.setVisibility(View.GONE); + tvAddMembers.setOnClickListener(this); tvGroupDescription.setTypeface(FontUtils.robotoRegular); tvGroupDescriptionLabel = findViewById(R.id.group_description_labal); @@ -120,9 +130,23 @@ protected void onDestroy() { groupDetailPresenter.detach(); } + @Override + protected void onResume() { + super.onResume(); + } + @Override public void onClick(View view) { + switch (view.getId()){ + + case R.id.addMember: + Intent addMemberIntent=new Intent(this,SelectUserActivity.class); + addMemberIntent.putExtra(StringContract.IntentStrings.INTENT_GROUP_ID,groupId); + addMemberIntent.putExtra(StringContract.IntentStrings.INTENT_SCOPE,scope); + startActivity(addMemberIntent); + break; + } } @Override @@ -158,6 +182,16 @@ public void setOwnerDetail(User user) { ownerUid = user.getUid(); } + @Override + public void setUserScope(String scope) { + this.scope=scope; + if (scope.equals(CometChatConstants.SCOPE_ADMIN)||scope.equals(CometChatConstants.SCOPE_MODERATOR)) { + tvAddMembers.setVisibility(View.VISIBLE); + } + else { + tvAddMembers.setVisibility(View.GONE); + } + } @Override public void setGroupOwnerName(String owner) { @@ -189,4 +223,4 @@ public void setGroupDescription(String description) { tvGroupDescription.setText(description); } } -} +} \ No newline at end of file diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/OneToOneChatActivity.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/OneToOneChatActivity.java index adba56b9..09807567 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/OneToOneChatActivity.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/OneToOneChatActivity.java @@ -1,6 +1,8 @@ package com.inscripts.cometchatpulse.demo.Activity; import android.annotation.TargetApi; +import android.app.SearchManager; +import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Bitmap; @@ -15,6 +17,7 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.SearchView; import android.support.v7.widget.Toolbar; import android.text.Editable; import android.text.TextUtils; @@ -34,6 +37,7 @@ import android.widget.Toast; import com.bumptech.glide.Glide; import com.cometchat.pro.constants.CometChatConstants; +import com.cometchat.pro.core.CometChat; import com.cometchat.pro.models.BaseMessage; import com.cometchat.pro.models.MediaMessage; import com.cometchat.pro.models.MessageReceipt; @@ -139,7 +143,7 @@ public class OneToOneChatActivity extends AppCompatActivity implements OneToOneA private BaseMessage baseMessage; - private RelativeLayout rlMain; + private static RelativeLayout rlMain; private static RelativeLayout rlReplyContainer; @@ -161,6 +165,10 @@ public class OneToOneChatActivity extends AppCompatActivity implements OneToOneA private boolean isEditMessage; + private MenuItem searchItem; + + private SearchView searchView; + @Override protected void onCreate(Bundle savedInstanceState) { @@ -177,10 +185,12 @@ protected void onCreate(Bundle savedInstanceState) { private void initViewComponent() { + ivAttchament = findViewById(R.id.iv_attchment); ivAttchament.setOnClickListener(this); sendButton = findViewById(R.id.buttonSendMessage); sendButton.setOnClickListener(this); + recordMicButton = findViewById(R.id.record_button); recordAudioLayout = findViewById(R.id.record_audio_view); tvBanner=findViewById(R.id.tvBlock); @@ -240,6 +250,7 @@ private void initViewComponent() { viewAniamtion = AnimationUtils.loadAnimation(this, R.anim.animate); goneAnimation = AnimationUtils.loadAnimation(this, R.anim.gone_animation); + oneToOnePresenter.setContext(this); oneToOnePresenter.getOwnerDetail(); oneToOnePresenter.handleIntent(getIntent()); @@ -394,6 +405,42 @@ protected void onDestroy() { @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.one_to_one_chat_menu, menu); + + + searchItem=menu.findItem(R.id.app_bar_search); + + SearchManager searchManager=((SearchManager)getSystemService(Context.SEARCH_SERVICE)); + + if (searchItem!=null){ + + searchView=((SearchView)searchItem.getActionView()); + + searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + @Override + public boolean onQueryTextSubmit(String s) { + return false; + } + + @Override + public boolean onQueryTextChange(String s) { + oneToOnePresenter.searchMessage(s,contactUid); + return false; + } + }); + + searchView.setOnCloseListener(new SearchView.OnCloseListener() { + @Override + public boolean onClose() { + oneToOnePresenter.fetchPreviousMessage(contactUid,30); + return false; + } + }); + } + + if (searchView!=null){ + searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); + } + return super.onCreateOptionsMenu(menu); } @@ -954,6 +1001,13 @@ public void setEditedMessage(BaseMessage baseMessage) { } } + @Override + public void setFilterList(List list) { + if (oneToOneAdapter!=null){ + oneToOneAdapter.setFilterList(list); + } + } + @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/SelectUserActivity.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/SelectUserActivity.java new file mode 100644 index 00000000..0afba53d --- /dev/null +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/SelectUserActivity.java @@ -0,0 +1,147 @@ +package com.inscripts.cometchatpulse.demo.Activity; + +import android.content.Intent; +import android.support.annotation.NonNull; +import android.support.v4.app.ActivityOptionsCompat; +import android.support.v4.util.Pair; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.Toolbar; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; + +import com.cometchat.pro.models.User; +import com.inscripts.cometchatpulse.demo.Adapter.ContactListAdapter; +import com.inscripts.cometchatpulse.demo.Contracts.SelectUserActivityContract; +import com.inscripts.cometchatpulse.demo.Contracts.StringContract; +import com.inscripts.cometchatpulse.demo.Helper.RecyclerTouchListener; +import com.inscripts.cometchatpulse.demo.Presenters.SelectUserActivityPresenter; +import com.inscripts.cometchatpulse.demo.R; + +import java.util.HashMap; +import java.util.Set; + +public class SelectUserActivity extends AppCompatActivity implements SelectUserActivityContract.SelectUserActivityView { + + private Toolbar toolbar; + + private RecyclerView rvUserList; + + private LinearLayoutManager linearLayoutManager; + + private ContactListAdapter contactListAdapter; + + private SelectUserActivityContract.SelectUserActivityPresenter selectUserActivityPresenter; + + private String scope; + + private String guid; + + private HashMap selectedUserView=new HashMap<>(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_select_user); + + selectUserActivityPresenter=new SelectUserActivityPresenter(); + selectUserActivityPresenter.attach(this); + initView(); + } + + private void initView() { + + selectUserActivityPresenter.getIntent(getIntent()); + toolbar = findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setTitle("Select Members"); + + rvUserList=findViewById(R.id.rvUserList); + linearLayoutManager= new LinearLayoutManager(this); + rvUserList.setLayoutManager(linearLayoutManager); + + selectUserActivityPresenter.getUserList(30); + + + rvUserList.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { + + if (!recyclerView.canScrollVertically(1)) { + selectUserActivityPresenter.getUserList(30); + } + + } + }); + + rvUserList.addOnItemTouchListener(new RecyclerTouchListener(this, + rvUserList, new RecyclerTouchListener.ClickListener() { + @Override + public void onClick(View var1, int position) { + User user= (User) var1.getTag(R.string.user); + if (selectedUserView.containsKey(user.getUid())){ + selectedUserView.get(user.getUid()).setBackgroundColor(getResources().getColor(android.R.color.transparent)); + selectedUserView.remove(user.getUid()); + } + else { + selectedUserView.put(user.getUid(),var1); + selectedUserView.get(user.getUid()).setBackgroundColor(getResources().getColor(R.color.selection)); + } + } + + @Override + public void onLongClick(View var1, int position) { + + } + })); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.add_member,menu); + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()){ + + case R.id.check: + + if (!selectedUserView.isEmpty()){ + Set keySet= selectedUserView.keySet(); + selectUserActivityPresenter.addMemberToGroup(guid,SelectUserActivity.this,keySet); + } + break; + } + return super.onOptionsItemSelected(item); + } + + @Override + public void setScope(String scope) { + this.scope=scope; + } + + @Override + public void setGUID(String guid) { + this.guid=guid; + } + + @Override + public void setContactAdapter(HashMap userHashMap) { + + if (contactListAdapter == null) { + contactListAdapter = new ContactListAdapter(userHashMap, this, R.layout.contact_list_item,true); + rvUserList.setAdapter(contactListAdapter); + } else { + if (userHashMap != null && userHashMap.size() == 0) { + contactListAdapter.refreshData(userHashMap); + } + } + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Adapter/GroupMessageAdapter.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Adapter/GroupMessageAdapter.java index 9801727c..93a87250 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Adapter/GroupMessageAdapter.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Adapter/GroupMessageAdapter.java @@ -165,6 +165,7 @@ private void setList(List messageList){ for (BaseMessage basemessage:messageList) { this.messageList.put(basemessage.getId(),basemessage); } + notifyDataSetChanged(); } @NonNull @Override @@ -412,6 +413,7 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) .apply(videoOption) .into(leftVideoViewHolder.imageMessage); + final String finalMediaFile3 = mediaFile; leftVideoViewHolder.btnPlayVideo.setOnClickListener(new View.OnClickListener() { @Override @@ -585,6 +587,8 @@ public void run() { if (!player.isPlaying()) { leftAudioViewHolder.playAudio.setImageResource(R.drawable.ic_play_arrow); } + + leftAudioViewHolder.audioSeekBar.setProgress(0); final String finalMediaFile1 = mediaFile; @@ -1539,6 +1543,12 @@ public void setEditMessage(BaseMessage baseMessage) { notifyDataSetChanged(); } + public void setFilteredList(List list) { + messageList.clear(); + setList(list); + + } + class DateItemHolder extends RecyclerView.ViewHolder { TextView txtMessageDate; diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Adapter/OneToOneAdapter.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Adapter/OneToOneAdapter.java index 16efcac9..7a701b8b 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Adapter/OneToOneAdapter.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Adapter/OneToOneAdapter.java @@ -1224,6 +1224,7 @@ private void setList(List messageList){ for (BaseMessage basemessage:messageList) { messageArrayList.put(basemessage.getId(),basemessage); } + notifyDataSetChanged(); } private void startIntent(String url, boolean isVideo) { @@ -1489,6 +1490,12 @@ public void setEditMessage(BaseMessage baseMessage) { notifyDataSetChanged(); } + public void setFilterList(List list) { + messageArrayList.clear(); + setList(list); + } + + class DateItemHolder extends RecyclerView.ViewHolder { TextView txtMessageDate; diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/CometApplication.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/CometApplication.java index 21065fea..c6b33649 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/CometApplication.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/CometApplication.java @@ -16,6 +16,7 @@ public class CometApplication extends Application { @Override public void onCreate() { + super.onCreate(); CometChat.init(this,StringContract.AppDetails.APP_ID,new CometChat.CallbackListener() { diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/GroupChatActivityContract.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/GroupChatActivityContract.java index 2ec77088..e63efc41 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/GroupChatActivityContract.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/GroupChatActivityContract.java @@ -46,6 +46,8 @@ interface GroupChatView extends BaseView { void setDeletedMessage(BaseMessage baseMessage); void setEditedMessage(BaseMessage baseMessage); + + void setFilterList(List list); } interface GroupChatPresenter extends BasePresenter { @@ -85,6 +87,8 @@ interface GroupChatPresenter extends BasePresenter { void deleteMessage(BaseMessage baseMessage); void editMessage(BaseMessage baseMessage, String message); + + void searchMessage(String s, String groupId); } } diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/GroupDetailActivityContract.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/GroupDetailActivityContract.java index 3fb905d8..7938c24c 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/GroupDetailActivityContract.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/GroupDetailActivityContract.java @@ -24,6 +24,8 @@ interface GroupDetailView{ void setGroupIcon(String icon); void setGroupDescription(String description); + + void setUserScope(String scope); } interface GroupDetailPresenter extends BasePresenter { diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/OneToOneActivityContract.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/OneToOneActivityContract.java index 55b15d38..daddaa52 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/OneToOneActivityContract.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/OneToOneActivityContract.java @@ -52,6 +52,8 @@ interface OneToOneView extends BaseView { void setDeletedMessage(BaseMessage baseMessage); void setEditedMessage(BaseMessage baseMessage); + + void setFilterList(List list); } interface OneToOnePresenter extends BasePresenter { @@ -95,5 +97,7 @@ interface OneToOnePresenter extends BasePresenter { void deleteMessage(BaseMessage baseMessage); void editMessage(BaseMessage baseMessage,String message); + + void searchMessage(String s,String UID); } } diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/SelectUserActivityContract.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/SelectUserActivityContract.java new file mode 100644 index 00000000..49f900d3 --- /dev/null +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/SelectUserActivityContract.java @@ -0,0 +1,33 @@ +package com.inscripts.cometchatpulse.demo.Contracts; + +import android.content.Intent; + +import com.cometchat.pro.models.User; +import com.inscripts.cometchatpulse.demo.Activity.SelectUserActivity; +import com.inscripts.cometchatpulse.demo.Base.BasePresenter; + +import java.util.HashMap; +import java.util.Set; + +public interface SelectUserActivityContract { + + + interface SelectUserActivityView{ + + void setScope(String scope); + + void setGUID(String guid); + + void setContactAdapter(HashMap userHashMap); + } + + interface SelectUserActivityPresenter extends BasePresenter { + + void getIntent(Intent intent); + + void getUserList(int i); + + + void addMemberToGroup(String guid, SelectUserActivity selectUserActivity, Set keySet); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/StringContract.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/StringContract.java index c7375fbd..d334910d 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/StringContract.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/StringContract.java @@ -26,11 +26,11 @@ public static class IntentStrings { public static final String ID = "id"; public static final String AVATAR = "avatar"; public static final String ISVIDEO ="isvideo"; + public static final String INTENT_SCOPE = "intent_scope"; } public static class PreferenceString{ public static final String BLOCKED_USERS="blocked_users"; - } public static class RequestCode { @@ -45,7 +45,7 @@ public static class RequestCode { } public static class AppDetails{ - public static final String APP_ID = "XXXXXXXXXXXXXXX"; - public static final String API_KEY = "XXXXXXXXXXXXXXX"; + public static final String APP_ID = "XXXXXXXXXXXXXX"; + public static final String API_KEY = "XXXXXXXXXXXXXX"; } } diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/ContactsListPresenter.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/ContactsListPresenter.java index 207fb28c..bb6b60af 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/ContactsListPresenter.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/ContactsListPresenter.java @@ -19,6 +19,7 @@ public class ContactsListPresenter extends Presenter userHashMap=new HashMap<>(); private static final String TAG = "ContactsListPresenter"; @@ -37,6 +38,7 @@ public void onSuccess(List users) { Logger.error(TAG," "+users.size()); for (int i = 0; i < users.size(); i++) { + Log.d(TAG, "fetchNext onSuccess: "+users.get(i).toString()); userHashMap.put(users.get(i).getUid(), users.get(i)); } getBaseView().setContactAdapter(userHashMap); @@ -45,7 +47,7 @@ public void onSuccess(List users) { @Override public void onError(CometChatException e) { - Log.d(TAG, "fetchNext onError: "); + Log.d(TAG, "fetchNext onError: "+e.getMessage()); } }); } @@ -54,10 +56,10 @@ public void onError(CometChatException e) { @Override public void onSuccess(List users) { if (users != null) { - Logger.error("old user list request obj"); - Logger.error(TAG," "+users.size()); - for (int i = 0; i < users.size(); i++) { + + Log.d(TAG, "fetchNext onSuccess: "+users.toString()); + userHashMap.put(users.get(i).getUid(), users.get(i)); } getBaseView().setContactAdapter(userHashMap); @@ -114,16 +116,13 @@ public void onSuccess(List users) { hashMap.put(user.getUid(),user); } getBaseView().setFilterList(hashMap); - } - @Override public void onError(CometChatException e) { Log.d(TAG, "onError: fetchNext "+e.getMessage()); } }); - } public void fetchCount() { diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/GroupChatPresenter.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/GroupChatPresenter.java index 993cac11..0247cf53 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/GroupChatPresenter.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/GroupChatPresenter.java @@ -92,8 +92,7 @@ public void addMessageReceiveListener(String listenerId, final String groupId, f CometChat.addMessageListener(listenerId, new CometChat.MessageListener() { @Override public void onTextMessageReceived(TextMessage message) { - if (groupId != null && groupId.equals(message.getReceiverUid()) && - !message.getSender().getUid().equals(ownerId)) { + if (groupId != null && groupId.equals(message.getReceiverUid()) && !message.getSender().getUid().equals(ownerId)) { MediaUtils.playSendSound(context,R.raw.receive); getBaseView().addReceivedMessage(message); } @@ -130,6 +129,16 @@ public void onMessageRead(MessageReceipt messageReceipt) { getBaseView().onMessageRead(messageReceipt); } + @Override + public void onMessageEdited(BaseMessage message) { + getBaseView().setEditedMessage(message); + } + + @Override + public void onMessageDeleted(BaseMessage message) { + getBaseView().setDeletedMessage(message); + } + }); } @@ -188,13 +197,13 @@ public void onGroupMemberUnbanned(Action action, User unbannedUser, User unbanne } } - @Override - public void onGroupMemberScopeChanged(Action action, User user, String scopeChangedTo, String scopeChangedFrom, Group group) { - if (groupId != null && groupId.equals(action.getReceiverUid())){ - if (isViewAttached()) - getBaseView().addSentMessage(action); - } - } +// @Override +// public void onGroupMemberScopeChanged(Action action, User user, String scopeChangedTo, String scopeChangedFrom, Group group) { +// if (groupId != null && groupId.equals(action.getReceiverUid())){ +// if (isViewAttached()) +// getBaseView().addSentMessage(action); +// } +// } }); } @@ -332,11 +341,41 @@ public void onError(CometChatException e) { }); } + @Override + public void searchMessage(String s,String GUID) { + List list=new ArrayList<>(); + + messagesRequest=null; + MessagesRequest searchMessageRequest=new MessagesRequest.MessagesRequestBuilder() + .setGUID(GUID).setSearchKeyword(s).setLimit(30).build(); + + searchMessageRequest.fetchPrevious(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List baseMessages) { + if (isViewAttached()) { + for (BaseMessage baseMessage : baseMessages) { + Log.d(TAG, "onSuccess: delete "+baseMessage.getDeletedAt()); + if (!baseMessage.getCategory().equals(CometChatConstants.CATEGORY_ACTION)&&baseMessage.getDeletedAt()==0) { + list.add(baseMessage); + } + } + getBaseView().setFilterList(list); + } + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, " onError: "+e.getMessage()); + } + }); + + } + @Override public void fetchPreviousMessage(String groupId, int limit) { List list=new ArrayList<>(); if (messagesRequest == null) { - messagesRequest = new MessagesRequest.MessagesRequestBuilder().setGUID(groupId).setLimit(limit).build(); + messagesRequest = new MessagesRequest.MessagesRequestBuilder().setGUID(groupId).setLimit(limit).hideMessagesFromBlockedUsers(true).build(); messagesRequest.fetchPrevious(new CometChat.CallbackListener>() { @Override public void onSuccess(List baseMessages) { @@ -346,11 +385,10 @@ public void onSuccess(List baseMessages) { Log.d(TAG, "onSuccess: fetchPrevious" + baseMessage.toString()); Logger.error("groupMessage" + baseMessage.getId() + " timestamp : " + baseMessage.getSentAt() + " list size :" + baseMessages.size()); - if (!baseMessage.getCategory().equals(CometChatConstants.CATEGORY_ACTION) && baseMessage.getDeletedAt() == 0) { + if (baseMessage.getDeletedAt() == 0) { list.add(baseMessage); } - } getBaseView().setAdapter(list); } @@ -372,7 +410,7 @@ public void onSuccess(List baseMessages) { Log.d(TAG, "onSuccess: fetchPrevious" + baseMessage.toString()); Logger.error("groupMessage" + baseMessage.getId()); - if (!baseMessage.getCategory().equals(CometChatConstants.CATEGORY_ACTION) && baseMessage.getDeletedAt() == 0) { + if (baseMessage.getDeletedAt() == 0) { list.add(baseMessage); } diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/GroupDetailActivityPresenter.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/GroupDetailActivityPresenter.java index 8a54d4c0..7d1d7b50 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/GroupDetailActivityPresenter.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/GroupDetailActivityPresenter.java @@ -37,6 +37,7 @@ public void onSuccess(Group group) { getBaseView().setGroupName(group.getName()); getBaseView().setGroupOwnerName(group.getOwner()); getBaseView().setGroupIcon(group.getIcon()); + getBaseView().setUserScope(group.getScope()); getBaseView().setGroupDescription(group.getDescription()); } } diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/OneToOneActivityPresenter.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/OneToOneActivityPresenter.java index d524e14d..314e5123 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/OneToOneActivityPresenter.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/OneToOneActivityPresenter.java @@ -123,6 +123,7 @@ public void addMessageReceiveListener(final String contactUid) { @Override public void onTextMessageReceived(TextMessage message) { if (isViewAttached()) { + Log.d(TAG, "onTextMessageReceived: "+message.toString()); if (message.getSender().getUid().equals(contactUid)) { MediaUtils.playSendSound(context, R.raw.receive); Log.d(TAG, "onTextMessageReceived: "+message.toString()); @@ -166,9 +167,20 @@ public void onMessageRead(MessageReceipt messageReceipt) { getBaseView().onMessageRead(messageReceipt); } + @Override + public void onMessageEdited(BaseMessage message) { + getBaseView().setEditedMessage(message); + } + + @Override + public void onMessageDeleted(BaseMessage message) { + getBaseView().setDeletedMessage(message); + } + }); + } @Override @@ -210,7 +222,6 @@ public void fetchPreviousMessage(String contactUid, int limit) { List list=new ArrayList<>(); if (messagesRequest == null) { - messagesRequest = new MessagesRequest.MessagesRequestBuilder().setUID(contactUid).setLimit(limit).build(); messagesRequest.fetchPrevious(new CometChat.CallbackListener>() { @Override @@ -399,7 +410,6 @@ public void onSuccess(BaseMessage baseMessage) { Log.d(TAG, "onSuccess: deleteMessage "+baseMessage.toString()); getBaseView().setDeletedMessage(baseMessage); } - @Override public void onError(CometChatException e) { Log.d(TAG, "onError: deleteMessage"); @@ -425,6 +435,36 @@ public void onError(CometChatException e) { }); } + @Override + public void searchMessage(String s,String UID) { + List list=new ArrayList<>(); + + messagesRequest=null; + MessagesRequest searchMessageRequest=new MessagesRequest.MessagesRequestBuilder() + .setUID(UID).setSearchKeyword(s).setLimit(30).build(); + + searchMessageRequest.fetchPrevious(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List baseMessages) { + if (isViewAttached()) { + for (BaseMessage baseMessage : baseMessages) { + Log.d(TAG, "onSuccess: delete "+baseMessage.getDeletedAt()); + if (!baseMessage.getCategory().equals(CometChatConstants.CATEGORY_ACTION)&&baseMessage.getDeletedAt()==0) { + list.add(baseMessage); + } + } + getBaseView().setFilterList(list); + } + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, " onError: "+e.getMessage()); + } + }); + + } + @Override public void removeMessageLisenter(String listenerId) { CometChat.removeMessageListener(listenerId); diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/SelectUserActivityPresenter.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/SelectUserActivityPresenter.java new file mode 100644 index 00000000..031d66e2 --- /dev/null +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/SelectUserActivityPresenter.java @@ -0,0 +1,121 @@ +package com.inscripts.cometchatpulse.demo.Presenters; + +import android.content.Context; +import android.content.Intent; +import android.util.Log; +import android.widget.Toast; + +import com.cometchat.pro.constants.CometChatConstants; +import com.cometchat.pro.core.CometChat; +import com.cometchat.pro.core.UsersRequest; +import com.cometchat.pro.exceptions.CometChatException; +import com.cometchat.pro.models.GroupMember; +import com.cometchat.pro.models.User; +import com.inscripts.cometchatpulse.demo.Activity.SelectUserActivity; +import com.inscripts.cometchatpulse.demo.Base.Presenter; +import com.inscripts.cometchatpulse.demo.Contracts.SelectUserActivityContract; +import com.inscripts.cometchatpulse.demo.Contracts.StringContract; +import com.inscripts.cometchatpulse.demo.Utils.Logger; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +public class SelectUserActivityPresenter extends Presenter implements + SelectUserActivityContract.SelectUserActivityPresenter { + + private UsersRequest usersRequest; + HashMap userHashMap=new HashMap<>(); + + private static final String TAG = "SelectUserActivityPrese"; + + @Override + public void getIntent(Intent intent) { + + if (intent.hasExtra(StringContract.IntentStrings.INTENT_GROUP_ID)){ + getBaseView().setGUID(intent.getStringExtra(StringContract.IntentStrings.INTENT_GROUP_ID)); + } + + if (intent.hasExtra(StringContract.IntentStrings.INTENT_SCOPE)){ + getBaseView().setScope(intent.getStringExtra(StringContract.IntentStrings.INTENT_SCOPE)); + } + } + + @Override + public void getUserList(int i) { + + + if (usersRequest==null) { + + usersRequest = new UsersRequest.UsersRequestBuilder().setLimit(i).build(); + + usersRequest.fetchNext(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List users) { + Logger.error(TAG," "+users.size()); + + for (int i = 0; i < users.size(); i++) { + userHashMap.put(users.get(i).getUid(), users.get(i)); + } + getBaseView().setContactAdapter(userHashMap); + + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "fetchNext onError: "); + } + }); + } + else { + usersRequest.fetchNext(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List users) { + if (users != null) { + Logger.error(TAG," "+users.size()); + + for (int i = 0; i < users.size(); i++) { + userHashMap.put(users.get(i).getUid(), users.get(i)); + } + getBaseView().setContactAdapter(userHashMap); + } + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "fetchNext old onError: "); + } + + }); + } + + } + + @Override + public void addMemberToGroup(String guid, SelectUserActivity selectUserActivity, Set keySet) { + + List userList=new ArrayList<>(); + Iterator value=keySet.iterator(); + while (value.hasNext()){ + userList.add(new GroupMember((String) value.next(), CometChatConstants.SCOPE_PARTICIPANT)); + } + + CometChat.addMembersToGroup(guid, userList, null, + new CometChat.CallbackListener>() { + @Override + public void onSuccess(HashMap stringStringHashMap) { + selectUserActivity.finish(); + } + + @Override + public void onError(CometChatException e) { + Toast.makeText(selectUserActivity, e.getMessage(), Toast.LENGTH_SHORT).show(); + } + }); + + } + + +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_person_add_black_24dp.xml b/app/src/main/res/drawable/ic_person_add_black_24dp.xml new file mode 100644 index 00000000..921084c9 --- /dev/null +++ b/app/src/main/res/drawable/ic_person_add_black_24dp.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_comet_chat.xml b/app/src/main/res/layout/activity_comet_chat.xml index dec40302..a97f900a 100755 --- a/app/src/main/res/layout/activity_comet_chat.xml +++ b/app/src/main/res/layout/activity_comet_chat.xml @@ -43,9 +43,6 @@ - - - + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/bottom_message_bar.xml b/app/src/main/res/layout/bottom_message_bar.xml index cb064706..fdb69326 100755 --- a/app/src/main/res/layout/bottom_message_bar.xml +++ b/app/src/main/res/layout/bottom_message_bar.xml @@ -47,7 +47,6 @@ - - \ No newline at end of file diff --git a/app/src/main/res/layout/create_group.xml b/app/src/main/res/layout/create_group.xml index b3a039ce..9751b235 100755 --- a/app/src/main/res/layout/create_group.xml +++ b/app/src/main/res/layout/create_group.xml @@ -18,8 +18,6 @@ app:layout_constraintTop_toTopOf="parent" app:title="@string/create_chatroom" /> - - + + + + + @@ -126,6 +152,7 @@ android:layout_marginTop="16dp" android:layout_marginStart="16dp" android:layout_marginEnd="16dp" + android:background="@drawable/tab" app:tabBackground="@drawable/tab_background" app:tabIndicator="@null" diff --git a/app/src/main/res/menu/add_member.xml b/app/src/main/res/menu/add_member.xml new file mode 100644 index 00000000..7963449d --- /dev/null +++ b/app/src/main/res/menu/add_member.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/group_chat_menu.xml b/app/src/main/res/menu/group_chat_menu.xml index b59502a5..5930d57c 100755 --- a/app/src/main/res/menu/group_chat_menu.xml +++ b/app/src/main/res/menu/group_chat_menu.xml @@ -2,6 +2,13 @@ + + + + + #C8E6C9 #FFCDD2 #E53935 + #dddddd \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c57205e2..c9cb9097 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -88,6 +88,7 @@ Decline Typing.. is Typing... + Add Members