Polyv Help Center

Help Center

6_2-互动学堂场景-登录

Updated: 2023-04-17 15:27:57

1 Feature Overview

The login UI for the Interactive Classroom scenario is implemented as PLVLoginHiClassActivity.

This is the shared interface for both instructor login and student login in the Interactive Classroom scenario.

Instructor login flow:

Select the instructor role -> Enter account and password for login verification -> Select company for login verification -> Verification successful, retrieve the lesson list page -> Select a lesson to enter the classroom.

If an instructor appears in multiple companies, the instructor must select a company; otherwise, it is not required.

Student login flow using lesson ID:

Select the student role -> Enter lesson ID for lesson verification -> Enter name +/verification/student code for login verification -> Verification successful, enter the classroom.

Student login flow using course ID:

Select the student role -> Enter course ID for course verification -> Enter name +/verification/student code for login verification -> Verification successful, retrieve the lesson list page -> Select a lesson to enter the classroom.

2 Usage Demo

Since the login system involves multiple flows with different UI interactions, the demo uses an Activity + ViewPager + multiple Fragments. The following example demonstrates the instructor login verification method, with the code as follows:

//讲师登录验证示例
loginManager.loginHiClassTeacher(
    areaCode,
    account,
    password,
    null,
    null,
    new IPLVSceneLoginManager.OnLoginListener<PLVHCTeacherLoginVO>() {
        @Override
        public void onLoginSuccess(PLVHCTeacherLoginVO result) {
        if (result == null
            || result.getStatus() == null
            || loginViewModel == null
            || getContext() == null) {
            return;
        }

        PLVHCTeacherLoginAccountVO accountVO = new PLVHCTeacherLoginAccountVO();
        accountVO.setAreaCode(areaCode);
        accountVO.setAccount(account);
        accountVO.setPassword(password);
        loginViewModel.getTeacherLoginAccountLiveData().setValue(accountVO);

        saveLastLoginAccount(areaCode, account);
        saveLastLoginPassword(plvhcLoginTeacherRememberPasswordCb.isChecked(), password);
        saveAgreeContract(true);

        if (result.getStatus() == PLVHCTeacherLoginVO.STATUS_LOGIN_SELECT_COMPANY) {
            List<PLVHCLoginCompanyVO> loginCompanyVOList = new ArrayList<>();
            for (PLVHCTeacherLoginResultVO.CompanyVO companyVO : result.getCompanyList()) {
                loginCompanyVOList.add(PLVHCLoginCompanyVO.fromLoginResult(companyVO));
            }
            loginViewModel.getCompanyListLiveData().setValue(loginCompanyVOList);
            KeyboardUtils.hideSoftInput(plvhcLoginTeacherPasswordEt);
            //进入选择公司页
            PLVHCLoginFragmentManager.getInstance().addLast(PLVHCLoginFragmentManager.FRAG_TEACHER_COMPANY);
        } else if (result.getStatus() == PLVHCTeacherLoginVO.STATUS_LOGIN_SUCCESS) {
            if (result.getSuccessData() != null) {
            PLVHCLoginDataVO loginTokenVO = new PLVHCLoginDataVO();
            loginTokenVO.setRole(PLVSocketUserConstant.USERTYPE_TEACHER);
            loginTokenVO.setToken(result.getSuccessData().getToken());
            loginTokenVO.setNickname(result.getSuccessData().getNickname());
            loginTokenVO.setViewerId(result.getSuccessData().getViewerId());
            loginViewModel.setLoginDataVOWithSave(loginTokenVO, timestamp);

            List<PLVHCLoginLessonVO> loginLessonVOList = listMap(result.getSuccessData().getLessonList(),
                new PLVSugarUtil.Function<PLVHCTeacherLoginResultVO.DataVO.LessonVO, PLVHCLoginLessonVO>() {
                    @Override
                    public PLVHCLoginLessonVO apply(PLVHCTeacherLoginResultVO.DataVO.LessonVO lessonVO) {
                        return PLVHCLoginLessonVO.fromTeacherLoginResultLessonVO(lessonVO);
                    }
                });
            loginViewModel.getLoginLessonListLiveData().setValue(loginLessonVOList);
            }
            KeyboardUtils.hideSoftInput(plvhcLoginTeacherPasswordEt);
            // 进入选择课节页
            PLVHCLoginFragmentManager.getInstance().addLast(PLVHCLoginFragmentManager.FRAG_LESSON_SELECT);
            } else {
                PLVHCToast.Builder.context(getContext())
                    .setText("登录状态错误:" + result.getStatus())
                    .build().show();
            }
        }

        @Override
        public void onLoginFailed(String msg, Throwable throwable) {
        if (getContext() == null) {
            return;
        }
        PLVHCToast.Builder.context(getContext())
            .setText(msg)
            .build().show();
        }
    }
);

Specific use cases for the above method can be found in the PLVHCTeacherLoginFragment class.

3 Implementation Details

The entire login process essentially involves confirming and obtaining the user type, user ID, user nickname, login token, course ID, and lesson ID.

3.1 PLVLoginHiClassActivity

The login page Activity for the Interactive Classroom. The layout defines a ViewPager for adding Fragments that appear during the login flow.

3.2 PLVHCRoleSelectFragment

Interactive Classroom login - Role selection Fragment, used to select the instructor/student role.

3.3 PLVHCTeacherLoginFragment

Interactive Classroom login - Instructor login Fragment, providing UI interaction for entering the instructor's account, password, and login verification.

3.4 PLVHCTeacherCompanyFragment

Interactive Classroom login - Instructor company selection Fragment, providing UI interaction for selecting the instructor's company. This Fragment appears after successful login verification when an instructor is bound to multiple companies.

3.5 PLVHCLessonSelectFragment

Interactive Classroom login - Lesson selection Fragment. This page displays a list of available lessons, from which a lesson can be selected to enter the classroom.

3.6 PLVHCStudentLoginFragment

Interactive Classroom login - Student login Fragment, providing UI interaction for entering the course ID/lesson ID and information verification.

3.7 PLVHCStudentVerifyFragment

Interactive Classroom login - Student verification Fragment, providing UI interaction for entering the student name +/verification/student code and viewing condition verification.

联系客服,在线咨询