|
@@ -19,8 +19,6 @@ import androidx.recyclerview.widget.GridLayoutManager
|
|
|
import com.bumptech.glide.Glide
|
|
|
import com.example.devicemanager.view.ConfirmPopupWindow
|
|
|
import com.google.gson.Gson
|
|
|
-import com.goyourfly.multiple.adapter.MultipleSelect
|
|
|
-import com.goyourfly.multiple.adapter.StateChangeListener
|
|
|
import org.brynhild.graduation.R
|
|
|
import org.brynhild.graduation.activity.common.AccountInfoActivity
|
|
|
import org.brynhild.graduation.activity.common.BaseActivity
|
|
@@ -33,16 +31,16 @@ import org.brynhild.graduation.common.constant.FileStorageConstant
|
|
|
import org.brynhild.graduation.common.transfer.Result
|
|
|
import org.brynhild.graduation.common.transfer.handler.ResponseHandler
|
|
|
import org.brynhild.graduation.common.transfer.utils.ServiceCreator
|
|
|
-import org.brynhild.graduation.common.transfer.vo.AdminAddUser
|
|
|
-import org.brynhild.graduation.common.transfer.vo.AdminDeleteUser
|
|
|
-import org.brynhild.graduation.common.transfer.vo.QueryAcademyRequest
|
|
|
-import org.brynhild.graduation.common.transfer.vo.QueryUserRequest
|
|
|
+import org.brynhild.graduation.common.transfer.vo.*
|
|
|
import org.brynhild.graduation.common.utils.JsonUtils
|
|
|
import org.brynhild.graduation.common.utils.MultipleSelectHandler
|
|
|
import org.brynhild.graduation.databinding.ActivityMainPageBinding
|
|
|
+import org.brynhild.graduation.databinding.AdminCreateAcademyDialogBinding
|
|
|
import org.brynhild.graduation.databinding.AdminCreateUserDialogBinding
|
|
|
import org.brynhild.graduation.databinding.NavHeaderBinding
|
|
|
+import org.brynhild.graduation.network.adapter.AcademyAdapter
|
|
|
import org.brynhild.graduation.network.adapter.UserAdapter
|
|
|
+import org.brynhild.graduation.network.entiity.Academy
|
|
|
import org.brynhild.graduation.network.entiity.User
|
|
|
import org.brynhild.graduation.service.http.AccountService
|
|
|
import org.brynhild.graduation.service.http.AdminService
|
|
@@ -57,6 +55,8 @@ class AdminMainPageActivity : BaseActivity() {
|
|
|
private var currentPage = 0
|
|
|
private val loadUserList=0
|
|
|
private val refreshUserList=1
|
|
|
+ private val loadAcademyList=2
|
|
|
+ private val refreshAcademyList=3;
|
|
|
|
|
|
private var lastBack = 0L
|
|
|
private lateinit var activityMainPageBinding: ActivityMainPageBinding
|
|
@@ -88,6 +88,15 @@ class AdminMainPageActivity : BaseActivity() {
|
|
|
Toast.makeText(this, "数据更新完成", Toast.LENGTH_SHORT).show()
|
|
|
}
|
|
|
}
|
|
|
+ loadAcademyList->{
|
|
|
+ switchToAcademy{}
|
|
|
+ }
|
|
|
+ refreshAcademyList->{
|
|
|
+ switchToAcademy{
|
|
|
+ activityMainPageBinding.swipeRefresh.isRefreshing=false
|
|
|
+ Toast.makeText(this, "数据更新完成", Toast.LENGTH_SHORT).show()
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
false
|
|
|
}
|
|
@@ -190,6 +199,67 @@ class AdminMainPageActivity : BaseActivity() {
|
|
|
"AddDeviceActivity",
|
|
|
"flag is ${result.flag},message is ${result.message},data is ${result.data}"
|
|
|
)
|
|
|
+ val academyArrayList=ArrayList<Academy>()
|
|
|
+ val gson=Gson()
|
|
|
+ for(item in result.data as ArrayList<*>){
|
|
|
+ val json=gson.toJson(item)
|
|
|
+ val academy=JsonUtils.fromJson<Academy>(json)
|
|
|
+ if(academy!=null){
|
|
|
+ academyArrayList.add(academy)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ val adapter=AcademyAdapter(this@AdminMainPageActivity,academyArrayList)
|
|
|
+
|
|
|
+ activityMainPageBinding.recyclerView.adapter=MultipleSelectHandler.createHandler(this@AdminMainPageActivity,adapter,object :RecyclerViewCallback{
|
|
|
+ override fun execute(selected: List<Int>) {
|
|
|
+ val builder=StringBuilder()
|
|
|
+ println(selected)
|
|
|
+ var first=true
|
|
|
+
|
|
|
+ val rmList=ArrayList<Long>()
|
|
|
+ for (index in selected){
|
|
|
+ rmList.add(academyArrayList[index].id)
|
|
|
+ if(!first){
|
|
|
+ builder.append("、")
|
|
|
+ }else{
|
|
|
+ first=false
|
|
|
+ }
|
|
|
+ builder.append(academyArrayList[index].name)
|
|
|
+ }
|
|
|
+ ConfirmPopupWindow.ConfirmPopupWindowBuilder.init(this@AdminMainPageActivity)
|
|
|
+ .setContent("以下学院将被删除:${builder}")
|
|
|
+ .setCancelText("取消删除")
|
|
|
+ .setEnsureText("确定删除")
|
|
|
+ .setEnsureListener {
|
|
|
+
|
|
|
+ val service=ServiceCreator.create(AdminService::class.java)
|
|
|
+ val rmData=AdminDeleteAcademy(rmList)
|
|
|
+ println("send data with:${Gson().toJson(rmData)}")
|
|
|
+ service.deleteAcademy(LoginConfiguration.userInfo!!.token,rmData).enqueue(object:Callback<Result>{
|
|
|
+ override fun onResponse(
|
|
|
+ call: Call<Result>,
|
|
|
+ response: Response<Result>
|
|
|
+ ) {
|
|
|
+ ResponseHandler.handle(response,{
|
|
|
+ handler.sendEmptyMessage(refreshAcademyList)
|
|
|
+ },{
|
|
|
+ ResponseHandler.showMessage(it)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onFailure(call: Call<Result>, t: Throwable) {
|
|
|
+ t.printStackTrace()
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+ .build()
|
|
|
+ .show()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ supportActionBar?.let { bar->
|
|
|
+ bar.title="AcademyList"
|
|
|
+ }
|
|
|
callback.execute()
|
|
|
}, {
|
|
|
ResponseHandler.showMessage(it)
|
|
@@ -328,7 +398,7 @@ class AdminMainPageActivity : BaseActivity() {
|
|
|
val dialogLayout=AdminCreateUserDialogBinding.inflate(LayoutInflater.from(this))
|
|
|
|
|
|
AlertDialog.Builder(this)
|
|
|
- .setTitle("添加用户")
|
|
|
+ .setTitle("添加学院")
|
|
|
.setView(dialogLayout.root)
|
|
|
.setPositiveButton("确认添加"){_,_->
|
|
|
val service=ServiceCreator.create(AdminService::class.java)
|
|
@@ -362,6 +432,43 @@ class AdminMainPageActivity : BaseActivity() {
|
|
|
}
|
|
|
.show()
|
|
|
}
|
|
|
+
|
|
|
+ R.id.admin_academy_add->{
|
|
|
+ val dialogLayout=AdminCreateAcademyDialogBinding.inflate(LayoutInflater.from(this))
|
|
|
+
|
|
|
+ AlertDialog.Builder(this)
|
|
|
+ .setTitle("添加学院")
|
|
|
+ .setView(dialogLayout.root)
|
|
|
+ .setPositiveButton("确认添加"){_,_->
|
|
|
+ val service=ServiceCreator.create(AdminService::class.java)
|
|
|
+ val data=AdminAddAcademy(
|
|
|
+ dialogLayout.no.text.toString(),
|
|
|
+ dialogLayout.name.text.toString(),
|
|
|
+ dialogLayout.liable.text.toString().toLongOrNull()
|
|
|
+ )
|
|
|
+ service.addAcademy(LoginConfiguration.userInfo!!.token,data).enqueue(object :Callback<Result>{
|
|
|
+ override fun onResponse(
|
|
|
+ call: Call<Result>,
|
|
|
+ response: Response<Result>
|
|
|
+ ) {
|
|
|
+ ResponseHandler.handle(response,{
|
|
|
+ handler.sendEmptyMessage(refreshAcademyList)
|
|
|
+ },{
|
|
|
+ ResponseHandler.showMessage(it)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onFailure(call: Call<Result>, t: Throwable) {
|
|
|
+ t.printStackTrace()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ .setNegativeButton("取消添加"){_,_->
|
|
|
+
|
|
|
+ }
|
|
|
+ .show()
|
|
|
+ }
|
|
|
+
|
|
|
R.id.delete -> Toast.makeText(this, "You clicked Delete", Toast.LENGTH_SHORT).show()
|
|
|
R.id.settings -> Toast.makeText(this, "You clicked Settings", Toast.LENGTH_SHORT).show()
|
|
|
}
|