Commit e8cc0c4c authored by 宋永孟's avatar 宋永孟

add 更新首页

parent 2a81ff52
......@@ -10,6 +10,7 @@ class XRouterPathConstants {
const val LOGIN_NATIVE = "/loginNative"
const val USER_INFO = "/fragment/userInfo"
const val NEWS_MAIN = "/MainActivity"
const val HOME = "/Home"
const val NEWS_CONTENT = "/news"
const val GALLERY = "/imageGallery"
const val PROTOCOL = "/protocol"
......
package com.yidian.common.ui.widget
import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.viewpager.widget.ViewPager
/**
* @version : 1.0
* @date : 2019-11-19 19:20
* @depiction : 可设置是否滑动的ViewPager
*/
class ScrollViewPager : ViewPager {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
private var scrollable = false
fun setScrollable(isScrollable: Boolean) {
scrollable = isScrollable
}
override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
return if (scrollable) {
super.onInterceptTouchEvent(ev)
} else {
scrollable
}
}
override fun onTouchEvent(ev: MotionEvent?): Boolean {
return if (scrollable) {
super.onTouchEvent(ev)
} else {
scrollable
}
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package com.yidian.common.utils
import android.content.Context
import android.os.Build
import android.util.DisplayMetrics
import android.util.Log
import android.util.TypedValue
import com.google.gson.Gson
......@@ -53,6 +54,10 @@ object ToolsUtil {
).toInt()
}
fun dp2px(dpValue: Float): Int {
return TypedValue.applyDimension(1, dpValue, DisplayMetrics()).toInt()
}
//格式化展示
fun formatShowNum(count: Int): String{
var showCount = count.toString()
......
......@@ -3,7 +3,7 @@
package="com.yidian.shenghuoquan.newscontent">
<application>
<activity android:name=".ui.CommonDetailActivity"/>
<activity android:name=".ui.CommonDetailActivity" />
<activity
android:name=".ui.FlashActivity"
android:theme="@style/FlashTheme">
......@@ -16,11 +16,14 @@
</activity>
<activity
android:name=".ui.MainActivity"
android:launchMode="singleTask"/>
android:launchMode="singleTask" />
<activity
android:name=".ui.DeepLinkActivity">
android:name=".ui.HomeActivity"
android:launchMode="singleTask" />
<activity android:name=".ui.DeepLinkActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
......@@ -29,8 +32,9 @@
android:scheme="ydsubway" />
</intent-filter>
</activity>
<activity android:name=".ui.NewsContentActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize|uiMode"/>
<activity
android:name=".ui.NewsContentActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize|uiMode" />
<activity android:name=".ui.author.AuthorHomePageActivity" />
......
package com.yidian.shenghuoquan.newscontent.adapter
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
class ViewPagerAdapter(fragmentManager: FragmentManager,
private val fragments: List<Fragment>) : FragmentPagerAdapter(fragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
override fun getItem(index: Int): Fragment = fragments[index]
override fun getCount(): Int = fragments.size
}
\ No newline at end of file
......@@ -57,7 +57,7 @@ class FlashActivity: BaseActivity<ActivityFlashBinding>() {
val isAgree = Hawk.get<Boolean>(HawkConfig.ProtocolIsAgree, false)
if(isAgree){
viewBind.clRoot.postDelayed( {
XPageManager.push(XRouterPathConstants.NEWS_MAIN, paramsMap)
XPageManager.push(XRouterPathConstants.HOME, paramsMap)
finish()
},2000)
}else{
......
package com.yidian.shenghuoquan.newscontent.ui
import android.os.Bundle
import android.view.MenuItem
import androidx.core.view.forEach
import androidx.core.view.get
import androidx.fragment.app.Fragment
import androidx.viewpager.widget.ViewPager
import com.google.android.material.bottomnavigation.LabelVisibilityMode
import com.yidian.common.XRouterPathConstants
import com.yidian.common.base.BaseActivity
import com.yidian.shenghuoquan.newscontent.R
import com.yidian.shenghuoquan.newscontent.adapter.ViewPagerAdapter
import com.yidian.shenghuoquan.newscontent.databinding.ActivityHomeLayoutBinding
import com.yidian.shenghuoquan.newscontent.ui.search.SearchFragment
import com.yidian.shenghuoquan.newscontent.utils.badgeStyle
/**
* Author: sym
* Date: 2021/5/11 10:35 AM
* Describe:生活圈B端首页
*/
class HomeActivity : BaseActivity<ActivityHomeLayoutBinding>() {
private var fragmentList = mutableListOf<Fragment>()
var menus = arrayListOf("广场", "求职招聘", "燕郊圈", "中间出角标", "2出数字")
var menuIcons = arrayListOf<Int>(
R.drawable.ic_launcher_foreground,
R.mipmap.ic_launcher_round,
R.mipmap.ic_launcher_round,
R.mipmap.ic_launcher_round,
R.mipmap.ic_launcher_round
)
override fun createViewBinding(): ActivityHomeLayoutBinding {
return ActivityHomeLayoutBinding.inflate(layoutInflater)
}
override fun getXPageName(): String {
return XRouterPathConstants.NEWS_MAIN
}
override fun init(savedInstanceState: Bundle?) {
super.init(savedInstanceState)
initFragment()
initView()
initListener()
}
private fun initFragment() {
fragmentList.add(SearchFragment())
fragmentList.add(SearchFragment())
fragmentList.add(SearchFragment())
fragmentList.add(SearchFragment())
fragmentList.add(SearchFragment())
}
private fun initView() {
viewBind.viewPager.offscreenPageLimit = fragmentList.size
viewBind.viewPager.adapter = ViewPagerAdapter(
supportFragmentManager, fragmentList
)
viewBind.viewPager.setScrollable(true)
viewBind.viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
}
override fun onPageSelected(position: Int) {
viewBind.navView.menu.forEach {
viewBind.navView.menu[position].isChecked = true
if (position == it.itemId) {
it.setIcon(R.drawable.ic_launcher_foreground)
if (it.itemId == 1) {
viewBind.navView.getOrCreateBadge(1).clearNumber()
viewBind.navView.getOrCreateBadge(1).isVisible = false
}
if (it.itemId == 2) {
viewBind.navView.getOrCreateBadge(2).isVisible = false
}
if (it.itemId == 3) {
viewBind.navView.getOrCreateBadge(2).isVisible = true
}
if (it.itemId == 4) {
viewBind.navView.getOrCreateBadge(1).number = 998
viewBind.navView.getOrCreateBadge(1).isVisible = true
}
} else {
it.setIcon(R.mipmap.ic_launcher_round)
}
}
}
override fun onPageScrollStateChanged(state: Int) {
}
})
viewBind.navView.itemIconTintList = null
viewBind.navView.labelVisibilityMode = LabelVisibilityMode.LABEL_VISIBILITY_LABELED;//1 不开动画 0 动画
menus.forEachIndexed { index, title ->
viewBind.navView.menu.add(0, index, 0, title)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM)
viewBind.navView.menu.getItem(index).setIcon(menuIcons[index])
}
//设置默认选中
viewBind.navView.menu[0].isChecked = true
addBadgeView()
}
private fun initListener() {
viewBind.navView.setOnNavigationItemSelectedListener { menuItem ->
viewBind.navView.menu.forEach {
if (it.itemId == menuItem.itemId) {
viewBind.viewPager.setCurrentItem(menuItem.itemId, false)
it.setIcon(R.drawable.ic_launcher_foreground)
if (it.itemId == 1) {
viewBind.navView.getOrCreateBadge(1).clearNumber()
viewBind.navView.getOrCreateBadge(1).isVisible = false
}
if (it.itemId == 2) {
viewBind.navView.getOrCreateBadge(2).isVisible = false
}
if (it.itemId == 3) {
viewBind.navView.getOrCreateBadge(2).isVisible = true
}
if (it.itemId == 4) {
viewBind.navView.getOrCreateBadge(1).number = 998
viewBind.navView.getOrCreateBadge(1).isVisible = true
}
} else {
it.setIcon(R.mipmap.ic_launcher_round)
}
}
true
}
}
private fun addBadgeView() {
viewBind.navView.badgeStyle(1, null, android.R.color.holo_red_dark)
viewBind.navView.getOrCreateBadge(1).maxCharacterCount = 3
viewBind.navView.getOrCreateBadge(1).number = 99
viewBind.navView.getOrCreateBadge(2).isVisible = true
}
}
\ No newline at end of file
package com.yidian.shenghuoquan.newscontent.utils
import com.google.android.material.badge.BadgeDrawable
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.yidian.common.utils.ToolsUtil
/**
* @description: 小红点操作工具类 结合BottomNavigationView使用
* @author: huyajun
* @date: 2021/4/28
**/
class BadgeUtils {
// companion object {
/**
* 设置badge样式
*/
}
fun BottomNavigationView.badgeStyle(index: Int, textColor: Int?, backgroundColor: Int?) {
getOrCreateBadge(index).horizontalOffset = ToolsUtil.dp2px(-10f)
getOrCreateBadge(index).verticalOffset = ToolsUtil.dp2px(5f)
textColor?.let {
getOrCreateBadge(index).badgeTextColor = resources.getColor(it)
}
backgroundColor?.let {
getOrCreateBadge(index).backgroundColor =
resources.getColor(it)
}
}
/**
* 设置数字
*/
fun setBadgeNumber(
view: BottomNavigationView,
index: Int, number: Int
) {
if (number == 0) {
removeBadge(view, index)
} else {
view.getOrCreateBadge(index).number = number
}
}
/**
* 移除badge
*/
fun removeBadge(view: BottomNavigationView, index: Int) {
view.removeBadge(index)
}
fun BottomNavigationView.item(index: Int): BadgeDrawable {
return getOrCreateBadge(index)
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.yidian.common.ui.widget.ScrollViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
\ No newline at end of file
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/transparent</item>
<item name="colorPrimaryDark">@color/transparent</item>
......
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