diff --git a/src/FruitandVegetableGuide/.gitignore b/src/FruitandVegetableGuide/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/src/FruitandVegetableGuide/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/src/FruitandVegetableGuide/.idea/.gitignore b/src/FruitandVegetableGuide/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/src/FruitandVegetableGuide/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/src/FruitandVegetableGuide/.idea/compiler.xml b/src/FruitandVegetableGuide/.idea/compiler.xml new file mode 100644 index 0000000..b589d56 --- /dev/null +++ b/src/FruitandVegetableGuide/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/FruitandVegetableGuide/.idea/dbnavigator.xml b/src/FruitandVegetableGuide/.idea/dbnavigator.xml new file mode 100644 index 0000000..2f23ff3 --- /dev/null +++ b/src/FruitandVegetableGuide/.idea/dbnavigator.xml @@ -0,0 +1,405 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/FruitandVegetableGuide/.idea/gradle.xml b/src/FruitandVegetableGuide/.idea/gradle.xml new file mode 100644 index 0000000..a2d7c21 --- /dev/null +++ b/src/FruitandVegetableGuide/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/src/FruitandVegetableGuide/.idea/inspectionProfiles/Project_Default.xml b/src/FruitandVegetableGuide/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..44ca2d9 --- /dev/null +++ b/src/FruitandVegetableGuide/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,41 @@ + + + + \ No newline at end of file diff --git a/src/FruitandVegetableGuide/.idea/kotlinc.xml b/src/FruitandVegetableGuide/.idea/kotlinc.xml new file mode 100644 index 0000000..9a55c2d --- /dev/null +++ b/src/FruitandVegetableGuide/.idea/kotlinc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/src/FruitandVegetableGuide/.idea/misc.xml b/src/FruitandVegetableGuide/.idea/misc.xml new file mode 100644 index 0000000..773fe0f --- /dev/null +++ b/src/FruitandVegetableGuide/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/src/FruitandVegetableGuide/.idea/vcs.xml b/src/FruitandVegetableGuide/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/src/FruitandVegetableGuide/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/FruitandVegetableGuide/app/.gitignore b/src/FruitandVegetableGuide/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/src/FruitandVegetableGuide/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/src/FruitandVegetableGuide/app/build.gradle b/src/FruitandVegetableGuide/app/build.gradle new file mode 100644 index 0000000..5376ae4 --- /dev/null +++ b/src/FruitandVegetableGuide/app/build.gradle @@ -0,0 +1,91 @@ +plugins { + id 'com.android.application' + id 'org.jetbrains.kotlin.android' +} + +android { + namespace 'com.example.fruitandvegetableguide' + compileSdk 34 + + defaultConfig { + applicationId "com.example.fruitandvegetableguide" + minSdk 21 + targetSdk 34 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + vectorDrawables { + useSupportLibrary true + } + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } + buildFeatures { + compose true + } + composeOptions { + kotlinCompilerExtensionVersion '1.4.8' + } + packagingOptions { + resources { + excludes += '/META-INF/{AL2.0,LGPL2.1}' + } + } +} + +dependencies { + implementation("androidx.navigation:navigation-compose:2.5.3") + + implementation "androidx.appcompat:appcompat:1.6.1" + implementation "androidx.core:core-ktx:1.10.1" + implementation "com.google.android.material:material:1.9.0" + + def composeBom = platform('androidx.compose:compose-bom:2023.08.00') + implementation(composeBom) + androidTestImplementation(composeBom) + + implementation("androidx.compose.material3:material3") + implementation("androidx.compose.material:material-icons-extended") + implementation 'androidx.compose.ui:ui-tooling-preview' + androidTestImplementation 'androidx.compose.ui:ui-test-junit4' + debugImplementation 'androidx.compose.ui:ui-tooling' + debugImplementation("androidx.compose.ui:ui-test-manifest") + + implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1") + implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1" + implementation("androidx.activity:activity-compose:1.7.2") + implementation 'androidx.core:core-ktx:1.10.1' + implementation "androidx.window:window:1.1.0" + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1" + + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.5' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' + +} +// implementation("androidx.compose.material:material") +// implementation("androidx.compose.foundation:foundation") +// implementation("androidx.compose.ui:ui") +// implementation("androidx.compose.material:material-icons-core") +// implementation("androidx.compose.material3:material3-window-size-class") +// implementation("androidx.compose.runtime:runtime-livedata") +// implementation("androidx.compose.runtime:runtime-rxjava2") +// implementation platform('org.jetbrains.kotlin:kotlin-bom:1.8.0') +// implementation platform('androidx.compose:compose-bom:2022.10.00') +// implementation 'androidx.compose.ui:ui-graphics' +// implementation 'androidx.appcompat:appcompat:1.4.1' +// implementation 'com.google.android.material:material:1.5.0' +// androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00') diff --git a/src/FruitandVegetableGuide/app/proguard-rules.pro b/src/FruitandVegetableGuide/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/src/FruitandVegetableGuide/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/src/FruitandVegetableGuide/app/src/androidTest/java/com/example/fruitandvegetableguide/ExampleInstrumentedTest.kt b/src/FruitandVegetableGuide/app/src/androidTest/java/com/example/fruitandvegetableguide/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..11351c4 --- /dev/null +++ b/src/FruitandVegetableGuide/app/src/androidTest/java/com/example/fruitandvegetableguide/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.example.fruitandvegetableguide + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.example.fruitandvegetableguide", appContext.packageName) + } +} \ No newline at end of file diff --git a/src/FruitandVegetableGuide/app/src/main/AndroidManifest.xml b/src/FruitandVegetableGuide/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..b53bc0f --- /dev/null +++ b/src/FruitandVegetableGuide/app/src/main/AndroidManifest.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/data/Account.kt b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/data/Account.kt new file mode 100644 index 0000000..92a8f04 --- /dev/null +++ b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/data/Account.kt @@ -0,0 +1,7 @@ +package com.example.fruitandvegetableguide.data + +data class Account( + val username: String, + val id:Long, + val password:String +) diff --git a/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/data/Guide.kt b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/data/Guide.kt new file mode 100644 index 0000000..84d7a9a --- /dev/null +++ b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/data/Guide.kt @@ -0,0 +1,12 @@ +package com.example.fruitandvegetableguide.data + +data class Guide( + val id: Long, + val imgId: Int, + val kind: String, + val imgUrl: String, + val suitable: String, + val taboo: String, + val nutritiveValue: String, + val recommendedMenu: String +) diff --git a/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/data/Post.kt b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/data/Post.kt new file mode 100644 index 0000000..2a068dd --- /dev/null +++ b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/data/Post.kt @@ -0,0 +1,10 @@ +package com.example.fruitandvegetableguide.data + +data class Post( + val id: Long, + val userId: Long, + val title: String, + val imgId: Int, + val labels: ArrayList, + val content: String +) diff --git a/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/data/local/LocalAccountsDataProvider.kt b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/data/local/LocalAccountsDataProvider.kt new file mode 100644 index 0000000..1141a6a --- /dev/null +++ b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/data/local/LocalAccountsDataProvider.kt @@ -0,0 +1,11 @@ +package com.example.fruitandvegetableguide.data.local + +import com.example.fruitandvegetableguide.data.Account + +object LocalAccountsDataProvider { + val allUserAccounts = mutableListOf( + Account("aaa",1,"123456"), + Account("bbb",2,"123456"), + Account("ccc",3,"123456") + ) +} \ No newline at end of file diff --git a/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/data/local/LocalGuidesDataProvider.kt b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/data/local/LocalGuidesDataProvider.kt new file mode 100644 index 0000000..c1f7497 --- /dev/null +++ b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/data/local/LocalGuidesDataProvider.kt @@ -0,0 +1,129 @@ +package com.example.fruitandvegetableguide.data.local + +import com.example.fruitandvegetableguide.data.Guide +import com.example.fruitandvegetableguide.R + +object LocalGuidesDataProvider { + val allGuides = mutableListOf( + Guide( + 1, + R.drawable.carrots, + "胡萝卜", + "https://ai-public-console.cdn.bcebos.com/portal-pc-static/1694501570778/images/technology/imagerecognition/ingredient/2.jpg", + "一般人皆可食用,尤以[癌症、高血压、夜盲症干眼症、营养不良、皮肤粗糙]者为最。", + "[饮酒过量]者不宜食用", + "热量: 37千卡, 蛋白质: 1克, 碳水化合物: 8.8克, 膳食纤维3.2克, 胡萝卜素: 4130微克", + "炝腌萝卜" + ), + Guide( + 2, + R.drawable.cucumbers, + "黄瓜", + "https://ai-public-console.cdn.bcebos.com/portal-pc-static/1694501570778/images/technology/imagerecognition/ingredient/3.jpg", + "一般人群均可食用。尤适宜[热病、肥胖、高血脂、水肿、癌症、嗜酒者、糖尿病 ]患者食用。", + "[腰胃虚弱、腹痛腹泻、肺寒咳嗽、 肝病心血管病、肠胃病]患者慎食。", + "蛋白质: 0.8克, 维生素A: 15微克, 胡萝卜素: 90微克", + "黄瓜玉子烧" + ), + Guide( + 3, + R.drawable.tomatoes, + "西红柿", + "https://bkimg.cdn.bcebos.com/pic/0823dd54564e9258d109b7bb1bd4c658ccbf6c81e012?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2U5Mg==,g_7,xp_5,yp_5/format,f_auto", + "一般人群均可食用。尤适宜于[热性病发热、口渴、食欲不振、习惯性牙龈出血、贫血、头晕心悸、高血压、急慢性肝炎、急慢性肾炎、夜盲症、近视眼]者食用", + "[急性肠炎、菌痢、溃疡活动期]病人不宜食", + "热量: 19千卡,蛋白质: 0.9 克, 碳水化合物: 4克", + "番茄乌冬面" + ), + Guide( + 4, + R.drawable.carrots, + "胡萝卜", + "https://ai-public-console.cdn.bcebos.com/portal-pc-static/1694501570778/images/technology/imagerecognition/ingredient/2.jpg", + "一般人皆可食用,尤以[癌症、高血压、夜盲症干眼症、营养不良、皮肤粗糙]者为最。", + "[饮酒过量]者不宜食用", + "热量: 37千卡, 蛋白质: 1克, 碳水化合物: 8.8克, 膳食纤维3.2克, 胡萝卜素: 4130微克", + "炝腌萝卜" + ), + Guide( + 5, + R.drawable.cucumbers, + "黄瓜", + "https://ai-public-console.cdn.bcebos.com/portal-pc-static/1694501570778/images/technology/imagerecognition/ingredient/3.jpg", + "一般人群均可食用。尤适宜[热病、肥胖、高血脂、水肿、癌症、嗜酒者、糖尿病 ]患者食用。", + "[腰胃虚弱、腹痛腹泻、肺寒咳嗽、 肝病心血管病、肠胃病]患者慎食。", + "蛋白质: 0.8克, 维生素A: 15微克, 胡萝卜素: 90微克", + "黄瓜玉子烧" + ), + Guide( + 6, + R.drawable.tomatoes, + "西红柿", + "https://bkimg.cdn.bcebos.com/pic/0823dd54564e9258d109b7bb1bd4c658ccbf6c81e012?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2U5Mg==,g_7,xp_5,yp_5/format,f_auto", + "一般人群均可食用。尤适宜于[热性病发热、口渴、食欲不振、习惯性牙龈出血、贫血、头晕心悸、高血压、急慢性肝炎、急慢性肾炎、夜盲症、近视眼]者食用", + "[急性肠炎、菌痢、溃疡活动期]病人不宜食", + "热量: 19千卡,蛋白质: 0.9 克, 碳水化合物: 4克", + "番茄乌冬面" + ), + Guide( + 1, + R.drawable.carrots, + "胡萝卜", + "https://ai-public-console.cdn.bcebos.com/portal-pc-static/1694501570778/images/technology/imagerecognition/ingredient/2.jpg", + "一般人皆可食用,尤以[癌症、高血压、夜盲症干眼症、营养不良、皮肤粗糙]者为最。", + "[饮酒过量]者不宜食用", + "热量: 37千卡, 蛋白质: 1克, 碳水化合物: 8.8克, 膳食纤维3.2克, 胡萝卜素: 4130微克", + "炝腌萝卜" + ), + Guide( + 2, + R.drawable.cucumbers, + "黄瓜", + "https://ai-public-console.cdn.bcebos.com/portal-pc-static/1694501570778/images/technology/imagerecognition/ingredient/3.jpg", + "一般人群均可食用。尤适宜[热病、肥胖、高血脂、水肿、癌症、嗜酒者、糖尿病 ]患者食用。", + "[腰胃虚弱、腹痛腹泻、肺寒咳嗽、 肝病心血管病、肠胃病]患者慎食。", + "蛋白质: 0.8克, 维生素A: 15微克, 胡萝卜素: 90微克", + "黄瓜玉子烧" + ), + Guide( + 3, + R.drawable.tomatoes, + "西红柿", + "https://bkimg.cdn.bcebos.com/pic/0823dd54564e9258d109b7bb1bd4c658ccbf6c81e012?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2U5Mg==,g_7,xp_5,yp_5/format,f_auto", + "一般人群均可食用。尤适宜于[热性病发热、口渴、食欲不振、习惯性牙龈出血、贫血、头晕心悸、高血压、急慢性肝炎、急慢性肾炎、夜盲症、近视眼]者食用", + "[急性肠炎、菌痢、溃疡活动期]病人不宜食", + "热量: 19千卡,蛋白质: 0.9 克, 碳水化合物: 4克", + "番茄乌冬面" + ), + Guide( + 4, + R.drawable.carrots, + "胡萝卜", + "https://ai-public-console.cdn.bcebos.com/portal-pc-static/1694501570778/images/technology/imagerecognition/ingredient/2.jpg", + "一般人皆可食用,尤以[癌症、高血压、夜盲症干眼症、营养不良、皮肤粗糙]者为最。", + "[饮酒过量]者不宜食用", + "热量: 37千卡, 蛋白质: 1克, 碳水化合物: 8.8克, 膳食纤维3.2克, 胡萝卜素: 4130微克", + "炝腌萝卜" + ), + Guide( + 5, + R.drawable.cucumbers, + "黄瓜", + "https://ai-public-console.cdn.bcebos.com/portal-pc-static/1694501570778/images/technology/imagerecognition/ingredient/3.jpg", + "一般人群均可食用。尤适宜[热病、肥胖、高血脂、水肿、癌症、嗜酒者、糖尿病 ]患者食用。", + "[腰胃虚弱、腹痛腹泻、肺寒咳嗽、 肝病心血管病、肠胃病]患者慎食。", + "蛋白质: 0.8克, 维生素A: 15微克, 胡萝卜素: 90微克", + "黄瓜玉子烧" + ), + Guide( + 6, + R.drawable.tomatoes, + "西红柿", + "https://bkimg.cdn.bcebos.com/pic/0823dd54564e9258d109b7bb1bd4c658ccbf6c81e012?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2U5Mg==,g_7,xp_5,yp_5/format,f_auto", + "一般人群均可食用。尤适宜于[热性病发热、口渴、食欲不振、习惯性牙龈出血、贫血、头晕心悸、高血压、急慢性肝炎、急慢性肾炎、夜盲症、近视眼]者食用", + "[急性肠炎、菌痢、溃疡活动期]病人不宜食", + "热量: 19千卡,蛋白质: 0.9 克, 碳水化合物: 4克", + "番茄乌冬面" + ) + ) +} \ No newline at end of file diff --git a/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/data/local/LocalPostsDataProvider.kt b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/data/local/LocalPostsDataProvider.kt new file mode 100644 index 0000000..b83fa9f --- /dev/null +++ b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/data/local/LocalPostsDataProvider.kt @@ -0,0 +1,189 @@ +package com.example.fruitandvegetableguide.data.local + +import com.example.fruitandvegetableguide.R +import com.example.fruitandvegetableguide.data.Post + +object LocalPostsDataProvider { + val allPosts = mutableListOf( + Post( + 1, + 1, + "白菜怎么挑选", + R.drawable.cabbage, + labels = arrayListOf("挑选方法", "白菜"), + "大白菜一般菜心是黄色的,越往外菜叶绿色逐渐增多,黄色菜叶越多,大白菜越好吃。\n" + + "黄色菜叶多说明生长周期长,主要是大白菜生长时间越长,黄色菜叶越多,说明长势很好,包的也瓷实。\n" + + "黄色菜叶多说明农家肥用得多。一般来说,农家肥种的白菜个头大,菜瓷实,黄色菜叶比较多,吃起来口感也要好一些。颜色发绿的白菜叶片厚实,吃起来口感比较粗,特别耐储存。\n" + ), + Post( + 2, + 2, + "关于西瓜的挑选经验", + R.drawable.watermelon, + labels = arrayListOf("西瓜", "经验"), + "1、看脐圈: 西瓜底部的脐圈,小、圆而且略微凹陷的西瓜,一般生长时间充分,果实会更甜。\n" + + "2、辨颜色: 颜色最好挑青绿色,不要雾雾白白的。\n" + + "3、看纹路: 西瓜纹路整齐的,就是好瓜。\n" + + "4、看瓜蒂: 西瓜头,就是所谓的瓜蒂头,从蒂部的弯曲程度,一般可判断出是第一茬瓜还是第二茬瓜。 ...\n" + + "5、听声音: 将西瓜托在手里,手指轻轻敲,如果发出“咚、咚”的清脆声,并且托瓜的手有震动的感觉就是熟透的瓜,一般瓜味也会比较甜。" + ), + Post( + 3, + 3, + "生姜怎么挑选?", + R.drawable.ginger, + labels = arrayListOf("生姜", "提问"), + "有没有好心人教教如何挑选生姜,大的和小的有什么区别" + ), + Post( + 4, + 1, + "白菜怎么挑选", + R.drawable.cabbage, + labels = arrayListOf("挑选方法", "白菜"), + "大白菜一般菜心是黄色的,越往外菜叶绿色逐渐增多,黄色菜叶越多,大白菜越好吃。\n" + + "黄色菜叶多说明生长周期长,主要是大白菜生长时间越长,黄色菜叶越多,说明长势很好,包的也瓷实。\n" + + "黄色菜叶多说明农家肥用得多。一般来说,农家肥种的白菜个头大,菜瓷实,黄色菜叶比较多,吃起来口感也要好一些。颜色发绿的白菜叶片厚实,吃起来口感比较粗,特别耐储存。\n" + ), + Post( + 5, + 2, + "关于西瓜的挑选经验", + R.drawable.watermelon, + labels = arrayListOf("西瓜", "经验"), + "1、看脐圈: 西瓜底部的脐圈,小、圆而且略微凹陷的西瓜,一般生长时间充分,果实会更甜。\n" + + "2、辨颜色: 颜色最好挑青绿色,不要雾雾白白的。\n" + + "3、看纹路: 西瓜纹路整齐的,就是好瓜。\n" + + "4、看瓜蒂: 西瓜头,就是所谓的瓜蒂头,从蒂部的弯曲程度,一般可判断出是第一茬瓜还是第二茬瓜。 ...\n" + + "5、听声音: 将西瓜托在手里,手指轻轻敲,如果发出“咚、咚”的清脆声,并且托瓜的手有震动的感觉就是熟透的瓜,一般瓜味也会比较甜。" + ), + Post( + 6, + 3, + "生姜怎么挑选?", + R.drawable.ginger, + labels = arrayListOf("生姜", "提问"), + "有没有好心人教教如何挑选生姜,大的和小的有什么区别" + ), + Post( + 1, + 1, + "白菜怎么挑选", + R.drawable.cabbage, + labels = arrayListOf("挑选方法", "白菜"), + "大白菜一般菜心是黄色的,越往外菜叶绿色逐渐增多,黄色菜叶越多,大白菜越好吃。\n" + + "黄色菜叶多说明生长周期长,主要是大白菜生长时间越长,黄色菜叶越多,说明长势很好,包的也瓷实。\n" + + "黄色菜叶多说明农家肥用得多。一般来说,农家肥种的白菜个头大,菜瓷实,黄色菜叶比较多,吃起来口感也要好一些。颜色发绿的白菜叶片厚实,吃起来口感比较粗,特别耐储存。\n" + ), + Post( + 2, + 2, + "关于西瓜的挑选经验", + R.drawable.watermelon, + labels = arrayListOf("西瓜", "经验"), + "1、看脐圈: 西瓜底部的脐圈,小、圆而且略微凹陷的西瓜,一般生长时间充分,果实会更甜。\n" + + "2、辨颜色: 颜色最好挑青绿色,不要雾雾白白的。\n" + + "3、看纹路: 西瓜纹路整齐的,就是好瓜。\n" + + "4、看瓜蒂: 西瓜头,就是所谓的瓜蒂头,从蒂部的弯曲程度,一般可判断出是第一茬瓜还是第二茬瓜。 ...\n" + + "5、听声音: 将西瓜托在手里,手指轻轻敲,如果发出“咚、咚”的清脆声,并且托瓜的手有震动的感觉就是熟透的瓜,一般瓜味也会比较甜。" + ), + Post( + 3, + 3, + "生姜怎么挑选?", + R.drawable.ginger, + labels = arrayListOf("生姜", "提问"), + "有没有好心人教教如何挑选生姜,大的和小的有什么区别" + ), + Post( + 4, + 1, + "白菜怎么挑选", + R.drawable.cabbage, + labels = arrayListOf("挑选方法", "白菜"), + "大白菜一般菜心是黄色的,越往外菜叶绿色逐渐增多,黄色菜叶越多,大白菜越好吃。\n" + + "黄色菜叶多说明生长周期长,主要是大白菜生长时间越长,黄色菜叶越多,说明长势很好,包的也瓷实。\n" + + "黄色菜叶多说明农家肥用得多。一般来说,农家肥种的白菜个头大,菜瓷实,黄色菜叶比较多,吃起来口感也要好一些。颜色发绿的白菜叶片厚实,吃起来口感比较粗,特别耐储存。\n" + ), + Post( + 5, + 2, + "关于西瓜的挑选经验", + R.drawable.watermelon, + labels = arrayListOf("西瓜", "经验"), + "1、看脐圈: 西瓜底部的脐圈,小、圆而且略微凹陷的西瓜,一般生长时间充分,果实会更甜。\n" + + "2、辨颜色: 颜色最好挑青绿色,不要雾雾白白的。\n" + + "3、看纹路: 西瓜纹路整齐的,就是好瓜。\n" + + "4、看瓜蒂: 西瓜头,就是所谓的瓜蒂头,从蒂部的弯曲程度,一般可判断出是第一茬瓜还是第二茬瓜。 ...\n" + + "5、听声音: 将西瓜托在手里,手指轻轻敲,如果发出“咚、咚”的清脆声,并且托瓜的手有震动的感觉就是熟透的瓜,一般瓜味也会比较甜。" + ), + Post( + 6, + 3, + "生姜怎么挑选?", + R.drawable.ginger, + labels = arrayListOf("生姜", "提问"), + "有没有好心人教教如何挑选生姜,大的和小的有什么区别" + ), + Post( + 1, + 1, + "白菜怎么挑选", + R.drawable.cabbage, + labels = arrayListOf("挑选方法", "白菜"), + "大白菜一般菜心是黄色的,越往外菜叶绿色逐渐增多,黄色菜叶越多,大白菜越好吃。\n" + + "黄色菜叶多说明生长周期长,主要是大白菜生长时间越长,黄色菜叶越多,说明长势很好,包的也瓷实。\n" + + "黄色菜叶多说明农家肥用得多。一般来说,农家肥种的白菜个头大,菜瓷实,黄色菜叶比较多,吃起来口感也要好一些。颜色发绿的白菜叶片厚实,吃起来口感比较粗,特别耐储存。\n" + ), + Post( + 2, + 2, + "关于西瓜的挑选经验", + R.drawable.watermelon, + labels = arrayListOf("西瓜", "经验"), + "1、看脐圈: 西瓜底部的脐圈,小、圆而且略微凹陷的西瓜,一般生长时间充分,果实会更甜。\n" + + "2、辨颜色: 颜色最好挑青绿色,不要雾雾白白的。\n" + + "3、看纹路: 西瓜纹路整齐的,就是好瓜。\n" + + "4、看瓜蒂: 西瓜头,就是所谓的瓜蒂头,从蒂部的弯曲程度,一般可判断出是第一茬瓜还是第二茬瓜。 ...\n" + + "5、听声音: 将西瓜托在手里,手指轻轻敲,如果发出“咚、咚”的清脆声,并且托瓜的手有震动的感觉就是熟透的瓜,一般瓜味也会比较甜。" + ), + Post( + 3, + 3, + "生姜怎么挑选?", + R.drawable.ginger, + labels = arrayListOf("生姜", "提问"), + "有没有好心人教教如何挑选生姜,大的和小的有什么区别" + ), + Post( + 4, + 1, + "白菜怎么挑选", + R.drawable.cabbage, + labels = arrayListOf("挑选方法", "白菜"), + "大白菜一般菜心是黄色的,越往外菜叶绿色逐渐增多,黄色菜叶越多,大白菜越好吃。\n" + + "黄色菜叶多说明生长周期长,主要是大白菜生长时间越长,黄色菜叶越多,说明长势很好,包的也瓷实。\n" + + "黄色菜叶多说明农家肥用得多。一般来说,农家肥种的白菜个头大,菜瓷实,黄色菜叶比较多,吃起来口感也要好一些。颜色发绿的白菜叶片厚实,吃起来口感比较粗,特别耐储存。\n" + ), + Post( + 5, + 2, + "关于西瓜的挑选经验", + R.drawable.watermelon, + labels = arrayListOf("西瓜", "经验"), + "1、看脐圈: 西瓜底部的脐圈,小、圆而且略微凹陷的西瓜,一般生长时间充分,果实会更甜。\n" + + "2、辨颜色: 颜色最好挑青绿色,不要雾雾白白的。\n" + + "3、看纹路: 西瓜纹路整齐的,就是好瓜。\n" + + "4、看瓜蒂: 西瓜头,就是所谓的瓜蒂头,从蒂部的弯曲程度,一般可判断出是第一茬瓜还是第二茬瓜。 ...\n" + + "5、听声音: 将西瓜托在手里,手指轻轻敲,如果发出“咚、咚”的清脆声,并且托瓜的手有震动的感觉就是熟透的瓜,一般瓜味也会比较甜。" + ), + Post( + 6, + 3, + "生姜怎么挑选?", + R.drawable.ginger, + labels = arrayListOf("生姜", "提问"), + "有没有好心人教教如何挑选生姜,大的和小的有什么区别" + ) + ) +} \ No newline at end of file diff --git a/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/ui/ImgRecognitionPage.kt b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/ui/ImgRecognitionPage.kt new file mode 100644 index 0000000..132bbe1 --- /dev/null +++ b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/ui/ImgRecognitionPage.kt @@ -0,0 +1,2 @@ +package com.example.fruitandvegetableguide.ui + diff --git a/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/ui/LoginActivity.kt b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/ui/LoginActivity.kt new file mode 100644 index 0000000..32212cf --- /dev/null +++ b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/ui/LoginActivity.kt @@ -0,0 +1,397 @@ +@file:OptIn(ExperimentalMaterial3Api::class) + +package com.example.fruitandvegetableguide.ui + +import android.content.Intent +import android.os.Bundle +import android.widget.Toast +import androidx.activity.compose.setContent +import androidx.appcompat.app.AppCompatActivity +import androidx.compose.foundation.Image +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.AccountBox +import androidx.compose.material.icons.filled.Lock +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.material3.TextField +import androidx.compose.material3.TextFieldDefaults +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.input.PasswordVisualTransformation +import androidx.compose.ui.text.input.VisualTransformation +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import com.example.fruitandvegetableguide.R +import com.example.fruitandvegetableguide.data.local.LocalAccountsDataProvider +import com.example.fruitandvegetableguide.ui.theme.FruitandVegetableGuideTheme + +class LoginActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContent { + FruitandVegetableGuideTheme() { + Surface( + modifier = Modifier.fillMaxSize(), + color = MaterialTheme.colorScheme.background + ) { + var username by remember { mutableStateOf("") } + var password by remember { mutableStateOf("") } + val pwdVisualTransformation = PasswordVisualTransformation() + var showPwd by remember { mutableStateOf(true) } + + val transformation = + if (showPwd) pwdVisualTransformation else VisualTransformation.None + Box(modifier = Modifier.fillMaxSize()) { + Text( + text = "注册", + fontSize = 20.sp, + textAlign = TextAlign.End, + modifier = Modifier + .fillMaxWidth() + .padding(20.dp) + ) + Column() { + Spacer(modifier = Modifier.weight(1f)) + Column( + modifier = Modifier + .weight(3f) + .background(Color.White) + .padding(40.dp) + .fillMaxWidth(), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center + ) { + Column { + TextField( + modifier = Modifier.fillMaxWidth(), + value = username, + onValueChange = { str -> username = str }, + placeholder = { + Text("账号") + }, + colors = TextFieldDefaults.colors(focusedTextColor = Color.Black), + leadingIcon = { + Icon( + imageVector = Icons.Default.AccountBox, + contentDescription = null + ) + } + ) + TextField( + value = password, + onValueChange = { str -> password = str }, + modifier = Modifier.fillMaxWidth(), + placeholder = { + Text("密码") + }, + visualTransformation = transformation, + colors = TextFieldDefaults.colors(focusedTextColor = Color.Black), + leadingIcon = { + Icon( + imageVector = Icons.Default.Lock, + contentDescription = null + ) + }, + trailingIcon = { + if (showPwd) { + IconButton(onClick = { showPwd = !showPwd }) { + Icon( + painter = painterResource(id = R.drawable.sleep), + contentDescription = null, + Modifier.size(30.dp) + ) + } + } else { + IconButton(onClick = { showPwd = !showPwd }) { + Icon( + painter = painterResource(id = R.drawable.eye), + contentDescription = null, + Modifier.size(30.dp) + ) + } + } + } + ) + } + Spacer(modifier = Modifier.height(20.dp)) + Row( + horizontalArrangement = Arrangement.SpaceBetween, + modifier = Modifier.fillMaxWidth() + ) { + Text(text = "快捷登录", fontSize = 16.sp, color = Color.Gray) + Text(text = "忘记密码", fontSize = 16.sp, color = Color.Gray) + } + Spacer(modifier = Modifier.height(20.dp)) + Row( + horizontalArrangement = Arrangement.Center, + verticalAlignment = Alignment.CenterVertically + ) { + Button( + onClick = { + // TODO 2.此处由验证结果实现页面跳转 + if (loginVerification(username, password)) { + Toast.makeText( + this@LoginActivity, + "登陆成功", + Toast.LENGTH_SHORT + ).show() + val intent = Intent( + this@LoginActivity, + MainActivity::class.java + ) + startActivity(intent) + } + else{ + Toast.makeText( + this@LoginActivity, + "登陆失败", + Toast.LENGTH_SHORT + ).show() + } + }, + colors = ButtonDefaults.buttonColors( + containerColor = Color( + 0xff5c59fe + ) + ), + contentPadding = PaddingValues(12.dp, 16.dp) + ) { + Text("登录", color = Color.White, fontSize = 18.sp) + } + } + Spacer(modifier = Modifier.height(100.dp)) + Column( + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center + ) { + Row( + Modifier + .background(Color(0xFFCFC5C5)) + .padding(end = 10.dp) + ) {} + Spacer(modifier = Modifier.height(20.dp)) + Text(text = "第三方登录", fontSize = 16.sp, color = Color.Gray) + Row( + Modifier + .fillMaxWidth() + .weight(1f), + horizontalArrangement = Arrangement.Center, + verticalAlignment = Alignment.Top + ) { + repeat(3) { + Column( + Modifier.weight(1f), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + Image( + modifier = Modifier.size(50.dp), + painter = painterResource(id = R.drawable.qq), + contentDescription = null + ) + Text( + "QQ", + color = Color(0xffcdcdcd), + fontSize = 16.sp, + fontWeight = FontWeight.Bold + ) + } + } + } + } + } + } + } + } + } + } + } +} + +private fun loginVerification(username: String, password: String): Boolean { + // TODO 1.此处需要完成登录验证的相关代码 + return username == LocalAccountsDataProvider.allUserAccounts[0].username && password == LocalAccountsDataProvider.allUserAccounts[0].password +} + +@Composable +fun LoginForm() { + var username by remember { mutableStateOf("") } + var password by remember { mutableStateOf("") } + val pwdVisualTransformation = PasswordVisualTransformation() + var showPwd by remember { mutableStateOf(true) } + + val transformation = if (showPwd) pwdVisualTransformation else VisualTransformation.None + + Box(modifier = Modifier.fillMaxSize()) { + Text( + text = "注册", + fontSize = 20.sp, + textAlign = TextAlign.End, + modifier = Modifier + .fillMaxWidth() + .padding(20.dp) + ) + Column() { + Spacer(modifier = Modifier.weight(1f)) + Column( + modifier = Modifier + .weight(3f) + .background(Color.White) + .padding(40.dp) + .fillMaxWidth(), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center + ) { + Column { + TextField( + modifier = Modifier.fillMaxWidth(), + value = username, + onValueChange = { str -> username = str }, + placeholder = { + Text("账号") + }, + colors = TextFieldDefaults.colors(focusedTextColor = Color.Transparent), + leadingIcon = { + Icon( + imageVector = Icons.Default.AccountBox, + contentDescription = null + ) + } + ) + TextField( + value = password, + onValueChange = { str -> password = str }, + modifier = Modifier.fillMaxWidth(), + placeholder = { + Text("密码") + }, + visualTransformation = transformation, + colors = TextFieldDefaults.colors(focusedTextColor = Color.Transparent), + leadingIcon = { + Icon( + imageVector = Icons.Default.Lock, + contentDescription = null + ) + }, + trailingIcon = { + if (showPwd) { + IconButton(onClick = { showPwd = !showPwd }) { + Icon( + painter = painterResource(id = R.drawable.sleep), + contentDescription = null, + Modifier.size(30.dp) + ) + } + } else { + IconButton(onClick = { showPwd = !showPwd }) { + Icon( + painter = painterResource(id = R.drawable.eye), + contentDescription = null, + Modifier.size(30.dp) + ) + } + } + } + ) + } + Spacer(modifier = Modifier.height(20.dp)) + Row( + horizontalArrangement = Arrangement.SpaceBetween, + modifier = Modifier.fillMaxWidth() + ) { + Text(text = "快捷登录", fontSize = 16.sp, color = Color.Gray) + Text(text = "忘记密码", fontSize = 16.sp, color = Color.Gray) + } + Spacer(modifier = Modifier.height(20.dp)) + Row( + horizontalArrangement = Arrangement.Center, + verticalAlignment = Alignment.CenterVertically + ) { + Button( + onClick = { +// TODO 2.此处由验证结果实现页面跳转 + }, + colors = ButtonDefaults.buttonColors(containerColor = Color(0xff5c59fe)), + contentPadding = PaddingValues(12.dp, 16.dp) + ) { + Text("登录", color = Color.White, fontSize = 18.sp) + } + } + Spacer(modifier = Modifier.height(100.dp)) + Column( + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center + ) { + Row( + Modifier + .background(Color(0xFFCFC5C5)) + .padding(end = 10.dp) + ) {} + Spacer(modifier = Modifier.height(20.dp)) + Text(text = "第三方登录", fontSize = 16.sp, color = Color.Gray) + Row( + Modifier + .fillMaxWidth() + .weight(1f), + horizontalArrangement = Arrangement.Center, + verticalAlignment = Alignment.Top + ) { + repeat(3) { + Column( + Modifier.weight(1f), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + Image( + modifier = Modifier.size(50.dp), + painter = painterResource(id = R.drawable.qq), + contentDescription = null + ) + Text( + "QQ", + color = Color(0xffcdcdcd), + fontSize = 16.sp, + fontWeight = FontWeight.Bold + ) + } + } + } + } + } + } + } +} + +@Preview +@Composable +fun Login() { + LoginForm() +} diff --git a/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/ui/MainActivity.kt b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/ui/MainActivity.kt new file mode 100644 index 0000000..d56ae2a --- /dev/null +++ b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/ui/MainActivity.kt @@ -0,0 +1,250 @@ +package com.example.fruitandvegetableguide.ui + +import android.os.Bundle +import androidx.activity.compose.setContent +import androidx.annotation.DrawableRes +import androidx.appcompat.app.AppCompatActivity +import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.paddingFromBaseline +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.lazy.grid.GridCells +import androidx.compose.foundation.lazy.grid.LazyHorizontalGrid +import androidx.compose.foundation.lazy.grid.items +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.foundation.verticalScroll +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.AccountCircle +import androidx.compose.material.icons.filled.Camera +import androidx.compose.material.icons.filled.Search +import androidx.compose.material.icons.filled.Spa +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.NavigationBar +import androidx.compose.material3.NavigationBarItem +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.material3.TextField +import androidx.compose.material3.TextFieldDefaults +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import com.example.fruitandvegetableguide.data.local.LocalGuidesDataProvider.allGuides +import com.example.fruitandvegetableguide.data.local.LocalPostsDataProvider.allPosts +import com.example.fruitandvegetableguide.ui.theme.FruitandVegetableGuideTheme + +class MainActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContent { + FruitandVegetableGuideTheme() { + Surface( + modifier = Modifier.fillMaxSize(), + color = MaterialTheme.colorScheme.background + ) { + MainPage() + } + } + } + } +} + +//主页 +@Composable +fun MainPage() { + FruitandVegetableGuideTheme() { + Scaffold(bottomBar = { MyBottomNavigation() }) { padding -> + HomeScreen(modifier = Modifier.padding(padding)) + } + } +} + +//主屏幕 +@Composable +fun HomeScreen(modifier: Modifier = Modifier) { + Column(modifier.verticalScroll(rememberScrollState())) { + Spacer(modifier = Modifier.height(16.dp)) + SearchBar(Modifier.padding(horizontal = 16.dp)) + HomeSection(title = "指南") { + GuideRow() + } + HomeSection(title = "社区") { + PostGrid() + } + Spacer(modifier = Modifier.height(16.dp)) + } +} + +//搜索框 +@Composable +fun SearchBar(modifier: Modifier = Modifier) { + TextField( + value = "", onValueChange = {}, + leadingIcon = { Icon(imageVector = Icons.Default.Search, contentDescription = null) }, + colors = TextFieldDefaults.colors( + unfocusedContainerColor = MaterialTheme.colorScheme.surface, + focusedContainerColor = MaterialTheme.colorScheme.surface + ), + placeholder = { Text(text = "搜索") }, + modifier = modifier + .fillMaxWidth() + .heightIn(56.dp) + ) +} + +//指南元素 +@Composable +fun GuideElement( + modifier: Modifier = Modifier, + @DrawableRes drawable: Int, + kind: String +) { + Column( + modifier = modifier, + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Image( + painter = painterResource(id = drawable), + contentDescription = null, + contentScale = ContentScale.Crop, + modifier = Modifier + .size(88.dp) + .clip(CircleShape) + ) + Text( + text = kind, + modifier = Modifier.paddingFromBaseline(top = 24.dp, bottom = 8.dp), + style = MaterialTheme.typography.bodyMedium + ) + } +} + +//帖子元素 +@Composable +fun PostCard( + modifier: Modifier = Modifier, + @DrawableRes drawable: Int, + title: String +) { + Surface( + shape = MaterialTheme.shapes.medium, + modifier = modifier, + color = MaterialTheme.colorScheme.surfaceVariant, + ) { + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier.width(255.dp) + ) { + Image( + painter = painterResource(id = drawable), contentDescription = null, + contentScale = ContentScale.Crop, + modifier = Modifier.size(80.dp) + ) + Text( + text = title, + style = MaterialTheme.typography.titleMedium, + modifier = Modifier.padding(horizontal = 16.dp) + ) + } + } +} + +//指南的网格显示 +@Composable +fun GuideRow(modifier: Modifier = Modifier) { + LazyHorizontalGrid( + rows = GridCells.Fixed(2), + contentPadding = PaddingValues(horizontal = 16.dp), + horizontalArrangement = Arrangement.spacedBy(8.dp), + verticalArrangement = Arrangement.spacedBy(16.dp), + modifier = modifier.height(240.dp) + ) { + items(allGuides) { item -> GuideElement(drawable = item.imgId, kind = item.kind) } + } +} + +//帖子的网格显示 +@Composable +fun PostGrid(modifier: Modifier = Modifier) { + LazyHorizontalGrid( + rows = GridCells.Fixed(4), + contentPadding = PaddingValues(horizontal = 16.dp), + horizontalArrangement = Arrangement.spacedBy(16.dp), + verticalArrangement = Arrangement.spacedBy(16.dp), + modifier = modifier.height(288.dp) + ) { + items(allPosts) { item -> PostCard(drawable = item.imgId, title = item.title) } + } +} + +//小组件加上标题 +@Composable +fun HomeSection(title: String, modifier: Modifier = Modifier, content: @Composable () -> Unit) { + Column(modifier) { + Text( + text = title, + style = MaterialTheme.typography.titleMedium, + modifier = Modifier + .paddingFromBaseline(top = 40.dp, bottom = 16.dp) + .padding(horizontal = 16.dp) + ) + content() + } +} + +//底部导航栏 +@Composable +fun MyBottomNavigation(modifier: Modifier = Modifier) { + NavigationBar(containerColor = MaterialTheme.colorScheme.surfaceVariant, modifier = modifier) { + NavigationBarItem(icon = { + Icon( + imageVector = Icons.Default.Spa, + contentDescription = null + ) + }, + label = { Text(text = "首页") }, + selected = true, + onClick = { /*TODO*/ }) + NavigationBarItem(icon = { + Icon( + imageVector = Icons.Default.Camera, + contentDescription = null + ) + }, + label = { Text(text = "识别")}, + selected = false, + onClick = { /*TODO*/ }) + NavigationBarItem(icon = { + Icon( + imageVector = Icons.Default.AccountCircle, + contentDescription = null + ) + }, label = { Text(text = "用户") }, + selected = false, + onClick = { /*TODO*/ }) + } +} + +//预览 +@Preview(showBackground = true, backgroundColor = 0xFFF5F0EE) +@Composable +fun PostPrev() { + MainPage() +} diff --git a/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/ui/theme/Color.kt b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/ui/theme/Color.kt new file mode 100644 index 0000000..1cbfd8c --- /dev/null +++ b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/ui/theme/Color.kt @@ -0,0 +1,11 @@ +package com.example.fruitandvegetableguide.ui.theme + +import androidx.compose.ui.graphics.Color + +val Purple80 = Color(0xFFD0BCFF) +val PurpleGrey80 = Color(0xFFCCC2DC) +val Pink80 = Color(0xFFEFB8C8) + +val Purple40 = Color(0xFF6650a4) +val PurpleGrey40 = Color(0xFF625b71) +val Pink40 = Color(0xFF7D5260) \ No newline at end of file diff --git a/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/ui/theme/Theme.kt b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/ui/theme/Theme.kt new file mode 100644 index 0000000..3b9c4bc --- /dev/null +++ b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/ui/theme/Theme.kt @@ -0,0 +1,70 @@ +package com.example.fruitandvegetableguide.ui.theme + +import android.app.Activity +import android.os.Build +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable +import androidx.compose.runtime.SideEffect +import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalView +import androidx.core.view.WindowCompat + +private val DarkColorScheme = darkColorScheme( + primary = Purple80, + secondary = PurpleGrey80, + tertiary = Pink80 +) + +private val LightColorScheme = lightColorScheme( + primary = Purple40, + secondary = PurpleGrey40, + tertiary = Pink40 + + /* Other default colors to override + background = Color(0xFFFFFBFE), + surface = Color(0xFFFFFBFE), + onPrimary = Color.White, + onSecondary = Color.White, + onTertiary = Color.White, + onBackground = Color(0xFF1C1B1F), + onSurface = Color(0xFF1C1B1F), + */ +) + +@Composable +fun FruitandVegetableGuideTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + // Dynamic color is available on Android 12+ + dynamicColor: Boolean = true, + content: @Composable () -> Unit +) { + val colorScheme = when { + dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { + val context = LocalContext.current + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + } + + darkTheme -> DarkColorScheme + else -> LightColorScheme + } + val view = LocalView.current + if (!view.isInEditMode) { + SideEffect { + val window = (view.context as Activity).window + window.statusBarColor = colorScheme.primary.toArgb() + WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme + } + } + + MaterialTheme( + colorScheme = colorScheme, + typography = Typography, + content = content + ) +} \ No newline at end of file diff --git a/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/ui/theme/Type.kt b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/ui/theme/Type.kt new file mode 100644 index 0000000..0d59622 --- /dev/null +++ b/src/FruitandVegetableGuide/app/src/main/java/com/example/fruitandvegetableguide/ui/theme/Type.kt @@ -0,0 +1,34 @@ +package com.example.fruitandvegetableguide.ui.theme + +import androidx.compose.material3.Typography +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp + +// Set of Material typography styles to start with +val Typography = Typography( + bodyLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + lineHeight = 24.sp, + letterSpacing = 0.5.sp + ) + /* Other default text styles to override + titleLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 22.sp, + lineHeight = 28.sp, + letterSpacing = 0.sp + ), + labelSmall = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 11.sp, + lineHeight = 16.sp, + letterSpacing = 0.5.sp + ) + */ +) \ No newline at end of file diff --git a/src/FruitandVegetableGuide/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/src/FruitandVegetableGuide/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/src/FruitandVegetableGuide/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/FruitandVegetableGuide/app/src/main/res/drawable/cabbage.png b/src/FruitandVegetableGuide/app/src/main/res/drawable/cabbage.png new file mode 100644 index 0000000..2ce6663 Binary files /dev/null and b/src/FruitandVegetableGuide/app/src/main/res/drawable/cabbage.png differ diff --git a/src/FruitandVegetableGuide/app/src/main/res/drawable/carrots.png b/src/FruitandVegetableGuide/app/src/main/res/drawable/carrots.png new file mode 100644 index 0000000..b869c2b Binary files /dev/null and b/src/FruitandVegetableGuide/app/src/main/res/drawable/carrots.png differ diff --git a/src/FruitandVegetableGuide/app/src/main/res/drawable/cucumbers.png b/src/FruitandVegetableGuide/app/src/main/res/drawable/cucumbers.png new file mode 100644 index 0000000..9c5aee1 Binary files /dev/null and b/src/FruitandVegetableGuide/app/src/main/res/drawable/cucumbers.png differ diff --git a/src/FruitandVegetableGuide/app/src/main/res/drawable/eye.png b/src/FruitandVegetableGuide/app/src/main/res/drawable/eye.png new file mode 100644 index 0000000..5defa1b Binary files /dev/null and b/src/FruitandVegetableGuide/app/src/main/res/drawable/eye.png differ diff --git a/src/FruitandVegetableGuide/app/src/main/res/drawable/ginger.png b/src/FruitandVegetableGuide/app/src/main/res/drawable/ginger.png new file mode 100644 index 0000000..bf4e13b Binary files /dev/null and b/src/FruitandVegetableGuide/app/src/main/res/drawable/ginger.png differ diff --git a/src/FruitandVegetableGuide/app/src/main/res/drawable/ic_launcher_background.xml b/src/FruitandVegetableGuide/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/src/FruitandVegetableGuide/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/FruitandVegetableGuide/app/src/main/res/drawable/qq.xml b/src/FruitandVegetableGuide/app/src/main/res/drawable/qq.xml new file mode 100644 index 0000000..fb9fd6a --- /dev/null +++ b/src/FruitandVegetableGuide/app/src/main/res/drawable/qq.xml @@ -0,0 +1,9 @@ + + + diff --git a/src/FruitandVegetableGuide/app/src/main/res/drawable/sleep.xml b/src/FruitandVegetableGuide/app/src/main/res/drawable/sleep.xml new file mode 100644 index 0000000..9746c69 --- /dev/null +++ b/src/FruitandVegetableGuide/app/src/main/res/drawable/sleep.xml @@ -0,0 +1,24 @@ + + + + + + + + diff --git a/src/FruitandVegetableGuide/app/src/main/res/drawable/tomatoes.png b/src/FruitandVegetableGuide/app/src/main/res/drawable/tomatoes.png new file mode 100644 index 0000000..8721fcb Binary files /dev/null and b/src/FruitandVegetableGuide/app/src/main/res/drawable/tomatoes.png differ diff --git a/src/FruitandVegetableGuide/app/src/main/res/drawable/watermelon.png b/src/FruitandVegetableGuide/app/src/main/res/drawable/watermelon.png new file mode 100644 index 0000000..136f09b Binary files /dev/null and b/src/FruitandVegetableGuide/app/src/main/res/drawable/watermelon.png differ diff --git a/src/FruitandVegetableGuide/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/src/FruitandVegetableGuide/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/src/FruitandVegetableGuide/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/FruitandVegetableGuide/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/src/FruitandVegetableGuide/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/src/FruitandVegetableGuide/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/FruitandVegetableGuide/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/src/FruitandVegetableGuide/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000..c209e78 Binary files /dev/null and b/src/FruitandVegetableGuide/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/src/FruitandVegetableGuide/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/src/FruitandVegetableGuide/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 0000000..b2dfe3d Binary files /dev/null and b/src/FruitandVegetableGuide/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/src/FruitandVegetableGuide/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/src/FruitandVegetableGuide/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000..4f0f1d6 Binary files /dev/null and b/src/FruitandVegetableGuide/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/src/FruitandVegetableGuide/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/src/FruitandVegetableGuide/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 0000000..62b611d Binary files /dev/null and b/src/FruitandVegetableGuide/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/src/FruitandVegetableGuide/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/src/FruitandVegetableGuide/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000..948a307 Binary files /dev/null and b/src/FruitandVegetableGuide/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/src/FruitandVegetableGuide/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/src/FruitandVegetableGuide/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..1b9a695 Binary files /dev/null and b/src/FruitandVegetableGuide/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/src/FruitandVegetableGuide/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/src/FruitandVegetableGuide/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 0000000..28d4b77 Binary files /dev/null and b/src/FruitandVegetableGuide/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/src/FruitandVegetableGuide/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/src/FruitandVegetableGuide/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9287f50 Binary files /dev/null and b/src/FruitandVegetableGuide/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/src/FruitandVegetableGuide/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/src/FruitandVegetableGuide/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 0000000..aa7d642 Binary files /dev/null and b/src/FruitandVegetableGuide/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/src/FruitandVegetableGuide/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/src/FruitandVegetableGuide/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9126ae3 Binary files /dev/null and b/src/FruitandVegetableGuide/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/src/FruitandVegetableGuide/app/src/main/res/values/colors.xml b/src/FruitandVegetableGuide/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..f8c6127 --- /dev/null +++ b/src/FruitandVegetableGuide/app/src/main/res/values/colors.xml @@ -0,0 +1,10 @@ + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/src/FruitandVegetableGuide/app/src/main/res/values/strings.xml b/src/FruitandVegetableGuide/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..ee94730 --- /dev/null +++ b/src/FruitandVegetableGuide/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + FruitandVegetableGuide + \ No newline at end of file diff --git a/src/FruitandVegetableGuide/app/src/main/res/values/themes.xml b/src/FruitandVegetableGuide/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..589b8ec --- /dev/null +++ b/src/FruitandVegetableGuide/app/src/main/res/values/themes.xml @@ -0,0 +1,5 @@ + + + +