Commit 5f3f98a1 authored by jyx's avatar jyx

代码优化

parent a6494f52
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/page_title_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/page_title_layout">
android:background="@color/read_dot_bg">
<LinearLayout
android:id="@+id/page_title_left_group"
......@@ -20,16 +21,16 @@
android:id="@+id/page_title_left_icon"
android:layout_width="20dp"
android:layout_height="20dp"
android:clickable="false"
android:background="?attr/core_title_bar_back_icon" />
android:background="?attr/core_title_bar_back_icon"
android:clickable="false" />
<com.tencent.qcloud.tuikit.timcommon.component.UnreadCountTextView
android:id="@+id/new_message_total_unread"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:gravity="center"
android:includeFontPadding="false"
android:layout_marginEnd="5dp"
android:minWidth="18.4dp"
android:minHeight="18.4dp"
android:textColor="#ffffff"
......@@ -40,10 +41,10 @@
android:id="@+id/page_title_left_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/core_title_bar_text_bg"
android:gravity="center"
android:textColor="?attr/core_title_bar_text_bg"
android:textSize="16.3sp"
android:textStyle="bold"/>
android:textStyle="bold" />
</LinearLayout>
......@@ -53,15 +54,15 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:ellipsize="end"
android:gravity="center"
android:maxWidth="200dp"
android:singleLine="true"
android:ellipsize="end"
android:textAlignment="gravity"
android:textColor="?attr/core_title_bar_text_bg"
android:textSize="16.3sp"
android:textStyle="bold"
android:gravity="center"
tools:text="Title"/>
tools:text="Title" />
<LinearLayout
android:id="@+id/page_title_right_group"
......@@ -81,7 +82,7 @@
android:gravity="end"
android:textColor="?attr/core_title_bar_text_bg"
android:textSize="16.3sp"
android:textStyle="bold"/>
android:textStyle="bold" />
<ImageView
android:id="@+id/page_title_right_icon"
......
......@@ -22,8 +22,6 @@ import com.tencent.qcloud.tuikit.tuichat.classicui.widget.message.MessageRecycle
*/
public interface IChatLayout extends ILayout {
InputView getInputLayout();
MessageRecyclerView getMessageLayout();
NoticeLayout getNoticeLayout();
......@@ -34,6 +32,8 @@ public interface IChatLayout extends ILayout {
void exitChat();
InputView getInputView();
void initDefault(TUIBaseChatFragment fragment);
void loadMessages(int type);
......
......@@ -3,7 +3,10 @@ package com.tencent.qcloud.tuikit.tuichat.classicui.page;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import androidx.annotation.Nullable;
import com.tencent.imsdk.v2.V2TIMGroupAtInfo;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.qcloud.tuicore.TUIConstants;
......@@ -17,6 +20,7 @@ import com.tencent.qcloud.tuikit.tuichat.bean.DraftInfo;
import com.tencent.qcloud.tuikit.tuichat.bean.GroupChatInfo;
import com.tencent.qcloud.tuikit.tuichat.util.ChatMessageBuilder;
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatLog;
import java.util.List;
public abstract class TUIBaseChatActivity extends BaseLightActivity {
......@@ -27,10 +31,12 @@ public abstract class TUIBaseChatActivity extends BaseLightActivity {
TUIChatLog.i(TAG, "onCreate " + this);
super.onCreate(savedInstanceState);
setContentView(R.layout.chat_activity);
setContentView(getContentViewLayoutID());
initChat(getIntent());
}
protected abstract int getContentViewLayoutID();
@Override
protected void onNewIntent(Intent intent) {
TUIChatLog.i(TAG, "onNewIntent");
......
......@@ -9,6 +9,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.annotation.NonNull;
......@@ -210,7 +211,7 @@ public abstract class TUIBaseChatFragment extends Fragment {
callTypeString = TUIConstants.TUICalling.TYPE_AUDIO;
}
Map<String, Object> map = new HashMap<>();
map.put(TUIConstants.TUICalling.PARAM_NAME_USERIDS, new String[] {messageInfo.getUserId()});
map.put(TUIConstants.TUICalling.PARAM_NAME_USERIDS, new String[]{messageInfo.getUserId()});
map.put(TUIConstants.TUICalling.PARAM_NAME_TYPE, callTypeString);
TUICore.callService(TUIConstants.TUICalling.SERVICE_NAME, TUIConstants.TUICalling.METHOD_NAME_CALL, map);
}
......@@ -240,7 +241,7 @@ public abstract class TUIBaseChatFragment extends Fragment {
Map<String, Object> param = new HashMap<>();
param.put(TUIConstants.TUIChat.Extension.ChatUserIconClickedProcessor.USER_ID, userID);
List<TUIExtensionInfo> extensionInfoList =
TUICore.getExtensionList(TUIConstants.TUIChat.Extension.ChatUserIconClickedProcessor.CLASSIC_EXTENSION_ID, param);
TUICore.getExtensionList(TUIConstants.TUIChat.Extension.ChatUserIconClickedProcessor.CLASSIC_EXTENSION_ID, param);
if (!extensionInfoList.isEmpty()) {
Collections.singletonList(extensionInfoList);
TUIExtensionInfo extensionInfo = extensionInfoList.get(0);
......@@ -441,4 +442,6 @@ public abstract class TUIBaseChatFragment extends Fragment {
}
public abstract ChatPresenter getPresenter();
public abstract TitleBarLayout getTitleBarLayout();
}
package com.tencent.qcloud.tuikit.tuichat.classicui.page;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import com.tencent.qcloud.tuicore.util.ToastUtil;
import com.tencent.qcloud.tuikit.timcommon.component.TitleBarLayout;
import com.tencent.qcloud.tuikit.timcommon.component.interfaces.ITitleBarLayout;
import com.tencent.qcloud.tuikit.tuichat.R;
import com.tencent.qcloud.tuikit.tuichat.TUIChatConstants;
import com.tencent.qcloud.tuikit.tuichat.bean.C2CChatInfo;
import com.tencent.qcloud.tuikit.tuichat.bean.ChatInfo;
import com.tencent.qcloud.tuikit.tuichat.presenter.C2CChatPresenter;
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatLog;
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatUtils;
public class TUIC2CChatActivity extends TUIBaseChatActivity {
private static final String TAG = TUIC2CChatActivity.class.getSimpleName();
private TUIC2CChatFragment chatFragment;
@Override
protected int getContentViewLayoutID() {
return R.layout.chat_activity;
}
@Override
public void initChat(ChatInfo chatInfo) {
TUIChatLog.i(TAG, "inti chat " + chatInfo);
......@@ -27,6 +36,26 @@ public class TUIC2CChatActivity extends TUIBaseChatActivity {
chatFragment = new TUIC2CChatFragment();
chatFragment.setChatInfo((C2CChatInfo) chatInfo);
getSupportFragmentManager().beginTransaction().replace(R.id.empty_view, chatFragment).commitAllowingStateLoss();
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
chatFragment.getTitleBarLayout().getRightGroup().setVisibility(View.VISIBLE);
chatFragment.getInputView().setInterceptTouchEvent(true);
chatFragment.getInputView().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
TitleBarLayout titleBarLayout = chatFragment.getTitleBarLayout();
titleBarLayout.setTitle("哈哈哈", ITitleBarLayout.Position.MIDDLE);
}
}, 1000);
}
public TUIC2CChatFragment getChatFragment() {
return chatFragment;
}
@Override
......
......@@ -4,13 +4,17 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.Nullable;
import com.tencent.qcloud.tuicore.TUIConstants;
import com.tencent.qcloud.tuicore.TUICore;
import com.tencent.qcloud.tuicore.interfaces.TUIExtensionEventListener;
import com.tencent.qcloud.tuicore.interfaces.TUIExtensionInfo;
import com.tencent.qcloud.tuikit.timcommon.component.TitleBarLayout;
import com.tencent.qcloud.tuikit.tuichat.bean.C2CChatInfo;
import com.tencent.qcloud.tuikit.tuichat.bean.ChatInfo;
import com.tencent.qcloud.tuikit.tuichat.classicui.widget.input.InputView;
import com.tencent.qcloud.tuikit.tuichat.config.classicui.TUIChatConfigClassic;
import com.tencent.qcloud.tuikit.tuichat.presenter.C2CChatPresenter;
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatLog;
......@@ -42,6 +46,8 @@ public class TUIC2CChatFragment extends TUIBaseChatFragment {
initView();
TUIChatConfigClassic.hideItemsWhenLongPressMessage(TUIChatConfigClassic.SELECT);
return baseView;
}
......@@ -97,6 +103,15 @@ public class TUIC2CChatFragment extends TUIBaseChatFragment {
return (C2CChatInfo) chatInfo;
}
@Override
public TitleBarLayout getTitleBarLayout() {
return chatView.getTitleBar();
}
public InputView getInputView() {
return chatView.getInputView();
}
public void setChatInfo(C2CChatInfo c2CChatInfo) {
this.chatInfo = c2CChatInfo;
}
......
......@@ -10,6 +10,11 @@ import com.tencent.qcloud.tuikit.tuichat.util.TUIChatUtils;
public class TUIGroupChatActivity extends TUIBaseChatActivity {
private static final String TAG = TUIGroupChatActivity.class.getSimpleName();
@Override
protected int getContentViewLayoutID() {
return R.layout.chat_activity;
}
@Override
public void initChat(ChatInfo chatInfo) {
TUIChatLog.i(TAG, "inti chat " + chatInfo);
......
......@@ -4,7 +4,9 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.Nullable;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.qcloud.tuicore.TUIConstants;
import com.tencent.qcloud.tuicore.TUICore;
......@@ -12,14 +14,17 @@ import com.tencent.qcloud.tuicore.interfaces.TUIExtensionEventListener;
import com.tencent.qcloud.tuicore.interfaces.TUIExtensionInfo;
import com.tencent.qcloud.tuicore.interfaces.TUIValueCallback;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
import com.tencent.qcloud.tuikit.timcommon.component.TitleBarLayout;
import com.tencent.qcloud.tuikit.timcommon.interfaces.OnItemClickListener;
import com.tencent.qcloud.tuikit.tuichat.TUIChatConstants;
import com.tencent.qcloud.tuikit.tuichat.bean.C2CChatInfo;
import com.tencent.qcloud.tuikit.tuichat.bean.GroupChatInfo;
import com.tencent.qcloud.tuikit.tuichat.bean.message.MergeMessageBean;
import com.tencent.qcloud.tuikit.tuichat.classicui.widget.input.InputView;
import com.tencent.qcloud.tuikit.tuichat.presenter.GroupChatPresenter;
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatLog;
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -28,6 +33,7 @@ public class TUIGroupChatFragment extends TUIBaseChatFragment {
private static final String TAG = TUIGroupChatFragment.class.getSimpleName();
private final GroupChatPresenter presenter;
private TitleBarLayout titleBarLayout;
public TUIGroupChatFragment() {
presenter = new GroupChatPresenter();
......@@ -53,6 +59,7 @@ public class TUIGroupChatFragment extends TUIBaseChatFragment {
chatView.setPresenter(presenter);
presenter.setGroupInfo((GroupChatInfo) chatInfo);
chatView.setChatInfo(chatInfo);
titleBarLayout = chatView.getTitleBar();
presenter.getGroupType(chatInfo.getId(), new TUIValueCallback<String>() {
@Override
......@@ -122,6 +129,11 @@ public class TUIGroupChatFragment extends TUIBaseChatFragment {
return presenter;
}
@Override
public TitleBarLayout getTitleBarLayout() {
return titleBarLayout;
}
public GroupChatInfo getChatInfo() {
return ((GroupChatInfo) chatInfo);
}
......
......@@ -737,7 +737,6 @@ public class ChatView extends LinearLayout implements IChatLayout {
return mForwardMergeButton;
}
@Override
public InputView getInputLayout() {
return mInputView;
}
......@@ -766,6 +765,10 @@ public class ChatView extends LinearLayout implements IChatLayout {
return mTitleBar;
}
public InputView getInputView() {
return mInputView;
}
private void initListener() {
getMessageLayout().setPopActionClickListener(new OnChatPopActionClickListener() {
@Override
......
......@@ -23,6 +23,7 @@ import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.tencent.imsdk.v2.V2TIMManager;
......@@ -65,6 +66,7 @@ import com.tencent.qcloud.tuikit.tuichat.util.ChatMessageBuilder;
import com.tencent.qcloud.tuikit.tuichat.util.ChatMessageParser;
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatLog;
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
......@@ -73,7 +75,6 @@ import java.util.List;
import java.util.Map;
/**
*
* Chat interface, send pictures, take pictures, video, file panels at the bottom
*/
......@@ -87,21 +88,18 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
private static final int STATE_ACTION_INPUT = 3;
/**
*
* Voice/text switch input controls
*/
protected ImageView mAudioInputSwitchButton;
protected boolean mAudioInputDisable;
/**
*
* emoji button
*/
protected ImageView mEmojiInputButton;
protected boolean mEmojiInputDisable;
/**
*
* more button
*/
protected ImageView mMoreInputButton;
......@@ -109,24 +107,23 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
protected boolean mMoreInputDisable;
/**
*
* message send button
*/
protected TextView mSendTextButton;
/**
*
* voice send button
*/
protected Button mSendAudioButton;
/**
*
* input text
*/
protected TIMMentionEditText mTextInput;
private boolean mIsSending = false;
private boolean mIsIntercept = false;
protected FragmentActivity mActivity;
protected View mInputMoreView;
protected ChatInfo mChatInfo;
......@@ -310,7 +307,7 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
@Override
public void onMentionCharacterInput(String tag) {
if ((tag.equals(TIMMentionEditText.TIM_MENTION_TAG) || tag.equals(TIMMentionEditText.TIM_MENTION_TAG_FULL))
&& TUIChatUtils.isGroupChat(mChatLayout.getChatInfo().getType())) {
&& TUIChatUtils.isGroupChat(mChatLayout.getChatInfo().getType())) {
if (mOnInputViewListener != null) {
mOnInputViewListener.onStartGroupMemberSelectActivity();
}
......@@ -339,10 +336,14 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
}
ArrayList<String> nameList = new ArrayList<String>() {
{ add(name); }
{
add(name);
}
};
ArrayList<String> idList = new ArrayList<String>() {
{ add(id); }
{
add(id);
}
};
updateAtUserInfoMap(nameList, idList);
......@@ -540,7 +541,7 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
}
@Override
public void onProgress(Uri originalUri, int progress) {
public void onProgress(Uri originalUri, int progress) {
presenter.updateMessageProgress(originalUri, progress);
}
......@@ -624,7 +625,8 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
}
@Override
public void onError(int errorCode, String errorMessage) {}
public void onError(int errorCode, String errorMessage) {
}
});
}
......@@ -647,8 +649,8 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
@Override
public void onClick(View view) {
TUIChatLog.i(TAG,
"onClick id:" + view.getId() + "|voice_input_switch:" + R.id.voice_input_switch + "|face_btn:" + R.id.face_btn + "|more_btn:" + R.id.more_btn
+ "|send_btn:" + R.id.send_btn + "|mCurrentState:" + mCurrentState + "|mSendEnable:" + mSendEnable + "|mMoreInputEvent:" + mMoreInputEvent);
"onClick id:" + view.getId() + "|voice_input_switch:" + R.id.voice_input_switch + "|face_btn:" + R.id.face_btn + "|more_btn:" + R.id.more_btn
+ "|send_btn:" + R.id.send_btn + "|mCurrentState:" + mCurrentState + "|mSendEnable:" + mSendEnable + "|mMoreInputEvent:" + mMoreInputEvent);
if (view.getId() == R.id.voice_input_switch) {
if (mCurrentState == STATE_FACE_INPUT || mCurrentState == STATE_ACTION_INPUT) {
mCurrentState = STATE_VOICE_INPUT;
......@@ -910,7 +912,8 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
......@@ -1091,7 +1094,8 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
if (TUIChatConfigClassic.isShowInputBarCustom()
&& getChatInfo().isEnableCustomHelloMessage()
&& !excludeItems.contains(TUIChatConfigClassic.CUSTOM)) {
actionUnit = new InputMoreItem() {};
actionUnit = new InputMoreItem() {
};
actionUnit.setIconResId(R.drawable.custom);
actionUnit.setName(getResources().getString(R.string.test_custom_action));
actionUnit.setActionId(CustomHelloMessage.CUSTOM_HELLO_ACTION_ID);
......@@ -1146,18 +1150,18 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
param.put(TUIConstants.TUIChat.Extension.InputMore.FILTER_ROOM, true);
} else {
param.put(TUIConstants.TUIChat.Extension.InputMore.FILTER_VIDEO_CALL,
!TUIChatConfigClassic.isShowInputBarVideoCall() || !getChatInfo().isEnableVideoCall()
|| excludeItems.contains(TUIChatConfigClassic.VIDEO_CALL));
!TUIChatConfigClassic.isShowInputBarVideoCall() || !getChatInfo().isEnableVideoCall()
|| excludeItems.contains(TUIChatConfigClassic.VIDEO_CALL));
param.put(TUIConstants.TUIChat.Extension.InputMore.FILTER_VOICE_CALL,
!TUIChatConfigClassic.isShowInputBarAudioCall() || !getChatInfo().isEnableAudioCall()
|| excludeItems.contains(TUIChatConfigClassic.AUDIO_CALL));
!TUIChatConfigClassic.isShowInputBarAudioCall() || !getChatInfo().isEnableAudioCall()
|| excludeItems.contains(TUIChatConfigClassic.AUDIO_CALL));
param.put(TUIConstants.TUIChat.Extension.InputMore.FILTER_ROOM,
!TUIChatConfigClassic.isShowInputBarRoomKit() || !getChatInfo().isEnableRoom() || excludeItems.contains(TUIChatConfigClassic.ROOM_KIT));
!TUIChatConfigClassic.isShowInputBarRoomKit() || !getChatInfo().isEnableRoom() || excludeItems.contains(TUIChatConfigClassic.ROOM_KIT));
param.put(TUIConstants.TUIChat.Extension.InputMore.FILTER_GROUP_NOTE,
!TUIChatConfigClassic.isShowInputBarGroupNote() || !getChatInfo().isEnableGroupNote()
|| excludeItems.contains(TUIChatConfigClassic.GROUP_NOTE));
!TUIChatConfigClassic.isShowInputBarGroupNote() || !getChatInfo().isEnableGroupNote()
|| excludeItems.contains(TUIChatConfigClassic.GROUP_NOTE));
param.put(TUIConstants.TUIChat.Extension.InputMore.FILTER_POLL,
!TUIChatConfigClassic.isShowInputBarPoll() || !getChatInfo().isEnablePoll() || excludeItems.contains(TUIChatConfigClassic.POLL));
!TUIChatConfigClassic.isShowInputBarPoll() || !getChatInfo().isEnablePoll() || excludeItems.contains(TUIChatConfigClassic.POLL));
}
param.put(TUIConstants.TUIChat.Extension.InputMore.INPUT_MORE_LISTENER, chatInputMoreListener);
List<TUIExtensionInfo> extensionList = TUICore.getExtensionList(TUIConstants.TUIChat.Extension.InputMore.CLASSIC_EXTENSION_ID, param);
......@@ -1299,10 +1303,22 @@ public class InputView extends LinearLayout implements View.OnClickListener, Tex
return mChatInfo;
}
public void setInterceptTouchEvent(boolean isIntercept) {
this.mIsIntercept = isIntercept;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (mIsIntercept) return true;
return super.onInterceptTouchEvent(ev);
}
public interface MessageHandler {
void sendMessage(TUIMessageBean msg);
default void sendMessages(List<TUIMessageBean> messageBeans) {}
default void sendMessages(List<TUIMessageBean> messageBeans) {
}
void scrollToEnd();
}
......
package com.tencent.qcloud.tuikit.tuichat.presenter;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
import com.tencent.qcloud.tuikit.timcommon.bean.MessageFeature;
......@@ -108,9 +109,9 @@ public class C2CChatPresenter extends ChatPresenter {
}
/**
*
* pull message
* @param type Pull forward, backward, or both
*
* @param type Pull forward, backward, or both
* @param lastMessageInfo The starting point for pulling messages
*/
@Override
......@@ -121,7 +122,7 @@ public class C2CChatPresenter extends ChatPresenter {
isLoading = true;
String chatId = c2CChatInfo.getId();
// Pull older messages forward
if (type == TUIChatConstants.GET_MESSAGE_FORWARD) {
provider.loadC2CMessage(chatId, MSG_PAGE_COUNT, lastMessageInfo, new IUIKitCallback<Pair<List<TUIMessageBean>, Integer>>() {
......@@ -146,13 +147,13 @@ public class C2CChatPresenter extends ChatPresenter {
}
});
} else {
// Pull the updated message backward or pull the message forward and backward at the same time
loadHistoryMessageList(chatId, false, type, MSG_PAGE_COUNT, lastMessageInfo, callback);
}
}
// This method is called after the message is loaded successfully
@Override
protected void onMessageLoadCompleted(List<TUIMessageBean> data, int getType) {
......@@ -222,7 +223,8 @@ public class C2CChatPresenter extends ChatPresenter {
}
@Override
public void onError(String module, int errCode, String errMsg) {}
public void onError(String module, int errCode, String errMsg) {
}
});
}
......@@ -265,7 +267,7 @@ public class C2CChatPresenter extends ChatPresenter {
TUIChatUtils.callbackOnProgress(callBack, data);
}
});
TUIChatLog.i(TAG, "sendTypingStatusMessage msgID:" + msgId);
message.setId(msgId);
message.setStatus(TUIMessageBean.MSG_STATUS_SENDING);
......
......@@ -35,6 +35,8 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!--允许获取wifi状态改变,用于网络定位,若无gps但仍需实现定位小蓝点功能则此权限必选-->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<application
......@@ -251,11 +253,10 @@
android:screenOrientation="portrait" />
<activity
android:name=".ui.activitys.CustomChatActivity"
android:name=".ui.activitys.IMActivity"
android:exported="false"
android:screenOrientation="portrait" />
<service
android:name=".ui.service.UpdateService"
android:exported="true" />
......
......@@ -223,6 +223,11 @@ object GlideUtils {
//加载毛玻璃图片
fun loadBlurImageView(mContext: Context, url: String, imageView: ImageView) {
Glide.with(mContext).load(url)
.apply(
RequestOptions.bitmapTransform(
RoundedCorners(BubbleUtils.px2dp(10f))
)
) //圆角半径
.apply(RequestOptions.bitmapTransform(BlurTransformation(25, 4)))
.into(imageView)
}
......
package com.duben.roseplaylet.common;
import com.duben.roseplaylet.im.GenerateTestUserSig;
import com.duben.roseplaylet.manager.GenerateTestUserSig;
/**
* 描述:配置app设置开关
......@@ -34,10 +34,5 @@ public class AppConfig {
public static long splashTime = 0L;
public static double firstVipPrice = 0.0;
public static String IM_FLAVOR_VERSION = Constant.FLAVOR_LOCAL;
public static final int IM_UI_STYLE_CLASSIC = 0;
public static int IM_UI_STYLE = IM_UI_STYLE_CLASSIC;
public static int IM_SDK_APPID = GenerateTestUserSig.SDKAPPID;
}
......@@ -51,27 +51,8 @@ object Constant {
const val GRO_MORE_ADTYPE3 = "3"
const val GRO_MORE_ADTYPE4 = "4"
var mTabs = mutableListOf("城市不限", "20-60岁", "男士", "人气优先")
val mAges = listOf(
"20-60岁",
"18-22岁",
"23-26岁",
"27-30岁",
"31-34岁",
"35-38岁",
"39-42岁",
"43-46岁",
"47-50岁",
"51-54岁",
"55-58岁",
"59-62岁",
"63-64岁"
)
val mSexes = listOf("男士", "女士", "男同性", "女同性")
// val mConstellations = listOf("注册优先", "在线优先", "人气优先", "活跃优先", "照片优先", "最近距离")
val mConstellations = listOf("人气优先", "照片优先")
const val NEED_REQUEST_LOCATION = "need_request_location"
const val FIRST_LOCATION = "first_location"
const val FLAVOR_LOCAL = "local"
const val USERINFO = "userInfo"
......
package com.duben.roseplaylet.im;
import android.text.TextUtils;
import com.tencent.qcloud.tuicore.util.TUIBuild;
public class BrandUtil {
/**
* Xiaomi device
*/
public static boolean isBrandXiaoMi() {
return "xiaomi".equalsIgnoreCase(getBuildBrand()) || "xiaomi".equalsIgnoreCase(getBuildManufacturer());
}
/**
* oppo device
*
* @return
*/
public static boolean isBrandOppo() {
return "oppo".equalsIgnoreCase(getBuildBrand()) || "realme".equalsIgnoreCase(getBuildBrand()) || "oneplus".equalsIgnoreCase(getBuildBrand())
|| "oppo".equalsIgnoreCase(getBuildManufacturer()) || "realme".equalsIgnoreCase(getBuildManufacturer())
|| "oneplus".equalsIgnoreCase(getBuildManufacturer());
}
/**
* oppo device
*
* @return
*/
public static boolean isSamsungS9Series() {
return "samsung".equalsIgnoreCase(getBuildBrand())
&& (!TextUtils.isEmpty(getBuildModel()) && (getBuildModel().startsWith("SM-G965") || getBuildModel().startsWith("SM-G960")));
}
public static String getBuildBrand() {
return TUIBuild.getBrand();
}
public static String getBuildManufacturer() {
return TUIBuild.getManufacturer();
}
public static String getBuildModel() {
return TUIBuild.getModel();
}
public static String getBuildVersionRelease() {
return TUIBuild.getVersion();
}
public static int getBuildVersionSDKInt() {
return TUIBuild.getVersionInt();
}
}
package com.duben.roseplaylet.im;
import android.content.Context;
import com.tencent.qcloud.tuicore.TUIConfig;
import com.tencent.qcloud.tuicore.TUIThemeManager;
import com.tencent.qcloud.tuikit.tuichat.config.classicui.TUIChatConfigClassic;
import com.tencent.qcloud.tuikit.tuichat.config.minimalistui.TUIChatConfigMinimalist;
public class CustomConfigHelper {
private static Context mContext;
public static void initCustom(Context context) {
mContext = context;
initConversationDefaultAvatar();
initChatSettings();
}
public static void initConversationDefaultAvatar() {
TUIConfig.setEnableGroupGridAvatar(true);
TUIConfig.setDefaultAvatarImage(TUIThemeManager.getAttrResId(mContext, com.tencent.qcloud.tuikit.timcommon.R.attr.core_default_user_icon));
TUIConfig.setDefaultGroupAvatarImage(TUIThemeManager.getAttrResId(mContext, com.tencent.qcloud.tuikit.timcommon.R.attr.core_default_group_icon_work));
}
public static void initChatSettings() {
if (BrandUtil.isSamsungS9Series()) {
TUIChatConfigClassic.setUseSystemCamera(true);
TUIChatConfigMinimalist.setUseSystemCamera(true);
}
}
}
package com.duben.roseplaylet.im;
public interface HandleOfflinePushCallBack {
void onHandleOfflinePush(boolean hasLogged);
}
\ No newline at end of file
package com.duben.roseplaylet.im;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.text.TextUtils;
import android.util.Log;
import com.duben.roseplaylet.R;
import com.duben.roseplaylet.common.AppConfig;
import com.duben.roseplaylet.im.push.OfflinePushAPIDemo;
import com.duben.roseplaylet.im.push.OfflinePushConfigs;
import com.duben.roseplaylet.im.push.OfflinePushLocalReceiver;
import com.duben.roseplaylet.utils.LogUtil;
import com.tencent.imsdk.v2.V2TIMManager;
import com.tencent.imsdk.v2.V2TIMValueCallback;
import com.tencent.qcloud.tuicore.TUICore;
import com.tencent.qcloud.tuicore.TUIThemeManager;
import com.tencent.qcloud.tuicore.util.ErrorMessageConverter;
import com.tencent.qcloud.tuicore.util.PermissionRequester;
import com.tencent.qcloud.tuikit.tuichat.TUIChatConstants;
import com.tencent.qcloud.tuikit.tuichat.config.TUIChatConfigs;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class InitSetting {
private static final String TAG = InitSetting.class.getSimpleName();
public Context mContext;
private OfflinePushAPIDemo offlinePushAPIDemo;
private OfflinePushLocalReceiver offlinePushLocalReceiver = null;
public InitSetting(Context context) {
this.mContext = context;
}
public void init() {
// add Demo theme
// TUIThemeManager.addLightTheme(R.style.DemoLightTheme);
// TUIThemeManager.addLivelyTheme(R.style.DemoLivelyTheme);
// TUIThemeManager.addSeriousTheme(R.style.DemoSeriousTheme);
setPermissionRequestContent();
TUIChatConfigs.getGeneralConfig().setEnableMultiDeviceForCall(true);
TUIChatConfigs.getGeneralConfig().setEnableVirtualBackgroundForCall(true);
CustomConfigHelper.initCustom(mContext);
initOfflinePushConfigs();
initDemoStyle();
}
private void initDemoStyle() {
final SharedPreferences sharedPreferences = mContext.getSharedPreferences("TUIKIT_DEMO_SETTINGS", mContext.MODE_PRIVATE);
AppConfig.IM_UI_STYLE = sharedPreferences.getInt("tuikit_demo_style", AppConfig.IM_UI_STYLE_CLASSIC);
}
public void setPermissionRequestContent() {
if (mContext == null) {
return;
}
ApplicationInfo applicationInfo = mContext.getApplicationInfo();
CharSequence labelCharSequence = applicationInfo.loadLabel(mContext.getPackageManager());
String appName = "App";
if (!TextUtils.isEmpty(labelCharSequence)) {
appName = labelCharSequence.toString();
}
PermissionRequester.PermissionRequestContent microphoneContent = new PermissionRequester.PermissionRequestContent();
microphoneContent.setReasonTitle(mContext.getResources().getString(R.string.demo_permission_mic_reason_title, appName));
String micReason = mContext.getResources().getString(R.string.demo_permission_mic_reason);
microphoneContent.setReason(micReason);
microphoneContent.setIconResId(R.drawable.demo_permission_icon_mic);
String micDeniedAlert = mContext.getResources().getString(R.string.demo_permission_mic_dialog_alert, appName);
microphoneContent.setDeniedAlert(micDeniedAlert);
PermissionRequester.setPermissionRequestContent(PermissionRequester.PermissionConstants.MICROPHONE, microphoneContent);
PermissionRequester.PermissionRequestContent cameraContent = new PermissionRequester.PermissionRequestContent();
cameraContent.setReasonTitle(mContext.getResources().getString(R.string.demo_permission_camera_reason_title, appName));
String cameraReason = mContext.getResources().getString(R.string.demo_permission_camera_reason);
cameraContent.setReason(cameraReason);
cameraContent.setIconResId(R.drawable.demo_permission_icon_camera);
String cameraDeniedAlert = mContext.getResources().getString(R.string.demo_permission_camera_dialog_alert, appName);
cameraContent.setDeniedAlert(cameraDeniedAlert);
PermissionRequester.setPermissionRequestContent(PermissionRequester.PermissionConstants.CAMERA, cameraContent);
}
private void initOfflinePushConfigs() {
final SharedPreferences sharedPreferences = mContext.getSharedPreferences("TUIKIT_DEMO_SETTINGS", mContext.MODE_PRIVATE);
int callbackMode = sharedPreferences.getInt("test_OfflinePushCallbackMode_v2", 1);
Log.i(TAG, "initOfflinePushConfigs callbackMode = " + callbackMode);
OfflinePushConfigs.getOfflinePushConfigs().setClickNotificationCallbackMode(callbackMode);
// ring
boolean enablePrivateRing = sharedPreferences.getBoolean("test_enable_private_ring", false);
Map<String, Object> param = new HashMap<>();
param.put(TUIChatConstants.OFFLINE_MESSAGE_PRIVATE_RING, enablePrivateRing);
TUICore.notifyEvent(TUIChatConstants.EVENT_KEY_OFFLINE_MESSAGE_PRIVATE_RING, TUIChatConstants.EVENT_SUB_KEY_OFFLINE_MESSAGE_PRIVATE_RING, param);
// register callback
registerNotify();
}
// call after login success
public void registerPushManually() {
if (offlinePushAPIDemo == null) {
offlinePushAPIDemo = new OfflinePushAPIDemo();
}
offlinePushAPIDemo.registerPush(mContext);
}
// call in Application onCreate
private void registerNotify() {
if (offlinePushAPIDemo == null) {
offlinePushAPIDemo = new OfflinePushAPIDemo();
}
int callbackMode = OfflinePushConfigs.getOfflinePushConfigs().getClickNotificationCallbackMode();
Log.d(TAG, "OfflinePush callback mode:" + callbackMode);
switch (callbackMode) {
case OfflinePushConfigs.CLICK_NOTIFICATION_CALLBACK_NOTIFY:
// 1 TUICore NotifyEvent
offlinePushAPIDemo.registerNotifyEvent();
break;
case OfflinePushConfigs.CLICK_NOTIFICATION_CALLBACK_BROADCAST:
// 2 broadcast
if (offlinePushLocalReceiver == null) {
offlinePushLocalReceiver = new OfflinePushLocalReceiver();
}
offlinePushAPIDemo.registerNotificationReceiver(mContext, offlinePushLocalReceiver);
break;
default:
// 3 intent
break;
}
}
public void initBeforeLogin(int imsdkAppId) {
Log.d(TAG, "initBeforeLogin sdkAppid = " + imsdkAppId);
initBuildInformation();
int sdkAppId = 0;
if (imsdkAppId != 0) {
sdkAppId = imsdkAppId;
} else {
sdkAppId = GenerateTestUserSig.SDKAPPID;;
}
AppConfig.IM_SDK_APPID = sdkAppId;
}
private void initBuildInformation() {
try {
JSONObject buildInfoJson = new JSONObject();
buildInfoJson.put("buildBrand", BrandUtil.getBuildBrand());
buildInfoJson.put("buildManufacturer", BrandUtil.getBuildManufacturer());
buildInfoJson.put("buildModel", BrandUtil.getBuildModel());
buildInfoJson.put("buildVersionRelease", BrandUtil.getBuildVersionRelease());
buildInfoJson.put("buildVersionSDKInt", BrandUtil.getBuildVersionSDKInt());
// The Ministry of Industry and Information Technology requires the app to obtain device information only once
// during its operation. Therefore, after the app obtains the device information and sets it to the SDK, the SDK
// uses this value and no longer calls the system interface.
V2TIMManager.getInstance().callExperimentalAPI("setBuildInfo", buildInfoJson.toString(), new V2TIMValueCallback<Object>() {
@Override
public void onSuccess(Object o) {
LogUtil.i(TAG, "setBuildInfo success");
}
@Override
public void onError(int code, String desc) {
LogUtil.i(TAG, "setBuildInfo code:" + code + " desc:" + ErrorMessageConverter.convertIMError(code, desc));
}
});
} catch (JSONException e) {
e.printStackTrace();
}
}
}
package com.duben.roseplaylet.im;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.duben.roseplaylet.common.Constant;
import com.duben.roseplaylet.utils.LogUtil;
import com.google.auto.service.AutoService;
import com.tencent.qcloud.tuicore.ServiceInitializer;
import com.tencent.qcloud.tuicore.TUILogin;
import com.tencent.qcloud.tuicore.annotations.TUIInitializerDependency;
import com.tencent.qcloud.tuicore.annotations.TUIInitializerID;
import com.tencent.qcloud.tuicore.interfaces.ITUIService;
import com.tencent.qcloud.tuicore.interfaces.TUICallback;
import com.tencent.qcloud.tuicore.interfaces.TUIInitializer;
import com.tencent.qcloud.tuicore.interfaces.TUILoginListener;
@AutoService(TUIInitializer.class)
@TUIInitializerDependency("TIMCommon")
@TUIInitializerID("TIMAppService")
public class TIMAppService implements TUIInitializer, ITUIService {
public static final String TAG = TIMAppService.class.getSimpleName();
private static TIMAppService instance;
public static TIMAppService getInstance() {
return instance;
}
public Context mContext;
private BroadcastReceiver languageChangedReceiver;
private BroadcastReceiver themeChangedReceiver;
private InitSetting initSetting;
@Override
public void init(Context context) {
instance = this;
mContext = context;
initSetting = new InitSetting(mContext);
initSetting.init();
initThemeAndLanguageChangedReceiver();
initLoginStatusListener();
}
public void initLoginStatusListener() {
TUILogin.addLoginListener(loginStatusListener);
}
private final TUILoginListener loginStatusListener = new TUILoginListener() {
@Override
public void onKickedOffline() {
// ToastUtil.toastLongMessage(getAppContext().getString(R.string.repeat_login_tip));
logout();
}
@Override
public void onUserSigExpired() {
// ToastUtil.toastLongMessage(getAppContext().getString(R.string.expired_login_tip));
TUILogin.logout(new TUICallback() {
@Override
public void onSuccess() {
logout();
}
@Override
public void onError(int errorCode, String errorMessage) {
logout();
}
});
}
};
public void logout() {
LogUtil.i(TAG, "logout");
// UserInfo.getInstance().cleanUserInfo();
}
private void initThemeAndLanguageChangedReceiver() {
languageChangedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
initSetting.setPermissionRequestContent();
}
};
themeChangedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
CustomConfigHelper.initConversationDefaultAvatar();
}
};
IntentFilter languageFilter = new IntentFilter();
languageFilter.addAction(Constant.DEMO_LANGUAGE_CHANGED_ACTION);
LocalBroadcastManager.getInstance(mContext).registerReceiver(languageChangedReceiver, languageFilter);
IntentFilter themeFilter = new IntentFilter();
themeFilter.addAction(Constant.DEMO_THEME_CHANGED_ACTION);
LocalBroadcastManager.getInstance(mContext).registerReceiver(themeChangedReceiver, themeFilter);
}
public void registerPushManually() {
if (initSetting == null) {
initSetting = new InitSetting(mContext);
}
initSetting.registerPushManually();
}
public void initBeforeLogin(int sdkappid) {
if (initSetting == null) {
initSetting = new InitSetting(mContext);
}
initSetting.initBeforeLogin(sdkappid);
}
public static Context getAppContext() {
return ServiceInitializer.getAppContext();
}
}
package com.duben.roseplaylet.im;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import com.duben.roseplaylet.common.AppConfig;
import com.duben.roseplaylet.im.push.OfflineMessageDispatcher;
import com.duben.roseplaylet.utils.LogUtil;
import com.tencent.imsdk.v2.V2TIMConversation;
import com.tencent.imsdk.v2.V2TIMManager;
import com.tencent.qcloud.tuicore.TUIConfig;
import com.tencent.qcloud.tuicore.TUIConstants;
import com.tencent.qcloud.tuicore.TUICore;
import com.tencent.qcloud.tuicore.interfaces.TUILoginConfig;
import com.tencent.qcloud.tuicore.push.OfflinePushExtInfo;
import com.tencent.qcloud.tuicore.util.TUIBuild;
import com.tencent.qcloud.tuikit.timcommon.BuildConfig;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public class TUIUtils {
private static final String TAG = TUIUtils.class.getSimpleName();
public static String offlineData = null;
private static boolean hasTryToLogin = false;
public static void startActivity(String activityName, Bundle param) {
TUICore.startActivity(activityName, param);
}
public static void startChat(String chatId, String chatName, int chatType) {
Bundle bundle = new Bundle();
bundle.putString(TUIConstants.TUIChat.CHAT_ID, chatId);
bundle.putString(TUIConstants.TUIChat.CHAT_NAME, chatName);
bundle.putInt(TUIConstants.TUIChat.CHAT_TYPE, chatType);
if (AppConfig.IM_UI_STYLE == AppConfig.IM_UI_STYLE_CLASSIC) {
if (chatType == V2TIMConversation.V2TIM_C2C) {
TUICore.startActivity(TUIConstants.TUIChat.C2C_CHAT_ACTIVITY_NAME, bundle);
} else if (chatType == V2TIMConversation.V2TIM_GROUP) {
TUICore.startActivity(TUIConstants.TUIChat.GROUP_CHAT_ACTIVITY_NAME, bundle);
}
} else {
if (chatType == V2TIMConversation.V2TIM_C2C) {
TUICore.startActivity("TUIC2CChatMinimalistActivity", bundle);
} else if (chatType == V2TIMConversation.V2TIM_GROUP) {
TUICore.startActivity("TUIGroupChatMinimalistActivity", bundle);
}
}
}
public static boolean isZh(Context context) {
Locale locale = null;
if (TUIBuild.getVersionInt() < Build.VERSION_CODES.N) {
locale = context.getResources().getConfiguration().locale;
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
locale = context.getResources().getConfiguration().getLocales().get(0);
}
}
String language = locale.getLanguage();
return language.endsWith("zh");
}
public static int getCurrentVersionCode(Context context) {
try {
return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
} catch (PackageManager.NameNotFoundException ignored) {
LogUtil.e(TAG, "getCurrentVersionCode exception= " + ignored);
}
return 0;
}
public static void handleOfflinePush(Intent intent, HandleOfflinePushCallBack callBack) {
Context context = TIMAppService.getAppContext();
if (V2TIMManager.getInstance().getLoginStatus() == V2TIMManager.V2TIM_STATUS_LOGOUT) {
if (TUIConfig.getTUIHostType() == TUIConfig.TUI_HOST_TYPE_RTCUBE) {
LogUtil.e(TAG, "rtcube not logined");
Map<String, Object> param = new HashMap<>();
param.put(TUIConstants.TIMAppKit.OFFLINE_PUSH_INTENT_DATA, intent);
TUICore.notifyEvent(TUIConstants.TIMAppKit.NOTIFY_RTCUBE_EVENT_KEY, TUIConstants.TIMAppKit.NOTIFY_RTCUBE_LOGIN_SUB_KEY, param);
return;
}
Intent intentAction = new Intent();
intentAction.setAction("com.tencent.qloud.splash");
intentAction.addCategory("android.intent.category.LAUNCHER");
intentAction.addCategory("android.intent.category.DEFAULT");
if (intent != null) {
intentAction.putExtras(intent);
}
intentAction.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intentAction);
if (callBack != null) {
callBack.onHandleOfflinePush(false);
}
return;
}
final OfflinePushExtInfo offlinePushExtInfo = OfflineMessageDispatcher.parseOfflineMessage(intent);
if (offlinePushExtInfo != null) {
if (callBack != null) {
callBack.onHandleOfflinePush(true);
}
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (manager != null) {
manager.cancelAll();
}
String senderId = offlinePushExtInfo.getBusinessInfo().getSenderId();
if (offlinePushExtInfo.getBusinessInfo().getChatAction() == OfflinePushExtInfo.REDIRECT_ACTION_CHAT) {
if (TextUtils.isEmpty(senderId)) {
return;
}
TUIUtils.startChat(senderId, offlinePushExtInfo.getBusinessInfo().getSenderNickName(), offlinePushExtInfo.getBusinessInfo().getChatType());
}
}
}
public static void handleOfflinePush(String ext, HandleOfflinePushCallBack callBack) {
LogUtil.d(TAG, "handleOfflinePush ext = " + ext);
final OfflinePushExtInfo offlinePushExtInfo = OfflineMessageDispatcher.getOfflinePushExtInfo(ext);
if (offlinePushExtInfo == null) {
return;
}
Context context = TIMAppService.getAppContext();
if (V2TIMManager.getInstance().getLoginStatus() == V2TIMManager.V2TIM_STATUS_LOGOUT && !hasTryToLogin) {
hasTryToLogin = true;
if (TUIConfig.getTUIHostType() == TUIConfig.TUI_HOST_TYPE_RTCUBE) {
offlineData = ext;
TUICore.notifyEvent(TUIConstants.TIMAppKit.NOTIFY_RTCUBE_EVENT_KEY, TUIConstants.TIMAppKit.NOTIFY_RTCUBE_LOGIN_SUB_KEY, null);
return;
}
Intent intentAction = new Intent();
intentAction.setAction("com.tencent.qloud.splash");
intentAction.addCategory("android.intent.category.LAUNCHER");
intentAction.addCategory("android.intent.category.DEFAULT");
if (!TextUtils.isEmpty(ext)) {
intentAction.putExtra(TUIConstants.TIMPush.NOTIFICATION_EXT_KEY, ext);
}
intentAction.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intentAction);
if (callBack != null) {
callBack.onHandleOfflinePush(false);
}
return;
}
if (callBack != null) {
callBack.onHandleOfflinePush(true);
}
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (manager != null) {
manager.cancelAll();
}
String senderId = offlinePushExtInfo.getBusinessInfo().getSenderId();
if (offlinePushExtInfo.getBusinessInfo().getChatAction() == OfflinePushExtInfo.REDIRECT_ACTION_CHAT) {
if (TextUtils.isEmpty(senderId)) {
return;
}
TUIUtils.startChat(senderId, offlinePushExtInfo.getBusinessInfo().getSenderNickName(), offlinePushExtInfo.getBusinessInfo().getChatType());
}
}
public static TUILoginConfig getLoginConfig() {
TUILoginConfig config = new TUILoginConfig();
if (BuildConfig.DEBUG) {
config.setLogLevel(TUILoginConfig.TUI_LOG_DEBUG);
}
return config;
}
}
package com.duben.roseplaylet.im.activities;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.tencent.qcloud.tuicore.TUIThemeManager;
import com.tencent.qcloud.tuikit.timcommon.R;
public class BaseLightActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(
getResources().getColor(TUIThemeManager.getAttrResId(this, com.tencent.qcloud.tuicore.R.attr.core_header_start_color)));
getWindow().setNavigationBarColor(getResources().getColor(R.color.navigation_bar_color));
int vis = getWindow().getDecorView().getSystemUiVisibility();
vis |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
vis |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
getWindow().getDecorView().setSystemUiVisibility(vis);
}
}
@Override
public void finish() {
hideSoftInput();
super.finish();
}
public void hideSoftInput() {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
Window window = getWindow();
if (window != null) {
imm.hideSoftInputFromWindow(window.getDecorView().getWindowToken(), 0);
}
}
}
package com.duben.roseplaylet.im.activities;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import androidx.annotation.Nullable;
import com.tencent.imsdk.v2.V2TIMGroupAtInfo;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.qcloud.tuicore.TUIConstants;
import com.tencent.qcloud.tuicore.util.ToastUtil;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
import com.tencent.qcloud.tuikit.timcommon.component.activities.BaseLightActivity;
import com.tencent.qcloud.tuikit.tuichat.R;
import com.tencent.qcloud.tuikit.tuichat.bean.C2CChatInfo;
import com.tencent.qcloud.tuikit.tuichat.bean.ChatInfo;
import com.tencent.qcloud.tuikit.tuichat.bean.DraftInfo;
import com.tencent.qcloud.tuikit.tuichat.bean.GroupChatInfo;
import com.tencent.qcloud.tuikit.tuichat.util.ChatMessageBuilder;
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatLog;
import java.util.List;
public abstract class TUIBaseChatActivity extends BaseLightActivity {
private static final String TAG = TUIBaseChatActivity.class.getSimpleName();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
TUIChatLog.i(TAG, "onCreate " + this);
super.onCreate(savedInstanceState);
setContentView(R.layout.chat_activity);
initChat(getIntent());
}
@Override
protected void onNewIntent(Intent intent) {
TUIChatLog.i(TAG, "onNewIntent");
super.onNewIntent(intent);
initChat(intent);
}
@Override
protected void onResume() {
TUIChatLog.i(TAG, "onResume");
super.onResume();
}
private void initChat(Intent intent) {
Bundle bundle = intent.getExtras();
TUIChatLog.i(TAG, "bundle: " + bundle + " intent: " + intent);
ChatInfo chatInfo = getChatInfo(intent);
TUIChatLog.i(TAG, "start chatActivity chatInfo: " + chatInfo);
if (chatInfo != null) {
initChat(chatInfo);
} else {
ToastUtil.toastShortMessage("init chat failed , chatInfo is empty.");
TUIChatLog.e(TAG, "init chat failed , chatInfo is empty.");
finish();
}
}
public abstract void initChat(ChatInfo chatInfo);
private ChatInfo getChatInfo(Intent intent) {
int chatType = intent.getIntExtra(TUIConstants.TUIChat.CHAT_TYPE, ChatInfo.TYPE_INVALID);
ChatInfo chatInfo;
if (chatType == ChatInfo.TYPE_C2C) {
chatInfo = new C2CChatInfo();
} else if (chatType == ChatInfo.TYPE_GROUP) {
chatInfo = new GroupChatInfo();
} else {
return null;
}
chatInfo.setType(chatType);
chatInfo.setId(intent.getStringExtra(TUIConstants.TUIChat.CHAT_ID));
chatInfo.setChatName(intent.getStringExtra(TUIConstants.TUIChat.CHAT_NAME));
DraftInfo draftInfo = new DraftInfo();
draftInfo.setDraftText(intent.getStringExtra(TUIConstants.TUIChat.DRAFT_TEXT));
draftInfo.setDraftTime(intent.getLongExtra(TUIConstants.TUIChat.DRAFT_TIME, 0));
chatInfo.setDraft(draftInfo);
chatInfo.setTopChat(intent.getBooleanExtra(TUIConstants.TUIChat.IS_TOP_CHAT, false));
V2TIMMessage v2TIMMessage = (V2TIMMessage) intent.getSerializableExtra(TUIConstants.TUIChat.LOCATE_MESSAGE);
TUIMessageBean messageInfo = ChatMessageBuilder.buildMessage(v2TIMMessage);
chatInfo.setLocateMessage(messageInfo);
chatInfo.setAtInfoList((List<V2TIMGroupAtInfo>) intent.getSerializableExtra(TUIConstants.TUIChat.AT_INFO_LIST));
chatInfo.setFaceUrl(intent.getStringExtra(TUIConstants.TUIChat.FACE_URL));
chatInfo.setEnableAudioCall(intent.getBooleanExtra(TUIConstants.TUIChat.ENABLE_AUDIO_CALL, true));
chatInfo.setEnableVideoCall(intent.getBooleanExtra(TUIConstants.TUIChat.ENABLE_VIDEO_CALL, true));
chatInfo.setEnableRoom(intent.getBooleanExtra(TUIConstants.TUIChat.ENABLE_ROOM, true));
if (chatType == ChatInfo.TYPE_GROUP) {
GroupChatInfo groupChatInfo = (GroupChatInfo) chatInfo;
groupChatInfo.setGroupName(intent.getStringExtra(TUIConstants.TUIChat.GROUP_NAME));
groupChatInfo.setGroupType(intent.getStringExtra(TUIConstants.TUIChat.GROUP_TYPE));
groupChatInfo.setNotice(intent.getStringExtra(TUIConstants.TUIChat.NOTICE));
}
if (TextUtils.isEmpty(chatInfo.getId())) {
return null;
}
return chatInfo;
}
}
package com.duben.roseplaylet.im.activities;
import com.tencent.qcloud.tuicore.util.ToastUtil;
import com.tencent.qcloud.tuikit.tuichat.R;
import com.tencent.qcloud.tuikit.tuichat.bean.C2CChatInfo;
import com.tencent.qcloud.tuikit.tuichat.bean.ChatInfo;
import com.tencent.qcloud.tuikit.tuichat.classicui.page.TUIBaseChatActivity;
import com.tencent.qcloud.tuikit.tuichat.classicui.page.TUIC2CChatFragment;
import com.tencent.qcloud.tuikit.tuichat.presenter.C2CChatPresenter;
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatLog;
public class TUIC2CChatActivity extends TUIBaseChatActivity {
private static final String TAG = TUIC2CChatActivity.class.getSimpleName();
private TUIC2CChatFragment chatFragment;
@Override
public void initChat(ChatInfo chatInfo) {
TUIChatLog.i(TAG, "inti chat " + chatInfo);
if (!(chatInfo instanceof C2CChatInfo)) {
TUIChatLog.e(TAG, "init C2C chat failed , chatInfo = " + chatInfo);
ToastUtil.toastShortMessage("init c2c chat failed.");
return;
}
chatFragment = new TUIC2CChatFragment();
chatFragment.setChatInfo((C2CChatInfo) chatInfo);
getSupportFragmentManager().beginTransaction().replace(R.id.empty_view, chatFragment).commitAllowingStateLoss();
}
@Override
protected void onDestroy() {
C2CChatPresenter chatPresenter = null;
if (chatFragment != null) {
chatPresenter = chatFragment.getPresenter();
}
if (chatPresenter != null) {
chatPresenter.removeC2CChatEventListener();
}
super.onDestroy();
}
}
package com.duben.roseplaylet.im.push;
public interface HandleOfflinePushCallBack {
void onHandleOfflinePush(boolean hasLogged);
}
\ No newline at end of file
package com.duben.roseplaylet.im.push;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.text.TextUtils;
import com.duben.roseplaylet.R;
import com.duben.roseplaylet.im.BrandUtil;
import com.duben.roseplaylet.im.TIMAppService;
import com.duben.roseplaylet.utils.LogUtil;
import com.google.gson.Gson;
import com.tencent.qcloud.tuicore.push.OfflinePushExtBusinessInfo;
import com.tencent.qcloud.tuicore.push.OfflinePushExtInfo;
import com.tencent.qcloud.tuicore.util.ToastUtil;
import java.util.Map;
import java.util.Set;
public class OfflineMessageDispatcher {
private static final String TAG = OfflineMessageDispatcher.class.getSimpleName();
private static final String OEMMessageKey = "ext";
private static final String XIAOMIMessageKey = "key_message";
public static OfflinePushExtInfo parseOfflineMessage(Intent intent) {
LogUtil.i(TAG, "intent: " + intent);
if (intent == null) {
return null;
}
LogUtil.i(TAG, "parse OEM push");
Bundle bundle = intent.getExtras();
LogUtil.i(TAG, "bundle: " + bundle);
if (bundle == null) {
LogUtil.i(TAG, "bundle is null");
return null;
} else {
String ext = bundle.getString(OEMMessageKey);
LogUtil.i(TAG, "push custom data ext: " + ext);
if (TextUtils.isEmpty(ext)) {
if (BrandUtil.isBrandXiaoMi()) {
ext = getXiaomiMessage(bundle);
return getOfflinePushExtInfo(ext);
} else if (BrandUtil.isBrandOppo()) {
ext = getOPPOMessage(bundle);
return getOPPOOfflinePushExtInfo(ext);
}
LogUtil.i(TAG, "ext is null");
return null;
} else {
return getOfflinePushExtInfo(ext);
}
}
}
private static String getXiaomiMessage(Bundle bundle) {
Map extra = null;
try {
Object objectMessage = bundle.getSerializable(XIAOMIMessageKey);
extra = (Map) objectMessage.getClass().getMethod("getExtra").invoke(objectMessage);
} catch (Exception e) {
LogUtil.e(TAG, "getXiaomiMessage e = " + e);
}
if (extra == null) {
LogUtil.e(TAG, "getXiaomiMessage is null");
return "";
}
LogUtil.i(TAG, "getXiaomiMessage ext: " + extra.get("ext").toString());
return extra.get("ext").toString();
}
private static String getOPPOMessage(Bundle bundle) {
Set<String> set = bundle.keySet();
if (set != null) {
for (String key : set) {
Object value = bundle.get(key);
LogUtil.i(TAG, "push custom data key: " + key + " value: " + value);
if (TextUtils.equals("entity", key)) {
return value.toString();
}
}
}
return null;
}
public static OfflinePushExtInfo getOfflinePushExtInfo(String ext) {
if (TextUtils.isEmpty(ext)) {
return null;
}
OfflinePushExtInfo offlinePushExtInfo = null;
try {
offlinePushExtInfo = new Gson().fromJson(ext, OfflinePushExtInfo.class);
} catch (Exception e) {
LogUtil.w(TAG, "getOfflinePushExtInfo: " + e.getMessage());
}
if (offlinePushExtInfo == null) {
return null;
}
// getCustomData example
/*byte[] byteData = offlinePushExtInfo.getEntity().getCustomData();
String customString = "";
if (byteData != null && byteData.length > 0) {
try {
customString = new String(byteData, "UTF-8");
} catch (UnsupportedEncodingException e) {
LogUtil.w(TAG, "getCustomData e: " + e);
}
}
LogUtil.e(TAG, "customString = " + customString);
ChatInfo chatInfo = null;
try{
chatInfo = new Gson().fromJson(customString, ChatInfo.class);
} catch (Exception e) {
LogUtil.w(TAG, "getCustomData fromJson e: " + e);
}*/
return OfflinePushExtInfoValidCheck(offlinePushExtInfo);
}
private static OfflinePushExtInfo getOPPOOfflinePushExtInfo(String ext) {
if (TextUtils.isEmpty(ext)) {
return null;
}
OfflinePushExtInfo offlinePushExtInfo = new OfflinePushExtInfo();
OfflinePushExtBusinessInfo bean = null;
try {
bean = new Gson().fromJson(ext, OfflinePushExtBusinessInfo.class);
} catch (Exception e) {
LogUtil.w(TAG, "getOPPOOfflinePushExtInfo: " + e.getMessage());
}
if (bean == null) {
return null;
}
offlinePushExtInfo.setBusinessInfo(bean);
return OfflinePushExtInfoValidCheck(offlinePushExtInfo);
}
private static OfflinePushExtInfo OfflinePushExtInfoValidCheck(OfflinePushExtInfo offlinePushExtInfo) {
if (offlinePushExtInfo == null || offlinePushExtInfo.getBusinessInfo() == null) {
return null;
}
int version = offlinePushExtInfo.getBusinessInfo().getVersion();
int action = offlinePushExtInfo.getBusinessInfo().getChatAction();
if (version != 1 || (action != OfflinePushExtInfo.REDIRECT_ACTION_CHAT && action != OfflinePushExtInfo.REDIRECT_ACTION_CALL)) {
PackageManager packageManager = TIMAppService.getAppContext().getPackageManager();
String label = String.valueOf(packageManager.getApplicationLabel(TIMAppService.getAppContext().getApplicationInfo()));
ToastUtil.toastLongMessage(
TIMAppService.getAppContext().getString(R.string.app_name) + label + TIMAppService.getAppContext().getString(R.string.app_name));
LogUtil.e(TAG, "unknown version: " + version + " or action: " + action);
return null;
}
return offlinePushExtInfo;
}
}
package com.duben.roseplaylet.im.push;
import android.content.Context;
import android.content.IntentFilter;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.duben.roseplaylet.common.AppConfig;
import com.duben.roseplaylet.common.Constant;
import com.duben.roseplaylet.im.TUIUtils;
import com.duben.roseplaylet.utils.LogUtil;
import com.google.gson.Gson;
import com.tencent.qcloud.tuicore.TUIConstants;
import com.tencent.qcloud.tuicore.TUICore;
import com.tencent.qcloud.tuicore.interfaces.ITUINotification;
import com.tencent.qcloud.tuicore.interfaces.TUIServiceCallback;
import com.tencent.qcloud.tuikit.tuichat.util.OfflinePushInfoUtils;
import java.util.HashMap;
import java.util.Map;
public class OfflinePushAPIDemo {
public static final String TAG = OfflinePushAPIDemo.class.getSimpleName();
/**
* Register offline push service, called when IM account login is successful.Calling this interface does not require filling parameters into the
* component's PrivateConstants.
*
* @note json:
* {
* // huawei
* "huaweiPushBussinessId": "",
* "huaweiBadgeClassName": "",
* launcher interface
*
* // xiaomi
* "xiaomiPushBussinessId": "",
* "xiaomiPushAppId": "",
* "xiaomiPushAppKey": "",
*
* // meizu
* "meizuPushBussinessId": "",
* "meizuPushAppId": "",
* "meizuPushAppKey": "",
*
* // vivo
* "vivoPushBussinessId": "",
*
* // google
* "fcmPushBussinessId": "",
*
* // oppo
* "oppoPushBussinessId": "",
* "oppoPushAppKey": "",
* "oppoPushAppSecret": "",
*
* // honor
* "honorPushBussinessId": "",
* }
*
*/
public void registerPush(Context context) {
OfflinePushParamBean offlinePushParamBean = new OfflinePushParamBean();
String huaweiBussinessId, xiaomiBussinessId, meizuBussinessId, vivoBussinessId, oppoBussinessId;
String fcmBussinessId, honorBussinessId;
int callbackMode = OfflinePushConfigs.getOfflinePushConfigs().getClickNotificationCallbackMode();
Log.d(TAG, "OfflinePush callback mode:" + callbackMode);
if (callbackMode == OfflinePushConfigs.CLICK_NOTIFICATION_CALLBACK_NOTIFY ||
callbackMode == OfflinePushConfigs.CLICK_NOTIFICATION_CALLBACK_BROADCAST) {
if (TextUtils.equals(AppConfig.IM_FLAVOR_VERSION, Constant.FLAVOR_INTERNATIONAL)) {
huaweiBussinessId = "";
xiaomiBussinessId = "";
meizuBussinessId = "";
vivoBussinessId = "";
oppoBussinessId = "";
fcmBussinessId = "";
honorBussinessId = "";
} else {
huaweiBussinessId = "";
xiaomiBussinessId = "";
meizuBussinessId = "";
vivoBussinessId = "";
oppoBussinessId = "";
fcmBussinessId = "";
honorBussinessId = "";
}
} else {
if (TextUtils.equals(AppConfig.IM_FLAVOR_VERSION, Constant.FLAVOR_INTERNATIONAL)) {
huaweiBussinessId = "";
xiaomiBussinessId = "";
meizuBussinessId = "";
vivoBussinessId = "";
oppoBussinessId = "";
fcmBussinessId = "";
honorBussinessId = "";
} else {
huaweiBussinessId = "";
xiaomiBussinessId = "";
meizuBussinessId = "";
vivoBussinessId = "";
oppoBussinessId = "";
fcmBussinessId = "";
honorBussinessId = "";
}
}
offlinePushParamBean.setHuaweiPushBussinessId(huaweiBussinessId);
offlinePushParamBean.setHuaweiBadgeClassName("com.tencent.qcloud.tim.demo.SplashActivity");
offlinePushParamBean.setXiaomiPushBussinessId(xiaomiBussinessId);
offlinePushParamBean.setXiaomiPushAppId("");
offlinePushParamBean.setXiaomiPushAppKey("");
offlinePushParamBean.setMeizuPushBussinessId(meizuBussinessId);
offlinePushParamBean.setMeizuPushAppId("");
offlinePushParamBean.setMeizuPushAppKey("");
offlinePushParamBean.setVivoPushBussinessId(vivoBussinessId);
offlinePushParamBean.setFcmPushBussinessId(fcmBussinessId);
offlinePushParamBean.setFcmPushChannelId(OfflinePushInfoUtils.FCM_PUSH_CHANNEL_ID);
offlinePushParamBean.setFcmPushChannelSoundName(OfflinePushInfoUtils.PRIVATE_RING_NAME);
offlinePushParamBean.setOppoPushBussinessId(oppoBussinessId);
offlinePushParamBean.setOppoPushAppKey("");
offlinePushParamBean.setOppoPushAppSecret("");
offlinePushParamBean.setHonorPushBussinessId(honorBussinessId);
String jsonStr = new Gson().toJson(offlinePushParamBean);
if (TextUtils.isEmpty(jsonStr)) {
LogUtil.e(TAG, "registerPush json is null");
return;
}
LogUtil.d(TAG, "registerPush json = " + jsonStr);
Map<String, Object> param = new HashMap<>();
param.put(TUIConstants.TIMPush.SET_CUSTOM_CONFIG_JSON_KEY, jsonStr);
TUICore.callService(TUIConstants.TIMPush.SERVICE_NAME, TUIConstants.TIMPush.METHOD_SET_CUSTOM_CONFIG_JSON, param);
Map<String, Object> registerParam = new HashMap<>();
param.put(TUIConstants.TIMPush.CONTEXT, context);
TUICore.callService(TUIConstants.TIMPush.SERVICE_NAME, TUIConstants.TIMPush.METHOD_REGISTER_PUSH, registerParam, new TUIServiceCallback() {
@Override
public void onServiceCallback(int errorCode, String errorMessage, Bundle bundle) {
LogUtil.d(TAG, "registerPush errorCode = " + errorCode + ", errorMessage = " + errorMessage);
}
});
}
/**
* When the IM console sets the click follow-up action to "use push component callback to jump",After the push is successful, register NotifyEvent through
* TUICore, and click the notification bar event will be returned through the TUICore.onNotifyEvent callback.
*/
public void registerNotifyEvent() {
TUICore.registerEvent(TUIConstants.TIMPush.EVENT_NOTIFY, TUIConstants.TIMPush.EVENT_NOTIFY_NOTIFICATION, new ITUINotification() {
@Override
public void onNotifyEvent(String key, String subKey, Map<String, Object> param) {
Log.d(TAG, "onNotifyEvent key = " + key + "subKey = " + subKey);
if (TUIConstants.TIMPush.EVENT_NOTIFY.equals(key)) {
if (TUIConstants.TIMPush.EVENT_NOTIFY_NOTIFICATION.equals(subKey)) {
if (param != null) {
String extString = (String) param.get(TUIConstants.TIMPush.NOTIFICATION_EXT_KEY);
TUIUtils.handleOfflinePush(extString, null);
}
}
}
}
});
}
/**
* When the IM console sets the click follow-up action to "use push component callback to jump",After the push is successful, register the broadcast
* receiver, click the notification bar event to return by sending the broadcast callback. IntentFilter
* TUIConstants.TIMPush.NOTIFICATION_BROADCAST_ACTION.
*/
public void registerNotificationReceiver(Context context, OfflinePushLocalReceiver localReceiver) {
LogUtil.d(TAG, "registerNotificationReceiver ");
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(TUIConstants.TIMPush.NOTIFICATION_BROADCAST_ACTION);
intentFilter.addAction(TUIConstants.TIMPush.BROADCAST_IM_LOGIN_AFTER_APP_WAKEUP);
LocalBroadcastManager.getInstance(context).registerReceiver(localReceiver, intentFilter);
}
}
package com.duben.roseplaylet.im.push;
public class OfflinePushConfigs {
private static OfflinePushConfigs offlinePushConfigs;
public static final int REGISTER_PUSH_MODE_AUTO = 0;
public static final int REGISTER_PUSH_MODE_API = 1;
public static final int CLICK_NOTIFICATION_CALLBACK_INTENT = 0;
public static final int CLICK_NOTIFICATION_CALLBACK_NOTIFY = 1;
public static final int CLICK_NOTIFICATION_CALLBACK_BROADCAST = 2;
private int registerPushMode = 0;
private int clickNotificationCallbackMode = 0;
public static OfflinePushConfigs getOfflinePushConfigs() {
if (offlinePushConfigs == null) {
offlinePushConfigs = new OfflinePushConfigs();
}
return offlinePushConfigs;
}
/*
* Demo integrates two push registration methods to obtain the push service registration method that the application is using:
*
* REGISTER_PUSH_MODE_AUTO,After the component monitors the account login successfully, to register the push service automatically, you need to manually
* configure the push parameters to the PrivateConstants of the push component; REGISTER_PUSH_MODE_API,Manual registration of offline push service, called
* when the IM account is successfully logged in, see the interface description for push parameters;
*/
public int getRegisterPushMode() {
return registerPushMode;
}
public void setRegisterPushMode(int registerPushMode) {
this.registerPushMode = registerPushMode;
}
/*
* Demo integrates three ways to click the notification bar to jump to the interface to get the jumping method the application is using:
*
* CLICK_NOTIFICATION_CALLBACK_INTENT,Configure the jump parameters in the IM console according to the specifications, click the notification bar to jump
* to the configuration interface, parse the transparent transmission parameters and perform interface redirection; CLICK_NOTIFICATION_CALLBACK_NOTIFY,In
* the IM console configuration jump parameter, select "Use push component callback to jump", and click the notification bar event registration callback to
* receive; CLICK_NOTIFICATION_CALLBACK_BROADCAST,In the IM console configuration jump parameter, select "Use push component callback to jump", and click
* the notification bar event to register to receive the broadcast;
*/
public int getClickNotificationCallbackMode() {
return clickNotificationCallbackMode;
}
public void setClickNotificationCallbackMode(int clickNotificationCallbackMode) {
this.clickNotificationCallbackMode = clickNotificationCallbackMode;
}
}
package com.duben.roseplaylet.im.push;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import com.duben.roseplaylet.im.TUIUtils;
import com.duben.roseplaylet.utils.LogUtil;
import com.tencent.qcloud.tuicore.TUIConstants;
import java.util.HashMap;
import java.util.Map;
public class OfflinePushLocalReceiver extends BroadcastReceiver {
public static final String TAG = OfflinePushLocalReceiver.class.getSimpleName();
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "BROADCAST_PUSH_RECEIVER intent = " + intent);
if (intent != null) {
String action = intent.getAction();
if (TextUtils.equals(TUIConstants.TIMPush.NOTIFICATION_BROADCAST_ACTION, action)) {
String ext = intent.getStringExtra(TUIConstants.TIMPush.NOTIFICATION_EXT_KEY);
TUIUtils.handleOfflinePush(ext, null);
} else if (TextUtils.equals(TUIConstants.TIMPush.BROADCAST_IM_LOGIN_AFTER_APP_WAKEUP, action)) {
Bundle receivedBundle = intent.getExtras();
if (receivedBundle != null) {
Map<String, String> receivedMap = new HashMap<>();
for (String key : receivedBundle.keySet()) {
String value = receivedBundle.getString(key);
receivedMap.put(key, value);
Log.d(TAG, "key = " + key + ", value = " + value);
}
} else {
LogUtil.e(TAG, "receivedBundle is null");
}
}
} else {
LogUtil.e(TAG, "onReceive intent is null");
}
}
}
package com.duben.roseplaylet.im.push;
public class OfflinePushParamBean {
public String huaweiPushBussinessId, huaweiBadgeClassName;
public String xiaomiPushBussinessId, xiaomiPushAppId, xiaomiPushAppKey;
public String meizuPushBussinessId, meizuPushAppId, meizuPushAppKey;
public String vivoPushBussinessId;
public String fcmPushBussinessId;
public String oppoPushBussinessId, oppoPushAppKey, oppoPushAppSecret;
public String honorPushBussinessId;
public String fcmPushChannelId, fcmPushChannelSoundName;
// huawei
public String getHuaweiPushBussinessId() {
return huaweiPushBussinessId;
}
public void setHuaweiPushBussinessId(String huaweiPushBussinessId) {
this.huaweiPushBussinessId = huaweiPushBussinessId;
}
public String getHuaweiBadgeClassName() {
return huaweiBadgeClassName;
}
public void setHuaweiBadgeClassName(String huaweiBadgeClassName) {
this.huaweiBadgeClassName = huaweiBadgeClassName;
}
// xiaomi
public String getXiaomiPushBussinessId() {
return xiaomiPushBussinessId;
}
public void setXiaomiPushBussinessId(String xiaomiPushBussinessId) {
this.xiaomiPushBussinessId = xiaomiPushBussinessId;
}
public String getXiaomiPushAppId() {
return xiaomiPushAppId;
}
public void setXiaomiPushAppId(String xiaomiPushAppId) {
this.xiaomiPushAppId = xiaomiPushAppId;
}
public String getXiaomiPushAppKey() {
return xiaomiPushAppKey;
}
public void setXiaomiPushAppKey(String xiaomiPushAppKey) {
this.xiaomiPushAppKey = xiaomiPushAppKey;
}
// meizu
public String getMeizuPushBussinessId() {
return meizuPushBussinessId;
}
public void setMeizuPushBussinessId(String meizuPushBussinessId) {
this.meizuPushBussinessId = meizuPushBussinessId;
}
public String getMeizuPushAppId() {
return meizuPushAppId;
}
public void setMeizuPushAppId(String meizuPushAppId) {
this.meizuPushAppId = meizuPushAppId;
}
public String getMeizuPushAppKey() {
return meizuPushAppKey;
}
public void setMeizuPushAppKey(String meizuPushAppKey) {
this.meizuPushAppKey = meizuPushAppKey;
}
// vivo
public String getVivoPushBussinessId() {
return vivoPushBussinessId;
}
public void setVivoPushBussinessId(String vivoPushBussinessId) {
this.vivoPushBussinessId = vivoPushBussinessId;
}
// google
public String getFcmPushBussinessId() {
return fcmPushBussinessId;
}
public void setFcmPushBussinessId(String fcmPushBussinessId) {
this.fcmPushBussinessId = fcmPushBussinessId;
}
public String getFcmPushChannelId() {
return fcmPushChannelId;
}
public void setFcmPushChannelId(String fcmPushChannelId) {
this.fcmPushChannelId = fcmPushChannelId;
}
public String getFcmPushChannelSoundName() {
return fcmPushChannelSoundName;
}
public void setFcmPushChannelSoundName(String fcmPushChannelSoundName) {
this.fcmPushChannelSoundName = fcmPushChannelSoundName;
}
// oppo
public String getOppoPushAppKey() {
return oppoPushAppKey;
}
public void setOppoPushAppKey(String oppoPushAppKey) {
this.oppoPushAppKey = oppoPushAppKey;
}
public String getOppoPushAppSecret() {
return oppoPushAppSecret;
}
public void setOppoPushAppSecret(String oppoPushAppSecret) {
this.oppoPushAppSecret = oppoPushAppSecret;
}
public String getOppoPushBussinessId() {
return oppoPushBussinessId;
}
public void setOppoPushBussinessId(String oppoPushBussinessId) {
this.oppoPushBussinessId = oppoPushBussinessId;
}
// honor
public String getHonorPushBussinessId() {
return honorPushBussinessId;
}
public void setHonorPushBussinessId(String honorPushBussinessId) {
this.honorPushBussinessId = honorPushBussinessId;
}
}
......@@ -94,15 +94,20 @@ object CsjAppLogManager {
*/
override fun onAbVidsChange(s: String, s1: String) {}
})
//SDK会采集OAID、ANDROID_ID和其他的设备特征字段,请遵循相关合规要求在隐私弹窗后采集
//传入需要init的AppLog实例,若没有多个AppLog实例,则传入AppLog.getInstance()即可
BDConvert.getInstance().init(application, AppLog.getInstance())
// 如果在 onCreate 阶段初始化拿不到 XXXActivity 则不需要传递第三个参数
AppLog.init(application, config)
// 请在用户授权后调用如下方法,start 开始实际采集用户信息+上报:
AppLog.start()
// 在初始化后必须设置AppLog.setHeaderInfo("csj_attribution",1),否则会直接影响归因结果。
AppLog.setHeaderInfo("csj_attribution", 1)
try {
//SDK会采集OAID、ANDROID_ID和其他的设备特征字段,请遵循相关合规要求在隐私弹窗后采集
//传入需要init的AppLog实例,若没有多个AppLog实例,则传入AppLog.getInstance()即可
BDConvert.getInstance().init(application, AppLog.getInstance())
// 如果在 onCreate 阶段初始化拿不到 XXXActivity 则不需要传递第三个参数
AppLog.init(application, config)
// 请在用户授权后调用如下方法,start 开始实际采集用户信息+上报:
AppLog.start()
// 在初始化后必须设置AppLog.setHeaderInfo("csj_attribution",1),否则会直接影响归因结果。
AppLog.setHeaderInfo("csj_attribution", 1)
} catch (e: Exception) {
e.printStackTrace()
}
}
......
package com.duben.roseplaylet.im;
package com.duben.roseplaylet.manager;
import android.text.TextUtils;
import android.util.Base64;
......
package com.duben.roseplaylet.manager
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.LayoutInflater
import android.widget.TextView
import com.duben.roseplaylet.MintsApplication
import com.duben.roseplaylet.R
import com.duben.roseplaylet.mvp.model.WXInfo
import com.duben.roseplaylet.utils.ToastUtil
import com.duben.roseplaylet.utils.UcropUtils
import com.sunfusheng.marqueeview.MarqueeView
import com.tencent.qcloud.tuikit.timcommon.config.classicui.TUIConfigClassic
import com.tencent.qcloud.tuikit.tuichat.config.classicui.TUIChatConfigClassic
import com.tencent.qcloud.tuikit.tuiconversation.config.classicui.TUIConversationConfigClassic
/**
* @author Assen
* @date 2025/1/12
* @desc
*/
class IMHelper private constructor() {
init {
customSet()
}
companion object {
val instance: IMHelper by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
IMHelper()
}
}
fun customSet() {
//隐藏更多菜单中选项(全局)
TUIChatConfigClassic.hideItemsInMoreMenu(
TUIChatConfigClassic.CUSTOM
)
//设置会话列表、cell 背景色
// TUIConversationConfigClassic.setListBackground(ColorDrawable(0xFFFFFFF0.toInt()))
// TUIConversationConfigClassic.setCellBackground(ColorDrawable(0xFFF0FFF0.toInt()))
// TUIConversationConfigClassic.setPinnedCellBackground(ColorDrawable(0xFFE1FFFF.toInt()))
//展示在线状态
TUIConversationConfigClassic.setShowUserOnlineStatusIcon(true)
//开启消息已读回执
TUIChatConfigClassic.setMessageReadReceiptNeeded(true)
//设置系统通知消息文字的字体、颜色和背景色,针对所有系统通知消息生效
TUIChatConfigClassic.setSystemMessageTextColor(Color.WHITE)
TUIChatConfigClassic.setSystemMessageFontSize(23)
TUIChatConfigClassic.setSystemMessageBackground(
ColorDrawable(MintsApplication.getContext().resources.getColor(R.color.color_07060C))
)
// 聊天界面背景色
TUIChatConfigClassic.setBackground(
ColorDrawable(MintsApplication.getContext().resources.getColor(R.color.color_07060C))
)
TUIConfigClassic.setSendBubbleBackground(
MintsApplication.getContext().resources.getDrawable(R.drawable.shape_bg_market)
)
TUIConfigClassic.setReceiveBubbleBackground(
MintsApplication.getContext().resources.getDrawable(R.drawable.shape_bg_market)
)
TUIChatConfigClassic.setSendTextMessageColor(Color.WHITE)
TUIChatConfigClassic.setReceiveTextMessageColor(Color.BLACK)
}
fun setCustomTopView(wxInfo: WXInfo?) {
val tipsView = LayoutInflater.from(MintsApplication.getContext())
.inflate(R.layout.custom_tips_view, null)
val marqueeView = tipsView.findViewById<MarqueeView<*>>(R.id.marqueeView)
val message = "请勿轻易通过第三方账户进行红包、转账、借"
marqueeView.startWithText(message)
marqueeView.startWithText(
message,
com.sunfusheng.marqueeview.R.anim.anim_left_in,
com.sunfusheng.marqueeview.R.anim.anim_left_out
)
val tvWxNo = tipsView.findViewById<TextView>(R.id.tv_wx_no)
val tvCopy = tipsView.findViewById<TextView>(R.id.tv_copy)
val tvSend = tipsView.findViewById<TextView>(R.id.tv_send)
tvCopy.setOnClickListener {
ToastUtil.show(MintsApplication.getContext(), "微信已复制到剪切板!")
UcropUtils.clipData(tvWxNo.text.toString())
}
tvSend.setOnClickListener {
}
TUIChatConfigClassic.setCustomTopView(tipsView)
}
}
\ No newline at end of file
package com.duben.roseplaylet.im;
package com.duben.roseplaylet.manager;
import android.content.Context;
import android.text.TextUtils;
import com.duben.roseplaylet.MintsApplication;
import com.duben.roseplaylet.common.AppConfig;
import com.duben.roseplaylet.manager.UserManager;
import com.duben.roseplaylet.utils.LogUtil;
import com.tencent.imsdk.BaseConstants;
import com.tencent.imsdk.v2.V2TIMConversationListener;
......@@ -13,6 +13,7 @@ import com.tencent.imsdk.v2.V2TIMSDKListener;
import com.tencent.qcloud.tuicore.TUILogin;
import com.tencent.qcloud.tuicore.interfaces.TUICallback;
import com.tencent.qcloud.tuicore.interfaces.TUILoginConfig;
import com.tencent.qcloud.tuikit.timcommon.BuildConfig;
import com.tencent.qcloud.tuikit.timcommon.util.ThreadUtils;
import java.util.ArrayList;
......@@ -137,6 +138,9 @@ public class LoginWrapper {
UserManager.getInstance().setLastImLoginCode(BaseConstants.ERR_SUCC);
}
setIMSetting();
if (tuiCallback != null) {
tuiCallback.onSuccess();
}
......@@ -149,12 +153,11 @@ public class LoginWrapper {
UserManager userInfo = UserManager.getInstance();
int lastLoginCode = userInfo.getLastImLoginCode();
// if (loginStatus == V2TIMManager.V2TIM_STATUS_LOGOUT && !TextUtils.isEmpty(userInfo.getUserID()) && userInfo.isAutoLogin()) {
if (loginStatus == V2TIMManager.V2TIM_STATUS_LOGOUT && !TextUtils.isEmpty(userInfo.getUserID())) {
if (lastLoginCode >= BaseConstants.ERR_SDK_NET_ENCODE_FAILED && lastLoginCode <= BaseConstants.ERR_SDK_NET_SEND_REMAINING_TIMEOUT_NO_NETWORK) {
LogUtil.i(TAG, "onConnectSuccess, login IMSDK");
loginIMSDK(TIMAppService.getAppContext(), AppConfig.IM_SDK_APPID, userInfo.getUserID(),
GenerateTestUserSig.genTestUserSig(userInfo.getUserID()), TUIUtils.getLoginConfig(),
loginIMSDK(MintsApplication.getContext(), AppConfig.IM_SDK_APPID, userInfo.getUserID(),
GenerateTestUserSig.genTestUserSig(userInfo.getUserID()), getLoginConfig(),
new TUICallback() {
@Override
public void onSuccess() {
......@@ -197,4 +200,16 @@ public class LoginWrapper {
public void onSyncServerFailed() {
}
}
private void setIMSetting() {
IMHelper.Companion.getInstance().setCustomTopView(null);
}
public static TUILoginConfig getLoginConfig() {
TUILoginConfig config = new TUILoginConfig();
if (BuildConfig.DEBUG) {
config.setLogLevel(TUILoginConfig.TUI_LOG_DEBUG);
}
return config;
}
}
package com.duben.roseplaylet.manager;
import com.duben.roseplaylet.MintsApplication;
import com.duben.roseplaylet.common.AppConfig;
import com.duben.roseplaylet.im.LoginWrapper;
import com.duben.roseplaylet.im.TIMAppService;
import com.duben.roseplaylet.im.TUIUtils;
import com.duben.roseplaylet.mvp.model.VedioBean;
import com.duben.roseplaylet.mvp.presenters.TrackPresenter;
import com.duben.roseplaylet.utils.LogUtil;
import com.tencent.qcloud.tuicore.interfaces.TUICallback;
import com.tencent.qcloud.tuicore.interfaces.TUILoginConfig;
import com.tencent.qcloud.tuicore.util.ToastUtil;
import java.util.HashMap;
......
......@@ -8,10 +8,6 @@ import com.duben.library.net.neterror.Throwable;
import com.duben.roseplaylet.MintsApplication;
import com.duben.roseplaylet.common.AppConfig;
import com.duben.roseplaylet.common.DeviceInfo;
import com.duben.roseplaylet.im.GenerateTestUserSig;
import com.duben.roseplaylet.im.LoginWrapper;
import com.duben.roseplaylet.im.TIMAppService;
import com.duben.roseplaylet.im.TUIUtils;
import com.duben.roseplaylet.manager.AppHttpManager;
import com.duben.roseplaylet.manager.UserManager;
import com.duben.roseplaylet.mvp.model.BaseResponse;
......@@ -48,32 +44,12 @@ public class TrackPresenter extends BaseTrackPresenter {
UserManager.getInstance().saveUserInfo(baseResponse.getData());
// firstShowVedio();
saveTerminalInfo();
initUserLocalData();
}
}
}
});
}
private void initUserLocalData() {
UserManager instance = UserManager.getInstance();
TUILoginConfig tuiLoginConfig = TUIUtils.getLoginConfig();
tuiLoginConfig.setInitLocalStorageOnly(true);
LoginWrapper.getInstance().loginIMSDK(MintsApplication.getContext(), AppConfig.IM_SDK_APPID, instance.getUserID(),
GenerateTestUserSig.genTestUserSig(instance.getUserID()), tuiLoginConfig, new TUICallback() {
@Override
public void onSuccess() {
LogUtil.d("AAAAAAAAAAA onSuccess");
TIMAppService.getInstance().registerPushManually();
}
@Override
public void onError(final int errorCode, final String errorMessage) {
LogUtil.e("LoginWrapper ", "imLogin errorCode = " + errorCode + ", errorInfo = " + errorMessage);
}
});
}
public void getMyInfo() {
HashMap<String, Object> vo = new HashMap<>();
vo.put("os", "android");
......
package com.duben.roseplaylet.ui.activitys
import android.os.Bundle
import android.view.View
import com.duben.library.utils.nodoubleclick.AntiShake
import com.duben.roseplaylet.R
import com.duben.roseplaylet.ui.activitys.base.BaseActivity
import com.tencent.qcloud.tuikit.tuichat.bean.C2CChatInfo
import com.tencent.qcloud.tuikit.tuichat.classicui.page.TUIC2CChatFragment
class CustomChatActivity : BaseActivity(), View.OnClickListener {
companion object {
const val CHAT_ID = "chat-id"
}
private var chatID: String = ""
override fun getBundleExtras(extras: Bundle?) {
super.getBundleExtras(extras)
extras?.let {
chatID = it.getString(CHAT_ID, "")
}
}
override fun getContentViewLayoutID() = R.layout.activity_custom_chat
override fun isApplyKitKatTranslucency() = false
override fun initViewsAndEvents() {
initListener()
initChatFragment()
}
private fun initChatFragment() {
val c2cChatInfo = C2CChatInfo()
c2cChatInfo.id = chatID
val tuic2CChatFragment = TUIC2CChatFragment()
tuic2CChatFragment.chatInfo = c2cChatInfo
supportFragmentManager.beginTransaction()
.add(R.id.chat_fragment_container, tuic2CChatFragment).commitAllowingStateLoss();
}
override fun onClick(v: View?) {
if (AntiShake.check(v?.id)) return
when (v?.id) {
R.id.iv_left_icon -> finish()
}
}
private fun initListener() {
}
}
package com.duben.roseplaylet.ui.activitys
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import com.duben.roseplaylet.MintsApplication
import com.duben.roseplaylet.R
import com.duben.roseplaylet.utils.ToastUtil
import com.gyf.barlibrary.ImmersionBar
import com.tencent.qcloud.tuikit.timcommon.component.interfaces.ITitleBarLayout
import com.tencent.qcloud.tuikit.tuichat.bean.C2CChatInfo
import com.tencent.qcloud.tuikit.tuichat.bean.ChatInfo
import com.tencent.qcloud.tuikit.tuichat.classicui.page.TUIBaseChatActivity
import com.tencent.qcloud.tuikit.tuichat.classicui.page.TUIC2CChatFragment
import com.tencent.qcloud.tuikit.tuichat.presenter.C2CChatPresenter
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatLog
/**
* @author Assen
* @date 2025/1/12
* @desc
*/
class IMActivity : TUIBaseChatActivity() {
companion object {
private val TAG = IMActivity::class.java.simpleName
}
private lateinit var chatFragment: TUIC2CChatFragment
override fun onCreate(savedInstanceState: Bundle?) {
ImmersionBar.with(this).statusBarDarkFont(false, 0.5f).init()
super.onCreate(savedInstanceState)
}
override fun initChat(chatInfo: ChatInfo) {
TUIChatLog.i(TAG, "inti chat $chatInfo")
if (chatInfo !is C2CChatInfo) {
TUIChatLog.e(TAG, "init C2C chat failed , chatInfo = $chatInfo")
ToastUtil.show(MintsApplication.getContext(), "init c2c chat failed.")
return
}
chatFragment = TUIC2CChatFragment()
chatFragment.chatInfo = chatInfo
supportFragmentManager.beginTransaction()
.replace(R.id.chat_fragment_container, chatFragment)
.commitAllowingStateLoss()
initChatSetting()
}
private fun initChatSetting() {
Handler(Looper.getMainLooper()).postDelayed({
// chatFragment.titleBarLayout.rightGroup.visibility = View.VISIBLE
chatFragment.inputView.setInterceptTouchEvent(true)
chatFragment.inputView.setBackgroundColor(
resources.getColor(R.color.color_171619)
)
chatFragment.inputView.setOnClickListener {
}
val titleBarLayout = chatFragment.titleBarLayout
// titleBarLayout.setBackgroundColor(
// resources.getColor(R.color.color_15141A)
// )
titleBarLayout.setTitle("哈哈哈", ITitleBarLayout.Position.MIDDLE)
titleBarLayout.setRightIcon(R.mipmap.ic_alipay)
titleBarLayout.rightGroup.setOnClickListener {
ToastUtil.show(MintsApplication.getContext(), "OOOOOOO")
}
}, 100)
}
override fun onDestroy() {
val chatPresenter: C2CChatPresenter? = chatFragment.presenter
chatPresenter?.removeC2CChatEventListener()
super.onDestroy()
}
override fun getContentViewLayoutID(): Int {
return R.layout.activity_im
}
}
\ No newline at end of file
......@@ -7,8 +7,6 @@ import android.net.Uri
import android.os.Bundle
import android.view.KeyEvent
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction
import com.duben.roseplaylet.R
......@@ -18,6 +16,7 @@ import com.duben.roseplaylet.ui.activitys.base.BaseActivity
import com.duben.roseplaylet.ui.fragment.*
import com.duben.roseplaylet.ui.widgets.DialogListener
import com.duben.roseplaylet.ui.widgets.PhoneDialog
import kotlinx.android.synthetic.main.activity_main.*
/**
* 描述:首页
......@@ -28,22 +27,13 @@ class MainActivity : BaseActivity(), View.OnClickListener {
private var audioManager: AudioManager? = null
private var tabTvVideo: TextView? = null
private var tabTvSquare: TextView? = null
private var tabTvInvite: TextView? = null
private var tabTvMsg: TextView? = null
private var tabTvMy: TextView? = null
// 底部标签切换的Fragment
private var firstFragment: Fragment? = null
private var videoFragment: Fragment? = null
private var squareFragment: Fragment? = null
private var inviteFragment: Fragment? = null
private var msgFragment: Fragment? = null
private var myFragment: Fragment? = null
private var vipEnjoyFragment: Fragment? = null
private var currentFragment: Fragment? = null
private var phoneDialog: PhoneDialog? = null
......@@ -54,31 +44,25 @@ class MainActivity : BaseActivity(), View.OnClickListener {
override fun initViewsAndEvents() {
audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
tabTvVideo = findViewById(R.id.tab_tv_video)
tabTvSquare = findViewById(R.id.tab_tv_square)
tabTvInvite = findViewById(R.id.tab_tv_invite)
tabTvMsg = findViewById(R.id.tab_tv_msg)
tabTvMy = findViewById(R.id.tab_tv_my)
findViewById<View>(R.id.tab_rl_video).setOnClickListener(this)
findViewById<View>(R.id.tab_rl_square).setOnClickListener(this)
findViewById<View>(R.id.tab_rl_invite).setOnClickListener(this)
findViewById<View>(R.id.tab_rl_msg).setOnClickListener(this)
findViewById<View>(R.id.tab_rl_my).setOnClickListener(this)
tab_rl_video.setOnClickListener(this)
tab_rl_square.setOnClickListener(this)
tab_rl_invite.setOnClickListener(this)
tab_rl_msg.setOnClickListener(this)
tab_rl_my.setOnClickListener(this)
AppConfig.fragmentClickFlag = Constant.FRAGMENT_CLICK_ONE
if (firstFragment == null) {
firstFragment = FirstFragment()
if (videoFragment == null) {
videoFragment = FirstFragment()
}
if (!firstFragment!!.isAdded) {
if (!videoFragment!!.isAdded) {
// 提交事务
supportFragmentManager.beginTransaction()
.add(R.id.content_layout, firstFragment!!).commitAllowingStateLoss()
.add(R.id.content_layout, videoFragment!!).commitAllowingStateLoss()
// 记录当前Fragment
currentFragment = firstFragment
currentFragment = videoFragment
}
tabTvVideo?.isSelected = true
tab_iv_video.isSelected = true
tab_tv_video.isSelected = true
}
override fun isApplyKitKatTranslucency(): Boolean {
......@@ -145,15 +129,20 @@ class MainActivity : BaseActivity(), View.OnClickListener {
*/
fun clickTab1Layout() {
AppConfig.fragmentClickFlag = Constant.FRAGMENT_CLICK_ONE
if (firstFragment == null) {
firstFragment = FirstFragment()
if (videoFragment == null) {
videoFragment = FirstFragment()
}
addOrShowFragment(supportFragmentManager.beginTransaction(), firstFragment!!)
tabTvVideo?.isSelected = true
tabTvSquare?.isSelected = false
tabTvInvite?.isSelected = false
tabTvMsg?.isSelected = false
tabTvMy?.isSelected = false
addOrShowFragment(supportFragmentManager.beginTransaction(), videoFragment!!)
tab_iv_video.isSelected = true
tab_tv_video.isSelected = true
tab_iv_square.isSelected = false
tab_tv_square.isSelected = false
tab_iv_invite.isSelected = false
tab_tv_invite.isSelected = false
tab_iv_msg.isSelected = false
tab_tv_msg.isSelected = false
tab_iv_my.isSelected = false
tab_tv_my.isSelected = false
}
/**
......@@ -165,11 +154,16 @@ class MainActivity : BaseActivity(), View.OnClickListener {
squareFragment = SquareFragment()
}
addOrShowFragment(supportFragmentManager.beginTransaction(), squareFragment!!)
tabTvVideo?.isSelected = false
tabTvSquare?.isSelected = true
tabTvInvite?.isSelected = false
tabTvMsg?.isSelected = false
tabTvMy?.isSelected = false
tab_iv_video.isSelected = false
tab_tv_video.isSelected = false
tab_iv_square.isSelected = true
tab_tv_square.isSelected = true
tab_iv_invite.isSelected = false
tab_tv_invite.isSelected = false
tab_iv_msg.isSelected = false
tab_tv_msg.isSelected = false
tab_iv_my.isSelected = false
tab_tv_my.isSelected = false
}
/**
......@@ -181,11 +175,16 @@ class MainActivity : BaseActivity(), View.OnClickListener {
inviteFragment = InviteFragment()
}
addOrShowFragment(supportFragmentManager.beginTransaction(), inviteFragment!!)
tabTvVideo?.isSelected = false
tabTvSquare?.isSelected = false
tabTvInvite?.isSelected = true
tabTvMsg?.isSelected = false
tabTvMy?.isSelected = false
tab_iv_video.isSelected = false
tab_tv_video.isSelected = false
tab_iv_square.isSelected = false
tab_tv_square.isSelected = false
tab_iv_invite.isSelected = true
tab_tv_invite.isSelected = true
tab_iv_msg.isSelected = false
tab_tv_msg.isSelected = false
tab_iv_my.isSelected = false
tab_tv_my.isSelected = false
}
/**
......@@ -197,11 +196,16 @@ class MainActivity : BaseActivity(), View.OnClickListener {
msgFragment = MessageFragment()
}
addOrShowFragment(supportFragmentManager.beginTransaction(), msgFragment!!)
tabTvVideo?.isSelected = false
tabTvSquare?.isSelected = false
tabTvInvite?.isSelected = false
tabTvMsg?.isSelected = true
tabTvMy?.isSelected = false
tab_iv_video.isSelected = false
tab_tv_video.isSelected = false
tab_iv_square.isSelected = false
tab_tv_square.isSelected = false
tab_iv_invite.isSelected = false
tab_tv_invite.isSelected = false
tab_iv_msg.isSelected = true
tab_tv_msg.isSelected = true
tab_iv_my.isSelected = false
tab_tv_my.isSelected = false
}
/**
......@@ -213,11 +217,16 @@ class MainActivity : BaseActivity(), View.OnClickListener {
myFragment = MyFragment()
}
addOrShowFragment(supportFragmentManager.beginTransaction(), myFragment!!)
tabTvVideo?.isSelected = false
tabTvSquare?.isSelected = false
tabTvInvite?.isSelected = false
tabTvMsg?.isSelected = false
tabTvMy?.isSelected = true
tab_iv_video.isSelected = false
tab_tv_video.isSelected = false
tab_iv_square.isSelected = false
tab_tv_square.isSelected = false
tab_iv_invite.isSelected = false
tab_tv_invite.isSelected = false
tab_iv_msg.isSelected = false
tab_tv_msg.isSelected = false
tab_iv_my.isSelected = true
tab_tv_my.isSelected = true
}
/**
......
......@@ -6,13 +6,9 @@ import android.view.KeyEvent
import android.view.View
import com.duben.roseplaylet.R
import com.duben.roseplaylet.ad.splash.SplashManager
import com.duben.roseplaylet.common.AppConfig
import com.duben.roseplaylet.common.Constant
import com.duben.roseplaylet.common.Constant.PRIVACY_URL
import com.duben.roseplaylet.common.Constant.REGISTER_URL
import com.duben.roseplaylet.im.LoginWrapper
import com.duben.roseplaylet.im.TIMAppService
import com.duben.roseplaylet.im.TUIUtils
import com.duben.roseplaylet.manager.TrackManager
import com.duben.roseplaylet.ui.activitys.base.BaseActivity
import com.duben.roseplaylet.ui.widgets.CycleProgress
......@@ -23,9 +19,6 @@ import com.duben.roseplaylet.ui.widgets.countdowntimer.CountDownTimerSupport
import com.duben.roseplaylet.ui.widgets.countdowntimer.OnCountDownTimerListener
import com.duben.roseplaylet.utils.AppPreferencesManager.get
import com.duben.roseplaylet.utils.LogUtil
import com.tencent.qcloud.tuicore.interfaces.TUICallback
import com.tencent.qcloud.tuicore.interfaces.TUILoginConfig
import com.tencent.qcloud.tuicore.util.ToastUtil
import java.util.*
/**
......
......@@ -47,7 +47,8 @@ public abstract class BaseActivity extends BaseAppCompatActivity implements Base
try {
if (TextUtils.equals(getClass().getSimpleName(), "SplashActivity") ||
TextUtils.equals(getClass().getSimpleName(), "GuideActivity")) {
TextUtils.equals(getClass().getSimpleName(), "GuideActivity")
) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else if (TextUtils.equals(getClass().getSimpleName(), "VideoActivity")) {
......
package com.duben.roseplaylet.ui.adapter
import android.content.Intent
import android.widget.ImageView
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.duben.library.utils.GlideUtils
import com.duben.roseplaylet.R
import com.duben.roseplaylet.mvp.model.VedioBean
import com.duben.roseplaylet.ui.activitys.UserInfoActivity
......@@ -12,12 +12,15 @@ import com.duben.roseplaylet.ui.activitys.UserInfoActivity
class SquareAdapter : BaseQuickAdapter<VedioBean, BaseViewHolder>(R.layout.item_square) {
override fun convert(holder: BaseViewHolder, item: VedioBean) {
holder.getView<ImageView>(R.id.iv_recommend_header)
holder.getView<TextView>(R.id.tv_recommend_name).text = item.title
holder.getView<TextView>(R.id.tv_recommend_name).text = item.title
holder.getView<TextView>(R.id.tv_recommend_location).text
GlideUtils.loadBlurImageView(
holder.itemView.context,
"",
holder.getView(R.id.iv_recommend_header)
)
holder.itemView.setOnClickListener {
val intent = Intent(it.context, UserInfoActivity::class.java)
......
......@@ -11,10 +11,8 @@ import com.duben.roseplaylet.ad.express.ExpressAdCallback
import com.duben.roseplaylet.ad.express.MyExpressManager
import com.duben.roseplaylet.common.AppConfig
import com.duben.roseplaylet.common.Constant
import com.duben.roseplaylet.im.GenerateTestUserSig
import com.duben.roseplaylet.im.LoginWrapper
import com.duben.roseplaylet.im.TIMAppService
import com.duben.roseplaylet.im.TUIUtils
import com.duben.roseplaylet.manager.GenerateTestUserSig
import com.duben.roseplaylet.manager.LoginWrapper
import com.duben.roseplaylet.manager.UserManager
import com.duben.roseplaylet.mvp.model.UserBean
import com.duben.roseplaylet.mvp.presenters.MyPresenter
......@@ -28,8 +26,6 @@ import com.duben.roseplaylet.utils.UIUtils
import com.tencent.imsdk.v2.V2TIMConversation
import com.tencent.qcloud.tuicore.TUIConstants
import com.tencent.qcloud.tuicore.interfaces.TUICallback
import com.tencent.qcloud.tuikit.tuichat.classicui.ClassicUIService
import com.tencent.qcloud.tuikit.tuichat.classicui.page.TUIC2CChatActivity
import kotlinx.android.synthetic.main.fragment_main_my.*
/**
......@@ -88,7 +84,7 @@ class MyFragment : LazyLoadBaseFragment(), MyView, View.OnClickListener {
}
private fun startChatActivity() {
val intent = Intent(ClassicUIService.getAppContext(), TUIC2CChatActivity::class.java)
val intent = Intent(MintsApplication.getContext(), IMActivity::class.java)
intent.putExtra(TUIConstants.TUIChat.CHAT_TYPE, V2TIMConversation.V2TIM_C2C)
intent.putExtra(TUIConstants.TUIChat.CHAT_ID, userManager.userID)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
......@@ -97,16 +93,16 @@ class MyFragment : LazyLoadBaseFragment(), MyView, View.OnClickListener {
private fun initUserLocalData() {
val instance = UserManager.getInstance()
val tuiLoginConfig = TUIUtils.getLoginConfig()
val tuiLoginConfig = LoginWrapper.getLoginConfig()
tuiLoginConfig.isInitLocalStorageOnly = true
val userID = instance.userID
val userSig = GenerateTestUserSig.genTestUserSig(instance.userID)
val userSig = GenerateTestUserSig.genTestUserSig(userID)
LoginWrapper.getInstance().loginIMSDK(MintsApplication.getContext(),
AppConfig.IM_SDK_APPID, userID, userSig, tuiLoginConfig, object : TUICallback() {
override fun onSuccess() {
LogUtil.i("LoginWrapper ", "imLogin onSuccess")
TIMAppService.getInstance().registerPushManually()
startChatActivity()
}
override fun onError(errorCode: Int, errorMessage: String) {
......@@ -126,7 +122,6 @@ class MyFragment : LazyLoadBaseFragment(), MyView, View.OnClickListener {
// if (!userManager.vipFlag) {
// readyGo(VipActivity::class.java)
// }
initUserLocalData()
}
R.id.ll_my_setting -> {
// readyGo(SettingsActivity::class.java)
......@@ -147,7 +142,8 @@ class MyFragment : LazyLoadBaseFragment(), MyView, View.OnClickListener {
}
R.id.ll_contactus -> {
// (requireActivity() as MainActivity).backPhoneDialog()
startChatActivity()
initUserLocalData()
}
R.id.ll_my_payrecord -> {
readyGo(OrderRecordActivity::class.java)
......
package com.duben.roseplaylet.ui.fragment
import android.Manifest
import android.os.Build
import android.os.Handler
import android.os.Looper
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.widget.ViewPager2
import com.amap.api.location.AMapLocationClient
import com.amap.api.location.AMapLocationClientOption
import com.amap.api.location.AMapLocationListener
import com.amap.api.maps.MapsInitializer
import com.duben.library.utils.nodoubleclick.AntiShake
import com.duben.roseplaylet.MintsApplication
import com.duben.roseplaylet.R
import com.duben.roseplaylet.common.AppConfig
import com.duben.roseplaylet.common.Constant
......@@ -14,22 +24,36 @@ import com.duben.roseplaylet.mvp.presenters.SquarePresenter
import com.duben.roseplaylet.mvp.views.SquareView
import com.duben.roseplaylet.ui.adapter.*
import com.duben.roseplaylet.ui.fragment.base.LazyLoadBaseFragment
import com.duben.roseplaylet.utils.AppPreferencesManager
import com.duben.roseplaylet.utils.LogUtil
import com.duben.roseplaylet.utils.PermissionXUtils
import com.duben.roseplaylet.utils.SpanUtils
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import kotlinx.android.synthetic.main.fragment_square.*
import java.lang.reflect.Field
class SquareFragment : LazyLoadBaseFragment(), SquareView {
class SquareFragment : LazyLoadBaseFragment(), SquareView, View.OnClickListener {
//声明AMapLocationClient类对象
private var mLocationClient: AMapLocationClient? = null
private var mLocationOption: AMapLocationClientOption? = null
private var isFirstLocation = false
private var haveLocationPermission = false
private val squarePresenter by lazy { SquarePresenter() }
private val bannerList = mutableListOf<BannerBean>()
private val tabsData = mutableListOf<String>()
private var vpAdapter: SquarePageAdapter? = null
override fun getContentViewLayoutID() = R.layout.fragment_square
override fun initViewsAndEvents() {
initVp()
initLocation()
tv_location.setOnClickListener(this)
}
override fun onFragmentFirstVisible() {
......@@ -47,11 +71,15 @@ class SquareFragment : LazyLoadBaseFragment(), SquareView {
override fun onDestroy() {
super.onDestroy()
mLocationClient?.stopLocation()
mLocationClient?.onDestroy()
mLocationClient = null
squarePresenter.detachView()
}
private fun initVp() {
tabsData.addAll(arrayOf("活跃", "附近", "新人"))
tabsData.addAll(arrayOf("附近", "推荐", "新人"))
vpAdapter = SquarePageAdapter(tabsData, this)
vp2.adapter = vpAdapter
......@@ -60,39 +88,51 @@ class SquareFragment : LazyLoadBaseFragment(), SquareView {
// 初始化Tab
tab.id = position
if (tabsData.size > 0) {
tab.customView = getTabView(tabsData[position])
if (position == 0) {
tab.customView = getTabView(tabsData[position], true)
} else {
tab.customView = getTabView(tabsData[position], false)
}
}
}.attach()
tablayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab?) {
updateTab(tab, true)
// MainFragment.mSelectTabIndex = tab!!.id
tab?.let {
updateTab(it.customView, true)
showLocationTx()
}
}
override fun onTabUnselected(tab: TabLayout.Tab?) {
updateTab(tab, false)
tab?.let {
updateTab(it.customView, false)
}
}
override fun onTabReselected(tab: TabLayout.Tab?) {}
})
tablayout.getTabAt(0)?.select()
vp2.offscreenPageLimit = 100
}
private fun updateTab(tab: TabLayout.Tab?, isSelected: Boolean) {
tab?.customView?.let {
private fun updateTab(view: View?, isSelected: Boolean) {
view?.let {
val text = it.findViewById<TextView>(R.id.item_tv)
val bar = it.findViewById<View>(R.id.view_bar)
if (isSelected) {
text.setTextColor(ContextCompat.getColor(requireContext(), R.color.red))
text.setTextColor(ContextCompat.getColor(requireContext(), R.color.color_E4C46C))
bar.visibility = View.VISIBLE
} else {
text.setTextColor(ContextCompat.getColor(requireContext(), R.color.color_8D8F90))
text.setTextColor(ContextCompat.getColor(requireContext(), R.color.color_959595))
bar.visibility = View.INVISIBLE
}
}
}
private fun getTabView(text: String): View {
val view = LayoutInflater.from(requireContext()).inflate(R.layout.item_video_tab, null)
private fun getTabView(text: String, isSelected: Boolean): View {
val view = LayoutInflater.from(requireContext()).inflate(R.layout.item_square_tab, null)
view.findViewById<TextView>(R.id.item_tv).text = text
updateTab(view, isSelected)
return view
}
......@@ -118,21 +158,134 @@ class SquareFragment : LazyLoadBaseFragment(), SquareView {
}
}
override fun getHallListSuc(list: BannerList) {
private fun initLocation() {
val permissions: List<String> = if (Build.VERSION.SDK_INT >= 29) {
listOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_BACKGROUND_LOCATION
)
} else {
listOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
)
}
if (PermissionXUtils.checkLocationPermission(requireContext(), permissions)) {
haveLocationPermission = true
startLocation()
} else {
haveLocationPermission = false
requestPermissions()
tv_location.text = SpanUtils()
.append("未开启")
.setForegroundColor(ContextCompat.getColor(requireContext(), R.color.color_959595))
.append(" 定位服务 ")
.setForegroundColor(ContextCompat.getColor(requireContext(), R.color.color_E5C565))
.append("无法计算你与其他用户的距离")
.setForegroundColor(ContextCompat.getColor(requireContext(), R.color.color_959595))
.create()
showLocationTx()
}
}
override fun getHallListFail() {
private fun showLocationTx() {
if (haveLocationPermission) {
tv_location.visibility = View.GONE
} else {
tv_location.visibility = View.VISIBLE
}
}
override fun autoListSuc(data: BannerList) {
private fun requestPermissions() {
PermissionXUtils.requestLocationPermission(
this, object : PermissionXUtils.Callback {
override fun success() {
haveLocationPermission = true
showLocationTx()
AppPreferencesManager.get().put(Constant.FIRST_LOCATION, false)
AppPreferencesManager.get().put(Constant.NEED_REQUEST_LOCATION, true)
// 首次定位提示
if (!isFirstLocation) {
isFirstLocation = true
Handler(Looper.getMainLooper()).postDelayed({
showToast("正在开启定位...")
}, 300)
}
startLocation()
}
override fun fail() {
haveLocationPermission = false
// showMissingPermissionDialog("位置")
AppPreferencesManager.get().put(Constant.NEED_REQUEST_LOCATION, false)
}
}
)
}
override fun autoListFail() {
private fun startLocation() {
// 高德地图合规设定
MapsInitializer.updatePrivacyShow(context, true, true)
MapsInitializer.updatePrivacyAgree(context, true)
mLocationClient = AMapLocationClient(MintsApplication.getContext())
mLocationOption = AMapLocationClientOption()
mLocationOption?.let {
// 设置定位模式为高精度模式
it.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy
//只定位一次
it.isOnceLocation = false
// 设置是否需要显示地址信息
it.isNeedAddress = true
/**
* 设置是否优先返回GPS定位结果,如果30秒内GPS没有返回定位结果则进行网络定位
* 注意:只有在高精度模式下的单次定位有效,其他方式无效
*/
it.isGpsFirst = true
// 设置是否开启缓存
it.isLocationCacheEnable = true
// 设置发送定位请求的时间间隔,最小值为1000,如果小于1000,按照1000算
it.interval = 1000
}
mLocationClient?.let {
// 设置定位监听
it.setLocationListener(mapLocationListener)
it.setLocationOption(mLocationOption)
it.startLocation()
}
}
private val mapLocationListener = AMapLocationListener { loc ->
if (loc != null && loc.errorCode == 0) {
// app全局使用
val curLongitude = loc.longitude
val curLatitude = loc.latitude
val poiName = loc.poiName
LogUtil.d("AAAAAA ------> curLongitude${curLongitude} curLatitude${curLatitude} poiName${poiName}")
mLocationClient?.stopLocation()
}
}
override fun getHallListSuc(list: BannerList) {
}
override fun getHallListFail() {
}
override fun autoListSuc(data: BannerList) {}
override fun autoListFail() {}
fun ViewPager2.desensitization() {
//动态设置ViewPager2 灵敏度
try {
......@@ -146,4 +299,14 @@ class SquareFragment : LazyLoadBaseFragment(), SquareView {
} catch (ignore: java.lang.Exception) {
}
}
override fun onClick(v: View?) {
if (AntiShake.check(v?.id)) return
when (v?.id) {
R.id.tv_location -> {
requestPermissions()
}
}
}
}
\ No newline at end of file
......@@ -113,8 +113,6 @@ class SquareListFragment : LazyLoadBaseFragment(), SquareView, OnLoadMoreListene
override fun autoListFail() {}
override fun topTabsSuc(data: BannerList?) {}
override fun getHallListSuc(list: BannerList) {
}
override fun getHallListSuc(list: BannerList) {}
override fun getHallListFail() {}
}
\ No newline at end of file
package com.duben.roseplaylet.ui.widgets
import android.app.Dialog
import android.content.Context
import android.content.Intent
import android.view.Gravity
import android.view.KeyEvent
import android.view.View
import android.view.WindowManager
import android.widget.ImageView
import com.duben.roseplaylet.R
import com.duben.roseplaylet.ui.activitys.RealAuthActivity
class RealAuthDialog(private val context: Context) : Dialog(
context, R.style.dialog
) {
private val lp: WindowManager.LayoutParams
private val iv_phone_dialog_quit: ImageView
private val iv_auth: ImageView
init {
setContentView(R.layout.dialog_real_auth)
// 设置window属性
lp = window!!.attributes
lp.gravity = Gravity.CENTER
lp.width = WindowManager.LayoutParams.MATCH_PARENT
lp.windowAnimations = R.style.DialogAnimFade
window!!.attributes = lp
// 设置外部不可关闭
setCancelable(false)
setCanceledOnTouchOutside(false)
setOnKeyListener { dialogInterface, i, keyEvent ->
i == KeyEvent.KEYCODE_BACK
}
// 查找View
iv_phone_dialog_quit = findViewById<View>(R.id.iv_phone_dialog_quit) as ImageView
iv_auth = findViewById<View>(R.id.iv_auth) as ImageView
iv_phone_dialog_quit.setOnClickListener {
dismiss()
}
iv_auth.setOnClickListener {
val intent = Intent(context, RealAuthActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
dismiss()
}
}
}
\ No newline at end of file
package com.duben.roseplaylet.utils
import android.Manifest
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import com.permissionx.guolindev.PermissionX
object PermissionXUtils {
/**
* 位置权限
*/
fun requestLocationPermission(
ctx: Fragment,
callback: Callback
) {
val permissions: List<String> = if (Build.VERSION.SDK_INT >= 29) {
listOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_BACKGROUND_LOCATION
)
} else {
listOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
)
}
if (checkLocationPermission(
ctx.requireContext(),
arrayListOf(Manifest.permission.ACCESS_FINE_LOCATION)
)
) {
callback.success()
return
}
PermissionX.init(ctx)
.permissions(permissions)
.request { allGranted, grantedList, deniedList ->
if (allGranted) {
callback.success()
} else {
if (grantedList.contains(Manifest.permission.ACCESS_FINE_LOCATION))
callback.success()
else
callback.fail()
}
}
}
fun checkPermission2(
ctx: Fragment,
permissions: List<String>,
callback: Callback
) {
PermissionX.init(ctx)
.permissions(permissions)
.request { allGranted, _, _ ->
if (allGranted) {
callback.success()
} else {
if (checkLocationPermission(ctx.requireContext(), permissions))
callback.success()
else
callback.fail()
}
}
}
fun checkLocationPermission(ctx: Context, permissions: List<String>): Boolean {
//是否是定位权限判断
var isLocation = false
var failCount = 0
for (perm in permissions) {
if (Manifest.permission.ACCESS_BACKGROUND_LOCATION == perm) {
isLocation = true
}
if (ContextCompat.checkSelfPermission(
ctx,
perm
) !== PackageManager.PERMISSION_GRANTED
) {
++failCount
}
}
return if (isLocation) {
//定位权限的判断
//当点击仅在使用中允许 或 全部允许 失败数量为1 , 0 但是这两种是都可以成功定位的
failCount <= 1
} else {
//没有安卓10的定位权限
failCount == 0
}
}
interface Callback {
fun success()
fun fail()
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/black" android:state_selected="true" />
<item android:color="@color/graya" android:state_selected="false" />
<item android:color="#E5C565" android:state_selected="true" />
<item android:color="#8E8E8E" android:state_selected="false" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@mipmap/ic_tab_home_selected" android:state_selected="true" />
<item android:drawable="@mipmap/ic_tab_home_unselected" android:state_selected="false" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 填充的颜色 -->
<solid android:color="@color/color_0F0913" />
<!-- 设置按钮的四个角为弧形 -->
<!-- android:radius 弧形的半径 -->
<corners android:radius="5dip" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 填充的颜色 -->
<solid android:color="@color/color_4C4B51" />
<!-- 设置按钮的四个角为弧形 -->
<!-- android:radius 弧形的半径 -->
<corners android:radius="50dip" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 填充的颜色 -->
<solid android:color="@color/color_FDEEC8" />
<!-- 设置按钮的四个角为弧形 -->
<!-- android:radius 弧形的半径 -->
<corners android:radius="10dip" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 填充的颜色 -->
<solid android:color="@color/color_232122" />
<!-- 设置按钮的四个角为弧形 -->
<!-- android:radius 弧形的半径 -->
<corners android:radius="10dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="180"
android:endColor="#FE49B6"
android:startColor="#DD6470" />
<corners
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 填充的颜色 -->
<solid android:color="@color/color_E4C46C" />
<!-- 设置按钮的四个角为弧形 -->
<!-- android:radius 弧形的半径 -->
<corners android:radius="30dip" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
<FrameLayout
android:id="@+id/chat_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
......@@ -23,7 +23,7 @@
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_alignParentBottom="true"
android:background="@color/white"
android:background="@color/black"
android:elevation="2dp"
android:gravity="center_vertical"
android:orientation="horizontal">
......@@ -36,6 +36,14 @@
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/tab_iv_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:contentDescription="@null"
android:src="@drawable/selector_tab_home" />
<TextView
android:id="@+id/tab_tv_video"
android:layout_width="wrap_content"
......@@ -54,6 +62,14 @@
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/tab_iv_square"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:contentDescription="@null"
android:src="@drawable/selector_tab_home" />
<TextView
android:id="@+id/tab_tv_square"
android:layout_width="wrap_content"
......@@ -72,6 +88,14 @@
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/tab_iv_invite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:contentDescription="@null"
android:src="@drawable/selector_tab_home" />
<TextView
android:id="@+id/tab_tv_invite"
android:layout_width="wrap_content"
......@@ -90,6 +114,14 @@
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/tab_iv_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:contentDescription="@null"
android:src="@drawable/selector_tab_home" />
<TextView
android:id="@+id/tab_tv_msg"
android:layout_width="wrap_content"
......@@ -108,6 +140,14 @@
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/tab_iv_my"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:contentDescription="@null"
android:src="@drawable/selector_tab_home" />
<TextView
android:id="@+id/tab_tv_my"
android:layout_width="wrap_content"
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.sunfusheng.marqueeview.MarqueeView
android:id="@+id/marqueeView"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="@color/color_48484C"
app:mvAnimDuration="1000"
app:mvDirection="bottom_to_top"
app:mvInterval="3000"
app:mvSingleLine="true"
app:mvTextColor="@color/color_F9F9F9"
app:mvTextSize="14sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/shape_chat_tips"
android:elevation="2dp"
android:paddingStart="20dp"
android:paddingTop="10dp"
android:paddingEnd="10dp"
android:paddingBottom="10dp">
<ImageView
android:id="@+id/iv_wx"
android:layout_width="26dp"
android:layout_height="26dp"
android:src="@mipmap/ic_call_wx" />
<TextView
android:id="@+id/tv_wx_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/iv_wx"
android:layout_alignBottom="@id/iv_wx"
android:layout_marginStart="10dp"
android:layout_toEndOf="@id/iv_wx"
android:gravity="center_vertical"
android:text="33343434"
android:textColor="@color/black"
android:textSize="18sp" />
<TextView
android:id="@+id/tv_wx_info"
android:layout_width="wrap_content"
android:layout_height="26dp"
android:layout_alignTop="@id/tv_send"
android:layout_alignBottom="@id/tv_send"
android:gravity="center_vertical"
android:src="@mipmap/ic_call_wx"
android:text="微信仅保留24小时"
android:textColor="@color/black"
android:textSize="16sp" />
<TextView
android:id="@+id/tv_copy"
android:layout_width="110dp"
android:layout_height="28dp"
android:layout_alignParentEnd="true"
android:background="@drawable/shape_chat_black"
android:gravity="center"
android:text="复制"
android:textColor="@color/color_FDEEC8" />
<TextView
android:id="@+id/tv_send"
android:layout_width="110dp"
android:layout_height="28dp"
android:layout_below="@id/tv_copy"
android:layout_alignParentEnd="true"
android:layout_marginTop="5dp"
android:background="@drawable/shape_chat_black"
android:gravity="center"
android:text="发送微信给TA"
android:textColor="@color/color_FDEEC8" />
</RelativeLayout>
<TextView
android:id="@+id/tv_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:background="@drawable/shape_chat_gray"
android:gravity="center"
android:paddingStart="15dp"
android:paddingTop="5dp"
android:paddingEnd="15dp"
android:paddingBottom="5dp"
android:text="她已通过(真人认证),验证是本人"
android:textColor="@color/color_F9F9F9"
android:textSize="16sp" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/iv_auth"
android:layout_width="300dp"
android:layout_height="300dp"
android:src="@mipmap/ic_my_avat" />
<ImageView
android:id="@+id/iv_phone_dialog_quit"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"
android:padding="10dp"
android:src="@mipmap/ic_activity_quit" />
</LinearLayout>
......@@ -2,12 +2,13 @@
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:background="@color/color_232122"
android:paddingTop="30dp">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:background="@android:color/transparent"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_behavior=".ui.widgets.AppBarLayoutBehavior">
......@@ -20,7 +21,8 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:orientation="vertical">
<com.youth.banner.Banner
android:id="@+id/banner"
......@@ -28,6 +30,14 @@
android:layout_height="160dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp" />
<TextView
android:id="@+id/tv_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:visibility="gone" />
</LinearLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
......@@ -35,10 +45,10 @@
<com.google.android.material.tabs.TabLayout
android:id="@+id/tablayout"
android:layout_width="wrap_content"
android:layout_height="38dp"
android:layout_height="45dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:paddingTop="-10dp"
app:tabBackground="@null"
app:tabIndicatorHeight="0dp"
app:tabMaxWidth="200dp"
......
......@@ -15,13 +15,12 @@
android:id="@+id/rcy_square_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_F1F2F8"
android:overScrollMode="never"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
<com.scwang.smartrefresh.layout.footer.ClassicsFooter
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srlAccentColor="@color/black"
app:srlPrimaryColor="@color/white" />
app:srlAccentColor="@color/color_E4C46C"
app:srlPrimaryColor="@color/color_232122" />
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
\ No newline at end of file
......@@ -4,21 +4,37 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@color/white"
android:background="@drawable/shape_square_item"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:id="@+id/iv_recommend_header"
android:layout_width="80dp"
android:layout_height="120dp"
android:src="@mipmap/ic_my_avat" />
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/iv_recommend_header"
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@mipmap/ic_my_avat" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/shape_square_label"
android:paddingStart="10dp"
android:paddingTop="2dp"
android:paddingEnd="10dp"
android:paddingBottom="2dp"
android:text="真人"
android:textColor="@color/white"
android:textSize="12sp" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="8dp"
android:orientation="vertical">
<RelativeLayout
......@@ -31,59 +47,61 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:lines="1"
android:singleLine="true"
android:text="张三"
android:textColor="#454A69"
android:textSize="15sp" />
android:textSize="18sp" />
<TextView
android:id="@+id/tv_recommend_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:text="●在线"
android:textColor="@color/apk_uninstalled"
android:textSize="12sp" />
<!-- <TextView-->
<!-- android:id="@+id/tv_recommend_status"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_alignParentEnd="true"-->
<!-- android:layout_centerVertical="true"-->
<!-- android:text="●在线"-->
<!-- android:textColor="@color/apk_uninstalled"-->
<!-- android:textSize="12sp" />-->
<TextView
android:id="@+id/tv_recommend_vip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="10dp"
android:layout_toEndOf="@+id/tv_recommend_name"
android:background="@drawable/shape_bg_reco3"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="VIP"
android:textColor="@color/white"
android:textSize="10sp" />
<!-- <TextView-->
<!-- android:id="@+id/tv_recommend_vip"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_centerVertical="true"-->
<!-- android:layout_marginStart="10dp"-->
<!-- android:layout_toEndOf="@+id/tv_recommend_name"-->
<!-- android:background="@drawable/shape_bg_reco3"-->
<!-- android:paddingLeft="8dp"-->
<!-- android:paddingRight="8dp"-->
<!-- android:text="VIP"-->
<!-- android:textColor="@color/white"-->
<!-- android:textSize="10sp" />-->
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:orientation="horizontal">
<!-- <LinearLayout-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginTop="8dp"-->
<!-- android:layout_marginBottom="8dp"-->
<!-- android:orientation="horizontal">-->
<TextView
android:id="@+id/tv_recommend_age"
android:layout_width="wrap_content"
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp"
android:background="@drawable/shape_bg_reco2"
android:drawableLeft="@mipmap/ic_quit_yuan"
android:gravity="center"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:text="40"
android:textColor="@color/white"
android:textSize="13sp" />
<!-- <TextView-->
<!-- android:id="@+id/tv_recommend_age"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="24dp"-->
<!-- android:layout_gravity="center_vertical"-->
<!-- android:layout_marginStart="10dp"-->
<!-- android:background="@drawable/shape_bg_reco2"-->
<!-- android:drawableLeft="@mipmap/ic_quit_yuan"-->
<!-- android:gravity="center"-->
<!-- android:paddingLeft="4dp"-->
<!-- android:paddingRight="4dp"-->
<!-- android:text="40"-->
<!-- android:textColor="@color/white"-->
<!-- android:textSize="13sp" />-->
</LinearLayout>
<!-- </LinearLayout>-->
<LinearLayout
android:layout_width="wrap_content"
......@@ -95,7 +113,7 @@
<TextView
android:id="@+id/tv_recommend_height"
android:layout_width="wrap_content"
android:layout_height="24dp"
android:layout_height="22dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="6dp"
android:background="@drawable/shape_bg_reco1"
......@@ -104,12 +122,12 @@
android:paddingRight="4dp"
android:text="176cm"
android:textColor="@color/white"
android:textSize="13sp" />
android:textSize="12sp" />
<TextView
android:id="@+id/tv_recommend_city"
android:layout_width="wrap_content"
android:layout_height="24dp"
android:layout_height="22dp"
android:layout_gravity="center_vertical"
android:background="@drawable/shape_bg_reco1"
android:gravity="center"
......@@ -118,7 +136,7 @@
android:singleLine="true"
android:text="四川 成都"
android:textColor="@color/white"
android:textSize="13sp" />
android:textSize="12sp" />
</LinearLayout>
<TextView
......@@ -131,6 +149,58 @@
android:text="308.1km"
android:textColor="#454A69"
android:textSize="12sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv_photo1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginEnd="6dp"
android:src="@mipmap/ic_my_avat" />
<ImageView
android:id="@+id/iv_photo2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginEnd="6dp"
android:src="@mipmap/ic_my_avat" />
<FrameLayout
android:id="@+id/fl_photo_more"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<ImageView
android:id="@+id/iv_photo_more"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@mipmap/ic_my_avat" />
<TextView
android:id="@+id/tv_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="+1"
android:textColor="@color/white"
android:textSize="10dp" />
</FrameLayout>
<TextView
android:id="@+id/tv_status"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|right"
android:text="近日活跃"
android:textColor="@color/color_E4C46C" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/item_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="2dp"
android:paddingTop="6dp"
android:paddingEnd="5dp"
android:paddingBottom="6dp"
android:text="附近"
android:textColor="@color/color_E4C46C"
android:textSize="18sp"
android:textStyle="bold" />
<View
android:id="@+id/view_bar"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_marginStart="2dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="2dp"
android:background="@drawable/shape_square_tab" />
</LinearLayout>
\ No newline at end of file
......@@ -42,4 +42,17 @@
<color name="color_84C6FA">#84C6FA</color>
<color name="color_232122">#232122</color>
<color name="color_E4C46C">#E4C46C</color>
<color name="color_959595">#959595</color>
<color name="color_15141A">#15141A</color>
<color name="color_48484C">#48484C</color>
<color name="color_F9F9F9">#F9F9F9</color>
<color name="color_FDEEC8">#FDEEC8</color>
<color name="color_0F0913">#0F0913</color>
<color name="color_4C4B51">#4C4B51</color>
<color name="color_07060C">#07060C</color>
<color name="color_171619">#171619</color>
<color name="color_E5C565">#E5C565</color>
</resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment