Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,5 @@ androidExtensions {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':main')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
repositories {
mavenCentral()
}
}
3 changes: 3 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-libraryjars libs/litepal-1.5.1.jar
-dontwarn org.litepal.**
-keep class org.litepal.** {*; }
53 changes: 41 additions & 12 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,59 @@
package="com.example.quxiang">

<application
android:name="com.example.main.GifFunApplication"
android:networkSecurityConfig="@xml/network_security_config"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:resizeableActivity="false"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:name="com.example.main.GifFunApplication"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".opensource.MainActivity">

<uses-library android:name="org.apache.http.legacy" android:required="false"/>

<activity
android:name="com.example.quxiang.opensource.OpenSourceSplashActivity"
android:screenOrientation="portrait"
android:theme="@style/GifFun.SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

<meta-data
android:name="APP_CHANNEL"
android:value="opensource"/>
<meta-data
android:name="UMENG_APPKEY"
android:value="5c18feb8f1f5568cb70001f9"/>
<meta-data
android:name="UMENG_CHANNEL"
android:value="opensource"/>
<activity android:name=".opensource.OpenSourceLoginActivity"
android:screenOrientation="portrait"
android:theme="@style/GifFun.LoginActivity"
android:windowSoftInputMode="adjustResize|stateHidden">

<intent-filter>
<action android:name="com.example.quxiang.ACTION_LOGIN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="com.example.quxiang.ACTION_LOGIN_WITH_TRANSITION"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>

<activity
android:name=".opensource.OpenSourceRegisterActivity"
android:screenOrientation="portrait"
android:theme="@style/GifFun.RegisterActivity"/>


<meta-data
android:name="APP_CHANNEL"
android:value="opensource" />
<meta-data
android:name="UMENG_APPKEY"
android:value="5c18feb8f1f5568cb70001f9" />
<meta-data
android:name="UMENG_CHANNEL"
android:value="opensource" />
</application>

</manifest>
15 changes: 0 additions & 15 deletions app/src/main/java/com/example/quxiang/opensource/MainActivity.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
package com.example.quxiang.opensource

import android.content.Context
import android.os.Bundle
import android.os.CountDownTimer
import android.support.transition.Fade
import android.support.transition.TransitionManager
import android.transition.Transition
import android.view.View
import android.view.inputmethod.InputMethodManager
import com.example.core.extension.logWarn
import com.example.core.extension.showToast
import com.example.core.util.AndroidVersion
import com.example.core.util.GlobalUtil
import com.example.main.common.callback.SimpleTransitionListener
import com.example.main.event.FinishActivityEvent
import com.example.main.login.ui.LoginActivity
import com.example.main.util.ResponseHandler
import com.example.quxiang.R
import com.quxianggif.network.model.Callback
import com.quxianggif.network.model.FetchVCode
import com.quxianggif.network.model.PhoneLogin
import com.quxianggif.network.model.Response
import com.quxianggif.network.request.FetchVCodeRequest
import kotlinx.android.synthetic.main.activity_login.*
import org.greenrobot.eventbus.EventBus
import java.lang.Exception
import java.util.*
import java.util.regex.Pattern

/**
* Anthor: Zhuangmingzhu
* Date: 2019/4/22 下午5:55
* Describe:开源版界面登录,支持手机号登录,如果登陆的账号没有注册就会跳转到注册界面如果已经注册过了就直接会跳转到主界面
*/
class OpenSourceLoginActivity :LoginActivity(){

companion object {
const val TAG="OpenSourceLoginActivity"
}

private lateinit var timer:CountDownTimer

//是否正在登录中
private var isLogin=false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
}

override fun setupViews() {
super.setupViews()
val isStartWithTransition=intent.getBooleanExtra(LoginActivity.START_WITH_TRANSITION,false)
if(AndroidVersion.hasLollipop()&&isStartWithTransition){
isTransitioning=true
window.sharedElementEnterTransition.addListener(object : SimpleTransitionListener() {
override fun onTransitionEnd(transition: Transition?) {
val event=FinishActivityEvent()
event.activityClass=OpenSourceSplashActivity::class.java
EventBus.getDefault().post(event)
isTransitioning=false
fadeElementsIn()
}
})
}else{
loginLayoutBottom.visibility= View.VISIBLE
loginBgWallLayout.visibility=View.VISIBLE
}

timer=SMSTimer(60*1000,1000)
getVerifyCode.setOnClickListener {
getVerifyCodeAction()
}

loginButton.setOnClickListener {
getLoginAction()
}

}

//获取验证码
private fun getVerifyCodeAction(){
val number=phoneNumberEdit.text.toString()
if(number.isEmpty()){
showToast(GlobalUtil.getString(R.string.phone_number_is_empty))
return
}

if(!isLegalPhone(number)){
return
}

getVerifyCode.isClickable=false
processGetVerifyCode(number)
}

//登录操作
private fun getLoginAction(){
if(isLogin) return
val number=phoneNumberEdit.text.toString()
val code=verifyCodeEdit.text.toString()
if(number.isEmpty()||code.isEmpty()){
showToast(GlobalUtil.getString(R.string.phone_number_or_code_is_empty))
return
}

if(!isLegalPhone(number)){
return
}
processLogin(number,code)
}

//验证手机号是否合法
private fun isLegalPhone(number:String):Boolean{
val pattern="^1\\d{10}\$"
if(!Pattern.matches(pattern,number)){
showToast(GlobalUtil.getString(R.string.phone_number_is_invalid))
return false
}
return true
}

//将LoginActivity的界面元素使用淡入的方式显示出来
private fun fadeElementsIn(){
TransitionManager.beginDelayedTransition(loginLayoutBottom, Fade())
loginLayoutBottom.visibility = View.VISIBLE
TransitionManager.beginDelayedTransition(loginBgWallLayout,Fade())
loginBgWallLayout.visibility = View.VISIBLE
}

//开始获取验证码
private fun processGetVerifyCode(number: String){
FetchVCode.getResponse(number,object :Callback{
override fun onResponse(response: Response) {
if(response.status==0){
timer.start()
verifyCodeEdit.requestFocus()
}else{
showToast(response.msg)
getVerifyCode.isClickable=true
}
}

override fun onFailure(e: Exception) {
logWarn(TAG,e.message,e)
ResponseHandler.handleFailure(e)
getVerifyCode.isClickable=true
}

})
}

//开始登陆
private fun processLogin(number: String,code:String){
hideSoftKeyboard()
loginInProgress(true)
PhoneLogin.getResponse(number,code,object:Callback{
override fun onResponse(response: Response) {
if(!ResponseHandler.handleResponse(response)){
val thirdPartyLogin=response as PhoneLogin
val status=thirdPartyLogin.status
val msg=thirdPartyLogin.msg
val userId=thirdPartyLogin.userId
val token=thirdPartyLogin.token
when (status){
0->{
hideSoftKeyboard()
//处理登录成功时的逻辑,包括数据缓存,界面跳转等
saveAuthData(userId,token, TYPE_PHONE_LOGIN)
getUserBaseInfo()
}
10101->{
hideSoftKeyboard()
OpenSourceRegisterActivity.registerByPhone(this@OpenSourceLoginActivity,number,code)
loginInProgress(false)
}
else->{
logWarn(TAG, "Login failed. " + GlobalUtil.getResponseClue(status, msg))
showToast(response.msg)
loginInProgress(false)
}
}
}else{
loginInProgress(false)
}
}

override fun onFailure(e: Exception) {
logWarn(TAG, e.message, e)
ResponseHandler.handleFailure(e)
loginInProgress(false)
}

})
}

//根据用户是否正在注册来刷新页面。如果正在处理就显示进度条,否则的话就显示输入框
private fun loginInProgress(inProgress:Boolean){
if(AndroidVersion.hasMarshmallow()&&!(inProgress&&loginRootLayout.keyboardShowed)){
TransitionManager.beginDelayedTransition(loginRootLayout,Fade())
}
isLogin=inProgress
if (inProgress) {
loginInputElements.visibility = View.INVISIBLE
loginProgressBar.visibility = View.VISIBLE
} else {
loginProgressBar.visibility = View.INVISIBLE
loginInputElements.visibility = View.VISIBLE
}
}

inner class SMSTimer(millisInFuture:Long,countDownInterval:Long):CountDownTimer(millisInFuture,countDownInterval){

override fun onFinish() {
getVerifyCode.text="获取验证码"
getVerifyCode.isClickable=true
}

override fun onTick(millisUntilFinished: Long) {
getVerifyCode.text=String.format(GlobalUtil.getString(R.string.sms_is_sent),millisUntilFinished/1000)
}

}
}
Loading