next!!.setOnClickListener {
closeKeyboard(this@LoginActivity, accountActivityClick)
checkMailInputData(accountMailEdittext, accountMailErrorMsg)
checkPasswordInputData(accountMailPasswordEdittext, accountMailPasswordErrorMsg)
if (!viewISVisible(accountMailErrorMsg) && !viewISVisible(accountMailPasswordErrorMsg)) {
val login = LoginRequestBean()
login.userKey = accountMailEdittext!!.text.toString()
login.userType = "1"
login.password = accountMailPasswordEdittext!!.text.toString()
loginApi(this@LoginActivity, login)
}
}
/**
* ログイン
*/
fun loginApi(activity: Activity, loginRequest: LoginRequestBean) {
val uuid = SharedPreferencesUtils.getUUid(activity)
if (!Common.prepareToCallAPI(activity, true)) {
return
}
val param = RequestJson.loginRequest(activity, uuid, realm, loginRequest)
object : Thread() {
override fun run() {
try {
val url = Common.commonApiUrl + "api/account/accountLogin"
val content = curlUrl.postDownloadUrl(url, uuid, param, activity)
activity.runOnUiThread {
Common.cancelLoadingDialog()
if (!content.isNullOrEmpty()) {
val resultResponse: ResultResponse? = JsonUtil.jsonToBean(content!!, ResultResponse::class.java)
if (resultResponse != null && resultResponse.resultStatus.equals("OK")) {
DBRealm.addUserInfoData(realm, resultResponse.resultData!!)
setUUid(activity, resultResponse.resultData!!.uuid!!)
Api.getNoticeUrl(activity)
Api.getPushNum(activity)
EventBus.getDefault().post(LoginEvent())
activity.finish()
} else {
if (AllMsgData.getName(resultResponse!!.errorCode) != 0) {
Common.alertMsg(activity, activity.resources.getString(AllMsgData.getName(resultResponse.errorCode)))
}
}
}
}
} catch (e: Exception) {
activity.runOnUiThread {
Common.cancelLoadingDialog()
}
}
}
}.start()
}
/**
* ログイン
*/
fun loginRequest(context: Context, uuid: String, realm: Realm, loginRequest: LoginRequestBean): String {
val request = LoginRequestBean()
request.requestHeader = getRequestHeader(context, uuid, realm)
request.userKey = loginRequest.userKey
request.userType = loginRequest.userType
request.password = loginRequest.password
//FacebookID
request.facebookId = loginRequest.facebookId
//Facebookユーザ名
request.facebookName = loginRequest.facebookName
//Facebookメールアドレス
request.facebookEmail = loginRequest.facebookEmail
//Facebook性別
request.facebookSex = loginRequest.facebookSex
//Facebook生年月日
request.facebookBirthday = loginRequest.facebookBirthday
//Facebook電話番号
request.facebookPhoneNumber = loginRequest.facebookPhoneNumber
//Facebook住所
request.facebookAddress = loginRequest.facebookAddress
//YahooID
request.yahooId = loginRequest.yahooId
request.yahooEmail = loginRequest.yahooEmail
//GoogleID
request.googleId = loginRequest.googleId
request.googleEmail = loginRequest.googleEmail
return JsonUtil.beanTojson(request)
}
package jp.co.hyakujushibank.util
import com.google.gson.Gson
object JsonUtil {
/**
* Json Object To String
*
* @param Any
* @return jsonStr String
*/
fun beanTojson(bean: Any?): String {
val gson = Gson()
val jsonStr = gson.toJson(bean)
return jsonStr;
}
/**
* Json String to Object
*
* @param str
* @param type
* @return Object
*/
fun <T> jsonToBean(str: String?, type: Class<T>): T? {
try {
if (!str.isNullOrEmpty() && str != "null") {
val gson = Gson()
return gson.fromJson(str, type)
} else {
return null
}
} catch(e: Exception) {
return null
}
}
}
package jp.co.hyakujushibank.entity
class ResultResponse {
var resultStatus: String? = null
var errorCode: String? = null
var messages: String? = null
var resultCode: String? = null
var resultData: ResultData? = null
}