Skip to content

Commit

Permalink
v1.2.0 提取所有语言资源到strings.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
jixiaoyong committed Nov 2, 2019
1 parent bfe0db9 commit 5dc39df
Show file tree
Hide file tree
Showing 28 changed files with 194 additions and 538 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ android {
}

productFlavors.all {

flavor ->
flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name
, APP_KEY : UMENG_APP_KEY
Expand Down
17 changes: 3 additions & 14 deletions app/src/main/java/cf/android666/wanandroid/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,12 @@ class MainActivity : BaseActivity() {
}

val fragments = arrayListOf<BaseFragment>()

fragments.add(IndexFragment())
fragments.add(DiscoverFragment())
fragments.add(AboutFragment())

viewpager.adapter = MFragmentViewPagerAdapter(supportFragmentManager, fragments)

val bottomNavIds = arrayListOf(R.id.index, R.id.discover, R.id.about)

viewpager.addOnPageChangeListener(object : androidx.viewpager.widget.ViewPager.OnPageChangeListener {
override fun onPageScrollStateChanged(state: Int) {
}
Expand All @@ -51,20 +48,17 @@ class MainActivity : BaseActivity() {
}
})

bottom_nav.setOnNavigationItemSelectedListener { it ->
bottom_nav.setOnNavigationItemSelectedListener {
when (it.itemId) {
R.id.index -> {
// viewpager.currentItem = 0
viewpager.setCurrentItem(0, false)
return@setOnNavigationItemSelectedListener true
}
R.id.discover -> {
// viewpager.currentItem = 1
viewpager.setCurrentItem(1, false)
return@setOnNavigationItemSelectedListener true
}
R.id.about -> {
// viewpager.currentItem = 2
viewpager.setCurrentItem(2, false)
return@setOnNavigationItemSelectedListener true
}
Expand All @@ -77,15 +71,10 @@ class MainActivity : BaseActivity() {


override fun onCreateOptionsMenu(menu: Menu?): Boolean {

menuInflater.inflate(R.menu.menu_main, menu)

var searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager

var searchView: SearchView = menu!!.findItem(R.id.app_bar_search).actionView as SearchView

val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager
val searchView: SearchView = menu!!.findItem(R.id.app_bar_search).actionView as SearchView
searchView.setSearchableInfo(searchManager.getSearchableInfo(componentName))

return true
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package cf.android666.wanandroid.activity

import android.content.Intent
import android.graphics.Bitmap
import android.net.Uri
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.webkit.WebResourceError
import android.webkit.WebResourceRequest
import android.webkit.WebView
import android.webkit.WebViewClient
import cf.android666.mylibrary.view.SwitchStateLayout
import cf.android666.wanandroid.R
import cf.android666.wanandroid.utils.SuperUtil
import cf.android666.wanandroid.base.BaseActivity
import android.content.Intent
import android.graphics.Bitmap
import android.net.Uri
import android.webkit.*
import cf.android666.mylibrary.view.SwitchStateLayout
import cf.android666.wanandroid.utils.SuperUtil
import kotlinx.android.synthetic.main.activity_content.*


Expand All @@ -24,15 +27,11 @@ class ContentActivity : BaseActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContentView(R.layout.activity_content)

setSupportActionBar(toolbar)

supportActionBar!!.setDisplayHomeAsUpEnabled(true)

toolbar.setNavigationOnClickListener { finish() }

switch_state.showView(SwitchStateLayout.VIEW_EMPTY)

SuperUtil.loadUrl(web_view, intent.getStringExtra("url"))
Expand All @@ -56,7 +55,7 @@ class ContentActivity : BaseActivity() {
super.onPageFinished(view, url)
switch_state.showContentView()
webTitle = view!!.title
toolbar.title = view!!.title
toolbar.title = view.title
}

override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
Expand All @@ -76,29 +75,20 @@ class ContentActivity : BaseActivity() {
override fun onOptionsItemSelected(item: MenuItem?): Boolean {

when (item!!.itemId) {

R.id.refresh -> web_view.reload()

R.id.open_sys ->
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(intent.getStringExtra("url"))))

R.id.share -> {
var share_intent = Intent()

share_intent.action = Intent.ACTION_SEND

share_intent.type = "text/plain"

share_intent.putExtra(Intent.EXTRA_SUBJECT, "分享")

share_intent.putExtra(Intent.EXTRA_TEXT, "这篇文章不错,快来看看。${intent.getStringExtra("url")}" +
"\n分享自【WanAndroid】")

share_intent = Intent.createChooser(share_intent, "分享")

startActivity(share_intent)
var shareIntent = Intent()
shareIntent.action = Intent.ACTION_SEND
shareIntent.type = "text/plain"
shareIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share))
shareIntent.putExtra(Intent.EXTRA_TEXT,
"${getString(R.string.tips_share_look_at_this)}${intent.getStringExtra("url")}" +
"\n${getString(R.string.tips_share_from)}")
shareIntent = Intent.createChooser(shareIntent, getString(R.string.share))
startActivity(shareIntent)
}

}

return super.onOptionsItemSelected(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ package cf.android666.wanandroid.activity

import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.Window
import android.view.WindowManager
import android.widget.Toast
import cf.android666.mylibrary.view.SwitchStateLayout
import cf.android666.wanandroid.MainActivity
import cf.android666.wanandroid.R
import cf.android666.wanandroid.api.cookie.CookieTools
import cf.android666.wanandroid.base.BaseActivity
Expand All @@ -20,154 +17,116 @@ import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.activity_login.*
import org.greenrobot.eventbus.EventBus
import cf.android666.wanandroid.MainActivity


/**
* Created by jixiaoyong on 2018/3/12.
* email:[email protected]
*/
class LoginActivity: BaseActivity(){
class LoginActivity : BaseActivity() {

private var isSaveNamePwd = false

private lateinit var context:Context
private lateinit var context: Context

override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

setContentView(R.layout.activity_login)

context = this

var isLogin = SharePreference.getV<Boolean>(SharePreference.IS_LOGIN, false)

if (isLogin) {

login_box.visibility = View.GONE

go2MainActivity()

}


skip.setOnClickListener {
go2MainActivity()
}

register.setOnCheckedChangeListener{

_, isChecked ->

register.setOnCheckedChangeListener { _, isChecked ->
user_password_re.visibility = if (isChecked) View.VISIBLE else View.GONE

login_btn.text = if (isChecked)"注册" else "登录"
login_btn.text = if (isChecked) getString(R.string.register) else getString(R.string.login)
}

isSaveNamePwd = SharePreference.getV(SharePreference.IS_SAVE_NAME_PWD,false)
isSaveNamePwd = SharePreference.getV(SharePreference.IS_SAVE_NAME_PWD, false)

if (isSaveNamePwd) {

user_name.text = SharePreference.getV(SharePreference.USER_NAME,"")

user_password.text = SharePreference.getV(SharePreference.USER_PWD,"")

user_name.text = SharePreference.getV(SharePreference.USER_NAME, "")
user_password.text = SharePreference.getV(SharePreference.USER_PWD, "")
}

save_name_pwd.isChecked = isSaveNamePwd

save_name_pwd.setOnCheckedChangeListener{

_, isChecked ->

save_name_pwd.setOnCheckedChangeListener { _, isChecked ->
isSaveNamePwd = isChecked

SharePreference.saveKV(SharePreference.IS_SAVE_NAME_PWD,isSaveNamePwd)

SharePreference.saveKV(SharePreference.IS_SAVE_NAME_PWD, isSaveNamePwd)
}

login_btn.setOnClickListener {

val userName = user_name.text.toString()

val userPwd = user_password.text.toString()

if (userName.isEmpty() || userPwd.isEmpty()) {
Toast.makeText(baseContext,"账号或密码不能为空",Toast.LENGTH_SHORT).show()
if (userName.isEmpty() || userPwd.isEmpty()) {
Toast.makeText(baseContext, getString(R.string.tips_username_pwd_null), Toast.LENGTH_SHORT).show()
return@setOnClickListener
}

if (register.isChecked) {

val userPwdRe = user_password_re.text.toString()

register(userName, userPwd, userPwdRe)

} else {

login(userName, userPwd)

}
}

}

private fun login(userName: String,userPwd: String) {

private fun login(userName: String, userPwd: String) {
saveNamePwd(userName, userPwd)

CookieTools.getCookieService()!!
.login(userName,userPwd)
.login(userName, userPwd)
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
updateLoginState(it, userName,"登录成功")
},{
Toast("登录失败,请检查账号/密码或者网络")
updateLoginState(it, userName, getString(R.string.tips_login_succeeded))
}, {
Toast(getString(R.string.tips_username_pwd_error))
})

}

private fun register(username: String, password1: String, password2: String) {

saveNamePwd(username, password1)

CookieTools.getCookieService()!!
.register(username, password1, password2)
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe ({
updateLoginState(it, username,"注册成功")
},{
Toast("登录失败,请检查账号/密码或者网络")
.subscribe({
updateLoginState(it, username, getString(R.string.tips_reigster_succeeded))
}, {
Toast(getString(R.string.tips_username_pwd_error))
})

}

private fun updateLoginState(it: CookieBean, userName: String,msg:String) {
private fun updateLoginState(it: CookieBean, userName: String, msg: String) {

if (it.errorCode < 0) {

Toast.makeText(baseContext, it.errorMsg, Toast.LENGTH_SHORT).show()

} else {

SharePreference.saveKV(SharePreference.IS_LOGIN, true)

SharePreference.saveKV(SharePreference.USER_NAME, userName)

EventBus.getDefault().postSticky(EventFactory.LoginState(true, userName))

Toast.makeText(baseContext, msg, Toast.LENGTH_SHORT).show()

go2MainActivity()

}
}

private fun Toast(msg: String) {
Toast.makeText(context,msg,Toast.LENGTH_SHORT).show()
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show()
}


Expand All @@ -179,19 +138,14 @@ class LoginActivity: BaseActivity(){
}

private fun checkNameAndPassWord(userName: String, userPwd: String): Boolean {

if (userName.isEmpty() || userName.length < 6 || userName.length > 50) return false

if (userPwd.isEmpty() || userPwd.length < 6 || userName.length > 50) return false

// <!--密码6~50位且为数字、字母、-、_-->

// 最长不得超过7个汉字,或14个字节(数字,字母和下划线)正则表达式
// ^[\u4e00-\u9fa5]{1,7}$|^[\dA-Za-z_]{1,14}$
var r = """^[\dA-Za-z_]{6,50}$""".toRegex()

var r2 = """^[\dA-Za-z_]{6,50}$""".toRegex()

return r.matches(userPwd)

}
Expand All @@ -202,7 +156,5 @@ class LoginActivity: BaseActivity(){
finish()
}



}

Loading

0 comments on commit 5dc39df

Please sign in to comment.