Commit 480dc309 by 范玉宾

rewrite article home

parent c41d5167
......@@ -20,8 +20,8 @@ import java.util.List;
*/
public final class DemoGlobalConfig implements IConfigModule {
String APP_DOMAIN = "https://api.github.com/";
public static String appEnv = YDLConstants.ENV_TEST;
// public static String appEnv = YDLConstants.ENV_PROD;
// public static String appEnv = YDLConstants.ENV_TEST;
public static String appEnv = YDLConstants.ENV_PROD;
// public static String appEnv = YDLConstants.ENV_NEW_TEST;//配置未上传到maven库
@Override
......
......@@ -80,6 +80,9 @@ dependencies {
kapt 'com.alibaba:arouter-compiler:1.2.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
implementation "androidx.lifecycle:lifecycle-runtime:2.0.0"
api rootProject.ext.dependencies["ydl-user-router"]
if (rootProject.ext.dev_mode){
//开发时使用
......
......@@ -5,6 +5,8 @@
<application>
<activity android:name=".flutter.ArticleActivity"
android:screenOrientation="portrait"/>
<activity android:name="activity.ArticleHomeActivity"
android:screenOrientation="portrait"/>
</application>
</manifest>
\ No newline at end of file
package activity
import adapter.ArticleHomeAdapter
import android.graphics.Typeface
import android.text.SpannableString
import android.text.Spanned
import android.text.style.StyleSpan
import androidx.viewpager2.widget.ViewPager2
import com.alibaba.android.arouter.facade.annotation.Route
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.ydl.ydlcommon.base.BaseActivity
import com.ydl.ydlcommon.utils.actionutil.ActionCountUtils
import com.yidianling.article.R
import http.ArticleHttp
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
@Route(path = "/article/list")
class ArticleHomeActivity:BaseActivity() {
private var TAG_IDS = mutableListOf(0,1,2,3,4,5)
private var TAGS = mutableListOf("推荐","情绪","亲子","职能部门","健康","科普")
private var mTabLayout:TabLayout?=null
private var mViewPager: ViewPager2?=null
override fun initDataAndEvent() {
mTabLayout = findViewById(R.id.tab_layout)
mViewPager = findViewById(R.id.view_pager)
mViewPager?.isUserInputEnabled = false
mViewPager?.adapter = ArticleHomeAdapter()
mTabLayout?.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab?) {
//冥想|声音|睡眠点击事件
// ActionCountUtils.count(HomeBIConstants.YDL_HOME_MEDITATION_SUBJECT_CLICK,
// tab?.let { bean?.mditationListResponse?.get(it.position)?.buried } ?:"")
var text: String? = tab?.text.toString().trim()
val spStr = SpannableString(text)
val styleSpan = StyleSpan(Typeface.BOLD)
spStr.setSpan(styleSpan, 0, text?.length ?: 0, Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
tab?.text = spStr
}
override fun onTabUnselected(tab: TabLayout.Tab?) {
var text: String? = tab?.text.toString().trim()
val spStr = SpannableString(text)
val styleSpan = StyleSpan(Typeface.NORMAL)
spStr.setSpan(styleSpan, 0, text?.length ?: 0, Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
tab?.text = spStr
}
override fun onTabReselected(tab: TabLayout.Tab?) {
}
})
TabLayoutMediator(mTabLayout!!, mViewPager!!) { tab, position ->
tab.text = TAGS[position]
}.attach()
}
override fun onResume() {
super.onResume()
getArticleList()
}
private fun getArticleList(){
ArticleHttp.getInstance().getArticleList(perPageRows = 20,
page = 1,tagId = 485)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
}
}
override fun layoutResId(): Int {
return R.layout.article_home_activity_layout
}
}
\ No newline at end of file
package adapter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.yidianling.article.R
class ArticleHomeAdapter:RecyclerView.Adapter<ArticleHomeAdapter.ArticleViewHolder>() {
val list = listOf("One","Two","Three","Four","Five","Six")
override fun onCreateViewHolder(parent: ViewGroup, position: Int): ArticleViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.article_fragment_layout,parent,false)
return ArticleViewHolder(view)
}
override fun onBindViewHolder(holder: ArticleViewHolder, position: Int) {
}
override fun getItemCount(): Int {
return list.size
}
inner class ArticleViewHolder(val view: View):RecyclerView.ViewHolder(view)
}
\ No newline at end of file
......@@ -9,7 +9,7 @@ import org.json.JSONObject
* Created by harvie on 2019/9/6.
*/
@Route(path = "/article/list")
//@Route(path = "/article/list")
class ArticleActivity : BaseFlutterActivity() {
override fun initialRoute(): String {
......
package data
data class ArticleListBean(
val list:MutableList<ArticleBean>?=null
)
//"id": 12516,
//"readNum": 215,
//"title": "当你过于敏感焦虑,来试一下系统脱敏训练吧!",
//"desc": "解析阿辰过于敏感失眠的案例,分析过于敏感和外归因的影响,介绍系统脱敏训练方法,鼓励大家用系统脱敏训练来学会放松,缓解敏感焦虑。",
//"imgUrl": "https://img.ydlcdn.com/file/2022/07/05/z5g81dlgbbu6wjq1.jpg!/fw/270",
//"name": "徐姗姗",
//"doctorId": 33094,
//"smallImage": "http://ydl-userprivacy.ydl.com/2022_05_28_63195910000PWTRVQPVQQUQU.772.jpg",
//"pseudonym": "",
//"countOfFavorite": 2,
//"hUrl": "https://h2.yidianling.com/article/12516",
//"mUrl": "https://m.ydl.com/article/12516",
//"createTime": "Jul 5, 2022 9:58:24 AM",
//"createTimeFormat": "2022-07-05",
//"zanNum": 2,
//"url": "https://h2.yidianling.com/article/12516"
data class ArticleBean(
val id:Int,
val readNum:Int,
val title:String,
val desc:String,
val imgUrl:String,
val name:String,
val doctorId:Int,
val smallImage:String,
val pseudonym:String,
val countOfFavorite:Int,
val hUrl:String,
val mUrl:String,
val createTime:String,
val createTimeFormat:String,
val zanNum:Int,
val url:String
)
package http
import com.ydl.ydlcommon.base.config.YDL_DOMAIN
import com.ydl.ydlcommon.base.config.YDL_DOMAIN_JAVA
import com.ydl.ydlcommon.data.http.BaseAPIResponse
import data.ArticleListBean
import io.reactivex.Observable
import retrofit2.http.GET
import retrofit2.http.Headers
import retrofit2.http.Query
interface ArticleApi {
//文章列表
@GET("article/list/all")
@Headers(YDL_DOMAIN + YDL_DOMAIN_JAVA)
fun getArticleList(
@Query("perPageRows") perPageRows: Int = 20,
@Query("page") page: Int = 1,
@Query("tagId") tagId: Int = 0
): Observable<BaseAPIResponse<ArticleListBean>>
}
\ No newline at end of file
package http
import com.ydl.ydlcommon.data.http.BaseAPIResponse
import com.ydl.ydlnet.YDLHttpUtils
import data.ArticleListBean
import io.reactivex.Observable
class ArticleHttp {
companion object{
fun getInstance() = Holder.INSTANCE
}
object Holder{
val INSTANCE = ArticleHttp()
}
private var articleApi:ArticleApi?=null
private fun getArticleApi():ArticleApi{
if (articleApi == null){
articleApi = YDLHttpUtils.obtainApi(ArticleApi::class.java)
}
return articleApi!!
}
fun getArticleList(perPageRows:Int,page:Int,tagId:Int):Observable<BaseAPIResponse<ArticleListBean>>{
return getArticleApi().getArticleList(perPageRows = perPageRows,page = page,tagId = tagId)
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/white"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:orientation="horizontal"
android:gravity="center_vertical">
<ImageView
android:id="@+id/iv_back"
android:layout_width="42dp"
android:layout_height="42dp"
android:layout_marginStart="9dp"
android:padding="9dp"
android:src="@drawable/platform_common_back"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="文章·阅读"
android:textSize="18sp"
android:textColor="#000000"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#F8F8F8"/>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="40dp"
app:tabBackground="@color/transparent"
app:tabRippleColor="@color/transparent"
app:tabMode="scrollable"
app:tabIndicatorFullWidth="false"
style="@style/ArticleTabLayoutStyle" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="color_1DA1F2">#1DA1F2</color>
<color name="color_999999">#999999</color>
<color name="color_000000">#000000</color>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="ArticleTabLayoutStyle" parent="Widget.Design.TabLayout">
<item name="tabIndicatorColor">@color/color_1DA1F2</item>
<item name="tabIndicatorHeight">4dp</item>
<item name="tabIndicatorFullWidth">false</item>
<item name="tabSelectedTextColor">@color/color_000000</item>
<item name="android:textSize">16sp</item>
<item name="android:textColor">@color/color_999999</item>
</style>
</resources>
\ No newline at end of file
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