Commit 52219307 by konghaorui

add some user code

parent 78e71ebd
ext{
//自动添加***-api依赖
autoImportApiDependency = {extension -> //extension project对象
def children = project.rootProject.childProjects
//遍历所有child project
children.each {child ->
//判断 是否同时存在 *** module 和 ***-api module
if(child.key.contains("-api") && children.containsKey(child.key.substring(0,child.key.length() - 4))){
print "\n"
def targetKey = child.key.substring(0,child.key.length() - 4)
def targetProject = children[targetKey]
targetProject.afterEvaluate {
print '*********************\n'
print targetProject.dependencies
//通过打印 所有dependencies,推断需要添加如下两个依赖
targetProject.dependencies.add("implementation",targetProject.dependencies.create(project(":" + child.key)))
targetProject.dependencies.add("implementationDependenciesMetadata",targetProject.dependencies.create(project(":" + child.key)))
//打印 module 添加的依赖
targetProject.configurations.each {configuration ->
print '\n---------------------------------------\n'
configuration.allDependencies.each { dependency ->
print configuration.name + "--->" +dependency.group + ":" + dependency.name + ":" + dependency.version +'\n'
}
}
print '*********************\n'
}
}
}
}
}
\ No newline at end of file
//导出函数
ext {
includeWithApi = this.&includeWithApi
}
def includeWithApi(String moduleName) {
print " --- includeWithApi :$moduleName --- \n"
//先正常加载这个模块
include(moduleName)
//找到这个模块的路径
String originDir = project(moduleName).projectDir
//这个是新的路径
String targetDir = "${originDir}-api"
//原模块的名字
String originName=project(moduleName).name;
//新模块的名字
def sdkName = "${originName}-api"
//这个是公共模块的位置,预先放了一个 新建的api.gradle 文件进去
String apiGradle = project(":ydl-platform").projectDir
// 每次编译删除之前的文件
deleteDir(targetDir)
//复制.api文件到新的路径
copy() {
from originDir
into targetDir
exclude '**/build/'
exclude '**/res/'
include '**/*.api'
include '**/*.kapi'
}
//直接复制公共模块的AndroidManifest文件到新的路径,作为该模块的文件
copy() {
from "${apiGradle}/template/AndroidManifest.xml"
into "${targetDir}/src/main/"
}
//复制 gradle文件到新的路径,作为该模块的gradle
copy() {
from "${apiGradle}/template/template.gradle"
into "${targetDir}/"
}
//删除空文件夹
deleteEmptyDir(new File(targetDir))
//为AndroidManifest新建路径,路径就是在原来的包下面新建一个api包,作为AndroidManifest里面的包名
String packagePath = "${targetDir}/src/main/java/com/ydl/${originName.replaceAll("m-","")}/api";
//修改AndroidManifest文件包路径
fileReader("${targetDir}/src/main/AndroidManifest.xml", "template","${originName.replaceAll("m-","")}.api");
new File(packagePath).mkdirs()
//重命名一下gradle
def build = new File(targetDir + "/template.gradle")
if (build.exists()) {
build.renameTo(new File(targetDir + "/build.gradle"))
}
// 重命名.api文件,生成正常的.java文件
renameApiFiles(targetDir, '.api', '.java')
renameApiFiles(targetDir, '.kapi', '.kt')
//正常加载新的模块
include ":$sdkName"
}
private void deleteEmptyDir(File dir) {
if (dir.isDirectory()) {
File[] fs = dir.listFiles();
if (fs != null && fs.length > 0) {
for (int i = 0; i < fs.length; i++) {
File tmpFile = fs[i];
if (tmpFile.isDirectory()) {
deleteEmptyDir(tmpFile);
}
if (tmpFile.isDirectory() && tmpFile.listFiles().length <= 0) {
tmpFile.delete();
}
}
}
if (dir.isDirectory() && dir.listFiles().length == 0) {
dir.delete();
}
}
}
private void deleteDir(String targetDir) {
FileTree targetFiles = fileTree(targetDir)
targetFiles.exclude "*.iml"
targetFiles.each { File file ->
file.delete()
}
}
/**
* rename api files(java, kotlin...)
*/
private def renameApiFiles(root_dir, String suffix, String replace) {
FileTree files = fileTree(root_dir).include("**/*$suffix")
files.each {
File file ->
file.renameTo(new File(file.absolutePath.replace(suffix, replace)))
}
}
//替换AndroidManifest里面的字段
def fileReader(path, name,sdkName) {
def readerString = "";
def hasReplace = false
file(path).withReader('UTF-8') { reader ->
reader.eachLine {
if (it.find(name)) {
it = it.replace(name, sdkName)
hasReplace = true
}
readerString <<= it
readerString << '\n'
}
if (hasReplace) {
file(path).withWriter('UTF-8') {
within ->
within.append(readerString)
}
}
return readerString
}
}
......@@ -3,8 +3,6 @@ apply plugin: 'com.android.library'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
......
......@@ -3,8 +3,6 @@ apply plugin: 'com.android.library'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
......
package com.yidianling.user.bean
import com.google.gson.annotations.SerializedName
import com.yidianling.user.route.UserRouterImp
/**
* author : hgw
* time : 2018/02/02
*/
class UserResponse {
var uid: String? = null
var accessToken: String? = null
var firstLogin: Int = 0 //1是 2否
var hxpwd: String? = null
var userInfo: UserInfo? = UserInfo()
inner class UserInfo {
var uid: String = "0"
@field:SerializedName("userName")
var user_name: String? = null
var accessToken: String? = null//
@field:SerializedName("bindPhone")
var bind_phone: Int? = 0 //1为绑定
var phone: String? = null
@field:SerializedName("realName")
var real_name: String? = null
@field:SerializedName("nickName")
var nick_name: String? = null
var head: String? = null
var gender: Int = 0//性别1男2女
var birthday: String? = null
@field:SerializedName("availableMoney")
var available_money: String? = null
var address: String? = null
@field:SerializedName("unionId")
var union_id: String? = null//微信标识,
@field:SerializedName("openIdQqweb")
var open_id_qqapp: String? = null//qq标识
@field:SerializedName("bindWeixin")
var bind_weixin: Int = 0 //是否绑定微信1绑定0未绑定
set(value) {
if (value != bind_weixin) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
@field:SerializedName("bindQq")
var bind_qq: Int = 0
//是否绑定qq 1绑定0未绑定
set(value) {
if (value != bind_qq) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
@field:SerializedName("userType")
var user_type: Int = 0//1普通用户2心理专家
@field:SerializedName("listenCards")
var listen_cards: Int = 0//收听卡的次数
var profession: Int = 0
set(value) {
if (value != profession) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
var marriage: Int = 0
set(value) {
if (value != marriage) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
@field:SerializedName("countryCode")
var country_code: String? = null
@field:SerializedName("homeBg")
var home_bg: String? = null
//我的封面地址
set(value) {
if (!(value?.equals(home_bg) ?: false)) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
//是否同意过隐私权限 1同意过 0未同意
var privacyAgreementStatus: Int = 1
set(value) {
if (value != privacyAgreementStatus) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
var description: String? = null
//简介
set(value) {
if (!(value?.equals(description) ?: false)) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
@field:SerializedName("isSilenced")
var is_silenced: Int = 0 // 1 正常 2 禁言
set(value) {
if (value != is_silenced) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
var hasCoupon: Int = 0
var firstLogin: Int = 0 //1是2否
set(value) {
if (value != firstLogin) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
var trendNum: Int = 0 //我的动态
set(value) {
if (value != trendNum) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
var fansNum: Int = 0
//我的粉丝
set(value) {
if (value != fansNum) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
var testRecordNum: Int = 0
//测试记录
set(value) {
if (value != testRecordNum) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
var attentionNum: Int = 0
//我的关注
set(value) {
if (value != attentionNum) {
field = value
UserRouterImp..updateUserInfoSp(this)
}
}
var registTime: String? = null
//你我相识已502天
set(value) {
if (!(value?.equals(registTime) ?: false)) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
var privacyArr: PrivacyArr? = null
override fun toString(): String {
return "UserInfo(uid='$uid', user_name=$user_name, accessToken=$accessToken, bind_phone=$bind_phone, phone=$phone, real_name=$real_name, nick_name=$nick_name, head=$head, gender=$gender, birthday=$birthday, available_money=$available_money, address=$address, union_id=$union_id, open_id_qqapp=$open_id_qqapp, bind_weixin=$bind_weixin, bind_qq=$bind_qq, user_type=$user_type, listen_cards=$listen_cards, profession=$profession, marriage=$marriage, country_code=$country_code, home_bg=$home_bg, description=$description, is_silenced=$is_silenced, hasCoupon=$hasCoupon, firstLogin=$firstLogin, trendNum=$trendNum, fansNum=$fansNum, testRecordNum=$testRecordNum, attentionNum=$attentionNum, registTime=$registTime)"
}
}
inner class PrivacyArr {
var time: String? = null
var content: String? = null
}
override fun toString(): String {
return "UserResponse(uid=$uid, accessToken=$accessToken, firstLogin=$firstLogin, hxpwd=$hxpwd, userInfo=$userInfo)"
}
}
\ No newline at end of file
package com.yidianling.user.route;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import com.alibaba.android.arouter.facade.template.IProvider;
import com.yidianling.user.bean.UserResponse;
import com.yidianling.user.bean.UserSetting;
/**
* Created by haorui on 2019-09-23.
* Des:
*/
public interface IUserService extends IProvider {
boolean isLogin();
boolean isFirstLogin();
void setFirstLogin(boolean var1);
boolean isSafePrivacyClicked();
void putSafePrivacyClicked(boolean var1);
void setUserResponse( UserResponse var1);
UserResponse.UserInfo getUserInfo();
UserResponse getUserResponse();
UserSetting getUserSetting();
boolean isBindPhone();
void putUnlockCheckSuccessTime(long var1);
boolean getChatTeamHisShow();
void setChatTeamHisShowed(boolean var1);
Intent privacyIntent( Activity var1);
Intent loginWayIntent( Context var1);
Intent inputPhoneIntent( Activity var1, String var2);
boolean safeTipViewGone();
void setTrendsSafeTip(boolean var1);
long errorAgainTime();
boolean isFirstStart();
void updateUserInfoSp( UserResponse.UserInfo var1);
void updateUserSetingSp( UserSetting var1);
void clearUserInfo();
}
apply plugin: 'com.android.library'
if (isApplicaiton.toBoolean()) {
apply plugin: 'com.android.application'
} else {
apply plugin: 'com.android.library'
}
apply from: "../pins.gradle"
android {
compileSdkVersion 28
defaultConfig {
if (isApplicaiton.toBoolean()) {
applicationId "com.ydl.other"
}
minSdkVersion 14
targetSdkVersion 28
versionCode 1
......@@ -11,12 +19,13 @@ android {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
arguments = [AROUTER_MODULE_NAME: project.getName()]
}
}
flavorDimensions "versionCode"
}
......@@ -26,7 +35,21 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
publishNonDefault true
productFlavors {
ydl {}
xlzx {}
}
sourceSets {
main {
if (isApplicaiton.toBoolean()) {
manifest.srcFile 'src/main/module/AndroidManifest.xml'
} else {
manifest.srcFile 'src/main/AndroidManifest.xml'
}
}
}
}
dependencies {
......@@ -40,4 +63,5 @@ dependencies {
annotationProcessor 'com.alibaba:arouter-compiler:1.2.2'
implementation project(":m-user-api")
implementation project(":ydl-platform")
compile "org.jetbrains.kotlin:kotlin-script-runtime:1.3.41"
}
isApplicaiton = false
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><link rel="shortcut icon" href="/favicon.ico"><meta name="theme-color" content="#000000"><meta name="viewport" content="initial-scale=1,maximum-scale=1.3,minimum-scale=1"><meta name="format-detection" content="telephone=yes"/><meta name="format-detection" content="telephone=no"/><link rel="manifest" href="/manifest.json"><link rel="stylesheet" href="/lib/antd.min.css"><script type="text/javascript">document.documentElement.style.fontSize="12px"</script><script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script><script src="https://as.alipayobjects.com/g/component/fastclick/1.0.6/fastclick.js"></script><script>window.jumpWeiXinApp=function(i){wx.miniProgram.navigateTo({url:i})};var webviewSystem=function(){var i=navigator.userAgent,e=i.indexOf("Android")>-1||i.indexOf("Adr")>-1,n=!!i.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);return"micromessenger"==window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i)?"wx":n?"iOS":e?"Android":"web"},browser=webviewSystem();function connectWebViewJavascriptBridge(i){window.WebViewJavascriptBridge?i(WebViewJavascriptBridge):document.addEventListener("WebViewJavascriptBridgeReady",function(){i(WebViewJavascriptBridge)},!1)}function sendDataToNative(i){sendDataToOC(i)}window.sendDataToOC=function(i){},"iOS"==browser?connectWebViewJavascriptBridge(function(i){i.init(function(i,e){}),i.registerHandler("javascriptHandler",function(i,e){}),window.sendDataToOC=function(e){i.callHandler("javascriptHandler",e,function(i){i.uid})}}):"Android"==browser&&(window.sendDataToOC=function(i){var e;e=JSON.stringify(i),window.javascriptHandler.sendDataToOC(e)})</script><script>"addEventListener"in document&&document.addEventListener("DOMContentLoaded",function(){FastClick.attach(document.body)},!1),window.Promise||document.writeln('<script src="https://as.alipayobjects.com/g/component/es6-promise/3.2.2/es6-promise.min.js"><\/script>')</script><script src="/lib/react.production.min.js"></script><script src="/lib/react-dom.production.min.js"></script><script src="/lib/react-router-dom.min.js"></script><script src="/lib/moment.min.js"></script><script src="/lib/antd.min.js"></script><script>function setTitle(t){document.title=t}</script><title>加载中</title><link href="/static/css/main.6b28a61a.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script type="text/javascript" src="/static/js/main.e593085e.js"></script></body></html>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -11,7 +11,6 @@ import com.alibaba.android.arouter.facade.annotation.Route;
@Route(path = "/user/UserService")
public class UserServiceImpl implements UserService {
public UserServiceImpl() {
}
......
package com.yidianling.user;
import android.app.Activity;
import android.widget.ImageView;
import com.lzy.imagepicker.loader.ImageLoader;
import com.ydl.ydl_image.config.ISimpleImageOpConfig;
import com.ydl.ydl_image.config.SimpleImageOpConfiger;
import com.ydl.ydl_image.manager.YDLImageCacheManager;
/**
* Created by xiongyu on 2017/4/7.
*/
public class GlideImageLoader implements ImageLoader {
@Override
public void displayImage(Activity activity, String path, ImageView imageView, int width, int height) {
showImage(activity,path,imageView,width,height);
}
@Override
public void displayImagePreview(Activity activity, String path, ImageView imageView, int width, int height) {
showImage(activity,path,imageView,width,height);
}
private void showImage(Activity activity, String path, ImageView imageView, int width, int height){
SimpleImageOpConfiger sp = new SimpleImageOpConfiger();
sp.loadingPic = R.drawable.default_img;
sp.errorPic = R.drawable.default_img;
sp.scaleType = ISimpleImageOpConfig.CENTER_CROP;
sp.isCacheOnDisk = false;
YDLImageCacheManager.showImage(activity,path,imageView,width, height,sp);
}
@Override
public void clearMemoryCache() {
}
}
package com.yidianling.user
import com.yidianling.user.http.request.LoginParam
import com.yidianling.router.user.UserResponse
import com.yidianling.ydlcommon.http.BaseResponse
import com.yidianling.ydlcommon.mvp.MVPModel
import com.yidianling.ydlcommon.mvp.MVPPresenter
import com.yidianling.ydlcommon.mvp.MVPView
import io.reactivex.Observable
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/02/02
*/
interface LoginContract {
interface View: MVPView {
// 开始登录
fun startLogin()
// 登录成功
fun loginSuccess(userInfo: UserResponse?)
// 登录失败
fun loginFail(msg: String)
// 登录完成
fun onLoginStop()
fun showErrorUserType()
}
interface Model: MVPModel {
fun login(param: LoginParam): Observable<BaseResponse<UserResponse>>
}
interface Presenter: MVPPresenter<View, Model> {
fun login(param: LoginParam)
}
}
\ No newline at end of file
package com.yidianling.user;
import android.util.Log;
import com.yidianling.router.user.UserResponse;
import com.yidianling.user.http.UserHttp;
import com.yidianling.user.http.UserHttpImpl;
import com.yidianling.user.http.request.ChannelIdParam;
import com.yidianling.ydlcommon.YdlBuryPointUtil;
import com.yidianling.ydlcommon.event.LoginStateEvent;
import com.yidianling.ydlcommon.http.RxUtils;
import com.yidianling.ydlcommon.http.ThrowableConsumer;
import com.yidianling.ydlcommon.log.LogHelper;
import com.yidianling.ydlcommon.tool.BuryPointUtils;
import com.yidianling.ydlcommon.tool.JPushUtils;
import org.jetbrains.annotations.NotNull;
import de.greenrobot.event.EventBus;
import io.reactivex.android.schedulers.AndroidSchedulers;
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/03/06
*/
public class LoginHelper {
public static boolean isRegister;
public static void setChannelId() {
String channelId = JPushUtils.INSTANCE.getRegistrationID();
if (UserHelper.INSTANCE.isLogin() && channelId != null) {
UserHttp userHttp = UserHttpImpl.Companion.getInstance();
userHttp.channelId(new ChannelIdParam(channelId))
.compose(RxUtils.resultData())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(map -> {
if (map.get("upload_log").equals("1")) {
LogHelper.Companion.getInstance().uploadLog(false);
}
Log.d("TAG", "setChannelId: ");
}, new ThrowableConsumer() {
@Override
public void accept(@NotNull String msg) {
// ToastHelper.Companion.show(msg);
}
});
}
}
public static void login(UserResponse response) {
YdlBuryPointUtil.reLogin();
UserHelper.INSTANCE.setUserinfo(response);
EventBus.getDefault().post(new LoginStateEvent("login",response.getUid()));
BuryPointUtils.bindUid(String.valueOf(response.getUid()));
}
}
package com.yidianling.user
import com.yidianling.user.http.request.LoginParam
import com.yidianling.router.user.UserResponse
import com.yidianling.user.http.UserHttp
import com.yidianling.user.http.UserHttpImpl
import com.yidianling.ydlcommon.http.BaseResponse
import io.reactivex.Observable
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/02/02
*/
class LoginModel: LoginContract.Model {
override fun login(param: LoginParam): Observable<BaseResponse<UserResponse>> {
val userHttp: UserHttp = UserHttpImpl.getInstance()
return userHttp.login(param)
}
}
\ No newline at end of file
package com.yidianling.user
import com.yidianling.user.http.request.LoginParam
import com.yidianling.user.route.UserIn
import com.yidianling.ydlcommon.UserInfoCache
import com.yidianling.ydlcommon.http.RxUtils
import com.yidianling.ydlcommon.http.ThrowableConsumer
import com.yidianling.router.im.IMLoginInfo
import com.yidianling.router.im.IMRequestCallback
import com.yidianling.router.user.UserResponse
import com.yidianling.ydlcommon.event.RefreshEvent
import com.yidianling.ydlcommon.log.LogHelper
import com.yidianling.ydlcommon.mvp.RxPresenter
import de.greenrobot.event.EventBus
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.functions.Consumer
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/02/02
*/
class LoginPresenter(view: LoginContract.View): RxPresenter<LoginContract.View, LoginContract.Model>(view), LoginContract.Presenter {
override fun createModel(): LoginContract.Model {
return LoginModel()
}
override fun login(param: LoginParam) {
val d = model.login(param).compose(RxUtils.resultData())
.doOnNext {
//存储登录缓存
LoginHelper.login(it)
}
.observeOn(AndroidSchedulers.mainThread())
.doOnSubscribe { view.startLogin() }
.doAfterTerminate {
view.onLoginStop()
}
.subscribe(Consumer {
LogHelper.getInstance().writeLogSync("登录成功")
EventBus.getDefault().post(RefreshEvent(1))
view.loginSuccess(it)
val info = IMLoginInfo(it.uid.toString(), it.hxpwd!!)
val callback = object : IMRequestCallback<IMLoginInfo> {
override fun onSuccess(t: IMLoginInfo?) {
setHXInfo(it)
}
override fun onFailed(i: Int) {
view.loginFail("账号登录异常")
}
override fun onException(throwable: Throwable?) {
view.loginFail("未知错误02")
}
}
UserIn.imSetAccount(info.account)
UserIn.imLogin(info, callback)
}, object : ThrowableConsumer() {
override fun accept(msg: String) {
LogHelper.getInstance().writeLogSync("登录失败:$msg")
view.loginFail(msg)
}
})
addDisposable(d)
}
private fun setHXInfo(userInfo: UserResponse?) {
try {
if (userInfo != null) {
UserIn.imSetAccount(userInfo.uid.toString())
}
} catch (e: Exception) {
e.printStackTrace()
}
}
}
\ No newline at end of file
package com.yidianling.user
import com.yidianling.common.tools.LogUtil
import com.tencent.bugly.crashreport.CrashReport
import com.yidianling.router.im.IMLoginInfo
import com.yidianling.router.im.IMRequestCallback
import com.yidianling.router.user.UserResponse
import com.yidianling.user.http.UserHttpImpl
import com.yidianling.user.http.request.ChannelIdParam
import com.yidianling.user.http.request.Logout
import com.yidianling.user.route.UserIn
import com.yidianling.ydlcommon.event.LoginStateEvent
import com.yidianling.ydlcommon.http.RxUtils
import com.yidianling.ydlcommon.http.ThrowableConsumer
import com.yidianling.ydlcommon.log.LogHelper
import com.yidianling.ydlcommon.tool.BuryPointUtils
import com.yidianling.ydlcommon.tool.JPushUtils
import de.greenrobot.event.EventBus
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.functions.Consumer
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/05/09
*/
object LoginUtils {
@JvmStatic
fun saveData(userInfo: UserResponse?) {
UserHelper.setUserinfo(userInfo)
}
@JvmStatic
fun onLogin(userInfo: UserResponse?) {
//设置异常用户ID
CrashReport.setUserId(userInfo?.uid)
//登录IM聊天
loginIm(userInfo)
//设置极光注册id
LoginHelper.setChannelId()
val event = LoginStateEvent("login",userInfo?.uid)
EventBus.getDefault().post(event)
BuryPointUtils.bindUid(userInfo?.uid ?: "")
val channelId = JPushUtils.getRegistrationID()
UserHttpImpl.getInstance().channelId(ChannelIdParam(channelId))
.compose(RxUtils.resultData())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Consumer {
if (it["upload_log"] == "1") {
LogHelper.getInstance().uploadLog(false)
}
}, object : ThrowableConsumer() {
override fun accept(msg: String) {
// ToastHelper.show(msg)
}
})
}
private fun loginIm(userInfo: UserResponse?) {
val info = IMLoginInfo(userInfo?.uid ?: "", userInfo?.hxpwd ?: "")
val callback = object : IMRequestCallback<IMLoginInfo> {
override fun onSuccess(t: IMLoginInfo?) {
UserIn.imSetAccount(userInfo?.uid ?: "")
}
override fun onFailed(i: Int) {
LogUtil.e("IM登录失败:$i")
}
override fun onException(throwable: Throwable?) {
LogUtil.e("IM登录onException:${throwable?.message}")
}
}
UserIn.imSetAccount(info.account)
UserIn.imLogin(info, callback)
}
@JvmStatic
fun logout() {
UserHttpImpl.getInstance().logout(Logout())
.compose(RxUtils.resultData())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
logoutClearLocal()
}, {
logoutClearLocal()
})
}
@JvmStatic
fun logoutClearLocal() {
UserIn.imLogout()
UserIn.closePlayer()
UserIn.clearImData()
UserHelper.setUserinfo(null)
}
}
\ No newline at end of file
package com.yidianling.user
object UserConstants {
const val REGISTER_ACTION = "register"
const val FORGET_ACTION = "forget"
const val SIGNIN_ACTION = "signin"
const val CHANGE_ACTION = "change"
const val BIND_PHONE_ACTION = "wxbind"
const val MIN_GET_CODE_TIME = 60
const val IS_REGISTER_FROM_PACKET = "isRegisterFromRedPacket"
}
\ No newline at end of file
package com.yidianling.user
import android.text.TextUtils
import com.google.gson.Gson
import com.yidianling.user.bean.UserResponse
import com.yidianling.user.bean.`UserSetting.api`
import com.yidianling.ydlcommon.utils.SharedPreferencesEditor
import com.yidianling.ydlcommon.utils.UserInfoCache
/**
* 用户信息辅助类
*/
object UserHelper {
val gson: Gson = Gson()
//用户信息存储
private val user_info_name_sp = "ydl_user_info"
private val user_info_key_sp = "ydl_user_info_key"
//用户设置存储
private val user_setting_name_sp = "ydl_user_setting"
private val user_setting_key_sp = "ydl_user_setting_key"
//用户信息//缓存
private var userTemp: UserResponse? = null
//用户设置信息缓存
private var userSetting: `UserSetting.api`? = null
//存储用户信息
fun setUserinfo(userInfo: UserResponse?) {
try {
userTemp = userInfo
var str = gson.toJson(userTemp)
SharedPreferencesEditor.putFileString(user_info_name_sp, user_info_key_sp, str)
UserInfoCache.getInstance().saveYDLUser("\"" + userInfo?.uid + "\"",
userInfo?.userInfo?.nick_name, userInfo?.userInfo?.head)
} catch (e: Exception) {
e.printStackTrace()
}
}
//获取用户设置信息
fun getUserInfo(): UserResponse? {
if (userTemp != null) return userTemp!!
try {
var obj = SharedPreferencesEditor.getFileString(user_info_name_sp, user_info_key_sp)
var app: UserResponse = gson.fromJson(obj, UserResponse::class.java)
userTemp = app
return userTemp!!
} catch (e: Exception) {
userTemp = UserResponse()
}
return userTemp
}
fun updateUserinfo(userInfo: UserResponse.UserInfo?) {
getUserInfo()?.userInfo = userInfo
}
fun updateUserSetting(userseting: `UserSetting.api`?) {
setUserSetting(userseting)
}
/**
* 是否登录
*/
fun isLogin(): Boolean {
try {
var user = getUserInfo()?.userInfo
if (TextUtils.isEmpty(user?.uid)) {
return false
}
var uid: Int = user?.uid?.toInt() ?: 0
if (uid > 0) {
return true
}
} catch (e: Exception) {
e.printStackTrace()
}
return false
}
/**
* 是否绑定手机
*/
fun isBindPhone(): Boolean {
return !TextUtils.isEmpty(getUserInfo()?.userInfo?.phone)
}
/**
* 存储用户设置信息
*/
fun setUserSetting(userseting: `UserSetting.api`?) {
try {
userSetting = userseting
var str = gson.toJson(userSetting)
SharedPreferencesEditor.putFileString(user_setting_name_sp, user_setting_key_sp, str)
} catch (e: Exception) {
e.printStackTrace()
}
}
/**
* 获取用户设置信息
*/
fun getUsetSetting(): `UserSetting.api`? {
if (userSetting != null) return userSetting!!
try {
var obj = SharedPreferencesEditor.getFileString(user_setting_name_sp, user_setting_key_sp)
if (TextUtils.isEmpty(obj)) {
setUserSetting(`UserSetting.api`())
}
var app: `UserSetting.api` = gson.fromJson(obj, `UserSetting.api`::class.java)
userSetting = app
return userSetting
} catch (e: Exception) {
}
return userSetting
}
}
\ No newline at end of file
package com.yidianling.user.bean;
/**
* @author jiucheng
* @描述:
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/11/29
*/
public class AliAuthBean {
public String accessCode;
public String deviceType;
public String osType;
public String vendor_key;
}
package com.yidianling.user.bean
import com.google.gson.annotations.SerializedName
import com.yidianling.user.route.UserRouterImp
/**
* author : hgw
* time : 2018/02/02
*/
class UserResponse {
var uid: String? = null
var accessToken: String? = null
var firstLogin: Int = 0 //1 2
var hxpwd: String? = null
var userInfo: UserInfo? = UserInfo()
inner class UserInfo {
var uid: String = "0"
@field:SerializedName("userName")
var user_name: String? = null
var accessToken: String? = null//
@field:SerializedName("bindPhone")
var bind_phone: Int? = 0 //1为绑定
var phone: String? = null
@field:SerializedName("realName")
var real_name: String? = null
@field:SerializedName("nickName")
var nick_name: String? = null
var head: String? = null
var gender: Int = 0//性别12
var birthday: String? = null
@field:SerializedName("availableMoney")
var available_money: String? = null
var address: String? = null
@field:SerializedName("unionId")
var union_id: String? = null//微信标识,
@field:SerializedName("openIdQqweb")
var open_id_qqapp: String? = null//qq标识
@field:SerializedName("bindWeixin")
var bind_weixin: Int = 0 //是否绑定微信1绑定0未绑定
set(value) {
if (value != bind_weixin) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
@field:SerializedName("bindQq")
var bind_qq: Int = 0
//是否绑定qq 1绑定0未绑定
set(value) {
if (value != bind_qq) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
@field:SerializedName("userType")
var user_type: Int = 0//1普通用户2心理专家
@field:SerializedName("listenCards")
var listen_cards: Int = 0//收听卡的次数
var profession: Int = 0
set(value) {
if (value != profession) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
var marriage: Int = 0
set(value) {
if (value != marriage) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
@field:SerializedName("countryCode")
var country_code: String? = null
@field:SerializedName("homeBg")
var home_bg: String? = null
//我的封面地址
set(value) {
if (!(value?.equals(home_bg) ?: false)) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
//是否同意过隐私权限 1同意过 0未同意
var privacyAgreementStatus: Int = 1
set(value) {
if (value != privacyAgreementStatus) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
var description: String? = null
//简介
set(value) {
if (!(value?.equals(description) ?: false)) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
@field:SerializedName("isSilenced")
var is_silenced: Int = 0 // 1 正常 2 禁言
set(value) {
if (value != is_silenced) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
var hasCoupon: Int = 0
var firstLogin: Int = 0 //12
set(value) {
if (value != firstLogin) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
var trendNum: Int = 0 //我的动态
set(value) {
if (value != trendNum) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
var fansNum: Int = 0
//我的粉丝
set(value) {
if (value != fansNum) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
var testRecordNum: Int = 0
//测试记录
set(value) {
if (value != testRecordNum) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
var attentionNum: Int = 0
//我的关注
set(value) {
if (value != attentionNum) {
field = value
UserRouterImp..updateUserInfoSp(this)
}
}
var registTime: String? = null
//你我相识已502
set(value) {
if (!(value?.equals(registTime) ?: false)) {
field = value
RouterManager.getUserRouter()?.updateUserInfoSp(this)
}
}
var privacyArr: PrivacyArr? = null
override fun toString(): String {
return "UserInfo(uid='$uid', user_name=$user_name, accessToken=$accessToken, bind_phone=$bind_phone, phone=$phone, real_name=$real_name, nick_name=$nick_name, head=$head, gender=$gender, birthday=$birthday, available_money=$available_money, address=$address, union_id=$union_id, open_id_qqapp=$open_id_qqapp, bind_weixin=$bind_weixin, bind_qq=$bind_qq, user_type=$user_type, listen_cards=$listen_cards, profession=$profession, marriage=$marriage, country_code=$country_code, home_bg=$home_bg, description=$description, is_silenced=$is_silenced, hasCoupon=$hasCoupon, firstLogin=$firstLogin, trendNum=$trendNum, fansNum=$fansNum, testRecordNum=$testRecordNum, attentionNum=$attentionNum, registTime=$registTime)"
}
}
inner class PrivacyArr {
var time: String? = null
var content: String? = null
}
override fun toString(): String {
return "UserResponse(uid=$uid, accessToken=$accessToken, firstLogin=$firstLogin, hxpwd=$hxpwd, userInfo=$userInfo)"
}
}
\ No newline at end of file
package com.yidianling.user.bean
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/04/26
*/
class UserSetting {
//是否开启指纹
var fingerPrintStatus: Boolean = false
set(value) {
if (fingerPrintStatus!=value){
field = value
RouterManager.getUserRouter()?.updateUserSetingSp(this)
}
}
//指纹或手势验证成功时间
var unLockCheckSuccessTime: Long = 0L
set(value) {
if (unLockCheckSuccessTime!=value){
field = value
RouterManager.getUserRouter()?.updateUserSetingSp(this)
}
}
//指纹多次错误被禁止使用的时间戳
var fingerErrorTime: Long = 0
set(value) {
if (fingerErrorTime!=value){
field = value
RouterManager.getUserRouter()?.updateUserSetingSp(this)
}
}
//手势密码
var gesturePassword: String = ""
set(value) {
if (!value.equals(gesturePassword)){
field = value
RouterManager.getUserRouter()?.updateUserSetingSp(this)
}
}
//设置群聊历史记录
var chatTeamHisShowed: Boolean = false
set(value) {
if (chatTeamHisShowed!=value){
field = value
RouterManager.getUserRouter()?.updateUserSetingSp(this)
}
}
//获取动态页面是否提示过安全解锁
var trendsIsClick: Boolean = false
set(value) {
if (trendsIsClick!=value){
field = value
RouterManager.getUserRouter()?.updateUserSetingSp(this)
}
}
//我的页面隐私安全是否点击过
var meSafePrivateIsClick = false
set(value) {
if (meSafePrivateIsClick!=value){
field = value
RouterManager.getUserRouter()?.updateUserSetingSp(this)
}
}
//最后一次登录的版本号
var lastVersionCode = 0
set(value) {
if (lastVersionCode!=value){
field = value
RouterManager.getUserRouter()?.updateUserSetingSp(this)
}
}
/**
* 消息语音提醒
*/
var hasVoice: Boolean = true
set(value) {
if (hasVoice!=value){
field = value
RouterManager.getUserRouter()?.updateUserSetingSp(this)
}
}
/**
* 消息震动提醒
*/
var hasShake: Boolean = true
set(value) {
if (hasShake!=value){
field = value
RouterManager.getUserRouter()?.updateUserSetingSp(this)
}
}
var time: Long = 0L
set(value) {
if (time!=value){
field = value
RouterManager.getUserRouter()?.updateUserSetingSp(this)
}
}
/**
* 手机识别吗是否已经提示过
*/
var phoneStatusPermissionIsShow : Boolean = false
set(value){
if (phoneStatusPermissionIsShow!=value){
field = value
RouterManager.getUserRouter()?.updateUserSetingSp(this)
}
}
}
\ No newline at end of file
package com.yidianling.user.http
import com.google.gson.Gson
import com.ydl.ydlnet.YDLHttpUtils
import com.yidianling.user.bean.UserResponse
import com.yidianling.user.http.request.*
import com.yidianling.user.http.response.ChcekPhoneResponeBean
import com.yidianling.user.http.response.PhoneAuthResponseBean
import com.yidianling.ydlcommon.data.http.BaseResponse
import io.reactivex.Observable
import okhttp3.MediaType
import okhttp3.RequestBody
/**
* @author jiucheng
* @描述:新版登录接口请求
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/11/9
*/
class LoginApiRequestUtil {
companion object {
/**
* 校验手机号:是否是用户版号码、是否有设置密码、是否被绑定
*/
fun checkPhoneStatus(phone: String, countryCode: String?): Observable<BaseResponse<ChcekPhoneResponeBean>> {
return YDLHttpUtils.obtainApi(UserApi::class.java).checkPhoneStatus(phone, countryCode!!)
}
/**
* 校验手机号:是否是用户版号码、是否有设置密码、是否被绑定
*/
fun checkAliAuth(param: CheckAliAuthParam): Observable<BaseResponse<PhoneAuthResponseBean>> {
var str = Gson().toJson(param)
val body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str)
return YdlRetrofitUtils.getRxRetrofit().newBuilder().baseUrl(YdlRetrofitUtils.SERVER_API_JAVA_URL).build()
.create(UserApi::class.java).checkAliAuth(body)
}
/**
* 一键登录
*/
fun autoLogin(param: PhoneLoginAutoParam): Observable<BaseResponse<UserResponse>> {
var str = Gson().toJson(param)
val body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str)
return YdlRetrofitUtils.getRxRetrofit().newBuilder().baseUrl(YdlRetrofitUtils.SERVER_API_JAVA_URL).build()
.create(UserApi::class.java).autoLogin(body)
}
/**
* 手机号密码登录
*/
fun userLoginByPassword(param: PhoneLoginPwdParam): Observable<BaseResponse<UserResponse>> {
var str = Gson().toJson(param)
val body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str)
return YdlRetrofitUtils.getRxRetrofit().newBuilder().baseUrl(YdlRetrofitUtils.SERVER_API_JAVA_URL).build()
.create(UserApi::class.java).loginByPassword(body)
}
/**
* 重新设置密码
*/
fun resetPwd(param: PhoneResetPwdParam): Observable<BaseResponse<UserResponse>> {
var str = Gson().toJson(param)
val body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str)
return YdlRetrofitUtils.getRxRetrofit().newBuilder().baseUrl(YdlRetrofitUtils.SERVER_API_JAVA_URL).build()
.create(UserApi::class.java).resetPwd(body)
}
/**
* 发送登录验证码
*/
fun sendLoginMsgCode(phone: String, countryCode: String): Observable<BaseResponse<Any>> {
return YdlRetrofitUtils.getRxRetrofit().newBuilder().baseUrl(YdlRetrofitUtils.SERVER_API_JAVA_URL).build()
.create(UserApi::class.java).sendLoginMsgCode(phone, countryCode)
}
/**
* 验证码登录
*/
fun loginByMsgCode(param: PhoneLoginCodeParam): Observable<BaseResponse<UserResponse>> {
var str = Gson().toJson(param)
val body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str)
return YdlRetrofitUtils.getRxRetrofit().newBuilder().baseUrl(YdlRetrofitUtils.SERVER_API_JAVA_URL).build()
.create(UserApi::class.java).loginByMsgCode(body)
}
/**
* 重置密码的验证码
*/
fun sendResetCode(phone: String, countryCode: String): Observable<BaseResponse<Any>> {
return YdlRetrofitUtils.getRxRetrofit().newBuilder().baseUrl(YdlRetrofitUtils.SERVER_API_JAVA_URL).build()
.create(UserApi::class.java).sendResetCode(phone, countryCode)
}
/**
* //验证重置密码的短信验证码
*/
fun checkResetCode(phone: String, countryCode: String, msgCode: String): Observable<BaseResponse<Any>> {
return YdlRetrofitUtils.getRxRetrofit().newBuilder().baseUrl(YdlRetrofitUtils.SERVER_API_JAVA_URL).build()
.create(UserApi::class.java).checkResetCode(phone, countryCode, msgCode)
}
/**
* 一键登录
*/
fun bindPhone(param: BindPhoneJavaParam): Observable<BaseResponse<Any>> {
var str = Gson().toJson(param)
val body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str)
return YdlRetrofitUtils.getRxRetrofit().newBuilder().baseUrl(YdlRetrofitUtils.SERVER_API_JAVA_URL).build()
.create(UserApi::class.java).bindPhone(body)
}
}
}
\ No newline at end of file
package com.yidianling.user.http
import com.google.gson.internal.LinkedTreeMap
import com.yidianling.user.http.response.*
import com.yidianling.ydlcommon.constant.YDLConstants
import com.yidianling.ydlcommon.constant.YDLConstants.Companion.HOLDER_PARAM
import com.yidianling.ydlcommon.data.http.BaseAPIResponse
import com.yidianling.ydlcommon.data.http.BaseResponse
import com.yidianling.ydlcommon.router.YdlCommonOut
import io.reactivex.Observable
import okhttp3.RequestBody
import retrofit2.http.*
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/02/02
*/
interface UserApi {
//登录
@FormUrlEncoded
@POST("user/user")
fun login(@FieldMap params: Map<String, String>): Observable<BaseResponse<UserResponse>>
//国家列表
@FormUrlEncoded
@POST("user/country-list")
fun countryList(@Field(YDLConstants.HOLDER_PARAM) params: String): Observable<BaseResponse<CountryResponse>>
//判断手机号是否存在
@FormUrlEncoded
@POST("user/phone-exist")
fun phoneExists(@FieldMap params: Map<String, String>): Observable<BaseResponse<ExistResponse>>
//获取验证码
@FormUrlEncoded
@POST("user/chk-code")
fun getCode(@FieldMap params: Map<String, String>): Observable<BaseResponse<Any>>
//绑定手机号
@FormUrlEncoded
@POST("user/bind-phone")
fun bindPhone(@FieldMap params: Map<String, String>): Observable<BaseResponse<UserResponse>>
//忘记密码
@FormUrlEncoded
@POST("user/forget")
fun forget(@FieldMap params: Map<String, String>): Observable<BaseResponse<Any>>
//注册
@FormUrlEncoded
@POST("user/reg")
fun register(@FieldMap params: Map<String, String>): Observable<BaseResponse<Any>>
//设置推送的channelId
@FormUrlEncoded
@POST("user/set-channel-id")
fun setChannelId(@FieldMap params: Map<String, String>): Observable<BaseResponse<LinkedTreeMap<String, String>>>
//第三方登录
@POST("user/user_q_w")
fun thirdPartyLogin(@Body body: RequestBody): Observable<BaseAPIResponse<UserResponse>>
//设置用户信息
@FormUrlEncoded
@POST("user/set-info")
fun setUserInfo(@FieldMap params: Map<String, String>): Observable<BaseResponse<Any>>
//上传头像
@Multipart
@POST("user/set-info")
fun uploadHeadImg(@PartMap params: MutableMap<String, RequestBody>): Observable<BaseResponse<Any>>
//上传头像
@Multipart
@POST("user/set-info")
fun uploadHeadImg(@Part("type") param: RequestBody): Observable<BaseResponse<Any>>
//验证账号密码
@FormUrlEncoded
@POST("user/chkin-pass")
fun checkPhonePass(@FieldMap params: Map<String, String>): Observable<BaseResponse<CheckPassword>>
//绑定QQ
@FormUrlEncoded
@POST("user/bind-qq")
fun bindQQ(@FieldMap params: Map<String, String>): Observable<BaseResponse<Any>>
//绑定微信
@FormUrlEncoded
@POST("user/bind-wx")
fun bindWx(@FieldMap params: Map<String, String>): Observable<BaseResponse<Any>>
//登出
@FormUrlEncoded
@POST("user/logout")
fun logout(@FieldMap params: Map<String, String>): Observable<BaseResponse<Any>>
//更换手机时密码验证
@FormUrlEncoded
@POST("user/confirm-pwd")
fun checkPwd(@FieldMap params: Map<String, String>): Observable<BaseResponse<Any>>
//更换手机时最后校验验证码和手机
@FormUrlEncoded
@POST("user/replace-mob")
fun changePhone(@FieldMap params: Map<String, String>): Observable<BaseResponse<Any>>
//同意隐私政策接口
@GET("user/agreePrivacyAgreement")
fun privacyAgree(@Query("uid") uid: String): Observable<BaseResponse<Any>>
//检查手机号来源
@GET("user/phone_detection")
fun checkPhoneStatus(@Query("phone") phone: String, @Query("countryCode") countryCode: String): Observable<BaseResponse<ChcekPhoneResponeBean>>
//服务端校验阿里一键认证
@POST("phone/verification/init")
fun checkAliAuth(@Body body: RequestBody): Observable<BaseResponse<PhoneAuthResponseBean>>
//一键登录
@POST("user/login_direct")
fun autoLogin(@Body body: RequestBody): Observable<BaseResponse<UserResponse>>
//手机号密码登录
@POST("user/login_pwd")
fun loginByPassword(@Body body: RequestBody): Observable<BaseResponse<UserResponse>>
//重新设置密码
@POST("user/reset_pwd")
fun resetPwd(@Body body: RequestBody): Observable<BaseResponse<UserResponse>>
//验证重置密码的短信验证码
@GET("user/precheck_reset_sms")
fun checkResetCode(@Query("phone") phone: String, @Query("countryCode") countryCode: String, @Query("code") code: String): Observable<BaseResponse<Any>>
//发送登录验证码
@GET("user/send_login_sms")
fun sendLoginMsgCode(@Query("phone") phone: String, @Query("countryCode") countryCode: String): Observable<BaseResponse<Any>>
//发送忘记密码重置密码的验证码
@GET("user/send_reset_sms")
fun sendResetCode(@Query("phone") phone: String, @Query("countryCode") countryCode: String): Observable<BaseResponse<Any>>
//绑定手机号
@POST("user/bind_phone")
fun bindPhone(@Body body: RequestBody): Observable<BaseResponse<Any>>
//验证码登录
@POST("user/login_sms")
fun loginByMsgCode(@Body body: RequestBody): Observable<BaseResponse<UserResponse>>
//第三方登录获取用户信息
@POST("user/user_q_w")
fun thirdPartJavaLogin(@Body body: RequestBody): Observable<BaseResponse<UserResponse>>
//第三方登录解绑
@POST("user/unbind_third")
fun unBindThirdLogin(@Body body: RequestBody): Observable<BaseResponse<Any>>
}
\ No newline at end of file
package com.yidianling.user.http
import android.app.Activity
import com.google.gson.internal.LinkedTreeMap
import com.umeng.socialize.bean.SHARE_MEDIA
import com.yidianling.router.user.UserResponse
import com.yidianling.user.http.request.*
import com.yidianling.user.http.response.CheckPassword
import com.yidianling.user.http.response.CountryResponse
import com.yidianling.user.http.response.ExistResponse
import com.yidianling.ydlcommon.http.BaseAPIResponse
import com.yidianling.ydlcommon.http.BaseResponse
import com.yidianling.ydlcommon.http.api.Command
import io.reactivex.Observable
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/02/02
*/
interface UserHttp {
fun login(param: LoginParam): Observable<BaseResponse<UserResponse>>
fun countryList(): Observable<BaseResponse<CountryResponse>>
fun phoneExist(param: ExistParam): Observable<BaseResponse<ExistResponse>>
fun code(param: CodeParam): Observable<BaseResponse<Any>>
fun bindPhone(param: BindPhoneParam): Observable<BaseResponse<UserResponse>>
fun forget(param: ForgetParam): Observable<BaseResponse<Any>>
fun register(param: RegisterParam): Observable<BaseResponse<Any>>
fun channelId(param: ChannelIdParam): Observable<BaseResponse<LinkedTreeMap<String, String>>>
fun thirdPartLogin(param: ThirdLoginParam): Observable<BaseAPIResponse<UserResponse>>
fun setUserInfo(param: UserInfoParam): Observable<BaseResponse<Any>>
fun uploadHead(param: HeadParam): Observable<BaseResponse<Any>>
fun checkPhonePass(cmd: Command.CheckPhonePass): Observable<BaseResponse<CheckPassword>>
fun bindQQ(param: BindQQ): Observable<BaseResponse<Any>>
fun bindWX(param: BindWX): Observable<BaseResponse<Any>>
fun logout(param: Logout): Observable<BaseResponse<Any>>
fun checkPwd(param: CheckPwd): Observable<BaseResponse<Any>>
fun changePhone(param: ChangePhone): Observable<BaseResponse<Any>>
fun privacyAgree(uid: String): Observable<BaseResponse<Any>>
fun thirdPartJavaLogin(param: ThirdLoginParam): Observable<BaseResponse<UserResponse>>
// 友盟第三方登录
fun umLogin(activity: Activity, media: SHARE_MEDIA): Observable<ThirdLoginParam>
fun unBindThirdLogin(param: UnBindThirdLoginParam): Observable<BaseResponse<Any>>
}
\ No newline at end of file
package com.yidianling.user.http
import android.app.Activity
import com.google.gson.Gson
import com.google.gson.internal.LinkedTreeMap
import com.umeng.socialize.bean.SHARE_MEDIA
import com.yidianling.common.tools.RxAppTool
import com.yidianling.common.tools.RxDeviceTool
import com.yidianling.router.user.UserResponse
import com.yidianling.user.UserHelper
import com.yidianling.user.http.request.*
import com.yidianling.user.http.response.CheckPassword
import com.yidianling.user.http.response.CountryResponse
import com.yidianling.user.http.response.ExistResponse
import com.yidianling.user.rxlogin.LoginObservable
import com.yidianling.ydlcommon.app.YdlCommonApp
import com.yidianling.ydlcommon.http.*
import com.yidianling.ydlcommon.http.api.Command
import com.yidianling.ydlcommon.router.YdlCommonOut
import io.reactivex.Observable
import io.reactivex.schedulers.Schedulers
import okhttp3.MediaType
import okhttp3.RequestBody
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/02/02
*/
class UserHttpImpl private constructor() : UserHttp {
companion object {
fun getInstance(): UserHttpImpl {
return Holder.INSTANCE
}
fun clearUserApi() {
Holder.INSTANCE.userApi = null
}
}
private var userApi: UserApi? = null
private fun getUserApi(): UserApi {
if (userApi == null) {
userApi = RetrofitProvider.getRetrofit().create(UserApi::class.java)
}
return userApi!!
}
// private val userApi: UserApi by lazy {
// RetrofitProvider.getRetrofit()
// .create(UserApi::class.java)
// }
override fun login(param: LoginParam): Observable<BaseResponse<UserResponse>> {
return RxUtils.mapObservable(param)
.flatMap { getUserApi().login(it) }
}
override fun countryList(): Observable<BaseResponse<CountryResponse>> {
return getUserApi().countryList("")
.compose(RxUtils.netCheck())
}
override fun phoneExist(param: ExistParam): Observable<BaseResponse<ExistResponse>> {
return RxUtils.mapObservable(param)
.flatMap { getUserApi().phoneExists(it) }
}
override fun code(param: CodeParam): Observable<BaseResponse<Any>> {
return RxUtils.mapObservable(param)
.flatMap { getUserApi().getCode(it) }
}
override fun bindPhone(param: BindPhoneParam): Observable<BaseResponse<UserResponse>> {
return RxUtils.mapObservable(param)
.flatMap { getUserApi().bindPhone(it) }
}
override fun forget(param: ForgetParam): Observable<BaseResponse<Any>> {
return RxUtils.mapObservable(param)
.flatMap { getUserApi().forget(it) }
}
override fun register(param: RegisterParam): Observable<BaseResponse<Any>> {
return RxUtils.mapObservable(param)
.flatMap { getUserApi().register(it) }
}
override fun channelId(param: ChannelIdParam): Observable<BaseResponse<LinkedTreeMap<String, String>>> {
return RxUtils.mapObservable(param)
.flatMap { getUserApi().setChannelId(it) }
}
override fun thirdPartLogin(param: ThirdLoginParam): Observable<BaseAPIResponse<UserResponse>> {
var param: String = com.alibaba.fastjson.JSONObject.toJSONString(param)
val body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), param)
return RetrofitProvider.getRetrofit().newBuilder().baseUrl(YdlRetrofitUtils.SERVER_API_JAVA_URL).build()
.create(UserApi::class.java).thirdPartyLogin(body)
}
override fun setUserInfo(param: UserInfoParam): Observable<BaseResponse<Any>> {
return RxUtils.mapObservable(param)
.flatMap { getUserApi().setUserInfo(it) }
}
//验证账号密码
override fun checkPhonePass(cmd: Command.CheckPhonePass): Observable<BaseResponse<CheckPassword>> {
return RxUtils.mapObservable(cmd)
.flatMap { getUserApi().checkPhonePass(it) }
}
override fun uploadHead(param: HeadParam): Observable<BaseResponse<Any>> {
return Observable.just(param)
.compose(RxUtils.netCheck())
.subscribeOn(Schedulers.io())
.map {
val map = HashMap<String, RequestBody>()
val mediaType = MediaType.parse("text/plain")
map["type"] = RequestBody.create(mediaType, it.type)
map["value"] = RequestBody.create(mediaType, it.value)
map["ffrom"] = RequestBody.create(mediaType, YdlCommonOut.getChannelName())
map["isFromApp"] = RequestBody.create(mediaType, "1")
map["osBuild"] = RequestBody.create(mediaType, """${RxDeviceTool.getBuildBrandModel()},${RxDeviceTool.getSDKVersionName()},${RxAppTool.getAppVersionName(YdlCommonApp.getApp())}""")
map["ts"] = RequestBody.create(mediaType, (System.currentTimeMillis() / 1000).toString())
map["version"] = RequestBody.create(mediaType, RxAppTool.getAppVersionName(YdlCommonApp.getApp()))
val userInfo = UserHelper.getUserInfo()
if (userInfo != null) {
map["uid"] = RequestBody.create(mediaType, userInfo.uid)
map["accessToken"] = RequestBody.create(mediaType, userInfo.accessToken)
}
val fileBody = RequestBody.create(MediaType.parse("multipart/form-data"), it.file)
map.put("""head"; filename="${it.file.name}""", fileBody)
map
}
.flatMap {
getUserApi().uploadHeadImg(it)
}
}
override fun bindQQ(param: BindQQ): Observable<BaseResponse<Any>> {
return RxUtils.mapObservable(param)
.flatMap { getUserApi().bindQQ(it) }
}
override fun bindWX(param: BindWX): Observable<BaseResponse<Any>> {
return RxUtils.mapObservable(param)
.flatMap { getUserApi().bindWx(it) }
}
override fun logout(param: Logout): Observable<BaseResponse<Any>> {
return RxUtils.mapObservable(param)
.flatMap { getUserApi().logout(it) }
}
override fun checkPwd(param: CheckPwd): Observable<BaseResponse<Any>> {
return RxUtils.mapObservable(param)
.flatMap { getUserApi().checkPwd(it) }
}
override fun changePhone(param: ChangePhone): Observable<BaseResponse<Any>> {
return RxUtils.mapObservable(param)
.flatMap { getUserApi().changePhone(it) }
}
override fun privacyAgree(uid: String): Observable<BaseResponse<Any>> {
return YdlRetrofitUtils.getRxRetrofit().newBuilder().baseUrl(YdlRetrofitUtils.SERVER_API_JAVA_URL)
.build().create(UserApi::class.java).privacyAgree(uid)
}
override fun umLogin(activity: Activity, media: SHARE_MEDIA): Observable<ThirdLoginParam> {
return LoginObservable(activity, media)
}
override fun thirdPartJavaLogin(param: ThirdLoginParam): Observable<BaseResponse<UserResponse>> {
var str = Gson().toJson(param)
val body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str)
return YdlRetrofitUtils.getRxRetrofit().newBuilder().baseUrl(YdlRetrofitUtils.SERVER_API_JAVA_URL)
.build().create(UserApi::class.java).thirdPartJavaLogin(body)
}
override fun unBindThirdLogin(param: UnBindThirdLoginParam): Observable<BaseResponse<Any>> {
var str = Gson().toJson(param)
val body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str)
return YdlRetrofitUtils.getRxRetrofit().newBuilder().baseUrl(YdlRetrofitUtils.SERVER_API_JAVA_URL)
.build().create(UserApi::class.java).unBindThirdLogin(body)
}
private object Holder {
val INSTANCE = UserHttpImpl()
}
}
\ No newline at end of file
package com.yidianling.user.http.request
/**
* @author jiucheng
* @描述:java接口的绑定手机号
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/12/3
*/
data class BindPhoneJavaParam(
var accessCode: String,//skd token
var countryCode: String,//手机区号
var phoneNumber: String,//手机号
var verifyCode: String,// 验证码
var uid: String,
var type: Int = 2//2:Android
)
\ No newline at end of file
package com.yidianling.user.http.request
import com.yidianling.ydlcommon.data.http.EncryptUtils
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/02/05
*/
data class BindPhoneParam(val country_code: String,
val userName: String,
val vcode: String,
var passwd: String) {
init {
passwd = EncryptUtils.encryptMD5ToString(passwd)
}
}
\ No newline at end of file
package com.yidianling.user.http.request;
public class BindPhoneRequest {
String accessCode;
String countryCode;
String outId;
String phoneNumber;
int type;
String uid;
String verifyCode;
@Override
public String toString() {
return "BindPhoneRequest{" +
"accessCode='" + accessCode + '\'' +
", countryCode='" + countryCode + '\'' +
", outId='" + outId + '\'' +
", phoneNumber='" + phoneNumber + '\'' +
", type=" + type +
", uid='" + uid + '\'' +
", verifyCode='" + verifyCode + '\'' +
'}';
}
public BindPhoneRequest(String accessCode, String countryCode, String outId, String phoneNumber, int type, String uid, String verifyCode) {
this.accessCode = accessCode;
this.countryCode = countryCode;
this.outId = outId;
this.phoneNumber = phoneNumber;
this.type = type;
this.uid = uid;
this.verifyCode = verifyCode;
}
public String getAccessCode() {
return accessCode;
}
public void setAccessCode(String accessCode) {
this.accessCode = accessCode;
}
public String getCountryCode() {
return countryCode;
}
public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
public String getOutId() {
return outId;
}
public void setOutId(String outId) {
this.outId = outId;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public String getVerifyCode() {
return verifyCode;
}
public void setVerifyCode(String verifyCode) {
this.verifyCode = verifyCode;
}
}
\ No newline at end of file
package com.yidianling.user.http.request;
public class BindQQ {
public String openid;
public String unionid;
public BindQQ(String openid,String unionid) {
this.openid = openid;
this.unionid = unionid;
}
}
\ No newline at end of file
package com.yidianling.user.http.request;
public class BindWX {
public String openid;
public String unionid;
public BindWX(String openid, String unionid) {
super();
this.openid = openid;
this.unionid = unionid;
}
}
\ No newline at end of file
package com.yidianling.user.http.request;
//更换手机时最后校验验证码和手机
public class ChangePhone {
public String country_code;
public String vcode;
public String userName;
public ChangePhone(String country_code, String vcode, String userName) {
this.country_code = country_code;
this.vcode = vcode;
this.userName = userName;
}
}
\ No newline at end of file
package com.yidianling.ydlcommon.data.http.params
package com.yidianling.user.http.request
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/04/20
* time : 2018/02/05
*/
open class PayParam(payId: String, val type: String) {
data class ChannelIdParam(val channelId: String, val type: String) {
data class WxPayParam(val payId: String) : PayParam(payId, "wxapp_hz")
constructor(channelId: String): this(channelId, "android")
data class AliPayParam(val payId: String) : PayParam(payId, "aliapp")
}
\ No newline at end of file
package com.yidianling.user.http.request
/**
* @author jiucheng
* @描述:
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/12/1
*/
data class CheckAliAuthParam(
var phoneNumber: String,
var sdkVersion: String
)
\ No newline at end of file
package com.yidianling.user.http.request;
public class CheckPhone {
String ffrom;
InitPhoneRequest initPhoneRequest;
public CheckPhone(String ffrom, InitPhoneRequest initPhoneRequest) {
this.ffrom = ffrom;
this.initPhoneRequest = initPhoneRequest;
}
public String getFfrom() {
return ffrom;
}
public void setFfrom(String ffrom) {
this.ffrom = ffrom;
}
public InitPhoneRequest getInitPhoneRequest() {
return initPhoneRequest;
}
public void setInitPhoneRequest(InitPhoneRequest initPhoneRequest) {
this.initPhoneRequest = initPhoneRequest;
}
@Override
public String toString() {
return "{" +
"ffrom='" + ffrom + '\'' +
", initPhoneRequest=" + initPhoneRequest +
'}';
}
}
// "phoneNumber": "18258897036",
// "sdkVersion": "0.001"
package com.yidianling.user.http.request;
import com.yidianling.ydlcommon.data.http.EncryptUtils;
//更换手机时密码验证
public class CheckPwd {
public String passwd;
public CheckPwd(String passwd) {
this.passwd = EncryptUtils.encryptMD5ToString(passwd);
}
}
\ No newline at end of file
package com.yidianling.ydlcommon.data.http.response
package com.yidianling.user.http.request
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/04/20
* time : 2018/02/03
*/
data class Balance(val balance: Float)
\ No newline at end of file
data class CodeParam(val country_code: String,
val userName: String,
val smsAction: String)
\ No newline at end of file
package com.yidianling.ydlcommon.data.http.params
package com.yidianling.user.http.request
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/04/20
* time : 2018/02/03
*/
data class RechargeParam(val money: String)
\ No newline at end of file
data class ExistParam(val country_code: String,
val userName: String)
\ No newline at end of file
package com.yidianling.user.http.request
import com.yidianling.ydlcommon.data.http.EncryptUtils
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/02/05
*/
data class ForgetParam(val country_code: String,
val userName: String,
var passwd: String,
val vcode: String) {
init {
passwd = EncryptUtils.encryptMD5ToString(passwd)
}
}
\ No newline at end of file
package com.yidianling.user.http.request
import java.io.File
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/02/10
*/
data class HeadParam internal constructor(val type: String, val value: String, val file: File) {
constructor(file: File): this("head", "", file)
}
\ No newline at end of file
package com.yidianling.user.http.request;
import com.yidianling.ydlcommon.data.http.BaseCommand;
public class InitPhoneRequest extends BaseCommand {
String phoneNumber;
String sdkVersion;
public InitPhoneRequest(String phoneNumber, String sdkVersion) {
this.phoneNumber = phoneNumber;
this.sdkVersion = sdkVersion;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getSdkVersion() {
return sdkVersion;
}
public void setSdkVersion(String sdkVersion) {
this.sdkVersion = sdkVersion;
}
@Override
public String toString() {
return "{" +
"phoneNumber='" + phoneNumber + '\'' +
", sdkVersion='" + sdkVersion + '\'' +
'}';
}
}
\ No newline at end of file
package com.yidianling.user.http.request
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/02/02
*/
data class LoginParam(val country_code: String,
val userName: String,//手机号
val passwd: String?,//密码(md5后的密码)
val login_type: Int = 1, // 登录方式(密码,短信验证码)
val vcode: String?) { // 短信验证码)
private constructor(builder: Builder) : this(builder.country_code,
builder.userName,
builder.passwd,
builder.login_type,
builder.vcode)
companion object {
fun build(init: Builder.() -> Unit) = Builder(init).build()
}
class Builder private constructor() {
constructor(init: Builder.() -> Unit) : this() {
init()
}
lateinit var country_code: String
lateinit var userName: String
var passwd: String? = null
var login_type: Int = 0
var vcode: String? = null
fun country_code(init: Builder.() -> String) = apply { country_code = init() }
fun userName(init: Builder.() -> String) = apply { userName = init() }
fun passwd(init: Builder.() -> String) = apply { passwd = init() }
fun login_type(init: Builder.() -> Int) = apply { login_type = init() }
fun vcode(init: Builder.() -> String) = apply { vcode = init() }
fun build() = LoginParam(this)
}
}
\ No newline at end of file
package com.yidianling.user.http.request;
public class Logout {
public int force;
public Logout() {
}
public Logout(int force) {
this.force = force;
}
}
\ No newline at end of file
package com.yidianling.user.http.request
/**
* @author jiucheng
* @描述:一键登录
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/12/1
*/
data class PhoneLoginAutoParam(
var accessCode: String,//sdk token
var phoneNumber: String,//手机号
var type: Int = 2
)
\ No newline at end of file
package com.yidianling.user.http.request
/**
* @author jiucheng
* @描述:验证码登录
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/12/3
*/
data class PhoneLoginCodeParam(
var code: String,//验证码
var countryCode: String,//手机区号
var phoneNumber: String,//手机号
var type: Int = 2
)
\ No newline at end of file
package com.yidianling.user.http.request;
import com.yidianling.ydlcommon.data.PlatformDataManager;
public class PhoneLoginDirectRequest {
String accessCode;
String channelId;
String outId;
String phoneNumber;
int type;
String ffrom;
String version;
public PhoneLoginDirectRequest(String accessCode, String channelId, String outId, String phoneNumber, int type, String version) {
this.accessCode = accessCode;
this.channelId = channelId;
this.outId = outId;
this.phoneNumber = phoneNumber;
this.type = type;
this.version = version;
this.ffrom = PlatformDataManager.INSTANCE.getRam().getChannelName();//渠Y道来源
}
public String getChannelId() {
return channelId;
}
public void setChannelId(String channelId) {
this.channelId = channelId;
}
public String getFfrom() {
return ffrom;
}
public void setFfrom(String ffrom) {
this.ffrom = ffrom;
}
public String getAccessCode() {
return accessCode;
}
public void setAccessCode(String accessCode) {
this.accessCode = accessCode;
}
public String getchannelId() {
return channelId;
}
public void setchannelId(String channelId) {
this.channelId = channelId;
}
public String getOutId() {
return outId;
}
public void setOutId(String outId) {
this.outId = outId;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
@Override
public String toString() {
return "PhoneLoginDirectRequest{" +
"accessCode='" + accessCode + '\'' +
", channelId='" + channelId + '\'' +
", outId='" + outId + '\'' +
", phoneNumber='" + phoneNumber + '\'' +
", type=" + type +
", version='" + version + '\'' +
'}';
}
}
\ No newline at end of file
package com.yidianling.user.http.request
/**
* @author jiucheng
* @描述:手机号密码登录
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/12/3
*/
data class PhoneLoginPwdParam(
var password: String,//密码
var countryCode: String,//手机区号
var phoneNumber: String,//手机号
var type: Int = 2 //Android 端
)
\ No newline at end of file
package com.yidianling.user.http.request;
public class PhoneLoginPwdRequest {
String channelId;
String password ;
String countryCode;
int type;
String phoneNumber;
String version;
public PhoneLoginPwdRequest(String channelId, String password, String countryCode, int type, String phoneNumber, String version) {
this.channelId = channelId;
this.password = password;
this.countryCode = countryCode;
this.type = type;
this.phoneNumber = phoneNumber;
this.version = version;
}
public String getChannelId() {
return channelId;
}
public void setChannelId(String channelId) {
this.channelId = channelId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getCountryCode() {
return countryCode;
}
public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
}
\ No newline at end of file
package com.yidianling.user.http.request;
public class PhoneLoginSmsRequest {
String channelId;
String code;
String countryCode;
int type;
String phoneNumber;
String version;
@Override
public String toString() {
return "PhoneLoginSmsRequest{" +
"channelId='" + channelId + '\'' +
", code='" + code + '\'' +
", countryCode='" + countryCode + '\'' +
", type=" + type +
", phoneNumber='" + phoneNumber + '\'' +
", version='" + version + '\'' +
'}';
}
public PhoneLoginSmsRequest(String channelId, String code, String countryCode, int type, String phoneNumber, String version) {
this.channelId = channelId;
this.code = code;
this.countryCode = countryCode;
this.type = type;
this.phoneNumber = phoneNumber;
this.version = version;
}
public String getchannelId() {
return channelId;
}
public void setchannelId(String channelId) {
this.channelId = channelId;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getCountryCode() {
return countryCode;
}
public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
}
\ No newline at end of file
package com.yidianling.user.http.request
/**
* @author jiucheng
* @描述:重新设置密码
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/12/3
*/
data class PhoneResetPwdParam(
var newPassword: String,//新密码
var countryCode: String,//手机区号
var code: String,//验证码
var phoneNumber: String,//手机号
var type: Int = 2
)
\ No newline at end of file
package com.yidianling.user.http.request
import com.yidianling.ydlcommon.data.http.BaseCommand
import com.yidianling.ydlcommon.data.http.EncryptUtils
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/02/05
*/
class RegisterParam : BaseCommand {
var country_code: String? = null
var userName: String? = null
var passwd: String?=null
var vcode: String?=null
constructor(country_code: String?, userName: String?, passwd: String?, vcode: String?) : super() {
this.country_code = country_code
this.userName = userName
this.passwd = passwd
this.vcode = vcode
}
init {
passwd = EncryptUtils.encryptMD5ToString(passwd?:"")
}
}
package com.yidianling.user.http.request;
public class ResetPwdRequest {
String channelId;
String newPassword;
String countryCode;
String code;
int type;
String phoneNumber;
String version;
public ResetPwdRequest(String channelId, String newPassword, String countryCode, String code, int type, String phoneNumber, String version) {
this.channelId = channelId;
this.newPassword = newPassword;
this.countryCode = countryCode;
this.code = code;
this.type = type;
this.phoneNumber = phoneNumber;
this.version = version;
}
public String getchannelId() {
return channelId;
}
public void setchannelId(String channelId) {
this.channelId = channelId;
}
public String getNewPassword() {
return newPassword;
}
public void setNewPassword(String newPassword) {
this.newPassword = newPassword;
}
public String getCountryCode() {
return countryCode;
}
public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
@Override
public String toString() {
return "ResetPwdRequest{" +
"channelId='" + channelId + '\'' +
", newPassword='" + newPassword + '\'' +
", countryCode='" + countryCode + '\'' +
", code='" + code + '\'' +
", type=" + type +
", phoneNumber='" + phoneNumber + '\'' +
", version='" + version + '\'' +
'}';
}
}
\ No newline at end of file
package com.yidianling.user.http.request
import com.yidianling.ydlcommon.data.http.BaseCommand
import com.yidianling.ydlcommon.utils.JPushUtils
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/02/05
*/
class ThirdLoginParam : BaseCommand(){
var type: Int = 1
var channelId: String? = JPushUtils.getRegistrationID()
var openid: String? = null
var unionid: String? = null
var nickname: String? = null
var sex: String? = null
var city: String? = null
var login_type: String? = null //登录类型:qq或weixin
var headimgurl: String? = null
}
package com.yidianling.ydlcommon.actions.pay.model;
package com.yidianling.user.http.request;
/**
* @author jiucheng
* @描述:
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/9/26
* @date 2019/2/15
*/
public class OrderChangeCouponBean {
//优惠券集合(可用优惠券和不可用优惠券)
public OrderDataBean.CouponsList coupons;
public String coupon_money;
public class UnBindThirdLoginParam {
public int type;//1-微信 2-qq
// public String unionId;//第三方唯一标识
}
package com.yidianling.user.http.request;
import com.yidianling.ydlcommon.utils.JPushUtils;
public class UserInfoCmdparam {
public int type;
public String channelId;
public UserInfoCmdparam() {
this.type = 1;//android = 1 ios = 2
this.channelId = JPushUtils.INSTANCE.getRegistrationID();
}
}
package com.yidianling.ydlcommon.data.http.params
package com.yidianling.user.http.request
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/04/20
* time : 2018/02/09
*/
data class BalanceParam(val balance: Int)
\ No newline at end of file
data class UserInfoParam(val type: String, val value: String)
\ No newline at end of file
package com.yidianling.user.http.response;
import com.yidianling.user.http.request.*;
import com.yidianling.ydlcommon.data.http.BaseResponse;
import retrofit2.Call;
import retrofit2.http.*;
public interface AliAuthTokenApi {
// getVendorConfig
@POST("phone/verification/init")
Call<BaseResponse> getVendorConfig(@Header("ffrom") String ffrom, @Body InitPhoneRequest initPhoneRequest);
@POST("user/login_direct")
// Observable<BaseResponse> getLoginDirect(@Header("ffrom") String ffrom, @Body PhoneLoginDirectRequest phoneLoginDirectRequest);
Call<BaseResponse> getLoginDirect(@Header("ffrom") String ffrom, @Body PhoneLoginDirectRequest phoneLoginDirectRequest);
@POST("user/login_sms")
Call<BaseResponse> loginBySMS(@Header("ffrom") String ffrom, @Body PhoneLoginSmsRequest PhoneLoginSmsRequest);
//POST /user/login_pwd
@POST("user/login_pwd")
Call<BaseResponse> loginByPassword(@Header("ffrom") String ffrom, @Body PhoneLoginPwdRequest phoneLoginPwdRequest);
//POST /user/reset_pwd
@POST("user/reset_pwd")
Call<BaseResponse> resetPwd(@Body ResetPwdRequest resetPwdRequest);
@GET("user/phone_detection")
Call<BaseResponse> getPhoneDetection(@Query("phone") String phone, @Query("countryCode") String countryCode);
@GET("user/send_login_sms")
Call<BaseResponse> sendLoginSms(@Query("phone") String phone, @Query("countryCode") String countryCode);
@GET("user/send_reset_sms")
Call<BaseResponse> sendResetSms(@Query("phone") String phone, @Query("countryCode") String countryCode);
//验证重置密码的短信验证码
@GET("user/precheck_reset_sms")
Call<BaseResponse> precheckResetSms(@Query("phone") String phone, @Query("countryCode") String countryCode, @Query("code") String code);
//验证重置密码的短信验证码
@POST("user/bind_phone")
Call<BaseResponse> bindPhone(@Header("ffrom") String ffrom, @Body BindPhoneRequest bindPhoneRequest);
}
// fun bindQQ(@FieldMap params: Map<String, String>): Observable<BaseResponse<Any>>
package com.yidianling.user.http.response
/**
* @author jiucheng
* @描述:
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/12/1
*/
data class ChcekPhoneResponeBean(
val hasPwd: Int,//是否有密码 1 是 0 否
val isDoctor: Int,//是否是专家账号 1 是 0 否
val isRegistered: Int//是否已经注册 1 是 0 否
)
\ No newline at end of file
package com.yidianling.ydlcommon.data.http.params
package com.yidianling.user.http.response
/**
* //验证账号密码
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/04/18
* time : 2018/04/03
*/
data class WXRechargeIdParam(val rechargeId: String)
\ No newline at end of file
data class CheckPassword(val result: Int)
\ No newline at end of file
package com.yidianling.user.http.response;
\ No newline at end of file
package com.yidianling.user.http.response
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/02/03
*/
data class CountryResponse(val countryList: List<Country>) {
data class Country(val code: String,
val en_name: String,
val name: String)
}
\ No newline at end of file
package com.yidianling.ydlcommon.data.http.params
package com.yidianling.user.http.response
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/04/20
* time : 2018/02/03
*/
data class BalancePayParam(val payId: String)
\ No newline at end of file
data class ExistResponse(val isExist: Int) // 0不存在1存在
\ No newline at end of file
package com.yidianling.user.http.response
import com.mobile.auth.gatewayauth.model.VendorConfig
/**
* @author jiucheng
* @描述:服务端阿里认证返回数据
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2018/12/1
*/
data class PhoneAuthResponseBean(
var requestId: String,
var code: String,
var message: String,
var vendorConfigDTOs: List<VendorConfig>
)
\ No newline at end of file
package com.yidianling.user.route
import android.app.Activity
import android.content.Context
import android.content.Intent
import com.yidianling.user.bean.UserResponse
import com.yidianling.user.bean.`UserSetting.api`
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/04/13
*/
interface IUserRouter {
// 是否已登录
fun isLogin(): Boolean
fun isFirstLogin(): Boolean
fun setFirstLogin(first: Boolean)
fun isSafePrivacyClicked(): Boolean
fun putSafePrivacyClicked(clicked: Boolean)
fun setUserResponse(userInfo: UserResponse?)
fun getUserInfo(): UserResponse.UserInfo?
fun getUserResponse() : UserResponse?
fun getUserSetting(): `UserSetting.api`?
fun isBindPhone(): Boolean
fun putUnlockCheckSuccessTime(time: Long)
fun getChatTeamHisShow(): Boolean
fun setChatTeamHisShowed(showed : Boolean)
// 跳转到隐私界面的 Activity
fun privacyIntent(activity: Activity): Intent
fun loginWayIntent(context: Context): Intent
fun inputPhoneIntent(activity: Activity, smsAction: String): Intent
fun safeTipViewGone(): Boolean
fun setTrendsSafeTip(status: Boolean)
fun errorAgainTime(): Long
fun isFirstStart(): Boolean
fun updateUserInfoSp(userInfo: UserResponse.UserInfo?)
fun updateUserSetingSp(userSetting: `UserSetting.api`?)
fun clearUserInfo()
}
\ No newline at end of file
package com.yidianling.user.route;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import com.alibaba.android.arouter.facade.template.IProvider;
import com.yidianling.user.bean.UserResponse;
import com.yidianling.user.bean.UserSetting;
/**
* Created by haorui on 2019-09-23.
* Des:
*/
public interface IUserService extends IProvider {
boolean isLogin();
boolean isFirstLogin();
void setFirstLogin(boolean var1);
boolean isSafePrivacyClicked();
void putSafePrivacyClicked(boolean var1);
void setUserResponse( UserResponse var1);
UserResponse.UserInfo getUserInfo();
UserResponse getUserResponse();
UserSetting getUserSetting();
boolean isBindPhone();
void putUnlockCheckSuccessTime(long var1);
boolean getChatTeamHisShow();
void setChatTeamHisShowed(boolean var1);
Intent privacyIntent( Activity var1);
Intent loginWayIntent( Context var1);
Intent inputPhoneIntent( Activity var1, String var2);
boolean safeTipViewGone();
void setTrendsSafeTip(boolean var1);
long errorAgainTime();
boolean isFirstStart();
void updateUserInfoSp( UserResponse.UserInfo var1);
void updateUserSetingSp( UserSetting var1);
void clearUserInfo();
}
package com.yidianling.user.route
import android.app.Activity
import android.content.Context
import android.content.Intent
import com.ydl.user.UserService
import com.yidianling.router.RouterManager
import com.yidianling.router.im.IMLoginInfo
import com.yidianling.router.im.IMRequestCallback
import com.yidianling.ydlcommon.router.RouteServiceManager
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/02/05
*/
object UserIn {
fun getUserService(): IUserService {
return RouteServiceManager.provide(IUserService::class.java)
}
fun mainIntent(activity: Activity): Intent? {
// return RouterManager.getAppRouter()?.mainIntent(activity)
return null
}
fun mainIntent(context: Context, selectTab: Int): Intent? {
// return RouterManager.getAppRouter()?.mainIntent(context, selectTab, false)
return null
}
fun imSetAccount(account: String) {
// RouterManager.getImRouter().setAccount(account)
}
fun splashIntent(activity: Activity): Intent? {
// return RouterManager.getAppRouter()?.splashIntent(activity)
return null
}
fun setChattingAccountAll() {
// RouterManager.getImRouter().setChattingAccountAll()
}
fun setChattingAccountNone() {
// RouterManager.getImRouter().setChattingAccountNone()
}
fun imLogin(info: IMLoginInfo, callback: IMRequestCallback<IMLoginInfo>) {
RouterManager.getImRouter().login(info, callback)
}
fun imLogout() {
// RouterManager.getImRouter().logout()
}
// 关闭音频播放
fun closePlayer() {
// RouterManager.getCourseRouter()?.closePlayer()
// RouterManager.getFMRouter()?.closePlayer()
// RouterManager.getPhoneCallRouter()?.closePlayer()
}
// 清除 im 数据
fun clearImData() {
// RouterManager.getImRouter().clear()
}
}
\ No newline at end of file
package com.yidianling.user.route
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.text.TextUtils
import com.yidianling.common.tools.RxAppTool
import com.yidianling.user.UserHelper
import com.yidianling.user.bean.UserResponse
import com.yidianling.user.bean.`UserSetting.api`
import com.yidianling.user.safePrivate.FingerPrintUtil
import com.yidianling.user.safePrivate.PrivacyActivity
import com.yidianling.user.ui.InputPhoneActivity
import com.yidianling.user.ui.login.RegisterAndLoginActivity
import com.yidianling.ydlcommon.base.BaseApplication
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/04/13
*/
class UserRouterImp : IUserRouter {
override fun getUserSetting(): `UserSetting.api`? {
return UserHelper.getUsetSetting()
}
override fun updateUserInfoSp(userInfo: UserResponse.UserInfo?) {
UserHelper.updateUserinfo(userInfo)
}
override fun updateUserSetingSp(userSetting: `UserSetting.api`?) {
UserHelper.updateUserSetting(userSetting)
}
override fun setChatTeamHisShowed(showed: Boolean) {
UserHelper.getUsetSetting()?.chatTeamHisShowed = showed
}
override fun setUserResponse(userInfo: UserResponse?) {
UserHelper.setUserinfo(userInfo)
}
override fun getUserResponse(): UserResponse? {
return UserHelper.getUserInfo()
}
override fun isLogin(): Boolean {
return UserHelper.isLogin()
}
override fun isFirstLogin(): Boolean {
return UserHelper.getUserInfo()?.firstLogin==1
}
override fun setFirstLogin(first: Boolean) {
var value : Int = if (first) 1 else 2 //1是2否
UserHelper.getUserInfo()?.firstLogin = value
}
override fun isSafePrivacyClicked(): Boolean {
return UserHelper.getUsetSetting()?.meSafePrivateIsClick?:true
}
override fun putSafePrivacyClicked(clicked: Boolean) {
UserHelper.getUsetSetting()?.meSafePrivateIsClick = clicked
}
override fun getUserInfo(): UserResponse.UserInfo? {
return UserHelper.getUserInfo()?.userInfo
}
override fun isBindPhone(): Boolean {
return !TextUtils.isEmpty(UserHelper.getUserInfo()?.userInfo?.phone)
}
override fun putUnlockCheckSuccessTime(time: Long) {
UserHelper.getUsetSetting()?.unLockCheckSuccessTime = time
}
override fun getChatTeamHisShow(): Boolean {
return UserHelper.getUsetSetting()?.chatTeamHisShowed?:true
}
override fun privacyIntent(activity: Activity): Intent {
return Intent(activity, PrivacyActivity::class.java)
}
override fun loginWayIntent(context: Context): Intent {
return RegisterAndLoginActivity.getIntent(context)
}
override fun inputPhoneIntent(activity: Activity, smsAction: String): Intent {
return InputPhoneActivity.newIntent(activity, smsAction)
}
override fun safeTipViewGone(): Boolean {
//如果是非登录状态 或者 app指纹开启 或者 手势密码不为空 或者 已提示过安全解锁 -> 隐藏 设置密码提示
return !UserHelper.isLogin() || FingerPrintUtil.instance().fingerPrintIsOpen()
|| !TextUtils.isEmpty(FingerPrintUtil.instance().getHandPass())
|| FingerPrintUtil.instance().getTrendsSafeTip()
}
override fun setTrendsSafeTip(status: Boolean) {
FingerPrintUtil.instance().setTrendsSafeTip(status)
}
override fun errorAgainTime(): Long {
return FingerPrintUtil.errorAgainTime
}
override fun isFirstStart(): Boolean {
val lastVersionCode : Int = UserHelper.getUsetSetting()?.lastVersionCode?:0
val currentVersionCode : Int = RxAppTool.getAppVersionCode(BaseApplication.getApp())
if (lastVersionCode < currentVersionCode) {
UserHelper.getUsetSetting()?.lastVersionCode = currentVersionCode
return true
}
return false
}
override fun clearUserInfo() {
UserHelper.setUserinfo(null)
UserIn.clearImData()
}
}
\ No newline at end of file
package com.yidianling.user.rxlogin
import android.app.Activity
import android.os.Looper
import com.umeng.socialize.UMAuthListener
import com.umeng.socialize.UMShareAPI
import com.umeng.socialize.bean.SHARE_MEDIA
import com.yidianling.user.http.request.ThirdLoginParam
import com.yidianling.ydlcommon.http.CustomThrowable
import io.reactivex.Observable
import io.reactivex.Observer
import io.reactivex.android.MainThreadDisposable
/**
* author : Zhangwenchao
* e-mail : zhangwch@yidianling.com
* time : 2018/05/09
*/
class LoginObservable(val activity: Activity, private val media: SHARE_MEDIA): Observable<ThirdLoginParam>() {
override fun subscribeActual(observer: Observer<in ThirdLoginParam>?) {
if (!checkMainThread(observer)) {
return
}
val listener = Listener(observer)
observer?.onSubscribe(listener)
UMShareAPI.get(activity).deleteOauth(activity, media, listener)
UMShareAPI.get(activity).getPlatformInfo(activity, media, listener)
}
private class Listener(private val observer: Observer<in ThirdLoginParam>?): MainThreadDisposable(), UMAuthListener {
override fun onDispose() {
}
override fun onComplete(p0: SHARE_MEDIA?, p1: Int, p2: MutableMap<String, String>?) {
if (p0 == null || p2 == null) {
return
}
val param = ThirdLoginParam().apply {
openid = p2["uid"]
unionid = p2["unionid"]
nickname = p2["name"]
headimgurl = p2["iconurl"]
city = p2["city"]
sex = when {
p2["gender"].equals("男") -> "1"
else -> "2"
}
}
when (p0) {
SHARE_MEDIA.QQ -> {
param.apply {
login_type = "QQ"
}
}
SHARE_MEDIA.WEIXIN -> {
param.apply {
unionid = p2["uid"]
login_type = "weixin"
}
}
else -> { }
}
observer?.onNext(param)
}
override fun onCancel(p0: SHARE_MEDIA?, p1: Int) {
observer?.onError(CustomThrowable("已取消授权"))
}
override fun onError(p0: SHARE_MEDIA?, p1: Int, p2: Throwable?) {
observer?.onError(p2)
}
override fun onStart(p0: SHARE_MEDIA?) {
}
}
private fun checkMainThread(observer: Observer<*>?): Boolean {
if (Looper.myLooper() != Looper.getMainLooper()) {
observer?.onError(IllegalStateException(
"Expected to be called on the main thread but was " + Thread.currentThread().name))
return false
}
return true
}
}
\ No newline at end of file
package com.yidianling.user.safePrivate
import android.app.Activity
import android.content.Intent
import android.text.TextUtils
import android.view.View
import android.widget.EditText
import android.widget.TextView
import com.yidianling.ydlcommon.tool.StringUtils
import com.yidianling.common.tools.ToastUtil
import com.yidianling.user.R
import com.yidianling.user.UserHelper
import com.yidianling.user.http.UserHttpImpl
import com.yidianling.user.route.UserIn
import com.yidianling.ydlcommon.base.BaseActivity
import com.yidianling.ydlcommon.http.YdlRetrofitUtils
import com.yidianling.ydlcommon.http.api.Command
import com.yidianling.ydlcommon.view.TitleBar
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.activity_check_password.*
/**
* 验证登录密码
*/
class CheckPasswordActivity : BaseActivity() {
override fun layoutResId(): Int {
return R.layout.activity_check_password
}
override fun initDataAndEvent() {
type = intent.getStringExtra("type")
initView()
init()
}
var titBar: TitleBar? = null
var textPhone: android.widget.TextView? = null
var editPass: android.widget.EditText? = null
var btn_next: TextView? = null
//密码验证成功后的跳转类型
var type: String? = null
//跳转来源
companion object {
fun startActivity(activity: Activity) {
activity.startActivity(Intent(activity, CheckPasswordActivity::class.java))
}
fun startActivity(activity: Activity, type: String) {
val intent = Intent(activity, CheckPasswordActivity::class.java)
intent.putExtra("type", type)
activity.startActivity(intent)
}
}
fun initView() {
titBar = findViewById<TitleBar>(R.id.title_bar)
textPhone = findViewById<TextView>(R.id.text_phoneNumber)
editPass = findViewById<EditText>(R.id.edit_pass)
btn_next = findViewById<TextView>(R.id.btn_next)
}
fun init() {
var userPhone = UserHelper.getUserInfo()?.userInfo?.phone
if (userPhone !=null && userPhone.length == 11) {
userPhone = userPhone.substring(0, 3) + "****" + userPhone.substring(7, 11)
}
textPhone?.setText(userPhone)
btn_next?.setOnClickListener {
//向服务器验证用户密码
val string = editPass?.text.toString()
if (TextUtils.isEmpty(string)) {
ToastUtil.toastShort("密码不能为空")
} else {
showProgressDialog(null)
val cmd = Command.CheckPhonePass(StringUtils.md5(string))
UserHttpImpl.getInstance().checkPhonePass(cmd)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ s ->
dismissProgressDialog()
if (s.code==0){
val check = s.data
if (check.result == 1) {//1正确,0密码错误
if (type == "") {
//进入启动页
// UserIn.startSplash(mContext)
startActivity(UserIn.splashIntent(this))
finish()
} else {
//跳转手势密码设置界面
startActivity(android.content.Intent(mContext, SetHandUnLockActivity::class.java))
finish()
}
} else {
ToastUtil.toastShort("密码错误")
}
}else{
ToastUtil.toastShort(s.msg)
}
}, { t ->
dismissProgressDialog()
YdlRetrofitUtils.handleError(mContext, t)
})
}
}
editPass?.requestFocus()
//自动弹出键盘
// InputMethonUtils.showSoftInputFromWindow(mContext,editPass)
}
override fun showProgressDialog(str: String?) {
pb_load.visibility = View.VISIBLE
}
override fun dismissProgressDialog() {
pb_load.visibility = View.GONE
}
}
package com.yidianling.user.safePrivate
import android.text.TextUtils
import android.view.View
import android.widget.TextView
import com.ydl.ydl_image.module.GlideApp
import com.yidianling.user.R
import com.yidianling.user.UserHelper
import com.yidianling.user.route.UserIn
import com.yidianling.user.ui.login.RegisterAndLoginActivity
import com.yidianling.ydlcommon.base.BaseActivity
import com.yidianling.ydlcommon.dialog.CommonDialog
import com.yidianling.ydlcommon.event.FinishActivityEvent
import com.yidianling.ydlcommon.view.CircleImageView
import com.yidianling.ydlcommon.view.TitleBar
import de.greenrobot.event.EventBus
/**
* 登录验证指纹
*/
class FingerPrintCheckActivity : BaseActivity(), View.OnClickListener {
override fun initDataAndEvent() {
EventBus.getDefault().register(this)
isFromBackground = intent.getBooleanExtra("isFromBackground", false)
init()
}
override fun layoutResId(): Int {
return R.layout.activity_finger_print_check
}
//是否来自于后台启动验证
var isFromBackground = false
lateinit var title_bar: TitleBar
var headImg: CircleImageView? = null
var checkText: TextView? = null
var loginText: TextView? = null
//错误次数 最多三次
var error_num = 3
override fun onDestroy() {
super.onDestroy()
EventBus.getDefault().unregister(this)
}
fun init() {
title_bar = findViewById<TitleBar>(R.id.title_bar)
headImg = findViewById<CircleImageView>(R.id.head_img)
checkText = findViewById<TextView>(R.id.text_check)
loginText = findViewById<TextView>(R.id.text_login)
//设置头像
val head = UserHelper.getUserInfo()?.userInfo?.head
if (!TextUtils.isEmpty(head)) {
GlideApp.with(mContext).load(head).into(headImg)
}
checkText?.setOnClickListener(this)
loginText?.setOnClickListener(this)
//开始验证
checkFinger()
}
fun onEvent(activityName: FinishActivityEvent) {
if (activityName.activityName.equals(this::class.simpleName)) {
finish()
}
}
override fun onClick(v: View) {
when (v.id) {
R.id.text_check -> {
//弹出验证
checkFinger()
}
R.id.text_login -> {
//跳转登录验证
RegisterAndLoginActivity.start(this)
// finish()
}
}
}
//弹窗开始验证
fun checkFinger() {
//如果系统指纹功能被关闭(关闭状态下指纹会被清除的),则提示
if (FingerPrintUtil.instance().isHaveFingerPrint() ?: false == false) {
//锁屏密码已关闭
CommonDialog(mContext)
.setMessage("\n您的指纹信息发生变更,请在手机中重新添加指纹后返回解锁,或切换登录方式")
.setRightClick("确定") {
}
.setCancelAble(false)
.show()
return
}
//进入其他页面返回后验证错误次数
if (error_num < 1) {
CommonDialog(mContext)
.setMessage(FingerPrintUtil.errorLogin)
.setMessageColor(R.color.price_color)
.setRightClick("确定") {
//跳转登录
RegisterAndLoginActivity.start(this)
// finish()
}
.setCancelAble(false)
.show()
return
}
//判断系统指纹是否被暂时禁止
if (!FingerPrintUtil.getFingerPrintIsAviable()) {
CommonDialog(mContext)
.setImageCenter(R.drawable.lock_ico_zhiwen)
.setMessage(FingerPrintUtil.errorMoreMessage)
.setMessageColor(R.color.price_color)
.setRightClick("取消") {
//停止指纹监听
FingerPrintUtil.instance().cancelFingerListener()
}
.show()
return
}
var dia = CommonDialog(mContext)
.setImageCenter(R.drawable.lock_ico_zhiwen)
.setMessage("验证已有手机指纹")
.setRightClick("取消") {
}
.setOnDismiss {
//停止指纹监听
FingerPrintUtil.instance().cancelFingerListener()
}
dia.show()
FingerPrintUtil.instance().startFingerPrint(object : FingerPrintUtil.FingerCallback {
override fun onAuthenticationSucceeded() {
//
FingerPrintUtil.instance().setCurrentUnLockTime(System.currentTimeMillis())
if (!isFromBackground) {
startActivity(UserIn.splashIntent(this@FingerPrintCheckActivity))
}
//关闭手势解锁页面与指纹解锁页面
// EventBus.getDefault().post(FinishActivityEvent(FingerPrintCheckActivity::class.simpleName))
// EventBus.getDefault().post(FinishActivityEvent(HandUnlockCheckActivity::class.simpleName))
if (!isFinishing && dia != null) {
dia.dismiss()
dia = null
}
finish()
}
override fun onAuthenticationFailed() {
if (dia != null) {
dia.setMessage(FingerPrintUtil.errorMessage).setMessageColor(R.color.price_color)
//设置抖动动画
dia.setMessageShake(true)
}
error_num--
if (error_num < 1) {
//关闭指纹监听
FingerPrintUtil.instance().cancelFingerListener()
//错误次数太多
if (dia != null) {
dia.dismiss()
}
CommonDialog(mContext)
.setMessage(FingerPrintUtil.errorLogin)
.setMessageColor(R.color.price_color)
.setRightClick("确定") {
//跳转登录
//跳转登录
RegisterAndLoginActivity.start(this@FingerPrintCheckActivity)
}
.setCancelAble(false)
.show()
}
}
override fun onAuthenticationError() {
if (dia != null) {
dia.setMessage(FingerPrintUtil.errorMoreMessage).setMessageColor(R.color.price_color)
}
}
})
}
override fun onBackPressed() {
}
}
package com.yidianling.user.safePrivate
import android.app.KeyguardManager
import android.content.Context
import android.os.Build
import android.support.v4.hardware.fingerprint.FingerprintManagerCompat
import android.support.v4.os.CancellationSignal
import com.yidianling.common.tools.LogUtil
import com.yidianling.user.UserHelper
import com.yidianling.ydlcommon.app.YdlCommonApp
/**
* 指纹识别与手势管理器
* Created by harvie on 2017/6/10 0010.
*/
class FingerPrintUtil {
//存放解锁开关的文件
var manager: FingerprintManagerCompat? = null
var keyManager: KeyguardManager? = null
var context: Context = YdlCommonApp.getApp()
private var mCancellationSignal: CancellationSignal? = null
companion object {
//后台到前台(10分钟内不需要验证)
// val formBackgroundTime = 30*1000 //测试用
val formBackgroundTime = 10 * 60 * 1000
//指纹重试间隔时间
val errorAgainTime: Long = 2 * 60 * 1000
//指纹错误次数太多提示文案
val errorMoreMessage: String = "错误次数太多,请稍后再试"
//指纹错误提示文字
val errorMessage: String = "请重试"
//设置指纹多次错误的提示
val errorTime: String = "指纹功能锁定,请2分钟后重试"
//验证指纹或手势错误多次后提示
val errorLogin: String = "\n错误次数太多,请验证账号\n"
fun instance(): FingerPrintUtil {
var fin: FingerPrintUtil = Inner.finger
fin.init()
return fin
}
//当前指纹识别是否可用
fun getFingerPrintIsAviable(): Boolean {
var time = System.currentTimeMillis()
var errTime =UserHelper.getUsetSetting()?.fingerErrorTime?:0L
var jiange : Long = time - errTime
return jiange > FingerPrintUtil.errorAgainTime
}
}
/** ********************************************指纹相关设置********************************************** */
//设置指纹开关
fun setFingerStatus(on: Boolean) {
UserHelper.getUsetSetting()?.fingerPrintStatus = on
}
//app指纹是否开启
fun fingerPrintIsOpen(): Boolean {
return UserHelper.getUsetSetting()?.fingerPrintStatus?:false
}
private fun init() {
if (Build.VERSION.SDK_INT >= 23) {
if (manager == null && keyManager == null) {
manager = FingerprintManagerCompat.from(context)
keyManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
}
}
}
//硬件设备是否支持指纹解锁功能
fun isFingerPrintAvaliable(): Boolean? {
return if (Build.VERSION.SDK_INT >= 23) {
manager?.isHardwareDetected
} else {
false
}
}
//判断是否有锁屏密码
fun isLockHavePassword(): Boolean? {
return keyManager?.isKeyguardSecure
}
// 判断设备是否录入指纹,貌似APP无法直接唤醒指纹设置页面
fun isHaveFingerPrint(): Boolean? {
return if (Build.VERSION.SDK_INT >= 23) {
manager?.hasEnrolledFingerprints()
} else {
false
}
}
// 开始识别指纹
// 参数分别是:防止第三方恶意攻击的包装类,CancellationSignal对象,flags,回调对象,handle
fun startFingerPrint(call: FingerCallback) {
if (Build.VERSION.SDK_INT >= 23) {
if (mCancellationSignal == null) {
mCancellationSignal = CancellationSignal()
}
manager?.authenticate(null, 0, mCancellationSignal, object : FingerprintManagerCompat.AuthenticationCallback() {
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
super.onAuthenticationError(errorCode, errString)
call.onAuthenticationError()
LogUtil.d("操作过于频繁")
}
override fun onAuthenticationSucceeded(result: FingerprintManagerCompat.AuthenticationResult?) {
super.onAuthenticationSucceeded(result)
call.onAuthenticationSucceeded()
LogUtil.d("指纹识别成功")
}
override fun onAuthenticationFailed() {
super.onAuthenticationFailed()
call.onAuthenticationFailed()
LogUtil.d("指纹识别失败")
}
}, null)
}
}
//停止指纹监听
fun cancelFingerListener() {
if (Build.VERSION.SDK_INT >= 23) {
mCancellationSignal?.cancel()
mCancellationSignal = null
}
}
private object Inner {
val finger = FingerPrintUtil()
}
//指纹监听回调
interface FingerCallback {
fun onAuthenticationError()
fun onAuthenticationSucceeded()
fun onAuthenticationFailed()
}
/** *********************************************手势解锁相关方法********************************************** */
//保存手势密码
fun setHandPassword(password: String) {
UserHelper.getUsetSetting()?.gesturePassword = password
}
//读取手势密码
fun getHandPass(): String {
return UserHelper.getUsetSetting()?.gesturePassword?:""
}
/************************************************其他与解锁相关的设置************************************************/
//获取动态页面是否提示过安全解锁
fun getTrendsSafeTip(): Boolean {
return UserHelper.getUsetSetting()?.trendsIsClick?:true
}
//设置动态页面提示
fun setTrendsSafeTip(status: Boolean) {
UserHelper.getUsetSetting()?.trendsIsClick = status
}
//设置当前解锁成功时间
fun setCurrentUnLockTime(time: Long) {
UserHelper.getUsetSetting()?.unLockCheckSuccessTime = time
}
//是否设置指纹或手势密码
fun appIsSetUnLockPass(): Boolean {
return fingerPrintIsOpen() || !getHandPass().equals("")
}
//后台到前台是否需要解锁验证
fun isShowActivity(): Boolean {
//是否已设置解锁
if (!fingerPrintIsOpen() && getHandPass().equals("")) {
return false
}
var firstTime = UserHelper.getUsetSetting()?.unLockCheckSuccessTime?:System.currentTimeMillis()
var curTime = System.currentTimeMillis()
if (curTime - firstTime > formBackgroundTime) {
//需要解锁验证
return true
}
return false
}
}
\ No newline at end of file
package com.yidianling.user.safePrivate
import android.content.Intent
import android.view.View
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import com.yidianling.user.R
import com.yidianling.user.UserConstants
import com.yidianling.user.UserHelper
import com.yidianling.user.ui.InputPhoneActivity
import com.yidianling.ydlcommon.base.BaseActivity
import com.yidianling.ydlcommon.dialog.CommonDialog
import com.yidianling.ydlcommon.event.BuryPointEventManager
import com.yidianling.ydlcommon.view.MyToggleButton
/**
* 安全隐私--手势解锁--指纹解锁
* Created by harvie on 2017/6/10 0010.
*/
class PrivacyActivity : BaseActivity() {
override fun layoutResId(): Int {
return R.layout.activity_me_privacy
}
override fun initDataAndEvent() {
init()
}
var rela_finger: android.widget.RelativeLayout? = null
var fingerToggle: MyToggleButton? = null
var handToggle: MyToggleButton? = null
var finger_tip: TextView? = null
var lin_update: LinearLayout? = null
override fun onResume() {
super.onResume()
//设置开关状态
setStatus()
}
fun setStatus() {
//设置开关状态
if (FingerPrintUtil.Companion.instance().fingerPrintIsOpen()) {
fingerToggle?.setToggleOn()
} else {
fingerToggle?.setToggleOff()
}
if (!FingerPrintUtil.Companion.instance().getHandPass().equals("")) {
handToggle?.setToggleOn()
} else {
handToggle?.setToggleOff()
}
if (!FingerPrintUtil.instance().getHandPass().equals("")) {
lin_update?.visibility = View.VISIBLE
} else {
lin_update?.visibility = View.GONE
}
}
fun init() {
finger_tip = findViewById<TextView>(R.id.finger_tip) as TextView
rela_finger = findViewById<RelativeLayout>(R.id.rela_finger) as RelativeLayout
fingerToggle = findViewById<MyToggleButton>(R.id.zhiwen) as MyToggleButton
handToggle = findViewById<MyToggleButton>(R.id.shoushi) as MyToggleButton
lin_update = findViewById<LinearLayout>(R.id.lin_update) as LinearLayout
//修改手势密码
lin_update?.setOnClickListener({
startActivity(Intent(mContext, CheckPasswordActivity::class.java))
})
var bo: Boolean? = FingerPrintUtil.Companion.instance().isFingerPrintAvaliable()
if (bo != null && bo) {
//支持指纹的设备显示指纹解锁栏目
rela_finger?.visibility = android.view.View.VISIBLE
finger_tip?.visibility = android.view.View.VISIBLE
fingerToggle?.setOnToggleChanged(object : MyToggleButton.OnToggleChanged {
override fun onToggle(on: Boolean) {
if (on) {
//开启指纹识别--验证指纹
//如果用户没有可用指纹--提示录入指纹
if (FingerPrintUtil.Companion.instance().isHaveFingerPrint() ?: false == false) {
CommonDialog(mContext)
.setMessage("\n你尚未设置指纹或指纹功能\n未启用,请在手机系统中添加指纹\n")
.setRightClick("确定", {
fingerToggle?.setToggleOff()
})
.setCancelAble(false)
.show()
return
}
//判断是否绑定手机号
if (!UserHelper.isBindPhone()) {
CommonDialog(mContext)
.setMessage("\n为了您的账号安全,请绑定手机号\n")
.setLeftOnclick("取消", {
fingerToggle?.setToggleOff()
})
.setRightClick("确定", {
fingerToggle?.setToggleOff()
//跳转绑定手机号页面
InputPhoneActivity.start(mContext, UserConstants.BIND_PHONE_ACTION, null, false)
})
.setCancelAble(false)
.show()
return
}
//跳转指纹设置页
startActivity(Intent(mContext, SetFingerPrintActivity::class.java))
} else {
//提示
CommonDialog(mContext)
.setMessage("\n确认关闭指纹解锁?\n")
.setLeftOnclick("取消", {
fingerToggle?.setToggleOn()
})
.setRightClick("确定", {
//关闭指纹识别
FingerPrintUtil.Companion.instance().setFingerStatus(on)
//买点统计
BuryPointEventManager.FingerprintClick(on)
})
.setCancelAble(false)
.show()
}
}
})
}
handToggle?.setOnToggleChanged(object : MyToggleButton.OnToggleChanged {
override fun onToggle(on: Boolean) {
if (on) {
//判断是否绑定手机号
if (!UserHelper.isBindPhone()) {
CommonDialog(mContext)
.setMessage("\n为了您的账号安全,请绑定手机号\n")
.setLeftOnclick("取消", {
handToggle?.setToggleOff()
})
.setRightClick("确定", {
handToggle?.setToggleOff()
//跳转绑定手机号页面
InputPhoneActivity.start(mContext, UserConstants.BIND_PHONE_ACTION, null, false);
})
.setCancelAble(false)
.show()
return
}
//验证登录密码
CheckPasswordActivity.startActivity(mContext)
} else {
//提示
CommonDialog(mContext)
.setMessage("\n确认关闭手势密码?\n")
.setLeftOnclick("取消", {
handToggle?.setToggleOn()
})
.setRightClick("确定", {
lin_update?.visibility = View.GONE
FingerPrintUtil.Companion.instance().setHandPassword("")
//买点统计
BuryPointEventManager.GestureClick(on)
})
.show()
}
}
})
}
}
package com.yidianling.user.safePrivate
import android.view.View
import android.widget.TextView
import com.yidianling.common.tools.ToastUtil
import com.yidianling.user.R
import com.yidianling.user.UserHelper
import com.yidianling.user.ui.login.RegisterAndLoginActivity
import com.yidianling.ydlcommon.base.BaseActivity
import com.yidianling.ydlcommon.dialog.CommonDialog
import com.yidianling.ydlcommon.event.BuryPointEventManager
import com.yidianling.ydlcommon.view.TitleBar
/**
* 设置指纹
*/
class SetFingerPrintActivity : BaseActivity(), View.OnClickListener {
override fun layoutResId(): Int {
return R.layout.activity_finger_print_set
}
override fun initDataAndEvent() {
init()
}
var title_bar: TitleBar? = null
var checkText: TextView? = null
fun init() {
title_bar = findViewById<TitleBar>(R.id.title_bar)
checkText = findViewById<TextView>(R.id.text_check)
checkText?.setOnClickListener(this)
//开始验证
checkFinger()
}
override fun onClick(v: View) {
when (v.id) {
R.id.text_check -> {
//弹出验证
checkFinger()
}
R.id.text_login -> {
//跳转登录验证
RegisterAndLoginActivity.start(this@SetFingerPrintActivity)
}
}
}
//弹窗开始验证
fun checkFinger() {
var dia = CommonDialog(mContext)
.setImageCenter(R.drawable.lock_ico_zhiwen)
.setMessage("验证已有手机指纹")
.setRightClick("取消") {
}
.setOnDismiss {
//停止指纹监听
FingerPrintUtil.instance().cancelFingerListener()
}
dia.show()
//判断系统指纹是否可用
if (!FingerPrintUtil.getFingerPrintIsAviable()) {
if (dia != null) {
dia.setMessage(FingerPrintUtil.errorMoreMessage).setMessageColor(R.color.price_color)
FingerPrintUtil.instance().cancelFingerListener()
}
return
}
FingerPrintUtil.instance().startFingerPrint(object : FingerPrintUtil.FingerCallback {
override fun onAuthenticationSucceeded() {
//设置成功
ToastUtil.toastShort("设置成功")
FingerPrintUtil.instance().setFingerStatus(true)
FingerPrintUtil.instance().cancelFingerListener()
//隐藏红点
UserHelper.getUsetSetting()?.meSafePrivateIsClick = true
//买点统计
BuryPointEventManager.FingerprintClick(true)
finish()
}
override fun onAuthenticationFailed() {
if (dia != null) {
dia.setMessage(FingerPrintUtil.errorMessage).setMessageColor(R.color.price_color)
//设置抖动动画
dia.setMessageShake(true)
}
}
override fun onAuthenticationError() {
if (dia != null) {
dia.setMessage(FingerPrintUtil.errorMoreMessage)
dia.dismiss()
}
ToastUtil.toastShort(FingerPrintUtil.errorTime)
//保存当前错误时间
UserHelper.getUsetSetting()?.fingerErrorTime = System.currentTimeMillis()
finish()
}
})
}
}
package com.yidianling.user.safePrivate
import android.support.v4.content.ContextCompat
import android.view.View
import android.widget.TextView
import com.yidianling.common.tools.ToastUtil
import com.yidianling.user.R
import com.yidianling.user.UserHelper
import com.yidianling.ydlcommon.ActivityManager
import com.yidianling.ydlcommon.base.BaseActivity
import com.yidianling.ydlcommon.dialog.CommonDialog
import com.yidianling.ydlcommon.event.BuryPointEventManager
import com.yidianling.ydlcommon.view.TitleBar
import com.yidianling.ydlcommon.view.shoushi.Lock9View
import com.yidianling.ydlcommon.view.shoushi.LockIndicator
/**
* 设置手势解锁界面
*/
class SetHandUnLockActivity : BaseActivity() {
override fun layoutResId(): Int {
return R.layout.activity_hand_unlock_set
}
override fun initDataAndEvent() {
init()
}
var titleBar: TitleBar? = null
var tip_bar: LockIndicator? = null
var tipText: TextView? = null
var lock9: Lock9View? = null
//第一次设置的密码
var first_pass: String? = null
fun init() {
titleBar = findViewById<TitleBar>(R.id.title_bar) as TitleBar
tip_bar = findViewById<LockIndicator>(R.id.tip_bar) as LockIndicator
tipText = findViewById<TextView>(R.id.text_tip) as TextView
lock9 = findViewById<Lock9View>(R.id.lock9View) as Lock9View
titleBar?.setRightTextColor(ContextCompat.getColor(this, R.color.google_green))
titleBar?.setRightTextVisiable(View.GONE)
titleBar?.setLeftImageListener {
onBackPressed()
}
titleBar?.setOnRightTextClick { _, _ ->
//重新绘制
first_pass = null
tipText?.visibility = View.INVISIBLE
tip_bar?.setPath(null)
lock9?.reSet()
lock9?.setSuccessPass(null)
}
lock9?.setCallBack(object : Lock9View.CallBack {
override fun onStart() {
if (first_pass != null) {
tipText?.setText("")
tipText?.setTextColor(ContextCompat.getColor(this@SetHandUnLockActivity, R.color.tag_text))
}
}
override fun onFinish(password: String) {
if (first_pass == null) {
//提示再次输入
if (password.length < 4) {
ToastUtil.toastShort("不能少于4个连接点")
return
}
lock9?.setSuccessPass(password)
tipText?.visibility = View.VISIBLE
tipText?.setText("再次绘制图案进行确认")
tipText?.setTextColor(ContextCompat.getColor(this@SetHandUnLockActivity, R.color.tag_text))
titleBar?.setRightTextVisiable(View.VISIBLE)
first_pass = password
tip_bar?.setPath(password)
} else {
if (password.length < 4) {
ToastUtil.toastShort("不能少于4个连接点")
return
}
//第二次输入--判断与第一次是否一致
if (password.equals(first_pass)) {
//手势密码设置成功
lock9?.setSuccessPass(null)
FingerPrintUtil.instance().setHandPassword(password)
//买点统计
BuryPointEventManager.GestureClick(true)
ToastUtil.toastShort("设置成功")
//关闭手势解锁页面与指纹解锁页面
ActivityManager.getInstance().finishActivity(FingerPrintCheckActivity::class.java)
ActivityManager.getInstance().finishActivity(HandUnlockCheckActivity::class.java)
FingerPrintUtil.instance().setCurrentUnLockTime(System.currentTimeMillis())
//隐藏红点
UserHelper.getUsetSetting()?.meSafePrivateIsClick = true
finish()
} else {
//与上次密码不一致,请重新绘制
tipText?.text = "与上次输入不一致,请重新绘制"
tipText?.setTextColor(ContextCompat.getColor(this@SetHandUnLockActivity, R.color.price_color))
}
}
}
})
}
override fun onBackPressed() {
CommonDialog(mContext)
.setMessage("\n确认退出手势设置流程吗\n")
.setLeftOnclick("取消", {})
.setRightClick("退出", {
finish()
})
.setCancelAble(false)
.show()
}
}
package com.yidianling.user.ui;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.jaeger.library.StatusBarUtil;
import com.yidianling.user.R;
import com.yidianling.user.http.UserHttp;
import com.yidianling.user.http.UserHttpImpl;
import com.yidianling.user.http.response.CountryResponse.Country;
import com.yidianling.ydlcommon.base.BaseActivity;
import com.yidianling.ydlcommon.http.RxUtils;
import com.yidianling.ydlcommon.http.ThrowableConsumer;
import com.yidianling.ydlcommon.remind.ToastHelper;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
/**
* 选择国家和地区
* Created by Wi1ls on 2016/11/23;
*/
public class CountryListActivity extends BaseActivity {
ListView mListView;
ImageView iv_close;
String userCountryCode;
private CountryAdapter mAdapter;
private List<Country> list = new ArrayList<>();
@Override
protected int layoutResId() {
return R.layout.activity_country_list;
}
@Override
protected void initDataAndEvent() {
StatusBarUtil.setTransparent(this);
Intent intent = getIntent();
userCountryCode = intent.getStringExtra("userCountryCode");
mListView = findViewById(R.id.country_lv);
iv_close = findViewById(R.id.iv_close);
iv_close.setOnClickListener(view -> {
overridePendingTransition(0, R.anim.slide_out_to_bottom);
finish();
});
init();
}
void init() {
mAdapter = new CountryAdapter(list, this, userCountryCode);
mListView.setAdapter(mAdapter);
getData();
}
public void getData() {
UserHttp userHttp = UserHttpImpl.Companion.getInstance();
userHttp.countryList()
.subscribeOn(Schedulers.io())
.compose(RxUtils.resultData())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(countryResponse -> {
list.addAll(countryResponse.getCountryList());
mAdapter.notifyDataSetChanged();
}, new ThrowableConsumer() {
@Override
public void accept(@NotNull String msg) {
ToastHelper.Companion.show(msg);
}
});
}
public class CountryAdapter extends BaseAdapter {
private List<Country> list;
private Context context;
private String userCountryCode;
public CountryAdapter(List<Country> list, Context context, String userCountryCode) {
this.list = list;
this.context = context;
this.userCountryCode = userCountryCode;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = LayoutInflater.from(context).inflate(R.layout.item_country_phone_code, parent, false);
TextView nameTv = view.findViewById(R.id.tv_name);
TextView codeTv = view.findViewById(R.id.tv_code);
final Country c = list.get(position);
nameTv.setText(c.getName());
codeTv.setText("+" + c.getCode().replace("00", ""));
if (c.getCode().equals(userCountryCode)) {
nameTv.setTextColor(Color.parseColor("#1DA1F2"));
codeTv.setTextColor(Color.parseColor("#1DA1F2"));
}
view.setOnClickListener(v -> {
Intent i = new Intent();
i.putExtra("code", c.getCode());
i.putExtra("name", c.getName());
i.putExtra("en_name", c.getEn_name());
setResult(45, i);
overridePendingTransition(0, R.anim.slide_out_to_bottom);
finish();
});
return view;
}
}
}
package com.yidianling.user.ui;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.View;
import com.yidianling.router.user.UserResponse;
import com.yidianling.user.LoginContract;
import com.yidianling.user.LoginPresenter;
import com.yidianling.user.R;
import com.yidianling.user.UserConstants;
import com.yidianling.user.http.request.LoginParam;
import com.yidianling.user.route.UserIn;
import com.yidianling.user.safePrivate.FingerPrintCheckActivity;
import com.yidianling.user.safePrivate.FingerPrintUtil;
import com.yidianling.user.safePrivate.HandUnlockCheckActivity;
import com.yidianling.ydlcommon.ActivityManager;
import com.yidianling.ydlcommon.http.EncryptUtils;
import com.yidianling.ydlcommon.log.LogHelper;
import com.yidianling.ydlcommon.mvp.MVPActivity;
import com.yidianling.ydlcommon.remind.ToastHelper;
import com.yidianling.ydlcommon.utils.UMEventUtils;
import com.yidianling.ydlcommon.view.DeleteEditTextView;
import com.yidianling.ydlcommon.view.JumpTextView;
import com.yidianling.ydlcommon.view.RoundCornerButton;
import com.yidianling.ydlcommon.view.TitleBar;
import org.jetbrains.annotations.NotNull;
import de.greenrobot.event.EventBus;
/**
* 手机登陆界面
*/
public class LoginActivity extends MVPActivity<LoginContract.Presenter> implements LoginContract.View, View.OnClickListener {
private String defaultCode = "0086";
int isSplash;
TitleBar tbTitle;
DeleteEditTextView tvPhone;
DeleteEditTextView tvPassword;
RoundCornerButton btnLogin;
JumpTextView tvCountry;
private boolean isFromSplash;
private static String IS_SPLASH = "isSplash";
private static String IS_FROM_SPLASH = "isFromSplash";
public static Intent newIntent(Context context, int isSplash, boolean isFromSplash) {
Intent intent = new Intent(context, LoginActivity.class);
intent.putExtra(IS_SPLASH, isSplash);
intent.putExtra(IS_FROM_SPLASH, isFromSplash);
return intent;
}
@Override
protected int layoutResId() {
return R.layout.activity_login;
}
@Override
protected void initDataAndEvent() {
LogHelper.Companion.getInstance().writeLogSync("登录界面创建");
tbTitle = findViewById(R.id.tb_title);
tvPhone = findViewById(R.id.detv_phone);
tvPassword = findViewById(R.id.detv_password);
btnLogin = findViewById(R.id.rcb_login);
tvCountry = findViewById(R.id.jtv_country);
tvCountry.setOnClickListener(this);
findViewById(R.id.sms_fast_login).setOnClickListener(this);
btnLogin.setOnClickListener(this);
findViewById(R.id.register).setOnClickListener(this);
isSplash = getIntent().getIntExtra(IS_SPLASH, 0);
isFromSplash = getIntent().getBooleanExtra(IS_FROM_SPLASH, false);
init();
}
@NotNull
@Override
protected LoginContract.Presenter createPresenter() {
return new LoginPresenter(this);
}
void init() {
UMEventUtils.um_login(this);
if (isSplash == -1) {//启动app进入,无取消
tbTitle.setmLeftText("");
tbTitle.setOnLeftTextClick((view, isActive) -> {
});
} else {//推出帐号进入的login,有取消
tbTitle.setOnLeftTextClick((view, isActive) -> LoginActivity.this.finish());
}
}
@Override
public void onClick(View v) {
int i = v.getId();
if (i == R.id.sms_fast_login) {
InputPhoneActivity.start(this, UserConstants.SIGNIN_ACTION, tvPhone.getText().toString(), isFromSplash);
} else if (i == R.id.rcb_login) {
login();
} else if (i == R.id.register) {
InputPhoneActivity.start(this, UserConstants.REGISTER_ACTION, null, isFromSplash);
} else if (i == R.id.jtv_country) {
startActivityForResult(new Intent(this, CountryListActivity.class), 44);
}
}
private void login() {
final String phone = tvPhone.getText().toString();
if (TextUtils.isEmpty(phone)) {
ToastHelper.Companion.show("请输入正确的手机号");
return;
}
final String password = EncryptUtils.encryptMD5ToString(tvPassword.getText().toString());
getPresenter().login(new LoginParam(defaultCode, phone, password, 1, null));
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 44 && resultCode == 45) {
defaultCode = data.getStringExtra("code");
String defaultCountry = data.getStringExtra("name");
tvCountry.setLeftText(String.format("%s +%s", defaultCountry, defaultCode));
}
}
@Override
public void startLogin() {
btnLogin.disableButton();
showProgressDialog("");
}
@Override
public void loginSuccess(UserResponse userInfo) {
finishFinger();
int size = ActivityManager.Companion.getActivitySize();
if (size == 2 || size == 1) {
ActivityManager.Companion.finishAll();
startActivity(UserIn.INSTANCE.mainIntent(this));
} else {
finish();
}
}
//关闭手势解锁页面与指纹解锁页面
private void finishFinger() {
ActivityManager.Companion.getInstance().finishActivity(FingerPrintCheckActivity.class);
ActivityManager.Companion.getInstance().finishActivity(HandUnlockCheckActivity.class);
FingerPrintUtil.Companion.instance().setCurrentUnLockTime(System.currentTimeMillis());
}
@Override
public void loginFail(@NotNull String msg) {
ToastHelper.Companion.show(msg);
}
@Override
public void onLoginStop() {
dismissProgressDialog();
btnLogin.enableButton();
}
@Override
public void showErrorUserType() {
dismissProgressDialog();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("请注意");
builder.setMessage("专家账号,请下载壹点灵专家版app喔");
builder.setPositiveButton("确定", (dialog, which) -> dialog.dismiss());
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment