不联网新华字典

介绍

首页字典

更多

 

 

 包含内容

内容对应Json数据文件
百家姓baijiaxing.json
曹操诗集caocao.json
弟子规dizigui.json
成语idiom.json
论语lunyu.json
纳兰性德诗集nalanshiji.json
千家诗qianjiashi.json
千字文qianziwen.json
三字经-传统版sanzijing_ct.json
三字经-新版sanzijing_xb.json
诗经shijing.json
水墨唐诗shuimotangshi.json
唐诗三百首tangshisanbaishou.json
新华字典word.json
歇后语xiehouyu.json
朱子家训zhuzijiaxun.json

依赖库

我这里用了应用更新,所以更新的时候需要网络,其他数据读取本地json数据不需要联网

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.1.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.4.+'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    //recyclerview
    implementation 'androidx.recyclerview:recyclerview:1.2.1'
    //cardview
    implementation 'androidx.cardview:cardview:1.0.0'
    //gson数据解析
    implementation 'com.google.code.gson:gson:2.10.1'
    //沉浸状态栏基础依赖包,必须要依赖
    implementation 'com.geyifeng.immersionbar:immersionbar:3.2.2'
    implementation 'com.geyifeng.immersionbar:immersionbar-ktx:3.2.2'
    //工具库
    implementation 'com.github.yechaoa.YUtils:yutilskt:3.2.2'
    //glide图片加载
    implementation 'com.github.bumptech.glide:glide:4.15.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.15.0'
    //网络请求所需
    implementation "io.reactivex.rxjava2:rxjava:2.2.8"
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
    implementation 'com.squareup.retrofit2:retrofit:2.6.2'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
    //下载更新
    implementation 'com.github.azhon:AppUpdate:3.0.5'
}

本地json数据加载与解析

import android.content.Context
import com.yechaoa.yutilskt.YUtils
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader

class JsonFileUtil {

    companion object {
        fun loadFile(context: Context, fileName: String): String {
            val stringBuilder = StringBuilder()
            try {
                val inputStream = context.resources.assets.open(fileName)
                val isr = InputStreamReader(inputStream)
                val reader = BufferedReader(isr)
                var jsonLine: String?
                while (reader.readLine().also { jsonLine = it } != null) {
                    stringBuilder.append(jsonLine)
                }
                reader.close()
                isr.close()
                inputStream.close()
                YUtils.hideLoading()
            } catch (e: IOException) {
                e.printStackTrace()
                YUtils.hideLoading()
            }
            return stringBuilder.toString()
        }
    }
}
private lateinit var mapBeanList: MutableList<Word>

val str = JsonFileUtil.loadFile(this, "word.json")

val mapBeanListType: Type = object : TypeToken<ArrayList<Word?>?>() {}.type
mapBeanList = Gson().fromJson(str, mapBeanListType)

initAdapter(mapBeanList)

private fun initAdapter(list: MutableList<More>) {
    //设置布局排列方式
    val staggeredGridLayoutManager = StaggeredGridLayoutManager(2, LinearLayoutManager.VERTICAL)
    binding.rv.layoutManager = staggeredGridLayoutManager

    //加载适配器
    moreAdapter = MoreAdapter(this, list)
    binding.rv.adapter = moreAdapter
}

代码详情

https://gitee.com/juer2017/xinhuazidian

下载

 https://fir.xcxwo.com/4jc9

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

举儿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值