Browse Source

添加老师端消息页面

Pq 2 years ago
parent
commit
0dccca9c47

+ 9 - 3
BaseLibrary/proguard-rules.pro

@@ -26,7 +26,13 @@
 *;
 }
 -keep public class * extends com.chad.library.adapter.base.BaseQuickAdapter
--keep public class * extends com.chad.library.adapter.base.BaseViewHolder
--keepclassmembers  class **$** extends com.chad.library.adapter.base.BaseViewHolder {
+-keep public class * extends com.chad.library.adapter.base.viewholder.BaseViewHolder
+-keepclassmembers  class **$** extends com.chad.library.adapter.base.viewholder.BaseViewHolder {
      <init>(...);
-}
+}
+
+-keep class com.luck.picture.lib.** { *; }
+-keep class com.luck.lib.camerax.** { *; }
+-dontwarn com.yalantis.ucrop**
+-keep class com.yalantis.ucrop** { *; }
+-keep interface com.yalantis.ucrop** { *; }

+ 15 - 0
BaseLibrary/src/main/res/drawable/custom_indicator_drawable.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:opacity="opaque"
+    tools:targetApi="23">
+
+    <item
+        android:width="16dp"
+        android:gravity="center_horizontal">
+        <shape android:shape="rectangle">
+            <corners android:radius="2dp"/>
+            <solid android:color="@color/colorAccent" />
+        </shape>
+    </item>
+</layer-list>

+ 1 - 0
rong_im/common_im_ui/.gitignore

@@ -0,0 +1 @@
+/build

+ 43 - 0
rong_im/common_im_ui/build.gradle

@@ -0,0 +1,43 @@
+plugins {
+    id 'com.android.library'
+}
+
+android {
+    compileSdkVersion rootProject.ext.android.compileSdkVersion
+    defaultConfig {
+        minSdkVersion rootProject.ext.android.minSdkVersion
+        targetSdkVersion rootProject.ext.android.targetSdkVersion
+        versionCode rootProject.ext.android.versionCode
+        versionName rootProject.ext.android.versionName
+
+        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+        consumerProguardFiles "consumer-rules.pro"
+    }
+
+    buildTypes {
+        release {
+            minifyEnabled false
+            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+        }
+    }
+    compileOptions {
+        sourceCompatibility JavaVersion.VERSION_1_8
+        targetCompatibility JavaVersion.VERSION_1_8
+    }
+
+    buildFeatures{
+        viewBinding = true
+    }
+}
+
+dependencies {
+
+    implementation 'androidx.appcompat:appcompat:1.3.0'
+    implementation 'com.google.android.material:material:1.4.0'
+    testImplementation 'junit:junit:4.13.2'
+    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
+    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
+    implementation project(':BaseLibrary')
+    implementation project(':rong_im:kit')
+
+}

+ 0 - 0
rong_im/common_im_ui/consumer-rules.pro


+ 21 - 0
rong_im/common_im_ui/proguard-rules.pro

@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile

+ 26 - 0
rong_im/common_im_ui/src/androidTest/java/com/example/common_im_ui/ExampleInstrumentedTest.java

@@ -0,0 +1,26 @@
+package com.example.common_im_ui;
+
+import android.content.Context;
+
+import androidx.test.platform.app.InstrumentationRegistry;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.*;
+
+/**
+ * Instrumented test, which will execute on an Android device.
+ *
+ * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
+ */
+@RunWith(AndroidJUnit4.class)
+public class ExampleInstrumentedTest {
+    @Test
+    public void useAppContext() {
+        // Context of the app under test.
+        Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
+        assertEquals("com.example.common_im_ui.test", appContext.getPackageName());
+    }
+}

+ 5 - 0
rong_im/common_im_ui/src/main/AndroidManifest.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.common.im_ui">
+
+</manifest>

+ 35 - 0
rong_im/common_im_ui/src/main/java/com/common/im/adapter/MessagePagerAdapter.java

@@ -0,0 +1,35 @@
+package com.common.im.adapter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import androidx.annotation.NonNull;
+import androidx.fragment.app.Fragment;
+import androidx.viewpager2.adapter.FragmentStateAdapter;
+
+/**
+ * Author by pq, Date on 2022/5/6.
+ */
+public class MessagePagerAdapter extends FragmentStateAdapter {
+    private ArrayList<Fragment> mFragments;
+
+    public MessagePagerAdapter(@NonNull Fragment fragment) {
+        super(fragment);
+    }
+
+    public void setData(ArrayList<Fragment> fragments) {
+        this.mFragments = fragments;
+        notifyDataSetChanged();
+    }
+
+    @NonNull
+    @Override
+    public Fragment createFragment(int position) {
+        return mFragments.get(position);
+    }
+
+    @Override
+    public int getItemCount() {
+        return mFragments != null ? mFragments.size() : 0;
+    }
+}

+ 18 - 0
rong_im/common_im_ui/src/main/java/com/common/im/contract/MessageFragmentContract.java

@@ -0,0 +1,18 @@
+package com.common.im.contract;
+
+import com.cooleshow.base.presenter.view.BaseView;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Author by pq, Date on 2022/4/20.
+ */
+public interface MessageFragmentContract {
+
+    interface MessageFragmentView extends BaseView {
+    }
+
+    interface Presenter {
+    }
+}

+ 10 - 0
rong_im/common_im_ui/src/main/java/com/common/im/presenter/MessagePresenter.java

@@ -0,0 +1,10 @@
+package com.common.im.presenter;
+
+import com.common.im.contract.MessageFragmentContract;
+import com.cooleshow.base.presenter.BasePresenter;
+
+/**
+ * Author by pq, Date on 2022/5/6.
+ */
+public class MessagePresenter extends BasePresenter<MessageFragmentContract.MessageFragmentView> implements MessageFragmentContract.Presenter {
+}

+ 98 - 0
rong_im/common_im_ui/src/main/java/com/common/im/ui/MessageFragment.java

@@ -0,0 +1,98 @@
+package com.common.im.ui;
+
+import android.graphics.Typeface;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.TextView;
+
+import com.common.im.adapter.MessagePagerAdapter;
+import com.common.im.contract.MessageFragmentContract;
+import com.common.im.presenter.MessagePresenter;
+import com.common.im_ui.R;
+import com.common.im_ui.databinding.FragmentMessageLayoutBinding;
+import com.cooleshow.base.ui.fragment.BaseMVPFragment;
+import com.cooleshow.base.utils.Utils;
+import com.google.android.material.tabs.TabLayout;
+import com.google.android.material.tabs.TabLayoutMediator;
+
+import java.util.ArrayList;
+
+import androidx.annotation.NonNull;
+import androidx.fragment.app.Fragment;
+import androidx.viewpager2.adapter.FragmentStateAdapter;
+import io.rong.imkit.conversationlist.ConversationListFragment;
+
+/**
+ * Author by pq, Date on 2022/5/6.
+ */
+public class MessageFragment extends BaseMVPFragment<FragmentMessageLayoutBinding, MessagePresenter> implements MessageFragmentContract.MessageFragmentView {
+    public static final String[] titles = new String[]{"聊天", "联系人"};
+    private ArrayList<Fragment> fragments = new ArrayList<>();
+
+    @Override
+    protected void initView(View rootView) {
+        Utils.setHeadView(mViewBinding.viewStatusBar, requireContext(), 0);
+        TabLayoutMediator tabLayoutMediator = new TabLayoutMediator(mViewBinding.tabLayout, mViewBinding.viewPager, new TabLayoutMediator.TabConfigurationStrategy() {
+            @Override
+            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
+                createTab(tab, titles[position]);
+            }
+        });
+        mViewBinding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
+            @Override
+            public void onTabSelected(TabLayout.Tab tab) {
+                if (tab != null && tab.getCustomView() != null) {
+                    View customView = tab.getCustomView();
+                    TextView tv_text = customView.findViewById(R.id.tv_text);
+                    tv_text.setTextColor(getResources().getColor(com.cooleshow.base.R.color.color_333333));
+                    tv_text.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
+                }
+            }
+
+            @Override
+            public void onTabUnselected(TabLayout.Tab tab) {
+                if (tab != null && tab.getCustomView() != null) {
+                    View customView = tab.getCustomView();
+                    TextView tv_text = customView.findViewById(R.id.tv_text);
+                    tv_text.setTextColor(getResources().getColor(com.cooleshow.base.R.color.color_666666));
+                    tv_text.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
+                }
+            }
+
+            @Override
+            public void onTabReselected(TabLayout.Tab tab) {
+            }
+        });
+        ConversationListFragment conversationListFragment = new ConversationListFragment();
+        ConversationListFragment conversationListFragment2 = new ConversationListFragment();
+        fragments.add(conversationListFragment);
+        fragments.add(conversationListFragment2);
+        MessagePagerAdapter messagePagerAdapter = new MessagePagerAdapter(this);
+        messagePagerAdapter.setData(fragments);
+        mViewBinding.viewPager.setAdapter(messagePagerAdapter);
+        tabLayoutMediator.attach();
+    }
+
+    private TabLayout.Tab createTab(TabLayout.Tab tab, String text) {
+        View view = LayoutInflater.from(getContext()).inflate(R.layout.view_message_tab_layout, null);
+        TextView tv_text = view.findViewById(R.id.tv_text);
+        tv_text.setText(text);
+        tab.setCustomView(view);
+        return tab;
+    }
+
+    @Override
+    protected void initData() {
+
+    }
+
+    @Override
+    protected FragmentMessageLayoutBinding getLayoutView() {
+        return FragmentMessageLayoutBinding.inflate(getLayoutInflater());
+    }
+
+    @Override
+    protected MessagePresenter createPresenter() {
+        return new MessagePresenter();
+    }
+}

+ 39 - 0
rong_im/common_im_ui/src/main/res/layout/fragment_message_layout.xml

@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout 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">
+
+    <View
+        android:id="@+id/view_status_bar"
+        android:layout_width="match_parent"
+        android:layout_height="1px"
+        app:layout_constraintTop_toTopOf="parent" />
+
+    <com.google.android.material.tabs.TabLayout
+        android:id="@+id/tab_layout"
+        android:layout_width="wrap_content"
+        android:layout_height="52dp"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toRightOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/view_status_bar"
+        app:tabBackground="@color/transparent"
+        app:tabGravity="fill"
+        app:tabIndicatorHeight="4dp"
+        app:tabIndicator="@drawable/custom_indicator_drawable"
+        app:tabIndicatorColor="@color/colorAccent"
+        app:tabIndicatorFullWidth="false"
+        app:tabMaxWidth="0dp"
+        app:tabRippleColor="@color/transparent"
+        app:tabSelectedTextColor="@color/color_333333"
+        app:tabTextColor="@color/color_666666" />
+
+    <androidx.viewpager2.widget.ViewPager2
+        android:id="@+id/viewPager"
+        android:layout_width="match_parent"
+        android:layout_height="0dp"
+        android:overScrollMode="never"
+        android:scrollbars="none"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/tab_layout" />
+</androidx.constraintlayout.widget.ConstraintLayout>

+ 15 - 0
rong_im/common_im_ui/src/main/res/layout/view_message_tab_layout.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content">
+    <TextView
+        android:gravity="center"
+        android:includeFontPadding="false"
+        android:textSize="@dimen/sp_18"
+        android:textColor="@color/color_666666"
+        android:id="@+id/tv_text"
+        android:minWidth="60dp"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"/>
+</FrameLayout>

+ 17 - 0
rong_im/common_im_ui/src/test/java/com/example/common_im_ui/ExampleUnitTest.java

@@ -0,0 +1,17 @@
+package com.example.common_im_ui;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
+ */
+public class ExampleUnitTest {
+    @Test
+    public void addition_isCorrect() {
+        assertEquals(4, 2 + 2);
+    }
+}

+ 1 - 0
settings.gradle

@@ -28,3 +28,4 @@ include ':rong_im:sight'
 include ':rong_im:im_lib'
 include ':rong_im:live'
 include ':live_teaching'
+include ':rong_im:common_im_ui'

+ 1 - 0
teacher/build.gradle

@@ -63,6 +63,7 @@ dependencies {
     implementation project(path: ':BaseLibrary')
     api project(path: ':usercenter')
     implementation project(path: ':rong_im:kit')
+    implementation project(path: ':rong_im:common_im_ui')
     implementation project(path: ':live_teaching')
     implementation "com.alibaba:arouter-api:$rootProject.ext.android.arouter_api_version"
     kapt "com.alibaba:arouter-compiler:$rootProject.ext.android.arouter_api_version"

+ 1 - 1
teacher/src/main/java/com/cooleshow/teacher/App.java

@@ -51,7 +51,7 @@ public class App extends BaseApplication {
         RongPushClient.setPushConfig(config);
 
         if (BuildConfig.DEBUG) {
-            IMManager.init(this, "c9kqb3rdc451j");////TODO 设置小班课appkey  uwd1c0sxuqp91   c9kqb3rdc451j 6tnym1br6pv07
+            IMManager.init(this, "0vnjpoad0jbdz");////TODO 设置小班课appkey  uwd1c0sxuqp91   c9kqb3rdc451j 6tnym1br6pv07
         } else {
             IMManager.init(this, "6tnym1br6pv07");////TODO 设置小班课appkey  uwd1c0sxuqp91   c9kqb3rdc451j 6tnym1br6pv07
         }

+ 39 - 2
teacher/src/main/java/com/cooleshow/teacher/ui/main/MainActivity.java

@@ -1,15 +1,21 @@
 package com.cooleshow.teacher.ui.main;
 
 import android.os.Bundle;
+import android.text.TextUtils;
 import android.view.MenuItem;
 
 import com.alibaba.android.arouter.facade.annotation.Route;
+import com.common.im.ui.MessageFragment;
 import com.cooleshow.base.router.RouterPath;
 import com.cooleshow.base.ui.activity.BaseActivity;
+import com.cooleshow.base.utils.LogUtils;
 import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
 import com.cooleshow.teacher.R;
 import com.cooleshow.teacher.adapter.HomePageAdapter;
 import com.cooleshow.teacher.databinding.ActivityMainBinding;
+import com.cooleshow.usercenter.helper.UserHelper;
+import com.daya.live_teaching.common.ResultCallback;
+import com.daya.live_teaching.im.IMManager;
 import com.google.android.material.bottomnavigation.BottomNavigationView;
 
 import java.util.ArrayList;
@@ -19,6 +25,7 @@ import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 import androidx.fragment.app.Fragment;
 import androidx.viewpager2.widget.ViewPager2;
+import io.rong.imlib.RongIMClient;
 
 /**
  * Author by pq, Date on 2022/4/20.
@@ -45,12 +52,12 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> {
         HomePageAdapter homePageAdapter = new HomePageAdapter(this);
         HomeFragment homeFragment = new HomeFragment();
         CourseTableFragment courseTableFragment = new CourseTableFragment();
-        HomeFragment homeFragment2 = new HomeFragment();
+        MessageFragment messageFragment = new MessageFragment();
         HomeFragment homeFragment3 = new HomeFragment();
         HomeFragment homeFragment4 = new HomeFragment();
         mFragments.add(homeFragment);
         mFragments.add(courseTableFragment);
-        mFragments.add(homeFragment2);
+        mFragments.add(messageFragment);
         mFragments.add(homeFragment3);
         mFragments.add(homeFragment4);
         homePageAdapter.setFragments(mFragments);
@@ -63,7 +70,37 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> {
                 return onTabClick(item.getItemId());
             }
         });
+    }
+
+    @Override
+    protected void initData() {
+        super.initData();
+        connectIM();
+    }
 
+    /**
+     * 连接rong IM
+     */
+    private void connectIM() {
+        if (UserHelper.isLogin()) {
+            String userIMToken = UserHelper.getUserIMToken();
+            if (!TextUtils.isEmpty(userIMToken)) {
+                RongIMClient.ConnectionStatusListener.ConnectionStatus currentConnectionStatus = RongIMClient.getInstance().getCurrentConnectionStatus();
+                if (currentConnectionStatus != RongIMClient.ConnectionStatusListener.ConnectionStatus.CONNECTED) {
+                    IMManager.getInstance().login(userIMToken, new ResultCallback<String>() {
+                        @Override
+                        public void onSuccess(String s) {
+                            LogUtils.i("im connect success:" + s);
+                        }
+
+                        @Override
+                        public void onFail(int errorCode, String errorStr) {
+                            LogUtils.i("im connect fail:" + errorStr + "-errorCode:" + errorCode);
+                        }
+                    });
+                }
+            }
+        }
     }
 
     private boolean onTabClick(int viewId) {