Android安卓毕业设计,SpringBoot+MySQL+Android studio 实现一个二手交易平台APP
Android安卓二手交易APP,使用Android+springboot+MySQL开发,集成第三方即时聊天。
·
Android毕业设计 Android 使用Java+kotlin 语言 后端使用 Java+springBoot 、mybatis、 mySQL,sqlite
源码可以出售,需要的私信。
主要实现的功能有:
(1)注册与登录,修改重置密码。
(2)浏览展示物品信息 、社区、轮播图、资讯、内容。
(3)发布二手物品、加入购物车、点赞、收藏、关注、留言、详聊。
(4)社区,可以点赞、评论回复或者买卖双方建立即时聊天。
(5)个人中心实现查看、管理关注、收藏、点赞、交易、消息、反馈、版本更新、浏览记录、个人信息管理。
贴出部分界面截图及主要代码。
1.1欢迎、登录界面
1.2 重置密码
实现重置密码的功能 模拟验证码 由后端发送。
4商品首页
商品详情
社区
社区详情
我的
浏览记录
侧边栏
修改位置
版本更新
贴出部分主要代码
登录loginActivity 的主要代码
class LoginActivity : BaseActivity() {
private var username: String=""
private var password: String=""
private lateinit var sqLiteHelper: SQLiteHelper
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
sqLiteHelper= SQLiteHelper(this)
getUser()
login_username_edittext.addTextChangedListener(
object : TextWatcher {
override fun beforeTextChanged(
s: CharSequence,
start: Int,
count: Int,
after: Int
) {
}
override fun onTextChanged(
s: CharSequence,
start: Int,
before: Int,
count: Int
) {
}
override fun afterTextChanged(s: Editable) {
if(login_username_edittext.text.toString()!=username){
remember_password.setChecked(false)
login_password_edittext.setText("")
}
}
}
)
login_forget.setOnClickListener {
startActivity(Intent(this,ForgetActivity::class.java))
}
login_regeist.setOnClickListener {
startActivity(Intent(this,RegistActivity::class.java))
}
remember_password.setOnClickListener {
if (TextUtils.isEmpty(login_username_edittext.text.toString())||TextUtils.isEmpty(login_password_edittext.text.toString())){
toast(getString(R.string.inputnameandpass))
remember_password.setChecked(false)
}
else{
if (remember_password.isChecked){
// toast(getString(R.string.remember))
addUser()
}
else{
deleteUser()
toast("取消记住密码")
}
}
}
login_login.setOnClickListener {
FunctionUtil.throttle(3000){
if(TextUtils.isEmpty(login_username_edittext.text.toString())){
toast(getString(R.string.namenull))
return@throttle
}
if(TextUtils.isEmpty(login_password_edittext.text.toString())){
toast(getString(R.string.passnull))
return@throttle
}
var map = HashMap<String,String>()
map.put("username",login_username_edittext.text.toString().trim())
if(login_username_edittext.text.toString().trim().equals("admin"))
{
map.put("password", login_password_edittext.text.toString().trim())
}
else{
//使用MD5方式加密密码
map.put("password", Md5AndSha1.md5(login_password_edittext.text.toString().trim()))
}
//提交登录
RetrofitTools.post("login",map, com.ygh.yiwu.ui.userinfo.model.User::class.java,object :RetrofitTools.IRetrofitResponse{
override fun <T> success(succ: T) {
if(TextUtils.isEmpty(succ.toString())){
toast(getString(R.string.errorNP))
return
}else{
//请求成功
var user = succ as com.ygh.yiwu.ui.userinfo.model.User
if(user.userid>0){
//登陆成功
//toast("登录成功")
MyApplication.user = user
getToken()
/*延时5秒,关闭LoginActivity*/
Timer().schedule(3000){
finish()
}
}
else{
//失败
toast(getString(R.string.errorNP))
}
}
}
override fun failure(msg: String) {
//请求失败
toast(getString(R.string.errorNET))
}
})
}
}
}
fun getUser(){
val userList =sqLiteHelper.getUser()
if (userList.isNotEmpty()){
username=userList[userList.size-1].username
password=userList[userList.size-1].password
remember_password.setChecked(true)
login_username_edittext.setText(username)
login_password_edittext.setText(password)
}
else{
remember_password.setChecked(false)
login_username_edittext.setText("")
login_password_edittext.setText("")
}
}
fun addUser(){
val username=login_username_edittext.text.toString()
val password=login_password_edittext.text.toString()
if(!TextUtils.isEmpty(login_username_edittext.text.toString())&&!TextUtils.isEmpty(login_password_edittext.text.toString())){
val user=UserModel(username = username, password = password)
val status=sqLiteHelper.insertUser(user)
if(status>-1){
toast(getString(R.string.rempass))
}
else{
toast(getString(R.string.errorrempass))
}
}
else{
toast(getString(R.string.inputnull))
}
}
fun deleteUser(){
val username=login_username_edittext.text.toString()
sqLiteHelper.deleteUser(username)
}
}
2.物品发布主要代码
class InsertGoodsActivity : BaseActivity() {
var parts = ArrayList<MultipartBody.Part>()
var urls:String=""
var goodstypeid = "0"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_insert_goods)
TongJi()
tongji_head_text.setText("发布商品")
goodstypeid = intent.getStringExtra("goodstypeid")!!
selectCamera.setOnClickListener {
var intent = Intent(applicationContext, TakeActivity::class.java)
intent.putExtra("takephoto", 5)
startActivityForResult(intent, 0x123)
}
submit_fornum.setOnClickListener {
FunctionUtil.throttle(5000){
if(TextUtils.isEmpty(insert_goods_title.text)){
toast("给商品取一个好的标题吧!")
// return@setOnClickListener
}
if (TextUtils.isEmpty(insert_goods_content.text)){
toast("详细介绍一下商品更容易卖出哦!")
// return@setOnClickListener
}
getdata(parts,insert_goods_content.text.toString())
}
}
}
//提交数据
fun getdata(parts:List<MultipartBody.Part>,content:String){
var map = HashMap<String,String>();
map.put("content",content)
map.put("title",insert_goods_title.text.toString())
map.put("userid", MyApplication.user.userid!!.toString())
map.put("oldprice", insert_goods_oldprice.text.toString())
map.put("price", insert_goods_price.text.toString())
map.put("stock", insert_goods_stock.text.toString())
map.put("remark1", insert_goods_remark1.text.toString())
map.put("goodstypeid", goodstypeid)
RetrofitTools.upload("insertGoods",map,parts,object: RetrofitTools.IRetrofitResponse{
override fun <T> success(succ: T) {
if("true".equals(succ.toString())){
toast("添加成功")
finish();
}else{
toast("添加失败")
}
}
override fun failure(msg: String) {
toast(getString(R.string.errorNET))
}
})
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == 0x123) {
var timgs = data!!.getSerializableExtra("results") as List<TImage>;
var cameras = ArrayList<String>();
for (item in timgs) {
cameras.add(item.originalPath)
var file = File(item.originalPath);
var requestFile: RequestBody =
RequestBody.create(MediaType.parse("multipart/form-data"), file);
var body: MultipartBody.Part =
MultipartBody.Part.createFormData("picture", file.getName(), requestFile);
parts.add(body)
urls = "${urls}#${file.name}"
}
insert_fornum_imageview.setList(cameras)
}
}
}
物品详情的主要代码
class GoodsInfoActivity : BaseActivity() {
lateinit var goods: com.ygh.yiwu.ui.goods.model.Goods;
@SuppressLint("SetTextI18n")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_goods_info)
TongJi()
tongji_head_text.setText("商品详情")
getdata()
goods = intent.getSerializableExtra("goods") as com.ygh.yiwu.ui.goods.model.Goods
insertRecords(goods.goodsid.toString())
var images = ArrayList<String>()
var pics = String()
pics=goods.pic
var pictures = listOf<String>()
pictures=pics.split("#")
for (i in pictures.indices){
images.add(MyApplication.hostFile+pictures[i])
}
goodsinfo_detail_iv.setDelayTime(2000);
goodsinfo_detail_iv.setImages(images.toMutableList()).setImageLoader(com.ygh.yiwu.utils.GlideImageLoader()).start()
goodsinfo_detail_stock.setText("剩余:${goods.stock}件")
goodsinfo_detail_content.setText(goods.content)
if (goods.remark1==null||goods.remark1=="0"){
goodsinfo_detail_remark1.setText("不支持退换")
}else{
goodsinfo_detail_remark1.setText("支持${goods.remark1}天内退换")
}
goodsinfo_detail_price.setText("¥${goods.price}")
goodsinfo_old_price.setText("原价¥${goods.oldprice}")
goodsinfo_old_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG)//原价添加删除线
Glide.with(applicationContext).load(MyApplication.hostFile+goods.user.headPic).error(R.drawable.nopic).into(user_headpic)
user_nickname.setText("发布人:${ goods.user.nickname }")
user_address.setText("来自:${ goods.user.address }")
//toast(goods.user.nickname.toString())
//如果是自己发布的,隐蔽购物车和聊一聊和关注功能
if (goods.userid==MyApplication.user.userid){
goods_info_user.visibility = View.GONE
check_goodsinfo_order.visibility = View.GONE
attention.visibility=View.GONE
}
//关注
attention.setOnClickListener {
if (f!=0){
CircleDialog.Builder(this@GoodsInfoActivity)
.setTitle("提示")
.setText("是否要关注TA?")
.setPositive("确定", {
//toast("已关注!")
var map = HashMap<String,String>()
map.put("my_userid", MyApplication.user.userid.toString())
map.put("userid",goods.userid.toString())
RetrofitTools.get("insertAttention", map, String::class.java, object : RetrofitTools.IRetrofitResponse {
override fun <T> success(succ: T) {
if ("true".equals(succ)) {
toast("已关注!")
getdata()
} else {
toast("失败")
}
}
override fun failure(msg: String) {
toast("网络连接失败")
}
},
false
)
})
.setNegative("取消", null)
.show()
}
}
//我要留言
goodsinfo_discuss.setOnClickListener {
CircleDialog.Builder(this@GoodsInfoActivity)
.setTitle("留言")
.setInputHint("请输入留言内容")
.setPositiveInput("确定",object: OnInputClickListener {
override fun onClick(text: String?, v: View?) {
if (TextUtils.isEmpty(text)){
toast("内容不能为空")
return;
}
insertData(goods.goodsid.toString(),text!!)
}
})
.setNegative("取消", null)
.show()
}
//查看留言
check_goodsinfo_discuss.setOnClickListener {
var intent = Intent(this, ShowdiscussActivity::class.java)
intent.putExtra("movieid",goods.goodsid.toString())
startActivity(intent)
}
//我要收藏
check_goodsinfo_cang.setOnClickListener {
CircleDialog.Builder(this)
.setTitle("提示")
.setText("是否确定要收藏?")
.setPositive("确定", {
insertCang(goods.goodsid.toString());
})
.setNegative("取消", null)
.show()
}
//我要点赞
check_goodsinfo_praise.setOnClickListener {
CircleDialog.Builder(this)
.setTitle("提示")
.setText("是否确定要点赞?")
.setPositive("确定", {
insertPraise(goods.goodsid.toString());
})
.setNegative("取消", null)
.show()
}
//加入购物车
check_goodsinfo_order.setOnClickListener {
CircleDialog.Builder(this)
.setTitle("提示")
.setText("你确定要加入购物车吗?")
.setPositive("确定", {
insertshoppingcar(goods.goodsid.toString());
})
.setNegative("取消",null)
.show()
}
//聊一聊
goods_info_user.setOnClickListener {
var map1 = HashMap<String, String>();//
map1.put("userid", goods.userid.toString())
var map = HashMap<String, String>()
var i:Int=0
var map2 = HashMap<String, String>()
map2.put("username",MyApplication.user.username)
map2.put("nickname",MyApplication.user.nickname)
map2.put("friendusername",goods.user.username)
map2.put("friendnickname",goods.user.nickname)
map2.put("headpic",goods.user.headPic)
RetrofitTools.post("getAllUserNameByUserid",map1, com.ygh.yiwu.ui.userinfo.model.User::class.java,object :RetrofitTools.IRetrofitResponse{
override fun <T> success(succ: T) {
var users = succ as List<com.ygh.yiwu.ui.userinfo.model.User>
users.forEach {
map.put("username",it.username)
i=1
map.put("nickname",it.nickname)
}
// toast("${map.get("username").toString()}")
if (i==1){
var conversationType = Conversation.ConversationType.PRIVATE;
val uri =
Uri.parse("rong://" + applicationContext.getApplicationInfo().processName)
.buildUpon().appendPath("conversation")
.appendPath(conversationType.getName().toLowerCase(Locale.CHINA))
.appendQueryParameter("targetId",map.get("username").toString())
.appendQueryParameter("title", "username").build()
var intent = Intent("android.intent.action.VIEW", uri);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.putExtra("username",map.get("nickname").toString())
startActivity(intent)
getChatData(map2)//买方加卖家好友
}
}
override fun failure(msg: String) {
toast("获取数据失败")
}
})
}
}
fun getChatData(map: HashMap<String, String>) {
var flag =true
var map1 = HashMap<String,String>()
map1.put("username", map.get("username").toString())
RetrofitTools.post(
"getAllChatByUsername",map1,
com.ygh.yiwu.ui.userinfo.model.Chat::class.java,
object : RetrofitTools.IRetrofitResponse {
override fun <T> success(succ: T) {
var news = succ as ArrayList<com.ygh.yiwu.ui.userinfo.model.Chat>;
news.forEach {
if (it.friendusername==goods.user.username)
{
flag=false
}
}
if(flag==true){
insertChat(map)
}
}
override fun failure(msg: String) {
toast(getString(R.string.errorNET));
}
})
}
fun insertChat(map: HashMap<String, String>){
RetrofitTools.get("insertChat", map, String::class.java, object : RetrofitTools.IRetrofitResponse {
override fun <T> success(succ: T) {
}
override fun failure(msg: String) {
toast("网络连接失败")
}
},
false
)
}
fun insertCang(targetid:String) {
var map1 = HashMap<String, String>();//map1 main insertCang data
map1.put("targetid", targetid)
map1.put("userid", MyApplication.user.userid.toString())
if (i==6||j==0){
RetrofitTools.get("insertCang", map1, String::class.java, object : RetrofitTools.IRetrofitResponse {
override fun <T> success(succ: T) {
if ("true".equals(succ)) {
toast("收藏成功!")
getdata()
} else {
toast("收藏失败")
}
}
override fun failure(msg: String) {
toast("加入收藏失败")
}
},
false
)}
if (i==0){
toast("重复收藏!")
}
if (i==1){
toast("该商品已下架!")
}
}
fun insertRecords(goodsid:String) {
var map = HashMap<String,String>()
map.put("userid", MyApplication.user.userid.toString())
map.put("goodsid", goodsid)
RetrofitTools.get("insertRecords", map, String::class.java, object : RetrofitTools.IRetrofitResponse {
override fun <T> success(succ: T) {
if ("true".equals(succ)) {
// toast("已添加!")
//getdata()
} else {
// toast("失败")
}
}
override fun failure(msg: String) {
toast(getString(R.string.errorNET))
}
},
false
)
}
fun getdata() {
var map = HashMap<String,String>()
map.put("userid",MyApplication.user.userid.toString())
map.put("remark1", "goods")
var map1 = HashMap<String,String>()
map1.put("userid",MyApplication.user.userid.toString())
var map2 = HashMap<String,String>()
map2.put("my_userid",MyApplication.user.userid.toString())
RetrofitTools.post("getAllPraiseByUseridAndRemark",map, com.ygh.yiwu.ui.praise.Praise::class.java,object :RetrofitTools.IRetrofitResponse{
override fun <T> success(succ: T) {
var praises = succ as List<com.ygh.yiwu.ui.praise.Praise>;
if (praises.isEmpty()){ c=0} // 点赞表空空如也
else{ c=1 }//点赞表不空
//判断是否点赞
praises.forEach{
if (it.targetid==goods.goodsid)// 物品重复点赞
{ d=0 }
if(goods.goodsid==0)
{d=1}
}
if (d==0){
check_goodsinfo_praise1.setImageResource(R.drawable.praise1)
check_goodsinfo_praise2.setText("已赞")
}
}
override fun failure(msg: String) {
toast("获取数据失败")
}
})
RetrofitTools.post("getTargetidByUserid",map1, com.ygh.yiwu.ui.cang.Cang::class.java,object :RetrofitTools.IRetrofitResponse{
override fun <T> success(succ: T) {
var cangs = succ as List<com.ygh.yiwu.ui.cang.Cang>;
if (cangs.isEmpty()){ j=0} // 收藏夹空空如也
else{ j=1 }//收藏夹不空
//判断是否收藏
cangs.forEach{
if (it.targetid==goods.goodsid)// 物品重复收藏
{ i=0 }
if(goods.goodsid==0)
{i=1}
}
if (i==0){
check_goodsinfo_cang1.setImageResource(R.drawable.shoucang1)
check_goodsinfo_cang2.setText("已收藏")
}
}
override fun failure(msg: String) {
toast("获取数据失败")
}
})
RetrofitTools.post("getAllAttentionByMyUserid",map2, com.ygh.yiwu.ui.attention.model.Attention::class.java,object :RetrofitTools.IRetrofitResponse{
override fun <T> success(succ: T) {
var attentions = succ as List<com.ygh.yiwu.ui.attention.model.Attention>;
if (attentions.isEmpty()){ e=0} // 关注空空如也
else{ e=1 }//不空
//判断是否关注
attentions.forEach{
// toast(it.user.nickname)
if (it.userid==goods.userid)// 重复
{ f=0 }
}
if (f==0){
attention.setText("已关注")
}
}
override fun failure(msg: String) {
toast("获取数据失败")
}
})
}
fun insertPraise(targetid:String) {
var map1 = HashMap<String, String>();//map1 main insertCang data
map1.put("targetid", targetid)
map1.put("userid", MyApplication.user.userid.toString())
map1.put("remark1", "goods")
if (d==6||c==0){
RetrofitTools.get("insertPraise", map1, String::class.java, object : RetrofitTools.IRetrofitResponse {
override fun <T> success(succ: T) {
if ("true".equals(succ)) {
toast("点赞成功!")
getdata()
} else {
toast("点赞失败")
}
}
override fun failure(msg: String) {
toast("点赞失败")
}
},
false
)}
if (d==0){
toast("重复点赞!")
}
if (d==1){
toast("该商品已下架!")
}
}
//发布评论
fun insertData(sid: String, content: String) {
var map1 = HashMap<String,String>() //map1 main getallcangbyuserid data
map1.put("userid",MyApplication.user.userid.toString())
RetrofitTools.post("getTargetidByUserid",map1, com.ygh.yiwu.ui.cang.Cang::class.java,object :RetrofitTools.IRetrofitResponse{
override fun <T> success(succ: T) {
var cangs = succ as List<com.ygh.yiwu.ui.cang.Cang>;
//判断是否为收藏中的商品
cangs.forEach{
if(goods.goodsid==0)//判断该商品是否下架
{k=0}
}
if (k==0){
toast("该商品已下架!")
}
else{
var map = HashMap<String, String>();
map.put("targetid", sid)
map.put("userid", MyApplication.user.userid!!.toString())
map.put("content", content)
map.put("remark1", "goods")
RetrofitTools.get("insertDiscuss", map, String::class.java, object : RetrofitTools.IRetrofitResponse {
override fun <T> success(succ: T) {
toast("发布成功")
}
override fun failure(msg: String) {
toast("发布失败")
}
})
}
}
override fun failure(msg: String) {
toast("获取数据失败")
}
})
}
fun insertshoppingcar(targetid:String) {
var map1= HashMap<String,String>() //map main getallcangbyuserid data
map1.put("userid",MyApplication.user.userid.toString())
map1.put("targetid", targetid)
map1.put("count","1")
var map = HashMap<String,String>() //map main getallcangbyuserid data
map.put("userid",MyApplication.user.userid.toString())
// map2.put("targetid", targetid)
RetrofitTools.post("getTargetidByUserid",map, com.ygh.yiwu.ui.cang.Cang::class.java,object :RetrofitTools.IRetrofitResponse{
override fun <T> success(succ: T) {
var cangs = succ as List<com.ygh.yiwu.ui.cang.Cang>;
//判断是否为收藏中的商品
cangs.forEach{
if(goods.goodsid==0)//判断该商品是否下架
{k=0}
}
if (k==0){
toast("该商品已下架!")
}
else{
//判断一下是否曾加入购物车
RetrofitTools.post("getscTargetidByUserid",map,com.ygh.yiwu.ui.shoppingcar.Shoppingcar::class.java,object :RetrofitTools.IRetrofitResponse{
override fun <T> success(succ: T) {
var shoppingcars= succ as List<Shoppingcar>;
//购物车为空
if (shoppingcars.isEmpty())
{
b=0
RetrofitTools.get("insertShoppingcar", map1, String::class.java, object : RetrofitTools.IRetrofitResponse {
override fun <T> success(succ: T) {
if ("true".equals(succ)) {
toast("加入成功")
} else {
toast("加入失败")
}
}
override fun failure(msg: String) {
toast("加入购物车失败")
}
}, false)
}
//购物车已存在该物品,只需数量再加一即可
shoppingcars.forEach {
if (it.targetid==goods.goodsid)
{
// 该物品存在,且数量不超过库存,数量加一
a=0
if (it.count<goods.stock){
var newcount= it.count+1
updateShoppingcar( it.shoppingcarid,newcount )
}
else {
toast("已添加至库存上限!")
}
}
}
if (a==6&&b==6){
RetrofitTools.get("insertShoppingcar", map1, String::class.java, object : RetrofitTools.IRetrofitResponse {
override fun <T> success(succ: T) {
if ("true".equals(succ)) {
toast("加入成功")
} else {
toast("加入失败")
}
}
override fun failure(msg: String) {
toast("加入购物车失败")
}
}, false)
}
}
override fun failure(msg: String) {
}
})
}
}
override fun failure(msg: String) {
toast("获取数据失败")
}
})
}
fun updateShoppingcar(shoppingcarid :Int, newcounts : Int){
var map = HashMap<String,String>();
map.put("shoppingcarid",shoppingcarid.toString())
map.put("count", newcounts.toString())
RetrofitTools.get("updateShoppingcar",map,String::class.java,object :RetrofitTools.IRetrofitResponse{
override fun <T> success(succ: T) {
if ("true".equals(succ)){
toast("加入成功")
}
else{
toast("加入失败")
}
}
override fun failure(msg: String) {
toast(getString(R.string.errorNET))
}
},false)
}
}
更多推荐
已为社区贡献1条内容
所有评论(0)