Browse Source

1.添加退出登录接口。

master
wangwanlei 11 months ago
parent
commit
fa4d92f035

+ 1
- 0
app/src/main/java/com/xhly/manageapp/ui/login/activity/LoginActivity.kt View File

67
         loginBean.loginpwd=code
67
         loginBean.loginpwd=code
68
         loginBean.device= Build.BRAND
68
         loginBean.device= Build.BRAND
69
         loginBean.deviceModel=Build.MODEL
69
         loginBean.deviceModel=Build.MODEL
70
+        loginBean.regionCode=regioncode
70
         loginBean.clientVersion=SystemUtil.getAppVersionName(this,packageName)
71
         loginBean.clientVersion=SystemUtil.getAppVersionName(this,packageName)
71
         ManageApplication.getDeviceInfo()?.let {
72
         ManageApplication.getDeviceInfo()?.let {
72
             loginBean.sn=it
73
             loginBean.sn=it

+ 7
- 0
app/src/main/java/com/xhly/manageapp/ui/login/netservice/LoginService.kt View File

14
 
14
 
15
     @POST(UriAdress.ULOGIN_LOGIN)
15
     @POST(UriAdress.ULOGIN_LOGIN)
16
     suspend fun postLogin(@Body loginBean: LoginBean): ResponseData<UserBean>
16
     suspend fun postLogin(@Body loginBean: LoginBean): ResponseData<UserBean>
17
+
18
+    /**
19
+     * 退出登录接口参数 userid	number 用户id
20
+     * loginpwd	string 密码
21
+     */
22
+    @POST(UriAdress.ULOGIN_LOGIN_OUT)
23
+    suspend fun postLoginOut(@Body map:HashMap<String,Any>): ResponseData<Any>
17
 }
24
 }

+ 27
- 9
app/src/main/java/com/xhly/manageapp/ui/main/activity/MainActivity.kt View File

16
 import android.widget.TextView
16
 import android.widget.TextView
17
 import android.widget.Toast
17
 import android.widget.Toast
18
 import androidx.activity.addCallback
18
 import androidx.activity.addCallback
19
-import androidx.multidex.BuildConfig
20
 import androidx.recyclerview.widget.GridLayoutManager
19
 import androidx.recyclerview.widget.GridLayoutManager
21
 import androidx.work.PeriodicWorkRequest
20
 import androidx.work.PeriodicWorkRequest
22
 import androidx.work.WorkManager
21
 import androidx.work.WorkManager
104
                 spUtils.setParam(Const.PADINFOTIMEKEY, System.currentTimeMillis())
103
                 spUtils.setParam(Const.PADINFOTIMEKEY, System.currentTimeMillis())
105
             }
104
             }
106
         }
105
         }
106
+        viewModel.loginOutData.observe(this) {
107
+            if (it) {
108
+                loginOut()
109
+            }
110
+        }
111
+        viewModel.updateInfoData.observe(this){
112
+            //TODO 需要编写更新代码
113
+        }
107
         startWorkManager()
114
         startWorkManager()
108
     }
115
     }
109
 
116
 
151
         //每天请求一次app更新接口
158
         //每天请求一次app更新接口
152
         try {
159
         try {
153
             var userBean = spUtils.getFromJson(Const.USERINFO, UserBean().javaClass) as UserBean
160
             var userBean = spUtils.getFromJson(Const.USERINFO, UserBean().javaClass) as UserBean
154
-            //获得pad信息提交时间,如果为同一天则不在上传,不然继续上传
161
+            //存储pad更新请求时间,如果为同一天则不在上传,不然继续上传
155
             val padTime = spUtils.getParam(Const.PADUPDATETIMEKEY, 0L) as Long
162
             val padTime = spUtils.getParam(Const.PADUPDATETIMEKEY, 0L) as Long
156
             val instance = Calendar.getInstance()
163
             val instance = Calendar.getInstance()
157
             val currentYear = instance.get(Calendar.YEAR)
164
             val currentYear = instance.get(Calendar.YEAR)
167
                 val packageInfo =
174
                 val packageInfo =
168
                     packageManager.getPackageInfo(packageName, PackageManager.GET_META_DATA)
175
                     packageManager.getPackageInfo(packageName, PackageManager.GET_META_DATA)
169
                 updateBean.cversion = packageInfo.versionName
176
                 updateBean.cversion = packageInfo.versionName
170
-                updateBean.schoolid=userBean.schoolid
171
-                updateBean.userid=userBean.userid
172
-                updateBean.regionid=userBean.regionid
177
+                updateBean.schoolid = userBean.schoolid
178
+                updateBean.userid = userBean.userid
179
+                updateBean.regionid = userBean.regionid
173
                 viewModel.updateMcApp(updateBean)
180
                 viewModel.updateMcApp(updateBean)
174
             }
181
             }
175
         } catch (e: Exception) {
182
         } catch (e: Exception) {
433
                     editText.hint = getString(R.string.inputcode)
440
                     editText.hint = getString(R.string.inputcode)
434
                     titleTv.text = getString(R.string.exit)
441
                     titleTv.text = getString(R.string.exit)
435
                     enterTv.setOnClickListener {
442
                     enterTv.setOnClickListener {
436
-                        dialog.dismiss()
437
-                        loginOut()
443
+                        val code = editText.text
444
+                        if (!code.isNullOrBlank()) {
445
+                            dialog.dismiss()
446
+                            try {
447
+                                val userBean = spUtils.getFromJson(
448
+                                    Const.USERINFO,
449
+                                    UserBean().javaClass
450
+                                ) as UserBean
451
+                                viewModel.loginOut(userBean.userid.toString(), code.toString())
452
+                            } catch (e: Exception) {
453
+
454
+                            }
455
+                        }
438
                     }
456
                     }
439
                     cancelTv.setOnClickListener {
457
                     cancelTv.setOnClickListener {
440
                         dialog.dismiss()
458
                         dialog.dismiss()
495
     private fun startWorkManager() {
513
     private fun startWorkManager() {
496
         WorkManager.getInstance(this).cancelAllWork()
514
         WorkManager.getInstance(this).cancelAllWork()
497
         // 周期性任务时间最少15分钟 所以除以实际周期的时间  看需要加入几个任务
515
         // 周期性任务时间最少15分钟 所以除以实际周期的时间  看需要加入几个任务
498
-        /*val taskList = arrayListOf(5, 10)*/
499
-        for (taskNo in 1..10) {
516
+        val taskList = arrayListOf(5, 10)
517
+        for (taskNo in taskList) {
500
             val request = PeriodicWorkRequest
518
             val request = PeriodicWorkRequest
501
                 // 最少15分钟 PeriodicWorkRequest
519
                 // 最少15分钟 PeriodicWorkRequest
502
                 .Builder(TimingWorker::class.java, 15, TimeUnit.MINUTES)
520
                 .Builder(TimingWorker::class.java, 15, TimeUnit.MINUTES)

+ 21
- 0
app/src/main/java/com/xhly/manageapp/ui/main/viewmodel/MainViewModel.kt View File

14
 import com.xhly.manageapp.network.app.AppService
14
 import com.xhly.manageapp.network.app.AppService
15
 import com.xhly.manageapp.network.log.LogService
15
 import com.xhly.manageapp.network.log.LogService
16
 import com.xhly.manageapp.network.strategy.StrategyService
16
 import com.xhly.manageapp.network.strategy.StrategyService
17
+import com.xhly.manageapp.ui.login.netservice.LoginService
17
 
18
 
18
 class MainViewModel : CommonBaseViewModel() {
19
 class MainViewModel : CommonBaseViewModel() {
19
     private val appService by lazy { RetrofitService.create<AppService>() }
20
     private val appService by lazy { RetrofitService.create<AppService>() }
21
+    private val loginService by lazy { RetrofitService.create<LoginService>() }
20
     private val strategyService by lazy { RetrofitService.create<StrategyService>() }
22
     private val strategyService by lazy { RetrofitService.create<StrategyService>() }
21
     private var logService = RetrofitService.create<LogService>()
23
     private var logService = RetrofitService.create<LogService>()
22
     private val listData = MutableLiveData<ArrayList<AppModel>>()
24
     private val listData = MutableLiveData<ArrayList<AppModel>>()
29
     val padInfoData: LiveData<Boolean> = padInfo
31
     val padInfoData: LiveData<Boolean> = padInfo
30
     private val updateInfo = MutableLiveData<Boolean>()
32
     private val updateInfo = MutableLiveData<Boolean>()
31
     val updateInfoData: LiveData<Boolean> = updateInfo
33
     val updateInfoData: LiveData<Boolean> = updateInfo
34
+    private val loginOut = MutableLiveData<Boolean>()
35
+    val loginOutData: LiveData<Boolean> = loginOut
36
+
32
     fun getAppList() {
37
     fun getAppList() {
33
         launchUI {
38
         launchUI {
34
             val postListApp = appService.postListApp(ListAppBean())
39
             val postListApp = appService.postListApp(ListAppBean())
101
             }
106
             }
102
         }
107
         }
103
     }
108
     }
109
+
110
+    fun loginOut(userid: String, loginpwd: String) {
111
+        launchUI {
112
+            val map = HashMap<String, Any>()
113
+            map["userid"] = userid
114
+            map["loginpwd"] = loginpwd
115
+            val postLoginOut = loginService.postLoginOut(map)
116
+            if (postLoginOut.code == 0) {
117
+                loginOut.value=true
118
+            } else {
119
+                if (postLoginOut.msg != null) {
120
+                    netMessage.value = postLoginOut.msg
121
+                }
122
+            }
123
+        }
124
+    }
104
 }
125
 }

+ 1
- 1
corelib/src/main/java/com/xhly/corelib/Const.kt View File

95
     //存储pad信息提交时间,如果为同一天则不在上传,不然继续上传
95
     //存储pad信息提交时间,如果为同一天则不在上传,不然继续上传
96
     const val PADINFOTIMEKEY = "PADINFOTIMEKEY"
96
     const val PADINFOTIMEKEY = "PADINFOTIMEKEY"
97
 
97
 
98
-    //存储pad更新请求时间,如果为同一天则不在上传,不然继续上传
98
+    //存储pad更新请求时间,如果为同一天则不在请求更新,不然继续请求更新
99
     const val PADUPDATETIMEKEY = "PADUPDATETIMEKEY"
99
     const val PADUPDATETIMEKEY = "PADUPDATETIMEKEY"
100
 
100
 
101
     //存储用户信息
101
     //存储用户信息

Loading…
Cancel
Save