Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from PNU-Sinbaram/snsfeed
Implement activity of SNS Feed(Post)
- Loading branch information
Showing
12 changed files
with
714 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
client/app/src/main/java/com/sinbaram/mapgo/API/ServerPostAPI.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
client/app/src/main/java/com/sinbaram/mapgo/CommentRecyclerAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
29
client/app/src/main/java/com/sinbaram/mapgo/ImageSliderAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
59
client/app/src/main/java/com/sinbaram/mapgo/Model/PostFeedItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.