kotlin转化完结
This commit is contained in:
@@ -20,62 +20,66 @@ import com.arpa.hndahesudintocctmsdriver.util.view.BaseAppCompatActivity
|
||||
import com.arpa.hndahesudintocctmsdriver.util.view.BottomTabUtil
|
||||
import com.arpa.hndahesudintocctmsdriver.util.view.PanDuanUtil
|
||||
import com.google.gson.Gson
|
||||
import com.luck.picture.lib.permissions.RxPermissions
|
||||
import io.reactivex.functions.Consumer
|
||||
import com.permissionx.guolindev.PermissionX
|
||||
|
||||
class MainActivity : BaseAppCompatActivity() {
|
||||
|
||||
private var ibs = arrayOf<ImageView>()
|
||||
private var title_view=arrayOf<TextView>()
|
||||
private var imgs0= intArrayOf(R.mipmap.tab1,R.mipmap.tab2,R.mipmap.xiaoxi0,R.mipmap.tab3)
|
||||
private var imgs1= intArrayOf(R.mipmap.tab1_s,R.mipmap.tab2_s,R.mipmap.xiaoxi1,R.mipmap.tab3_s)
|
||||
private var title_view = arrayOf<TextView>()
|
||||
private var imgs0 = intArrayOf(R.mipmap.tab1, R.mipmap.tab2, R.mipmap.xiaoxi0, R.mipmap.tab3)
|
||||
private var imgs1 =
|
||||
intArrayOf(R.mipmap.tab1_s, R.mipmap.tab2_s, R.mipmap.xiaoxi1, R.mipmap.tab3_s)
|
||||
private val gson = Gson()
|
||||
|
||||
override fun msgMethod(m: Message?) {
|
||||
super.msgMethod(m)
|
||||
when(m!!.what){
|
||||
1->{
|
||||
when (m!!.what) {
|
||||
1 -> {
|
||||
isExit = false;
|
||||
}
|
||||
RequsetCodeConstants.SUCCESS->{ }
|
||||
RequsetCodeConstants.SUCCESS -> {}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
StateStyleUtil.stateTextColor(this)
|
||||
setContentView(R.layout.activity_main)
|
||||
con=this
|
||||
act=this
|
||||
con = this
|
||||
act = this
|
||||
//隐藏标题栏
|
||||
val actionBar = supportActionBar
|
||||
actionBar?.hide()
|
||||
var r1=findViewById<LinearLayout>(R.id.r1)
|
||||
var r2=findViewById<LinearLayout>(R.id.r2)
|
||||
var r3=findViewById<LinearLayout>(R.id.r3)
|
||||
var r4=findViewById<LinearLayout>(R.id.r4)
|
||||
var r1 = findViewById<LinearLayout>(R.id.r1)
|
||||
var r2 = findViewById<LinearLayout>(R.id.r2)
|
||||
var r3 = findViewById<LinearLayout>(R.id.r3)
|
||||
var r4 = findViewById<LinearLayout>(R.id.r4)
|
||||
var fs = arrayOfNulls<Fragment>(4)
|
||||
fs[0] = HomeFragment()
|
||||
fs[1] = WalletFragment()
|
||||
fs[2] = NewsFragment()
|
||||
fs[3] = MyFragment()
|
||||
ibs=arrayOf(
|
||||
ibs = arrayOf(
|
||||
findViewById(R.id.huoyuan),
|
||||
findViewById(R.id.qianbao),
|
||||
findViewById(R.id.xiaoxi),
|
||||
findViewById(R.id.wode))
|
||||
title_view=arrayOf(findViewById(R.id.title1),findViewById(R.id.title2),findViewById(R.id.title3),findViewById(R.id.title4))
|
||||
title_view = arrayOf(findViewById(R.id.title1),
|
||||
findViewById(R.id.title2),
|
||||
findViewById(R.id.title3),
|
||||
findViewById(R.id.title4))
|
||||
var bt = BottomTabUtil(this, R.id.body, fs)
|
||||
bt.selectItem(fs[0])
|
||||
r1.setOnClickListener { v ->
|
||||
selectImage(bt.index,0)
|
||||
selectImage(bt.index, 0)
|
||||
bt.setDefaultFragment(fs[0])
|
||||
bt.index=0
|
||||
bt.index = 0
|
||||
}
|
||||
r2.setOnClickListener { v ->
|
||||
if (!PanDuanUtil.isLogin(con)){
|
||||
if (!PanDuanUtil.isLogin(con)) {
|
||||
jumpLogin()
|
||||
}else{
|
||||
selectImage(bt.index,1)
|
||||
} else {
|
||||
selectImage(bt.index, 1)
|
||||
if (!fs[1]!!.isAdded) {
|
||||
bt.hide(fs[bt.index])
|
||||
bt.selectItem(fs[1])
|
||||
@@ -86,10 +90,10 @@ class MainActivity : BaseAppCompatActivity() {
|
||||
}
|
||||
}
|
||||
r3.setOnClickListener { v ->
|
||||
if (!PanDuanUtil.isLogin(con)){
|
||||
if (!PanDuanUtil.isLogin(con)) {
|
||||
jumpLogin()
|
||||
}else{
|
||||
selectImage(bt.index,2)
|
||||
} else {
|
||||
selectImage(bt.index, 2)
|
||||
if (!fs[2]!!.isAdded) {
|
||||
bt.hide(fs[bt.index])
|
||||
bt.selectItem(fs[2])
|
||||
@@ -100,10 +104,10 @@ class MainActivity : BaseAppCompatActivity() {
|
||||
}
|
||||
}
|
||||
r4.setOnClickListener { v ->
|
||||
if (!PanDuanUtil.isLogin(con)){
|
||||
if (!PanDuanUtil.isLogin(con)) {
|
||||
jumpLogin()
|
||||
}else{
|
||||
selectImage(bt.index,3)
|
||||
} else {
|
||||
selectImage(bt.index, 3)
|
||||
if (!fs[3]!!.isAdded) {
|
||||
bt.hide(fs[bt.index])
|
||||
bt.selectItem(fs[3])
|
||||
@@ -113,41 +117,35 @@ class MainActivity : BaseAppCompatActivity() {
|
||||
bt.index = 3
|
||||
}
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q){
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
getPression()
|
||||
}
|
||||
}
|
||||
|
||||
fun getPression(){
|
||||
var gpsPermissions = RxPermissions(this)
|
||||
gpsPermissions.request(
|
||||
Manifest.permission.ACCESS_FINE_LOCATION,
|
||||
Manifest.permission.ACCESS_COARSE_LOCATION,
|
||||
Manifest.permission.ACCESS_BACKGROUND_LOCATION
|
||||
).subscribe(
|
||||
Consumer { b: Boolean ->
|
||||
if (b) {
|
||||
//判断GPS模块是否开启
|
||||
fun getPression() {
|
||||
PermissionX.init(this)
|
||||
.permissions(Manifest.permission.ACCESS_FINE_LOCATION,
|
||||
Manifest.permission.ACCESS_COARSE_LOCATION,
|
||||
Manifest.permission.ACCESS_BACKGROUND_LOCATION)
|
||||
.request { allGranted, grantedList, deniedList ->
|
||||
if (allGranted) {
|
||||
|
||||
} else {
|
||||
Toast.makeText(con,"开启权限失败,请在应用设置-权限-定位-始终允许",Toast.LENGTH_SHORT).show()
|
||||
//.show("开启权限失败,请在应用设置-权限-定位-始终允许")
|
||||
Toast.makeText(con, "开启权限失败,请在应用设置-权限-定位-始终允许", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun selectImage(old:Int, new:Int){
|
||||
fun selectImage(old: Int, new: Int) {
|
||||
ibs[old].setImageResource(imgs0[old])
|
||||
ibs[new].setImageResource(imgs1[new])
|
||||
title_view[old].setTextColor(resources.getColor(R.color.tab_select_no,null))
|
||||
title_view[new].setTextColor(resources.getColor(R.color.tab_select,null))
|
||||
title_view[old].setTextColor(resources.getColor(R.color.tab_select_no, null))
|
||||
title_view[new].setTextColor(resources.getColor(R.color.tab_select, null))
|
||||
}
|
||||
|
||||
fun jumpLogin(){
|
||||
var inl=Intent(con,LoginActivity::class.java)
|
||||
fun jumpLogin() {
|
||||
var inl = Intent(con, LoginActivity::class.java)
|
||||
startActivity(inl)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user