├── .idea
├── .name
├── vcs.xml
├── compiler.xml
├── misc.xml
└── gradle.xml
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── JniLibs
│ │ │ ├── x86
│ │ │ │ └── libbmob.so
│ │ │ ├── mips
│ │ │ │ └── libbmob.so
│ │ │ ├── armeabi
│ │ │ │ └── libbmob.so
│ │ │ ├── mips64
│ │ │ │ └── libbmob.so
│ │ │ ├── x86_64
│ │ │ │ └── libbmob.so
│ │ │ ├── arm64-v8a
│ │ │ │ └── libbmob.so
│ │ │ └── armeabi-v7a
│ │ │ │ └── libbmob.so
│ │ ├── Libs
│ │ │ └── BmobSDK_3.9.1.jar
│ │ ├── res
│ │ │ ├── values-land
│ │ │ │ └── dimens.xml
│ │ │ ├── values-w1240dp
│ │ │ │ └── dimens.xml
│ │ │ ├── values-w600dp
│ │ │ │ └── dimens.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── bmob.png
│ │ │ │ ├── bot.png
│ │ │ │ ├── android.png
│ │ │ │ ├── chatgpt.png
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── drawable
│ │ │ │ ├── not_content_button.xml
│ │ │ │ ├── voice_shape.xml
│ │ │ │ ├── rounded_corner.xml
│ │ │ │ ├── ic_home_black_24dp.xml
│ │ │ │ ├── baseline_arrow_back_24.xml
│ │ │ │ ├── ic_dashboard_black_24dp.xml
│ │ │ │ ├── baseline_delete_outline_24.xml
│ │ │ │ ├── baseline_message_24.xml
│ │ │ │ ├── baseline_keyboard_voice_24.xml
│ │ │ │ ├── baseline_delete_forever_24.xml
│ │ │ │ ├── baseline_keyboard_24.xml
│ │ │ │ ├── baseline_border_clear_24.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── attrs.xml
│ │ │ │ ├── styles.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── themes.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── menu
│ │ │ │ └── bottom_nav_menu.xml
│ │ │ ├── xml
│ │ │ │ ├── backup_rules.xml
│ │ │ │ └── data_extraction_rules.xml
│ │ │ ├── values-night
│ │ │ │ └── themes.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_splash.xml
│ │ │ │ ├── fragment_aboutme.xml
│ │ │ │ ├── fragment_home.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── chat_item.xml
│ │ │ │ ├── activity_login.xml
│ │ │ │ ├── character_item.xml
│ │ │ │ └── activity_chat.xml
│ │ │ ├── navigation
│ │ │ │ └── mobile_navigation.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── bmobapp
│ │ │ │ └── bmobchatai
│ │ │ │ ├── bean
│ │ │ │ ├── User.java
│ │ │ │ ├── Character.java
│ │ │ │ └── Message.java
│ │ │ │ ├── BmobApp.java
│ │ │ │ ├── ui
│ │ │ │ ├── aboutme
│ │ │ │ │ ├── DashboardViewModel.java
│ │ │ │ │ └── AboutmeFragment.java
│ │ │ │ └── conversation
│ │ │ │ │ └── ConversationFragment.java
│ │ │ │ ├── SplashActivity.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── adapter
│ │ │ │ ├── ChatAdapter.java
│ │ │ │ └── CharacterAdapter.java
│ │ │ │ ├── LoginActivity.java
│ │ │ │ └── ChatActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── bmobapp
│ │ │ └── bmobchatai
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── bmobapp
│ │ └── bmobchatai
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── 1.jpg
├── 2.jpg
├── 3.jpg
├── 4.jpg
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── settings.gradle
├── README.md
├── gradle.properties
├── gradlew.bat
└── gradlew
/.idea/.name:
--------------------------------------------------------------------------------
1 | BeAI
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/1.jpg
--------------------------------------------------------------------------------
/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/2.jpg
--------------------------------------------------------------------------------
/3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/3.jpg
--------------------------------------------------------------------------------
/4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/4.jpg
--------------------------------------------------------------------------------
/app/src/main/JniLibs/x86/libbmob.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/app/src/main/JniLibs/x86/libbmob.so
--------------------------------------------------------------------------------
/app/src/main/Libs/BmobSDK_3.9.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/app/src/main/Libs/BmobSDK_3.9.1.jar
--------------------------------------------------------------------------------
/app/src/main/res/values-land/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 48dp
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w1240dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 200dp
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 48dp
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/JniLibs/mips/libbmob.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/app/src/main/JniLibs/mips/libbmob.so
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/bmob.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/app/src/main/res/mipmap-hdpi/bmob.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/bot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/app/src/main/res/mipmap-hdpi/bot.png
--------------------------------------------------------------------------------
/app/src/main/JniLibs/armeabi/libbmob.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/app/src/main/JniLibs/armeabi/libbmob.so
--------------------------------------------------------------------------------
/app/src/main/JniLibs/mips64/libbmob.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/app/src/main/JniLibs/mips64/libbmob.so
--------------------------------------------------------------------------------
/app/src/main/JniLibs/x86_64/libbmob.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/app/src/main/JniLibs/x86_64/libbmob.so
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/android.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/app/src/main/res/mipmap-hdpi/android.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/chatgpt.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/app/src/main/res/mipmap-hdpi/chatgpt.png
--------------------------------------------------------------------------------
/app/src/main/JniLibs/arm64-v8a/libbmob.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/app/src/main/JniLibs/arm64-v8a/libbmob.so
--------------------------------------------------------------------------------
/app/src/main/JniLibs/armeabi-v7a/libbmob.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/app/src/main/JniLibs/armeabi-v7a/libbmob.so
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bmob/Bmob-Android-AI-Prompt/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bmobapp/bmobchatai/bean/User.java:
--------------------------------------------------------------------------------
1 | package com.bmobapp.bmobchatai.bean;
2 |
3 | import cn.bmob.v3.BmobUser;
4 |
5 | /**
6 | * 用户类
7 | */
8 | public class User extends BmobUser {
9 | }
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/not_content_button.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BeAI
3 | BeAI
4 | 角色
5 | 我的
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Jun 26 21:18:04 GMT+08:00 2023
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | local.properties
16 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/voice_shape.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/rounded_corner.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_home_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | google()
4 | mavenCentral()
5 | gradlePluginPortal()
6 | }
7 | }
8 | dependencyResolutionManagement {
9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
10 | repositories {
11 | google()
12 | mavenCentral()
13 | }
14 | }
15 | rootProject.name = "BeAI"
16 | include ':app'
17 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/baseline_arrow_back_24.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_dashboard_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/baseline_delete_outline_24.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
11 |
--------------------------------------------------------------------------------
/app/src/test/java/com/bmobapp/bmobchatai/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.bmobapp.bmobchatai;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/baseline_message_24.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/bottom_nav_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bmobapp/bmobchatai/BmobApp.java:
--------------------------------------------------------------------------------
1 | package com.bmobapp.bmobchatai;
2 |
3 | import android.app.Application;
4 |
5 | import cn.bmob.v3.Bmob;
6 | import cn.bmob.v3.ai.BmobAI;
7 |
8 | public class BmobApp extends Application {
9 | public static BmobAI bmobAI;
10 |
11 | @Override
12 | public void onCreate() {
13 | super.onCreate();
14 | //初始化
15 | Bmob.initialize(this,"e1a1a71e3df8d0da3e65c47379b1f7b4");
16 |
17 | bmobAI = new BmobAI();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FF000000
4 | #FFFFFFFF
5 | #FF039BE5
6 | #FF01579B
7 | #FF40C4FF
8 | #FF00B0FF
9 | #66000000
10 | #00000000
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/baseline_keyboard_voice_24.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_rules.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/baseline_delete_forever_24.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bmobapp/bmobchatai/ui/aboutme/DashboardViewModel.java:
--------------------------------------------------------------------------------
1 | package com.bmobapp.bmobchatai.ui.aboutme;
2 |
3 | import androidx.lifecycle.LiveData;
4 | import androidx.lifecycle.MutableLiveData;
5 | import androidx.lifecycle.ViewModel;
6 |
7 | public class DashboardViewModel extends ViewModel {
8 |
9 | private final MutableLiveData mText;
10 |
11 | public DashboardViewModel() {
12 | mText = new MutableLiveData<>();
13 | mText.setValue("页面正在建设中");
14 | }
15 |
16 | public LiveData getText() {
17 | return mText;
18 | }
19 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/baseline_keyboard_24.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/data_extraction_rules.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
12 |
13 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/baseline_border_clear_24.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BeAI开源项目说明文档
2 |
3 | ## 采用方案
4 |
5 | 开发工具:Android Studio Flamingo | 2022.2.1 Patch1版本
6 |
7 | 开发版本:gradle 8.0
8 |
9 | 开发语言:Java
10 |
11 | 云服务商:[Bmob后端云](https://www.bmobapp.com),使用了数据服务和AI服务。
12 |
13 | ## 前提条件
14 |
15 | 建议不了解Bmob AI服务的朋友,先花几分钟查看[Bmob AI快速入门](https://doc.bmobapp.com/ai/android/index.html)
16 |
17 | ## 现有功能
18 |
19 | - 手机号码注册登录
20 | - AI角色云端化
21 | - AI角色对话(接入chatgpt3.5/4.0),云端获取prompt信息
22 | - AI会话内容云端存储
23 | - 会话清除
24 |
25 | ## 未来计划
26 |
27 | - 语音AI对话
28 | - 图片AI对话
29 |
30 | ## 欢迎加入
31 |
32 | 欢迎有兴趣的朋友加我微信(xiaowon12),一起讨论AI大计。
33 |
34 | 
35 |
36 | ## 最终效果
37 |
38 | (如果看不到下面的图,请科学上网)
39 |
40 | 
41 |
42 | 
43 |
44 | 
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
18 |
19 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_splash.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/navigation/mobile_navigation.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
19 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/bmobapp/bmobchatai/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.bmobapp.bmobchatai;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 | assertEquals("com.bmobapp.bmobchatai", appContext.getPackageName());
25 | }
26 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_aboutme.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bmobapp/bmobchatai/ui/aboutme/AboutmeFragment.java:
--------------------------------------------------------------------------------
1 | package com.bmobapp.bmobchatai.ui.aboutme;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.TextView;
8 |
9 | import androidx.annotation.NonNull;
10 | import androidx.appcompat.app.AppCompatActivity;
11 | import androidx.appcompat.widget.Toolbar;
12 | import androidx.fragment.app.Fragment;
13 | import androidx.lifecycle.ViewModelProvider;
14 |
15 | import com.bmobapp.bmobchatai.R;
16 | import com.bmobapp.bmobchatai.databinding.FragmentAboutmeBinding;
17 |
18 | public class AboutmeFragment extends Fragment {
19 |
20 | private FragmentAboutmeBinding binding;
21 |
22 | public View onCreateView(@NonNull LayoutInflater inflater,
23 | ViewGroup container, Bundle savedInstanceState) {
24 | DashboardViewModel dashboardViewModel =
25 | new ViewModelProvider(this).get(DashboardViewModel.class);
26 |
27 | binding = FragmentAboutmeBinding.inflate(inflater, container, false);
28 | View root = binding.getRoot();
29 |
30 |
31 | return root;
32 | }
33 |
34 | @Override
35 | public void onDestroyView() {
36 | super.onDestroyView();
37 | binding = null;
38 | }
39 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Enables namespacing of each library's R class so that its R class includes only the
19 | # resources declared in the library itself and none from the library's dependencies,
20 | # thereby reducing the size of the R class for that library
21 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/app/src/main/java/com/bmobapp/bmobchatai/SplashActivity.java:
--------------------------------------------------------------------------------
1 | package com.bmobapp.bmobchatai;
2 |
3 | import androidx.appcompat.app.ActionBar;
4 | import androidx.appcompat.app.AppCompatActivity;
5 |
6 | import android.content.Intent;
7 | import android.graphics.Color;
8 | import android.os.Bundle;
9 | import android.os.Handler;
10 | import android.view.Window;
11 | import android.view.WindowManager;
12 |
13 | public class SplashActivity extends AppCompatActivity {
14 |
15 | private Handler mHandle = new Handler();
16 | private Runnable mRunnable = new Runnable() {
17 | @Override
18 | public void run() {
19 | Intent intent = new Intent(SplashActivity.this,MainActivity.class);
20 | startActivity(intent);
21 | SplashActivity.this.finish();
22 | }
23 | };
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 |
29 | /*ActionBar actionBar = getSupportActionBar();
30 | if(actionBar!=null){
31 | actionBar.hide();
32 | }*/
33 | getWindow().setStatusBarColor(Color.WHITE);
34 | setContentView(R.layout.activity_splash);
35 | mHandle.postDelayed(mRunnable,2000);
36 | }
37 |
38 | @Override
39 | protected void onPause() {
40 | super.onPause();
41 | mHandle.removeCallbacks(mRunnable);
42 | }
43 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_home.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
20 |
21 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
21 |
22 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bmobapp/bmobchatai/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.bmobapp.bmobchatai;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 | import android.view.WindowManager;
7 |
8 | import com.bmobapp.bmobchatai.bean.User;
9 | import com.google.android.material.bottomnavigation.BottomNavigationView;
10 |
11 | import androidx.appcompat.app.AppCompatActivity;
12 | import androidx.appcompat.widget.Toolbar;
13 | import androidx.navigation.NavController;
14 | import androidx.navigation.Navigation;
15 | import androidx.navigation.ui.AppBarConfiguration;
16 | import androidx.navigation.ui.NavigationUI;
17 |
18 | import com.bmobapp.bmobchatai.databinding.ActivityMainBinding;
19 |
20 | import cn.bmob.v3.BmobUser;
21 |
22 | public class MainActivity extends AppCompatActivity {
23 |
24 | private ActivityMainBinding binding;
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 |
29 | if(!BmobUser.isLogin()){
30 | Intent intent = new Intent(MainActivity.this, LoginActivity.class);
31 | startActivity(intent);
32 | }
33 |
34 | super.onCreate(savedInstanceState);
35 |
36 | binding = ActivityMainBinding.inflate(getLayoutInflater());
37 | setContentView(binding.getRoot());
38 |
39 | BottomNavigationView navView = findViewById(R.id.nav_view);
40 | AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
41 | R.id.navigation_home, R.id.navigation_dashboard)
42 | .build();
43 | NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_main);
44 | NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
45 | NavigationUI.setupWithNavController(binding.navView, navController);
46 | }
47 |
48 | }
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | }
4 |
5 | android {
6 | namespace 'com.bmobapp.bmobchatai'
7 | compileSdk 33
8 |
9 | defaultConfig {
10 | applicationId "com.bmobapp.bmobchatai"
11 | minSdk 24
12 | targetSdk 33
13 | versionCode 1
14 | versionName "1.0"
15 | multiDexEnabled true
16 |
17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18 | }
19 |
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 | compileOptions {
27 | sourceCompatibility JavaVersion.VERSION_1_8
28 | targetCompatibility JavaVersion.VERSION_1_8
29 | }
30 | buildFeatures {
31 | viewBinding true
32 | }
33 | }
34 |
35 | dependencies {
36 | implementation 'io.github.bmob:android-sdk:3.9.4'
37 | implementation 'io.reactivex.rxjava2:rxjava:2.2.8'
38 | implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
39 | implementation 'com.squareup.okhttp3:okhttp:4.7.2'
40 | implementation 'com.squareup.okio:okio:2.2.2'
41 | implementation 'com.google.code.gson:gson:2.8.5'
42 |
43 | implementation 'com.squareup.picasso:picasso:2.71828'
44 |
45 | implementation 'androidx.recyclerview:recyclerview:1.3.0'
46 | implementation 'androidx.appcompat:appcompat:1.4.1'
47 | implementation 'com.google.android.material:material:1.5.0'
48 | implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
49 | implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1'
50 | implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'
51 | implementation 'androidx.navigation:navigation-fragment:2.5.2'
52 | implementation 'androidx.navigation:navigation-ui:2.5.2'
53 | implementation 'androidx.annotation:annotation:1.3.0'
54 | testImplementation 'junit:junit:4.13.2'
55 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
56 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
57 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
21 |
24 |
30 |
31 |
32 |
33 |
34 |
35 |
38 |
42 |
43 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bmobapp/bmobchatai/ui/conversation/ConversationFragment.java:
--------------------------------------------------------------------------------
1 | package com.bmobapp.bmobchatai.ui.conversation;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | import androidx.annotation.NonNull;
9 | import androidx.appcompat.app.AppCompatActivity;
10 | import androidx.appcompat.widget.Toolbar;
11 | import androidx.fragment.app.Fragment;
12 | import androidx.recyclerview.widget.LinearLayoutManager;
13 | import androidx.recyclerview.widget.RecyclerView;
14 |
15 | import com.bmobapp.bmobchatai.R;
16 | import com.bmobapp.bmobchatai.adapter.CharacterAdapter;
17 | import com.bmobapp.bmobchatai.bean.Character;
18 | import com.bmobapp.bmobchatai.databinding.FragmentHomeBinding;
19 |
20 | import java.util.List;
21 |
22 | import cn.bmob.v3.BmobQuery;
23 | import cn.bmob.v3.exception.BmobException;
24 | import cn.bmob.v3.listener.FindListener;
25 |
26 | public class ConversationFragment extends Fragment {
27 |
28 | private FragmentHomeBinding binding;
29 |
30 | public View onCreateView(@NonNull LayoutInflater inflater,
31 | ViewGroup container, Bundle savedInstanceState) {
32 |
33 | binding = FragmentHomeBinding.inflate(inflater, container, false);
34 | View root = binding.getRoot();
35 |
36 | final RecyclerView prompt_recycle_view = binding.promptRecyclerView;
37 |
38 | //从Bmob上面获取AI信息
39 | BmobQuery query = new BmobQuery<>();
40 | query.order("rank").findObjects(new FindListener() {
41 | @Override
42 | public void done(List characterList, BmobException e) {
43 | CharacterAdapter characterAdapter = new CharacterAdapter(characterList,getContext());
44 | prompt_recycle_view.setAdapter(characterAdapter);
45 | LinearLayoutManager llm = new LinearLayoutManager(getActivity());
46 | llm.setStackFromEnd(true);
47 | prompt_recycle_view.setLayoutManager(llm);
48 | }
49 | });
50 |
51 | return root;
52 | }
53 |
54 | @Override
55 | public void onDestroyView() {
56 | super.onDestroyView();
57 | binding = null;
58 | }
59 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/bmobapp/bmobchatai/bean/Character.java:
--------------------------------------------------------------------------------
1 | package com.bmobapp.bmobchatai.bean;
2 |
3 | import android.content.Intent;
4 |
5 | import cn.bmob.v3.BmobObject;
6 |
7 | /**
8 | * 角色表类
9 | */
10 | public class Character extends BmobObject {
11 | /**
12 | * 多少人在用这个角色
13 | */
14 | String userNum;
15 |
16 | /**
17 | * 角色名称
18 | */
19 | String title;
20 |
21 | /**
22 | * 角色的英文名
23 | */
24 | String name;
25 |
26 | /**
27 | * 角色头像
28 | */
29 | String img;
30 |
31 | /**
32 | * 角色的prompt
33 | */
34 | String prompt;
35 |
36 | /**
37 | * 角色的描述信息
38 | */
39 | String description;
40 |
41 |
42 | /**
43 | * 开始的对话语
44 | */
45 | String startMsg;
46 |
47 | /**
48 | * 排列顺序
49 | */
50 | Integer rank;
51 |
52 | public Integer getRank() {
53 | return rank;
54 | }
55 |
56 | public void setRank(Integer rank) {
57 | this.rank = rank;
58 | }
59 |
60 | public String getStartMsg() {
61 | return startMsg;
62 | }
63 |
64 | public void setStartMsg(String startMsg) {
65 | this.startMsg = startMsg;
66 | }
67 |
68 |
69 |
70 | public String getTitle() {
71 | return title;
72 | }
73 |
74 | public void setTitle(String title) {
75 | this.title = title;
76 | }
77 |
78 | public String getName() {
79 | return name;
80 | }
81 |
82 | public void setName(String name) {
83 | this.name = name;
84 | }
85 |
86 | public String getImg() {
87 | return img;
88 | }
89 |
90 | public void setImg(String img) {
91 | this.img = img;
92 | }
93 |
94 | public String getPrompt() {
95 | return prompt;
96 | }
97 |
98 | public void setPrompt(String prompt) {
99 | this.prompt = prompt;
100 | }
101 |
102 | public String getDescription() {
103 | return description;
104 | }
105 |
106 | public void setDescription(String description) {
107 | this.description = description;
108 | }
109 |
110 | public String getUserNum() {
111 | return userNum;
112 | }
113 |
114 | public void setUserNum(String userNum) {
115 | this.userNum = userNum;
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bmobapp/bmobchatai/bean/Message.java:
--------------------------------------------------------------------------------
1 | package com.bmobapp.bmobchatai.bean;
2 |
3 | import cn.bmob.v3.BmobObject;
4 |
5 | /**
6 | * 聊天表类
7 | */
8 | public class Message extends BmobObject {
9 | public static String SEND_BY_ME="me";
10 | public static String SEND_BY_BOT="bot";
11 |
12 | /**
13 | * 会话
14 | */
15 | String session;
16 |
17 | /**
18 | * 内容的归属权
19 | */
20 | String username;
21 |
22 | /**
23 | * 发送的内容
24 | */
25 | String message;
26 |
27 | /**
28 | * 发送者(me和bot两种类型)
29 | */
30 | String sendBy;
31 |
32 | /**
33 | * 获取用户的名字
34 | * @return
35 | */
36 | public String getUsername() {
37 | return username;
38 | }
39 |
40 | /**
41 | * 设置用户的名字
42 | * @param username
43 | */
44 | public void setUsername(String username) {
45 | this.username = username;
46 | }
47 |
48 | /**
49 | * 获取会话信息
50 | * @return
51 | */
52 | public String getSession() {
53 | return session;
54 | }
55 |
56 | /**
57 | * 设置会话信息
58 | * @param session
59 | */
60 | public void setSession(String session) {
61 | this.session = session;
62 | }
63 |
64 | /**
65 | * 获取聊天内容
66 | * @return
67 | */
68 | public String getMessage() {
69 | return message;
70 | }
71 |
72 | /**
73 | * 设置聊天内容
74 | * @param message
75 | */
76 | public void setMessage(String message) {
77 | this.message = message;
78 | }
79 |
80 | /**
81 | * 获取发送者
82 | * @return
83 | */
84 | public String getSendBy() {
85 | return sendBy;
86 | }
87 |
88 | /**
89 | * 设置发送者
90 | * @param sendBy
91 | */
92 | public void setSendBy(String sendBy) {
93 | this.sendBy = sendBy;
94 | }
95 |
96 | /**
97 | * 构造函数
98 | */
99 | public Message(){
100 |
101 | }
102 |
103 | /**
104 | * 聊天内容的构造函数
105 | * @param message 聊天内容
106 | * @param sendBy 发送者
107 | */
108 | public Message(String message, String sendBy,String session,String username) {
109 | this.message = message;
110 | this.sendBy = sendBy;
111 | this.session = session;
112 | this.username = username;
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/chat_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
19 |
31 |
32 |
33 |
41 |
53 |
58 |
59 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
14 |
15 |
28 |
29 |
36 |
37 |
38 |
39 |
45 |
46 |
50 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bmobapp/bmobchatai/adapter/ChatAdapter.java:
--------------------------------------------------------------------------------
1 | package com.bmobapp.bmobchatai.adapter;
2 |
3 | import android.view.LayoutInflater;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.ImageView;
7 | import android.widget.LinearLayout;
8 | import android.widget.TextView;
9 |
10 | import androidx.annotation.NonNull;
11 | import androidx.recyclerview.widget.RecyclerView;
12 |
13 | import com.bmobapp.bmobchatai.R;
14 | import com.bmobapp.bmobchatai.bean.Message;
15 | import com.squareup.picasso.Picasso;
16 |
17 | import java.util.List;
18 |
19 | /**
20 | * 聊天内容的适配器类
21 | */
22 | public class ChatAdapter extends RecyclerView.Adapter {
23 | List messageList;
24 | String logo;
25 | public ChatAdapter(List messageList,String logo) {
26 | this.messageList = messageList;
27 | this.logo = logo;
28 | }
29 |
30 | @NonNull
31 | @Override
32 | public ChatViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
33 | View chatView = LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_item,null);
34 | ChatViewHolder myViewHolder = new ChatViewHolder(chatView);
35 |
36 | return myViewHolder;
37 | }
38 |
39 | @Override
40 | public void onBindViewHolder(@NonNull ChatViewHolder holder, int position) {
41 | Message message = messageList.get(position);
42 | if(message.getSendBy().equals(Message.SEND_BY_ME)){
43 | holder.leftChatView.setVisibility(View.GONE);
44 | holder.rightChatView.setVisibility(View.VISIBLE);
45 | holder.rightTextView.setText(message.getMessage());
46 | }else{
47 | holder.rightChatView.setVisibility(View.GONE);
48 | holder.leftChatView.setVisibility(View.VISIBLE);
49 | holder.leftTextView.setText(message.getMessage());
50 | //设置头像
51 | Picasso.get().load(logo).into(holder.logo);
52 | }
53 | }
54 |
55 | @Override
56 | public int getItemCount() {
57 | return messageList.size();
58 | }
59 |
60 | public class ChatViewHolder extends RecyclerView.ViewHolder{
61 | LinearLayout leftChatView,rightChatView;
62 | TextView leftTextView,rightTextView;
63 |
64 | ImageView logo;
65 |
66 | public ChatViewHolder(@NonNull View itemView) {
67 | super(itemView);
68 |
69 | leftChatView = itemView.findViewById(R.id.left_chat_view);
70 | rightChatView = itemView.findViewById(R.id.right_chat_view);
71 | logo = itemView.findViewById(R.id.chatgpt);
72 |
73 | leftTextView = itemView.findViewById(R.id.left_chat_text_view);
74 | rightTextView = itemView.findViewById(R.id.right_chat_text_view);
75 |
76 |
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
22 |
28 |
39 |
40 |
41 |
42 |
47 |
56 |
57 |
63 |
64 |
65 |
72 |
73 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/character_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
17 |
18 |
25 |
26 |
35 |
36 |
43 |
44 |
49 |
53 |
54 |
61 |
62 |
63 |
71 |
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bmobapp/bmobchatai/adapter/CharacterAdapter.java:
--------------------------------------------------------------------------------
1 | package com.bmobapp.bmobchatai.adapter;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.ImageView;
10 | import android.widget.TextView;
11 |
12 | import androidx.annotation.NonNull;
13 | import androidx.recyclerview.widget.RecyclerView;
14 |
15 | import com.bmobapp.bmobchatai.ChatActivity;
16 | import com.bmobapp.bmobchatai.R;
17 | import com.bmobapp.bmobchatai.bean.Character;
18 | import com.squareup.picasso.Picasso;
19 |
20 | import java.util.List;
21 |
22 | public class CharacterAdapter extends RecyclerView.Adapter {
23 | List characterList;
24 | Context context;
25 |
26 | public CharacterAdapter(List characterList, Context context){
27 | this.characterList = characterList;
28 | this.context = context;
29 | }
30 |
31 | @NonNull
32 | @Override
33 | public CharacterViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
34 | View promptView = LayoutInflater.from(parent.getContext()).inflate(R.layout.character_item,null);
35 | CharacterAdapter.CharacterViewHolder promptViewHolder = new CharacterAdapter.CharacterViewHolder(promptView);
36 |
37 | return promptViewHolder;
38 |
39 | }
40 |
41 | @Override
42 | public void onBindViewHolder(@NonNull CharacterViewHolder holder, @SuppressLint("RecyclerView") int position) {
43 | Character character = characterList.get(position);
44 | holder.character_title.setText(character.getTitle());
45 | holder.character_description.setText(character.getDescription());
46 | holder.character_user_num.setText(character.getUserNum());
47 |
48 | Picasso.get().load(character.getImg()).into(holder.character_img);
49 |
50 | holder.itemView.setOnClickListener(new View.OnClickListener() {
51 | @Override
52 | public void onClick(View v) {
53 | Intent intent = new Intent(v.getContext(), ChatActivity.class);
54 | intent.putExtra("title", character.getTitle());
55 | intent.putExtra("prompt", character.getPrompt());
56 | intent.putExtra("name", character.getName());
57 | intent.putExtra("img", character.getImg());
58 | intent.putExtra("startMsg", character.getStartMsg());
59 | v.getContext().startActivity(intent);
60 | }
61 | });
62 | }
63 |
64 | @Override
65 | public int getItemCount() {
66 | return characterList.size();
67 | }
68 |
69 | public class CharacterViewHolder extends RecyclerView.ViewHolder{
70 |
71 | TextView character_title;
72 | TextView character_user_num;
73 | TextView character_description;
74 |
75 | ImageView character_img;
76 |
77 | public CharacterViewHolder(@NonNull View itemView) {
78 | super(itemView);
79 |
80 | character_title = itemView.findViewById(R.id.prompt_title);
81 | character_user_num = itemView.findViewById(R.id.character_user_num);
82 | character_description = itemView.findViewById(R.id.character_description);
83 | character_img = itemView.findViewById(R.id.character_img);
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bmobapp/bmobchatai/LoginActivity.java:
--------------------------------------------------------------------------------
1 | package com.bmobapp.bmobchatai;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | import android.content.Intent;
6 | import android.os.Bundle;
7 | import android.util.Log;
8 | import android.view.View;
9 | import android.view.Window;
10 | import android.view.WindowManager;
11 | import android.widget.Button;
12 | import android.widget.CheckBox;
13 | import android.widget.EditText;
14 | import android.widget.RadioButton;
15 | import android.widget.Toast;
16 |
17 | import cn.bmob.v3.BmobSMS;
18 | import cn.bmob.v3.BmobUser;
19 | import cn.bmob.v3.exception.BmobException;
20 | import cn.bmob.v3.listener.LogInListener;
21 | import cn.bmob.v3.listener.QueryListener;
22 | import kotlin.jvm.internal.PropertyReference0Impl;
23 |
24 | public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
25 |
26 | private String code;
27 | private boolean ifCheck = false;
28 |
29 | private EditText phoneEdit;
30 | private EditText codeEdit;
31 | private RadioButton radioButton;
32 | private Button submitBt;
33 | private Button getCodeBt;
34 |
35 | @Override
36 | protected void onCreate(Bundle savedInstanceState) {
37 | super.onCreate(savedInstanceState);
38 |
39 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
40 |
41 | setContentView(R.layout.activity_login);
42 |
43 | setTitle("快速登录");
44 |
45 | phoneEdit = findViewById(R.id.phone);
46 | codeEdit = findViewById(R.id.code);
47 | radioButton = findViewById(R.id.checkRadio);
48 | getCodeBt = findViewById(R.id.getcode);
49 | getCodeBt.setOnClickListener(this);
50 | submitBt = findViewById(R.id.submit);
51 | submitBt.setOnClickListener(this);
52 | }
53 |
54 | @Override
55 | public void onClick(View v) {
56 | if(v==getCodeBt){
57 | if(!radioButton.isChecked()){
58 | Toast.makeText(v.getContext(),"请同意以上服务条款",Toast.LENGTH_SHORT).show();
59 | return;
60 | }
61 |
62 | //获取验证码
63 | String phone = phoneEdit.getText().toString().trim();
64 |
65 | //这里不检查phone的更多合规性问题,自行补上
66 | if(phone.length()!=11){
67 | Toast.makeText(v.getContext(),"请输入正确的手机号码",Toast.LENGTH_SHORT).show();
68 | return;
69 | }
70 |
71 | //发送验证码
72 | BmobSMS.requestSMSCode(phone, "", new QueryListener() {
73 | @Override
74 | public void done(Integer integer, BmobException e) {
75 | if(e==null){
76 | //获取到验证码
77 | Toast.makeText(v.getContext(),"验证码发送成功",Toast.LENGTH_SHORT).show();
78 | }
79 | }
80 | });
81 | }else if(v==submitBt){
82 | //注册登录
83 | String phone = phoneEdit.getText().toString().trim();
84 | String code = codeEdit.getText().toString().trim();
85 |
86 | if(code.isEmpty() || code.length()!=6){
87 | Toast.makeText(v.getContext(),"请输入验证码",Toast.LENGTH_SHORT).show();
88 | return;
89 | }
90 |
91 | //执行登录操作
92 | BmobUser.signOrLoginByMobilePhone(phone, code, new LogInListener() {
93 | @Override
94 | public void done(BmobUser o, BmobException e) {
95 | if(e==null){
96 | startActivity(new Intent(LoginActivity.this,MainActivity.class));
97 | }
98 | else{
99 |
100 | Toast.makeText(v.getContext(),"短信验证失败",Toast.LENGTH_SHORT).show();
101 | }
102 | }
103 | });
104 | }
105 | }
106 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_chat.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
24 |
25 |
26 |
32 |
33 |
40 |
47 |
48 |
59 |
69 |
70 |
71 |
78 |
84 |
92 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bmobapp/bmobchatai/ChatActivity.java:
--------------------------------------------------------------------------------
1 | package com.bmobapp.bmobchatai;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 | import androidx.appcompat.widget.Toolbar;
5 | import androidx.recyclerview.widget.LinearLayoutManager;
6 | import androidx.recyclerview.widget.RecyclerView;
7 |
8 | import android.app.AlertDialog;
9 | import android.app.DatePickerDialog;
10 | import android.content.DialogInterface;
11 | import android.content.Intent;
12 | import android.os.Bundle;
13 | import android.util.Log;
14 | import android.view.View;
15 | import android.widget.Button;
16 | import android.widget.EditText;
17 | import android.widget.ImageButton;
18 | import android.widget.RelativeLayout;
19 |
20 | import com.bmobapp.bmobchatai.adapter.ChatAdapter;
21 | import com.bmobapp.bmobchatai.bean.Message;
22 |
23 | import java.util.ArrayList;
24 | import java.util.List;
25 |
26 | import cn.bmob.v3.Bmob;
27 | import cn.bmob.v3.BmobQuery;
28 | import cn.bmob.v3.BmobUser;
29 | import cn.bmob.v3.ai.BmobAI;
30 | import cn.bmob.v3.ai.ChatMessageListener;
31 | import cn.bmob.v3.exception.BmobException;
32 | import cn.bmob.v3.listener.FindListener;
33 | import cn.bmob.v3.listener.SaveListener;
34 | import cn.bmob.v3.listener.UpdateListener;
35 | import cn.bmob.v3.realtime.Client;
36 |
37 | public class ChatActivity extends AppCompatActivity implements View.OnClickListener {
38 |
39 | RecyclerView recyclerView;
40 | EditText messageEditText;
41 | Button sendButton;
42 |
43 | List messageList = new ArrayList<>();
44 |
45 | ChatAdapter chatAdapter;
46 |
47 | //BmobAI bmobAI;
48 |
49 | String title;
50 |
51 | String session;
52 |
53 | String username = "default";
54 |
55 | String startMsg="";
56 |
57 | String logo ="";
58 |
59 | @Override
60 | protected void onCreate(Bundle savedInstanceState) {
61 | //获取这个机器人的标题、名称、prompt和头像信息
62 | Intent intent = getIntent();
63 | title = intent.getStringExtra("title");
64 | session = intent.getStringExtra("name");
65 | String prompt = intent.getStringExtra("prompt");
66 | logo = intent.getStringExtra("img");
67 | startMsg = intent.getStringExtra("startMsg");
68 |
69 | super.onCreate(savedInstanceState);
70 | setContentView(R.layout.activity_chat);
71 |
72 | //设置头部标题栏
73 | Toolbar toolbar = findViewById(R.id.toolbar);
74 | toolbar.setTitle(title);
75 | setSupportActionBar(toolbar);
76 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
77 |
78 | //获取用户信息,这里没有做用户权限的判定
79 | BmobUser user= BmobUser.getCurrentUser();
80 | if(user!=null)
81 | username = user.getUsername();
82 |
83 | //初始化view
84 | recyclerView = findViewById(R.id.msg_recycler_view);
85 | messageEditText = findViewById(R.id.message_edit_text);
86 | //输入框获取光标
87 | messageEditText.requestFocus();
88 | sendButton = findViewById(R.id.send_bt);
89 | sendButton.setOnClickListener(this);
90 | ImageButton clear_bt = findViewById(R.id.clearSession);
91 | clear_bt.setOnClickListener(this);
92 | ImageButton keyboard_bt = findViewById(R.id.keyboardbt);
93 | keyboard_bt.setOnClickListener(this);
94 | ImageButton voice_bt = findViewById(R.id.voicebt);
95 | voice_bt.setOnClickListener(this);
96 |
97 | //设置prompt信息
98 | if(prompt!=null && !prompt.isEmpty())
99 | BmobApp.bmobAI.setPrompt(prompt);
100 |
101 | //加载历史聊天记录
102 | initHistoryChatList();
103 | }
104 |
105 | /**
106 | * 初始化历史的聊天记录
107 | */
108 | private void initHistoryChatList(){
109 | //添加开场白
110 | Message start = new Message(startMsg, Message.SEND_BY_BOT,session,username);
111 | messageList.add(0,start);
112 |
113 | //初始化AI内容问答存储
114 | BmobQuery query = new BmobQuery<>();
115 | query.addWhereEqualTo("username",username);
116 | query.addWhereEqualTo("session",session);
117 | query.findObjects(new FindListener() {
118 | @Override
119 | public void done(List list, BmobException e) {
120 | if(e==null && list!=null){
121 | messageList.addAll(list);
122 | }
123 |
124 | chatAdapter = new ChatAdapter(messageList,logo);
125 | recyclerView.setAdapter(chatAdapter);
126 | LinearLayoutManager llm = new LinearLayoutManager(getApplicationContext());
127 | llm.setStackFromEnd(true);
128 | recyclerView.setLayoutManager(llm);
129 | }
130 | });
131 | }
132 |
133 | /**
134 | * 支持流的形式呈现内容到界面
135 | * @param s
136 | */
137 | public void addToLastMessage(String s)
138 | {
139 | runOnUiThread(new Runnable() {
140 | @Override
141 | public void run() {
142 | if(messageList.size()<=0) return;
143 | Message message = messageList.get(messageList.size()-1);
144 |
145 | if(message.getSendBy()==Message.SEND_BY_ME){
146 | Message newmessage = new Message(s,Message.SEND_BY_BOT,session,username);
147 | messageList.add(newmessage);
148 | recyclerView.smoothScrollToPosition(chatAdapter.getItemCount());
149 | }else{
150 | message.setMessage(message.getMessage() + s);
151 | recyclerView.smoothScrollToPosition(chatAdapter.getItemCount());
152 | }
153 |
154 | //更新界面
155 | chatAdapter.notifyDataSetChanged();
156 | }
157 | });
158 | }
159 |
160 | /**
161 | * 一次性将全部内容呈现到界面
162 | * @param message
163 | * @param sendBy
164 | */
165 | void addToChat(String message,String sendBy){
166 | runOnUiThread(new Runnable() {
167 | @Override
168 | public void run() {
169 | Message msg = new Message(message,sendBy,session,username);
170 | //存储到Bmob后端云上面
171 | msg.save(new SaveListener() {
172 | @Override
173 | public void done(String s, BmobException e) {
174 |
175 | }
176 | });
177 |
178 | //添加到本地
179 | messageList.add(msg);
180 | //更新界面
181 | chatAdapter.notifyDataSetChanged();
182 | recyclerView.smoothScrollToPosition(chatAdapter.getItemCount());
183 | }
184 | });
185 | }
186 |
187 | /**
188 | * 清除会话信息
189 | */
190 | void ClearSession(){
191 | //内置的清空会话
192 | BmobApp.bmobAI.Clear(session);
193 | //清空界面信息
194 | messageList.clear();
195 | chatAdapter.notifyDataSetChanged();
196 | //真实进行删除操作
197 | Message message = new Message();
198 | BmobQuery query = new BmobQuery<>();
199 | query.addWhereEqualTo("username",username);
200 | query.addWhereEqualTo("session",session);
201 | query.findObjects(new FindListener() {
202 | @Override
203 | public void done(List list, BmobException e) {
204 | if(e==null && list!=null){
205 | for (int i=0;i() {
267 | @Override
268 | public void done(String s, BmobException e) {
269 | }
270 | });
271 |
272 | sendButton.setEnabled(true);
273 | }
274 |
275 | @Override
276 | public void onError(String s) {
277 | //OpenAI的密钥错误或者超过OpenAI并发时,会返回这个错误,你也可以toast这个信息给用户
278 | Log.d("ai",s);
279 | sendButton.setEnabled(true);
280 | }
281 |
282 | @Override
283 | public void onClose() {
284 | //连接关闭了
285 | Log.d("ai","close");
286 | sendButton.setEnabled(true);
287 | }
288 | });
289 | }
290 | //切换对话方式为语音对话
291 | else if (v.getId()==R.id.keyboardbt){
292 | RelativeLayout key = findViewById(R.id.bottom_layout);
293 | key.setVisibility(View.VISIBLE);
294 |
295 | RelativeLayout voice = findViewById(R.id.bottom_layout_voice);
296 | voice.setVisibility(View.INVISIBLE);
297 | }
298 | //切换对话方式为文字对话
299 | else if(v.getId()==R.id.voicebt){
300 | RelativeLayout key = findViewById(R.id.bottom_layout);
301 | key.setVisibility(View.INVISIBLE);
302 |
303 | RelativeLayout voice = findViewById(R.id.bottom_layout_voice);
304 | voice.setVisibility(View.VISIBLE);
305 | }
306 | }
307 | }
--------------------------------------------------------------------------------