| @@ -40,13 +40,10 @@ import com.yzx.escreen.fragment.MyFragment | |||
| import com.yzx.escreen.model.* | |||
| import com.yzx.escreen.presenter.MainPresenter | |||
| import com.yzx.escreen.presenter.MainView | |||
| import com.yzx.escreen.presenter.base.JsonCallBack | |||
| import com.yzx.escreen.presenter.base.YzxResponse | |||
| import com.yzx.escreen.utils.hideNavigationBar | |||
| import com.yzx.escreen.widget.BaseDialog | |||
| import com.yzx.escreen.widget.ChangeDialog | |||
| import com.yzx.escreen.widget.LeaveDialog | |||
| import com.yzx.webebook.config.YzxInterface | |||
| import kotlinx.android.synthetic.main.activity_main.* | |||
| import org.greenrobot.eventbus.EventBus | |||
| import org.greenrobot.eventbus.Subscribe | |||
| @@ -78,8 +75,15 @@ class MainActivity : BaseActivity<MainPresenter>(), NetworkUtils.OnNetworkStatus | |||
| private val mHandler = Handler(Looper.getMainLooper()) | |||
| private val runnable = object : Runnable { | |||
| override fun run() { | |||
| mPresenter?.getLeaveShowIds() | |||
| mHandler.postDelayed(this, 2000) | |||
| val isAutoShowLeave = SPUtils.getInstance().getBoolean("auto_show_leave", false) | |||
| val isAutoShowChange = SPUtils.getInstance().getBoolean("auto_show_change", false) | |||
| if (isAutoShowLeave || isAutoShowChange) { | |||
| mPresenter?.getLeaveShowIds() | |||
| mHandler.postDelayed(this, 2000) | |||
| } else { | |||
| mHandler.removeCallbacks(this) | |||
| } | |||
| } | |||
| } | |||
| @@ -105,6 +109,10 @@ class MainActivity : BaseActivity<MainPresenter>(), NetworkUtils.OnNetworkStatus | |||
| checkVersion() | |||
| checkAuto() | |||
| } | |||
| override fun onError() { | |||
| } | |||
| }) | |||
| }else{ | |||
| checkVersion() | |||
| @@ -112,6 +120,10 @@ class MainActivity : BaseActivity<MainPresenter>(), NetworkUtils.OnNetworkStatus | |||
| RefreshToken.refresh(object :RefreshToken.RefreshCallback{ | |||
| override fun onSuccess() { | |||
| } | |||
| override fun onError() { | |||
| } | |||
| }) | |||
| } | |||
| } else { | |||
| @@ -162,6 +174,11 @@ class MainActivity : BaseActivity<MainPresenter>(), NetworkUtils.OnNetworkStatus | |||
| checkAuto() | |||
| } | |||
| override fun onDestroy() { | |||
| super.onDestroy() | |||
| mTimeHandler.removeCallbacks(timeRunnable) | |||
| } | |||
| //接收请假消息 | |||
| @Subscribe(threadMode = ThreadMode.MAIN) | |||
| fun onMessageEvent(detail: StuLeave) { | |||
| @@ -1,14 +1,19 @@ | |||
| package com.yzx.escreen.config | |||
| import android.content.Intent | |||
| import com.blankj.utilcode.util.ActivityUtils | |||
| import com.blankj.utilcode.util.LogUtils | |||
| import com.lzy.okgo.OkGo | |||
| import com.lzy.okgo.model.Response | |||
| import com.yzx.escreen.App.Companion.getContext | |||
| import com.yzx.escreen.MainActivity | |||
| import com.yzx.escreen.activity.WebActivity | |||
| import com.yzx.escreen.config.Config.OA_URL | |||
| import com.yzx.escreen.model.ReToken | |||
| import com.yzx.escreen.model.RefreshTokenEvent | |||
| import com.yzx.escreen.model.User | |||
| import com.yzx.escreen.presenter.base.JsonCallBack | |||
| import com.yzx.escreen.presenter.base.YzxResponse | |||
| import com.yzx.webebook.config.YzxInterface | |||
| import org.greenrobot.eventbus.EventBus | |||
| import java.util.* | |||
| @@ -41,13 +46,41 @@ object RefreshToken { | |||
| override fun onError(response: Response<YzxResponse<ReToken>>?) { | |||
| super.onError(response) | |||
| LogUtils.d(response) | |||
| User.clearUserInfo() | |||
| val intent = Intent(getContext(), WebActivity::class.java) | |||
| intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK | |||
| intent.putExtra("link", OA_URL + "/login?logout=1") | |||
| ActivityUtils.startActivity(intent) | |||
| ActivityUtils.finishActivity(MainActivity::class.java) | |||
| callBack.onError() | |||
| } | |||
| }) | |||
| }else{ | |||
| User.clearUserInfo() | |||
| val intent = Intent(getContext(), WebActivity::class.java) | |||
| intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK | |||
| intent.putExtra("link", OA_URL + "/login?logout=1") | |||
| ActivityUtils.startActivity(intent) | |||
| ActivityUtils.finishActivity(MainActivity::class.java) | |||
| callBack.onError() | |||
| } | |||
| }else{ | |||
| if (currTime - lastLoginTime > 365L * 24 * 60 * 60 * 1000){ | |||
| User.clearUserInfo() | |||
| val intent = Intent(getContext(), WebActivity::class.java) | |||
| intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK | |||
| intent.putExtra("link", OA_URL + "/login?logout=1") | |||
| ActivityUtils.startActivity(intent) | |||
| ActivityUtils.finishActivity(MainActivity::class.java) | |||
| callBack.onError() | |||
| }else{ | |||
| callBack.onSuccess() | |||
| } | |||
| } | |||
| } | |||
| interface RefreshCallback{ | |||
| fun onSuccess() | |||
| fun onError() | |||
| } | |||
| } | |||
| @@ -1,4 +1,4 @@ | |||
| package com.yzx.webebook.config | |||
| package com.yzx.escreen.config | |||
| object YzxInterface { | |||
| @@ -401,6 +401,7 @@ class ChangeFragment : BaseFragment<ChangePresenter>(), ChangeView, | |||
| override fun onListError(error: String) { | |||
| isLoading = false | |||
| showEmpty(3) | |||
| } | |||
| override fun onDetailSuccess(detail: StuChange) { | |||
| @@ -143,7 +143,7 @@ class HomeFragment : BaseFragment<HomePresenter>(), HomeView, | |||
| switchBtn.setOnCheckedChangeListener { buttonView, isChecked -> | |||
| SPUtils.getInstance().put("auto_show_leave", isChecked) | |||
| changeSwitchBtnTxt(isChecked) | |||
| EventBus.getDefault().post(AutoSwitchChange(1)) | |||
| } | |||
| val isAutoShowLeave = SPUtils.getInstance().getBoolean("auto_show_leave", false) | |||
| switchBtn.isChecked = isAutoShowLeave | |||
| @@ -470,6 +470,7 @@ class HomeFragment : BaseFragment<HomePresenter>(), HomeView, | |||
| override fun onLeaveListError(error: String) { | |||
| isLoading = false | |||
| showEmpty(3) | |||
| } | |||
| override fun onLeaveDetailSuccess(detail: StuLeave) { | |||
| @@ -98,7 +98,7 @@ class MyFragment : BaseFragment<MyPresenter>(), MyView { | |||
| } | |||
| override fun initData() { | |||
| mPresenter?.getTeacherInfo(User.getUser().user_id) | |||
| density.text = | |||
| "density:${ScreenUtils.getScreenDensity()},dpi:${ScreenUtils.getScreenDensityDpi()}" | |||
| @@ -111,6 +111,11 @@ class MyFragment : BaseFragment<MyPresenter>(), MyView { | |||
| } | |||
| } | |||
| override fun onResume() { | |||
| super.onResume() | |||
| mPresenter?.getTeacherInfo(User.getUser().user_id) | |||
| } | |||
| override fun initPresenter(): MyPresenter = MyPresenter(this) | |||
| override fun onUserInfoSuccess(info: TeacherInfo) { | |||
| userName.text = info.teacher_name | |||
| @@ -62,6 +62,11 @@ class User( | |||
| SPUtils.getInstance().put("unit_count", count); | |||
| } | |||
| fun saveLastLoginTime(time:Long){ | |||
| val sp = SPUtils.getInstance() | |||
| sp.put("loginTime", time) | |||
| } | |||
| fun clearUserInfo() { | |||
| val sp = SPUtils.getInstance() | |||
| sp.remove("user_name") | |||
| @@ -6,13 +6,13 @@ import com.lzy.okgo.model.Response | |||
| import com.yzx.escreen.config.Config | |||
| import com.yzx.escreen.model.* | |||
| import com.yzx.escreen.presenter.base.* | |||
| import com.yzx.webebook.config.YzxInterface | |||
| import com.yzx.escreen.config.YzxInterface | |||
| class ChangePresenter(view: ChangeView) : BasePresenter<ChangeView>(view) { | |||
| fun getList(pageNo: Int, keyword: String, status: String) { | |||
| if(!User.isLogin()){ | |||
| if(User.getUser().token.isEmpty()){ | |||
| return | |||
| } | |||
| val url = "${Config.BASE_URL}${YzxInterface.INTERFACE_STUDENT_GET_CHANGE_LIST}" | |||
| @@ -40,7 +40,7 @@ class ChangePresenter(view: ChangeView) : BasePresenter<ChangeView>(view) { | |||
| }) | |||
| } | |||
| fun getDetail(id: Int) { | |||
| if(!User.isLogin()){ | |||
| if(User.getUser().token.isEmpty()){ | |||
| return | |||
| } | |||
| val url = "${Config.BASE_URL}${YzxInterface.INTERFACE_STUDENT_GET_CHANGE_DETAIL}" | |||
| @@ -6,13 +6,13 @@ import com.lzy.okgo.model.Response | |||
| import com.yzx.escreen.config.Config | |||
| import com.yzx.escreen.model.* | |||
| import com.yzx.escreen.presenter.base.* | |||
| import com.yzx.webebook.config.YzxInterface | |||
| import com.yzx.escreen.config.YzxInterface | |||
| class HomePresenter(view: HomeView) : BasePresenter<HomeView>(view) { | |||
| fun getLeaveList(pageNo: Int, keyword: String, status: String) { | |||
| if(!User.isLogin()){ | |||
| if(User.getUser().token.isEmpty()){ | |||
| return | |||
| } | |||
| val url = "${Config.BASE_URL}${YzxInterface.INTERFACE_GET_STU_LEAVE_LIST}" | |||
| @@ -40,7 +40,7 @@ class HomePresenter(view: HomeView) : BasePresenter<HomeView>(view) { | |||
| }) | |||
| } | |||
| fun getLeaveShowIds() { | |||
| if(!User.isLogin()){ | |||
| if(User.getUser().token.isEmpty()){ | |||
| return | |||
| } | |||
| val url = "${Config.BASE_URL}${YzxInterface.INTERFACE_STUDENT_GET_SHOW_BOX_LIST}" | |||
| @@ -63,7 +63,7 @@ class HomePresenter(view: HomeView) : BasePresenter<HomeView>(view) { | |||
| } | |||
| fun getDetail(id: Int) { | |||
| if(!User.isLogin()){ | |||
| if(User.getUser().token.isEmpty()){ | |||
| return | |||
| } | |||
| val url = "${Config.BASE_URL}${YzxInterface.INTERFACE_GET_STU_LEAVE_INFO_DETAIL}" | |||
| @@ -89,7 +89,7 @@ class HomePresenter(view: HomeView) : BasePresenter<HomeView>(view) { | |||
| } | |||
| fun postVacation(data:Vacation){ | |||
| if(!User.isLogin()){ | |||
| if(User.getUser().token.isEmpty()){ | |||
| return | |||
| } | |||
| val url = "${Config.BASE_URL}${YzxInterface.INTERFACE_STUDENT_POST_LEAVE_VACATION}" | |||
| @@ -10,14 +10,14 @@ import com.yzx.escreen.presenter.base.BasePresenter | |||
| import com.yzx.escreen.presenter.base.IView | |||
| import com.yzx.escreen.presenter.base.JsonCallBack | |||
| import com.yzx.escreen.presenter.base.YzxResponse | |||
| import com.yzx.webebook.config.YzxInterface | |||
| import com.yzx.escreen.config.YzxInterface | |||
| class MainPresenter(view: MainView) : BasePresenter<MainView>(view) { | |||
| fun getLeaveShowIds() { | |||
| if(!User.isLogin()){ | |||
| if(User.getUser().token.isEmpty()){ | |||
| return | |||
| } | |||
| val url = "${Config.BASE_URL}${YzxInterface.INTERFACE_STUDENT_GET_SHOW_BOX_LIST}" | |||
| @@ -4,11 +4,9 @@ import com.blankj.utilcode.util.LogUtils | |||
| import com.lzy.okgo.OkGo | |||
| import com.lzy.okgo.model.Response | |||
| import com.yzx.escreen.config.Config | |||
| import com.yzx.escreen.model.Pager | |||
| import com.yzx.escreen.model.StuLeave | |||
| import com.yzx.escreen.model.TeacherInfo | |||
| import com.yzx.escreen.model.User | |||
| import com.yzx.webebook.config.YzxInterface | |||
| import com.yzx.escreen.config.YzxInterface | |||
| import com.yzx.escreen.presenter.base.BasePresenter | |||
| import com.yzx.escreen.presenter.base.IView | |||
| import com.yzx.escreen.presenter.base.JsonCallBack | |||
| @@ -18,7 +16,7 @@ class MyPresenter(view: MyView) : BasePresenter<MyView>(view) { | |||
| fun getTeacherInfo(user_id: Int) { | |||
| if(!User.isLogin()){ | |||
| if(User.getUser().token.isEmpty()){ | |||
| return | |||
| } | |||
| val url = "${Config.BASE_URL}${YzxInterface.INTERFACE_GET_TEACHER_INFO}" | |||
| @@ -4,6 +4,7 @@ import android.content.Intent; | |||
| import com.blankj.utilcode.util.ActivityUtils; | |||
| import com.blankj.utilcode.util.AppUtils; | |||
| import com.blankj.utilcode.util.LogUtils; | |||
| import com.google.gson.stream.JsonReader; | |||
| import com.lzy.okgo.callback.AbsCallback; | |||
| import com.lzy.okgo.model.HttpHeaders; | |||
| @@ -12,6 +13,7 @@ import com.yzx.escreen.App; | |||
| import com.yzx.escreen.MainActivity; | |||
| import com.yzx.escreen.activity.WebActivity; | |||
| import com.yzx.escreen.config.Config; | |||
| import com.yzx.escreen.config.RefreshToken; | |||
| import com.yzx.escreen.model.User; | |||
| import com.yzx.escreen.utils.Monitor; | |||
| @@ -21,6 +23,7 @@ import org.json.JSONObject; | |||
| import java.lang.reflect.ParameterizedType; | |||
| import java.lang.reflect.Type; | |||
| import java.util.Date; | |||
| import okhttp3.Response; | |||
| import okhttp3.ResponseBody; | |||
| @@ -145,12 +148,29 @@ public abstract class JsonCallBack<T> extends AbsCallback<T> { | |||
| //noinspection unchecked | |||
| return (T) yzxResponse; | |||
| } else if (code == 406) { | |||
| User.Companion.clearUserInfo(); | |||
| Intent intent = new Intent(App.Companion.getContext(),WebActivity.class); | |||
| intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |||
| intent.putExtra("link", Config.INSTANCE.getOA_URL()+"/login?logout=1"); | |||
| ActivityUtils.startActivity(intent); | |||
| ActivityUtils.finishActivity(MainActivity.class); | |||
| long currTime = new Date().getTime(); | |||
| User.Companion.saveLastLoginTime(currTime - 24*60*60*1000L); | |||
| RefreshToken.INSTANCE.refresh(new RefreshToken.RefreshCallback() { | |||
| @Override | |||
| public void onSuccess() { | |||
| LogUtils.d("onSuccess"); | |||
| Intent intent = new Intent(App.Companion.getContext(),MainActivity.class); | |||
| intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |||
| ActivityUtils.finishActivity(MainActivity.class); | |||
| ActivityUtils.startActivity(intent); | |||
| } | |||
| @Override | |||
| public void onError() { | |||
| LogUtils.d("onError"); | |||
| User.Companion.clearUserInfo(); | |||
| Intent intent = new Intent(App.Companion.getContext(),WebActivity.class); | |||
| intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |||
| intent.putExtra("link", Config.INSTANCE.getOA_URL()+"/login?logout=1"); | |||
| ActivityUtils.startActivity(intent); | |||
| ActivityUtils.finishActivity(MainActivity.class); | |||
| } | |||
| }); | |||
| throw new IllegalStateException("错误代码:" + code + ",错误信息:" + yzxResponse.msg); | |||
| } else { | |||
| // 直接将服务端的错误信息抛出,onError中可以获取 | |||
| @@ -4,7 +4,7 @@ import com.lzy.okgo.OkGo | |||
| import com.lzy.okgo.callback.StringCallback | |||
| import com.lzy.okgo.model.Response | |||
| import com.yzx.escreen.model.User | |||
| import com.yzx.webebook.config.YzxInterface | |||
| import com.yzx.escreen.config.YzxInterface | |||
| import org.json.JSONObject | |||
| import java.io.File | |||
| @@ -14,8 +14,7 @@ | |||
| android:background="@color/white" | |||
| android:gravity="center_vertical" | |||
| android:orientation="horizontal" | |||
| android:padding="30dp" | |||
| android:paddingStart="@dimen/d_20"> | |||
| android:padding="30dp"> | |||
| <TextView | |||
| android:layout_width="wrap_content" | |||