├── .gitignore ├── .idea ├── .gitignore ├── compiler.xml ├── gradle.xml ├── inspectionProfiles │ └── Project_Default.xml ├── kotlinc.xml ├── misc.xml └── vcs.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── recite ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── recite │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── recite │ │ │ ├── base │ │ │ ├── App.kt │ │ │ └── BaseActivity.kt │ │ │ └── ui │ │ │ ├── HistoryActivity.kt │ │ │ ├── MainActivity.kt │ │ │ ├── QuestionActivity.kt │ │ │ ├── SettingActivity.kt │ │ │ ├── SplashActivity.kt │ │ │ └── view │ │ │ └── LayoutQuestionSelector.kt │ └── res │ │ ├── drawable │ │ ├── baseline_more_horiz_24.xml │ │ ├── baseline_more_horiz_24_gray.xml │ │ ├── baseline_search_24.xml │ │ ├── baseline_settings_24.xml │ │ ├── baseline_warning_24.xml │ │ ├── ic_launcher_background.xml │ │ ├── ic_launcher_foreground.xml │ │ └── icon.png │ │ ├── layout │ │ ├── activity_base.xml │ │ ├── activity_history.xml │ │ ├── activity_main.xml │ │ ├── activity_question.xml │ │ ├── activity_setting.xml │ │ ├── activity_splash.xml │ │ ├── item_history.xml │ │ └── layout_question_selector.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── values-night │ │ └── themes.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── themes.xml │ └── test │ └── java │ └── com │ └── example │ └── recite │ └── ExampleUnitTest.kt ├── settings.gradle └── worddb ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── proguard-rules.pro └── src ├── androidTest └── java │ └── com │ └── example │ └── worddb │ └── ExampleInstrumentedTest.kt ├── main ├── AndroidManifest.xml ├── assets │ ├── tmp.db │ ├── tmp.db-shm │ └── tmp.db-wal └── java │ └── com │ └── example │ └── worddb │ ├── WordManager.kt │ ├── database │ ├── AppDatabase.kt │ ├── AppTypeConverters.kt │ ├── dao │ │ └── WordDao.kt │ └── entity │ │ ├── BookID.kt │ │ └── Word.kt │ └── utils │ └── Common.kt └── test └── java └── com └── example └── worddb └── ExampleUnitTest.kt /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | local.properties 16 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 20 | 21 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 41 | -------------------------------------------------------------------------------- /.idea/kotlinc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | plugins { 3 | id 'com.android.application' version '8.1.2' apply false 4 | id 'org.jetbrains.kotlin.android' version '1.8.10' apply false 5 | id 'com.android.library' version '8.1.2' apply false 6 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Kotlin code style for this project: "official" or "obsolete": 19 | kotlin.code.style=official 20 | # Enables namespacing of each library's R class so that its R class includes only the 21 | # resources declared in the library itself and none from the library's dependencies, 22 | # thereby reducing the size of the R class for that library 23 | android.nonTransitiveRClass=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nichem/reciteword/ca8f5922b7d9f6dfb07bb8ac42595b2a475572ed/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Jan 10 14:42:01 CST 2024 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /recite/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /recite/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'org.jetbrains.kotlin.android' 4 | } 5 | 6 | android { 7 | namespace 'com.example.recite' 8 | compileSdk 34 9 | 10 | defaultConfig { 11 | applicationId "com.example.recite" 12 | minSdk 24 13 | targetSdk 33 14 | versionCode 1 15 | versionName "1.0" 16 | 17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 18 | } 19 | 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | compileOptions { 27 | sourceCompatibility JavaVersion.VERSION_1_8 28 | targetCompatibility JavaVersion.VERSION_1_8 29 | } 30 | kotlinOptions { 31 | jvmTarget = '1.8' 32 | } 33 | viewBinding { 34 | enabled true 35 | } 36 | } 37 | 38 | dependencies { 39 | 40 | implementation 'androidx.core:core-ktx:1.9.0' 41 | implementation 'androidx.appcompat:appcompat:1.6.1' 42 | implementation 'com.google.android.material:material:1.11.0' 43 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4' 44 | testImplementation 'junit:junit:4.13.2' 45 | androidTestImplementation 'androidx.test.ext:junit:1.1.5' 46 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' 47 | implementation(project(":worddb")) 48 | implementation 'com.github.xuexiangjys:XUI:1.2.1' 49 | implementation 'com.github.bumptech.glide:glide:4.12.0' 50 | implementation 'com.github.JessYanCoding:AndroidAutoSize:v1.2.1' 51 | implementation 'com.blankj:utilcodex:1.31.1' 52 | def lifecycle_version = "2.6.2" 53 | implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" 54 | implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version" 55 | implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version" 56 | implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4' 57 | } -------------------------------------------------------------------------------- /recite/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /recite/src/androidTest/java/com/example/recite/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.example.recite 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.example.recite", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /recite/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 15 | 18 | 21 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 35 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /recite/src/main/java/com/example/recite/base/App.kt: -------------------------------------------------------------------------------- 1 | package com.example.recite.base 2 | 3 | import android.annotation.SuppressLint 4 | import android.app.Application 5 | import com.example.worddb.WordManager 6 | 7 | class App : Application() { 8 | companion object { 9 | @SuppressLint("StaticFieldLeak") 10 | lateinit var wordManager: WordManager 11 | } 12 | 13 | override fun onCreate() { 14 | super.onCreate() 15 | wordManager = WordManager(this) 16 | } 17 | } -------------------------------------------------------------------------------- /recite/src/main/java/com/example/recite/base/BaseActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.recite.base 2 | 3 | import android.os.Bundle 4 | import android.view.View 5 | import androidx.appcompat.app.AppCompatActivity 6 | import androidx.viewbinding.ViewBinding 7 | import com.example.recite.databinding.ActivityBaseBinding 8 | import com.xuexiang.xui.widget.actionbar.TitleBar 9 | 10 | abstract class BaseActivity : AppCompatActivity() { 11 | 12 | val binding: T by lazy { 13 | createBinding() 14 | } 15 | 16 | private val baseBinding: ActivityBaseBinding by lazy { 17 | ActivityBaseBinding.inflate(layoutInflater) 18 | } 19 | 20 | abstract fun createBinding(): T 21 | override fun onCreate(savedInstanceState: Bundle?) { 22 | super.onCreate(savedInstanceState) 23 | baseBinding.fl.addView(binding.root) 24 | if (hideTitleBar()) baseBinding.titleBar.visibility = View.GONE 25 | else initTitleBar(baseBinding.titleBar) 26 | setContentView(baseBinding.root) 27 | initView() 28 | } 29 | 30 | abstract fun initView() 31 | 32 | open fun initTitleBar(bar: TitleBar) {} 33 | 34 | open fun hideTitleBar(): Boolean = false 35 | 36 | fun getTitleBar() = baseBinding.titleBar 37 | 38 | fun addOver(view: View) { 39 | baseBinding.flOver.addView(view) 40 | } 41 | } -------------------------------------------------------------------------------- /recite/src/main/java/com/example/recite/ui/HistoryActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.recite.ui 2 | 3 | import android.content.Context 4 | import androidx.appcompat.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.util.Log 7 | import android.view.View 8 | import android.view.ViewGroup 9 | import android.widget.FrameLayout 10 | import androidx.lifecycle.lifecycleScope 11 | import com.chad.library.adapter.base.BaseQuickAdapter 12 | import com.chad.library.adapter.base.viewholder.BaseViewHolder 13 | import com.example.recite.R 14 | import com.example.recite.base.App 15 | import com.example.recite.base.App.Companion.wordManager 16 | import com.example.recite.base.BaseActivity 17 | import com.example.recite.databinding.ActivityHistoryBinding 18 | import com.example.worddb.database.entity.Word 19 | import com.example.worddb.utils.Common 20 | import com.google.android.material.search.SearchView 21 | import com.xuexiang.xui.widget.actionbar.TitleBar 22 | import com.xuexiang.xui.widget.actionbar.TitleBar.ImageAction 23 | import com.xuexiang.xui.widget.actionbar.TitleBar.TextAction 24 | import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog 25 | import com.xuexiang.xui.widget.popupwindow.popup.XUIListPopup 26 | import com.xuexiang.xui.widget.popupwindow.popup.XUISimplePopup 27 | import com.xuexiang.xui.widget.searchview.MaterialSearchView 28 | import kotlinx.coroutines.Job 29 | import kotlinx.coroutines.delay 30 | import kotlinx.coroutines.launch 31 | 32 | class HistoryActivity : BaseActivity() { 33 | override fun createBinding(): ActivityHistoryBinding = 34 | ActivityHistoryBinding.inflate(layoutInflater) 35 | 36 | private val adapter = HistoryAdapter() 37 | private lateinit var searchView: MaterialSearchView 38 | 39 | override fun initView() { 40 | binding.rv.adapter = adapter 41 | createSearchView() 42 | addOver(searchView) 43 | lifecycleScope.launch { 44 | val words = wordManager.getAllRecitedWords(wordManager.currentBookID) 45 | adapter.setList(words) 46 | } 47 | } 48 | 49 | override fun initTitleBar(bar: TitleBar) { 50 | super.initTitleBar(bar) 51 | bar.setTitle("背诵历史") 52 | .setLeftClickListener { onBackPressed() } 53 | .addAction(object : ImageAction(R.drawable.baseline_search_24) { 54 | override fun performAction(view: View?) { 55 | searchView.showSearch() 56 | } 57 | }) 58 | } 59 | 60 | 61 | private fun createSearchView() { 62 | searchView = MaterialSearchView(this).apply { 63 | layoutParams = FrameLayout.LayoutParams(-1, -1) 64 | setVoiceSearch(false) 65 | setEllipsize(true) 66 | setHint("搜索背诵记录") 67 | setOnQueryTextListener(object : MaterialSearchView.OnQueryTextListener { 68 | override fun onQueryTextSubmit(query: String?): Boolean { 69 | search(query) 70 | searchView.closeSearch() 71 | return false 72 | } 73 | 74 | override fun onQueryTextChange(newText: String?): Boolean { 75 | return false 76 | } 77 | 78 | }) 79 | } 80 | } 81 | 82 | private fun search(query: String?) { 83 | if (query.isNullOrBlank()) return 84 | lifecycleScope.launch { 85 | val words = wordManager.findRecitedWords(wordManager.currentBookID, query.trim()) 86 | adapter.setList(words) 87 | getTitleBar().setTitle("关键词:$query") 88 | isSearch = true 89 | } 90 | } 91 | 92 | private var isSearch = false 93 | 94 | override fun onBackPressed() { 95 | if (!isSearch) { 96 | super.onBackPressed() 97 | } else { 98 | isSearch = false 99 | getTitleBar().setTitle("背诵历史") 100 | lifecycleScope.launch { 101 | val words = wordManager.getAllRecitedWords(wordManager.currentBookID) 102 | adapter.setList(words) 103 | } 104 | } 105 | } 106 | 107 | 108 | } 109 | 110 | class HistoryAdapter : BaseQuickAdapter(R.layout.item_history) { 111 | override fun convert(holder: BaseViewHolder, item: Word) { 112 | holder.setText(R.id.tv_text, item.text) 113 | holder.setText(R.id.tv_trans_cn, item.tranCN) 114 | val sub = item.nextTime - Common.getNowDay() 115 | val review = if (sub <= 0) "今日需要复习" 116 | else "${sub}天后复习" 117 | holder.setText(R.id.tv_review, review) 118 | } 119 | 120 | } -------------------------------------------------------------------------------- /recite/src/main/java/com/example/recite/ui/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.recite.ui 2 | 3 | import android.annotation.SuppressLint 4 | import androidx.appcompat.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.util.Log 7 | import android.view.View 8 | import androidx.core.view.isGone 9 | import androidx.lifecycle.LiveData 10 | import androidx.lifecycle.MutableLiveData 11 | import androidx.lifecycle.ViewModel 12 | import androidx.lifecycle.ViewModelProvider 13 | import androidx.lifecycle.lifecycleScope 14 | import androidx.lifecycle.map 15 | import androidx.lifecycle.viewModelScope 16 | import com.blankj.utilcode.util.ActivityUtils 17 | import com.example.recite.R 18 | import com.example.recite.base.App.Companion.wordManager 19 | import com.example.recite.base.BaseActivity 20 | import com.example.recite.databinding.ActivityMainBinding 21 | import com.example.worddb.database.entity.BookID 22 | import com.example.worddb.database.entity.Word 23 | import com.xuexiang.xui.widget.actionbar.TitleBar 24 | import com.xuexiang.xui.widget.actionbar.TitleBar.ImageAction 25 | import kotlinx.coroutines.launch 26 | 27 | class MainActivity : BaseActivity() { 28 | private val viewModel by lazy { 29 | ViewModelProvider(this)[MainViewModel::class.java] 30 | } 31 | 32 | override fun createBinding(): ActivityMainBinding = ActivityMainBinding.inflate(layoutInflater) 33 | 34 | override fun initView() { 35 | viewModel.word.observe(this) { 36 | setWord(it) 37 | } 38 | viewModel.progressState.observe(this) { 39 | //设置副标题 40 | val leftCount = it.needReviewCount - it.index 41 | val subTitle = if (leftCount > 0) { 42 | "今日还需复习${leftCount}个单词" 43 | } else 44 | "还剩${it.noReciteCount - (it.index - it.needReviewCount)}个单词要学习" 45 | getTitleBar().setSubTitle(subTitle) 46 | 47 | //设置左边按钮文字 48 | binding.btnForget.text = if (it.index < it.needReviewCount) "忘记了" else "不知道" 49 | 50 | //设置进度 51 | if (it.index < it.needReviewCount) { 52 | binding.progress.isGone = false 53 | binding.progress.max = it.needReviewCount 54 | binding.progress.progress = it.index 55 | } else { 56 | binding.progress.isGone = true 57 | } 58 | } 59 | binding.btnForget.setOnClickListener { 60 | viewModel.operateWord(MainViewModel.Operation.Forget) 61 | } 62 | binding.btnNormal.setOnClickListener { 63 | viewModel.operateWord(MainViewModel.Operation.Normal) 64 | } 65 | binding.btnRemember.setOnClickListener { 66 | viewModel.operateWord(MainViewModel.Operation.Remember) 67 | } 68 | viewModel.initReciteWords() 69 | } 70 | 71 | override fun initTitleBar(bar: TitleBar) { 72 | super.initTitleBar(bar) 73 | bar.setTitle("背单词") 74 | .disableLeftView() 75 | .addAction(object : ImageAction(R.drawable.baseline_more_horiz_24) { 76 | override fun performAction(view: View?) { 77 | //toSetting 78 | ActivityUtils.startActivity(SettingActivity::class.java) 79 | } 80 | }) 81 | } 82 | 83 | @SuppressLint("SetTextI18n") 84 | private fun setWord(word: Word?) { 85 | if (word == null) return 86 | binding.tvWord.text = word.text.trim() 87 | binding.tvPhonetic.text = "[美] ${word.usPhonetic} [英] ${word.ukPhonetic}" 88 | binding.tvTransCn.text = word.tranCN.trim() 89 | binding.tvTransOther.text = word.tranOther.trim() 90 | binding.tvSentence.text = word.sentence.trim() 91 | binding.tvSentenceCn.text = word.sentenceCN.trim() 92 | binding.tvPhrase.text = word.phrase.trim() 93 | binding.tvPhraseCn.text = word.phraseCN.trim() 94 | } 95 | 96 | override fun onResume() { 97 | super.onResume() 98 | viewModel.initReciteWords() 99 | } 100 | 101 | } 102 | 103 | data class ProgressState( 104 | val index: Int, val needReviewCount: Int, val noReciteCount: Int 105 | ) 106 | 107 | class MainViewModel() : ViewModel() { 108 | private var needReviewWords: List = emptyList() 109 | private var noReciteWords: List = emptyList() 110 | private val _wordIndex = MutableLiveData() 111 | val word: LiveData = _wordIndex.map { 112 | getWord(it) 113 | } 114 | 115 | val progressState: LiveData = _wordIndex.map { 116 | ProgressState(it, needReviewWords.size, noReciteWords.size) 117 | } 118 | 119 | fun initReciteWords() = viewModelScope.launch { 120 | noReciteWords = wordManager.getNotReciteWords(wordManager.currentBookID) 121 | needReviewWords = wordManager.getNeedReviewWords(wordManager.currentBookID) 122 | if (wordManager.isSkipTodayReview()) _wordIndex.postValue(needReviewWords.size) 123 | else _wordIndex.postValue(0) 124 | } 125 | 126 | enum class Operation { 127 | Forget, Normal, Remember 128 | } 129 | 130 | fun operateWord(operation: Operation) { 131 | val word = word.value ?: return 132 | viewModelScope.launch { 133 | when (operation) { 134 | Operation.Forget -> { 135 | wordManager.forgetWord(word) 136 | } 137 | 138 | Operation.Normal -> { 139 | wordManager.normalWord(word) 140 | } 141 | 142 | Operation.Remember -> { 143 | wordManager.rememberWord(word) 144 | } 145 | } 146 | _wordIndex.postValue((_wordIndex.value ?: -1) + 1) 147 | } 148 | } 149 | 150 | private fun getWord(index: Int): Word? { 151 | return if (index < 0) null 152 | else if (index < needReviewWords.size) 153 | needReviewWords[index] 154 | else if (index < needReviewWords.size + noReciteWords.size) 155 | noReciteWords[index - needReviewWords.size] 156 | else null 157 | } 158 | 159 | } -------------------------------------------------------------------------------- /recite/src/main/java/com/example/recite/ui/QuestionActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.recite.ui 2 | 3 | import androidx.lifecycle.LiveData 4 | import androidx.lifecycle.MutableLiveData 5 | import androidx.lifecycle.ViewModel 6 | import androidx.lifecycle.ViewModelProvider 7 | import androidx.lifecycle.map 8 | import androidx.lifecycle.viewModelScope 9 | import com.example.recite.base.App.Companion.wordManager 10 | import com.example.recite.base.BaseActivity 11 | import com.example.recite.databinding.ActivityQuestionBinding 12 | import com.example.worddb.database.entity.Word 13 | import com.xuexiang.xui.widget.actionbar.TitleBar 14 | import kotlinx.coroutines.launch 15 | 16 | class QuestionActivity : BaseActivity() { 17 | private val viewModel by lazy { 18 | ViewModelProvider(this)[QuestionViewModel::class.java] 19 | } 20 | 21 | override fun createBinding(): ActivityQuestionBinding = 22 | ActivityQuestionBinding.inflate(layoutInflater) 23 | 24 | override fun initView() { 25 | viewModel.initQuestions() 26 | viewModel.question.observe(this) { 27 | setQuestion(it) 28 | } 29 | 30 | viewModel.questionState.observe(this) { 31 | if (it.isShowExplain) { 32 | binding.layoutExplain.expand() 33 | binding.btnLeft.text = "隐藏解析" 34 | } else { 35 | binding.layoutExplain.collapse() 36 | binding.btnLeft.text = "显示解析" 37 | } 38 | if (it.isAnswered) { 39 | binding.btnRight.text = "下一题" 40 | binding.questionSelector.setSelectEnable(false) 41 | binding.questionSelector.setSelectWithRightIndex(it.questionIndex, it.rightIndex) 42 | } else { 43 | binding.btnRight.text = "显示答案" 44 | binding.questionSelector.setSelectEnable(true) 45 | binding.questionSelector.setSelect(it.questionIndex) 46 | } 47 | } 48 | 49 | viewModel.subTitle.observe(this) { 50 | getTitleBar().setSubTitle(it) 51 | } 52 | 53 | binding.btnLeft.setOnClickListener { 54 | viewModel.leftClick() 55 | } 56 | binding.btnRight.setOnClickListener { 57 | viewModel.rightClick() 58 | } 59 | binding.questionSelector.callback = { 60 | viewModel.select(it) 61 | } 62 | } 63 | 64 | private fun setQuestion(question: Word?) { 65 | if (question == null) return 66 | binding.tvQuestion.text = question.question 67 | binding.tvExplain.text = question.explain 68 | binding.questionSelector.setAnswers( 69 | question.choiceIndexOne, 70 | question.choiceIndexTwo, 71 | question.choiceIndexThree, 72 | question.choiceIndexFour 73 | ) 74 | } 75 | 76 | override fun initTitleBar(bar: TitleBar) { 77 | super.initTitleBar(bar) 78 | bar.setTitle("选择题") 79 | .setLeftClickListener { finish() } 80 | } 81 | } 82 | 83 | data class QuestionState( 84 | val isShowExplain: Boolean = false, 85 | val isAnswered: Boolean = false, 86 | val questionIndex: Int = -1 /*-1代表未选中*/, 87 | val rightIndex: Int = -1 88 | ) 89 | 90 | class QuestionViewModel() : ViewModel() { 91 | private var questions: List = emptyList() 92 | 93 | private val _questionIndex = MutableLiveData() 94 | 95 | val question: LiveData = _questionIndex.map { 96 | questions.getOrNull(it) 97 | } 98 | 99 | private val _questionState = MutableLiveData(QuestionState()) 100 | val questionState: LiveData 101 | get() = _questionState 102 | 103 | private val _subTitle = _questionIndex.map { 104 | "还剩${questions.size - it}道题" 105 | } 106 | 107 | val subTitle: LiveData 108 | get() = _subTitle 109 | 110 | fun initQuestions() = viewModelScope.launch { 111 | questions = wordManager.getQuestions(false) 112 | _questionIndex.postValue(0) 113 | } 114 | 115 | fun rightClick() { 116 | if (questionState.value?.isAnswered == true) nextQuestion() 117 | else answerFinish() 118 | } 119 | 120 | fun leftClick() { 121 | val isShow = questionState.value?.isShowExplain ?: false 122 | showOrHideExplain(!isShow) 123 | } 124 | 125 | fun select(questionIndex: Int) { 126 | _questionState.postValue(_questionState.value?.copy(questionIndex = questionIndex)) 127 | } 128 | 129 | private fun answerFinish() { 130 | val rightIndex = Math.abs(question.value?.rightIndex!!) - 1 131 | _questionState.postValue( 132 | _questionState.value?.copy( 133 | isAnswered = true, 134 | rightIndex = rightIndex 135 | ) 136 | ) 137 | } 138 | 139 | private fun nextQuestion() { 140 | val question = question.value 141 | viewModelScope.launch { wordManager.answerQuestion(question) } 142 | _questionIndex.postValue((_questionIndex.value ?: -1) + 1) 143 | _questionState.postValue(QuestionState()) 144 | 145 | } 146 | 147 | private fun showOrHideExplain(isShow: Boolean) { 148 | _questionState.postValue(_questionState.value?.copy(isShowExplain = isShow)) 149 | } 150 | } -------------------------------------------------------------------------------- /recite/src/main/java/com/example/recite/ui/SettingActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.recite.ui 2 | 3 | import androidx.lifecycle.lifecycleScope 4 | import com.blankj.utilcode.util.ActivityUtils 5 | import com.example.recite.R 6 | import com.example.recite.base.App.Companion.wordManager 7 | import com.example.recite.base.BaseActivity 8 | import com.example.recite.databinding.ActivitySettingBinding 9 | import com.example.worddb.database.entity.BookID 10 | import com.example.worddb.utils.Common 11 | import com.xuexiang.xui.widget.actionbar.TitleBar 12 | import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog 13 | import com.xuexiang.xui.widget.grouplist.XUICommonListItemView 14 | import com.xuexiang.xui.widget.grouplist.XUIGroupListView 15 | import kotlinx.coroutines.launch 16 | 17 | 18 | class SettingActivity : BaseActivity() { 19 | override fun createBinding(): ActivitySettingBinding = 20 | ActivitySettingBinding.inflate(layoutInflater) 21 | 22 | private lateinit var itemBook: XUICommonListItemView 23 | private lateinit var itemReciteHistory: XUICommonListItemView 24 | private lateinit var itemSkipToday: XUICommonListItemView 25 | private lateinit var itemQuestion: XUICommonListItemView 26 | override fun initView() { 27 | itemBook = binding.groupListView.createItemView("词书").apply { 28 | detailText = wordManager.currentBookID.bookName 29 | } 30 | itemReciteHistory = binding.groupListView.createItemView("背诵历史").apply { 31 | accessoryType = XUICommonListItemView.ACCESSORY_TYPE_CHEVRON 32 | } 33 | itemSkipToday = binding.groupListView.createItemView("今日跳过复习").apply { 34 | accessoryType = XUICommonListItemView.ACCESSORY_TYPE_SWITCH 35 | switch.isChecked = wordManager.isSkipTodayReview() 36 | switch.setOnCheckedChangeListener { _, isChecked -> 37 | wordManager.skipToday = if (isChecked) Common.getNowDay() else 0 38 | } 39 | } 40 | itemQuestion = binding.groupListView.createItemView("做下选择题").apply { 41 | accessoryType = XUICommonListItemView.ACCESSORY_TYPE_CHEVRON 42 | } 43 | val itemAbout = binding.groupListView.createItemView("关于") 44 | val itemReset = binding.groupListView.createItemView("重置软件") 45 | XUIGroupListView.newSection(this) 46 | .addItemView(itemBook) { 47 | setBook() 48 | } 49 | .addItemView(itemQuestion) { 50 | ActivityUtils.startActivity(QuestionActivity::class.java) 51 | } 52 | .addItemView(itemReciteHistory) { 53 | ActivityUtils.startActivity(HistoryActivity::class.java) 54 | } 55 | .addItemView(itemSkipToday) { 56 | itemSkipToday.switch.isChecked = !itemSkipToday.switch.isChecked 57 | } 58 | .addTo(binding.groupListView) 59 | 60 | XUIGroupListView.newSection(this) 61 | .addItemView(itemReset) { 62 | resetDatabase() 63 | } 64 | .addItemView(itemAbout) { 65 | about() 66 | } 67 | .addTo(binding.groupListView) 68 | } 69 | 70 | 71 | override fun initTitleBar(bar: TitleBar) { 72 | super.initTitleBar(bar) 73 | bar.setTitle("更多") 74 | .setLeftClickListener { 75 | finish() 76 | } 77 | } 78 | 79 | private fun setBook() { 80 | val bookList = enumValues().toList() 81 | val bookIndex = enumValues().indexOf(wordManager.currentBookID) 82 | MaterialDialog.Builder(this) 83 | .items(bookList.map { 84 | it.bookName 85 | }) 86 | .itemsCallbackSingleChoice(bookIndex) { _, _, which, _ -> 87 | wordManager.currentBookID = bookList[which] 88 | itemBook.detailText = wordManager.currentBookID.bookName 89 | true 90 | } 91 | .positiveText("确认") 92 | .show() 93 | } 94 | 95 | 96 | private fun about() { 97 | val packageInfo = packageManager.getPackageInfo( 98 | packageName, 0 99 | ) 100 | val versionName: String = packageInfo.versionName 101 | 102 | MaterialDialog.Builder(this) 103 | .content("作者:dlearn\n版本:${versionName}") 104 | .positiveText("确认") 105 | .show() 106 | } 107 | 108 | private fun resetDatabase() { 109 | MaterialDialog.Builder(this) 110 | .iconRes(R.drawable.baseline_warning_24) 111 | .limitIconToDefaultSize() 112 | .title("警告") 113 | .content("此操作将清除你所有的背诵记录和做题记录!") 114 | .positiveText("确认清除") 115 | .negativeText("点错了") 116 | .onPositive { _, _ -> 117 | val dialog = MaterialDialog.Builder(this) 118 | .progress(true, 0) 119 | .progressIndeterminateStyle(false) 120 | .content("清除中") 121 | .cancelable(false) 122 | .canceledOnTouchOutside(false) 123 | .show() 124 | lifecycleScope.launch { 125 | wordManager.resetDatabase() 126 | dialog.dismiss() 127 | } 128 | } 129 | .show() 130 | } 131 | 132 | } -------------------------------------------------------------------------------- /recite/src/main/java/com/example/recite/ui/SplashActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.recite.ui 2 | 3 | import android.annotation.SuppressLint 4 | import android.content.Intent 5 | import androidx.appcompat.app.AppCompatActivity 6 | import android.os.Bundle 7 | import androidx.lifecycle.lifecycleScope 8 | import com.blankj.utilcode.util.ActivityUtils 9 | import com.example.recite.R 10 | import com.example.recite.base.App.Companion.wordManager 11 | import com.example.recite.base.BaseActivity 12 | import com.example.recite.databinding.ActivitySplashBinding 13 | import kotlinx.coroutines.launch 14 | 15 | @SuppressLint("CustomSplashScreen") 16 | class SplashActivity : BaseActivity() { 17 | override fun createBinding(): ActivitySplashBinding = 18 | ActivitySplashBinding.inflate(layoutInflater) 19 | 20 | override fun initView() { 21 | lifecycleScope.launch { 22 | wordManager.initDatabase() 23 | ActivityUtils.startActivity(MainActivity::class.java) 24 | finish() 25 | } 26 | } 27 | 28 | 29 | } -------------------------------------------------------------------------------- /recite/src/main/java/com/example/recite/ui/view/LayoutQuestionSelector.kt: -------------------------------------------------------------------------------- 1 | package com.example.recite.ui.view 2 | 3 | import android.content.Context 4 | import android.graphics.Color 5 | import android.graphics.drawable.BitmapDrawable 6 | import android.util.AttributeSet 7 | import android.view.LayoutInflater 8 | import android.widget.LinearLayout 9 | import com.blankj.utilcode.util.ConvertUtils 10 | import com.example.recite.databinding.LayoutQuestionSelectorBinding 11 | import com.xuexiang.xui.utils.DrawableUtils 12 | 13 | class LayoutQuestionSelector : LinearLayout { 14 | constructor(context: Context?) : super(context) 15 | constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) 16 | constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super( 17 | context, 18 | attrs, 19 | defStyleAttr 20 | ) 21 | 22 | private var binding: LayoutQuestionSelectorBinding = 23 | LayoutQuestionSelectorBinding.inflate(LayoutInflater.from(context), this, true) 24 | 25 | override fun onAttachedToWindow() { 26 | super.onAttachedToWindow() 27 | setClicks(binding.ll1, binding.ll2, binding.ll3, binding.ll4) 28 | setSelect(-1) 29 | } 30 | 31 | private fun setClicks(vararg layout: LinearLayout) { 32 | layout.forEachIndexed { index, linearLayout -> 33 | linearLayout.setOnClickListener { 34 | if (selectEnable) callback(index) 35 | } 36 | } 37 | } 38 | 39 | var callback: (Int) -> Unit = {} 40 | 41 | fun setAnswers(vararg answer: String) { 42 | binding.tv1.text = answer[0] 43 | binding.tv2.text = answer[1] 44 | binding.tv3.text = answer[2] 45 | binding.tv4.text = answer[3] 46 | } 47 | 48 | fun setSelect(selectIndex: Int) { 49 | val tvs = listOf(binding.tv1, binding.tv2, binding.tv3, binding.tv4) 50 | val images = listOf(binding.img1, binding.img2, binding.img3, binding.img4) 51 | val texts = listOf("A", "B", "C", "D") 52 | tvs.forEachIndexed { index, textView -> 53 | textView.setTextColor(if (selectIndex == index) selectColor else fontColor) 54 | } 55 | images.forEachIndexed { index, imageView -> 56 | imageView.setImageDrawable( 57 | createOption( 58 | texts[index], 59 | if (index == selectIndex) selectColor else Color.WHITE, 60 | if (index == selectIndex) Color.WHITE else fontColor 61 | ) 62 | ) 63 | } 64 | } 65 | 66 | fun setSelectWithRightIndex(selectIndex: Int, rightIndex: Int) { 67 | val tvs = listOf(binding.tv1, binding.tv2, binding.tv3, binding.tv4) 68 | val images = listOf(binding.img1, binding.img2, binding.img3, binding.img4) 69 | val texts = listOf("A", "B", "C", "D") 70 | tvs.forEachIndexed { index, textView -> 71 | val textColor = if (rightIndex == index) { 72 | correctColor 73 | } else if (selectIndex != rightIndex && selectIndex == index) { 74 | errorColor 75 | } else { 76 | fontColor 77 | } 78 | textView.setTextColor(textColor) 79 | } 80 | images.forEachIndexed { index, imageView -> 81 | val bgColor = if (rightIndex == index) { 82 | correctColor 83 | } else if (selectIndex != rightIndex && selectIndex == index) { 84 | errorColor 85 | } else { 86 | Color.WHITE 87 | } 88 | 89 | imageView.setImageDrawable( 90 | createOption( 91 | texts[index], 92 | bgColor, 93 | if (index == selectIndex || index == rightIndex) Color.WHITE else fontColor 94 | ) 95 | ) 96 | } 97 | } 98 | 99 | private var selectEnable = true 100 | fun setSelectEnable(enable: Boolean) { 101 | selectEnable = enable 102 | } 103 | 104 | private val fontColor = 105 | resources.getColor(com.xuexiang.xui.R.color.xui_config_color_middle_blue_gray) 106 | private val selectColor = 107 | resources.getColor(com.xuexiang.xui.R.color.xui_config_color_main_theme) 108 | private val errorColor = resources.getColor(com.xuexiang.xui.R.color.xui_config_color_red) 109 | 110 | private val correctColor = 111 | resources.getColor(com.xuexiang.xui.R.color.xui_btn_green_normal_color) 112 | 113 | private fun createOption(a: String, bgColor: Int, fontColor: Int): BitmapDrawable { 114 | return DrawableUtils.createCircleDrawableWithText( 115 | resources, ConvertUtils.dp2px(40f), bgColor, a, ConvertUtils.sp2px(18f) * 1f, 116 | fontColor 117 | ) 118 | } 119 | } -------------------------------------------------------------------------------- /recite/src/main/res/drawable/baseline_more_horiz_24.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /recite/src/main/res/drawable/baseline_more_horiz_24_gray.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /recite/src/main/res/drawable/baseline_search_24.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /recite/src/main/res/drawable/baseline_settings_24.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /recite/src/main/res/drawable/baseline_warning_24.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /recite/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /recite/src/main/res/drawable/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /recite/src/main/res/drawable/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nichem/reciteword/ca8f5922b7d9f6dfb07bb8ac42595b2a475572ed/recite/src/main/res/drawable/icon.png -------------------------------------------------------------------------------- /recite/src/main/res/layout/activity_base.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 19 | 20 | 26 | -------------------------------------------------------------------------------- /recite/src/main/res/layout/activity_history.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | -------------------------------------------------------------------------------- /recite/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 21 | 22 | 23 | 32 | 33 | 41 | 42 | 51 | 52 | 60 | 61 | 69 | 70 | 78 | 79 | 87 | 88 | 96 | 97 | 98 | 106 | 107 | 114 | 115 | 122 | 123 | 124 | 125 | 126 | 133 | 134 | 142 | 143 | 152 | 153 | 162 | 163 | 171 | 172 | 173 | -------------------------------------------------------------------------------- /recite/src/main/res/layout/activity_question.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 16 | 17 | 21 | 22 | 29 | 30 | 39 | 40 | 45 | 46 | 47 | 48 | 54 | 55 | 59 | 60 | 65 | 66 | 73 | 74 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 94 | 95 | 103 | 104 | 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /recite/src/main/res/layout/activity_setting.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 12 | 13 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /recite/src/main/res/layout/activity_splash.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 19 | 20 | 28 | 29 | -------------------------------------------------------------------------------- /recite/src/main/res/layout/item_history.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 19 | 20 | 29 | 30 | 39 | 40 | 41 | 52 | 53 | 61 | 62 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /recite/src/main/res/layout/layout_question_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 15 | 16 | 21 | 22 | 29 | 30 | 31 | 39 | 40 | 45 | 46 | 53 | 54 | 55 | 63 | 64 | 69 | 70 | 77 | 78 | 79 | 87 | 88 | 93 | 94 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /recite/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /recite/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /recite/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nichem/reciteword/ca8f5922b7d9f6dfb07bb8ac42595b2a475572ed/recite/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /recite/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nichem/reciteword/ca8f5922b7d9f6dfb07bb8ac42595b2a475572ed/recite/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /recite/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nichem/reciteword/ca8f5922b7d9f6dfb07bb8ac42595b2a475572ed/recite/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /recite/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nichem/reciteword/ca8f5922b7d9f6dfb07bb8ac42595b2a475572ed/recite/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /recite/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nichem/reciteword/ca8f5922b7d9f6dfb07bb8ac42595b2a475572ed/recite/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /recite/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nichem/reciteword/ca8f5922b7d9f6dfb07bb8ac42595b2a475572ed/recite/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /recite/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nichem/reciteword/ca8f5922b7d9f6dfb07bb8ac42595b2a475572ed/recite/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /recite/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nichem/reciteword/ca8f5922b7d9f6dfb07bb8ac42595b2a475572ed/recite/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /recite/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nichem/reciteword/ca8f5922b7d9f6dfb07bb8ac42595b2a475572ed/recite/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /recite/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nichem/reciteword/ca8f5922b7d9f6dfb07bb8ac42595b2a475572ed/recite/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /recite/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /recite/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FF000000 4 | #FFFFFFFF 5 | -------------------------------------------------------------------------------- /recite/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 20dp 4 | -------------------------------------------------------------------------------- /recite/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 背单词 3 | -------------------------------------------------------------------------------- /recite/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 |