Skip to content

Commit

Permalink
feat: Add option to subscribe tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Shailesh351 committed Apr 8, 2018
1 parent d0cf80a commit 405cb0e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class PostViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

fun bindPost(post: Post) {
this.name.text = post.name
this.price.text = "RS "+post.price.toString()
this.price.text = "RS " + post.price.toString()

post.tag?.let {
tag.text ="Category :"+it
tag.text = "Category :" + it
}

this.type.text = when (post.type) {
Expand All @@ -40,7 +40,7 @@ class PostViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
else -> ""
}

val sdf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.getDefault())
val sdf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.getDefault())
post.time?.run {
time.text = DateUtils.getRelativeTimeSpanString(sdf.parse(post.time).time, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package `in`.webdevlabs.campuscommerce.fragments

import `in`.webdevlabs.campuscommerce.R
import `in`.webdevlabs.campuscommerce.adapters.PostViewHolder
import `in`.webdevlabs.campuscommerce.adapters.StringViewHolder
import `in`.webdevlabs.campuscommerce.model.Post
import `in`.webdevlabs.campuscommerce.utils.FirebaseMessageUtil
import `in`.webdevlabs.campuscommerce.utils.FirebaseUtil
import android.app.AlertDialog
import android.content.DialogInterface
Expand All @@ -12,13 +11,11 @@ import android.support.design.widget.FloatingActionButton
import android.support.v4.app.Fragment
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.EditText
import android.widget.Toast
import com.firebase.ui.FirebaseRecyclerAdapter
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.database.FirebaseDatabase
import kotlinx.android.synthetic.main.fragment_subscription.*
Expand All @@ -30,7 +27,7 @@ class SubscriptionFragment : Fragment() {
savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_subscription, container, false)
val fab = view.findViewById<FloatingActionButton>(R.id.fab) as FloatingActionButton
fab.setOnClickListener(object :View.OnClickListener{
fab.setOnClickListener(object : View.OnClickListener {
override fun onClick(p0: View?) {
showDialog()
}
Expand All @@ -49,7 +46,7 @@ class SubscriptionFragment : Fragment() {
override fun populateViewHolder(viewHolder: StringViewHolder?, model: String?, position: Int) {
if (model != null) {
viewHolder?.bindPost(model)
Toast.makeText(context,model,Toast.LENGTH_LONG)
Toast.makeText(context, model, Toast.LENGTH_LONG)
}
}
}
Expand Down Expand Up @@ -88,7 +85,9 @@ class SubscriptionFragment : Fragment() {
dialogBuilder.setTitle("Tag")
dialogBuilder.setMessage("Enter Tag Below")
dialogBuilder.setPositiveButton("Ok", DialogInterface.OnClickListener { dialog, whichButton ->
FirebaseUtil.addTagToFirebaseDatabase(editText.text.toString(),uid)
FirebaseUtil.addTagToFirebaseDatabase(editText.text.toString(), uid)
FirebaseMessageUtil.subscribeToTag(editText.text.toString())
Toast.makeText(context, editText.text.toString() + " Subscribed", Toast.LENGTH_SHORT).show()
})
dialogBuilder.setNegativeButton("Cancel", DialogInterface.OnClickListener { dialog, whichButton ->
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,23 @@ object FirebaseMessageUtil {
val queue = Volley.newRequestQueue(App.applicationContext())
val url = "http://www.google.com"

val stringRequest = StringRequest(Request.Method.POST, url,
val stringRequest = object : StringRequest(Request.Method.POST, url,
Response.Listener<String> { response ->
Toast.makeText(App.applicationContext(), "Response is: ${response.substring(0, 500)}", Toast.LENGTH_SHORT).show()
// Display the first 500 characters of the response string.
},
Response.ErrorListener {
Toast.makeText(App.applicationContext(), "That didn't work!", Toast.LENGTH_SHORT).show()
})
}) {

override fun getHeaders(): MutableMap<String, String> {
val params = HashMap<String, String>()
params["Content-Type"] = "application/json"
params["Authorization"] = "api-key"

return params
}
}

// Add the request to the RequestQueue.
queue.add(stringRequest)
Expand Down
23 changes: 13 additions & 10 deletions app/src/main/res/layout/item_post.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="#DCDCDC"
card_view:cardCornerRadius="10dp"
card_view:cardElevation="5dp"
card_view:cardBackgroundColor="#DCDCDC"
card_view:cardUseCompatPadding="true">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:paddingBottom="4dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="4dp">

<RelativeLayout
android:id="@+id/name_time"
Expand All @@ -31,8 +35,8 @@
android:layout_alignParentLeft="true"
android:layout_margin="5dp"
android:text="Name"
android:textSize="30dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="30dp"
android:textStyle="bold" />

<TextView
Expand All @@ -54,8 +58,8 @@
android:layout_below="@+id/name_time"
android:layout_margin="5dp"
android:text="Price"
android:textSize="15dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15dp"
android:textStyle="italic" />

<ImageView
Expand All @@ -70,26 +74,25 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/price"
android:orientation="vertical"
android:layout_margin="5dp">
android:orientation="vertical">

<TextView
android:id="@+id/tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="tag"
android:textSize="15dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15dp" />

<TextView
android:id="@+id/type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Sell"
android:textSize="15dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15dp" />

</LinearLayout>

Expand Down

0 comments on commit 405cb0e

Please sign in to comment.