Skip to content

Commit

Permalink
展示、编辑群组信息
Browse files Browse the repository at this point in the history
  • Loading branch information
YuS1aN committed Mar 4, 2024
1 parent 3f4aaec commit 654bc6f
Show file tree
Hide file tree
Showing 39 changed files with 923 additions and 254 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ android {
}
buildFeatures {
viewBinding true
buildConfig true
}
externalNativeBuild {
cmake {
Expand Down Expand Up @@ -88,4 +89,5 @@ dependencies {
implementation deps.webkit
implementation deps.ansi4j_api
implementation deps.ansi4j_impl
implementation deps.viewpagerindicator
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<application
android:name=".ZxApplication"
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/assets/console_bar_charts.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@
});
}

function setChartData2(data) {
chart.setOption({
xAxis: {
axisLabel: {
width: chart.getWidth() / data.length
}
},
dataset: {
source: data
}
});
}

function setDarkMode(isDarkMode) {
let elements = document.getElementsByClassName('charts');
for (i = 0; i < elements.length; i++) {
Expand Down
18 changes: 10 additions & 8 deletions app/src/main/java/me/kbai/zhenxunui/api/ApiService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package me.kbai.zhenxunui.api

import me.kbai.zhenxunui.model.BotBaseInfo
import me.kbai.zhenxunui.model.BotMessageCount
import me.kbai.zhenxunui.model.FriendListItem
import me.kbai.zhenxunui.model.GroupInfo
import me.kbai.zhenxunui.model.GroupListItem
import me.kbai.zhenxunui.model.HandleRequest
import me.kbai.zhenxunui.model.LoginInfo
import me.kbai.zhenxunui.model.PluginDetail
import me.kbai.zhenxunui.model.PluginInfo
import me.kbai.zhenxunui.model.PluginSwitch
import me.kbai.zhenxunui.model.BotRequest
import me.kbai.zhenxunui.model.FriendListItem
import me.kbai.zhenxunui.model.GroupListItem
import me.kbai.zhenxunui.model.RequestListResult
import me.kbai.zhenxunui.model.SendMessage
import me.kbai.zhenxunui.model.UpdateGroup
Expand All @@ -35,21 +34,24 @@ interface ApiService {
@Field("password") password: String
): ApiResponse<LoginInfo>

@GET("get_group")
suspend fun getGroup(): ApiResponse<List<GroupInfo>>

@GET("manage/get_friend_list")
suspend fun getFriendList(@Query("bot_id") botId: String): ApiResponse<List<FriendListItem>>

@GET("manage/get_group_list")
suspend fun getGroupList(@Query("bot_id") botId: String): ApiResponse<List<GroupListItem>>

@POST("update_group")
@GET("manage/get_group_detail")
suspend fun getGroupDetail(
@Query("bot_id") botId: String,
@Query("group_id") groupId: String
): ApiResponse<GroupInfo>

@POST("manage/update_group")
suspend fun updateGroup(@Body updateGroup: UpdateGroup): ApiResponse<Unit>

@GET("plugin/get_plugin_list")
suspend fun getPluginList(
@Query("plugin_type") type: String,
@Query("plugin_type") type: Array<String>,
@Query("menu_type") menuType: String? = null
): ApiResponse<List<PluginInfo>>

Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/me/kbai/zhenxunui/api/BotApi.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.kbai.zhenxunui.api

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import me.kbai.zhenxunui.Constants
import okhttp3.Interceptor
import okhttp3.OkHttpClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package me.kbai.zhenxunui.extends

import android.view.animation.Animation
import android.view.animation.Animation.AnimationListener
import androidx.dynamicanimation.animation.DynamicAnimation.OnAnimationEndListener


fun Animation.setAnimationListener(
Expand Down
47 changes: 28 additions & 19 deletions app/src/main/java/me/kbai/zhenxunui/model/GroupInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,44 @@ import com.google.gson.annotations.SerializedName
* @author Sean on 2023/5/31
*/
data class GroupInfo(
val group: Group,
@SerializedName("group_id")
val groupId: String,

val name: String,

@SerializedName("call_count")
val callCount: Int,

@SerializedName("chat_count")
val chatCount: Int,

val level: Int,

val status: Boolean,

@SerializedName("ava_url")
val avatarUrl: String,

@SerializedName("max_member_count")
val maxMemberCount: Int,

@SerializedName("member_count")
val memberCount: Int,

@SerializedName("like_plugin")
val favouritePlugins: Map<String, Int>,

@SerializedName("close_plugins")
val closedPlugins: List<String>,

val task: List<Task>
) {

data class Group(
@SerializedName("group_id")
val groupId: String,
@SerializedName("group_name")
val groupName: String,
@SerializedName("member_count")
val memberCount: Int,
@SerializedName("max_member_count")
val maxMemberCount: Int
)

data class Task(
val name: String,
val nameZh: String,
@SerializedName("zh_name")
val zhName: String,
val status: Boolean
)

fun makeUpdateGroup() = UpdateGroup(
group.groupId,
status,
level
)
}

7 changes: 5 additions & 2 deletions app/src/main/java/me/kbai/zhenxunui/model/UpdateGroup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import com.google.gson.annotations.SerializedName
data class UpdateGroup(
@SerializedName("group_id")
val groupId: String,
var status: Boolean,
var level: Int
val status: Boolean,
val level: Int,
@SerializedName("close_plugins")
val closedPlugins: List<String>,
val task: List<String>
)
10 changes: 9 additions & 1 deletion app/src/main/java/me/kbai/zhenxunui/repository/ApiRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,18 @@ object ApiRepository {

fun getGroupList(botId: String) = networkFlow { BotApi.service.getGroupList(botId) }

fun getGroupDetail(botId: String, groupId: String) =
networkFlow { BotApi.service.getGroupDetail(botId, groupId) }

fun updateGroup(updateGroup: UpdateGroup) =
networkFlow { BotApi.service.updateGroup(updateGroup) }

fun getPluginList(type: PluginType) = networkFlow { BotApi.service.getPluginList(type.string) }
fun getPluginList(vararg types: PluginType, menuType: String? = null) = networkFlow {
BotApi.service.getPluginList(
types.map { it.string }.toTypedArray(),
menuType
)
}

fun getPluginDetail(pluginInfo: PluginInfo) = networkFlow(PluginDetail(pluginInfo, null)) {
BotApi.service.getPluginDetail(pluginInfo.module)
Expand Down
46 changes: 23 additions & 23 deletions app/src/main/java/me/kbai/zhenxunui/ui/console/ConsoleFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ import kotlin.math.abs
class ConsoleFragment : BaseFragment<FragmentConsoleBinding>() {

companion object {
private const val LOCAL_DOMAIN = "local.host"
private const val BAR_CHART_FILE = "http://$LOCAL_DOMAIN/assets/console_bar_charts.html"
private const val TANGENTIAL_BAR_FILE =
const val LOCAL_DOMAIN = "local.host"
const val BAR_CHART_FILE = "http://$LOCAL_DOMAIN/assets/console_bar_charts.html"
const val TANGENTIAL_BAR_FILE =
"http://$LOCAL_DOMAIN/assets/console_horizontal_bar_charts.html"
}

Expand Down Expand Up @@ -267,29 +267,29 @@ class ConsoleFragment : BaseFragment<FragmentConsoleBinding>() {
icPopularPlugin.wvCharts.detach()
}
}
}

class ConsoleChartWebViewClient(
private val assetsLoader: WebViewAssetLoader,
private val doOnPageFinished: (webView: WebView, url: String) -> Unit
) : WebViewClient() {
private var mLoading = true
class ConsoleChartWebViewClient(
private val assetsLoader: WebViewAssetLoader,
private val doOnPageFinished: (webView: WebView, url: String) -> Unit
) : WebViewClient() {
private var mLoading = true

override fun onPageFinished(view: WebView, url: String) {
super.onPageFinished(view, url)
mLoading = false
doOnPageFinished.invoke(view, url)
}
override fun onPageFinished(view: WebView, url: String) {
super.onPageFinished(view, url)
mLoading = false
doOnPageFinished.invoke(view, url)
}

override fun shouldInterceptRequest(
view: WebView,
request: WebResourceRequest
): WebResourceResponse? {
return assetsLoader.shouldInterceptRequest(request.url)
}
override fun shouldInterceptRequest(
view: WebView,
request: WebResourceRequest
): WebResourceResponse? {
return assetsLoader.shouldInterceptRequest(request.url)
}

suspend fun blockDuringLoading(block: () -> Unit) {
while (mLoading) delay(100)
block.invoke()
}
suspend fun blockDuringLoading(block: () -> Unit) {
while (mLoading) delay(100)
block.invoke()
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package me.kbai.zhenxunui.ui.group

import android.os.Bundle
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar
import androidx.core.view.MenuProvider
import androidx.core.widget.addTextChangedListener
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import me.kbai.zhenxunui.R
import me.kbai.zhenxunui.base.BaseFragment
import me.kbai.zhenxunui.databinding.FragmentConversationBinding
Expand Down Expand Up @@ -36,9 +42,6 @@ class ConversationFragment : BaseFragment<FragmentConversationBinding>() {
override fun initView(): Unit = viewBinding.run {
rvMessage.adapter = mMessageAdapter

requireActivity().findViewById<Toolbar>(R.id.toolbar).title =
arguments?.getString(ARGS_NAME)

etText.addTextChangedListener {
btnSend.isEnabled = !it.isNullOrEmpty()
}
Expand Down Expand Up @@ -81,5 +84,29 @@ class ConversationFragment : BaseFragment<FragmentConversationBinding>() {
mMessageAdapter.addData(it)
}
}

requireActivity().addMenuProvider(object : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menuInflater.inflate(R.menu.conversation_menu_items, menu)
}

override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
if (menuItem.itemId == R.id.menu_edit) {
if (groupId != null) {
findNavController().navigate(
R.id.action_conversationFragment_to_editGroupFragment,
Bundle().apply {
putString(EditGroupFragment.ARGS_GROUP_ID, groupId)
}
)
}
return true
}
return false
}
}, viewLifecycleOwner)

requireActivity().findViewById<Toolbar>(R.id.toolbar).title =
arguments?.getString(ARGS_NAME)
}
}

This file was deleted.

Loading

0 comments on commit 654bc6f

Please sign in to comment.