diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0deda79 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2017 Zhao Weihao + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..2633545 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# Second-hand transactions + +# 校园二手交易 + +## 总结 + +总结:这是我大半年前学校移动开发课的期末作业,一开始是做的校园社区APP,后来修改为校园二手交易,由于需求的变化和之前的水平比较水,当时又是刚开始学Kotlin就拿来用了,并且还没有学习架构,所以这个项目的整体结构比较混乱,代码比较难看🤢;但是还是留着做个纪念吧,毕竟这个APP也让我学习到了蛮多东西的,让我认识到写优秀代码的重要性,让我知道我有哪里的不足,同时也让我深度体验了一回Bmob后端云SDK的运用;在不会后端的前提下,运用后端云SDK蛮方便就是受制于SDK的功能性,SDK有提供就有没有就没有,这也是让我非常惆怅的。还是有闲的话自己搞后端比较好。推荐使用[Blade](https://github.com/lets-blade/blade)(Java)做简单的后端API,我上手了一下感觉很容易入门,非常适合我。好了~,要继续提升自己了。多看看别人优秀的代码后发现自己写的真的好水啊。。。 + +## 运行截图 + +| 主界面 | 公开评论界面 | 实时聊天界面 | 消息界面 | +| :-----------------------------: | :-------------------------------------: | :-------------------------------------: | :---------------------------------: | +| ![主界面](./art/主界面.png) | ![公开评论界面](./art/公开评论界面.png) | ![实时聊天界面](./art/实时聊天界面.png) | ![消息页面后](./art/消息页面后.png) | +| **翻译功能** | **天气功能** | **云笔记功能** | **登录界面** | +| ![翻译界面](./art/翻译界面.png) | ![天气界面](./art/天气界面.png) | ![云笔记界面](./art/云笔记界面.png) | ![登录界面](./art/登录界面.png) | + +## 关于我 + +简要介绍:一个大三的有志小青年,梦想是改变世界(Change the world),哈哈😄,梦想很伟大。从小事一点点做起吧,做个对社会有贡献的人就好了。 + +如何找到我:📮邮箱:zhaoweihao.dev@gmail.com(自从发现foxmail不能收到某些邮件我就果断改用gmail了) + +状态:目前可以接受暑期实习,大概七月份左右可以实习,这段时间我会尽量提升自己,如果有大佬看上我,可以给我个机会,非常期待你的邮件。 + +附上简历📖:[简历](http://zhaoweihao.com/resume/xxx.pdf) + + + +## 谢谢! \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/app.iml b/app/app.iml new file mode 100644 index 0000000..5080caf --- /dev/null +++ b/app/app.iml @@ -0,0 +1,200 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..d93b0c8 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,60 @@ +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' + +android { + compileSdkVersion 26 + buildToolsVersion "26.0.2" + useLibrary 'org.apache.http.legacy' + defaultConfig { + applicationId "me.zhaoweihao.hnuplus" + minSdkVersion 19 + targetSdkVersion 26 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + vectorDrawables.useSupportLibrary = true + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation 'com.android.support.constraint:constraint-layout:1.0.2' + compile fileTree(dir: 'libs', include: ['*.jar']) + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + compile 'com.android.support:appcompat-v7:26.1.0' + compile 'cn.bmob.android:bmob-im:2.0.9@aar' + compile 'cn.bmob.android:bmob-sdk:3.5.5' + compile 'org.greenrobot:eventbus:3.0.0' + compile 'cn.bmob.android:http-legacy:1.0' + compile 'com.android.support:recyclerview-v7:26.1.0' + compile 'com.android.support:cardview-v7:26.1.0' + compile 'de.hdodenhof:circleimageview:2.2.0' + compile 'com.android.support:design:26.1.0' + compile 'com.yalantis:phoenix:1.2.3' + compile 'com.rengwuxian.materialedittext:library:2.1.4' + compile 'com.jakewharton:butterknife:8.8.1' + compile "org.jetbrains.anko:anko-commons:0.10.2" + compile 'com.github.yoavst:androidKotlin:1.5.1' + compile 'com.zhihu.android:matisse:0.4.3' + compile 'com.github.bumptech.glide:glide:3.7.0' + compile 'com.github.chrisbanes:PhotoView:2.1.3' + compile 'nl.dionsegijn:konfetti:1.1.0' + compile 'com.github.pwittchen:weathericonview:1.1.0' + compile 'com.taishi-y:flipprogressdialog:0.1.0' + compile 'com.lzy.widget:ninegridview:0.2.0' + implementation 'com.squareup.picasso:picasso:2.5.2' + annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' + testCompile 'junit:junit:4.12' + compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" +} +repositories { + mavenCentral() +} diff --git a/app/libs/TencentLocationSdk_v6.2.5.3_r15b3b3cc_20171103_115903.jar b/app/libs/TencentLocationSdk_v6.2.5.3_r15b3b3cc_20171103_115903.jar new file mode 100644 index 0000000..45341f9 Binary files /dev/null and b/app/libs/TencentLocationSdk_v6.2.5.3_r15b3b3cc_20171103_115903.jar differ diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..4bb608d --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,29 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Users\Administrator\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# 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 *; +#} +-dontwarn com.squareup.picasso.** + +-keepclassmembers class ** { + public void on*Event(...); +} +-keep class c.t.**{*;} +-keep class com.tencent.map.geolocation.**{*;} +-keep class com.tencent.tencentmap.lbssdk.service.**{*;} + + +-dontwarn org.eclipse.jdt.annotation.** +-dontwarn c.t.** \ No newline at end of file diff --git a/app/release/output.json b/app/release/output.json new file mode 100644 index 0000000..c1074e5 --- /dev/null +++ b/app/release/output.json @@ -0,0 +1 @@ +[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1},"path":"app-release.apk","properties":{"packageId":"me.zhaoweihao.hnuplus","split":"","minSdkVersion":"19"}}] \ No newline at end of file diff --git a/app/src/androidTest/java/me/zhaoweihao/hnuplus/ExampleInstrumentedTest.kt b/app/src/androidTest/java/me/zhaoweihao/hnuplus/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..9e68e4a --- /dev/null +++ b/app/src/androidTest/java/me/zhaoweihao/hnuplus/ExampleInstrumentedTest.kt @@ -0,0 +1,27 @@ +package me.zhaoweihao.hnuplus + +import android.content.Context +import android.support.test.InstrumentationRegistry +import android.support.test.runner.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumentation test, which will execute on an Android device. + + * @see [Testing documentation](http://d.android.com/tools/testing) + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + @Throws(Exception::class) + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getTargetContext() + + assertEquals("me.zhaoweihao.hnuplus", appContext.packageName) + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..ef2ba86 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Adapter/CommentAdapter.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Adapter/CommentAdapter.kt new file mode 100644 index 0000000..38c99f2 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Adapter/CommentAdapter.kt @@ -0,0 +1,59 @@ +package me.zhaoweihao.hnuplus.Adapter + +import android.content.Context +import android.support.v7.widget.RecyclerView +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView +import com.squareup.picasso.Picasso + +import me.zhaoweihao.hnuplus.Bmob.Comment +import me.zhaoweihao.hnuplus.R + +/** + * Created by ZhaoWeihao on 2017/11/10. + */ + +/** + * Show comment's data to recyclerview + */ +class CommentAdapter(private val mCommentList: List) : RecyclerView.Adapter() { + + companion object { + private val TAG = "CommentAdapter" + } + + private var mContext: Context? = null + + class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var commentatorName = view.findViewById(R.id.tv_commentator_name) + var commentatorContent = view.findViewById(R.id.tv_commentator_content) + var commentAvatar = view.findViewById(R.id.iv_avatar) + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + if (mContext == null) { + mContext = parent.context + } + val view = LayoutInflater.from(parent.context) + .inflate(R.layout.comments_item, parent, false) + return ViewHolder(view) + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val comment = mCommentList[position] + holder.commentatorName.text = comment.user!!.username + holder.commentatorContent.text = comment.content + Picasso.with(mContext) + .load(comment.user!!.userAvatar) + .resize(40, 40) + .centerCrop() + .into(holder.commentAvatar) + } + + override fun getItemCount(): Int { + return mCommentList.size + } +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Adapter/MessageAdapter.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Adapter/MessageAdapter.kt new file mode 100644 index 0000000..2f344da --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Adapter/MessageAdapter.kt @@ -0,0 +1,101 @@ +package me.zhaoweihao.hnuplus.Adapter + + +import android.content.Context +import android.content.Intent +import android.support.v7.widget.CardView +import android.support.v7.widget.RecyclerView +import android.util.Log +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView + +import cn.bmob.newim.bean.BmobIMConversation +import me.zhaoweihao.hnuplus.Bmob.Note +import me.zhaoweihao.hnuplus.ChatActivity +import me.zhaoweihao.hnuplus.NoteActivity +import me.zhaoweihao.hnuplus.NoteEditActivity +import me.zhaoweihao.hnuplus.R +import java.text.SimpleDateFormat +import java.util.* +import cn.bmob.v3.exception.BmobException +import cn.bmob.v3.BmobQuery +import cn.bmob.v3.listener.QueryListener +import com.squareup.picasso.Picasso +import me.zhaoweihao.hnuplus.Bmob.MyUser + + +/** + * Created by ZhaoWeihao on 2018/1/10. + */ + +class MessageAdapter(private val mMessageList: List, private val mContext: Context) : RecyclerView.Adapter() { + + class ViewHolder(var messageView: View) : RecyclerView.ViewHolder(messageView) { + var messageTitle: TextView = messageView.findViewById(R.id.tv_message_title) + var messageConetent: TextView = messageView.findViewById(R.id.tv_message_content) + var messageTime: TextView = messageView.findViewById(R.id.tv_updatetime) + var messageAvatar: ImageView = messageView.findViewById(R.id.iv_avatar) + + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MessageAdapter.ViewHolder { + val view = LayoutInflater.from(mContext) + .inflate(R.layout.message_item, parent, false) + val holder = ViewHolder(view) + + holder.messageView.setOnClickListener { + val position = holder.adapterPosition + val conversation = mMessageList[position] + Log.d(TAG, conversation.conversationId) + val intent = Intent(mContext, ChatActivity::class.java) + intent.putExtra("userId", conversation.conversationId) + intent.putExtra("userName", conversation.conversationTitle) + intent.putExtra("code", FROM_MESSAGE_FRAGMENT_CODE) + mContext.startActivity(intent) + } + + + + return holder + } + + override fun onBindViewHolder(holder: MessageAdapter.ViewHolder, position: Int) { + val conversation = mMessageList[position] + holder.messageTitle.text = conversation.conversationTitle + holder.messageConetent.text = conversation.messages[0].content + holder.messageTime.text = SimpleDateFormat("yyyy-MM-dd HH:mm:ss") + .format(Date(conversation.updateTime)) + Log.d(TAG,conversation.conversationId) + val query = BmobQuery() + query.getObject(conversation.conversationId, object : QueryListener() { + + override fun done(user: MyUser, e: BmobException?) { + if (e == null) { + Picasso.with(mContext) + .load(user.userAvatar) + .resize(50, 50) + .centerCrop() + .into(holder.messageAvatar) + } else { + Log.d(TAG, "失败:" + e.message + "," + e.errorCode) + } + } + + }) + } + + override fun getItemCount(): Int { + return mMessageList.size + } + + companion object { + + private val TAG = "MessageAdapter" + + val FROM_MESSAGE_FRAGMENT_CODE = 0 + } + +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Adapter/NoteAdapter.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Adapter/NoteAdapter.kt new file mode 100644 index 0000000..b67bb44 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Adapter/NoteAdapter.kt @@ -0,0 +1,85 @@ +package me.zhaoweihao.hnuplus.Adapter + + +import android.content.Context +import android.content.Intent +import android.support.v7.widget.CardView +import android.support.v7.widget.RecyclerView + +import android.util.Log +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView + +import me.zhaoweihao.hnuplus.Bmob.Note +import me.zhaoweihao.hnuplus.NoteActivity +import me.zhaoweihao.hnuplus.NoteEditActivity +import me.zhaoweihao.hnuplus.R + +/** + * Created by ZhaoWeihao on 2018/1/10. + */ + +class NoteAdapter(private val mNoteList: List, private val mContext: Context) : RecyclerView.Adapter() { + + companion object { + private val TAG = "NoteAdapter" + } + + class ViewHolder(var noteView: View) : RecyclerView.ViewHolder(noteView) { + var textView: TextView = noteView.findViewById(R.id.tv_notes) + var cardView: CardView = noteView.findViewById(R.id.cv_notes) + var imageView: ImageView = noteView.findViewById(R.id.iv_notes) + + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NoteAdapter.ViewHolder { + val view = LayoutInflater.from(mContext) + .inflate(R.layout.note_item, parent, false) + val holder = ViewHolder(view) + holder.noteView.setOnClickListener { + val position = holder.adapterPosition + val note = mNoteList[position] + + Log.d(TAG, position.toString() + " " + mNoteList.size.toString()) + + val intent = Intent(mContext, NoteEditActivity::class.java) + if (position == 0) { + intent.putExtra("data", true) + } else { + intent.putExtra("data", false) + intent.putExtra("objectID", note.objectId) + intent.putExtra("content", note.content) + Log.d(TAG, note.content) + } + mContext.startActivity(intent) + } + return holder + } + + override fun onBindViewHolder(holder: NoteAdapter.ViewHolder, position: Int) { + val note = mNoteList[position] + if (position == 0) { + holder.imageView.visibility = View.VISIBLE + } + + holder.textView.text = note.content + holder.noteView.setOnLongClickListener { + if (position == 0) { + + } else { + Log.d(TAG, position.toString()) + (mContext as? NoteActivity)?.showDeleteDialog(mNoteList[position].objectId) + } + + true + } + } + + override fun getItemCount(): Int { + return mNoteList.size + } + +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Adapter/OrderAdapter.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Adapter/OrderAdapter.kt new file mode 100644 index 0000000..7a93e63 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Adapter/OrderAdapter.kt @@ -0,0 +1,83 @@ +package me.zhaoweihao.hnuplus.Adapter + +import android.content.Context + +import android.support.v7.widget.RecyclerView +import android.util.Log +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView + +import com.squareup.picasso.Picasso +import me.zhaoweihao.hnuplus.Bmob.Order +import me.zhaoweihao.hnuplus.R + +/** + * Show post's data to recyclerview + */ +class OrderAdapter(private val mOrderList: List) : RecyclerView.Adapter() { + + companion object { + private val TAG = "OrderAdapter" + } + + private var mContext: Context? = null + + + class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var goodImage = view.findViewById(R.id.iv_goodimage) + var goodName = view.findViewById(R.id.tv_goodname) + var goodPrice = view.findViewById(R.id.tv_goodprice) + var address = view.findViewById(R.id.tv_address) + var orderView: View = view + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + if (mContext == null) { + mContext = parent.context + } + Log.d(TAG, "onCreateViewHolder") + val view = LayoutInflater.from(mContext) + .inflate(R.layout.myorder_item,parent, false) + val holder = ViewHolder(view) + holder.orderView.setOnClickListener { + val position = holder.adapterPosition + val post = mOrderList[position] + + } + + + return holder + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val post = mOrderList[position] + + val imageUrl = post.imageUrl + val goodName = post.goodName + val goodPrice = post.price + val address = post.address + + Picasso.with(mContext) + .load(imageUrl) + .resize(70, 70) + .centerCrop() + .into(holder.goodImage) + + holder.address.text = "地址:"+address + holder.goodName.text = "商品名称:"+goodName + holder.goodPrice.text = "商品价格:"+goodPrice + + + Log.d(TAG, "onBindViewHolder") + + } + + override fun getItemCount(): Int { + return mOrderList.size + } + + +} \ No newline at end of file diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Adapter/PostAdapter.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Adapter/PostAdapter.kt new file mode 100644 index 0000000..f4c5306 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Adapter/PostAdapter.kt @@ -0,0 +1,135 @@ +package me.zhaoweihao.hnuplus.Adapter + +import android.content.Context +import android.content.Intent +import android.support.v7.widget.RecyclerView +import android.util.Log +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView + +import android.widget.TextView + +import me.zhaoweihao.hnuplus.CommentActivity +import me.zhaoweihao.hnuplus.Bmob.Post +import me.zhaoweihao.hnuplus.MainActivity + +import me.zhaoweihao.hnuplus.R +import com.lzy.ninegrid.ImageInfo +import com.lzy.ninegrid.NineGridView +import com.lzy.ninegrid.preview.NineGridViewClickAdapter +import com.squareup.picasso.Picasso +import com.yoavst.kotlin.`KotlinPackage$Toasts$53212cf1`.toast + + +/** + * Created by ZhaoWeihao on 2017/11/9. + */ + +/** + * Show post's data to recyclerview + */ +class PostAdapter(private val mPostList: List,private val disableCode: Int) : RecyclerView.Adapter() { + + companion object { + private val TAG = "PostAdapter" + } + + private var mContext: Context? = null + + private val disable = disableCode + + class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var postAuthor = view.findViewById(R.id.tv_author) + var postContent = view.findViewById(R.id.tv_content) + var postTime = view.findViewById(R.id.tv_time) + var postPrice = view.findViewById(R.id.tv_price) + var postLocation = view.findViewById(R.id.tv_location) + var nineGrid = view.findViewById(R.id.ninegridview) + var avatar = view.findViewById(R.id.iv_avatar) + var postView: View = view + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + if (mContext == null) { + mContext = parent.context + } + Log.d(TAG, "onCreateViewHolder") + val view = LayoutInflater.from(mContext) + .inflate(R.layout.posts_item, parent, false) + val holder = ViewHolder(view) + when (disable) { + 1 -> { + holder.postView.setOnClickListener { + val position = holder.adapterPosition + val post = mPostList[position] + val intent = Intent(mContext, CommentActivity::class.java) + intent.putExtra("author", post.author!!.username) + intent.putExtra("title", post.title) + intent.putExtra("detail", post.detail) + intent.putExtra("price", "¥ " + post.price) + intent.putExtra("time", post.createdAt) + intent.putExtra("location", post.location) + intent.putExtra("objectID", post.objectId) + intent.putExtra("authorObjectID", post.author!!.objectId) + intent.putExtra("avatarUrl", post.author!!.userAvatar) + if (post.imageUrls == null){ + + }else{ + intent.putStringArrayListExtra("imageUrls", post.imageUrls) + } + (mContext as MainActivity).startActivity(intent) + } + + } + + 0 -> { + holder.postView.setOnClickListener { + toast(mContext, "Please check your network status") + } + } + } + + return holder + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val post = mPostList[position] + holder.postAuthor.text = post.author!!.username + holder.postContent.text = post.title + " " + post.detail + holder.postPrice.text = "¥ " + post.price + holder.postTime.text = post.createdAt + holder.postLocation.text = post.location + + Picasso.with(mContext) + .load(post.author!!.userAvatar) + .resize(40, 40) + .centerCrop() + .into(holder.avatar) + + + Log.d(TAG, "onBindViewHolder") + + val imageInfo = ArrayList() + + val length = post.imageUrls!!.size + + for (i in 0..(length - 1)) { + Log.d(TAG, post.imageUrls!!.get(i)) + val info = ImageInfo() + info.setThumbnailUrl(post.imageUrls!!.get(i)) + info.setBigImageUrl(post.imageUrls!!.get(i)) + imageInfo.add(info) + } + + holder.nineGrid.setAdapter(NineGridViewClickAdapter(mContext, imageInfo)) + + } + + override fun getItemCount(): Int { + return mPostList.size + } + + +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Bmob/Comment.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Bmob/Comment.kt new file mode 100644 index 0000000..8e4bbc9 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Bmob/Comment.kt @@ -0,0 +1,13 @@ +package me.zhaoweihao.hnuplus.Bmob + +import cn.bmob.v3.BmobObject + +/** + * Created by ZhaoWeihao on 2017/11/9. + */ + +class Comment : BmobObject() { + var content: String? = null + var user: MyUser? = null + var post: Post? = null +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Bmob/MyUser.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Bmob/MyUser.kt new file mode 100644 index 0000000..aeb40ed --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Bmob/MyUser.kt @@ -0,0 +1,11 @@ +package me.zhaoweihao.hnuplus.Bmob + +import cn.bmob.v3.BmobUser + +/** + * Created by ZhaoWeihao on 2017/11/9. + */ + +class MyUser : BmobUser() { + var userAvatar: String? = null +} \ No newline at end of file diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Bmob/Note.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Bmob/Note.kt new file mode 100644 index 0000000..e4eeca9 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Bmob/Note.kt @@ -0,0 +1,12 @@ +package me.zhaoweihao.hnuplus.Bmob + +import cn.bmob.v3.BmobObject + +/** + * Created by ZhaoWeihao on 2018/1/7. + */ + +class Note : BmobObject() { + var content: String? = null + var author: MyUser? = null +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Bmob/Order.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Bmob/Order.kt new file mode 100644 index 0000000..a8eb22c --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Bmob/Order.kt @@ -0,0 +1,18 @@ +package me.zhaoweihao.hnuplus.Bmob + +import cn.bmob.v3.BmobObject + +/** + * Created by por on 2018/3/18. + */ +class Order : BmobObject() { + + var goodId: String? = null + var buyerId: String? = null + var sellerId: String? = null + var address: String? = null + var price: String? = null + var imageUrl: String? = null + var goodName: String? = null + +} \ No newline at end of file diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Bmob/Post.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Bmob/Post.kt new file mode 100644 index 0000000..90b4a78 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Bmob/Post.kt @@ -0,0 +1,19 @@ +package me.zhaoweihao.hnuplus.Bmob + +import cn.bmob.v3.BmobObject +import cn.bmob.v3.datatype.BmobFile +import cn.bmob.v3.datatype.BmobRelation +import java.util.ArrayList + +/** + * Created by ZhaoWeihao on 2017/11/9. + */ + +class Post : BmobObject() { + var title: String? = null + var detail: String? = null + var price: String? = null + var author: MyUser? = null + var imageUrls: ArrayList? = null + var location: String? = null +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/BmobIMApplication.kt b/app/src/main/java/me/zhaoweihao/hnuplus/BmobIMApplication.kt new file mode 100644 index 0000000..3d8a6ea --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/BmobIMApplication.kt @@ -0,0 +1,65 @@ +package me.zhaoweihao.hnuplus + +import android.app.Application +import android.content.Context +import android.graphics.Bitmap +import android.widget.ImageView + +import com.lzy.ninegrid.NineGridView +import com.squareup.picasso.Picasso + +import java.io.BufferedReader +import java.io.File +import java.io.FileReader + +import cn.bmob.newim.BmobIM + +/** + * Created by Administrator on 2018/2/11. + */ + +class BmobIMApplication : Application() { + + override fun onCreate() { + super.onCreate() + if (applicationInfo.packageName == myProcessName) { + BmobIM.init(this) + BmobIM.registerDefaultMessageHandler(DemoMessageHandler(this)) + } + + NineGridView.setImageLoader(PicassoImageLoader()) + } + + private inner class PicassoImageLoader : NineGridView.ImageLoader { + + override fun onDisplayImage(context: Context, imageView: ImageView, url: String) { + Picasso.with(context).load(url) + .resize(1000,1000) + .placeholder(R.drawable.ic_default_image) + .error(R.drawable.ic_default_image) + .centerCrop() + .into(imageView) + } + + override fun getCacheImage(url: String): Bitmap? { + return null + } + } + + companion object { + val myProcessName: String? + get() { + return try { + val file = File("/proc/" + android.os.Process.myPid() + "/" + "cmdline") + val mBufferedReader = BufferedReader(FileReader(file)) + val processName = mBufferedReader.readLine().trim { it <= ' ' } + mBufferedReader.close() + processName + } catch (e: Exception) { + e.printStackTrace() + null + } + + } + } +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/BuyActivity.kt b/app/src/main/java/me/zhaoweihao/hnuplus/BuyActivity.kt new file mode 100644 index 0000000..4a126cc --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/BuyActivity.kt @@ -0,0 +1,65 @@ +package me.zhaoweihao.hnuplus + +import android.content.Intent +import android.support.v7.app.AppCompatActivity +import android.os.Bundle +import android.util.Log +import cn.bmob.v3.BmobUser +import com.squareup.picasso.Picasso +import kotlinx.android.synthetic.main.activity_buy.* +import me.zhaoweihao.hnuplus.Bmob.MyUser + +class BuyActivity : AppCompatActivity() { + + companion object { + private val TAG = "BuyAcitivity" + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_buy) + + title = "购买(测试版)" + + val intent = intent + + val title = intent.getStringExtra("title") + val firstImageUrl = intent.getStringExtra("firstImageUrl") + val price = intent.getStringExtra("price") + val objectId = intent.getStringExtra("objectId") + val sellerId = intent.getStringExtra("sellerId") + + Log.d(TAG, "$title $firstImageUrl $price") + + tv_buy_title.text = title + tv_buy_price.text = price + tv_buy_price_2.text = price + + Picasso.with(this) + .load(firstImageUrl) + .resize(70, 70) + .centerCrop() + .into(iv_buy_image) + + btn_buy_sure.setOnClickListener { + + val userInfo = BmobUser.getCurrentUser(MyUser::class.java) + val buyerId = userInfo.objectId + val address = et_address.text.toString() + + val intent = Intent(this,OrderActivity::class.java) + intent.putExtra("buyerId",buyerId) + intent.putExtra("goodId",objectId) + intent.putExtra("sellerId",sellerId) + intent.putExtra("address",address) + intent.putExtra("price",price) + intent.putExtra("goodName",title) + intent.putExtra("imageUrl",firstImageUrl) + startActivity(intent) + + } + + + } + +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/ChatActivity.kt b/app/src/main/java/me/zhaoweihao/hnuplus/ChatActivity.kt new file mode 100644 index 0000000..c6e496b --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/ChatActivity.kt @@ -0,0 +1,192 @@ +package me.zhaoweihao.hnuplus + +import android.content.Intent +import android.support.v7.app.AppCompatActivity +import android.os.Bundle +import android.support.v7.widget.LinearLayoutManager +import android.text.TextUtils +import android.util.Log +import android.view.MenuItem +import android.view.View + +import com.squareup.picasso.Picasso + +import org.greenrobot.eventbus.EventBus +import org.greenrobot.eventbus.Subscribe + +import java.util.ArrayList + +import cn.bmob.newim.BmobIM +import cn.bmob.newim.bean.BmobIMConversation +import cn.bmob.newim.bean.BmobIMMessage +import cn.bmob.newim.bean.BmobIMTextMessage +import cn.bmob.newim.bean.BmobIMUserInfo +import cn.bmob.newim.core.BmobIMClient +import cn.bmob.newim.event.MessageEvent +import cn.bmob.newim.event.OfflineMessageEvent +import cn.bmob.newim.listener.ConnectListener +import cn.bmob.newim.listener.MessageSendListener +import cn.bmob.v3.BmobUser +import cn.bmob.v3.exception.BmobException +import kotlinx.android.synthetic.main.activity_chat.* +import me.zhaoweihao.hnuplus.Adapter.MessageAdapter +import me.zhaoweihao.hnuplus.Bmob.MyUser + +class ChatActivity : AppCompatActivity() { + + private val msgList = ArrayList() + + private var adapter: MsgAdapter? = null + + private var userName: String? = null + private var userId: String? = null + private var price: String? = null + private var firstImageUrl: String? = null + private var title: String? = null + private var objectId: String? = null + private var code: Int? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_chat) + + initMsgs() + + val layoutManager = LinearLayoutManager(this) + msg_recycler_view!!.layoutManager = layoutManager + + val actionBar = supportActionBar + + actionBar?.setDisplayHomeAsUpEnabled(true) + + adapter = MsgAdapter(msgList) + msg_recycler_view!!.adapter = adapter + + val intent = intent + + userId = intent.getStringExtra("userId") + userName = intent.getStringExtra("userName") + price = intent.getStringExtra("price") + firstImageUrl = intent.getStringExtra("firstImageUrl") + title = intent.getStringExtra("title") + objectId = intent.getStringExtra("objectId") + code = intent.getIntExtra("code",1) + + if(code == MessageAdapter.FROM_MESSAGE_FRAGMENT_CODE){ + cv_chat_top.visibility = View.GONE + } + + + Log.d(TAG, "传过来的ID是:" + userId!!) + + tv_chat_price!!.text = price + + Picasso.with(this@ChatActivity) + .load(firstImageUrl) + .resize(60, 60) + .centerCrop() + .into(iv_chat_image) + + setTitle("与" + userName + "的聊天") + + btn_buy!!.setOnClickListener { + val intent = Intent(this@ChatActivity, BuyActivity::class.java) + intent.putExtra("title", title) + intent.putExtra("firstImageUrl", firstImageUrl) + intent.putExtra("price", price) + intent.putExtra("objectId", objectId) + intent.putExtra("sellerId", userId) + startActivity(intent) + } + + val userInfo = BmobUser.getCurrentUser(MyUser::class.java) + if (!TextUtils.isEmpty(userInfo.objectId)) { + BmobIM.connect(userInfo.objectId, object : ConnectListener() { + override fun done(uid: String, e: BmobException?) { + if (e == null) { + send!!.setOnClickListener { + val content = input_text!!.text.toString() + if ("" != content) { + val bmobIMUserInfo = BmobIMUserInfo(userId, userName, "") + val conversationEntrance = BmobIM.getInstance().startPrivateConversation(bmobIMUserInfo, null) + val messageManager = BmobIMConversation.obtain(BmobIMClient.getInstance(), conversationEntrance) + sendMessage(messageManager, content) + + } + } + Log.d(TAG, "成功连接") + } else { + //连接失败 + Log.d(TAG, "连接失败") + } + } + }) + } + } + + private fun sendMessage(mConversationManager: BmobIMConversation, content: String) { + if (TextUtils.isEmpty(content.trim { it <= ' ' })) { + Log.d(TAG, "请输入一些东西") + return + } + val msg = BmobIMTextMessage() + msg.content = content + mConversationManager.sendMessage(msg, object : MessageSendListener() { + override fun done(bmobIMMessage: BmobIMMessage, e: BmobException?) { + if (e == null) { + Log.d(TAG, "成功发送信息") + val msg = Msg(content, Msg.TYPE_SENT) + msgList.add(msg) + adapter!!.notifyItemInserted(msgList.size - 1) + msg_recycler_view!!.scrollToPosition(msgList.size - 1) + input_text!!.setText("") + } else { + Log.d(TAG, "发送信息失败") + } + } + }) + } + + override fun onStart() { + super.onStart() + EventBus.getDefault().register(this) + } + + override fun onStop() { + EventBus.getDefault().unregister(this) + super.onStop() + + } + + private fun initMsgs() { + val msg1 = Msg("跟卖家商量一下价格吧", Msg.TYPE_SENT) + msgList.add(msg1) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + android.R.id.home -> finish() + } + return true + } + + @Subscribe + fun onEventMainThread(event: MessageEvent) { + Log.d(TAG, "收到一条信息") + val msg = Msg(event.message.content.toString(), Msg.TYPE_RECEIVED) + msgList.add(msg) + adapter!!.notifyItemInserted(msgList.size - 1) + msg_recycler_view!!.scrollToPosition(msgList.size - 1) + } + + @Subscribe + fun onEventMainThread(event: OfflineMessageEvent) { + Log.d(TAG, "收到离线信息") + } + + companion object { + + private val TAG = "ChatActivity" + } + +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/CommentActivity.kt b/app/src/main/java/me/zhaoweihao/hnuplus/CommentActivity.kt new file mode 100644 index 0000000..a02a8b2 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/CommentActivity.kt @@ -0,0 +1,81 @@ +package me.zhaoweihao.hnuplus + +import android.support.v7.app.AppCompatActivity +import android.os.Bundle +import android.util.Log +import android.view.MenuItem +import cn.bmob.v3.BmobUser +import com.squareup.picasso.Picasso +import kotlinx.android.synthetic.main.activity_comment.* +import me.zhaoweihao.hnuplus.Bmob.MyUser +import me.zhaoweihao.hnuplus.Interface.CommentInterface +import org.jetbrains.anko.toast + +class CommentActivity : AppCompatActivity() { + + companion object { + private val TAG = "CommentActivity" + } + + private var commentFragment: CommentFragment? = null + private var listener: CommentInterface? = null + private var user: MyUser? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_comment) + + user = BmobUser.getCurrentUser(MyUser::class.java) + + title = getString(R.string.comment_title) + val actionBar = supportActionBar + actionBar!!.setDisplayHomeAsUpEnabled(true) + + val transaction = (fragmentManager)!!.beginTransaction() + if (commentFragment == null) { + commentFragment = CommentFragment() + setListener(commentFragment!!) + transaction.add(R.id.fl_comment, commentFragment) + } else { + transaction.show(commentFragment) + } + transaction.commit() + + iv_comment.setOnClickListener { listener!!.myAction(et_comment!!.text.toString()) } + + if (user != null) { + btn_want.setOnClickListener { + listener!!.chat() + } + + setAvatar() + } + else{ + btn_want.setOnClickListener { + toast("你还没有登录,请先登录") + } + } + + + } + + private fun setListener(listener: CommentInterface) { + this.listener = listener + } + + private fun setAvatar() { + Picasso.with(this) + .load(user!!.userAvatar) + .resize(40, 40) + .centerCrop() + .into(iv_avatar_down) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + android.R.id.home -> finish() + } + return true + } + +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/CommentFragment.kt b/app/src/main/java/me/zhaoweihao/hnuplus/CommentFragment.kt new file mode 100644 index 0000000..f8d4a6e --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/CommentFragment.kt @@ -0,0 +1,230 @@ +package me.zhaoweihao.hnuplus + +import android.app.Fragment +import android.app.ProgressDialog + +import android.content.DialogInterface +import android.content.Intent + +import android.os.Bundle + +import android.support.design.widget.Snackbar +import android.support.v7.app.AlertDialog +import android.support.v7.widget.LinearLayoutManager +import android.support.v7.widget.RecyclerView +import android.util.Log +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.FrameLayout +import android.widget.ImageView +import android.widget.TextView +import android.widget.Toast + +import com.lzy.ninegrid.ImageInfo +import com.lzy.ninegrid.NineGridView +import com.lzy.ninegrid.preview.NineGridViewClickAdapter +import com.taishi.flipprogressdialog.FlipProgressDialog + +import java.util.ArrayList +import java.util.Collections + +import butterknife.BindView +import butterknife.ButterKnife +import cn.bmob.v3.BmobQuery +import cn.bmob.v3.BmobUser +import cn.bmob.v3.datatype.BmobPointer +import cn.bmob.v3.exception.BmobException +import cn.bmob.v3.listener.FindListener +import cn.bmob.v3.listener.SaveListener +import cn.bmob.v3.listener.UpdateListener +import com.squareup.picasso.Picasso +import kotlinx.android.synthetic.main.comment_layout.* +import kotlinx.android.synthetic.main.comment_top.* +import me.zhaoweihao.hnuplus.Adapter.CommentAdapter +import me.zhaoweihao.hnuplus.Interface.CommentInterface +import me.zhaoweihao.hnuplus.Bmob.Comment +import me.zhaoweihao.hnuplus.Bmob.MyUser +import me.zhaoweihao.hnuplus.Bmob.Post +import me.zhaoweihao.hnuplus.Utils.Utility + +/** + * Created by ZhaoWeihao on 2017/11/10. + */ + +class CommentFragment : Fragment(), CommentInterface { + + companion object { + private val TAG = "CommentFragment" + } + + private var layoutManager: LinearLayoutManager? = null + private var adapter: CommentAdapter? = null + private var objectID: String? = null + private var authorObjectID: String? = null + private var userName: String? = null + private var price: String? = null + private var firstImageUrl: String? = null + private var title: String? = null + private var detail: String? = null + private var avatarUrl: String? = null + private var user: MyUser? = null + private var flipProgressDialog: FlipProgressDialog? = null + + override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + return inflater!!.inflate(R.layout.comment_layout, + container, false) + } + + override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + user = BmobUser.getCurrentUser(MyUser::class.java) + val intent = activity.intent + userName = intent.getStringExtra("author") + price = intent.getStringExtra("price") + title = intent.getStringExtra("title") + detail = intent.getStringExtra("detail") + avatarUrl = intent.getStringExtra("avatarUrl") + + Picasso.with(activity) + .load(avatarUrl) + .resize(40, 40) + .centerCrop() + .into(iv_avatar) + + tv_author!!.text = userName + tv_content!!.text = title + " " + detail + tv_time!!.text = intent.getStringExtra("time") + tv_price!!.text = price + tv_location!!.text = intent.getStringExtra("location") + objectID = intent.getStringExtra("objectID") + authorObjectID = intent.getStringExtra("authorObjectID") + + if (intent.getStringArrayListExtra("imageUrls") == null) { + Log.d(TAG, "no photo") + } else { + val imageInfo = ArrayList() + val imageUrls = intent.getStringArrayListExtra("imageUrls") + firstImageUrl = imageUrls[0] + for (imageUrl in imageUrls) { + Log.d(TAG, imageUrl) + val info = ImageInfo() + info.setThumbnailUrl(imageUrl) + info.setBigImageUrl(imageUrl) + imageInfo.add(info) + } + ninegridview!!.setAdapter(NineGridViewClickAdapter(activity, imageInfo)) + } + + when { + user == null -> fl_delete!!.visibility = View.GONE + user!!.objectId == authorObjectID -> fl_delete!!.visibility = View.VISIBLE + else -> fl_delete!!.visibility = View.GONE + } + + fl_delete!!.setOnClickListener { + val dialog = AlertDialog.Builder(activity) + dialog.setTitle("你确定要删除这个商品吗") + dialog.setMessage(R.string.comment_delete_message) + dialog.setCancelable(false) + dialog.setPositiveButton(R.string.comment_sure) { _, _ -> + val p = Post() + p.objectId = objectID + p.delete(object : UpdateListener() { + override fun done(e: BmobException?) { + if (e == null) { + Toast.makeText(activity, R.string.delete_success, Toast.LENGTH_SHORT).show() + activity.finish() + } else { + Toast.makeText(activity, R.string.delete_failed, Toast.LENGTH_SHORT).show() + } + } + + }) + } + dialog.setNegativeButton(R.string.delete_cancel) { _, _ -> } + + dialog.show() + } + + flipProgressDialog = Utility.myDialog() + flipProgressDialog!!.show(fragmentManager, "") + + refreshCommentData(objectID) + } + + private fun refreshCommentData(objectID: String?) { + + val query = BmobQuery() + val post = Post() + post.objectId = objectID + query.addWhereEqualTo("post", BmobPointer(post)) + query.include("user,post.author") + query.findObjects(object : FindListener() { + + override fun done(objects: List, e: BmobException?) { + if (objects.isEmpty()) { + flipProgressDialog!!.dismiss() + } else { + Collections.reverse(objects) + rv_comments!!.isNestedScrollingEnabled = false + layoutManager = LinearLayoutManager(activity) + rv_comments!!.layoutManager = layoutManager + adapter = CommentAdapter(objects) + rv_comments!!.adapter = adapter + flipProgressDialog!!.dismiss() + } + } + }) + } + + override fun myAction(data: String) { + + when { + user == null -> Snackbar.make(rv_comments!!, R.string.not_signin_text, Snackbar.LENGTH_SHORT) + .setAction("Sign in") { + val intent = Intent(activity, SigninActivity::class.java) + startActivity(intent) + }.show() + data == "" -> Toast.makeText(activity, R.string.empty_text, Toast.LENGTH_SHORT).show() + else -> { + + flipProgressDialog!!.show(fragmentManager, "") + + val post = Post() + post.objectId = objectID + val comment = Comment() + comment.content = data + comment.post = post + comment.user = user + comment.save(object : SaveListener() { + + override fun done(objectId: String, e: BmobException?) { + if (e == null) { + refreshCommentData(objectID) + Toast.makeText(activity, R.string.add_commit_success, Toast.LENGTH_SHORT).show() + + } else { + Toast.makeText(activity, R.string.add_commit_failed, Toast.LENGTH_SHORT).show() + } + } + + }) + } + } + + } + + override fun chat() { + val intent = Intent(activity, ChatActivity::class.java) + intent.putExtra("userId", authorObjectID) + intent.putExtra("userName", userName) + intent.putExtra("price", price) + intent.putExtra("firstImageUrl", firstImageUrl) + intent.putExtra("title", title) + intent.putExtra("objectId", objectID) + startActivity(intent) + } + +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/CommunityFragment.kt b/app/src/main/java/me/zhaoweihao/hnuplus/CommunityFragment.kt new file mode 100644 index 0000000..adb34b1 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/CommunityFragment.kt @@ -0,0 +1,168 @@ +package me.zhaoweihao.hnuplus + +import android.app.Fragment +import android.content.Intent +import android.os.Bundle +import android.support.design.widget.Snackbar +import android.support.v7.widget.LinearLayoutManager +import android.support.v7.widget.RecyclerView +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup + +import java.util.Collections + +import cn.bmob.v3.BmobQuery +import cn.bmob.v3.BmobUser +import cn.bmob.v3.exception.BmobException +import cn.bmob.v3.listener.FindListener + +import me.zhaoweihao.hnuplus.Adapter.PostAdapter +import me.zhaoweihao.hnuplus.Bmob.MyUser +import me.zhaoweihao.hnuplus.Bmob.Post + +import android.preference.PreferenceManager + +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.yoavst.kotlin.`KotlinPackage$SystemServices$69d7d2d0`.connectivityManager + +import kotlinx.android.synthetic.main.fragment_community.* +import me.zhaoweihao.hnuplus.Interface.CommunityInterface +import org.jetbrains.anko.toast + +/** + * Created by ZhaoWeihao on 2017/11/9. + */ + +class CommunityFragment : Fragment(), CommunityInterface { + + private var layoutManager: LinearLayoutManager? = null + private var adapter: PostAdapter? = null + private var userInfo: MyUser? = null + + override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + return inflater!!.inflate(R.layout.fragment_community, + container, false) + } + + override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + loadData() + + pull_to_refresh!!.setOnRefreshListener { loadData() } + + fb!!.setOnClickListener { + userInfo = BmobUser.getCurrentUser(MyUser::class.java) + if (userInfo != null) { + (activity as MainActivity).gotoPostFragment() + } else { + Snackbar.make(fb!!, R.string.not_signin_text, Snackbar.LENGTH_SHORT) + .setAction("Sign in") { + val intent = Intent(activity, SigninActivity::class.java) + startActivity(intent) + }.show() + + } + } + + rv_posts!!.addOnScrollListener(object : RecyclerView.OnScrollListener() { + override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) { + if (dy > 0) + fb!!.hide() + else if (dy < 0) + fb!!.show() + } + }) + + } + + /** + * @networkCode 1 -> 有网络 + * 0 -> 没有网络 + */ + + private fun refreshRecyclerView(networkCode: Int) { + + when (networkCode) { + 1 -> { + pull_to_refresh!!.setRefreshing(true) + val query = BmobQuery() + query.include("author,imageUrls") + query.findObjects(object : FindListener() { + + override fun done(postList: List, e: BmobException?) { + if (postList.isEmpty()){ + toast("出现了一些错误,请过一会儿再尝试刷新一下") + pull_to_refresh!!.setRefreshing(false) + return + } + if (e == null) { + Collections.reverse(postList) + saveListToPrefs(postList) + + layoutManager = LinearLayoutManager(activity) + rv_posts!!.layoutManager = layoutManager + adapter = PostAdapter(postList,1) + rv_posts!!.adapter = adapter + pull_to_refresh!!.setRefreshing(false) + + } else { + Snackbar.make(rv_posts!!, R.string.refresh_failed, Snackbar.LENGTH_SHORT).show() + pull_to_refresh!!.setRefreshing(false) + } + } + + })} + 0 -> { + val appSharedPrefs = PreferenceManager + .getDefaultSharedPreferences(activity.applicationContext) + val gson = Gson() + val json = appSharedPrefs.getString("MyObject", "") + val type = object : TypeToken>() { + }.type + val postList: List = gson.fromJson(json,type) + + layoutManager = LinearLayoutManager(activity) + rv_posts!!.layoutManager = layoutManager + adapter = PostAdapter(postList,0) + rv_posts!!.adapter = adapter + Snackbar.make(rv_posts!!, getString(R.string.check_network_status), Snackbar.LENGTH_SHORT).show() + pull_to_refresh!!.setRefreshing(false) + } + + } + + } + + private fun loadData(){ + val conMgr = connectivityManager(activity) + val activeNetwork = conMgr.activeNetworkInfo + if (activeNetwork != null && activeNetwork.isConnected) { + refreshRecyclerView(1) + } else { + refreshRecyclerView(0) + } + } + + private fun saveListToPrefs(postList: List){ + val appSharedPrefs = PreferenceManager + .getDefaultSharedPreferences(activity.applicationContext) + val prefsEditor = appSharedPrefs.edit() + val gson = Gson() + val json = gson.toJson(postList) + prefsEditor.putString("MyObject", json) + prefsEditor.commit() + } + + override fun myMethod() { + loadData() + } + + override fun refreshView() { + refreshRecyclerView(1) + } + +} \ No newline at end of file diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Constant/Constant.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Constant/Constant.kt new file mode 100644 index 0000000..35f92ff --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Constant/Constant.kt @@ -0,0 +1,9 @@ +package me.zhaoweihao.hnuplus.Constant + +/** + * Created by ZhaoWeihao on 2017/11/19. + */ + +object Constant { + val APP_ID = "c6dc7bca6dddbf1563c5e846b4c9e23b" +} \ No newline at end of file diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/DemoMessageHandler.kt b/app/src/main/java/me/zhaoweihao/hnuplus/DemoMessageHandler.kt new file mode 100644 index 0000000..319410e --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/DemoMessageHandler.kt @@ -0,0 +1,42 @@ +package me.zhaoweihao.hnuplus + +import android.content.Context +import android.util.Log + +import com.yalantis.phoenix.util.Logger + +import org.greenrobot.eventbus.EventBus + +import cn.bmob.newim.event.MessageEvent +import cn.bmob.newim.event.OfflineMessageEvent +import cn.bmob.newim.listener.BmobIMMessageHandler + +/** + * Created by Administrator on 2018/2/11. + */ + +class DemoMessageHandler(private val context: Context) : BmobIMMessageHandler() { + + override fun onMessageReceive(event: MessageEvent?) { + Log.d(TAG, "got message" + event!!.message.content) + EventBus.getDefault().post(event) + } + + override fun onOfflineReceive(event: OfflineMessageEvent?) { + val map = event!!.eventMap + Log.d(TAG, "有" + map.size + "个用户发来离线消息") + for ((key, list) in map) { + val size = list.size + Log.d(TAG, "用户" + key + "发来" + size + "条消息") + for (i in 0 until size) { + + EventBus.getDefault().post(list[i]) + } + } + } + + companion object { + + private val TAG = "DemoMessageHandler" + } +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/GetOrderActivity.kt b/app/src/main/java/me/zhaoweihao/hnuplus/GetOrderActivity.kt new file mode 100644 index 0000000..8c9f86c --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/GetOrderActivity.kt @@ -0,0 +1,59 @@ +package me.zhaoweihao.hnuplus + +import android.support.v7.app.AppCompatActivity +import android.os.Bundle +import android.support.v7.widget.LinearLayoutManager +import android.util.Log +import cn.bmob.v3.BmobQuery +import cn.bmob.v3.BmobUser +import cn.bmob.v3.exception.BmobException +import cn.bmob.v3.listener.FindListener +import kotlinx.android.synthetic.main.activity_get_order.* +import me.zhaoweihao.hnuplus.Adapter.OrderAdapter +import me.zhaoweihao.hnuplus.Bmob.MyUser +import me.zhaoweihao.hnuplus.Bmob.Order +import org.jetbrains.anko.toast + +class GetOrderActivity : AppCompatActivity() { + + companion object { + private val TAG = "GetOrderActivity" + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_get_order) + + title = "收到订单" + + val user = BmobUser.getCurrentUser(MyUser::class.java) + + if (user == null){ + toast("你需要登录才能使用此功能") + return + } + + val userId = user.objectId + + val query = BmobQuery() + query.addWhereEqualTo("sellerId", userId) + query.setLimit(50) + query.findObjects(object : FindListener() { + override fun done(orders: List, e: BmobException?) { + if (e == null) { + Log.d(TAG,"查询成功:共" + orders.size + "条数据。") + if (orders.isEmpty()){ + toast("你当前没有任何订单信息") + return + } + val layoutManager = LinearLayoutManager(this@GetOrderActivity) + rv_get_order!!.layoutManager = layoutManager + val adapter = OrderAdapter(orders) + rv_get_order!!.adapter = adapter + } else { + Log.d(TAG, "失败:" + e.message + "," + e.errorCode) + } + } + }) + } +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Astronomy.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Astronomy.kt new file mode 100644 index 0000000..0f6883e --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Astronomy.kt @@ -0,0 +1,10 @@ +package me.zhaoweihao.hnuplus.Gson + +/** + * Created by ZhaoWeihao on 2018/1/6. + */ + +class Astronomy { + var sunrise: String? = null + var sunset: String? = null +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Atmosphere.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Atmosphere.kt new file mode 100644 index 0000000..48b4e71 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Atmosphere.kt @@ -0,0 +1,12 @@ +package me.zhaoweihao.hnuplus.Gson + +/** + * Created by ZhaoWeihao on 2018/1/6. + */ + +class Atmosphere { + var humidity: String? = null + var pressure: String? = null + var rising: String? = null + var visibility: String? = null +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Basic.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Basic.kt new file mode 100644 index 0000000..361fc7f --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Basic.kt @@ -0,0 +1,14 @@ +package me.zhaoweihao.hnuplus.Gson + +/** + * Created by Zhaoweihao on 2017/4/13. + */ + +class Basic { + + var phonetic: String? = null + + var explains: Array? = null + + +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Channel.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Channel.kt new file mode 100644 index 0000000..f538ea0 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Channel.kt @@ -0,0 +1,14 @@ +package me.zhaoweihao.hnuplus.Gson + +/** + * Created by ZhaoWeihao on 2018/1/6. + */ + +class Channel { + var lastBuildDate: String? = null + var location: Location? = null + var wind: Wind? = null + var atmosphere: Atmosphere? = null + var astronomy: Astronomy? = null + var item: Item? = null +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Condition.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Condition.kt new file mode 100644 index 0000000..3e79635 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Condition.kt @@ -0,0 +1,12 @@ +package me.zhaoweihao.hnuplus.Gson + +/** + * Created by ZhaoWeihao on 2018/1/6. + */ + +class Condition { + var code: String? = null + var date: String? = null + var temp: String? = null + var text: String? = null +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Forecast.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Forecast.kt new file mode 100644 index 0000000..b122c0c --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Forecast.kt @@ -0,0 +1,13 @@ +package me.zhaoweihao.hnuplus.Gson + +/** + * Created by ZhaoWeihao on 2018/1/6. + */ + +class Forecast { + var date: String? = null + var day: String? = null + var high: String? = null + var low: String? = null + var text: String? = null +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Item.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Item.kt new file mode 100644 index 0000000..ea7299c --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Item.kt @@ -0,0 +1,18 @@ +package me.zhaoweihao.hnuplus.Gson + +import com.google.gson.annotations.SerializedName + +/** + * Created by ZhaoWeihao on 2018/1/6. + */ + +class Item { + var title: String? = null + var lat: String? = null + @SerializedName("long") + var longtitude: String? = null + var pubDate: String? = null + var condition: Condition? = null + @SerializedName("forecast") + var forecastList: List? = null +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Location.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Location.kt new file mode 100644 index 0000000..673f41a --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Location.kt @@ -0,0 +1,11 @@ +package me.zhaoweihao.hnuplus.Gson + +/** + * Created by ZhaoWeihao on 2018/1/6. + */ + +class Location { + var city: String? = null + var country: String? = null + var region: String? = null +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Query.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Query.kt new file mode 100644 index 0000000..d57e89a --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Query.kt @@ -0,0 +1,9 @@ +package me.zhaoweihao.hnuplus.Gson + +/** + * Created by ZhaoWeihao on 2018/1/6. + */ + +class Query { + var results: Results? = null +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Results.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Results.kt new file mode 100644 index 0000000..e9f08ba --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Results.kt @@ -0,0 +1,9 @@ +package me.zhaoweihao.hnuplus.Gson + +/** + * Created by ZhaoWeihao on 2018/1/6. + */ + +class Results { + var channel: Channel? = null +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Translate.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Translate.kt new file mode 100644 index 0000000..15379e9 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Translate.kt @@ -0,0 +1,18 @@ +package me.zhaoweihao.hnuplus.Gson + +/** + * Created by Zhaoweihao on 2017/4/13. + */ + +class Translate { + + var translation: Array? = null + + var basic: Basic? = null + + var query: String? = null + + var errorCode: Int = 0 + + var web: List? = null +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Weather.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Weather.kt new file mode 100644 index 0000000..41c655b --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Weather.kt @@ -0,0 +1,9 @@ +package me.zhaoweihao.hnuplus.Gson + +/** + * Created by ZhaoWeihao on 2018/1/6. + */ + +class Weather { + var query: Query? = null +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Web.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Web.kt new file mode 100644 index 0000000..a4d8e2f --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Web.kt @@ -0,0 +1,14 @@ +package me.zhaoweihao.hnuplus.Gson + +/** + * Created by Zhaoweihao on 2017/4/13. + */ + +class Web { + + var value: Array? = null + + var key: String? = null + + private val finalValue: String? = null +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Wind.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Wind.kt new file mode 100644 index 0000000..302c125 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Gson/Wind.kt @@ -0,0 +1,11 @@ +package me.zhaoweihao.hnuplus.Gson + +/** + * Created by ZhaoWeihao on 2018/1/6. + */ + +class Wind { + var chill: String? = null + var direction: String? = null + var speed: String? = null +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Interface/CommentInterface.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Interface/CommentInterface.kt new file mode 100644 index 0000000..363dd36 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Interface/CommentInterface.kt @@ -0,0 +1,10 @@ +package me.zhaoweihao.hnuplus.Interface + +/** + * Created by ZhaoWeihao on 2017/11/10. + */ + +interface CommentInterface { + fun myAction(data: String) + fun chat() +} \ No newline at end of file diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Interface/CommunityInterface.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Interface/CommunityInterface.kt new file mode 100644 index 0000000..0ebea1a --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Interface/CommunityInterface.kt @@ -0,0 +1,10 @@ +package me.zhaoweihao.hnuplus.Interface + +/** + * Created by ZhaoWeihao on 2017/11/19. + */ + +interface CommunityInterface { + fun myMethod() + fun refreshView() +} \ No newline at end of file diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Interface/PostInterface.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Interface/PostInterface.kt new file mode 100644 index 0000000..187c92e --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Interface/PostInterface.kt @@ -0,0 +1,12 @@ +package me.zhaoweihao.hnuplus.Interface + +import android.net.Uri + +/** + * Created by ZhaoWeihao on 2017/12/3. + */ + +interface PostInterface { + fun myMethod() + fun showImage(imageUri: List) +} \ No newline at end of file diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/MainActivity.kt b/app/src/main/java/me/zhaoweihao/hnuplus/MainActivity.kt new file mode 100644 index 0000000..3c699f6 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/MainActivity.kt @@ -0,0 +1,275 @@ +package me.zhaoweihao.hnuplus + +import android.app.FragmentTransaction +import android.content.Intent +import android.graphics.Color + + +import android.support.v7.app.AppCompatActivity +import android.os.Bundle +import android.util.Log +import android.view.Window +import android.widget.Toast +import cn.bmob.newim.BmobIM +import cn.bmob.v3.Bmob +import cn.bmob.v3.BmobUser +import cn.bmob.v3.exception.BmobException +import cn.bmob.v3.listener.SaveListener + +import kotlinx.android.synthetic.main.activity_main.* +import me.zhaoweihao.hnuplus.Interface.CommunityInterface +import me.zhaoweihao.hnuplus.Bmob.MyUser +import me.zhaoweihao.hnuplus.Bmob.Post +import cn.bmob.v3.listener.UploadFileListener +import cn.bmob.v3.datatype.BmobFile +import org.jetbrains.anko.toast +import java.io.File + +import com.taishi.flipprogressdialog.FlipProgressDialog +import me.zhaoweihao.hnuplus.Utils.Utility +import nl.dionsegijn.konfetti.models.Shape +import nl.dionsegijn.konfetti.models.Size +import cn.bmob.v3.listener.UploadBatchListener +import org.greenrobot.eventbus.EventBus +import org.greenrobot.eventbus.Subscribe + + +/** + * Created by ZhaoWeihao on 2017/11/9. + * Github:https://github.com/zhaoweihaoChina + */ +class MainActivity : AppCompatActivity() { + + private var communityFragment: CommunityFragment? = null + private var moreFragment: MoreFragment? = null + private var userFragment: UserFragment? = null + private var messageFragment: MessageFragment? = null + + private var mListener: CommunityInterface? = null + + private var flipProgressDialog: FlipProgressDialog? = null + + companion object { + private val TAG = "MainActivity" + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + requestWindowFeature(Window.FEATURE_NO_TITLE) + setContentView(R.layout.activity_main) + + flipProgressDialog = Utility.myDialog() + + bindListener() + + setTabSelection(0) + } + + private fun bindListener() { + community_layout!!.setOnClickListener { setTabSelection(0) } + more_layout!!.setOnClickListener { setTabSelection(1) } + message_layout!!.setOnClickListener { setTabSelection(2) } + user_layout!!.setOnClickListener { setTabSelection(3) } + } + + private fun setTabSelection(index: Int) { + clearSelection() + val transaction = fragmentManager!!.beginTransaction() + hideFragments(transaction) + when (index) { + 0 -> { + community_image!!.setImageResource(R.drawable.community) + community_text!!.setTextColor(Color.WHITE) + title = "市场" + if (communityFragment == null) { + communityFragment = CommunityFragment() + setListener(communityFragment!!) + transaction.add(R.id.content, communityFragment) + } else { + transaction.show(communityFragment) + } + } + 1 -> { + more_image!!.setImageResource(R.drawable.more) + more_text!!.setTextColor(Color.WHITE) + title = "更多" + if (moreFragment == null) { + moreFragment = MoreFragment() + transaction.add(R.id.content, moreFragment) + } else { + transaction.show(moreFragment) + } + } + 2 -> { + message_image!!.setImageResource(R.drawable.user) + message_text!!.setTextColor(Color.WHITE) + title = "消息" + if (messageFragment == null) { + messageFragment = MessageFragment() + transaction.add(R.id.content, messageFragment) + } else { + transaction.show(messageFragment) + } + } + 3 -> { + user_image!!.setImageResource(R.drawable.user) + user_text!!.setTextColor(Color.WHITE) + title = "我的" + if (userFragment == null) { + userFragment = UserFragment() + transaction.add(R.id.content, userFragment) + } else { + transaction.show(userFragment) + } + } + } + transaction.commit() + } + + private fun clearSelection() { + community_image!!.setImageResource(R.drawable.community_grey) + community_text!!.setTextColor(Color.parseColor("#82858b")) + more_image!!.setImageResource(R.drawable.more_grey) + more_text!!.setTextColor(Color.parseColor("#82858b")) + message_image!!.setImageResource(R.drawable.user_grey) + message_text!!.setTextColor(Color.parseColor("#82858b")) + user_image!!.setImageResource(R.drawable.user_grey) + user_text!!.setTextColor(Color.parseColor("#82858b")) + } + + private fun hideFragments(transaction: FragmentTransaction) { + if (communityFragment != null) { + transaction.hide(communityFragment) + } + if (moreFragment != null) { + transaction.hide(moreFragment) + } + if (userFragment != null) { + transaction.hide(userFragment) + } + + if (messageFragment != null) { + transaction.hide(messageFragment) + } + } + + fun gotoPostFragment() { + val intent = Intent(this, PostActivity::class.java) + startActivityForResult(intent, 1) + } + + private fun setListener(listener: CommunityInterface) { + this.mListener = listener + } + + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + when (requestCode) { + 1 -> if (resultCode == RESULT_OK) { + val postTitle = data!!.getStringExtra("post_title") + val postDetail = data.getStringExtra("post_detail") + val postLocation = data.getStringExtra("post_location") + val postPrice = data.getStringExtra("post_price") + val paths = data.getStringArrayExtra("data_return_2") + for (path in paths) { + Log.d(TAG, path) + } + + if (paths == null) { + if (postTitle == "" || postDetail == "" || postLocation == "" || postPrice == "") { + Toast.makeText(this, getString(R.string.empty_text_warn), Toast.LENGTH_SHORT).show() + } else { + val user = BmobUser.getCurrentUser(MyUser::class.java) + val post = Post() + flipProgressDialog!!.show(getFragmentManager(), "") + + post.title = postTitle + post.detail = postDetail + post.price = postPrice + post.location = postLocation + post.author = user + + post.save(object : SaveListener() { + + override fun done(objectId: String, e: BmobException?) { + if (e == null) { + flipProgressDialog!!.dismiss() + Toast.makeText(this@MainActivity, getString(R.string.post_success), Toast.LENGTH_SHORT).show() + viewKonfetti.build() + .addColors(Color.parseColor("#fce18a"), Color.parseColor("#ff726d"), Color.parseColor("#b48def"), Color.parseColor("#f4306d")) + .setDirection(0.0, 359.0) + .setSpeed(1f, 5f) + .setFadeOutEnabled(true) + .setTimeToLive(600L) + .addShapes(Shape.RECT, Shape.CIRCLE) + .addSizes(Size(12)) + .setPosition(-50f, viewKonfetti.width + 50f, -50f, -50f) + .stream(300, 5000L) + mListener!!.myMethod() + } else { + Toast.makeText(this@MainActivity, getString(R.string.post_failed), Toast.LENGTH_SHORT).show() + } + } + }) + + } + } else { + if (postTitle == "" || postDetail == "" || postLocation == "" || postPrice == "") { + Toast.makeText(this, getString(R.string.empty_text_warn), Toast.LENGTH_SHORT).show() + } else { + val user = BmobUser.getCurrentUser(MyUser::class.java) + val post = Post() + + flipProgressDialog!!.show(fragmentManager, "") + + toast("正在发布帖子...") + + BmobFile.uploadBatch(paths, object : UploadBatchListener { + + override fun onSuccess(files: List, urls: List) { + if (urls.size == paths.size) {//如果数量相等,则代表文件全部上传完成 + post.title = postTitle + post.detail = postDetail + post.price = postPrice + post.location = postLocation + post.author = user + post.imageUrls = ArrayList(urls) + post.save(object : SaveListener() { + + override fun done(objectId: String, e: BmobException?) { + if (e == null) { + Toast.makeText(this@MainActivity, "发布商品成功", Toast.LENGTH_SHORT).show() + flipProgressDialog!!.dismiss() + mListener!!.refreshView() + } else { + Toast.makeText(this@MainActivity, "发布商品失败", Toast.LENGTH_SHORT).show() + } + } + }) + } + } + + override fun onError(statuscode: Int, errormsg: String) { + Log.d(TAG,"Error") + } + + override fun onProgress(curIndex: Int, curPercent: Int, total: Int, totalPercent: Int) { + //1、curIndex--表示当前第几个文件正在上传 + //2、curPercent--表示当前上传文件的进度值(百分比) + //3、total--表示总的上传文件数 + //4、totalPercent--表示总的上传进度(百分比) +// Log.d(TAG, curIndex.toString()) + + } + }) + + + } + } + + } + } + + } + +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/MessageFragment.kt b/app/src/main/java/me/zhaoweihao/hnuplus/MessageFragment.kt new file mode 100644 index 0000000..6c621f4 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/MessageFragment.kt @@ -0,0 +1,135 @@ +package me.zhaoweihao.hnuplus + +import android.app.Fragment +import android.os.Bundle +import android.support.v7.widget.LinearLayoutManager +import android.util.Log +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup + +import org.greenrobot.eventbus.EventBus +import org.greenrobot.eventbus.Subscribe + +import cn.bmob.newim.BmobIM +import cn.bmob.newim.bean.BmobIMConversation +import cn.bmob.newim.event.MessageEvent +import cn.bmob.newim.event.OfflineMessageEvent +import cn.bmob.newim.listener.ConnectListener +import cn.bmob.v3.BmobUser +import cn.bmob.v3.exception.BmobException +import kotlinx.android.synthetic.main.fragment_message.* +import me.zhaoweihao.hnuplus.Adapter.MessageAdapter +import me.zhaoweihao.hnuplus.Bmob.MyUser +import org.jetbrains.anko.toast +import org.greenrobot.eventbus.ThreadMode + + + +/** + * Created by Administrator on 2018/2/14. + */ + +class MessageFragment : Fragment() { + + private var mMessageAdapter: MessageAdapter? = null + + override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? { + + return inflater!!.inflate(R.layout.fragment_message, + container, false) + } + + override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + Log.d(TAG,"onViewCreated") + getMessage() + + } + + override fun onCreate(savedInstanceState: Bundle?) { + + super.onCreate(savedInstanceState) + EventBus.getDefault().register(this) + } + + override fun onDestroy() { + EventBus.getDefault().unregister(this) + super.onDestroy() + } + + private fun getMessage(){ + val userInfo = BmobUser.getCurrentUser(MyUser::class.java) + if (userInfo==null){ + toast("你需要先登录才能使用消息功能") + rv_message.visibility = View.GONE + return + } + if (userInfo.objectId!=null) { + BmobIM.connect(userInfo.objectId, object : ConnectListener() { + override fun done(uid: String, e: BmobException?) { + if (e == null) { + //连接成功 + rv_message.visibility = View.VISIBLE + val conversations = BmobIM.getInstance().loadAllConversation() + if (conversations.size==0){ + toast("你还没有任何消息纪录") + return + } + if (conversations[0] != null) { + Log.d(TAG, conversations[0].conversationTitle) + val layoutManager = LinearLayoutManager(activity) + rv_message!!.layoutManager = layoutManager + mMessageAdapter = MessageAdapter(conversations, activity) + rv_message!!.adapter = mMessageAdapter + } + Log.d(TAG, "成功连接") + } else { + //连接失败 + Log.d(TAG, "连接失败") + } + } + }) + } + } + + @Subscribe + fun onEventMainThread(event: MessageEvent) { + //重新获取本地消息并刷新列表 + + Log.d(TAG, "got a message from MessageFragment") + + val conversations = BmobIM.getInstance().loadAllConversation() + + Log.d(TAG, conversations.size.toString()) + + if (conversations[0] != null) { + mMessageAdapter = MessageAdapter(conversations, activity) + rv_message!!.adapter = mMessageAdapter + } + + + } + + @Subscribe + fun helloEventBus(message: String) { + Log.d(TAG,message) + if (message == "login"){ + getMessage() + } + else if (message == "signout"){ + getMessage() + } + } + + @Subscribe + fun onEventMainThread(event: OfflineMessageEvent) { + //重新刷新列表 + Log.d(TAG, "got a offline message") + } + + companion object { + + private val TAG = "MessageFragment" + } +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/MoreFragment.kt b/app/src/main/java/me/zhaoweihao/hnuplus/MoreFragment.kt new file mode 100644 index 0000000..a85f892 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/MoreFragment.kt @@ -0,0 +1,52 @@ +package me.zhaoweihao.hnuplus + + +import android.app.Fragment +import android.content.Intent +import android.os.Bundle + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import kotlinx.android.synthetic.main.fragment_more.* + + +/** + * Created by ZhaoWeihao on 2017/11/9. + */ + + +class MoreFragment : Fragment() { + + override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + return inflater!!.inflate(R.layout.fragment_more, container, false) + + } + + override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + ll_to_weather.setOnClickListener { + val intent = Intent(activity,WeatherActivity::class.java) + startActivity(intent) + } + + ll_to_note.setOnClickListener { + val intent = Intent(activity,NoteActivity::class.java) + startActivity(intent) + } + + ll_to_translate.setOnClickListener { + val intent = Intent(activity,TranslateActivity::class.java) + startActivity(intent) + } + } + + } + + + + + + diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Msg.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Msg.kt new file mode 100644 index 0000000..55b9a52 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Msg.kt @@ -0,0 +1,14 @@ +package me.zhaoweihao.hnuplus + +/** + * Created by Administrator on 2018/2/12. + */ + +class Msg(val content: String, val type: Int) { + companion object { + + val TYPE_RECEIVED = 0 + + val TYPE_SENT = 1 + } +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/MsgAdapter.kt b/app/src/main/java/me/zhaoweihao/hnuplus/MsgAdapter.kt new file mode 100644 index 0000000..c400252 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/MsgAdapter.kt @@ -0,0 +1,46 @@ +package me.zhaoweihao.hnuplus + +import android.support.v7.widget.RecyclerView +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.TextView + +/** + * Created by Administrator on 2018/2/12. + */ + +class MsgAdapter(private val mMsgList: List) : RecyclerView.Adapter() { + + class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var leftLayout: LinearLayout = view.findViewById(R.id.left_layout) + var rightLayout: LinearLayout = view.findViewById(R.id.right_layout) + var leftMsg: TextView = view.findViewById(R.id.left_msg) + var rightMsg: TextView = view.findViewById(R.id.right_msg) + + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MsgAdapter.ViewHolder { + val view = LayoutInflater.from(parent.context).inflate(R.layout.msg_item, parent, false) + return ViewHolder(view) + } + + override fun onBindViewHolder(holder: MsgAdapter.ViewHolder, position: Int) { + val msg = mMsgList[position] + if (msg.type == Msg.TYPE_RECEIVED) { + holder.leftLayout.visibility = View.VISIBLE + holder.rightLayout.visibility = View.GONE + holder.leftMsg.text = msg.content + } else if (msg.type == Msg.TYPE_SENT) { + holder.rightLayout.visibility = View.VISIBLE + holder.leftLayout.visibility = View.GONE + holder.rightMsg.text = msg.content + } + + } + + override fun getItemCount(): Int { + return mMsgList.size + } +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/MyOrderActivity.kt b/app/src/main/java/me/zhaoweihao/hnuplus/MyOrderActivity.kt new file mode 100644 index 0000000..877e477 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/MyOrderActivity.kt @@ -0,0 +1,61 @@ +package me.zhaoweihao.hnuplus + +import android.support.v7.app.AppCompatActivity +import android.os.Bundle +import android.support.v7.widget.LinearLayoutManager +import android.util.Log +import cn.bmob.v3.exception.BmobException +import cn.bmob.v3.BmobQuery +import cn.bmob.v3.BmobUser +import cn.bmob.v3.listener.FindListener +import kotlinx.android.synthetic.main.activity_my_order.* +import me.zhaoweihao.hnuplus.Adapter.OrderAdapter +import me.zhaoweihao.hnuplus.Bmob.MyUser +import me.zhaoweihao.hnuplus.Bmob.Order +import org.jetbrains.anko.toast + + +class MyOrderActivity : AppCompatActivity() { + + companion object { + private val TAG = "MyOrderActivity" + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_my_order) + + title = "我的订单" + + val user = BmobUser.getCurrentUser(MyUser::class.java) + + if (user == null){ + toast("你需要登录才能使用此功能") + return + } + + val userId = user.objectId + + val query = BmobQuery() + query.addWhereEqualTo("buyerId", userId) + query.setLimit(50) + query.findObjects(object : FindListener() { + override fun done(orders: List, e: BmobException?) { + if (e == null) { + Log.d(TAG,"查询成功:共" + orders.size + "条数据。") + if (orders.isEmpty()){ + toast("你目前还没有任何订单信息") + return + } + val layoutManager = LinearLayoutManager(this@MyOrderActivity) + rv_my_order!!.layoutManager = layoutManager + val adapter = OrderAdapter(orders) + rv_my_order!!.adapter = adapter + } else { + Log.d(TAG, "失败:" + e.message + "," + e.errorCode) + } + } + }) + + } +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/NoteActivity.kt b/app/src/main/java/me/zhaoweihao/hnuplus/NoteActivity.kt new file mode 100644 index 0000000..f15405e --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/NoteActivity.kt @@ -0,0 +1,132 @@ +package me.zhaoweihao.hnuplus + + +import android.support.v7.app.AlertDialog +import android.support.v7.app.AppCompatActivity +import android.os.Bundle + +import android.support.v7.widget.StaggeredGridLayoutManager +import android.util.Log +import android.view.View +import android.widget.Toast + +import com.taishi.flipprogressdialog.FlipProgressDialog + +import java.util.ArrayList +import java.util.Collections +import cn.bmob.v3.BmobQuery +import cn.bmob.v3.BmobUser +import cn.bmob.v3.exception.BmobException +import cn.bmob.v3.listener.FindListener +import cn.bmob.v3.listener.UpdateListener +import kotlinx.android.synthetic.main.activity_note.* +import me.zhaoweihao.hnuplus.Adapter.NoteAdapter +import me.zhaoweihao.hnuplus.Bmob.MyUser +import me.zhaoweihao.hnuplus.Bmob.Note +import me.zhaoweihao.hnuplus.Utils.Utility +import org.jetbrains.anko.toast + +class NoteActivity : AppCompatActivity() { + + private var noteAdapter: NoteAdapter? = null + private var flipProgressDialog: FlipProgressDialog? = null + + companion object { + private val TAG = "NoteActivity" + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_note) + + val user = BmobUser.getCurrentUser(MyUser::class.java) + + if (user == null){ + toast("你需要登录才能使用云笔记功能") + return + } + + flipProgressDialog = Utility.myDialog() + flipProgressDialog!!.show(fragmentManager, "") + + title = getString(R.string.note_title) + + updateData() + + } + + private fun updateData() { + val bmobQuery = BmobQuery() + bmobQuery.findObjects(object : FindListener() { + override fun done(list: MutableList, e: BmobException?) { + if (e == null) { + if (list.size==0){ + toast("你还没有任何笔记") + showOneItem() + return + } + Log.d(TAG, list[0].content) + val layoutManager = StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL) + rv_notes!!.layoutManager = layoutManager + rv_notes!!.isNestedScrollingEnabled = false + val note = Note() + note.content = "" + list.add(note) + Collections.reverse(list) + noteAdapter = NoteAdapter(list, this@NoteActivity) + rv_notes!!.adapter = noteAdapter + ll_note_bottom!!.visibility = View.VISIBLE + flipProgressDialog!!.dismiss() + } else { + Log.d(TAG, "发生异常") + showOneItem() + + } + } + }) + } + + fun showDeleteDialog(objectID: String) { + val strings = arrayOf(getString(R.string.delete_warn)) + AlertDialog.Builder(this) + .setItems(strings) { dialogInterface, i -> + if (i == 0) { + val note = Note() + note.objectId = objectID + note.delete(object : UpdateListener() { + override fun done(e: BmobException?) { + if (e == null) { + Toast.makeText(this@NoteActivity, R.string.delete_success, Toast.LENGTH_SHORT).show() + updateData() + } else { + Toast.makeText(this@NoteActivity, R.string.delete_failed, Toast.LENGTH_SHORT).show() + } + + } + }) + } + } + .create().show() + } + + fun showOneItem(){ + val noteList = ArrayList() + val layoutManager = StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL) + rv_notes!!.layoutManager = layoutManager + rv_notes!!.isNestedScrollingEnabled = false + val note = Note() + note.content = "" + noteList.add(note) + noteAdapter = NoteAdapter(noteList, this@NoteActivity) + rv_notes!!.adapter = noteAdapter + ll_note_bottom!!.visibility = View.VISIBLE + flipProgressDialog!!.dismiss() + } + + override fun onRestart() { + super.onRestart() + flipProgressDialog!!.show(fragmentManager, "") + updateData() + Log.d(TAG, "onRestart") + } +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/NoteEditActivity.kt b/app/src/main/java/me/zhaoweihao/hnuplus/NoteEditActivity.kt new file mode 100644 index 0000000..a988d03 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/NoteEditActivity.kt @@ -0,0 +1,99 @@ +package me.zhaoweihao.hnuplus + +import android.support.v7.app.AppCompatActivity +import android.os.Bundle +import android.view.MenuItem +import android.widget.Toast + +import cn.bmob.v3.BmobACL +import cn.bmob.v3.BmobUser +import cn.bmob.v3.exception.BmobException +import cn.bmob.v3.listener.SaveListener +import cn.bmob.v3.listener.UpdateListener +import kotlinx.android.synthetic.main.activity_note_edit.* +import me.zhaoweihao.hnuplus.Bmob.MyUser +import me.zhaoweihao.hnuplus.Bmob.Note + +class NoteEditActivity : AppCompatActivity() { + + private var isAdd: Boolean = false + private var contentBefore: String? = null + private var objectID: String? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_note_edit) + title = getString(R.string.edit_title) + val actionBar = supportActionBar + actionBar!!.setDisplayHomeAsUpEnabled(true) + + val intent = intent + isAdd = intent.getBooleanExtra("data", true) + if (isAdd) { + + } else { + contentBefore = intent.getStringExtra("content") + objectID = intent.getStringExtra("objectID") + et_note!!.setText(contentBefore) + } + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + android.R.id.home -> updateOrSaveData() + } + return true + } + + private fun updateOrSaveData() { + val contentAfter = et_note!!.text.toString() + if (isAdd) { + if (contentAfter == "") { + finish() + } else { + val user = BmobUser.getCurrentUser(MyUser::class.java) + val note = Note() + note.content = contentAfter + note.author = user + + val bmobACL = BmobACL() + bmobACL.setReadAccess(user, true) + bmobACL.setWriteAccess(user, true) + + note.acl = bmobACL + note.save(object : SaveListener() { + override fun done(s: String, e: BmobException?) { + if (e == null) { + Toast.makeText(this@NoteEditActivity, R.string.save_success, Toast.LENGTH_SHORT).show() + finish() + } else { + Toast.makeText(this@NoteEditActivity, R.string.save_failed, Toast.LENGTH_SHORT).show() + } + } + }) + } + + } else { + if (contentAfter == contentBefore) { + finish() + } else { + val note = Note() + note.content = contentAfter + note.update(objectID, object : UpdateListener() { + override fun done(e: BmobException?) { + if (e == null) { + Toast.makeText(this@NoteEditActivity, R.string.update_success, Toast.LENGTH_SHORT).show() + finish() + } else { + Toast.makeText(this@NoteEditActivity, R.string.save_failed, Toast.LENGTH_SHORT).show() + } + } + }) + } + } + } + + override fun onBackPressed() { + updateOrSaveData() + } +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/OrderActivity.kt b/app/src/main/java/me/zhaoweihao/hnuplus/OrderActivity.kt new file mode 100644 index 0000000..3f4a31e --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/OrderActivity.kt @@ -0,0 +1,60 @@ +package me.zhaoweihao.hnuplus + +import android.support.v7.app.AppCompatActivity +import android.os.Bundle +import android.widget.Toast +import cn.bmob.v3.exception.BmobException +import cn.bmob.v3.listener.SaveListener +import kotlinx.android.synthetic.main.activity_order.* +import me.zhaoweihao.hnuplus.Bmob.Order + +class OrderActivity : AppCompatActivity() { + + companion object { + private val TAG = "OrderActivity" + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_order) + + title = "确认订单(测试版)" + + val intent = intent + val goodId = intent.getStringExtra("goodId") + val buyerId = intent.getStringExtra("buyerId") + val sellerId = intent.getStringExtra("sellerId") + val address = intent.getStringExtra("address") + val goodName = intent.getStringExtra("goodName") + val price = intent.getStringExtra("price") + val imageUrl = intent.getStringExtra("imageUrl") + + tv_address.text = "地址:"+address + tv_price.text = "价格:"+price + tv_good.text = "商品名字:"+goodName + + btn_order.setOnClickListener { + val order = Order() + order.address = address + order.goodId = goodId + order.sellerId = sellerId + order.buyerId = buyerId + order.price = price + order.goodName = goodName + order.imageUrl = imageUrl + + + order.save(object : SaveListener() { + override fun done(s: String, e: BmobException?) { + if (e == null) { + Toast.makeText(this@OrderActivity, "下单成功", Toast.LENGTH_SHORT).show() + finish() + } else { + Toast.makeText(this@OrderActivity, "下单失败", Toast.LENGTH_SHORT).show() + } + } + }) + } + + } +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/PersonalActivity.kt b/app/src/main/java/me/zhaoweihao/hnuplus/PersonalActivity.kt new file mode 100644 index 0000000..3e09d2b --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/PersonalActivity.kt @@ -0,0 +1,128 @@ +package me.zhaoweihao.hnuplus + +import android.Manifest +import android.content.Intent +import android.content.pm.ActivityInfo +import android.content.pm.PackageManager +import android.support.v7.app.AppCompatActivity +import android.os.Bundle +import android.provider.MediaStore +import android.support.v4.app.ActivityCompat +import android.support.v4.content.ContextCompat +import android.util.Log +import cn.bmob.v3.BmobUser +import com.zhihu.matisse.Matisse +import com.zhihu.matisse.MimeType +import com.zhihu.matisse.engine.impl.GlideEngine +import kotlinx.android.synthetic.main.activity_personal.* +import me.zhaoweihao.hnuplus.Bmob.MyUser +import cn.bmob.v3.exception.BmobException +import cn.bmob.v3.listener.UpdateListener +import cn.bmob.v3.listener.UploadFileListener +import cn.bmob.v3.datatype.BmobFile +import java.io.File + + +class PersonalActivity : AppCompatActivity() { + + companion object { + private val TAG = "PersonalActivity" + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_personal) + + btn_change_avatar.setOnClickListener { + // 请求运行时权限申请 + if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), 1) + } else { + showImageSelector() + } + val user = BmobUser.getCurrentUser(MyUser::class.java) + + } + } + + private fun showImageSelector(){ + Matisse.from(this) + .choose(setOf(MimeType.JPEG, MimeType.PNG)) + .countable(true) + .maxSelectable(1) + .gridExpectedSize(resources.getDimensionPixelSize(R.dimen.grid_expected_size)) + .restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) + .thumbnailScale(0.85f) + .imageEngine(GlideEngine()) + .forResult(2) + } + + override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { + when (requestCode) { + 1 -> if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + showImageSelector() + } else { + Log.d(TAG,"用户拒绝了权限申请") + } + } + } + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + when (requestCode) { + 2 -> if (resultCode == RESULT_OK) { + //uri to path + var path: String? = null + val uri = Matisse.obtainResult(data)[0]//你需要转换的uri + val filePathColumn = arrayOf(MediaStore.Images.Media.DATA) + val cursor = contentResolver.query(uri, filePathColumn, null, null, null) + if (cursor!!.moveToFirst()) { + val columnIndex = cursor.getColumnIndex(filePathColumn[0]) + path = cursor.getString(columnIndex)//输出的path + Log.d(TAG,"输出的path为:"+path) + uploadAvatar(path) + } else { + //boooo, cursor doesn't have rows ... + } + cursor.close() + + } + } + } + + private fun uploadAvatar(path: String){ + + val bmobFile = BmobFile(File(path)) + bmobFile.uploadblock(object : UploadFileListener() { + + override fun done(e: BmobException?) { + if (e == null) { + //bmobFile.getFileUrl()--返回的上传文件的完整地址 + Log.d(TAG,"上传文件成功:" + bmobFile.fileUrl) + setAvatar(bmobFile.fileUrl) + } else { + Log.d(TAG,"上传文件失败:" + e.message) + } + + } + + override fun onProgress(value: Int?) { + // 返回的上传进度(百分比) + } + }) + + } + + private fun setAvatar(url:String){ + val newUser = MyUser() + newUser.userAvatar= url + val bmobUser = BmobUser.getCurrentUser(MyUser::class.java) + newUser.update(bmobUser.objectId, object : UpdateListener() { + override fun done(e: BmobException?) { + if (e == null) { + Log.d(TAG,"更新用户信息成功") + } else { + Log.d(TAG,"更新用户信息失败:" + e.message) + } + } + }) + } +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/PostActivity.kt b/app/src/main/java/me/zhaoweihao/hnuplus/PostActivity.kt new file mode 100644 index 0000000..fd0a17d --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/PostActivity.kt @@ -0,0 +1,93 @@ +package me.zhaoweihao.hnuplus + +import android.app.FragmentManager +import android.content.Intent +import android.support.v7.app.AppCompatActivity +import android.os.Bundle +import android.provider.MediaStore + +import android.util.Log +import android.view.Menu +import android.view.MenuItem + +import com.zhihu.matisse.Matisse +import kotlinx.android.synthetic.main.activity_post.* +import me.zhaoweihao.hnuplus.Interface.PostInterface + + +class PostActivity : AppCompatActivity() { + + private var postFragment: PostFragment? = null + + private var listener: PostInterface? = null + + companion object { + private val TAG = "PostActivity" + } + + var paths: Array = arrayOfNulls(9) + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_post) + setSupportActionBar(my_toolbar) + title = "发布二手商品" + val actionBar = supportActionBar + actionBar!!.setDisplayHomeAsUpEnabled(true) + val transaction = (fragmentManager as FragmentManager?)!!.beginTransaction() + if (postFragment == null) { + postFragment = PostFragment() + setListener(postFragment!!) + transaction.add(R.id.fl_post, postFragment) + } else { + transaction.show(postFragment) + } + transaction.commit() + + } + + fun setListener(listener: PostInterface) { + this.listener = listener + } + + override fun onCreateOptionsMenu(menu: Menu?): Boolean { + menuInflater.inflate(R.menu.toolbar,menu) + return true + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + when (requestCode) { + 2 -> if (resultCode == RESULT_OK) { + //uri to path + val uris = Matisse.obtainResult(data) + val uriLength = uris.size + paths = arrayOfNulls(uriLength) + listener!!.showImage(uris) + var i = 0 + for (uri in uris) { + val filePathColumn = arrayOf(MediaStore.Images.Media.DATA) + val cursor = contentResolver.query(uri, filePathColumn, null, null, null) + if (cursor!!.moveToFirst()) { + val columnIndex = cursor.getColumnIndex(filePathColumn[0]) + paths[i] = cursor.getString(columnIndex) + Log.d(TAG,paths[i]+" "+i.toString()+" "+paths.size.toString()) + i++ + + } else { + //boooo, cursor doesn't have rows ... + } + cursor.close() + } + } + } + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.action_submit -> listener!!.myMethod() + android.R.id.home -> finish() + } + return true + } + +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/PostFragment.kt b/app/src/main/java/me/zhaoweihao/hnuplus/PostFragment.kt new file mode 100644 index 0000000..accec91 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/PostFragment.kt @@ -0,0 +1,186 @@ +package me.zhaoweihao.hnuplus + +import android.Manifest +import android.app.Activity.RESULT_OK +import android.app.Fragment +import android.content.Intent +import android.content.pm.ActivityInfo +import android.content.pm.PackageManager +import android.net.Uri +import android.os.Build +import android.os.Bundle +import android.support.v4.app.ActivityCompat +import android.support.v4.content.ContextCompat +import android.util.Log +import android.view.* +import com.bumptech.glide.Glide +import com.lzy.ninegrid.ImageInfo +import com.lzy.ninegrid.preview.NineGridViewClickAdapter +import com.tencent.map.geolocation.TencentLocation +import com.tencent.map.geolocation.TencentLocationListener +import com.tencent.map.geolocation.TencentLocationManager +import com.tencent.map.geolocation.TencentLocationRequest +import com.yoavst.kotlin.`KotlinPackage$Toasts$53212cf1`.toast +import com.zhihu.matisse.Matisse +import com.zhihu.matisse.MimeType +import com.zhihu.matisse.engine.impl.GlideEngine +import kotlinx.android.synthetic.main.activity_buy.* +import kotlinx.android.synthetic.main.fragment_post.* +import me.zhaoweihao.hnuplus.Interface.PostInterface +import org.jetbrains.anko.toast + +/** + * Created by ZhaoWeihao on 2017/11/9. + */ + +class PostFragment : Fragment(), PostInterface,TencentLocationListener{ + + private var addressStr: String? = null + + + companion object { + private val TAG = "PostFragment" + } + + + override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + return inflater!!.inflate(R.layout.fragment_post, container, + false) + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + if (Build.VERSION.SDK_INT >= 23) { + val permissions = arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.READ_PHONE_STATE, Manifest.permission.WRITE_EXTERNAL_STORAGE) + + if (activity.checkSelfPermission(permissions[0]) != PackageManager.PERMISSION_GRANTED) { + requestPermissions(permissions, 0) + } else { + val request = TencentLocationRequest.create() + val locationManager = TencentLocationManager.getInstance(activity) + val error = locationManager.requestLocationUpdates(request, this) + } + } + + } + + override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + btn_pic!!.setOnClickListener { + // 请求运行时权限申请 + if (ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), 1) + } else { + showImageSelector() + } + + } + } + + private fun showImageSelector(){ + Matisse.from(activity) + .choose(setOf(MimeType.JPEG,MimeType.PNG)) + .countable(true) + .maxSelectable(9) + .gridExpectedSize(resources.getDimensionPixelSize(R.dimen.grid_expected_size)) + .restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) + .thumbnailScale(0.85f) + .imageEngine(GlideEngine()) + .forResult(2) + } + + override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { + when (requestCode) { + 1 -> if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + showImageSelector() + } else { + toast(activity, "denied") + } + } + } + + override fun myMethod() { + val intent = Intent() + + when { + et_post_title.text.isEmpty() -> { + toast("标题不能为空") + return + } + et_post_price.text.isEmpty() -> { + toast("价格不能为空") + return + } + et_post_detail.text.isEmpty() -> { + toast("细节不能为空") + return + } + tv_location.text.isEmpty() -> { + toast("地址不能为空") + return + } + + (activity as PostActivity).paths[0] == null -> { + intent.putExtra("post_title", et_post_title.text.toString()) + intent.putExtra("post_detail", et_post_detail.text.toString()) + intent.putExtra("post_location", tv_location.text.toString()) + intent.putExtra("post_price", et_post_price.text.toString()) + activity.setResult(RESULT_OK,intent) + activity.finish() + } + else -> { + Log.d(TAG,"have photo") + intent.putExtra("post_title", et_post_title.text.toString()) + intent.putExtra("post_detail", et_post_detail.text.toString()) + intent.putExtra("post_location", tv_location.text.toString()) + intent.putExtra("post_price", et_post_price.text.toString()) + intent.putExtra("data_return_2",(activity as PostActivity).paths) + activity.setResult(RESULT_OK,intent) + activity.finish() + } + } + } + + override fun showImage(imageUris: List) { + btn_pic.visibility = View.INVISIBLE + val imageInfo = ArrayList() + + val length = imageUris.size + + Log.d(TAG,length.toString()) + + for (imageUri in imageUris) { + Log.d(TAG, imageUri.toString()) + val info = ImageInfo() + info.setThumbnailUrl(imageUri.toString()) + info.setBigImageUrl(imageUri.toString()) + imageInfo.add(info) + } + + iv_show_pic.setAdapter(NineGridViewClickAdapter(activity, imageInfo)) + iv_show_pic.setOnClickListener { showImageSelector() } + } + + override fun onStatusUpdate(p0: String?, p1: Int, p2: String?) { + + } + + override fun onLocationChanged(tencentLocation: TencentLocation?, error: Int, reason: String?) { + if (TencentLocation.ERROR_OK == error) { + // 定位成功 + Log.d(TAG, tencentLocation!!.address) + addressStr = tencentLocation.address + tv_location.text = addressStr + //删除注册的监听器 + val locationManager = TencentLocationManager.getInstance(activity) + locationManager.removeUpdates(this) + } else { + // 定位失败 + } + } + + + +} \ No newline at end of file diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/SigninActivity.kt b/app/src/main/java/me/zhaoweihao/hnuplus/SigninActivity.kt new file mode 100644 index 0000000..a3915d0 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/SigninActivity.kt @@ -0,0 +1,60 @@ +package me.zhaoweihao.hnuplus + +import android.app.FragmentManager +import android.support.v7.app.AppCompatActivity +import android.os.Bundle + +import android.os.Build +import android.view.View +import android.view.ViewGroup + + +class SigninActivity : AppCompatActivity() { + + private var signinFragment: SigninFragment? = null + private var signupFragment: SignupFragment? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + findViewById(android.R.id.content).systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE + } + + setContentView(R.layout.activity_signin) + + val transaction = (fragmentManager as FragmentManager?)!!.beginTransaction() + + if (signinFragment == null) { + signinFragment = SigninFragment() + transaction.add(R.id.fl_signin, signinFragment) + } else { + transaction.show(signinFragment) + } + transaction.commit() + + } + + open fun toSignupFragment(){ + + val transaction = (fragmentManager as FragmentManager?)!!.beginTransaction() + + if (signinFragment != null) { + transaction.hide(signinFragment) + } + + if (signupFragment == null) { + signupFragment = SignupFragment() + transaction.add(R.id.fl_signin, signupFragment) + } else { + transaction.show(signupFragment) + } + transaction.commit() + + } + + + + + +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/SigninFragment.kt b/app/src/main/java/me/zhaoweihao/hnuplus/SigninFragment.kt new file mode 100644 index 0000000..6b4619b --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/SigninFragment.kt @@ -0,0 +1,110 @@ +package me.zhaoweihao.hnuplus + +import android.app.Fragment +import android.graphics.drawable.AnimationDrawable +import android.os.Bundle + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup + +import android.widget.Toast + +import cn.bmob.v3.BmobUser +import cn.bmob.v3.exception.BmobException +import cn.bmob.v3.listener.SaveListener +import com.taishi.flipprogressdialog.FlipProgressDialog +import kotlinx.android.synthetic.main.signin_layout.* +import me.zhaoweihao.hnuplus.Utils.Utility +import org.greenrobot.eventbus.EventBus +import org.jetbrains.anko.toast + + +/** + * Created by ZhaoWeihao on 2017/11/10. + */ + + +class SigninFragment : Fragment() { + + private var anim: AnimationDrawable? = null + + private var flipProgressDialog:FlipProgressDialog? = null + + override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + return inflater!!.inflate(R.layout.signin_layout, + container, false) + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + } + + override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + anim = container_1!!.background as AnimationDrawable + anim!!.setEnterFadeDuration(6000) + anim!!.setExitFadeDuration(2000) + + flipProgressDialog= Utility.myDialog() + + + btn_signup_1!!.setOnClickListener { (activity as SigninActivity).toSignupFragment() } + + btn_signin_2!!.setOnClickListener { + val username = et_username_1!!.text.toString() + val password = et_password_1!!.text.toString() + + if (username == "" || password == "") { + Toast.makeText(activity, getString(R.string.can_be_empty), Toast.LENGTH_SHORT).show() + } else { + + flipProgressDialog!!.show(fragmentManager,"") + + val bu2 = BmobUser() + bu2.username = username + bu2.setPassword(password) + + bu2.login(object : SaveListener() { + + override fun done(bmobUser: BmobUser?, e: BmobException?) { + if (e == null) { + Toast.makeText(activity, getString(R.string.signin_success), Toast.LENGTH_SHORT).show() + flipProgressDialog!!.dismiss() + val login = "login" + EventBus.getDefault().post(login) + activity.finish() + } else { + toast("登录失败,请检查用户名和密码") + flipProgressDialog!!.dismiss() + } + } + }) + + + + + } + } + } + + override fun onResume() { + super.onResume() + if (anim != null && !anim!!.isRunning) + anim!!.start() + } + + override fun onPause() { + super.onPause() + if (anim != null && anim!!.isRunning) { + anim!!.stop() + } + } + + override fun onDestroy() { + super.onDestroy() + } + + +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/SignupFragment.kt b/app/src/main/java/me/zhaoweihao/hnuplus/SignupFragment.kt new file mode 100644 index 0000000..442cfc5 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/SignupFragment.kt @@ -0,0 +1,108 @@ +package me.zhaoweihao.hnuplus + +import android.app.Fragment +import android.graphics.drawable.AnimationDrawable +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Toast + +import cn.bmob.v3.BmobUser +import cn.bmob.v3.exception.BmobException +import cn.bmob.v3.listener.SaveListener +import com.taishi.flipprogressdialog.FlipProgressDialog +import kotlinx.android.synthetic.main.signup_layout.* +import me.zhaoweihao.hnuplus.Bmob.MyUser +import me.zhaoweihao.hnuplus.Utils.Utility +import org.greenrobot.eventbus.EventBus +import org.jetbrains.anko.toast + +/** + * Created by ZhaoWeihao on 2017/11/10. + */ + +class SignupFragment : Fragment() { + + companion object { + private val TAG ="SignupFragment" + } + + private var anim: AnimationDrawable? = null + private var flipProgressDialog:FlipProgressDialog? = null + + override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + return inflater!!.inflate(R.layout.signup_layout, + container, false) + } + + override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + anim = container_2!!.background as AnimationDrawable + anim!!.setEnterFadeDuration(6000) + anim!!.setExitFadeDuration(2000) + + flipProgressDialog=Utility.myDialog() + + btn_signup_2!!.setOnClickListener { + val username = et_username_2!!.text.toString() + val password = et_password_2!!.text.toString() + val passwordConfirm = et_password_confirm!!.text.toString() + val email = et_email!!.text.toString() + + if (username == "" || password == "" || email == "" || passwordConfirm == "") { + Toast.makeText(activity, "不能为空", Toast.LENGTH_SHORT).show() + } else if (password != passwordConfirm) { + Toast.makeText(activity, getString(R.string.confirm_pwd_not_pwd), Toast.LENGTH_SHORT).show() + } else { + flipProgressDialog!!.show(fragmentManager,"") + + val bu = MyUser() + bu.username = username + bu.setPassword(password) + bu.email = email + bu.userAvatar= "http://bmob-cdn-16924.b0.upaiyun.com/2018/03/19/f25d585d60ea4365be5e79832af5837c.jpg" + bu.signUp(object : SaveListener() { + override fun done(s: MyUser?, e: BmobException?) { + if (e == null) { + Toast.makeText(activity, getString(R.string.signup_success), Toast.LENGTH_SHORT).show() + bu.login(object : SaveListener() { + + override fun done(bmobUser: BmobUser?, e: BmobException?) { + if (e == null) { + Toast.makeText(activity, R.string.signin_success, Toast.LENGTH_SHORT).show() + flipProgressDialog!!.dismiss() + val login = "login" + EventBus.getDefault().post(login) + activity.finish() + } else { + toast("登录失败,错误代码:"+e.toString()) + flipProgressDialog!!.dismiss() + } + } + }) + } else { + toast("注册失败,请检查你输入的内容,错误代码:"+e.toString()) + flipProgressDialog!!.dismiss() + } + } + }) + } + } + } + + override fun onResume() { + super.onResume() + if (anim != null && !anim!!.isRunning) + anim!!.start() + } + + override fun onPause() { + super.onPause() + if (anim != null && anim!!.isRunning) { + anim!!.stop() + } + } + +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/TranslateActivity.kt b/app/src/main/java/me/zhaoweihao/hnuplus/TranslateActivity.kt new file mode 100644 index 0000000..dccadd7 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/TranslateActivity.kt @@ -0,0 +1,205 @@ +package me.zhaoweihao.hnuplus + +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context +import android.content.Intent +import android.os.Bundle +import android.support.design.widget.Snackbar +import android.support.v7.app.AppCompatActivity +import android.text.Editable +import android.text.TextWatcher +import android.view.LayoutInflater +import android.view.View +import android.view.inputmethod.InputMethodManager +import android.widget.TextView +import android.widget.Toast + +import butterknife.ButterKnife +import kotlinx.android.synthetic.main.content_main.* +import kotlinx.android.synthetic.main.editarea.* +import kotlinx.android.synthetic.main.explain.* +import kotlinx.android.synthetic.main.query_layout.* +import kotlinx.android.synthetic.main.translate.* +import kotlinx.android.synthetic.main.web.* +import me.zhaoweihao.hnuplus.Gson.Translate +import me.zhaoweihao.hnuplus.Utils.HttpUtil +import me.zhaoweihao.hnuplus.Utils.Utility + +import java.io.IOException + +import okhttp3.Call +import okhttp3.Response + +/** + * Created by Zhaoweihao on 17/7/6. + * 如果对我的项目有任何疑问可以给我发邮件或者提issues + * Email:zhaoweihaochn@gmail.com + * 如果觉得我的项目写得好可以给我star和fork + * 谢谢! + */ + +class TranslateActivity : AppCompatActivity() { + + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.content_main) + + title = "翻译" + + translate_btn!!.visibility = View.INVISIBLE + iv_clear!!.visibility = View.INVISIBLE + copy!!.visibility = View.INVISIBLE + share!!.visibility = View.INVISIBLE + mixLayout!!.visibility = View.INVISIBLE + + iv_clear!!.setOnClickListener { word_input!!.setText("") } + word_input!!.addTextChangedListener(object : TextWatcher { + + override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {} + override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { + + if (word_input!!.editableText.toString().isNotEmpty()) { + iv_clear!!.visibility = View.VISIBLE + translate_btn!!.visibility = View.VISIBLE + } else { + iv_clear!!.visibility = View.INVISIBLE + translate_btn!!.visibility = View.INVISIBLE + } + } + + override fun afterTextChanged(s: Editable) {} + }) + translate_btn!!.setOnClickListener { + if (word_input!!.text.toString().isEmpty()) { + Snackbar.make(translate_btn!!, R.string.input_empty, Snackbar.LENGTH_SHORT) + .show() + } else { + progress_bar!!.visibility = View.VISIBLE + val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager + if (imm.isActive) { + imm.hideSoftInputFromWindow(translate_btn!!.windowToken, 0) + } + val word = word_input!!.text.toString() + val url = "http://fanyi.youdao.com/openapi.do?keyfrom=zhaotranslator&key=1681711370&type=data&doctype=json&version=1.1&q=" + + HttpUtil.sendOkHttpRequest(url + word, object : okhttp3.Callback { + override fun onFailure(call: Call, e: IOException) { + //网络请求失败,开启子进程,更新页面 + runOnUiThread { + progress_bar!!.visibility = View.GONE + Toast.makeText(this@TranslateActivity, R.string.translate_fail, Toast.LENGTH_SHORT).show() + } + } + + @Throws(IOException::class) + override fun onResponse(call: Call, response: Response) { + val responseData = response.body().string() + try { + val translate = Utility.handleTranslateResponse(responseData) + runOnUiThread { + if (translate!!.errorCode == 0) { + showTranslateInfo(translate) + } else if (translate.errorCode == 20) { + progress_bar!!.visibility = View.GONE + Toast.makeText(this@TranslateActivity, R.string.translate_overlong, Toast.LENGTH_SHORT).show() + } else { + progress_bar!!.visibility = View.GONE + Toast.makeText(this@TranslateActivity, R.string.translate_fail, Toast.LENGTH_SHORT).show() + } + } + } catch (e: Exception) { + e.printStackTrace() + progress_bar!!.visibility = View.INVISIBLE + } + + } + }) + } + } + } + + + private fun showTranslateInfo(translate: Translate?) { + translation_layout!!.removeAllViews() + explains_layout!!.removeAllViews() + web_layout!!.removeAllViews() + translate_title!!.setText(R.string.translate_title) + explains_title!!.setText(R.string.explains_title) + web_title!!.setText(R.string.web_title) + for (i in 0 until translate!!.translation!!.size) { + val view = LayoutInflater.from(this).inflate(R.layout.translation_item, translation_layout, false) + val translateText = view.findViewById(R.id.translation_text) as TextView + translateText.text = translate.translation!![i] + translateText.setTextColor(resources.getColor(R.color.white)) + translateText.textSize = 25f + translation_layout!!.addView(view) + } + + query_text!!.text = translate.query + if (translate.basic == null) { + phonetic_text!!.visibility = View.INVISIBLE + explains_layout!!.visibility = View.INVISIBLE + } else { + + phonetic_text!!.text = "[" + translate.basic!!.phonetic + "]" + for (i in 0 until translate.basic!!.explains!!.size) { + val view = LayoutInflater.from(this).inflate(R.layout.explains_item, explains_layout, false) + val explainsText = view.findViewById(R.id.expalins_text) as TextView + explainsText.text = translate.basic!!.explains!![i] + explains_layout!!.addView(view) + phonetic_text!!.visibility = View.VISIBLE + explains_layout!!.visibility = View.VISIBLE + } + } + + + if (translate.web == null) { + web_layout!!.visibility = View.INVISIBLE + } else { + + for (i in 0 until translate.web!!.size) { + val view = LayoutInflater.from(this).inflate(R.layout.web_item, web_layout, false) + val keyText = view.findViewById(R.id.key_text) as TextView + val valueText = view.findViewById(R.id.value_text) as TextView + keyText.text = translate.web!![i].key + val values = getFinalValue(translate.web!![i].value) + valueText.text = values + web_layout!!.addView(view) + web_layout!!.visibility = View.VISIBLE + } + } + progress_bar!!.visibility = View.GONE + copy!!.setOnClickListener { + val manager = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + val clipData = ClipData.newPlainText("text", translate.translation!![0]) + manager.primaryClip = clipData + Snackbar.make(translate_btn!!, R.string.copy_success, Snackbar.LENGTH_SHORT) + .show() + } + share!!.setOnClickListener { + val intent = Intent() + intent.setAction(Intent.ACTION_SEND).type = "text/plain" + intent.putExtra(Intent.EXTRA_TEXT, translate.translation!![0]) + startActivity(Intent.createChooser(intent, getString(R.string.share_choice))) + } + + copy!!.visibility = View.VISIBLE + share!!.visibility = View.VISIBLE + mixLayout!!.visibility = View.VISIBLE + } + + private fun getFinalValue(value: Array?): String { + var finalValue = "" + for (i in value!!.indices) { + if (i == value.size - 1) { + finalValue += value[i] + } else { + finalValue = finalValue + value[i] + "," + } + } + return finalValue + } + +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/UserFragment.kt b/app/src/main/java/me/zhaoweihao/hnuplus/UserFragment.kt new file mode 100644 index 0000000..f4089f8 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/UserFragment.kt @@ -0,0 +1,102 @@ +package me.zhaoweihao.hnuplus + +import android.app.Fragment +import android.content.Intent + +import android.os.Bundle + + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Toast + +import cn.bmob.v3.BmobUser +import com.squareup.picasso.Picasso +import com.taishi.flipprogressdialog.FlipProgressDialog +import kotlinx.android.synthetic.main.fragment_user.* + +import me.zhaoweihao.hnuplus.Bmob.MyUser +import me.zhaoweihao.hnuplus.Utils.Utility +import org.greenrobot.eventbus.EventBus + + +/** + * Created by ZhaoWeihao on 2017/11/9. + */ + +class UserFragment : Fragment() { + + private var userInfo: MyUser? = null + + private var flipProgressDialog:FlipProgressDialog? = null + + override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + return inflater!!.inflate(R.layout.fragment_user, + container, false) + } + + override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + flipProgressDialog = Utility.myDialog() + btn_signout!!.setOnClickListener { + BmobUser.logOut() + val currentUser = BmobUser.getCurrentUser() + if (currentUser == null) { + Toast.makeText(activity, getString(R.string.signout_success), Toast.LENGTH_SHORT).show() + tv_signinstatus!!.text = getString(R.string.not_signin_warn) + btn_signin_1!!.visibility = View.VISIBLE + btn_signout!!.visibility = View.GONE + val signout = "signout" + EventBus.getDefault().post(signout) + } + } + + btn_signin_1!!.setOnClickListener { + val intent = Intent(activity, SigninActivity::class.java) + startActivity(intent) + } + btn_my_order.setOnClickListener { + val intent = Intent(activity, MyOrderActivity::class.java) + startActivity(intent) + } + btn_get_order.setOnClickListener { + val intent = Intent(activity, GetOrderActivity::class.java) + startActivity(intent) + } +// iv_avatar.setOnClickListener { +// val intent = Intent(activity, PersonalActivity::class.java) +// startActivity(intent) +// } + + + } + + override fun onResume() { + super.onResume() + flipProgressDialog!!.show(fragmentManager,"") + + userInfo = BmobUser.getCurrentUser(MyUser::class.java) + if (userInfo != null) { + tv_signinstatus!!.text = "登录账户:" + userInfo!!.username + btn_signin_1!!.visibility = View.GONE + btn_signout!!.visibility = View.VISIBLE + + Picasso.with(activity) + .load(userInfo!!.userAvatar) + .resize(100, 100) + .centerCrop() + .into(iv_avatar) + + flipProgressDialog!!.dismiss() + } else { + tv_signinstatus!!.text = getString(R.string.not_signin_warn) + btn_signin_1!!.visibility = View.VISIBLE + btn_signout!!.visibility = View.GONE + flipProgressDialog!!.dismiss() + } + + } + +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Utils/HttpUtil.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Utils/HttpUtil.kt new file mode 100644 index 0000000..d85ae48 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Utils/HttpUtil.kt @@ -0,0 +1,18 @@ +package me.zhaoweihao.hnuplus.Utils + +import okhttp3.OkHttpClient +import okhttp3.Request + +/** + * Created by Zhaoweihao on 2018/1/6. + */ + +object HttpUtil { + fun sendOkHttpRequest(address: String, callback: okhttp3.Callback) { + val client = OkHttpClient() + val request = Request.Builder() + .url(address) + .build() + client.newCall(request).enqueue(callback) + } +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/Utils/Utility.kt b/app/src/main/java/me/zhaoweihao/hnuplus/Utils/Utility.kt new file mode 100644 index 0000000..42095c8 --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/Utils/Utility.kt @@ -0,0 +1,61 @@ +package me.zhaoweihao.hnuplus.Utils + +import android.graphics.Color + +import com.google.gson.Gson +import com.taishi.flipprogressdialog.FlipProgressDialog + +import java.util.ArrayList + +import me.zhaoweihao.hnuplus.Gson.Translate +import me.zhaoweihao.hnuplus.Gson.Weather +import me.zhaoweihao.hnuplus.R + + +/** + * Created by Zhaoweihao on 2018/1/6. + */ + +object Utility { + fun handleWeatherResponse(response: String): Weather? { + try { + val gson = Gson() + return gson.fromJson(response, Weather::class.java) + } catch (e: Exception) { + e.printStackTrace() + } + + return null + } + + fun handleTranslateResponse(response: String): Translate? { + try { + val gson = Gson() + return gson.fromJson(response, Translate::class.java) + } catch (e: Exception) { + e.printStackTrace() + } + + return null + + } + + fun myDialog(): FlipProgressDialog { + val imageList = ArrayList() + imageList.add(R.drawable.ic_favorite_border_white_24dp) + imageList.add(R.drawable.ic_favorite_white_24dp) + + val flipY = FlipProgressDialog() + flipY.setImageList(imageList) + flipY.setCanceledOnTouchOutside(false) + flipY.setOrientation("rotationY") + flipY.setBackgroundColor(Color.parseColor("#FF4081")) + flipY.setDimAmount(0.3f) + flipY.setCornerRadius(32) + + return flipY + + } + + +} diff --git a/app/src/main/java/me/zhaoweihao/hnuplus/WeatherActivity.kt b/app/src/main/java/me/zhaoweihao/hnuplus/WeatherActivity.kt new file mode 100644 index 0000000..059924b --- /dev/null +++ b/app/src/main/java/me/zhaoweihao/hnuplus/WeatherActivity.kt @@ -0,0 +1,237 @@ +package me.zhaoweihao.hnuplus + +import android.Manifest +import android.content.pm.PackageManager +import android.graphics.Color +import android.os.Build +import android.support.v7.app.AppCompatActivity +import android.os.Bundle +import android.util.Log +import android.view.LayoutInflater +import android.view.View +import android.widget.LinearLayout +import android.widget.TextView + +import com.github.pwittchen.weathericonview.WeatherIconView +import com.taishi.flipprogressdialog.FlipProgressDialog +import com.tencent.map.geolocation.TencentLocation +import com.tencent.map.geolocation.TencentLocationListener +import com.tencent.map.geolocation.TencentLocationManager +import com.tencent.map.geolocation.TencentLocationRequest + +import java.io.IOException + +import butterknife.BindView +import butterknife.ButterKnife +import kotlinx.android.synthetic.main.activity_weather.* +import kotlinx.android.synthetic.main.current.* +import me.zhaoweihao.hnuplus.Gson.Channel +import me.zhaoweihao.hnuplus.Gson.Forecast +import me.zhaoweihao.hnuplus.Gson.Weather +import me.zhaoweihao.hnuplus.Utils.HttpUtil +import me.zhaoweihao.hnuplus.Utils.Utility +import okhttp3.Call +import okhttp3.Callback +import okhttp3.Response + +class WeatherActivity : AppCompatActivity(), TencentLocationListener { + + private var latitudeStr: String? = null + private var longitudeStr: String? = null + private var addressStr: String? = null + private var icon: Int = 0 + + private var flipProgressDialog: FlipProgressDialog? = null + + companion object { + private val TAG = "WeatherActivity" + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_weather) + ButterKnife.bind(this) + + flipProgressDialog = Utility.myDialog() + + flipProgressDialog!!.show(fragmentManager, "") + + if (Build.VERSION.SDK_INT >= 23) { + val permissions = arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.READ_PHONE_STATE, Manifest.permission.WRITE_EXTERNAL_STORAGE) + + if (checkSelfPermission(permissions[0]) != PackageManager.PERMISSION_GRANTED) { + requestPermissions(permissions, 0) + } else { + val request = TencentLocationRequest.create() + val locationManager = TencentLocationManager.getInstance(this) + val error = locationManager.requestLocationUpdates(request, this) + } + } + + + } + + private fun requestWeather(latitude: String, longitude: String) { + + val url = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(SELECT%20woeid%20FROM%20geo.places%20WHERE%20text%3D%22($latitude%2C$longitude)%22)%20and%20u%3D'c'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys" + HttpUtil.sendOkHttpRequest(url, object : Callback { + override fun onFailure(call: Call, e: IOException) { + + } + + @Throws(IOException::class) + override fun onResponse(call: Call, response: Response) { + val responseData = response.body().string() + val weather = Utility.handleWeatherResponse(responseData) + val channel = weather!!.query!!.results!!.channel + val location = channel!!.location!!.city + "," + channel.location!!.region + "," + channel.location!!.country + Log.d(TAG, location) + runOnUiThread { + if (weather != null) { + showWeatherInfo(weather) + } else { + Log.d(TAG, "获取天气信息失败") + } + } + } + }) + } + + private fun showWeatherInfo(weather: Weather?) { + val channel = weather!!.query!!.results!!.channel + val locationStr = channel!!.location!!.city + "," + channel.location!!.region + "," + channel.location!!.country + val statusStr = channel.item!!.condition!!.text + val degreeStr = channel.item!!.condition!!.temp + val humidityStr = channel.atmosphere!!.humidity + val speedStr = channel.wind!!.speed + val sunriseStr = channel.astronomy!!.sunrise + val sunsetStr = channel.astronomy!!.sunset + val chillStr = channel.wind!!.chill + val directionStr = channel.wind!!.direction + val pressureStr = channel.atmosphere!!.pressure + val risingStr = channel.atmosphere!!.rising + val visibilityStr = channel.atmosphere!!.visibility + val code = channel.item!!.condition!!.code + + title = locationStr + status!!.text = statusStr + degree!!.text = degreeStr!! + " C" + humidity!!.text = humidityStr!! + " %" + speed!!.text = speedStr!! + " km/h" + sunrise!!.text = sunriseStr + sunset!!.text = sunsetStr + forecast_layout!!.removeAllViews() + chill!!.text = chillStr + direction!!.text = directionStr + speed_detail!!.text = speedStr + " km/h" + humidity_detail!!.text = humidityStr + " %" + pressure!!.text = pressureStr!! + " mb" + rising!!.text = risingStr + visibility!!.text = visibilityStr!! + " km" + latitude!!.text = latitudeStr + longitude!!.text = longitudeStr + address!!.text = addressStr + setWeatherIcon(code) + + my_weather_icon!!.setIconResource(getString(icon)) + my_weather_icon!!.setIconSize(80) + my_weather_icon!!.setIconColor(Color.GRAY) + + for (forecast in channel.item!!.forecastList!!) { + val view = LayoutInflater.from(this).inflate(R.layout.forecast_item, forecast_layout, false) + val date = view.findViewById(R.id.date) + val day = view.findViewById(R.id.day) + val statusForecast = view.findViewById(R.id.status_forecast) + val high = view.findViewById(R.id.high) + val low = view.findViewById(R.id.low) + val dateStr = forecast.date + val dayStr = forecast.day + val statusForecastStr = forecast.text + val highStr = forecast.high + val lowStr = forecast.low + date.text = dateStr + day.text = dayStr + statusForecast.text = statusForecastStr + high.text = highStr + low.text = lowStr + forecast_layout!!.addView(view) + } + + flipProgressDialog!!.dismiss() + } + + private fun setWeatherIcon(code: String?) { + when (code) { + "0" -> icon = R.string.wi_tornado + "1" -> icon = R.string.wi_storm_showers + "2" -> icon = R.string.wi_tornado + "3" -> icon = R.string.wi_thunderstorm + "4" -> icon = R.string.wi_thunderstorm + "5" -> icon = R.string.wi_snow + "6" -> icon = R.string.wi_rain_mix + "7" -> icon = R.string.wi_rain_mix + "8" -> icon = R.string.wi_sprinkle + "9" -> icon = R.string.wi_sprinkle + "10" -> icon = R.string.wi_hail + "11" -> icon = R.string.wi_showers + "12" -> icon = R.string.wi_showers + "13" -> icon = R.string.wi_snow + "14" -> icon = R.string.wi_storm_showers + "15" -> icon = R.string.wi_snow + "16" -> icon = R.string.wi_snow + "17" -> icon = R.string.wi_hail + "18" -> icon = R.string.wi_hail + "19" -> icon = R.string.wi_cloudy_gusts + "20" -> icon = R.string.wi_fog + "21" -> icon = R.string.wi_fog + "22" -> icon = R.string.wi_fog + "23" -> icon = R.string.wi_cloudy_gusts + "24" -> icon = R.string.wi_cloudy_windy + "25" -> icon = R.string.wi_thermometer + "26" -> icon = R.string.wi_cloudy + "27" -> icon = R.string.wi_night_cloudy + "28" -> icon = R.string.wi_day_cloudy + "29" -> icon = R.string.wi_night_cloudy + "30" -> icon = R.string.wi_day_cloudy + "31" -> icon = R.string.wi_night_clear + "32" -> icon = R.string.wi_day_sunny + "33" -> icon = R.string.wi_night_clear + "34" -> icon = R.string.wi_day_sunny_overcast + "35" -> icon = R.string.wi_hail + "36" -> icon = R.string.wi_day_sunny + "37" -> icon = R.string.wi_thunderstorm + "38" -> icon = R.string.wi_thunderstorm + "39" -> icon = R.string.wi_thunderstorm + "40" -> icon = R.string.wi_storm_showers + "41" -> icon = R.string.wi_snow + "42" -> icon = R.string.wi_snow + "43" -> icon = R.string.wi_snow + "44" -> icon = R.string.wi_cloudy + "45" -> icon = R.string.wi_lightning + "46" -> icon = R.string.wi_snow + "47" -> icon = R.string.wi_thunderstorm + "3200" -> icon = R.string.wi_cloud + else -> icon = R.string.wi_cloud + } + + } + + override fun onLocationChanged(tencentLocation: TencentLocation, error: Int, reason: String) { + if (TencentLocation.ERROR_OK == error) { + // 定位成功 + Log.d(TAG, tencentLocation.address) + latitudeStr = tencentLocation.latitude.toString() + longitudeStr = tencentLocation.longitude.toString() + addressStr = tencentLocation.address + requestWeather(latitudeStr!!, longitudeStr!!) + val locationManager = TencentLocationManager.getInstance(this) + locationManager.removeUpdates(this) + } else { + // 定位失败 + } + } + + override fun onStatusUpdate(s: String, i: Int, s1: String) { + + } +} diff --git a/app/src/main/jniLibs/README.txt b/app/src/main/jniLibs/README.txt new file mode 100644 index 0000000..300a1fd --- /dev/null +++ b/app/src/main/jniLibs/README.txt @@ -0,0 +1,6 @@ +ʱ䣺2016-12-05 +ߣyosonyuan from Tencent +˵ +soļΪr10룬ϵƫת⡣Ϊandroid Mtext relocation warningΪerrorµsoӿʧܵ⡣ +ľܽᣬ http://blog.csdn.net/yuanyl/article/details/48174387 +㷨 \ No newline at end of file diff --git a/app/src/main/jniLibs/arm64-v8a/libtencentloc.so b/app/src/main/jniLibs/arm64-v8a/libtencentloc.so new file mode 100644 index 0000000..43e9e99 Binary files /dev/null and b/app/src/main/jniLibs/arm64-v8a/libtencentloc.so differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libtencentloc.so b/app/src/main/jniLibs/armeabi-v7a/libtencentloc.so new file mode 100644 index 0000000..490c0b6 Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libtencentloc.so differ diff --git a/app/src/main/jniLibs/armeabi/libtencentloc.so b/app/src/main/jniLibs/armeabi/libtencentloc.so new file mode 100644 index 0000000..beb3d8f Binary files /dev/null and b/app/src/main/jniLibs/armeabi/libtencentloc.so differ diff --git a/app/src/main/jniLibs/x86/libtencentloc.so b/app/src/main/jniLibs/x86/libtencentloc.so new file mode 100644 index 0000000..4126da8 Binary files /dev/null and b/app/src/main/jniLibs/x86/libtencentloc.so differ diff --git a/app/src/main/jniLibs/x86_64/libtencentloc.so b/app/src/main/jniLibs/x86_64/libtencentloc.so new file mode 100644 index 0000000..cd91c38 Binary files /dev/null and b/app/src/main/jniLibs/x86_64/libtencentloc.so differ diff --git a/app/src/main/res/drawable-hdpi/ic_avatar_placeholder.png b/app/src/main/res/drawable-hdpi/ic_avatar_placeholder.png new file mode 100644 index 0000000..580bdba Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_avatar_placeholder.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_avatar_placeholder.png b/app/src/main/res/drawable-mdpi/ic_avatar_placeholder.png new file mode 100644 index 0000000..5d46052 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_avatar_placeholder.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_avatar_placeholder.png b/app/src/main/res/drawable-xhdpi/ic_avatar_placeholder.png new file mode 100644 index 0000000..cad37eb Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_avatar_placeholder.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_avatar_placeholder.png b/app/src/main/res/drawable-xxhdpi/ic_avatar_placeholder.png new file mode 100644 index 0000000..7789cdf Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_avatar_placeholder.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_avatar_placeholder.png b/app/src/main/res/drawable-xxxhdpi/ic_avatar_placeholder.png new file mode 100644 index 0000000..8810758 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_avatar_placeholder.png differ diff --git a/app/src/main/res/drawable/animation_list.xml b/app/src/main/res/drawable/animation_list.xml new file mode 100644 index 0000000..288f4f9 --- /dev/null +++ b/app/src/main/res/drawable/animation_list.xml @@ -0,0 +1,15 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/avatar.png b/app/src/main/res/drawable/avatar.png new file mode 100644 index 0000000..de76209 Binary files /dev/null and b/app/src/main/res/drawable/avatar.png differ diff --git a/app/src/main/res/drawable/button_background.xml b/app/src/main/res/drawable/button_background.xml new file mode 100644 index 0000000..697a745 --- /dev/null +++ b/app/src/main/res/drawable/button_background.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/button_background2.xml b/app/src/main/res/drawable/button_background2.xml new file mode 100644 index 0000000..00cd244 --- /dev/null +++ b/app/src/main/res/drawable/button_background2.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/button_background3.xml b/app/src/main/res/drawable/button_background3.xml new file mode 100644 index 0000000..f46899d --- /dev/null +++ b/app/src/main/res/drawable/button_background3.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/button_press.xml b/app/src/main/res/drawable/button_press.xml new file mode 100644 index 0000000..3a10748 --- /dev/null +++ b/app/src/main/res/drawable/button_press.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/button_press2.xml b/app/src/main/res/drawable/button_press2.xml new file mode 100644 index 0000000..6dfa437 --- /dev/null +++ b/app/src/main/res/drawable/button_press2.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/button_press3.xml b/app/src/main/res/drawable/button_press3.xml new file mode 100644 index 0000000..e1cacc5 --- /dev/null +++ b/app/src/main/res/drawable/button_press3.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/color1.xml b/app/src/main/res/drawable/color1.xml new file mode 100644 index 0000000..ab64359 --- /dev/null +++ b/app/src/main/res/drawable/color1.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/color2.xml b/app/src/main/res/drawable/color2.xml new file mode 100644 index 0000000..2549731 --- /dev/null +++ b/app/src/main/res/drawable/color2.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/color3.xml b/app/src/main/res/drawable/color3.xml new file mode 100644 index 0000000..31d1116 --- /dev/null +++ b/app/src/main/res/drawable/color3.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/color4.xml b/app/src/main/res/drawable/color4.xml new file mode 100644 index 0000000..09f8177 --- /dev/null +++ b/app/src/main/res/drawable/color4.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/community.png b/app/src/main/res/drawable/community.png new file mode 100644 index 0000000..2b7cde4 Binary files /dev/null and b/app/src/main/res/drawable/community.png differ diff --git a/app/src/main/res/drawable/community_grey.png b/app/src/main/res/drawable/community_grey.png new file mode 100644 index 0000000..571f56f Binary files /dev/null and b/app/src/main/res/drawable/community_grey.png differ diff --git a/app/src/main/res/drawable/ic_add_black_24dp.xml b/app/src/main/res/drawable/ic_add_black_24dp.xml new file mode 100644 index 0000000..6ac0287 --- /dev/null +++ b/app/src/main/res/drawable/ic_add_black_24dp.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable/ic_add_grey_24dp.xml b/app/src/main/res/drawable/ic_add_grey_24dp.xml new file mode 100644 index 0000000..338df38 --- /dev/null +++ b/app/src/main/res/drawable/ic_add_grey_24dp.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable/ic_add_white_24dp.png b/app/src/main/res/drawable/ic_add_white_24dp.png new file mode 100644 index 0000000..6704210 Binary files /dev/null and b/app/src/main/res/drawable/ic_add_white_24dp.png differ diff --git a/app/src/main/res/drawable/ic_arrow_forward_white_24dp.png b/app/src/main/res/drawable/ic_arrow_forward_white_24dp.png new file mode 100644 index 0000000..b8113ca Binary files /dev/null and b/app/src/main/res/drawable/ic_arrow_forward_white_24dp.png differ diff --git a/app/src/main/res/drawable/ic_book_round.png b/app/src/main/res/drawable/ic_book_round.png new file mode 100644 index 0000000..c55f878 Binary files /dev/null and b/app/src/main/res/drawable/ic_book_round.png differ diff --git a/app/src/main/res/drawable/ic_close_black_24dp.png b/app/src/main/res/drawable/ic_close_black_24dp.png new file mode 100644 index 0000000..08f59ea Binary files /dev/null and b/app/src/main/res/drawable/ic_close_black_24dp.png differ diff --git a/app/src/main/res/drawable/ic_comment_whitegrey_24dp.xml b/app/src/main/res/drawable/ic_comment_whitegrey_24dp.xml new file mode 100644 index 0000000..6891834 --- /dev/null +++ b/app/src/main/res/drawable/ic_comment_whitegrey_24dp.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable/ic_content_copy_white_24dp.png b/app/src/main/res/drawable/ic_content_copy_white_24dp.png new file mode 100644 index 0000000..5fc17a4 Binary files /dev/null and b/app/src/main/res/drawable/ic_content_copy_white_24dp.png differ diff --git a/app/src/main/res/drawable/ic_delete_black_24dp.xml b/app/src/main/res/drawable/ic_delete_black_24dp.xml new file mode 100644 index 0000000..9de01f9 --- /dev/null +++ b/app/src/main/res/drawable/ic_delete_black_24dp.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable/ic_favorite_border_white_24dp.png b/app/src/main/res/drawable/ic_favorite_border_white_24dp.png new file mode 100644 index 0000000..134a486 Binary files /dev/null and b/app/src/main/res/drawable/ic_favorite_border_white_24dp.png differ diff --git a/app/src/main/res/drawable/ic_favorite_white_24dp.png b/app/src/main/res/drawable/ic_favorite_white_24dp.png new file mode 100644 index 0000000..18d0768 Binary files /dev/null and b/app/src/main/res/drawable/ic_favorite_white_24dp.png differ diff --git a/app/src/main/res/drawable/ic_home_black_24dp.xml b/app/src/main/res/drawable/ic_home_black_24dp.xml new file mode 100644 index 0000000..5fb51c1 --- /dev/null +++ b/app/src/main/res/drawable/ic_home_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_home_grey_24dp.xml b/app/src/main/res/drawable/ic_home_grey_24dp.xml new file mode 100644 index 0000000..f850a61 --- /dev/null +++ b/app/src/main/res/drawable/ic_home_grey_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_image_black_24dp.xml b/app/src/main/res/drawable/ic_image_black_24dp.xml new file mode 100644 index 0000000..cd45326 --- /dev/null +++ b/app/src/main/res/drawable/ic_image_black_24dp.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable/ic_keyboard_backspace_white_24dp.png b/app/src/main/res/drawable/ic_keyboard_backspace_white_24dp.png new file mode 100644 index 0000000..8272676 Binary files /dev/null and b/app/src/main/res/drawable/ic_keyboard_backspace_white_24dp.png differ diff --git a/app/src/main/res/drawable/ic_location_on_3x.png b/app/src/main/res/drawable/ic_location_on_3x.png new file mode 100644 index 0000000..5a21dfa Binary files /dev/null and b/app/src/main/res/drawable/ic_location_on_3x.png differ diff --git a/app/src/main/res/drawable/ic_menu_white_24dp.png b/app/src/main/res/drawable/ic_menu_white_24dp.png new file mode 100644 index 0000000..42482eb Binary files /dev/null and b/app/src/main/res/drawable/ic_menu_white_24dp.png differ diff --git a/app/src/main/res/drawable/ic_mode_edit_black_24dp.xml b/app/src/main/res/drawable/ic_mode_edit_black_24dp.xml new file mode 100644 index 0000000..ba2c413 --- /dev/null +++ b/app/src/main/res/drawable/ic_mode_edit_black_24dp.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable/ic_more_horiz_white_24dp.png b/app/src/main/res/drawable/ic_more_horiz_white_24dp.png new file mode 100644 index 0000000..7f1e162 Binary files /dev/null and b/app/src/main/res/drawable/ic_more_horiz_white_24dp.png differ diff --git a/app/src/main/res/drawable/ic_refresh_white_24dp.png b/app/src/main/res/drawable/ic_refresh_white_24dp.png new file mode 100644 index 0000000..72128fe Binary files /dev/null and b/app/src/main/res/drawable/ic_refresh_white_24dp.png differ diff --git a/app/src/main/res/drawable/ic_send_black_24dp.xml b/app/src/main/res/drawable/ic_send_black_24dp.xml new file mode 100644 index 0000000..af16cff --- /dev/null +++ b/app/src/main/res/drawable/ic_send_black_24dp.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable/ic_share_white_24dp.png b/app/src/main/res/drawable/ic_share_white_24dp.png new file mode 100644 index 0000000..9963c6a Binary files /dev/null and b/app/src/main/res/drawable/ic_share_white_24dp.png differ diff --git a/app/src/main/res/drawable/ic_star_grey600_24dp.png b/app/src/main/res/drawable/ic_star_grey600_24dp.png new file mode 100644 index 0000000..4409173 Binary files /dev/null and b/app/src/main/res/drawable/ic_star_grey600_24dp.png differ diff --git a/app/src/main/res/drawable/ic_star_outline_grey600_24dp.png b/app/src/main/res/drawable/ic_star_outline_grey600_24dp.png new file mode 100644 index 0000000..b51f478 Binary files /dev/null and b/app/src/main/res/drawable/ic_star_outline_grey600_24dp.png differ diff --git a/app/src/main/res/drawable/ic_star_outline_white_24dp.png b/app/src/main/res/drawable/ic_star_outline_white_24dp.png new file mode 100644 index 0000000..ba8eccb Binary files /dev/null and b/app/src/main/res/drawable/ic_star_outline_white_24dp.png differ diff --git a/app/src/main/res/drawable/ic_star_white_24dp.png b/app/src/main/res/drawable/ic_star_white_24dp.png new file mode 100644 index 0000000..33a28c0 Binary files /dev/null and b/app/src/main/res/drawable/ic_star_white_24dp.png differ diff --git a/app/src/main/res/drawable/ic_translation_100.png b/app/src/main/res/drawable/ic_translation_100.png new file mode 100644 index 0000000..2b65f23 Binary files /dev/null and b/app/src/main/res/drawable/ic_translation_100.png differ diff --git a/app/src/main/res/drawable/material_18.png b/app/src/main/res/drawable/material_18.png new file mode 100644 index 0000000..01742e3 Binary files /dev/null and b/app/src/main/res/drawable/material_18.png differ diff --git a/app/src/main/res/drawable/message_left.9.png b/app/src/main/res/drawable/message_left.9.png new file mode 100644 index 0000000..c7337e3 Binary files /dev/null and b/app/src/main/res/drawable/message_left.9.png differ diff --git a/app/src/main/res/drawable/message_right.9.png b/app/src/main/res/drawable/message_right.9.png new file mode 100644 index 0000000..523c9cb Binary files /dev/null and b/app/src/main/res/drawable/message_right.9.png differ diff --git a/app/src/main/res/drawable/more.png b/app/src/main/res/drawable/more.png new file mode 100644 index 0000000..ea07984 Binary files /dev/null and b/app/src/main/res/drawable/more.png differ diff --git a/app/src/main/res/drawable/more_grey.png b/app/src/main/res/drawable/more_grey.png new file mode 100644 index 0000000..f66f5ce Binary files /dev/null and b/app/src/main/res/drawable/more_grey.png differ diff --git a/app/src/main/res/drawable/note.png b/app/src/main/res/drawable/note.png new file mode 100644 index 0000000..86d0173 Binary files /dev/null and b/app/src/main/res/drawable/note.png differ diff --git a/app/src/main/res/drawable/small_icon.png b/app/src/main/res/drawable/small_icon.png new file mode 100644 index 0000000..ec2d16a Binary files /dev/null and b/app/src/main/res/drawable/small_icon.png differ diff --git a/app/src/main/res/drawable/translate.png b/app/src/main/res/drawable/translate.png new file mode 100644 index 0000000..ca23615 Binary files /dev/null and b/app/src/main/res/drawable/translate.png differ diff --git a/app/src/main/res/drawable/user.png b/app/src/main/res/drawable/user.png new file mode 100644 index 0000000..3d0be4c Binary files /dev/null and b/app/src/main/res/drawable/user.png differ diff --git a/app/src/main/res/drawable/user_grey.png b/app/src/main/res/drawable/user_grey.png new file mode 100644 index 0000000..f906914 Binary files /dev/null and b/app/src/main/res/drawable/user_grey.png differ diff --git a/app/src/main/res/drawable/weather.png b/app/src/main/res/drawable/weather.png new file mode 100644 index 0000000..daf1066 Binary files /dev/null and b/app/src/main/res/drawable/weather.png differ diff --git a/app/src/main/res/layout/activity_buy.xml b/app/src/main/res/layout/activity_buy.xml new file mode 100644 index 0000000..751dc99 --- /dev/null +++ b/app/src/main/res/layout/activity_buy.xml @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + +