注册bug修复

This commit is contained in:
zhangsan 2024-05-22 18:50:49 +08:00
parent f7173bcbd4
commit e2b02eee1e
17 changed files with 239 additions and 155 deletions

26
README.md Normal file
View File

@ -0,0 +1,26 @@
## 如何运行本项目?
### 法一(推荐):
### 法二
1. 下载2022版本的android studio(老旧版本可能出现bug)
![屏幕截图 2024-05-22 163356](D:\folder\study\JianShu\mdfile_pic\屏幕截图 2024-05-22 163356.png)
2. android studio内置各种安卓模拟机需要首先打开Device Manager下载建议下载Pixel 5 API30下载模拟机可能耗时几分钟
![50e125560f05d7d05efbd30ab3059d3](D:\folder\study\JianShu\mdfile_pic\50e125560f05d7d05efbd30ab3059d3.png)
![屏幕截图 2024-05-22 164310](D:\folder\study\JianShu\mdfile_pic\屏幕截图 2024-05-22 164310.png)
![屏幕截图 2024-05-22 164348](D:\folder\study\JianShu\mdfile_pic\屏幕截图 2024-05-22 164348.png)
3. 导入本项目点击根目录JianShu
![屏幕截图 2024-05-22 164628](D:\folder\study\JianShu\mdfile_pic\屏幕截图 2024-05-22 164628.png)
4. Gradle会自动导入依赖下载本项目所依赖的文件若android studio右下角停止加载则说明项目导入成功第一次加载时间可能比较长
![image-20240522164840554](C:\Users\zhangsan\AppData\Roaming\Typora\typora-user-images\image-20240522164840554.png)
如果意外中断了可以在Android Studio中点击`File > Sync Project with Gradle Files`
5. 运行项目第一次运行会在模拟机上安卓该app
![a5d83c0db4d39a9222c9fe7af580e1e](D:\folder\study\JianShu\mdfile_pic\a5d83c0db4d39a9222c9fe7af580e1e.png)
6. 出现登录界面则成功
<img src="C:\Users\zhangsan\AppData\Roaming\Typora\typora-user-images\image-20240522165431074.png" alt="image-20240522165431074" style="zoom:80%;" />

BIN
app/release/app-release.apk Normal file

Binary file not shown.

View File

@ -0,0 +1,20 @@
{
"version": 3,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "edu.whut.jianshu",
"variantName": "release",
"elements": [
{
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 1,
"versionName": "1.0",
"outputFile": "app-release.apk"
}
],
"elementType": "File"
}

View File

@ -37,7 +37,7 @@ class MyActivity : AppCompatActivity() {
tUserName.text=p.nickName tUserName.text=p.nickName
tUserSignature.text=p.signature tUserSignature.text=p.signature
Glide.with(this@MyActivity) // 传入 Context Glide.with(this@MyActivity) // 传入 Context
.load(p.face.url) // 加载图片的 URL .load(p.face?.url ?: "https://bmob-cdn-31452.bmobpay.com/2024/04/30/6f0e4b19405153ed80f2f1bdfa10da0b.png") // 加载图片的 URL如果 face 为 null 使用默认 URL
.placeholder(R.drawable.pre_load) // 设置占位图 .placeholder(R.drawable.pre_load) // 设置占位图
.error(R.drawable.fail_load) // 设置加载失败时显示的图片 .error(R.drawable.fail_load) // 设置加载失败时显示的图片
.into(iv_avatar) // 将图片加载到指定的 ImageView 中 .into(iv_avatar) // 将图片加载到指定的 ImageView 中

View File

@ -7,6 +7,7 @@ import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import cn.bmob.v3.Bmob import cn.bmob.v3.Bmob
import cn.bmob.v3.BmobQuery import cn.bmob.v3.BmobQuery
import cn.bmob.v3.datatype.BmobFile
import cn.bmob.v3.exception.BmobException import cn.bmob.v3.exception.BmobException
import cn.bmob.v3.listener.FindListener import cn.bmob.v3.listener.FindListener
import cn.bmob.v3.listener.SaveListener import cn.bmob.v3.listener.SaveListener
@ -18,100 +19,112 @@ class RegisterActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_register) setContentView(R.layout.activity_register)
inits() Bmob.initialize(this, "8f9f1d1ea520b0ce4f84a6fa83a5f754")
initViews()
} }
private fun inits() { private fun initViews() {
image_backtoLogin.setOnClickListener{ image_backtoLogin.setOnClickListener {
val intent=Intent(this,LoginActivity::class.java) startActivity(Intent(this, LoginActivity::class.java))
startActivity(intent)
finish() finish()
} }
button_check.setOnClickListener { button_check.setOnClickListener {
var flag: Boolean = false checkAccountAvailability()
val use_account: String = et_reg_account.text.toString()
Log.d("zhangyu", use_account)
val bmobQuery = BmobQuery<User_bmob>()
// bmobQuery.addWhereEqualTo("account", use_account)
bmobQuery.findObjects(object : FindListener<User_bmob>() {
override fun done(list: List<User_bmob>, e: BmobException?) {
if (e == null) {
for (i in list) {
if (use_account.equals(i.account)) {
Toast.makeText(this@RegisterActivity, "账号已注册!", Toast.LENGTH_SHORT)
.show()
flag=true
}
}
if(flag!=true)
Toast.makeText(this@RegisterActivity,"可以注册",Toast.LENGTH_SHORT).show()
}
}
})
} }
bt_reg_register.setOnClickListener { bt_reg_register.setOnClickListener {
var sex: String = "" registerUser()
if (rg_reg_man.isChecked)
sex = ""
else if (rg_reg_woman.isChecked)
sex = ""
else
sex = "未知"
val user = User_bmob()
val use_account: String = et_reg_account.text.toString()
val use_pwd: String = et_reg_pwd.text.toString()
val use_agapwd: String = et_reg_agapwd.text.toString()
val use_name: String = et_reg_name.text.toString()
val use_mail: String = et_reg_email.text.toString()
val use_phone: String = et_reg_phone.text.toString()
val bmobQuery = BmobQuery<User_bmob>()
bmobQuery.findObjects(object : FindListener<User_bmob>() {
override fun done(list: List<User_bmob>, e: BmobException?) {
if (e == null) {
for (i in list) {
if (use_account.equals(i.account)) {
Toast.makeText(this@RegisterActivity, "账号已注册!", Toast.LENGTH_SHORT)
.show()
}
}
}
}
})
if (use_account.isEmpty() || use_pwd.isEmpty() || use_agapwd.isEmpty())
Toast.makeText(this, "账号或密码不能为空白!", Toast.LENGTH_SHORT).show()
if (use_mail.isEmpty())
Toast.makeText(this, "邮箱不能为空白!", Toast.LENGTH_SHORT).show()
else if (use_agapwd != use_pwd) {
Toast.makeText(this, "两次密码输入不一致!", Toast.LENGTH_SHORT).show()
}
else {
user.setaccount(use_account)
user.setpassword(use_pwd)
user.setemail(use_mail)
user.setnickName(use_name)
user.setphone(use_phone)
user.setsex(sex)
user.save(object : SaveListener<String>() {
override fun done(objectId: String?, e: BmobException?) {
if (e == null) {
Toast.makeText(
this@RegisterActivity,
objectId + "注册成功!",
Toast.LENGTH_SHORT
).show()
} else {
Toast.makeText(
this@RegisterActivity,
"注册失败!" + e.message,
Toast.LENGTH_SHORT
).show()
}
}
})
val intent = Intent(this, LoginActivity::class.java)
startActivity(intent)
finish()
}
} }
} }
private fun checkAccountAvailability() {
val account = et_reg_account.text.toString().trim()
if (account.isEmpty()) {
Toast.makeText(this, "账号不能为空", Toast.LENGTH_SHORT).show()
return
}
val query = BmobQuery<User_bmob>()
query.addWhereEqualTo("account", account)
query.findObjects(object : FindListener<User_bmob>() {
override fun done(users: List<User_bmob>, e: BmobException?) {
if (e == null) {
if (users.isNotEmpty()) {
Toast.makeText(this@RegisterActivity, "账号已注册!", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(this@RegisterActivity, "可以注册", Toast.LENGTH_SHORT).show()
}
} else {
Toast.makeText(this@RegisterActivity, "检查失败: ${e.message}", Toast.LENGTH_SHORT).show()
}
}
})
}
private fun registerUser() {
val account = et_reg_account.text.toString().trim()
val password = et_reg_pwd.text.toString().trim()
val confirmPassword = et_reg_agapwd.text.toString().trim()
val email = et_reg_email.text.toString().trim()
val name = et_reg_name.text.toString().trim()
val phone = et_reg_phone.text.toString().trim()
val sex = when {
rg_reg_man.isChecked -> ""
rg_reg_woman.isChecked -> ""
else -> "未知"
}
if (account.isEmpty() || password.isEmpty() || confirmPassword.isEmpty()) {
Toast.makeText(this, "账号或密码不能为空白!", Toast.LENGTH_SHORT).show()
return
}
if (email.isEmpty()) {
Toast.makeText(this, "邮箱不能为空白!", Toast.LENGTH_SHORT).show()
return
}
if (password != confirmPassword) {
Toast.makeText(this, "两次密码输入不一致!", Toast.LENGTH_SHORT).show()
return
}
val query = BmobQuery<User_bmob>()
query.addWhereEqualTo("account", account)
query.findObjects(object : FindListener<User_bmob>() {
override fun done(users: List<User_bmob>, e: BmobException?) {
if (e == null) {
if (users.isNotEmpty()) {
Toast.makeText(this@RegisterActivity, "账号已注册!", Toast.LENGTH_SHORT).show()
} else {
saveUser(account, password, email, name, phone, sex)
}
} else {
Toast.makeText(this@RegisterActivity, "检查失败: ${e.message}", Toast.LENGTH_SHORT).show()
}
}
})
}
private fun saveUser(account: String, password: String, email: String, name: String, phone: String, sex: String) {
val user = User_bmob().apply {
setaccount(account)
setpassword(password)
setemail(email)
setnickName(name)
setphone(phone)
setsex(sex)
}
user.save(object : SaveListener<String>() {
override fun done(objectId: String?, e: BmobException?) {
if (e == null) {
Toast.makeText(this@RegisterActivity, "注册成功!", Toast.LENGTH_SHORT).show()
startActivity(Intent(this@RegisterActivity, LoginActivity::class.java))
finish()
} else {
Toast.makeText(this@RegisterActivity, "注册失败: ${e.message}", Toast.LENGTH_SHORT).show()
}
}
})
}
} }

View File

@ -107,7 +107,7 @@ class sendPerceptionActivity:AppCompatActivity() {
if (e == null) { if (e == null) {
user?.let { user?.let {
Glide.with(this@sendPerceptionActivity) // 传入 Context Glide.with(this@sendPerceptionActivity) // 传入 Context
.load(it.face.url) // 加载图片的 URL .load(it.face?.url ?: "https://bmob-cdn-31452.bmobpay.com/2024/04/30/6f0e4b19405153ed80f2f1bdfa10da0b.png") // 加载图片的 URL
.placeholder(R.drawable.pre_load) // 设置占位图 .placeholder(R.drawable.pre_load) // 设置占位图
.error(R.drawable.fail_load) // 设置加载失败时显示的图片 .error(R.drawable.fail_load) // 设置加载失败时显示的图片
.into(send_avatar) // 将图片加载到指定的 ImageView 中 .into(send_avatar) // 将图片加载到指定的 ImageView 中

View File

@ -60,7 +60,7 @@ class MarkingAdapter(val markingList: List<Marking>) :
val userData = userList.first() val userData = userList.first()
holder.user_name.text = userData.nickName holder.user_name.text = userData.nickName
Glide.with(holder.itemView.context) Glide.with(holder.itemView.context)
.load(userData.face.url) .load(userData.face?.url ?: "https://bmob-cdn-31452.bmobpay.com/2024/04/30/6f0e4b19405153ed80f2f1bdfa10da0b.png")
.placeholder(R.drawable.pre_load) .placeholder(R.drawable.pre_load)
.error(R.drawable.fail_load) .error(R.drawable.fail_load)
.into(holder.user_Image) .into(holder.user_Image)

View File

@ -68,7 +68,7 @@ class PerceptionAdapter(val perceptionList: List<Perception>) :
val userData = userList.first() val userData = userList.first()
holder.perception_username.text = userData.nickName holder.perception_username.text = userData.nickName
Glide.with(holder.itemView.context) Glide.with(holder.itemView.context)
.load(userData.face.url) .load(userData.face?.url ?: "https://bmob-cdn-31452.bmobpay.com/2024/04/30/6f0e4b19405153ed80f2f1bdfa10da0b.png")
.placeholder(R.drawable.pre_load) .placeholder(R.drawable.pre_load)
.error(R.drawable.fail_load) .error(R.drawable.fail_load)
.into(holder.perception_userIcon) .into(holder.perception_userIcon)

View File

@ -3,63 +3,86 @@ package edu.whut.jianshu.Data.entity
import cn.bmob.v3.BmobObject import cn.bmob.v3.BmobObject
import cn.bmob.v3.datatype.BmobFile import cn.bmob.v3.datatype.BmobFile
class User_bmob:BmobObject(){ class User_bmob : BmobObject() {
var account:String="" var account: String = ""
var signature:String="" var signature: String = ""
var nickName:String="" var nickName: String = ""
var password:String="" var password: String = ""
var email:String="" var email: String = ""
var sex:String="" var sex: String = ""
var phone:String="" var phone: String = ""
var address:String="" var address: String = ""
var face:BmobFile=BmobFile() var face: BmobFile? = null
fun setaccount(account:String){
this.account=account fun setaccount(account: String) {
this.account = account
} }
fun getaccount():String{
fun getaccount(): String {
return this.account return this.account
} }
fun setsignature(signature:String){
this.signature=signature fun setsignature(signature: String) {
this.signature = signature
} }
fun getsignature():String{
fun getsignature(): String {
return this.signature return this.signature
} }
fun setnickName(nickName:String){
this.nickName=nickName fun setnickName(nickName: String) {
this.nickName = nickName
} }
fun getnickName():String{
fun getnickName(): String {
return this.nickName return this.nickName
} }
fun setpassword(password:String){
this.password=password fun setpassword(password: String) {
this.password = password
} }
fun getpassword():String{
fun getpassword(): String {
return this.password return this.password
} }
fun setemail(email:String){
this.email=email fun setemail(email: String) {
this.email = email
} }
fun getemail():String{
fun getemail(): String {
return this.email return this.email
} }
fun setsex(sex:String){
this.sex=sex fun setsex(sex: String) {
this.sex = sex
} }
fun getsex():String{
fun getsex(): String {
return this.sex return this.sex
} }
fun setphone(phone:String){
this.phone=phone fun setphone(phone: String) {
this.phone = phone
} }
fun getphone():String{
fun getphone(): String {
return this.phone return this.phone
} }
fun setaddress(address:String){
this.address=address fun setaddress(address: String) {
this.address = address
} }
fun getaddress():String{
fun getaddress(): String {
return this.address return this.address
} }
fun setface(face: BmobFile) {
this.face = face
}
fun getface(): BmobFile? {
return this.face
}
} }

View File

@ -1,11 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<LinearLayout <LinearLayout
android:id="@+id/activity_login" android:id="@+id/activity_login"
@ -42,19 +38,20 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="50dp" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">
<ImageView <ImageView
android:layout_width="35dp" android:layout_width="30dp"
android:layout_height="35dp" android:layout_height="30dp"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:src="@drawable/account" /> android:src="@drawable/account" />
<EditText <EditText
android:id="@+id/et_reg_account" android:id="@+id/et_reg_account"
android:layout_width="280dp" android:layout_width="280dp"
android:layout_height="48dp" android:layout_height="35dp"
android:layout_marginLeft="@dimen/s_dp_5"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:background="@drawable/edit_bg" android:background="@drawable/edit_bg"
android:hint="输入你的账号" /> android:hint="输入你的账号" />
@ -71,19 +68,20 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="50dp" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">
<ImageView <ImageView
android:layout_width="35dp" android:layout_width="30dp"
android:layout_height="35dp" android:layout_height="30dp"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:src="@drawable/account" /> android:src="@drawable/nickname" />
<EditText <EditText
android:id="@+id/et_reg_name" android:id="@+id/et_reg_name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="48dp" android:layout_marginLeft="@dimen/s_dp_5"
android:layout_height="35dp"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:background="@drawable/edit_bg" android:background="@drawable/edit_bg"
android:hint="输入你的昵称" /> android:hint="输入你的昵称" />
@ -112,13 +110,13 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="50dp" android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:orientation="horizontal"> android:orientation="horizontal">
<ImageView <ImageView
android:layout_width="35dp" android:layout_width="30dp"
android:layout_height="35dp" android:layout_height="30dp"
android:layout_marginTop="5dp" android:layout_marginTop="5dp"
android:src="@drawable/biji" /> android:src="@drawable/biji" />
@ -126,6 +124,7 @@
android:id="@+id/et_reg_pwd" android:id="@+id/et_reg_pwd"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="35dp" android:layout_height="35dp"
android:layout_marginLeft="@dimen/s_dp_5"
android:background="@drawable/edit_bg" android:background="@drawable/edit_bg"
android:hint="输入你的密码" android:hint="输入你的密码"
android:inputType="textPassword" /> android:inputType="textPassword" />
@ -133,12 +132,12 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="50dp" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">
<ImageView <ImageView
android:layout_width="35dp" android:layout_width="30dp"
android:layout_height="35dp" android:layout_height="30dp"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:src="@drawable/biji" /> android:src="@drawable/biji" />
@ -147,44 +146,47 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="35dp" android:layout_height="35dp"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:layout_marginLeft="@dimen/s_dp_5"
android:background="@drawable/edit_bg" android:background="@drawable/edit_bg"
android:hint="再次输入你的密码" android:hint="再次输入你的密码"
android:inputType="textPassword" /> android:inputType="textPassword" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="50dp" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">
<ImageView <ImageView
android:layout_width="35dp" android:layout_width="30dp"
android:layout_height="35dp" android:layout_height="30dp"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:src="@drawable/phone" /> android:src="@drawable/phone" />
<EditText <EditText
android:id="@+id/et_reg_phone" android:id="@+id/et_reg_phone"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="48dp" android:layout_height="35dp"
android:layout_marginLeft="@dimen/s_dp_5"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:background="@drawable/edit_bg" android:background="@drawable/edit_bg"
android:hint="输入你的手机号" /> android:hint="输入你的手机号" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="50dp" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">
<ImageView <ImageView
android:layout_width="35dp" android:layout_width="30dp"
android:layout_height="35dp" android:layout_height="30dp"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:src="@drawable/email" /> android:src="@drawable/email" />
<EditText <EditText
android:id="@+id/et_reg_email" android:id="@+id/et_reg_email"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="48dp" android:layout_height="35dp"
android:layout_marginLeft="@dimen/s_dp_5"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:background="@drawable/edit_bg" android:background="@drawable/edit_bg"
android:hint="输入你的邮箱" /> android:hint="输入你的邮箱" />
@ -195,6 +197,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp" android:layout_marginTop="20dp"
android:background="@drawable/edit_bg" android:background="@drawable/edit_bg"
android:text="提交" /> android:text="提交" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -1 +0,0 @@
安卓项目是面向用户的,目前数据库设计有点问题,应该“管理员”专门设置一个热门图书表和好评图书表,而不要用户自己来查图片