Skip to content

Commit

Permalink
Merge pull request #13 from PNU-Sinbaram/snsfeed
Browse files Browse the repository at this point in the history
Implement activity of SNS Feed(Post)
  • Loading branch information
lijm1358 committed Sep 2, 2021
2 parents 902c729 + a8bb976 commit 654db2d
Show file tree
Hide file tree
Showing 12 changed files with 714 additions and 1 deletion.
6 changes: 5 additions & 1 deletion client/app/build.gradle
Expand Up @@ -53,6 +53,8 @@ dependencies {
// Retrofit2 for REST API
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-moshi:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.6.2'
implementation 'com.squareup.retrofit2:converter-scalars:2.9.0'
// 네이버 지도 SDK
implementation 'com.naver.maps:map-sdk:3.12.0'
// Obj - a simple Wavefront OBJ file loader
Expand All @@ -67,4 +69,6 @@ dependencies {
implementation("com.gorisse.thomas.sceneform:sceneform:1.19.5")
// Google Location Service
implementation 'com.google.android.gms:play-services-location:16.0.0'
}
// Glide Image loading framework
implementation 'com.github.bumptech.glide:glide:4.12.0'
}
41 changes: 41 additions & 0 deletions client/app/src/main/java/com/sinbaram/mapgo/API/ServerClient.kt
Expand Up @@ -3,11 +3,17 @@ package com.sinbaram.mapgo.API
import com.sinbaram.mapgo.Model.CheckInResponse
import com.sinbaram.mapgo.Model.CheckInRequest
import com.sinbaram.mapgo.Model.Recommendation
import com.sinbaram.mapgo.Model.PostFeedItem
import com.sinbaram.mapgo.Model.Comment
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Headers
import retrofit2.http.POST
import retrofit2.http.Query
import retrofit2.http.Path
import retrofit2.http.Multipart
import retrofit2.http.Part
import retrofit2.http.HTTP
import retrofit2.Call

/** Collections of naver openapi search interface */
Expand All @@ -34,4 +40,39 @@ interface ServerClient {
@Query("epsilon") epsilon: Int,
@Query("keywords") keywords: String
): Call<List<Recommendation>>

/** Get posts from mapgo server */
@GET("Mapgo/sns/post/")
fun GetPosts() : Call<List<PostFeedItem>>

/** Get comments from post with {id} */
@GET("Mapgo/sns/post/{id}/comment/")
fun GetComments(
@Path("id") id: Int
) : Call<List<Comment>>

/** Post comment to post with {id} */
@Multipart
@POST("Mapgo/sns/post/{id}/comment/")
fun PostComment(
@Path("id") id: Int,
@Part("writer") writer: Int,
@Part("contents") contents: String
) : Call<String>

/** add like to post with {id}, as userID */
@Multipart
@POST("Mapgo/sns/post/{id}/like/")
fun AddLike(
@Path("id") id: Int,
@Part("userID") userID: Int
) : Call<String>

/** remove like to post with {id}, as userID */
@Multipart
@HTTP(method="DELETE", hasBody=true, path="Mapgo/sns/post/{id}/like/")
fun DeleteLike(
@Path("id") id: Int,
@Part("userID") userID: Int
) : Call<String>
}
25 changes: 25 additions & 0 deletions client/app/src/main/java/com/sinbaram/mapgo/API/ServerPostAPI.kt
@@ -0,0 +1,25 @@
package com.sinbaram.mapgo.API

import com.sinbaram.mapgo.BuildConfig
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.converter.scalars.ScalarsConverterFactory

/** Retrofit singleton instance for mapgo server post
* ServerAPI's MoshiConverterFactory was not suitable as response
* of PostFeedItem and String, so changed to Gson and Scalars each.
**/
object ServerPostAPI {
var BASE_URL: String = BuildConfig.SERVER_ADDRESS
var retrofit: Retrofit? = null
fun GetSnsClient(): Retrofit? {
if (retrofit == null) {
retrofit = Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build()
}
return retrofit
}
}
@@ -0,0 +1,56 @@
package com.sinbaram.mapgo

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide


/** Recycler adapter to show comments from List of Map containing content, writer, writer image */
class CommentRecyclerAdapter internal constructor(var context: Context, list: MutableList<Map<String, String>>?) :
RecyclerView.Adapter<CommentRecyclerAdapter.ViewHolder>() {
private var mData: MutableList<Map<String, String>>? = null

/** initialize views of comment_recycler.xml */
inner class ViewHolder internal constructor(itemView: View) :
RecyclerView.ViewHolder(itemView) {
var content: TextView
var writer: TextView
var image: ImageView

init {
content = itemView.findViewById(R.id.commentContent)
writer = itemView.findViewById(R.id.commentWriter)
image = itemView.findViewById(R.id.commentImage)
}
}

override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): ViewHolder {
val context: Context = parent.context
val inflater =
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val view: View = inflater.inflate(R.layout.comment_recycler, parent, false)
return ViewHolder(view)
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.writer.text = mData!![position]["writer"]
holder.content.text = mData!![position]["contents"]
Glide.with(context).load(mData!![position]["writerImage"]).into(holder.image)
}

override fun getItemCount(): Int {
return mData!!.size
}

init {
mData = list
}
}
29 changes: 29 additions & 0 deletions client/app/src/main/java/com/sinbaram/mapgo/ImageSliderAdapter.kt
@@ -0,0 +1,29 @@
package com.sinbaram.mapgo

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide

/** ViewPager2 Adapter to show images from post */
class ImageSliderAdapter(val context: Context, imageList: MutableList<String>) : RecyclerView.Adapter<ImageSliderAdapter.PagerViewHolder>() {

var imagelist = imageList

/** Initialize ImageView from image_viewpager.xml */
inner class PagerViewHolder(parent: ViewGroup) : RecyclerView.ViewHolder
(LayoutInflater.from(parent.context).inflate(R.layout.image_viewpager, parent, false)) {
val image = itemView.findViewById<ImageView>(R.id.imageView)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = PagerViewHolder((parent))

override fun onBindViewHolder(holder: PagerViewHolder, position: Int) {
Glide.with(context).load(imagelist[position]).into(holder.image)

}

override fun getItemCount(): Int = imagelist.size
}
59 changes: 59 additions & 0 deletions client/app/src/main/java/com/sinbaram/mapgo/Model/PostFeedItem.kt
@@ -0,0 +1,59 @@
package com.sinbaram.mapgo.Model

import java.io.Serializable

/** data class representing SNS Post
* @property comment : List of dataclass Comment
* @property contents : Content of sns post
* @property like : List of dataclass Like which contains liker's userId
* @property location : Location information which sns post contains
* @property postId : id of sns post
* @property postImage : List of sns post's images url
* @property postTime : String of sns post's upload time
* @property totalLikes : Number of person who liked this post
* @property writer : Writer of sns post which contains writer's deviceId, userId, profile image as String, and username
* */
data class PostFeedItem(
val comment: List<Comment>,
val contents: String,
val like: List<Like>,
val location: Location,
val postID: Int,
val postImage: List<PostImage>,
val postTime: String,
val totalLikes: Int,
val writer: Writer
) : Serializable

/** data class representing single comment object */
data class Comment(
val writer: Writer,
val contents: String,
val post: Int
) : Serializable

/** data class representing location information, latitude as [lat], longitude as [lng] */
data class Location(
val lat: Double,
val lng: Double
) : Serializable

/** data class representing writer of post */
data class Writer(
val deviceID: String,
val id: Int,
val picture: String,
val username: String
) : Serializable

/** data class representing single image object */
data class PostImage(
val image: String,
val post: Int
) : Serializable

/** data class representing liker's information */
data class Like(
val liker: Int,
val post: Int
) : Serializable

0 comments on commit 654db2d

Please sign in to comment.