完善 市场界面按钮显示
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package org.autojs.autojs.network
|
package org.autojs.autojs.network
|
||||||
|
|
||||||
import org.autojs.autojs.network.api.TopicApi
|
import org.autojs.autojs.network.api.TopicApi
|
||||||
|
import org.autojs.autojs.network.entity.topic.Post
|
||||||
import org.autojs.autojs.network.entity.topic.Topic
|
import org.autojs.autojs.network.entity.topic.Topic
|
||||||
|
|
||||||
object TopicService {
|
object TopicService {
|
||||||
@@ -16,6 +17,12 @@ object TopicService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun getMainPost(topic: Topic): Post {
|
||||||
|
val fullTopic = mTopicApi.getTopic(topic.tid.toLong()).await()
|
||||||
|
topic.mainPost = fullTopic.posts.first { post -> post.pid == topic.mainPid }
|
||||||
|
return topic.mainPost
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun getScriptsTopics(): List<Topic> {
|
suspend fun getScriptsTopics(): List<Topic> {
|
||||||
return getTopics(CID_SCRIPTS)
|
return getTopics(CID_SCRIPTS)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.autojs.autojs.network.api
|
|||||||
|
|
||||||
import kotlinx.coroutines.Deferred
|
import kotlinx.coroutines.Deferred
|
||||||
import org.autojs.autojs.network.entity.topic.Category
|
import org.autojs.autojs.network.entity.topic.Category
|
||||||
|
import org.autojs.autojs.network.entity.topic.Post
|
||||||
import org.autojs.autojs.network.entity.topic.Topic
|
import org.autojs.autojs.network.entity.topic.Topic
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
import retrofit2.http.Path
|
import retrofit2.http.Path
|
||||||
@@ -12,6 +13,7 @@ interface TopicApi {
|
|||||||
fun getCategory(@Path("cid") cid: Long): Deferred<Category>
|
fun getCategory(@Path("cid") cid: Long): Deferred<Category>
|
||||||
|
|
||||||
@GET("/api/topic/{tid}")
|
@GET("/api/topic/{tid}")
|
||||||
fun getTopic(@Path("tid") cid: Long): Deferred<Topic>
|
fun getTopic(@Path("tid") pid: Long): Deferred<Topic>
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,8 @@ import com.google.gson.annotations.SerializedName;
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class AppInfo {
|
public class AppInfo {
|
||||||
|
|
||||||
|
public static final String PERMISSION_ROOT = "root";
|
||||||
|
|
||||||
@SerializedName("details")
|
@SerializedName("details")
|
||||||
private String mDetails;
|
private String mDetails;
|
||||||
@SerializedName("email")
|
@SerializedName("email")
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ public class Topic {
|
|||||||
private Post mTeaser;
|
private Post mTeaser;
|
||||||
|
|
||||||
private AppInfo mAppInfo;
|
private AppInfo mAppInfo;
|
||||||
|
private Post mMainPost;
|
||||||
|
|
||||||
public Category getCategory() {
|
public Category getCategory() {
|
||||||
return mCategory;
|
return mCategory;
|
||||||
@@ -339,6 +340,22 @@ public class Topic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Post getTeaser() {
|
||||||
|
return mTeaser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTeaser(Post teaser) {
|
||||||
|
mTeaser = teaser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Post getMainPost() {
|
||||||
|
return mMainPost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMainPost(Post mainPost) {
|
||||||
|
mMainPost = mainPost;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Topic{" +
|
return "Topic{" +
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package org.autojs.autojs.ui.main.market
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.Gravity
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import kotlinx.android.synthetic.main.image_text.view.*
|
||||||
|
import org.autojs.autojs.R
|
||||||
|
|
||||||
|
class ImageText : LinearLayout {
|
||||||
|
|
||||||
|
var text: CharSequence?
|
||||||
|
get() = textView.text
|
||||||
|
set(value) {
|
||||||
|
textView.text = value
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(context: Context?) : super(context) {
|
||||||
|
init(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
|
||||||
|
init(attrs)
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
|
||||||
|
init(attrs)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun init(attrs: AttributeSet?) {
|
||||||
|
View.inflate(context, R.layout.image_text, this)
|
||||||
|
gravity = Gravity.CENTER
|
||||||
|
orientation = HORIZONTAL
|
||||||
|
if (attrs == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val a = context.obtainStyledAttributes(attrs, R.styleable.ImageText)
|
||||||
|
a.getString(R.styleable.ImageText_text)?.let {
|
||||||
|
textView.text = it
|
||||||
|
}
|
||||||
|
val iconResId = a.getResourceId(R.styleable.ImageText_src, 0)
|
||||||
|
if (iconResId != 0) {
|
||||||
|
imageView.setImageResource(iconResId)
|
||||||
|
}
|
||||||
|
val imageWidth = a.getDimensionPixelSize(R.styleable.ImageText_image_width, 0)
|
||||||
|
if (imageWidth != 0) {
|
||||||
|
imageView.layoutParams.width = imageWidth
|
||||||
|
}
|
||||||
|
a.recycle()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setColor(color: Int) {
|
||||||
|
textView.setTextColor(color)
|
||||||
|
imageView.setColorFilter(color)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import android.view.LayoutInflater
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
import com.stardust.autojs.workground.WrapContentLinearLayoutManager
|
import com.stardust.autojs.workground.WrapContentLinearLayoutManager
|
||||||
@@ -15,6 +16,8 @@ import kotlinx.coroutines.GlobalScope
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.autojs.autojs.R
|
import org.autojs.autojs.R
|
||||||
import org.autojs.autojs.network.TopicService
|
import org.autojs.autojs.network.TopicService
|
||||||
|
import org.autojs.autojs.network.entity.topic.AppInfo
|
||||||
|
import org.autojs.autojs.network.entity.topic.Post
|
||||||
import org.autojs.autojs.network.entity.topic.Topic
|
import org.autojs.autojs.network.entity.topic.Topic
|
||||||
import org.autojs.autojs.ui.main.ViewPagerFragment
|
import org.autojs.autojs.ui.main.ViewPagerFragment
|
||||||
import org.autojs.autojs.ui.widget.AvatarView
|
import org.autojs.autojs.ui.widget.AvatarView
|
||||||
@@ -59,11 +62,89 @@ class MarketFragment : ViewPagerFragment(0) {
|
|||||||
|
|
||||||
inner class TopicViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
inner class TopicViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||||
|
|
||||||
val rootView: TextView = itemView.findViewById(R.id.root)
|
private lateinit var topic: Topic
|
||||||
val titleView: TextView = itemView.findViewById(R.id.title)
|
|
||||||
val avatarView: AvatarView = itemView.findViewById(R.id.avatar)
|
private val rootView: TextView = itemView.findViewById(R.id.root)
|
||||||
val usernameView: TextView = itemView.findViewById(R.id.username)
|
private val titleView: TextView = itemView.findViewById(R.id.title)
|
||||||
val dateView: TextView = itemView.findViewById(R.id.date)
|
private val avatarView: AvatarView = itemView.findViewById(R.id.avatar)
|
||||||
|
private val usernameView: TextView = itemView.findViewById(R.id.username)
|
||||||
|
private val dateView: TextView = itemView.findViewById(R.id.date)
|
||||||
|
private val upvoteView: ImageText = itemView.findViewById(R.id.upvote)
|
||||||
|
private val downvoteView: ImageText = itemView.findViewById(R.id.downvote)
|
||||||
|
private val downloadView: ImageText = itemView.findViewById(R.id.download)
|
||||||
|
private val starView: ImageText = itemView.findViewById(R.id.star)
|
||||||
|
|
||||||
|
init {
|
||||||
|
upvoteView.setOnClickListener {
|
||||||
|
|
||||||
|
}
|
||||||
|
downvoteView.setOnClickListener {
|
||||||
|
|
||||||
|
}
|
||||||
|
starView.setOnClickListener {
|
||||||
|
|
||||||
|
}
|
||||||
|
downloadView.setOnClickListener {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bind(topic: Topic) {
|
||||||
|
this.topic = topic
|
||||||
|
rootView.setText(if (topic.appInfo.permissions.contains(AppInfo.PERMISSION_ROOT)) {
|
||||||
|
R.string.text_root
|
||||||
|
} else {
|
||||||
|
R.string.text_no_root
|
||||||
|
})
|
||||||
|
titleView.text = topic.title
|
||||||
|
avatarView.setUser(topic.user)
|
||||||
|
usernameView.text = topic.user.username
|
||||||
|
dateView.text = DateTimeFormat.mediumDateTime().print(topic.timestamp.toLong())
|
||||||
|
if (topic.mainPost != null) {
|
||||||
|
bindMainPost(topic.mainPost)
|
||||||
|
} else {
|
||||||
|
fetchMainPost(topic)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun fetchMainPost(topic: Topic) {
|
||||||
|
GlobalScope.launch(Dispatchers.Main) {
|
||||||
|
try {
|
||||||
|
val mainPost = TopicService.getMainPost(topic)
|
||||||
|
if (topic === this@TopicViewHolder.topic) {
|
||||||
|
bindMainPost(mainPost)
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun bindMainPost(mainPost: Post) {
|
||||||
|
context?.let { context ->
|
||||||
|
upvoteView.text = if (mainPost.upvotes == 0L) {
|
||||||
|
context.getString(R.string.text_upvote)
|
||||||
|
} else {
|
||||||
|
mainPost.upvotes.toString()
|
||||||
|
}
|
||||||
|
upvoteView.setColor(if (mainPost.upvoted) {
|
||||||
|
ContextCompat.getColor(context, R.color.market_button_selected)
|
||||||
|
} else {
|
||||||
|
ContextCompat.getColor(context, R.color.market_button_unselected)
|
||||||
|
})
|
||||||
|
downvoteView.text = if (mainPost.downvotes == 0L) {
|
||||||
|
context.getString(R.string.text_downvote)
|
||||||
|
} else {
|
||||||
|
mainPost.downvotes.toString()
|
||||||
|
}
|
||||||
|
downvoteView.setColor(if (mainPost.downvoted) {
|
||||||
|
ContextCompat.getColor(context, R.color.market_button_selected)
|
||||||
|
} else {
|
||||||
|
ContextCompat.getColor(context, R.color.market_button_unselected)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,21 +158,8 @@ class MarketFragment : ViewPagerFragment(0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: TopicViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: TopicViewHolder, position: Int) {
|
||||||
|
|
||||||
val topic = mTopics[position]
|
val topic = mTopics[position]
|
||||||
holder.run {
|
holder.bind(topic)
|
||||||
val root = topic.appInfo.permissions.contains("root")
|
|
||||||
rootView.text = if (root) {
|
|
||||||
"Root"
|
|
||||||
} else {
|
|
||||||
"免Root"
|
|
||||||
}
|
|
||||||
titleView.text = topic.title
|
|
||||||
avatarView.setUser(topic.user)
|
|
||||||
usernameView.text = topic.user.username
|
|
||||||
|
|
||||||
dateView.text = DateTimeFormat.mediumDateTime().print(topic.timestamp.toLong())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
17
app/src/main/res/layout/image_text.xml
Normal file
17
app/src/main/res/layout/image_text.xml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/imageView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:tint="#939393"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
|
</merge>
|
||||||
@@ -93,37 +93,44 @@
|
|||||||
android:paddingTop="3dp"
|
android:paddingTop="3dp"
|
||||||
android:paddingBottom="3dp">
|
android:paddingBottom="3dp">
|
||||||
|
|
||||||
<ImageView
|
<org.autojs.autojs.ui.main.market.ImageText
|
||||||
android:id="@+id/download"
|
android:id="@+id/download"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:src="@drawable/download"
|
android:background="?selectableItemBackgroundBorderless"
|
||||||
android:tint="#939393"/>
|
android:tint="#939393"
|
||||||
|
app:image_width="30dp"
|
||||||
|
app:src="@drawable/download"
|
||||||
|
app:text="@string/text_download"/>
|
||||||
|
|
||||||
<ImageView
|
<org.autojs.autojs.ui.main.market.ImageText
|
||||||
android:id="@+id/upvote"
|
android:id="@+id/upvote"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:src="@drawable/upvote"
|
android:background="?selectableItemBackgroundBorderless"
|
||||||
android:tint="#939393"/>
|
app:image_width="30dp"
|
||||||
|
app:src="@drawable/upvote"/>
|
||||||
|
|
||||||
<ImageView
|
<org.autojs.autojs.ui.main.market.ImageText
|
||||||
android:id="@+id/downvote"
|
android:id="@+id/downvote"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:src="@drawable/downvote"
|
android:background="?selectableItemBackgroundBorderless"
|
||||||
android:tint="#939393"/>
|
app:image_width="30dp"
|
||||||
|
app:src="@drawable/downvote"/>
|
||||||
|
|
||||||
<ImageView
|
<org.autojs.autojs.ui.main.market.ImageText
|
||||||
android:id="@+id/star"
|
android:id="@+id/star"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:src="@drawable/star"
|
android:background="?selectableItemBackgroundBorderless"
|
||||||
android:tint="#939393"/>
|
app:image_width="30dp"
|
||||||
|
app:src="@drawable/star"
|
||||||
|
app:text="@string/text_star"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|||||||
@@ -35,4 +35,10 @@
|
|||||||
<attr name="cam_angle" format="integer"/>
|
<attr name="cam_angle" format="integer"/>
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
|
<declare-styleable name="ImageText">
|
||||||
|
<attr name="text"/>
|
||||||
|
<attr name="src"/>
|
||||||
|
<attr name="image_width" format="dimension|reference"/>
|
||||||
|
</declare-styleable>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
@@ -26,7 +26,8 @@
|
|||||||
<color name="toolbar_disabled">#77e0e0e0</color>
|
<color name="toolbar_disabled">#77e0e0e0</color>
|
||||||
<color name="console_debug">#cc000000</color>
|
<color name="console_debug">#cc000000</color>
|
||||||
<color name="console_verbose">#dfc0c0c0</color>
|
<color name="console_verbose">#dfc0c0c0</color>
|
||||||
|
<color name="market_button_selected">#e14123</color>
|
||||||
|
<color name="market_button_unselected">#939393</color>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -400,6 +400,11 @@
|
|||||||
<string name="text_usage_stats_permission">查看使用统计权限</string>
|
<string name="text_usage_stats_permission">查看使用统计权限</string>
|
||||||
<string name="description_usage_stats_permission">通过\"查看使用统计\"权限可以获取本设备过去使用应用的情况,从而使获取当前应用(currentPackage)时更准确。</string>
|
<string name="description_usage_stats_permission">通过\"查看使用统计\"权限可以获取本设备过去使用应用的情况,从而使获取当前应用(currentPackage)时更准确。</string>
|
||||||
<string name="text_open_with">打开方式</string>
|
<string name="text_open_with">打开方式</string>
|
||||||
|
<string name="text_root">Root</string>
|
||||||
|
<string name="text_no_root">免Root</string>
|
||||||
|
<string name="text_star">收藏</string>
|
||||||
|
<string name="text_upvote">赞</string>
|
||||||
|
<string name="text_downvote">踩</string>
|
||||||
<plurals name="air_error_short_description" key="air_error_short_description">
|
<plurals name="air_error_short_description" key="air_error_short_description">
|
||||||
<item quantity="one">描述至少要 %d 个字.</item>
|
<item quantity="one">描述至少要 %d 个字.</item>
|
||||||
<item quantity="other">描述至少要 %d 个字.</item>
|
<item quantity="other">描述至少要 %d 个字.</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user