diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.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/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml new file mode 100644 index 0000000..70f212e --- /dev/null +++ b/.idea/dbnavigator.xml @@ -0,0 +1,414 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..f22a539 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,13 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..639900d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..5e30ab0 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,51 @@ +plugins { + id 'com.android.application' +} + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.3" + + defaultConfig { + applicationId "com.example.food" + minSdkVersion 16 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'com.google.android.material:material:1.1.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + testImplementation 'junit:junit:4.+' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + //litepal + implementation 'org.litepal.android:core:1.6.1' + //glide图片加载框架 + implementation 'com.github.bumptech.glide:glide:4.11.0' + //recyclerview + implementation 'androidx.recyclerview:recyclerview:1.1.0' + compile 'com.google.code.gson:gson:2.7' + //网络请求 + implementation 'com.squareup.okhttp3:okhttp:4.4.0' + implementation 'com.squareup.okhttp3:logging-interceptor:4.4.0' + implementation 'com.zhy:okhttputils:2.0.0' //glide图片加载框架 + implementation 'com.github.bumptech.glide:glide:3.6.1' +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/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/app/src/androidTest/java/com/example/food/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/food/ExampleInstrumentedTest.java new file mode 100644 index 0000000..544b6f9 --- /dev/null +++ b/app/src/androidTest/java/com/example/food/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.food; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.food", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..d84ae1f --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/assets/db.json b/app/src/main/assets/db.json new file mode 100644 index 0000000..92b543b --- /dev/null +++ b/app/src/main/assets/db.json @@ -0,0 +1,327 @@ +{ + "fruit": [ + { + "typeId": 0, + "title": "水煮肉片", + "img": "https://st-cn.meishij.net/r/41/203/113291/s113291_154088128763034.jpg", + "content": "水煮肉片是一道汉族新创名菜,起源于自贡,由自贡名菜,水煮牛肉变来,发扬于西南,属于渝菜、川菜中著名的家常菜 。其起源于上世纪30年代, 自贡名厨范吉安(1887 -1982年),创新出风味突出的水煮肉片 。因肉片未经划油,以水煮熟故名水煮肉片。", + "issuer": "18.80", + "date": "2021-9-28 19:35:14" + }, + { + "typeId": 0, + "title": "白切鸡", + "img": "https://st-cn.meishij.net/r/41/203/113291/s113291_154337576945105.jpg", + "content": "无", + "issuer": "23.0", + "date": "2021-9-28 19:35:14" + }, + { + "typeId": 0, + "title": "辣子鸡丁", + "img": "https://st-cn.meishij.net/r/41/203/113291/s113291_154338772988443.jpg", + "content": "辣子鸡丁,鲜香麻辣~", + "issuer": "28.00", + "date": "2021-9-28 19:35:14" + }, + { + "typeId": 0, + "title": "宫保鸡丁", + "img": "https://st-cn.meishij.net/r/207/11/9502957/s9502957_151304147951837.jpg", + "content": "一盘酥香,略带微辣、咸鲜、微甜、微酸的宫保鸡丁出炉啦", + "issuer": "30.80", + "date": "2021-9-28 19:35:14" + }, + { + "typeId": 0, + "title": "川味干锅鸡翅", + "img": "https://st-cn.meishij.net/r/141/154/4351141/s4351141_150509718716126.jpg", + "content": "\n青椒、五花肉、土豆、花椒、姜片、蒜头、干辣椒、生抽、老抽、鸡精、糖", + "issuer": "20.80", + "date": "2021-9-28 19:35:14" + }, + { + "typeId": 0, + "title": "经典川菜【麻婆豆腐】", + "img": "https://ali.xinshipu.cn/20170204/original/1486196929827.jpg@196w_126h_99q_1e_1c.jpg", + "content": "鸡翅用黄酒、生抽、蒜蓉、姜茸、盐腌制半个小时左右", + "issuer": "23.00", + "date": "2021-9-28 19:35:14" + }, + { + "typeId": 1, + "title": "蓑衣黄瓜", + "img": "https://st-cn.meishij.net/r/147/198/4174647/s4174647_150943807386688.jpg", + "content": "黄瓜我通常都喜欢切成小块,或拍碎凉拌着吃。然而,今天心血来潮,想换个花样,于是便试做了这道地方名菜-蓑衣黄瓜,没想到竟一次成功,特别有成就感。", + "issuer": "12.80", + "date": "2021-9-28 19:35:1 4" + }, + { + "typeId": 1, + "title": "赛螃蟹", + "img": "https://st-cn.meishij.net/r/41/203/113291/s113291_154338475808551.jpg", + "content": "无", + "issuer": "25.50", + "date": "2021-9-28 19:35:14" + }, + { + "typeId": 1, + "title": "红烧鲤鱼", + "img": "https://st-cn.meishij.net/r/08/75/3768758/s3768758_142763265871365.jpg", + "content": "鱼收拾干净切花刀,抹上盐和料酒腌制10分钟", + "issuer": "18.20", + "date": "2021-9-28 19:35:14" + }, + { + "typeId": 1, + "title": "红烧排骨", + "img": "https://st-cn.meishij.net/r/08/75/3768758/s3768758_143164448562685.jpg", + "content": "倒入生抽,老抽,八角,桂皮,陈皮,香叶,炒出香味,加开水没过排骨,放入葱姜,大火烧开,小火炖1小时", + "issuer": "13.50", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 1, + "title": "葱烧海参", + "img": "https://st-cn.meishij.net/r/112/108/4089612/s4089612_145431725551281.jpg", + "content": "海参清鲜,柔软香滑,葱香味醇,食后无余汁,营养丰富,尤其对生殖功能作用突出,对促进性功能的提高很有帮助。另外,可以改善和调理女性内分泌,促进体内良性循环。因此,准备孕育下一代的夫妻,可以在受孕前三个月开始进行身体调理。", + "issuer": "25.50", + "date": "2021-9-28 19:35:14" + }, + { + "typeId": 2, + "title": "白切鸡", + "img": "https://st-cn.meishij.net/r/41/203/113291/s113291_154337576945105.jpg", + "content": "放蒜末、姜末、葱末、白砂糖、盐、生抽", + "issuer": "22.50", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 2, + "title": "梅菜扣肉", + "img": "https://st-cn.meishij.net/r/60/35/3321310/s3321310_154891634276312.jpg", + "content": "梅菜扣肉菜系来说应该算是广东的客家菜,但因其太过于好吃所以流传大家南北,也是不少家庭过年必做的硬菜之一,虽然做法不是很难,但因其制作略有些繁琐所以一般人平时都不愿意碰这个菜。我这道菜是刚学做饭那会跟一位广东网友学习的,此菜被此网友成为“超级大工程”自己尝试了之后觉得虽谈不上“超级”但也可谓之“大工程”,前前后后怎么也得两三个小时,虽然麻烦了点,但尝过之后就一个字“值”。自己家庭制作没有那么多所谓的“秘方调料”,吃的就是用时间带引出的食材本香,无肉不欢的你,不试试还等什么呢?", + "issuer": "27.80", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 2, + "title": "广东油鸡", + "img": "https://st-cn.meishij.net/r/41/203/113291/s113291_154338658073949.jpg", + "content": "\n鸡腿2只,水1/2杯,广东油鸡淋酱13杯", + "issuer": "25.80", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 2, + "title": "煲仔饭", + "img": "https://st-cn.meishij.net/r/41/203/113291/s113291_154089314708674.jpg", + "content": "无", + "issuer": "16.80", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 2, + "title": "小鸡炖蘑菇", + "img": "https://st-cn.meishij.net/r/118/144/6286118/s6286118_146857570754913.jpg", + "content": "儿时味道的经典再现,满满的回忆,融入到浓醇鲜美的味道之中,一缕缕感动在舌尖化开。", + "issuer": "20.80", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 3, + "title": "剁椒鱼头", + "img": "https://st-cn.meishij.net/r/246/212/8615746/s8615746_150003929415096.jpg", + "content": "鱼头中含有丰富的不饱和脂肪酸,对脑部的发育尤为重要,可使大脑细胞活跃,因此能极大增强推理,判断能力,常吃鱼头不仅可以健脑,还可以延缓脑力衰退。\n\n鱼头味美,易被人体消化和吸收,含脂肪较少,含有丰富的维生素A、维生素D和维生素K。尤其是富含两种不饱和脂肪酸:DHA和EPA,它们对清理和软化血管、降血脂以及健脑、延缓衰老都有好处。", + "issuer": "20.80", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 3, + "title": "蒸腊鱼", + "img": "https://st-cn.meishij.net/r/185/123/1655935/s1655935_18695.jpg", + "content": "还记得舌尖2三餐里湖南小夫妻解乡愁的那道蒸腊鱼么?虽然不是我的家乡菜,但是那份乡愁却是深深的感染到了我。家乡的味道,有种特殊的魔力,能让天各一方的家人,穿越时空,聚在一起。\n既然不是湘妹子,所以嗜辣程度也有限,我没有用湿的豆豉辣酱,而是用的罗定干豆豉,辣味减少,鲜香味增加。不过这腊鱼可是正宗的湖南腊鱼哦,值得一提的是,用电视上的方法处理腊鱼块,就是先浸泡,再焯烫,这样真的可以让很咸的腊鱼去掉大部分咸味,最后出来的成品咸淡适口,鱼肉干香又而不柴,这个方法值得一试哦。", + "issuer": "68.80", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 3, + "title": "酿烧青尖椒", + "img": "https://st-cn.meishij.net/r/150/78/3394650/s3394650_149849114659095.jpg", + "content": "这个是一个“酿青尖椒”在一次饭店吃到,我就喜欢上了。香 辣 醇的口感非常的美味,青尖椒是比较常见的炒制食材。它含有非常高的维生素C堪比柠檬,并且能开胃、促进食欲、降脂减肥、还具有预防癌症的作用,经常食用点对健康非常有帮助。", + "issuer": "28.80", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 3, + "title": "酸辣椒炒肉", + "img": "https://st-cn.meishij.net/r/97/32/4758097/s4758097_150520942704178.jpg", + "content": "酸辣椒采用新鲜的青嫩辣椒,用白醋、加点冰糖浸泡一个星期之后就可以食用。选择的辣椒要嫩,才不会辣,浸泡的时间不要太久,否则会很酸。辣椒尽量切小,让酸味散发出来,肉中融入,酸酸甜甜,开胃好吃。\n白醋具有美容、美白功效,浸泡过多白醋还能喝上一小口,味道酸酸甜甜,很不错。浸泡的酸辣椒也可以直接吃。选择不辣椒的辣椒才能直接吃,太辣的辣椒不建议吃。", + "issuer": "20.80", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 3, + "title": "全家福", + "img": "https://st-cn.meishij.net/r/137/202/3863137/s3863137_142806509977951.jpg", + "content": "一天接近尾声,走在行色匆匆的人群中,是不是有一刻,最想念的不是餐厅里的美味珍馐,而是记忆深处,那个属于家的味道,妈妈的味道。\n全家福是妈妈最爱做给我们吃的一道烩菜,温暖的背后,是妈妈对营养用心的搭配。今天尝试着也做一次,味道也许并不惊艳,但那熟悉的味道弥漫开来的时候,对心最为温暖的一击,这时,是离家最近的时刻。", + "issuer": "28.80", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 4, + "title": "红烧鱼块", + "img": "https://st-cn.meishij.net/r/41/203/113291/s113291_154337102842238.jpg", + "content": "鱼,每个人都喜欢吃的,也是每个人都吃过的,鱼总是带着家的味道,有着父亲的味道,我从小很爱吃鱼,父亲总是说“吃鱼会变聪明”,我现在知道他只是想让我吃掉那最后那一块没有刺滑嫩的鱼肉而已。鱼肉的营养价值十分丰富,鱼肉质细嫩,有温中益气、暖胃、润肌肤等功能,是温中补气养生食品。鱼肉脂肪含量低,供热能低,有益气养血,柔筋利骨等功能。鱼有暖胃和中平肝祛风等功能。", + "issuer": "28.80", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 4, + "title": "酱鸭腿", + "img": "https://st-cn.meishij.net/r/20/89/1272270/s1272270_142554525691812.jpg", + "content": "鸭腿的营养价值很高,可食部分鸭肉中的蛋白质含量16%一25%,比畜肉含量高得多。鸭腿肉蛋白质主要是肌浆蛋白和肌凝蛋白。另一部分是间质蛋白,其中含有溶于水的胶原蛋白和弹性蛋白,此外还有少量的明胶,其余为非蛋白氮。肉食含氮浸出物越多,味道越鲜美。鸭肉中含氮浸出物比畜肉多,所以鸭肉味美。老鸭肉的含氮浸出物比幼鸭肉多,野鸭内含氮浸出物更多,因此,老鸭的汤比幼鸭鲜美,野鸭滋味更比老鸭好。此外,烹调时,加入少量盐,能有效地溶出含氮浸出物,会获得更鲜美的肉汤。", + "issuer": "40.00", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 4, + "title": "胡萝卜丝饼", + "img": "https://st-cn.meishij.net/r/206/231/5120456/s5120456_147748643457600.jpg", + "content": "上大学的时候最爱吃的就是三食堂的饼,记得那个窗口有各种饼,葱花饼、手抓饼、掉渣饼、龙凤大饼、土豆丝饼、胡萝卜丝饼等,每一种都很好吃,其中最爱的就是胡萝卜丝饼,既有萝卜丝的清甜又有饼的鲜香,很是美味。毕业后,自己没少做这个饼,开始老拿捏不住食材的量,做出来总是差强人意,不过做过几次后就好了,面粉不需要加太多,主要就是萝卜丝,我自己比较喜欢香菜的香气,这次加入了香菜碎,真的要香掉牙了,胡萝卜丝和香菜一起竟然会这么好吃,太意外啦,哈哈,感觉赚到了,以后就要这么做。", + "issuer": "48.80", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 4, + "title": "清蒸大闸蟹", + "img": "https://st-cn.meishij.net/r/19/208/1364519/s1364519_44452.jpg", + "content": "味道很不错,一人干掉2只大闸蟹还嫌不够呢。", + "issuer": "28.80", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 4, + "title": "正宗盐水鸭", + "img": "https://st-cn.meishij.net/r/199/170/3917699/s3917699_142889626409737.jpg", + "content": "古都金陵(今南京),早在战国时期就有金陵人筑地养鸭的记载,可见当地人吃鸭肉已有上千年的历史。估计所有做鸭肉的方法,已经让南京人试了一遍了,但能保留到今天的,也就能数的上来那几种,“盐水鸭”便是其中经久不衰的一道菜。以前总是托同事给我带,想吃一次得等很久,现在用咱自动烹饪锅E15(E153/E152)型号也能做了,味道比当地买的还要好,以后随时都可以尝到“盐水鸭”。想想也是怪任性的,说了这么多,吊足了大家的胃口,也不能让各位失望,回家都试试,准备着春节露一手", + "issuer": "30.00", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 5, + "title": "烤肉", + "img": "https://st-cn.meishij.net/r/41/203/113291/s113291_154338548467834.jpg", + "content": "无", + "issuer": "28.80", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 5, + "title": "油焖大虾", + "img": "https://st-cn.meishij.net/r/139/60/2827639/s2827639_151556829530544.jpg", + "content": "鲁菜中的油焖大虾是鲁菜中的经典,成品色泽亮丽,味美鲜香,鲜嫩微甜,趁热吃,虾肉洁白细腻,让人胃口大开。作为生活在胶东半岛的人家,油焖大虾也是年夜饭必备的一道菜;", + "issuer": "28.80", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 5, + "title": "红焖羊肉", + "img": "https://st-cn.meishij.net/r/23/225/2118773/s2118773_142471761675876.jpg", + "content": "冬天吃羊肉可以驱寒保暖,但很多人不喜欢羊肉的那股膻味,可是把羊肉和萝卜搭配起来,萝卜的辣味刚好可以去除羊肉的膻味而且还能提鲜。中医认为羊肉与萝卜在一起有很好的食疗作用,羊肉含有丰富的动物蛋白,萝卜含有丰富的植物蛋白,两者可以互补,充分补充人体所需的蛋白质,并且羊肉较温热,而萝卜性寒凉,能两样东西一起组合,上火的人吃了不会咽喉肿痛,虚寒的人吃了也不会肠胃不适。不爱吃羊肉的小伙伴不防这样做羊肉试试,说不定会喜欢上羊肉哦。", + "issuer": "28.80", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 5, + "title": "酱牛肉", + "img": "https://st-cn.meishij.net/r/115/102/588115/s588115_149347346669780.jpg", + "content": "酱牛肉,肉质紧实 酱香浓郁,虽是一道传统年菜但依旧在上海人过年的餐桌上占据一席之地。个人觉得酱牛肉有点和红烧肉很相似,各家都有自己的一种味道,我们喜欢带有一丝甜味的酱牛肉,除了调味料外还可以加一点干辣椒来解腻去腥增味,菜品酱香浓郁,口味层次丰富,让人垂涎欲滴,欲罢不能", + "issuer": "28.80", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 5, + "title": "贵妃鸡翅", + "img": "https://st-cn.meishij.net/r/50/123/6030800/s6030800_155374584131082.jpg", + "content": "一提到鸡翅,是不是首先想到是可乐鸡翅?其实鸡翅的做法有很多种,并不仅限于可乐鸡翅,红烧鸡翅、清蒸鸡翅、剁椒鸡翅,还有贵妃鸡翅。相传杨贵妃最喜欢吃两种美食,第一是荔枝,第二就是鸡翅了。杨贵妃酷爱美食,在饮食上也是极为讲究,最爱吃鸡翅。宫廷御厨反复研究琢磨,新鲜鸡翅,选配多种调料,精心研制,做出了杨贵妃最喜欢吃的这道鸡翅。所以这道菜因杨贵妃而得名。这道贵妃鸡翅色泽红亮、软嫩爽滑、浓厚醇香,回味悠长。比可乐鸡翅要好吃100倍!", + "issuer": "28.80", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 6, + "title": "西湖醋鱼", + "img": "https://st-cn.meishij.net/r/41/203/113291/s113291_154338858269516.jpg", + "content": "江南美味", + "issuer": "28.80", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 6, + "title": "油焖春笋", + "img": "https://st-cn.meishij.net/r/246/109/4089996/s4089996_148768018789201.jpg", + "content": "笋含脂肪、淀粉很少,属天然低脂、低热量食品,是肥胖者减肥的佳品。养生学家认为,竹林丛生之地的人们多长寿,且极少患高血压,这与经常吃笋有一定关系。\n笋一年四季皆有,但惟有春笋、冬笋味道最佳。烹调时无论是凉拌、煎炒还是熬汤,均鲜嫩清香,是人们喜欢的佳肴之一。春笋含有充足的水分、丰富的植物蛋白,钙、磷、铁等人体必需的营养成分和微量元素。\n但是春笋中难溶性草酸钙含量较多,因此各种结石患者不宜多食。草酸也会影响人体对钙的吸收和利用,为防其弊,在食用笋时,应将它烧熟煮透,若用笋片、笋丁炒菜,也要先把笋用开水烫5-10分钟,然后再配其它食物炒食。这样既可因高温分解大部分草酸减少其弊,又能使菜肴无涩感,味道更鲜美。\n小时候,隔壁家邻居阿姨经常自己去山里挖一些很小的笋,然后做油焖笋,也时常给我家送一些。记得当时第一次吃到,觉得好好吃啊!颜色靓丽,口味鲜甜,至今想起来,那次的美味仿佛还在嘴边!", + "issuer": "28.80", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 6, + "title": "花雕酒蒸鸡", + "img": "https://st-cn.meishij.net/r/115/102/588115/s588115_153477246215536.jpg", + "content": "花雕清蒸鸡是我们这里的传统滋补菜,蒸制过程里面不加一滴水,无需用太多的调料,只需用盐、葱,姜,花雕酒,也不必担心会有浓烈的酒味,通过蒸制之后,早已散发,鸡肉鲜嫩,汤汁清澈醇厚,原汁原味的鲜美,滋补又养身。", + "issuer": "28.80", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 6, + "title": "桂花糯米藕", + "img": "https://st-cn.meishij.net/r/95/122/8905595/s8905595_148008095338853.jpg", + "content": "江浙菜品多以甜味为主,在上海呆了多年,桂花糯米藕基本是每次聚餐必点的菜品。秋冬莲藕上市,此时桂花飘香,选用莲藕加上糯米,辅以桂花蜜,软香甜糯,桂香浓郁,甜甜蜜蜜的味道老少皆宜。", + "issuer": "28.80", + "date": "2021-5-19 19:35:14" + }, + { + "typeId": 6, + "title": "小黄鱼烧豆腐", + "img": "https://st-cn.meishij.net/r/85/180/5045085/s5045085_145014288167252.jpg", + "content": "黄鱼含有丰富的蛋白质、矿物质和维生素,对人体有很好的补益作用", + "issuer": "28.80", + "date": "2021-5-19 19:35:14" + }, { + "typeId": 7, + "title": "红烧鳝鱼", + "img": "https://st-cn.meishij.net/r/41/203/113291/s113291_154468650537397.jpg", + "content": "无", + "issuer": "28.80", + "date": "2021-5-19 19:35:14" + }, { + "typeId": 7, + "title": "红烧狮子头", + "img": "https://st-cn.meishij.net/r/86/63/1640836/s1640836_151543003415109.jpg", + "content": "红烧狮子头,颜色红润,寓意着富贵团圆,摆上桌后整桌菜都显气派,而且还是一道非常美味的下饭下酒菜,赶紧来预热春节年菜吧。\n红烧狮子头是一道传统的苏菜,选用三肥七瘦的梅肉最好,肉要粗切细斩,才能保持肉中汁水的存在,做起来才入味,吃起来才松软,加一些荸荠碎和香菇碎,不但增加口感松嫩味道也更鲜香,而且最好选用干香菇味道才更浓郁,泡发香菇的水也千万别倒掉,放在肉馅里更香哦,今天做的这个红烧狮子头我还放里了我们平时吃的馒头,大约1斤肉馅里放入1个平时市售2个/元的馒头刚好,用刚好浸泡馒头能碾碎的水来浸泡馒头然后搅拌再馅里,我刚好用了泡发香菇的水浸泡的馒头,既不浪费香菇水,味道又浓郁,做出来的狮子头非常松软美味哦,喜欢的朋友快来试一试吧。", + "issuer": "28.80", + "date": "2021-5-19 19:35:14" + }, { + "typeId": 7, + "title": "芋头蒸排骨", + "img": "https://st-cn.meishij.net/r/71/149/9599821/s9599821_150509435566915.jpg", + "content": "排骨与芋头是最完美的搭配,\n排骨的肉汁与芋头的香味相互渗透,\n嫩滑、绵软,两种口感同时兼得。\n虽是朴素的菜式,却给予人安稳的家庭归属感!", + "issuer": "28.80", + "date": "2021-5-19 19:35:14" + }, { + "typeId": 7, + "title": "鲈鱼汤", + "img": "https://st-cn.meishij.net/r/150/78/3394650/s3394650_142838520357353.jpg", + "content": "鲈鱼含蛋白质、脂肪、碳水化合物等营养成分,还含有维生素B2、烟酸和微量的维生素B1、磷、铁等物质。\n鲈鱼能补肝肾、健脾胃、化痰止咳,对肝肾不足的人有很好的补益作用,还可以治胎动不安、产后少乳等症。准妈妈和产后妇女吃鲈鱼,既可补身,又不会造成营养过剩而导致肥胖。另外,鲈鱼血中含有较多的铜元素,铜是维持人体神经系统正常功能并参与数种物质代谢的关键酶功能发挥的不可缺少的矿物质。", + "issuer": "28.80", + "date": "2021-5-19 19:35:14" + }, { + "typeId": 7, + "title": "红烧带鱼", + "img": "https://st-cn.meishij.net/r/219/162/6603219/s6603219_151290369598435.jpg", + "content": "非常简单的一道家常烧菜,口味咸鲜,是不错的下酒下饭菜。", + "issuer": "28.80", + "date": "2021-5-19 19:35:14" + } + ] +} \ No newline at end of file diff --git a/app/src/main/assets/litepal.xml b/app/src/main/assets/litepal.xml new file mode 100644 index 0000000..b5babbf --- /dev/null +++ b/app/src/main/assets/litepal.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/app/src/main/java/com/example/food/MyApplication.java b/app/src/main/java/com/example/food/MyApplication.java new file mode 100644 index 0000000..0322fee --- /dev/null +++ b/app/src/main/java/com/example/food/MyApplication.java @@ -0,0 +1,25 @@ +package com.example.food; + +import android.app.Activity; +import android.app.Application; + +import org.litepal.LitePal; + +public class MyApplication extends Application { + public static MyApplication Instance; + @Override + public void onCreate() { + super.onCreate(); + Instance = this; + LitePal.initialize(this);//初始化LitePal数据库 + } + private Activity mMainActivity; + + public Activity getMainActivity() { + return mMainActivity; + } + + public void setMainActivity(Activity mainActivity) { + mMainActivity = mainActivity; + } +} diff --git a/app/src/main/java/com/example/food/adapter/BrowseAdapter.java b/app/src/main/java/com/example/food/adapter/BrowseAdapter.java new file mode 100644 index 0000000..b59f91a --- /dev/null +++ b/app/src/main/java/com/example/food/adapter/BrowseAdapter.java @@ -0,0 +1,83 @@ +package com.example.food.adapter; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.example.food.R; +import com.example.food.bean.Browse; + +import java.util.ArrayList; +import java.util.List; + +/** + * 浏览记录适配器 + */ + +public class BrowseAdapter extends RecyclerView.Adapter { + private List list =new ArrayList<>(); + private Context mActivity; + private ItemListener mItemListener; + private LinearLayout llEmpty; + private RecyclerView rvNewsList; + public void setItemListener(ItemListener itemListener){ + this.mItemListener = itemListener; + } + public BrowseAdapter(LinearLayout llEmpty, RecyclerView rvNewsList){ + this.llEmpty = llEmpty; + this.rvNewsList =rvNewsList; + } + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { + mActivity = viewGroup.getContext(); + View view= LayoutInflater.from(mActivity).inflate(R.layout.item_rv_collect_list,viewGroup,false); + return new ViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) { + Browse browse = list.get(i); + if (browse != null) { + viewHolder.title.setText(browse.getTitle()); + viewHolder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (mItemListener!=null){ + mItemListener.ItemClick(browse); + } + } + }); + } + } + public void addItem(List listAdd) { + //如果是加载第一页,需要先清空数据列表 + this.list.clear(); + if (listAdd!=null){ + //添加数据 + this.list.addAll(listAdd); + } + //通知RecyclerView进行改变--整体 + notifyDataSetChanged(); + } + @Override + public int getItemCount() { + return list.size(); + } + public class ViewHolder extends RecyclerView.ViewHolder { + private TextView title; + public ViewHolder(@NonNull View itemView) { + super(itemView); + title = itemView.findViewById(R.id.title); + } + } + public interface ItemListener{ + void ItemClick(Browse browse); + } +} diff --git a/app/src/main/java/com/example/food/adapter/FruitAdapter.java b/app/src/main/java/com/example/food/adapter/FruitAdapter.java new file mode 100644 index 0000000..c3914f7 --- /dev/null +++ b/app/src/main/java/com/example/food/adapter/FruitAdapter.java @@ -0,0 +1,138 @@ +package com.example.food.adapter; + +import android.content.Context; +import android.content.DialogInterface; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.recyclerview.widget.RecyclerView; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.example.food.R; +import com.example.food.bean.Fruit; +import com.example.food.util.SPUtils; + +import java.util.ArrayList; +import java.util.List; + + +public class FruitAdapter extends RecyclerView.Adapter { + private List list =new ArrayList<>(); + private Context mActivity; + private ItemListener mItemListener; + private LinearLayout llEmpty; + private RecyclerView rvfruitList; + public void setItemListener(ItemListener itemListener){ + this.mItemListener = itemListener; + } + public FruitAdapter(LinearLayout llEmpty, RecyclerView rvfruitList){ + this.llEmpty = llEmpty; + this.rvfruitList =rvfruitList; + } + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { + mActivity = viewGroup.getContext(); + View view= LayoutInflater.from(mActivity).inflate(R.layout.item_rv_fruit_list,viewGroup,false); + return new ViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) { + Fruit fruit = list.get(i); + if (fruit != null) { + viewHolder.title.setText(fruit.getTitle()); + viewHolder.author_name.setText(String.format("¥ %s",fruit.getIssuer())); + viewHolder.date.setText(fruit.getDate()); + Glide.with(mActivity) + .asBitmap() + .load(fruit.getImg()) + .error(R.drawable.ic_error) + .skipMemoryCache(true) + .diskCacheStrategy(DiskCacheStrategy.NONE) + .into(viewHolder.img); + Boolean isAdmin = (Boolean) SPUtils.get(mActivity,SPUtils.IS_ADMIN,false); + viewHolder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (mItemListener!=null){ + mItemListener.ItemClick(fruit); + } + } + }); + if (isAdmin){ + viewHolder.itemView.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + AlertDialog.Builder dialog = new AlertDialog.Builder(mActivity); + dialog.setMessage("确认要删除该美食吗"); + dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + list.remove(fruit); + fruit.delete(); + notifyDataSetChanged(); + Toast.makeText(mActivity,"删除成功", Toast.LENGTH_LONG).show(); + if (list!=null && list.size() > 0){ + rvfruitList.setVisibility(View.VISIBLE); + llEmpty.setVisibility(View.GONE); + }else { + rvfruitList.setVisibility(View.GONE); + llEmpty.setVisibility(View.VISIBLE); + } + } + }); + dialog.setNeutralButton("取消", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }); + dialog.show(); + return false; + } + }); + } + } + } + + @Override + public int getItemCount() { + return list.size(); + } + public void addItem(List listAdd) { + //如果是加载第一页,需要先清空数据列表 + this.list.clear(); + if (listAdd!=null){ + //添加数据 + this.list.addAll(listAdd); + } + //通知RecyclerView进行改变--整体 + notifyDataSetChanged(); + } + public class ViewHolder extends RecyclerView.ViewHolder { + private TextView title; + private TextView author_name; + private TextView date; + private ImageView img; + public ViewHolder(@NonNull View itemView) { + super(itemView); + title = itemView.findViewById(R.id.title); + author_name = itemView.findViewById(R.id.author_name); + date = itemView.findViewById(R.id.date); + img = itemView.findViewById(R.id.img); + } + } + + public interface ItemListener{ + void ItemClick(Fruit fruit); + } +} diff --git a/app/src/main/java/com/example/food/adapter/OrderAdapter.java b/app/src/main/java/com/example/food/adapter/OrderAdapter.java new file mode 100644 index 0000000..3fcfb75 --- /dev/null +++ b/app/src/main/java/com/example/food/adapter/OrderAdapter.java @@ -0,0 +1,134 @@ +package com.example.food.adapter; + +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.recyclerview.widget.RecyclerView; + +import com.bumptech.glide.request.RequestOptions; +import com.example.food.R; +import com.example.food.bean.Fruit; +import com.example.food.bean.Orders; +import com.example.food.bean.User; +import com.example.food.ui.activity.FruitDetailActivity; +import com.example.food.util.SPUtils; + +import org.litepal.crud.DataSupport; + +import java.util.ArrayList; +import java.util.List; + + +public class OrderAdapter extends RecyclerView.Adapter { + private List list =new ArrayList<>(); + private Context mActivity; + private RequestOptions headerRO = new RequestOptions().circleCrop();//圆角变换 + private LinearLayout llEmpty; + private RecyclerView rvOrderList; + private ItemListener mItemListener; + public void setItemListener(ItemListener itemListener){ + this.mItemListener = itemListener; + } + public OrderAdapter(LinearLayout llEmpty, RecyclerView rvOrderList){ + this.llEmpty = llEmpty; + this.rvOrderList =rvOrderList; + } + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { + mActivity = viewGroup.getContext(); + View view= LayoutInflater.from(mActivity).inflate(R.layout.item_rv_order_list,viewGroup,false); + return new ViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) { + Orders order = list.get(i); + User user = DataSupport.where("account = ? ", order.getAccount()).findFirst(User.class); + if (order != null && user!=null) { + viewHolder.nickName.setText(String.format("用户:%s",user.getNickName())); + viewHolder.number.setText(order.getNumber()); + viewHolder.date.setText(order.getDate()); + viewHolder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(mActivity, FruitDetailActivity.class); + Fruit fruit = DataSupport.where("title = ?",order.getTitle()).findFirst(Fruit.class); + intent.putExtra("fruit",fruit); + mActivity.startActivity(intent); + } + }); + Boolean isAdmin = (Boolean) SPUtils.get(mActivity,SPUtils.IS_ADMIN,false); + if (isAdmin){ + viewHolder.itemView.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + AlertDialog.Builder dialog = new AlertDialog.Builder(mActivity); + dialog.setMessage("确认要删除该订单吗"); + dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + list.remove(order); + order.delete(); + notifyDataSetChanged(); + Toast.makeText(mActivity,"删除成功", Toast.LENGTH_LONG).show(); + if (list!=null && list.size() > 0){ + rvOrderList.setVisibility(View.VISIBLE); + llEmpty.setVisibility(View.GONE); + }else { + rvOrderList.setVisibility(View.GONE); + llEmpty.setVisibility(View.VISIBLE); + } + } + }); + dialog.setNeutralButton("取消", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }); + dialog.show(); + return false; + } + }); + } + } + } + public void addItem(List listAdd) { + //如果是加载第一页,需要先清空数据列表 + this.list.clear(); + if (listAdd!=null){ + //添加数据 + this.list.addAll(listAdd); + } + //通知RecyclerView进行改变--整体 + notifyDataSetChanged(); + } + @Override + public int getItemCount() { + return list.size(); + } + public class ViewHolder extends RecyclerView.ViewHolder { + private TextView nickName; + private TextView date; + private TextView number; + public ViewHolder(@NonNull View itemView) { + super(itemView); + nickName = itemView.findViewById(R.id.nickName); + date = itemView.findViewById(R.id.date); + number = itemView.findViewById(R.id.number); + } + } + public interface ItemListener{ + void ItemClick(Orders order); + } +} diff --git a/app/src/main/java/com/example/food/adapter/UserAdapter.java b/app/src/main/java/com/example/food/adapter/UserAdapter.java new file mode 100644 index 0000000..294f56e --- /dev/null +++ b/app/src/main/java/com/example/food/adapter/UserAdapter.java @@ -0,0 +1,123 @@ +package com.example.food.adapter; + +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.recyclerview.widget.RecyclerView; + +import com.example.food.R; +import com.example.food.bean.Browse; +import com.example.food.bean.User; +import com.example.food.ui.activity.UserDetailActivity; +import com.example.food.util.SPUtils; + +import org.litepal.crud.DataSupport; + +import java.util.ArrayList; +import java.util.List; + + +public class UserAdapter extends RecyclerView.Adapter { + private List list =new ArrayList<>(); + private Context mActivity; + private LinearLayout llEmpty; + private RecyclerView rvUserList; + + public UserAdapter(LinearLayout llEmpty, RecyclerView rvUserList){ + this.llEmpty = llEmpty; + this.rvUserList =rvUserList; + } + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { + mActivity = viewGroup.getContext(); + View view= LayoutInflater.from(mActivity).inflate(R.layout.item_rv_user_list,viewGroup,false); + return new ViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) { + User user = list.get(i); + if (user!=null) { + String account = (String) SPUtils.get(mActivity,SPUtils.ACCOUNT,""); + viewHolder.itemView.setVisibility(account.equals(user.getAccount())? View.GONE: View.VISIBLE); + viewHolder.nickName.setText(user.getNickName()); + viewHolder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(mActivity, UserDetailActivity.class); + intent.putExtra("user",user); + mActivity.startActivity(intent); + } + }); + viewHolder.itemView.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + AlertDialog.Builder dialog = new AlertDialog.Builder(mActivity); + dialog.setMessage("确认要删除该用户吗"); + dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + //删除收藏记录和浏览记录 + List browses = DataSupport.where("account = ?",user.getAccount()).find(Browse.class); + if (browses !=null && browses.size() > 0){ + for (Browse browse: browses) { + browse.delete(); + } + } + list.remove(user); + user.delete(); + notifyDataSetChanged(); + Toast.makeText(mActivity,"删除成功", Toast.LENGTH_LONG).show(); + if (list!=null && list.size() > 1){ + rvUserList.setVisibility(View.VISIBLE); + llEmpty.setVisibility(View.GONE); + }else { + rvUserList.setVisibility(View.GONE); + llEmpty.setVisibility(View.VISIBLE); + } + } + }); + dialog.setNeutralButton("取消", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }); + dialog.show(); + return false; + } + }); + } + } + public void addItem(List listAdd) { + //如果是加载第一页,需要先清空数据列表 + this.list.clear(); + if (listAdd!=null){ + //添加数据 + this.list.addAll(listAdd); + } + //通知RecyclerView进行改变--整体 + notifyDataSetChanged(); + } + @Override + public int getItemCount() { + return list.size(); + } + public class ViewHolder extends RecyclerView.ViewHolder { + private TextView nickName; + public ViewHolder(@NonNull View itemView) { + super(itemView); + nickName = itemView.findViewById(R.id.nickName); + } + } +} diff --git a/app/src/main/java/com/example/food/bean/Browse.java b/app/src/main/java/com/example/food/bean/Browse.java new file mode 100644 index 0000000..a713cbb --- /dev/null +++ b/app/src/main/java/com/example/food/bean/Browse.java @@ -0,0 +1,33 @@ +package com.example.food.bean; + +import org.litepal.crud.DataSupport; + + +/** + * 浏览记录 + */ +public class Browse extends DataSupport { + private String account;//账号 + private String title;//菜品标题 + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public Browse(String account, String title) { + this.account = account; + this.title = title; + } +} diff --git a/app/src/main/java/com/example/food/bean/Fruit.java b/app/src/main/java/com/example/food/bean/Fruit.java new file mode 100644 index 0000000..1a086e8 --- /dev/null +++ b/app/src/main/java/com/example/food/bean/Fruit.java @@ -0,0 +1,75 @@ +package com.example.food.bean; + +import org.litepal.crud.DataSupport; + +import java.io.Serializable; + + +/** + * 菜品 + */ +public class Fruit extends DataSupport implements Serializable { + private Integer typeId;//类型 0科技,1娱乐,2体育,3军事,4汽车,5健康 + private String title;//标题 + private String img;//图片 + private String content;//内容 + private String issuer;//发布人 + private String date;//时间 + + public Integer getTypeId() { + return typeId; + } + + public void setTypeId(Integer typeId) { + this.typeId = typeId; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getImg() { + return img; + } + + public void setImg(String img) { + this.img = img; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDate() { + return date; + } + + public void setDate(String date) { + this.date = date; + } + + public String getIssuer() { + return issuer; + } + + public void setIssuer(String issuer) { + this.issuer = issuer; + } + + public Fruit(Integer typeId, String title, String img, String content, String issuer, String date) { + this.typeId = typeId; + this.title = title; + this.img = img; + this.content = content; + this.issuer = issuer; + this.date = date; + } +} diff --git a/app/src/main/java/com/example/food/bean/Orders.java b/app/src/main/java/com/example/food/bean/Orders.java new file mode 100644 index 0000000..2726aee --- /dev/null +++ b/app/src/main/java/com/example/food/bean/Orders.java @@ -0,0 +1,62 @@ +package com.example.food.bean; + +import org.litepal.crud.DataSupport; + +import java.io.Serializable; + +public class Orders extends DataSupport implements Serializable { + private String account;//账号 + private String title;//标题 + private String number;//编号 + private String amount;//数量 + private String date;//时间 + + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + + public String getAmount() { + return amount; + } + + public void setAmount(String amount) { + this.amount = amount; + } + + public String getDate() { + return date; + } + + public void setDate(String date) { + this.date = date; + } + + public Orders(String account, String title, String number, String amount, String date) { + this.account = account; + this.title = title; + this.number = number; + this.amount = amount; + this.date = date; + } +} diff --git a/app/src/main/java/com/example/food/bean/User.java b/app/src/main/java/com/example/food/bean/User.java new file mode 100644 index 0000000..10c1d1c --- /dev/null +++ b/app/src/main/java/com/example/food/bean/User.java @@ -0,0 +1,66 @@ +package com.example.food.bean; + +import org.litepal.crud.DataSupport; + +import java.io.Serializable; + + +/** + * 用户 + */ +public class User extends DataSupport implements Serializable { + private String account;//账号 + private String password;//密码 + private String nickName;//昵称 + private Integer age;//年龄 + private String email;//邮箱 + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getNickName() { + return nickName; + } + + public void setNickName(String nickName) { + this.nickName = nickName; + } + + + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public User(String account, String password, String nickName, Integer age, String email) { + this.account = account; + this.password = password; + this.nickName = nickName; + this.age = age; + this.email = email; + } +} diff --git a/app/src/main/java/com/example/food/ui/activity/AddFruitActivity.java b/app/src/main/java/com/example/food/ui/activity/AddFruitActivity.java new file mode 100644 index 0000000..27227e8 --- /dev/null +++ b/app/src/main/java/com/example/food/ui/activity/AddFruitActivity.java @@ -0,0 +1,132 @@ +package com.example.food.ui.activity; + +import android.app.Activity; +import android.os.Bundle; +import android.view.View; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.Spinner; +import android.widget.Toast; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.example.food.R; +import com.example.food.bean.Fruit; +import com.example.food.widget.ActionBar; + +import org.litepal.crud.DataSupport; + +import java.text.SimpleDateFormat; +import java.util.Date; + + +/** + * 添加页面 + */ +public class AddFruitActivity extends AppCompatActivity { + private ActionBar mActionBar;//标题栏 + private Activity myActivity; + private EditText etTitle;//标题 + private EditText etIssuer;//发布单位 + private EditText etImg;//图片 + private Spinner spType;//类型 + private EditText etContent;//内容 + private ImageView ivImg;//图片 + SimpleDateFormat sf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + private Fruit mfruit; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + myActivity = this; + setContentView(R.layout.activity_fruit_add); + etTitle = findViewById(R.id.title); + etIssuer = findViewById(R.id.issuer); + spType = findViewById(R.id.type); + etImg = findViewById(R.id.img); + etContent = findViewById(R.id.content); + ivImg = findViewById(R.id.iv_img); + mActionBar = findViewById(R.id.myActionBar); + //侧滑菜单 + mActionBar.setData(myActivity,"编辑美食信息", R.drawable.ic_back, 0, 0, getResources().getColor(R.color.colorPrimary), new ActionBar.ActionBarClickListener() { + @Override + public void onLeftClick() { + finish(); + } + + @Override + public void onRightClick() { + } + }); + initView(); + } + + private void initView() { + mfruit = (Fruit) getIntent().getSerializableExtra("fruit"); + if (mfruit !=null){ + etTitle.setText(mfruit.getTitle()); + spType.setSelection(mfruit.getTypeId()); + etImg.setText(mfruit.getImg()); + etIssuer.setText(mfruit.getIssuer()); + etContent.setText(mfruit.getContent()); + spType.setSelection(mfruit.getTypeId(),true); + Glide.with(myActivity) + .asBitmap() + .load(mfruit.getImg()) + .error(R.drawable.ic_error) + .skipMemoryCache(true) + .diskCacheStrategy(DiskCacheStrategy.NONE) + .into(ivImg); + } + ivImg.setVisibility(mfruit ==null? View.GONE: View.VISIBLE); + } + + public void save(View view){ + String title = etTitle.getText().toString(); + String issuer = etIssuer.getText().toString(); + String img = etImg.getText().toString(); + String content = etContent.getText().toString(); + Integer typeId = spType.getSelectedItemPosition(); + if ("".equals(title)) { + Toast.makeText(myActivity,"标题不能为空", Toast.LENGTH_LONG).show(); + return; + } + if ("".equals(issuer)) { + Toast.makeText(myActivity,"价格不能为空", Toast.LENGTH_LONG).show(); + return; + } + if ("".equals(img)) { + Toast.makeText(myActivity,"图片地址不能为空", Toast.LENGTH_LONG).show(); + return; + } + if ("".equals(content)) { + Toast.makeText(myActivity,"描述不能为空", Toast.LENGTH_LONG).show(); + return; + } + Fruit fruit = null; + if (!title.equals(mfruit != null? mfruit.getTitle():"")){ + fruit = DataSupport.where("title = ?",title).findFirst(Fruit.class); + } + if (fruit == null ){ + if (mfruit != null){ + fruit = DataSupport.where("title = ?", mfruit.getTitle()).findFirst(Fruit.class); + fruit.setTypeId(typeId); + fruit.setTitle(title); + fruit.setIssuer(issuer); + fruit.setImg(img); + fruit.setContent(content); + }else { + fruit = new Fruit(typeId,title,img,content,issuer,sf.format(new Date())); + } + fruit.save(); + setResult(RESULT_OK); + finish(); + Toast.makeText(myActivity,"保存成功", Toast.LENGTH_LONG).show(); + }else { + Toast.makeText(myActivity,"该标题已存在", Toast.LENGTH_LONG).show(); + } + } +} diff --git a/app/src/main/java/com/example/food/ui/activity/BrowseActivity.java b/app/src/main/java/com/example/food/ui/activity/BrowseActivity.java new file mode 100644 index 0000000..7d5797d --- /dev/null +++ b/app/src/main/java/com/example/food/ui/activity/BrowseActivity.java @@ -0,0 +1,101 @@ +package com.example.food.ui.activity; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.LinearLayout; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.example.food.R; +import com.example.food.adapter.BrowseAdapter; +import com.example.food.bean.Browse; +import com.example.food.bean.Fruit; +import com.example.food.util.SPUtils; +import com.example.food.widget.ActionBar; + +import org.litepal.crud.DataSupport; + +import java.util.List; + + +/** + * 浏览记录 + */ +public class BrowseActivity extends AppCompatActivity { + private Activity myActivity; + private ActionBar mTitleBar;//标题栏 + private LinearLayout llEmpty; + private RecyclerView rvBrowseList; + private BrowseAdapter mBrowseAdapter; + private List mBrowses; + private String account; + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_browse); + myActivity = this; + rvBrowseList = findViewById(R.id.rv_collect_list); + llEmpty = findViewById(R.id.ll_empty); + mTitleBar = (ActionBar)findViewById(R.id.myActionBar); + mTitleBar.setData(myActivity,"浏览记录", R.drawable.ic_back, 0, 0,getResources().getColor(R.color.colorPrimary), new ActionBar.ActionBarClickListener() { + @Override + public void onLeftClick() { + finish(); + } + + @Override + public void onRightClick() { + } + }); + initView(); + } + + private void initView() { + account = (String) SPUtils.get(myActivity,SPUtils.ACCOUNT,""); + LinearLayoutManager layoutManager=new LinearLayoutManager(myActivity); + //=1.2、设置为垂直排列,用setOrientation方法设置(默认为垂直布局) + layoutManager.setOrientation(LinearLayoutManager.VERTICAL); + //=1.3、设置recyclerView的布局管理器 + rvBrowseList.setLayoutManager(layoutManager); + //==2、实例化适配器 + //=2.1、初始化适配器 + mBrowseAdapter=new BrowseAdapter(llEmpty,rvBrowseList); + //=2.3、设置recyclerView的适配器 + rvBrowseList.setAdapter(mBrowseAdapter); + loadData();//加载数据 + mBrowseAdapter.setItemListener(new BrowseAdapter.ItemListener() { + @Override + public void ItemClick(Browse collect) { + Intent intent = new Intent(myActivity, FruitDetailActivity.class);; + Fruit news = DataSupport.where("title = ?",collect.getTitle()).findFirst(Fruit.class); + intent.putExtra("fruit",news); + startActivityForResult(intent,100); + } + }); + } + + /** + * 加载数据 + */ + private void loadData(){ + mBrowses = DataSupport.where("account = ?",account).find(Browse.class);//查询浏览记录 + if (mBrowses !=null && mBrowses.size()>0){ + rvBrowseList.setVisibility(View.VISIBLE); + llEmpty.setVisibility(View.GONE); + mBrowseAdapter.addItem(mBrowses); + }else { + rvBrowseList.setVisibility(View.GONE); + llEmpty.setVisibility(View.VISIBLE); + } + } + @Override + public void onResume() { + super.onResume(); + loadData(); + } +} diff --git a/app/src/main/java/com/example/food/ui/activity/FruitDetailActivity.java b/app/src/main/java/com/example/food/ui/activity/FruitDetailActivity.java new file mode 100644 index 0000000..e8efc5f --- /dev/null +++ b/app/src/main/java/com/example/food/ui/activity/FruitDetailActivity.java @@ -0,0 +1,113 @@ +package com.example.food.ui.activity; + +import android.app.Activity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.example.food.R; +import com.example.food.bean.Browse; +import com.example.food.bean.Fruit; +import com.example.food.bean.Orders; +import com.example.food.util.SPUtils; +import com.example.food.widget.ActionBar; + +import org.litepal.crud.DataSupport; + +import java.text.SimpleDateFormat; +import java.util.Date; + + +/** + * 菜品明细信息 + */ +public class FruitDetailActivity extends AppCompatActivity { + private Activity mActivity; + private ImageView ivImg; + private TextView tvTitle; + private TextView tvDate; + private TextView tvContent; + private TextView tvIssuer; + private Button btnCollect; + private Button btnCancel; + private ActionBar mActionBar;//标题栏 + private SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mActivity = this; + setContentView(R.layout.activity_fruit_detail); + ivImg = findViewById(R.id.img); + tvTitle= findViewById(R.id.title); + tvDate = findViewById(R.id.date); + tvContent = findViewById(R.id.content); + tvIssuer = findViewById(R.id.issuer); + btnCollect = findViewById(R.id.btn_collect); + btnCancel = findViewById(R.id.btn_cancel); + mActionBar = findViewById(R.id.myActionBar); + //侧滑菜单 + mActionBar.setData(mActivity,"明细信息", R.drawable.ic_back, 0, 0, getResources().getColor(R.color.colorPrimary), new ActionBar.ActionBarClickListener() { + @Override + public void onLeftClick() { + finish(); + } + + @Override + public void onRightClick() { + } + }); + Fruit fruit = (Fruit) getIntent().getSerializableExtra("fruit"); + tvTitle.setText(fruit.getTitle()); + tvDate.setText(fruit.getDate()); + tvContent.setText(fruit.getContent()); + tvIssuer.setText(String.format("¥ %s",fruit.getIssuer())); + Glide.with(mActivity) + .asBitmap() + .skipMemoryCache(true) + .load(fruit.getImg()) + .diskCacheStrategy(DiskCacheStrategy.NONE) + .into(ivImg); + String account = (String) SPUtils.get(mActivity,SPUtils.ACCOUNT,""); + Browse browse = DataSupport.where("account = ? and title = ?",account,fruit.getTitle()).findFirst(Browse.class);//浏览记录 + if (browse == null) {//不存在该条浏览记录 新增记录 + Browse browse1 = new Browse(account,fruit.getTitle()); + browse1.save(); + } + Boolean isAdmin = (Boolean) SPUtils.get(mActivity,SPUtils.IS_ADMIN,false); + if (!isAdmin){ + Orders order = DataSupport.where("account = ? and title = ?",account,fruit.getTitle()).findFirst(Orders.class); + btnCollect.setVisibility(order!=null? View.GONE: View.VISIBLE); + btnCancel.setVisibility(order!=null? View.VISIBLE: View.GONE); + } + //收藏 + btnCollect.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Orders order = new Orders(account,fruit.getTitle(),"S"+ System.currentTimeMillis(),account,sf.format(new Date())); + order.save(); + Toast.makeText(mActivity,"点餐成功", Toast.LENGTH_SHORT).show(); + btnCollect.setVisibility(View.GONE); + btnCancel.setVisibility(View.VISIBLE); + } + }); + //取消收藏 + btnCancel.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Orders order = DataSupport.where("account = ? and title = ?",account,fruit.getTitle()).findFirst(Orders.class); + order.delete(); + Toast.makeText(mActivity,"取消成功", Toast.LENGTH_SHORT).show(); + btnCollect.setVisibility(View.VISIBLE); + btnCancel.setVisibility(View.GONE); + } + }); + } +} diff --git a/app/src/main/java/com/example/food/ui/activity/LoginActivity.java b/app/src/main/java/com/example/food/ui/activity/LoginActivity.java new file mode 100644 index 0000000..d83a2f6 --- /dev/null +++ b/app/src/main/java/com/example/food/ui/activity/LoginActivity.java @@ -0,0 +1,126 @@ +package com.example.food.ui.activity; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.Button; +import android.widget.EditText; +import android.widget.RadioButton; +import android.widget.RadioGroup; +import android.widget.TextView; +import android.widget.Toast; + +import com.example.food.R; +import com.example.food.bean.User; +import com.example.food.util.SPUtils; +import com.example.food.widget.ActionBar; + +import org.litepal.crud.DataSupport; + + +/** + * 登录页面 + */ +public class LoginActivity extends Activity { + private static final String TAG = "LoginActivity"; + private Activity activity; + private ActionBar mTitleBar;//标题栏 + private EditText etAccount;//手机号 + private EditText etPassword;//密码 + private TextView tvRegister;//注册 + private Button btnLogin;//登录按钮 + private RadioGroup rgType;//用户类型 + private RadioButton rbUser;//用户类型 + private RadioButton rbAdmin;//用户类型 + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + activity=this; + setContentView(R.layout.activity_login);//加载页面 + etAccount =(EditText) findViewById(R.id.et_account);//获取手机号 + etPassword=(EditText)findViewById(R.id.et_password);//获取密码 + tvRegister=(TextView)findViewById(R.id.tv_register);//获取注册 + btnLogin=(Button)findViewById(R.id.btn_login);//获取登录 + rgType = findViewById(R.id.rg_type); + rbUser = findViewById(R.id.rb_user); + rbAdmin = findViewById(R.id.rb_admin); + mTitleBar = (ActionBar)findViewById(R.id.myActionBar); + mTitleBar.setData(activity,"登录",0, 0, 0,getResources().getColor(R.color.colorPrimary), new ActionBar.ActionBarClickListener() { + @Override + public void onLeftClick() { + finish(); + } + + @Override + public void onRightClick() { + } + }); + + //手机号注册 + tvRegister.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //跳转到注册页面 + Intent intent=new Intent(activity, RegisterActivity.class); + startActivity(intent); + } + }); + //选择类型 + rgType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(RadioGroup group, int checkedId) { + SPUtils.put(activity,SPUtils.IS_ADMIN,checkedId == R.id.rb_admin); + } + }); + //设置点击按钮 + btnLogin.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //关闭虚拟键盘 + InputMethodManager inputMethodManager= (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(),0); + //获取请求参数 + String account= etAccount.getText().toString(); + String password=etPassword.getText().toString(); + Boolean isAdmit = (Boolean) SPUtils.get(activity,SPUtils.IS_ADMIN,false); + if ("".equals(account)){//账号不能为空 + Toast.makeText(activity,"账号不能为空", Toast.LENGTH_LONG).show(); + return; + } + if ("".equals(password)){//密码为空 + Toast.makeText(activity,"密码为空", Toast.LENGTH_LONG).show(); + return; + } + User user = DataSupport.where("account = ?", account).findFirst(User.class); + if (user != null) { + if (!password.equals(user.getPassword())) { + Toast.makeText(activity, "密码错误", Toast.LENGTH_SHORT).show(); + }else{ + if (isAdmit && !"admin".equals(user.getAccount())){ + Toast.makeText(activity,"该账号不是管理员账号", Toast.LENGTH_LONG).show(); + return; + } + if (!isAdmit && "admin".equals(user.getAccount())){ + Toast.makeText(activity,"该账号不是普通用户账号", Toast.LENGTH_LONG).show(); + return; + } + SPUtils.put(LoginActivity.this,"account",account); + Intent intent = new Intent(activity, MainActivity.class); + startActivity(intent); + finish(); + } + }else{ + Toast.makeText(activity, "账号不存在", Toast.LENGTH_SHORT).show(); + } + } + }); + } + + @Override + protected void onResume() { + super.onResume(); + } +} diff --git a/app/src/main/java/com/example/food/ui/activity/MainActivity.java b/app/src/main/java/com/example/food/ui/activity/MainActivity.java new file mode 100644 index 0000000..91f9d40 --- /dev/null +++ b/app/src/main/java/com/example/food/ui/activity/MainActivity.java @@ -0,0 +1,220 @@ +package com.example.food.ui.activity; + +import android.app.Activity; +import android.app.Fragment; +import android.app.FragmentManager; +import android.app.FragmentTransaction; +import android.content.Intent; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.view.KeyEvent; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.RadioButton; +import android.widget.Toast; + +import com.example.food.MyApplication; +import com.example.food.R; +import com.example.food.ui.fragment.FruitFragment; +import com.example.food.ui.fragment.OrderFragment; +import com.example.food.ui.fragment.UserFragment; +import com.example.food.ui.fragment.UserManageFragment; +import com.example.food.util.SPUtils; +import com.example.food.widget.ActionBar; + + +/** + * 主页面 + */ +public class MainActivity extends Activity { + private ActionBar mActionBar;//标题栏 + private Activity myActivity; + private LinearLayout llContent; + private RadioButton rbFruit; + private RadioButton rbFruitData; + private RadioButton rbUserManage; + private RadioButton rbUser; + private Fragment[] fragments = new Fragment[]{null, null,null,null};//存放Fragment + private Boolean mIsAdmin;//是否管理员 + private String mAccount;//账号 + + @Override + protected void onCreate( Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + myActivity = this; + setContentView(R.layout.activity_main); + MyApplication.Instance.setMainActivity(myActivity); + mIsAdmin = (Boolean) SPUtils.get(myActivity, SPUtils.IS_ADMIN,false); + llContent = (LinearLayout) findViewById(R.id.ll_main_content); + rbFruit = (RadioButton) findViewById(R.id.rb_main_fruit); + rbFruitData = (RadioButton) findViewById(R.id.rb_main_fruit_data); + rbUserManage = (RadioButton) findViewById(R.id.rb_main_setting); + rbUser = (RadioButton) findViewById(R.id.rb_main_user); + mActionBar = (ActionBar) findViewById(R.id.myActionBar); + //侧滑菜单 + mActionBar.setData(myActivity,"美食点餐", 0, 0, 0, getResources().getColor(R.color.colorPrimary), new ActionBar.ActionBarClickListener() { + @Override + public void onLeftClick() { + } + + @Override + public void onRightClick() { + } + }); + initView(); + setViewListener(); + } + + private void setViewListener() { + rbFruit.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + mActionBar.setTitle("美食点餐"); + switchFragment(0); + } + }); + rbFruitData.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if ("".equals(mAccount)) {////未登录,跳转到登录页面 + MyApplication.Instance.getMainActivity().finish(); + startActivity(new Intent(myActivity, LoginActivity.class)); + }else {//已经登录 + mActionBar.setTitle("订单"); + switchFragment(1); + } + } + }); + rbUserManage.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + mActionBar.setTitle("用户管理"); + switchFragment(2); + } + }); + rbUser.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if ("".equals(mAccount)) {////未登录,跳转到登录页面 + MyApplication.Instance.getMainActivity().finish(); + startActivity(new Intent(myActivity, LoginActivity.class)); + }else {//已经登录 + mActionBar.setTitle("我的"); + switchFragment(mIsAdmin?3:2); + } + } + }); + } + + private void initView() { + mIsAdmin = (Boolean) SPUtils.get(myActivity,SPUtils.IS_ADMIN,false); + mAccount = (String) SPUtils.get(myActivity,SPUtils.ACCOUNT,""); + //设置导航栏图标样式 + Drawable iconNews=getResources().getDrawable(R.drawable.selector_main_rb_home);//设置主页图标样式 + iconNews.setBounds(0,0,68,68);//设置图标边距 大小 + rbFruit.setCompoundDrawables(null,iconNews,null,null);//设置图标位置 + rbFruit.setCompoundDrawablePadding(5);//设置文字与图片的间距 + Drawable iconNewsData=getResources().getDrawable(R.drawable.selector_main_rb_buy);//设置主页图标样式 + iconNewsData.setBounds(0,0,68,68);//设置图标边距 大小 + rbFruitData.setCompoundDrawables(null,iconNewsData,null,null);//设置图标位置 + rbFruitData.setCompoundDrawablePadding(5);//设置文字与图片的间距 + Drawable iconSetting=getResources().getDrawable(R.drawable.selector_main_rb_manage);//设置主页图标样式 + iconSetting.setBounds(0,0,60,60);//设置图标边距 大小 + rbUserManage.setCompoundDrawables(null,iconSetting,null,null);//设置图标位置 + rbUserManage.setCompoundDrawablePadding(5);//设置文字与图片的间距 + Drawable iconUser=getResources().getDrawable(R.drawable.selector_main_rb_user);//设置主页图标样式 + iconUser.setBounds(0,0,55,55);//设置图标边距 大小 + rbUser.setCompoundDrawables(null,iconUser,null,null);//设置图标位置 + rbUser.setCompoundDrawablePadding(5);//设置文字与图片的间距 + rbUserManage.setVisibility(mIsAdmin? View.VISIBLE: View.GONE); + switchFragment(0); + rbFruit.setChecked(true); + } + /** + * 方法 - 切换Fragment + * + * @param fragmentIndex 要显示Fragment的索引 + */ + private void switchFragment(int fragmentIndex) { + //在Activity中显示Fragment + //1、获取Fragment管理器 FragmentManager + FragmentManager fragmentManager = this.getFragmentManager(); + //2、开启fragment事务 + FragmentTransaction transaction = fragmentManager.beginTransaction(); + + //懒加载 - 如果需要显示的Fragment为null,就new。并添加到Fragment事务中 + if (fragments[fragmentIndex] == null) { + if (mIsAdmin){ + switch (fragmentIndex) { + case 0://NewsFragment + fragments[fragmentIndex] = new FruitFragment(); + break; + case 1://CollectFragment + fragments[fragmentIndex] = new OrderFragment(); + break; + case 2://UserManageFragment + fragments[fragmentIndex] = new UserManageFragment(); + break; + case 3://UserFragment + fragments[fragmentIndex] = new UserFragment(); + break; + } + }else { + switch (fragmentIndex) { + case 0://NewsFragment + fragments[fragmentIndex] = new FruitFragment(); + break; + case 1://CollectFragment + fragments[fragmentIndex] = new OrderFragment(); + break; + case 2://UserFragment + fragments[fragmentIndex] = new UserFragment(); + break; + } + } + + //==添加Fragment对象到Fragment事务中 + //参数:显示Fragment的容器的ID,Fragment对象 + transaction.add(R.id.ll_main_content, fragments[fragmentIndex]); + } + + //隐藏其他的Fragment + for (int i = 0; i < fragments.length; i++) { + if (fragmentIndex != i && fragments[i] != null) { + //隐藏指定的Fragment + transaction.hide(fragments[i]); + } + } + //4、显示Fragment + transaction.show(fragments[fragmentIndex]); + + //5、提交事务 + transaction.commit(); + } + /** + * 双击退出 + * + * @param keyCode + * @param event + * @return + */ + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + if (keyCode == KeyEvent.KEYCODE_BACK) { + exit(); + } + + return false; + } + + private long time = 0; + + public void exit() { + if (System.currentTimeMillis() - time > 2000) { + time = System.currentTimeMillis(); + Toast.makeText(myActivity,"再点击一次退出应用程序", Toast.LENGTH_LONG).show(); + } else { + finish(); + } + } +} diff --git a/app/src/main/java/com/example/food/ui/activity/OpeningActivity.java b/app/src/main/java/com/example/food/ui/activity/OpeningActivity.java new file mode 100644 index 0000000..03a4a19 --- /dev/null +++ b/app/src/main/java/com/example/food/ui/activity/OpeningActivity.java @@ -0,0 +1,111 @@ +package com.example.food.ui.activity; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; + +import com.example.food.R; +import com.example.food.bean.Fruit; +import com.example.food.bean.User; +import com.example.food.util.SPUtils; +import com.example.food.util.StatusBarUtil; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.text.SimpleDateFormat; +import java.util.Date; + + +/** + * 开屏页面 + */ +public class OpeningActivity extends AppCompatActivity { + private Activity myActivity; + private SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + myActivity = this; + //设置页面布局 + setContentView(R.layout.activity_opening); + try { + initView(); + } catch (IOException | JSONException e) { + e.printStackTrace(); + } + + } + private void initView() throws IOException, JSONException { + StatusBarUtil.setStatusBar(myActivity,true);//设置当前界面是否是全屏模式(状态栏) + StatusBarUtil.setStatusBarLightMode(myActivity,true);//状态栏文字颜色 + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + if((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0){ + finish(); + return; + } + Boolean isFirst= (Boolean) SPUtils.get(myActivity,SPUtils.IF_FIRST,true); + String account= (String) SPUtils.get(myActivity,SPUtils.ACCOUNT,""); + if (isFirst){//第一次进来 初始化本地数据 + SPUtils.put(myActivity,SPUtils.IF_FIRST,false);//第一次 + //初始化数据 + //获取json数据 + String rewardJson = ""; + String rewardJsonLine; + //assets文件夹下db.json文件的路径->打开db.json文件 + BufferedReader bufferedReader = null; + try { + bufferedReader = new BufferedReader(new InputStreamReader(myActivity.getAssets().open("db.json"))); + while (true) { + if (!((rewardJsonLine = bufferedReader.readLine()) != null)) break; + rewardJson += rewardJsonLine; + } + JSONObject jsonObject = new JSONObject(rewardJson); + JSONArray fruitList = jsonObject.getJSONArray("fruit");//获得列表 + //把物品列表保存到本地 + for (int i = 0, length = fruitList.length(); i < length; i++) { + JSONObject o = fruitList.getJSONObject(i); + Fruit fruit = new Fruit(o.getInt("typeId"), + o.getString("title"), + o.getString("img"), + o.getString("content"), + o.getString("issuer"), + sf.format(new Date()) + ); + fruit.save();//保存到本地 + } + User user = new User("admin","123","管理员",22,"123456789@qq.com"); + user.save(); + } catch (IOException | JSONException e) { + e.printStackTrace(); + } + } + //两秒后跳转到主页面 + Intent intent2 = new Intent(); + if ("".equals(account)) { + intent2.setClass(OpeningActivity.this, MainActivity.class); + }else { + intent2.setClass(OpeningActivity.this, MainActivity.class); + } + startActivity(intent2); + finish(); + } + }, 2000); + } + + + @Override + public void onBackPressed() { + + } +} diff --git a/app/src/main/java/com/example/food/ui/activity/PasswordActivity.java b/app/src/main/java/com/example/food/ui/activity/PasswordActivity.java new file mode 100644 index 0000000..0d7e7e1 --- /dev/null +++ b/app/src/main/java/com/example/food/ui/activity/PasswordActivity.java @@ -0,0 +1,80 @@ +package com.example.food.ui.activity; + +import android.app.Activity; +import android.content.Context; +import android.os.Bundle; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.EditText; +import android.widget.Toast; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; + +import com.example.food.R; +import com.example.food.bean.User; +import com.example.food.widget.ActionBar; + +import org.litepal.crud.DataSupport; + + +/** + * 重置密码 + */ +public class PasswordActivity extends AppCompatActivity { + private Activity activity; + private ActionBar mTitleBar;//标题栏 + private EditText etAccount; + private EditText etEmail; private EditText etNewPassword; + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + activity =this; + setContentView(R.layout.activity_password); + etAccount = findViewById(R.id.et_account); + etEmail = findViewById(R.id.et_email); + etNewPassword = findViewById(R.id.et_new_password); + mTitleBar = (ActionBar)findViewById(R.id.myActionBar); + mTitleBar.setData(activity,"重置密码", R.drawable.ic_back, 0, 0,getResources().getColor(R.color.colorPrimary), new ActionBar.ActionBarClickListener() { + @Override + public void onLeftClick() { + finish(); + } + + @Override + public void onRightClick() { + } + }); + } + + //保存信息 + public void save(View v){ + //关闭虚拟键盘 + InputMethodManager inputMethodManager= (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(),0); + String account = etAccount.getText().toString(); + String email = etEmail.getText().toString(); + String newPassword = etNewPassword.getText().toString(); + if ("".equals(account)){//账号不能为空 + Toast.makeText(activity,"账号不能为空", Toast.LENGTH_LONG).show(); + return; + } + if ("".equals(email)){//邮箱为空 + Toast.makeText(activity,"邮箱为空", Toast.LENGTH_LONG).show(); + return; + } + if ("".equals(newPassword)){//密码为空 + Toast.makeText(activity,"新密码为空", Toast.LENGTH_LONG).show(); + return; + } + User user = DataSupport.where("account = ? and email = ?", account,email).findFirst(User.class); + if (user != null) { + user.setPassword(newPassword); + user.save(); + Toast.makeText(activity, "密码修改成功", Toast.LENGTH_SHORT).show(); + finish(); + }else{ + Toast.makeText(activity, "账号或者邮箱错误", Toast.LENGTH_SHORT).show(); + } + } +} diff --git a/app/src/main/java/com/example/food/ui/activity/PersonActivity.java b/app/src/main/java/com/example/food/ui/activity/PersonActivity.java new file mode 100644 index 0000000..41d9649 --- /dev/null +++ b/app/src/main/java/com/example/food/ui/activity/PersonActivity.java @@ -0,0 +1,103 @@ +package com.example.food.ui.activity; + +import android.app.Activity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; + +import com.example.food.R; +import com.example.food.bean.User; +import com.example.food.util.SPUtils; +import com.example.food.widget.ActionBar; + +import org.litepal.crud.DataSupport; + + +/** + * 个人信息 + */ +public class PersonActivity extends AppCompatActivity { + private Activity mActivity; + private ActionBar mTitleBar;//标题栏 + private TextView tvAccount; + private TextView etNickName; + private TextView etAge; + private TextView etEmail; + private Button btnSave;//保存 + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_person); + mActivity = this; + tvAccount = findViewById(R.id.tv_account); + etNickName = findViewById(R.id.tv_nickName); + etAge = findViewById(R.id.tv_age); + etEmail = findViewById(R.id.tv_email); + btnSave = findViewById(R.id.btn_save); + mTitleBar = (ActionBar) findViewById(R.id.myActionBar); + mTitleBar.setData(mActivity,"个人信息", R.drawable.ic_back, 0, 0, getResources().getColor(R.color.colorPrimary), new ActionBar.ActionBarClickListener() { + @Override + public void onLeftClick() { + finish(); + } + + @Override + public void onRightClick() { + } + }); + initView(); + } + + private void initView() { + String account = (String) SPUtils.get(mActivity,"account",""); + User user = DataSupport.where("account = ?", account).findFirst(User.class); + if (user != null) { + tvAccount.setText(user.getAccount()); + etNickName.setText(user.getNickName()); + etAge.setText(String.valueOf(user.getAge())); + etEmail.setText(user.getEmail()); + } + //保存 + btnSave.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + String account = tvAccount.getText().toString(); + String nickName = etNickName.getText().toString(); + String age = etAge.getText().toString(); + String email = etEmail.getText().toString(); + User user1 = DataSupport.where("account = ?",account).findFirst(User.class); + if ("".equals(nickName)) { + Toast.makeText(mActivity,"昵称不能为空", Toast.LENGTH_SHORT).show(); + return; + } + if ("".equals(age)) { + Toast.makeText(mActivity,"年龄不能为空", Toast.LENGTH_SHORT).show(); + return; + } + if ("".equals(email)) { + Toast.makeText(mActivity,"邮箱不能为空", Toast.LENGTH_SHORT).show(); + return; + } + user1.setNickName(nickName); + user1.setAge(Integer.valueOf(age)); + user1.setEmail(email); + user1.save(); + Toast.makeText(mActivity,"保存成功", Toast.LENGTH_SHORT).show(); + finish();//关闭页面 + } + }); + /* btnLogout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + MyApplication.Instance.getMainActivity().finish(); + SPUtils.remove(mActivity,"account"); + startActivity(new Intent(mActivity, LoginActivity.class)); + } + });*/ + } +} diff --git a/app/src/main/java/com/example/food/ui/activity/RegisterActivity.java b/app/src/main/java/com/example/food/ui/activity/RegisterActivity.java new file mode 100644 index 0000000..218c538 --- /dev/null +++ b/app/src/main/java/com/example/food/ui/activity/RegisterActivity.java @@ -0,0 +1,125 @@ +package com.example.food.ui.activity; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.Nullable; + +import com.example.food.R; +import com.example.food.bean.User; +import com.example.food.widget.ActionBar; + +import org.litepal.crud.DataSupport; + +import java.text.SimpleDateFormat; + + +/** + * 注册页面 + */ +public class RegisterActivity extends Activity { + private Activity activity; + private ActionBar mTitleBar;//标题栏 + private EditText etAccount;//手机号 + private EditText etNickName;//昵称 + private EditText etAge;//年龄 + private EditText etEmail;//邮箱 + private EditText etPassword;//密码 + private EditText etPasswordSure;//确认密码 + private TextView tvLogin;//登录 + private Button btnRegister;//注册按钮 + private SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + activity=this; + setContentView(R.layout.activity_register);//加载页面 + etAccount =(EditText) findViewById(R.id.et_account);//获取手机号 + etNickName =(EditText) findViewById(R.id.et_nickName);//获取昵称 + etAge =(EditText) findViewById(R.id.et_age);//获取年龄 + etEmail =(EditText) findViewById(R.id.et_email);//获取邮箱 + etPassword=(EditText) findViewById(R.id.et_password);//获取密码 + etPasswordSure=(EditText) findViewById(R.id.et_password_sure);//获取确认密码 + tvLogin=(TextView) findViewById(R.id.tv_login);//登录 + btnRegister=(Button) findViewById(R.id.btn_register);//获取注册按钮 + mTitleBar = (ActionBar) findViewById(R.id.myActionBar); + mTitleBar.setData(activity,"注册", R.drawable.ic_back, 0, 0, getResources().getColor(R.color.colorPrimary), new ActionBar.ActionBarClickListener() { + @Override + public void onLeftClick() { + finish(); + } + + @Override + public void onRightClick() { + } + }); + tvLogin.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //跳转到登录页面 + Intent intent=new Intent(activity, LoginActivity.class); + startActivity(intent); + finish(); + } + }); + //设置注册点击按钮 + btnRegister.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //关闭虚拟键盘 + InputMethodManager inputMethodManager= (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(),0); + String account= etAccount.getText().toString(); + String nickName= etNickName.getText().toString(); + String age = etAge.getText().toString(); + String email= etEmail.getText().toString(); + String password=etPassword.getText().toString(); + String passwordSure=etPasswordSure.getText().toString(); + if ("".equals(account)){//账号不能为空 + Toast.makeText(activity,"账号不能为空", Toast.LENGTH_LONG).show(); + return; + } + if ("".equals(nickName)){//昵称不能为空 + Toast.makeText(activity,"昵称不能为空", Toast.LENGTH_LONG).show(); + return; + } + if ("".equals(age)){//年龄不能为空 + Toast.makeText(activity,"年龄不能为空", Toast.LENGTH_LONG).show(); + return; + } + if ("".equals(email)){//邮箱不能为空 + Toast.makeText(activity,"邮箱不能为空", Toast.LENGTH_LONG).show(); + return; + } + if ("".equals(password)){//密码为空 + Toast.makeText(activity,"密码为空", Toast.LENGTH_LONG).show(); + return; + } + if (!password.equals(passwordSure)){//密码不一致 + Toast.makeText(activity,"密码不一致", Toast.LENGTH_LONG).show(); + return; + } + User user = DataSupport.where("account = ?", account).findFirst(User.class); + if (user == null) { + user = new User (account,password,nickName, Integer.valueOf(age),email); + user.save();//保存用户信息 + Intent intent = new Intent(activity, LoginActivity.class); + startActivity(intent); + Toast.makeText(activity, "注册成功", Toast.LENGTH_SHORT).show(); + finish(); + }else { + Toast.makeText(activity, "该账号已存在", Toast.LENGTH_SHORT).show(); + } + } + }); + } +} diff --git a/app/src/main/java/com/example/food/ui/activity/UserDetailActivity.java b/app/src/main/java/com/example/food/ui/activity/UserDetailActivity.java new file mode 100644 index 0000000..f032805 --- /dev/null +++ b/app/src/main/java/com/example/food/ui/activity/UserDetailActivity.java @@ -0,0 +1,92 @@ +package com.example.food.ui.activity; + +import android.app.Activity; +import android.os.Bundle; +import android.view.View; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; + +import com.example.food.R; +import com.example.food.bean.User; +import com.example.food.widget.ActionBar; + +import org.litepal.crud.DataSupport; + + +/** + * 用户明细 + */ +public class UserDetailActivity extends AppCompatActivity { + private ActionBar mActionBar;//标题栏 + private Activity mActivity; + private TextView account; + private EditText nickName; + private EditText age; + private EditText email; + private User mUser; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_user_detail); + mActivity = this; + account = findViewById(R.id.account); + nickName = findViewById(R.id.nickName); + age = findViewById(R.id.age); + email = findViewById(R.id.email); + mActionBar = findViewById(R.id.myActionBar); + //侧滑菜单 + mActionBar.setData(mActivity,"用户信息", R.drawable.ic_back, 0, 0, getResources().getColor(R.color.colorPrimary), new ActionBar.ActionBarClickListener() { + @Override + public void onLeftClick() { + finish(); + } + + @Override + public void onRightClick() { + } + }); + mUser = (User) getIntent().getSerializableExtra("user"); + if (mUser != null) { + account.setText(mUser.getAccount()); + nickName.setText(mUser.getNickName()); + age.setText(String.valueOf(mUser.getAge())); + email.setText(mUser.getEmail()); + } + } + + //保存 + public void save(View view){ + User user = DataSupport.where("account = ?",mUser.getAccount()).findFirst(User.class); + String nickNameStr = nickName.getText().toString(); + String ageStr = age.getText().toString(); + String emailStr = email.getText().toString(); + if ("".equals(nickNameStr)) { + Toast.makeText(mActivity,"昵称不能为空", Toast.LENGTH_SHORT).show(); + return; + } + if ("".equals(ageStr)) { + Toast.makeText(mActivity,"年龄不能为空", Toast.LENGTH_SHORT).show(); + return; + } + if ("".equals(emailStr)) { + Toast.makeText(mActivity,"邮箱不能为空", Toast.LENGTH_SHORT).show(); + return; + } + if (user != null) { + user.setNickName(nickNameStr); + user.setAge(Integer.valueOf(ageStr)); + user.setEmail(emailStr); + user.save(); + Toast.makeText(mActivity,"保存成功", Toast.LENGTH_SHORT).show(); + finish(); + }else { + Toast.makeText(mActivity,"保存失败", Toast.LENGTH_SHORT).show(); + } + + } +} diff --git a/app/src/main/java/com/example/food/ui/fragment/FruitFragment.java b/app/src/main/java/com/example/food/ui/fragment/FruitFragment.java new file mode 100644 index 0000000..f202158 --- /dev/null +++ b/app/src/main/java/com/example/food/ui/fragment/FruitFragment.java @@ -0,0 +1,195 @@ +package com.example.food.ui.fragment; + +import android.app.Activity; +import android.app.Fragment; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.view.KeyEvent; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.EditorInfo; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.example.food.MyApplication; +import com.example.food.R; +import com.example.food.adapter.FruitAdapter; +import com.example.food.bean.Fruit; +import com.example.food.ui.activity.AddFruitActivity; +import com.example.food.ui.activity.FruitDetailActivity; +import com.example.food.ui.activity.LoginActivity; +import com.example.food.util.SPUtils; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.google.android.material.tabs.TabLayout; + +import org.litepal.crud.DataSupport; + +import java.util.List; + +import static android.app.Activity.RESULT_OK; + + +/** + * 水果 + */ + +public class FruitFragment extends Fragment { + private Activity myActivity;//上下文 + private TabLayout tabTitle; + private RecyclerView rvfruitList; + private FruitAdapter mfruitAdapter; + private LinearLayout llEmpty; + private Boolean mIsAdmin; + private EditText etQuery;//搜索内容 + private ImageView ivSearch;//搜索图标 + private FloatingActionButton btnAdd; + private String[] state = {"0","1","2","3","4","5","6"}; + private String[] title = {"川菜", "鲁菜","粤菜" ,"湘菜","沪菜","京菜","浙菜"}; + private String typeId = "0"; + private List mfruit; + + @Override + public void onAttach(Context context) { + super.onAttach(context); + myActivity= (Activity) context; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view=inflater.inflate(R.layout.fragment_fruit,container,false); + tabTitle = (TabLayout)view.findViewById(R.id.tab_title); + rvfruitList = (RecyclerView)view.findViewById(R.id.rv_fruit_list); + llEmpty = view.findViewById(R.id.ll_empty); + etQuery=view.findViewById(R.id.et_query); + ivSearch=view.findViewById(R.id.iv_search); + btnAdd = (FloatingActionButton)view.findViewById(R.id.btn_add); + //获取控件 + initView(); + //软键盘搜索 + ivSearch.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + loadData();//加载数据 + } + }); + //点击软键盘中的搜索 + etQuery.setOnEditorActionListener(new TextView.OnEditorActionListener() { + @Override + public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { + if (actionId == EditorInfo.IME_ACTION_SEARCH) { + loadData();//加载数据 + return true; + } + return false; + } + }); + btnAdd.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(myActivity, AddFruitActivity.class); + startActivityForResult(intent,100); + } + }); + return view; + } + + /** + * 初始化页面 + */ + private void initView() { + mIsAdmin = (Boolean) SPUtils.get(myActivity, SPUtils.IS_ADMIN, false); + btnAdd.setVisibility(mIsAdmin? View.VISIBLE: View.GONE); + tabTitle.setTabMode(TabLayout.MODE_SCROLLABLE); + //设置tablayout距离上下左右的距离 + //tab_title.setPadding(20,20,20,20); + + //为TabLayout添加tab名称 + for (int i=0;i0){ + rvfruitList.setVisibility(View.VISIBLE); + llEmpty.setVisibility(View.GONE); + mfruitAdapter.addItem(mfruit); + }else { + rvfruitList.setVisibility(View.GONE); + llEmpty.setVisibility(View.VISIBLE); + } + } + @Override + public void onResume() { + super.onResume(); + loadData(); + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == 100 && resultCode == RESULT_OK){ + loadData();//加载数据 + } + } +} diff --git a/app/src/main/java/com/example/food/ui/fragment/OrderFragment.java b/app/src/main/java/com/example/food/ui/fragment/OrderFragment.java new file mode 100644 index 0000000..9beaef5 --- /dev/null +++ b/app/src/main/java/com/example/food/ui/fragment/OrderFragment.java @@ -0,0 +1,131 @@ +package com.example.food.ui.fragment; + +import android.app.Activity; +import android.app.Fragment; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.view.KeyEvent; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.EditorInfo; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.example.food.R; +import com.example.food.adapter.OrderAdapter; +import com.example.food.bean.Orders; +import com.example.food.util.SPUtils; + +import org.litepal.crud.DataSupport; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * 订单 + */ +public class OrderFragment extends Fragment { + private Activity myActivity; + private LinearLayout llEmpty; + private RecyclerView rvOrderList; + public OrderAdapter mOrderAdapter; + private Boolean mIsAdmin; + private EditText etQuery;//搜索内容 + private ImageView ivSearch;//搜索图标 + private List mOrder = new ArrayList<>(); + private String account; + @Override + public void onAttach(Context context) { + super.onAttach(context); + myActivity = (Activity) context; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view=inflater.inflate(R.layout.fragment_order,container,false); + rvOrderList = view.findViewById(R.id.rv_order_list); + llEmpty = view.findViewById(R.id.ll_empty); + etQuery=view.findViewById(R.id.et_query); + ivSearch=view.findViewById(R.id.iv_search); + //获取控件 + initView(); + //软键盘搜索 + ivSearch.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + loadData();//加载数据 + } + }); + //点击软键盘中的搜索 + etQuery.setOnEditorActionListener(new TextView.OnEditorActionListener() { + @Override + public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { + if (actionId == EditorInfo.IME_ACTION_SEARCH) { + loadData();//加载数据 + return true; + } + return false; + } + }); + return view; + } + + private void initView() { + mIsAdmin = (Boolean) SPUtils.get(myActivity, SPUtils.IS_ADMIN, false); + account = (String) SPUtils.get(myActivity, SPUtils.ACCOUNT, ""); + LinearLayoutManager layoutManager=new LinearLayoutManager(myActivity); + //=1.2、设置为垂直排列,用setOrientation方法设置(默认为垂直布局) + layoutManager.setOrientation(LinearLayoutManager.VERTICAL); + //=1.3、设置recyclerView的布局管理器 + rvOrderList.setLayoutManager(layoutManager); + //==2、实例化适配器 + //=2.1、初始化适配器 + mOrderAdapter =new OrderAdapter(llEmpty, rvOrderList); + //=2.3、设置recyclerView的适配器 + rvOrderList.setAdapter(mOrderAdapter); + loadData();//加载数据 + } + + /** + * 加载数据 + */ + private void loadData(){ + String content=etQuery.getText().toString();//获取搜索内容 + if ("".equals(content) && !mIsAdmin){ + mOrder = DataSupport.where("account = ? " ,account).find(Orders.class);//查询全部 + }else { + mOrder =DataSupport.where("number like ? and account != ?" ,"%"+content+"%","admin").find(Orders.class);//通过标题模糊查询留言 + } + Collections.reverse(mOrder); + if (mOrder !=null && mOrder.size()>0){ + rvOrderList.setVisibility(View.VISIBLE); + llEmpty.setVisibility(View.GONE); + mOrderAdapter.addItem(mOrder); + }else { + rvOrderList.setVisibility(View.GONE); + llEmpty.setVisibility(View.VISIBLE); + } + } + + @Override + public void onResume() { + super.onResume(); + loadData(); + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == 100){ + loadData(); + } + } +} diff --git a/app/src/main/java/com/example/food/ui/fragment/UserFragment.java b/app/src/main/java/com/example/food/ui/fragment/UserFragment.java new file mode 100644 index 0000000..f18bed8 --- /dev/null +++ b/app/src/main/java/com/example/food/ui/fragment/UserFragment.java @@ -0,0 +1,90 @@ +package com.example.food.ui.fragment; + +import android.app.Activity; +import android.app.Fragment; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.LinearLayout; + +import com.example.food.MyApplication; +import com.example.food.R; +import com.example.food.ui.activity.BrowseActivity; +import com.example.food.ui.activity.LoginActivity; +import com.example.food.ui.activity.PasswordActivity; +import com.example.food.ui.activity.PersonActivity; +import com.example.food.util.SPUtils; + + +/** + * 个人中心 + */ +public class UserFragment extends Fragment { + private Activity mActivity; + private LinearLayout llPerson; + private LinearLayout llSecurity; + private LinearLayout llBrowse; + private Button btnLogout; + @Override + public void onAttach(Context context) { + super.onAttach(context); + mActivity = (Activity) context; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_user,container,false); + llPerson = view.findViewById(R.id.person); + llSecurity = view.findViewById(R.id.security); + llBrowse = view.findViewById(R.id.browse); + btnLogout = view.findViewById(R.id.logout); + initView(); + return view; + } + + private void initView() { + Boolean isAdmin = (Boolean) SPUtils.get(mActivity,SPUtils.IS_ADMIN,false); + llBrowse.setVisibility(isAdmin? View.GONE: View.VISIBLE); + //个人信息 + llPerson.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //跳转页面 + Intent intent = new Intent(mActivity, PersonActivity.class); + startActivity(intent); + } + }); + //账号安全 + llSecurity.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //跳转页面 + Intent intent = new Intent(mActivity, PasswordActivity.class); + startActivity(intent); + } + }); + //浏览记录 + llBrowse.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //跳转页面 + Intent intent = new Intent(mActivity, BrowseActivity.class); + startActivity(intent); + } + }); + //退出登录 + btnLogout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + MyApplication.Instance.getMainActivity().finish(); + SPUtils.remove(mActivity,SPUtils.IS_ADMIN); + SPUtils.remove(mActivity,SPUtils.ACCOUNT); + startActivity(new Intent(mActivity, LoginActivity.class)); + } + }); + } +} diff --git a/app/src/main/java/com/example/food/ui/fragment/UserManageFragment.java b/app/src/main/java/com/example/food/ui/fragment/UserManageFragment.java new file mode 100644 index 0000000..82dbada --- /dev/null +++ b/app/src/main/java/com/example/food/ui/fragment/UserManageFragment.java @@ -0,0 +1,128 @@ +package com.example.food.ui.fragment; + +import android.app.Activity; +import android.app.Fragment; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.view.KeyEvent; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.EditorInfo; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.example.food.R; +import com.example.food.adapter.UserAdapter; +import com.example.food.bean.User; +import com.google.android.material.floatingactionbutton.FloatingActionButton; + +import org.litepal.crud.DataSupport; + +import java.util.Collections; +import java.util.List; + + +/** + * 用户管理 + */ +public class UserManageFragment extends Fragment { + private Activity myActivity; + private LinearLayout llEmpty; + private RecyclerView rvUserList; + public UserAdapter mUserAdapter; + private FloatingActionButton btnAdd; + private EditText etQuery;//搜索内容 + private ImageView ivSearch;//搜索图标 + private List mUsers; + @Override + public void onAttach(Context context) { + super.onAttach(context); + myActivity = (Activity) context; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view=inflater.inflate(R.layout.fragment_user_manage,container,false); + rvUserList = view.findViewById(R.id.rv_user_list); + llEmpty = view.findViewById(R.id.ll_empty); + etQuery=view.findViewById(R.id.et_query); + ivSearch=view.findViewById(R.id.iv_search); + //获取控件 + initView(); + //软键盘搜索 + ivSearch.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + loadData();//加载数据 + } + }); + //点击软键盘中的搜索 + etQuery.setOnEditorActionListener(new TextView.OnEditorActionListener() { + @Override + public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { + if (actionId == EditorInfo.IME_ACTION_SEARCH) { + loadData();//加载数据 + return true; + } + return false; + } + }); + return view; + } + + private void initView() { + LinearLayoutManager layoutManager=new LinearLayoutManager(myActivity); + //=1.2、设置为垂直排列,用setOrientation方法设置(默认为垂直布局) + layoutManager.setOrientation(LinearLayoutManager.VERTICAL); + //=1.3、设置recyclerView的布局管理器 + rvUserList.setLayoutManager(layoutManager); + //==2、实例化适配器 + //=2.1、初始化适配器 + mUserAdapter=new UserAdapter(llEmpty, rvUserList); + //=2.3、设置recyclerView的适配器 + rvUserList.setAdapter(mUserAdapter); + loadData(); + } + + /** + * 加载数据 + */ + private void loadData(){ + String content=etQuery.getText().toString();//获取搜索内容 + if ("".equals(content)){ + mUsers= DataSupport.where("account != ?","admin").find(User.class);//查询全部 + }else { + mUsers=DataSupport.where("account like ?","%"+content+"%").find(User.class);//通过账号模糊查询用户 + } + Collections.reverse(mUsers); + if (mUsers !=null && mUsers.size()>0){ + rvUserList.setVisibility(View.VISIBLE); + llEmpty.setVisibility(View.GONE); + mUserAdapter.addItem(mUsers); + }else { + rvUserList.setVisibility(View.GONE); + llEmpty.setVisibility(View.VISIBLE); + } + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == 100){ + initView(); + } + } + + @Override + public void onResume() { + super.onResume(); + loadData(); + } +} diff --git a/app/src/main/java/com/example/food/util/SPUtils.java b/app/src/main/java/com/example/food/util/SPUtils.java new file mode 100644 index 0000000..213224b --- /dev/null +++ b/app/src/main/java/com/example/food/util/SPUtils.java @@ -0,0 +1,176 @@ +package com.example.food.util; + +import android.content.Context; +import android.content.SharedPreferences; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Map; + +/** + * 数据持久化工具类 + */ +public class SPUtils { + public static final String IF_FIRST = "is_first";//是否第一次进来 + public static final String IS_ADMIN = "is_admin";//是否是管理员 + public static final String ACCOUNT = "account";//账号 + /** + * 保存在手机里面的文件名 + */ + private static final String FILE_NAME = "share_data"; + /** + * 保存数据的方法,我们需要拿到保存数据的具体类型,然后根据类型调用不同的保存方法 + * + * @param context 上下文 + * @param key key值 + * @param object value值 + */ + public static void put(Context context, String key, Object object) { + + SharedPreferences sp = context.getSharedPreferences(FILE_NAME, + Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sp.edit(); + + if (object instanceof String) { + editor.putString(key, (String) object); + } else if (object instanceof Integer) { + editor.putInt(key, (Integer) object); + } else if (object instanceof Boolean) { + editor.putBoolean(key, (Boolean) object); + } else if (object instanceof Float) { + editor.putFloat(key, (Float) object); + } else if (object instanceof Long) { + editor.putLong(key, (Long) object); + } else { + editor.putString(key, object.toString()); + } + + SharedPreferencesCompat.apply(editor); + } + + /** + * 得到保存数据的方法,我们根据默认值得到保存的数据的具体类型,然后调用相对于的方法获取值 + * + * @param context 上下文 + * @param key key值 + * @param defaultObject 默认value值 + * @return value值 + */ + public static Object get(Context context, String key, Object defaultObject) { + SharedPreferences sp = context.getSharedPreferences(FILE_NAME, + Context.MODE_PRIVATE); + + if (defaultObject instanceof String) { + return sp.getString(key, (String) defaultObject); + } else if (defaultObject instanceof Integer) { + return sp.getInt(key, (Integer) defaultObject); + } else if (defaultObject instanceof Boolean) { + return sp.getBoolean(key, (Boolean) defaultObject); + } else if (defaultObject instanceof Float) { + return sp.getFloat(key, (Float) defaultObject); + } else if (defaultObject instanceof Long) { + return sp.getLong(key, (Long) defaultObject); + } + + return null; + } + + /** + * 移除某个key值已经对应的值 + * + * @param context 上下文 + * @param key key值 + */ + public static void remove(Context context, String key) { + SharedPreferences sp = context.getSharedPreferences(FILE_NAME, + Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sp.edit(); + editor.remove(key); + SharedPreferencesCompat.apply(editor); + } + + /** + * 清除所有数据 + * + * @param context 上下文 + */ + public static void clear(Context context) { + SharedPreferences sp = context.getSharedPreferences(FILE_NAME, + Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sp.edit(); + editor.clear(); + SharedPreferencesCompat.apply(editor); + } + + /** + * 查询某个key是否已经存在 + * + * @param context 上下文 + * @param key key值 + * @return 是否存在 + */ + public static boolean contains(Context context, String key) { + SharedPreferences sp = context.getSharedPreferences(FILE_NAME, + Context.MODE_PRIVATE); + return sp.contains(key); + } + + /** + * 返回所有的键值对 + * + * @param context 上下文 + * @return 所有的键值对 + */ + public static Map getAll(Context context) { + SharedPreferences sp = context.getSharedPreferences(FILE_NAME, + Context.MODE_PRIVATE); + return sp.getAll(); + } + + /** + * 创建一个解决SharedPreferencesCompat.apply方法的一个兼容类 + * + * @author zhy + */ + private static class SharedPreferencesCompat { + private static final Method sApplyMethod = findApplyMethod(); + + /** + * 反射查找apply的方法 + * + * @return Method + */ + @SuppressWarnings({"unchecked", "rawtypes"}) + private static Method findApplyMethod() { + try { + Class clz = SharedPreferences.Editor.class; + return clz.getMethod("apply"); + } catch (NoSuchMethodException e) { + } + + return null; + } + + /** + * 如果找到则使用apply执行,否则使用commit + * + * @param editor SharedPreferences.Edito + */ + public static void apply(SharedPreferences.Editor editor) { + try { + if (sApplyMethod != null) { + sApplyMethod.invoke(editor); + return; + } + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + editor.commit(); + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/food/util/StatusBarUtil.java b/app/src/main/java/com/example/food/util/StatusBarUtil.java new file mode 100644 index 0000000..8de888f --- /dev/null +++ b/app/src/main/java/com/example/food/util/StatusBarUtil.java @@ -0,0 +1,212 @@ +package com.example.food.util; + +import android.annotation.TargetApi; +import android.app.Activity; +import android.content.Context; +import android.graphics.Color; +import android.os.Build; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; +import android.view.WindowManager; + +import com.example.food.R; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +/** + * 全屏显示 状态栏工具类 + */ +public class StatusBarUtil { + /** + * 修改当前 Activity 的显示模式,hideStatusBarBackground :true 全屏模式,false 着色模式 + * + * @param activity + * @param hideStatusBarBackground + */ + public static void setStatusBar(Activity activity, boolean hideStatusBarBackground) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + Window window = activity.getWindow(); + window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); + if (hideStatusBarBackground) { + window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); + } else { + window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); + } + + ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT); + View mChildView = mContentView.getChildAt(0); + if (mChildView != null) { + if (hideStatusBarBackground) { + mChildView.setPadding( + mChildView.getPaddingLeft(), + 0, + mChildView.getPaddingRight(), + mChildView.getPaddingBottom() + ); + } else { + int statusHeight = getStatusBarHeight(activity); + mChildView.setPadding( + mChildView.getPaddingLeft(), + statusHeight, + mChildView.getPaddingRight(), + mChildView.getPaddingBottom() + ); + } + } + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + Window window = activity.getWindow(); + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + if (hideStatusBarBackground) { + window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); + window.setStatusBarColor(Color.TRANSPARENT); + window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); + } else { + window.setStatusBarColor(activity.getResources().getColor(R.color.colorPrimary)); + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); + } + } + } + /** + * 获取手机状态栏高度 + */ + public static int getStatusBarHeight(Context context) { + int result = 0; + int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android"); + if (resourceId > 0) { + result = context.getResources().getDimensionPixelSize(resourceId); + } + return result; + } + /** + *设置状态栏颜色 + */ + /* public static void setStatusBarColor(Activity activity, int colorId) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + Window window = activity.getWindow(); + window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + window.setStatusBarColor(activity.getResources().getColor(colorId)); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + //使用SystemBarTint库使4.4版本状态栏变色,需要先将状态栏设置为透明 + transparentBar(activity); + SystemBarTintManager tintManager = new SystemBarTintManager(activity); + tintManager.setStatusBarTintEnabled(true); + tintManager.setStatusBarTintResource(colorId); + } + }*/ + @TargetApi(19) + public static void transparentBar(Activity activity) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + Window window = activity.getWindow(); + window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + window.setStatusBarColor(Color.TRANSPARENT); + window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); + + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + Window window = activity.getWindow(); + window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, + WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); + } + } + /** + * 设置状态栏文字颜色 true 为黑色 false 为白色(XML跟布局配置 android:fitsSystemWindows="true",否则布局会上移) + */ + public static void setStatusBarLightMode(Activity activity, boolean dark) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + if (dark) { // + if (MIUISetStatusBarLightMode(activity, dark)) { + } else if (FlymeSetStatusBarLightMode(activity.getWindow(), dark)) { + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + //其他 + activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); + } + } else { + if (MIUISetStatusBarLightMode(activity, dark)) { + } else if (FlymeSetStatusBarLightMode(activity.getWindow(), dark)) { + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); + } + } + } + } + /** + * 设置状态栏图标为深色和魅族特定的文字风格 + * 可以用来判断是否为Flyme用户 + * + * @param window 需要设置的窗口 + * @param dark 是否把状态栏文字及图标颜色设置为深色 + * @return boolean 成功执行返回true + */ + public static boolean FlymeSetStatusBarLightMode(Window window, boolean dark) { + boolean result = false; + if (window != null) { + try { + WindowManager.LayoutParams lp = window.getAttributes(); + Field darkFlag = WindowManager.LayoutParams.class + .getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON"); + Field meizuFlags = WindowManager.LayoutParams.class + .getDeclaredField("meizuFlags"); + darkFlag.setAccessible(true); + meizuFlags.setAccessible(true); + int bit = darkFlag.getInt(null); + int value = meizuFlags.getInt(lp); + if (dark) { + value |= bit; + } else { + value &= ~bit; + } + meizuFlags.setInt(lp, value); + window.setAttributes(lp); + result = true; + } catch (Exception e) { + + } + } + return result; + } + + /** + * 需要MIUIV6以上 + * + * @param activity + * @param dark 是否把状态栏文字及图标颜色设置为深色 + * @return boolean 成功执行返回true + */ + public static boolean MIUISetStatusBarLightMode(Activity activity, boolean dark) { + boolean result = false; + Window window = activity.getWindow(); + if (window != null) { + Class clazz = window.getClass(); + try { + int darkModeFlag = 0; + Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams"); + Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE"); + darkModeFlag = field.getInt(layoutParams); + Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class); + if (dark) { + extraFlagField.invoke(window, darkModeFlag, darkModeFlag);//状态栏透明且黑色字体 + } else { + extraFlagField.invoke(window, 0, darkModeFlag);//清除黑色字体 + } + result = true; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + //开发版 7.7.13 及以后版本采用了系统API,旧方法无效但不会报错,所以两个方式都要加上 + if (dark) { + activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); + } else { + activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); + } + } + } catch (Exception e) { + } + } + return result; + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/food/widget/ActionBar.java b/app/src/main/java/com/example/food/widget/ActionBar.java new file mode 100644 index 0000000..5566f3a --- /dev/null +++ b/app/src/main/java/com/example/food/widget/ActionBar.java @@ -0,0 +1,307 @@ +package com.example.food.widget; + + +import android.app.Activity; +import android.content.Context; +import android.graphics.Color; +import android.text.TextUtils; +import android.util.AttributeSet; +import android.view.View; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.core.graphics.ColorUtils; + +import com.example.food.R; + + +/** + * 自定义ActionBar + */ +public final class ActionBar extends LinearLayout { + + private LinearLayout llActionbarRoot;//自定义ActionBar根节点 + private View vStatusBar;//状态栏位置 + private ImageView ivLeft;//左边图标 + private TextView tvLeft;//左边 + private TextView tvTitle;//中间标题 + private ImageView ivRight;//右边图标 + private Button btnRight;//右边按钮 + private TextView tvRight;//右边文字 + public ActionBar(Context context) { + this(context, null); + } + + public ActionBar(Context context, AttributeSet attrs) { + super(context, attrs); + init(context); + + } + + /** + * 设置标题 + * @param title + */ + public void setTitle(String title){ + if (!TextUtils.isEmpty(title)) { + tvTitle.setText(title); + } else { + tvTitle.setVisibility(View.GONE); + } + } + + /** + * 设置左侧文本 + * @param text + */ + public void setLeftText(String text){ + if (!TextUtils.isEmpty(text)) { + tvLeft.setText(text); + tvLeft.setVisibility(View.VISIBLE); + } else { + tvLeft.setVisibility(View.GONE); + } + } + + /** + * 设置左侧图标 + * @param ico + */ + public void setLeftIco(int ico){ + if (ico!=0) { + ivLeft.setImageResource(ico); + ivLeft.setVisibility(View.VISIBLE); + } else { + ivLeft.setVisibility(View.GONE); + } + } + + + /** + * 设置右侧文本 + * @param text + */ + public void setRightText(String text){ + if (!TextUtils.isEmpty(text)) { + tvRight.setText(text); + tvRight.setVisibility(View.VISIBLE); + } else { + tvRight.setVisibility(View.GONE); + } + } + + /** + * 设置右侧btn + * @param text + */ + public void setRightBtn(String text){ + if (!TextUtils.isEmpty(text)) { + btnRight.setText(text); + btnRight.setVisibility(View.VISIBLE); + } else { + btnRight.setVisibility(View.GONE); + } + } + + /** + * 设置右侧图标 + * @param ico + */ + public void setRightIco(int ico){ + if (ico!=0) { + ivRight.setImageResource(ico); + ivRight.setVisibility(View.VISIBLE); + } else { + ivRight.setVisibility(View.GONE); + } + } + + private void init(Context context) { + setOrientation(HORIZONTAL);//设置横向布局 + View contentView = inflate(getContext(), R.layout.widget_actionbar, this); + //获取控件 + llActionbarRoot = (LinearLayout)contentView.findViewById(R.id.ll_actionbar_root); + vStatusBar = contentView.findViewById(R.id.v_statusbar); + ivLeft = (ImageView)contentView.findViewById(R.id.iv_actionbar_left); + tvLeft=(TextView) contentView.findViewById(R.id.tv_actionbar_left); + tvTitle =(TextView) contentView.findViewById(R.id.tv_actionbar_title); + ivRight =(ImageView) contentView.findViewById(R.id.iv_actionbar_right); + btnRight=(Button) contentView.findViewById(R.id.btn_actionbar_right); + tvRight=(TextView) contentView.findViewById(R.id.tv_actionbar_right); + } + + /** + * 设置透明度 + * + * @param transAlpha{Integer} 0-255 之间 + */ + public void setTranslucent(int transAlpha) { + //设置透明度 + llActionbarRoot.setBackgroundColor(ColorUtils.setAlphaComponent(getResources().getColor(R.color.colorPrimary), transAlpha)); + tvTitle.setAlpha(transAlpha); + ivLeft.setAlpha(transAlpha); + ivRight.setAlpha(transAlpha); + } + /** + * 设置数据 + * + * @param strTitle 标题 + * @param resIdLeft 左边图标资源 + * @param resIdRight 右边图标资源 + * @param intColor 内容颜色 0为白色 1为黑色 + * @param backgroundColor 背景颜色 + * @param listener 点击事件监听 + */ + public void setData(String strTitle, int resIdLeft, int resIdRight, int intColor, int backgroundColor, final ActionBarClickListener listener) { + String textColor=intColor==0?"#FFFFFF":"#000000"; + if (!TextUtils.isEmpty(strTitle)) { + tvTitle.setText(strTitle); + tvTitle.setTextColor(Color.parseColor(textColor)); + } else { + tvTitle.setVisibility(View.GONE); + } + if (resIdLeft == 0) { + ivLeft.setVisibility(View.GONE); + } else { + ivLeft.setBackgroundResource(resIdLeft); + ivLeft.setVisibility(View.VISIBLE); + } + if (resIdRight == 0) { + ivRight.setVisibility(View.GONE); + } else { + ivRight.setBackgroundResource(resIdRight); + ivRight.setVisibility(View.VISIBLE); + } + + if (backgroundColor==0){ + llActionbarRoot.setBackgroundResource(0); + }else { + llActionbarRoot.setBackgroundColor(backgroundColor);//设置标题栏背景颜色 + } + if (listener != null) { + ivLeft.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + listener.onLeftClick(); + } + }); + ivRight.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + listener.onRightClick(); + } + }); + } + } + public void setData(Activity context, String strTitle, int resIdLeft, int resIdRight, int intColor, int backgroundColor, final ActionBarClickListener listener) { + String textColor=intColor==0?"#FFFFFF":"#000000"; + if (!TextUtils.isEmpty(strTitle)) { + tvTitle.setText(strTitle); + tvTitle.setTextColor(Color.parseColor(textColor)); + } else { + tvTitle.setVisibility(View.GONE); + } + if (resIdLeft == 0) { + ivLeft.setVisibility(View.GONE); + } else { + ivLeft.setBackgroundResource(resIdLeft); + ivLeft.setVisibility(View.VISIBLE); + } + if (resIdRight == 0) { + ivRight.setVisibility(View.GONE); + } else { + ivRight.setBackgroundResource(resIdRight); + ivRight.setVisibility(View.VISIBLE); + } + + if (backgroundColor==0){ + llActionbarRoot.setBackgroundResource(0); + }else { + llActionbarRoot.setBackgroundColor(backgroundColor);//设置标题栏背景颜色 + } + if (listener != null) { + ivLeft.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + listener.onLeftClick(); + } + }); + ivRight.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + listener.onRightClick(); + } + }); + } + } + + public void setData(String strTitle, int resIdLeft, String strRight, int intColor, int backgroundColor, final ActionBarClickListener listener) { + String textColor=intColor==0?"#FFFFFF":"#000000"; + if (!TextUtils.isEmpty(strTitle)) { + tvTitle.setText(strTitle); + tvTitle.setTextColor(Color.parseColor(textColor)); + } else { + tvTitle.setVisibility(View.GONE); + } + if (resIdLeft == 0) { + ivLeft.setVisibility(View.GONE); + } else { + ivLeft.setBackgroundResource(resIdLeft); + ivLeft.setVisibility(View.VISIBLE); + } + if (!TextUtils.isEmpty(strRight)) { + btnRight.setText(strRight); + btnRight.setVisibility(View.VISIBLE); + } else { + btnRight.setVisibility(View.GONE); + } + if (backgroundColor==0){ + llActionbarRoot.setBackgroundResource(0); + }else { + llActionbarRoot.setBackgroundColor(backgroundColor);//设置标题栏背景颜色 + } + if (listener != null) { + if(ivLeft.getVisibility()==VISIBLE){ + ivLeft.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + listener.onLeftClick(); + } + }); + }else if(tvLeft.getVisibility()==VISIBLE){ + tvLeft.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + listener.onLeftClick(); + } + }); + } + + + if(btnRight.getVisibility()==VISIBLE){ + btnRight.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + listener.onRightClick(); + } + }); + }else if(tvRight.getVisibility()==VISIBLE){ + tvRight.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + listener.onRightClick(); + } + }); + } + + } + } + public interface ActionBarClickListener { + //左边点击 + void onLeftClick(); + //右边点击 + void onRightClick(); + } +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_border_bottom.xml b/app/src/main/res/drawable/bg_border_bottom.xml new file mode 100644 index 0000000..6cc85d7 --- /dev/null +++ b/app/src/main/res/drawable/bg_border_bottom.xml @@ -0,0 +1,12 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_border_top.xml b/app/src/main/res/drawable/bg_border_top.xml new file mode 100644 index 0000000..6d55a27 --- /dev/null +++ b/app/src/main/res/drawable/bg_border_top.xml @@ -0,0 +1,13 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_ripple.xml b/app/src/main/res/drawable/bg_ripple.xml new file mode 100644 index 0000000..8196e32 --- /dev/null +++ b/app/src/main/res/drawable/bg_ripple.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_round_white.xml b/app/src/main/res/drawable/bg_round_white.xml new file mode 100644 index 0000000..f21b914 --- /dev/null +++ b/app/src/main/res/drawable/bg_round_white.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/btn_border_fill.xml b/app/src/main/res/drawable/btn_border_fill.xml new file mode 100644 index 0000000..679e3d7 --- /dev/null +++ b/app/src/main/res/drawable/btn_border_fill.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/app/src/main/res/drawable/btn_border_fill_enabled.xml b/app/src/main/res/drawable/btn_border_fill_enabled.xml new file mode 100644 index 0000000..5799fad --- /dev/null +++ b/app/src/main/res/drawable/btn_border_fill_enabled.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/app/src/main/res/drawable/btn_border_radius_fill_gray.xml b/app/src/main/res/drawable/btn_border_radius_fill_gray.xml new file mode 100644 index 0000000..01c37c3 --- /dev/null +++ b/app/src/main/res/drawable/btn_border_radius_fill_gray.xml @@ -0,0 +1,8 @@ + + + + + + + diff --git a/app/src/main/res/drawable/ic_add.png b/app/src/main/res/drawable/ic_add.png new file mode 100644 index 0000000..b364668 Binary files /dev/null and b/app/src/main/res/drawable/ic_add.png differ diff --git a/app/src/main/res/drawable/ic_back.png b/app/src/main/res/drawable/ic_back.png new file mode 100644 index 0000000..14d7a52 Binary files /dev/null and b/app/src/main/res/drawable/ic_back.png differ diff --git a/app/src/main/res/drawable/ic_browse.png b/app/src/main/res/drawable/ic_browse.png new file mode 100644 index 0000000..57d9df6 Binary files /dev/null and b/app/src/main/res/drawable/ic_browse.png differ diff --git a/app/src/main/res/drawable/ic_buy.png b/app/src/main/res/drawable/ic_buy.png new file mode 100644 index 0000000..f7ed474 Binary files /dev/null and b/app/src/main/res/drawable/ic_buy.png differ diff --git a/app/src/main/res/drawable/ic_buy_check.png b/app/src/main/res/drawable/ic_buy_check.png new file mode 100644 index 0000000..83ed900 Binary files /dev/null and b/app/src/main/res/drawable/ic_buy_check.png differ diff --git a/app/src/main/res/drawable/ic_empty.png b/app/src/main/res/drawable/ic_empty.png new file mode 100644 index 0000000..a78bcb0 Binary files /dev/null and b/app/src/main/res/drawable/ic_empty.png differ diff --git a/app/src/main/res/drawable/ic_error.png b/app/src/main/res/drawable/ic_error.png new file mode 100644 index 0000000..2b30898 Binary files /dev/null and b/app/src/main/res/drawable/ic_error.png differ diff --git a/app/src/main/res/drawable/ic_favorite.png b/app/src/main/res/drawable/ic_favorite.png new file mode 100644 index 0000000..48b30ef Binary files /dev/null and b/app/src/main/res/drawable/ic_favorite.png differ diff --git a/app/src/main/res/drawable/ic_go.png b/app/src/main/res/drawable/ic_go.png new file mode 100644 index 0000000..539d327 Binary files /dev/null and b/app/src/main/res/drawable/ic_go.png differ diff --git a/app/src/main/res/drawable/ic_home.png b/app/src/main/res/drawable/ic_home.png new file mode 100644 index 0000000..72b80fb Binary files /dev/null and b/app/src/main/res/drawable/ic_home.png differ diff --git a/app/src/main/res/drawable/ic_home_check.png b/app/src/main/res/drawable/ic_home_check.png new file mode 100644 index 0000000..edb59c4 Binary files /dev/null and b/app/src/main/res/drawable/ic_home_check.png differ diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_logo.png b/app/src/main/res/drawable/ic_logo.png new file mode 100644 index 0000000..0a3b6d0 Binary files /dev/null and b/app/src/main/res/drawable/ic_logo.png differ diff --git a/app/src/main/res/drawable/ic_manage.png b/app/src/main/res/drawable/ic_manage.png new file mode 100644 index 0000000..9a9b8f1 Binary files /dev/null and b/app/src/main/res/drawable/ic_manage.png differ diff --git a/app/src/main/res/drawable/ic_manage_check.png b/app/src/main/res/drawable/ic_manage_check.png new file mode 100644 index 0000000..18fd6ef Binary files /dev/null and b/app/src/main/res/drawable/ic_manage_check.png differ diff --git a/app/src/main/res/drawable/ic_person.png b/app/src/main/res/drawable/ic_person.png new file mode 100644 index 0000000..7ca59c4 Binary files /dev/null and b/app/src/main/res/drawable/ic_person.png differ diff --git a/app/src/main/res/drawable/ic_right.png b/app/src/main/res/drawable/ic_right.png new file mode 100644 index 0000000..e6e167b Binary files /dev/null and b/app/src/main/res/drawable/ic_right.png differ diff --git a/app/src/main/res/drawable/ic_search_gray.png b/app/src/main/res/drawable/ic_search_gray.png new file mode 100644 index 0000000..baefd29 Binary files /dev/null and b/app/src/main/res/drawable/ic_search_gray.png differ diff --git a/app/src/main/res/drawable/ic_security.png b/app/src/main/res/drawable/ic_security.png new file mode 100644 index 0000000..219e92b Binary files /dev/null and b/app/src/main/res/drawable/ic_security.png differ diff --git a/app/src/main/res/drawable/ic_user.png b/app/src/main/res/drawable/ic_user.png new file mode 100644 index 0000000..ba7689b Binary files /dev/null and b/app/src/main/res/drawable/ic_user.png differ diff --git a/app/src/main/res/drawable/ic_user_check.png b/app/src/main/res/drawable/ic_user_check.png new file mode 100644 index 0000000..3a7a272 Binary files /dev/null and b/app/src/main/res/drawable/ic_user_check.png differ diff --git a/app/src/main/res/drawable/selector_main_rb_buy.xml b/app/src/main/res/drawable/selector_main_rb_buy.xml new file mode 100644 index 0000000..81c3050 --- /dev/null +++ b/app/src/main/res/drawable/selector_main_rb_buy.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/selector_main_rb_home.xml b/app/src/main/res/drawable/selector_main_rb_home.xml new file mode 100644 index 0000000..7e3c375 --- /dev/null +++ b/app/src/main/res/drawable/selector_main_rb_home.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/selector_main_rb_manage.xml b/app/src/main/res/drawable/selector_main_rb_manage.xml new file mode 100644 index 0000000..c4d3c2d --- /dev/null +++ b/app/src/main/res/drawable/selector_main_rb_manage.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/selector_main_rb_text.xml b/app/src/main/res/drawable/selector_main_rb_text.xml new file mode 100644 index 0000000..ddfd02c --- /dev/null +++ b/app/src/main/res/drawable/selector_main_rb_text.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/selector_main_rb_user.xml b/app/src/main/res/drawable/selector_main_rb_user.xml new file mode 100644 index 0000000..be28f20 --- /dev/null +++ b/app/src/main/res/drawable/selector_main_rb_user.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_browse.xml b/app/src/main/res/layout/activity_browse.xml new file mode 100644 index 0000000..785ff60 --- /dev/null +++ b/app/src/main/res/layout/activity_browse.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_fruit_add.xml b/app/src/main/res/layout/activity_fruit_add.xml new file mode 100644 index 0000000..1568764 --- /dev/null +++ b/app/src/main/res/layout/activity_fruit_add.xml @@ -0,0 +1,172 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +