Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
Shailesh351 committed Apr 8, 2018
1 parent 71e4058 commit 4fe6e80
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 48 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ dependencies {
implementation 'com.firebaseui:firebase-ui-database:1.0.1'
implementation 'com.firebase:firebase-client-android:2.4.0'
implementation 'com.firebaseui:firebase-ui:0.3.1'
implementation 'com.hootsuite.android:nachos:1.1.1'
implementation 'com.github.fiskurgit:ChipCloud:3.0.5'
implementation 'com.google.android:flexbox:0.3.2'

implementation "com.google.android.gms:play-services-auth:${firebaseLibraryVersion}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.support.v7.app.AppCompatActivity
import android.view.MenuItem
import android.widget.Toast
import com.google.firebase.auth.FirebaseAuth
import com.hootsuite.nachos.terminator.ChipTerminatorHandler
import kotlinx.android.synthetic.main.activity_new_post.*
import java.text.SimpleDateFormat
import java.util.*
Expand All @@ -25,6 +26,8 @@ class NewPostActivity : AppCompatActivity() {
}

private fun setup() {
nacho_text_view.addChipTerminator('\n', ChipTerminatorHandler.BEHAVIOR_CHIPIFY_ALL)

submit.setOnClickListener({
submit()
})
Expand All @@ -46,9 +49,17 @@ class NewPostActivity : AppCompatActivity() {
val currentLocalTime = Calendar.getInstance(TimeZone.getDefault()).time
val date = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.getDefault())
val time = date.format(currentLocalTime)
val tagList: ArrayList<String> = arrayListOf()

// Iterate over all of the chips in the NachoTextView
for (chip in nacho_text_view.allChips) {
// Do something with the text of each chip
val text = chip.text
tagList.add(text.toString())
}

val post = Post("1", title, price, firebaseAuth.currentUser?.uid!!, time, type, listOf(""))
Toast.makeText(this, "Post.kt submitted", Toast.LENGTH_SHORT).show()
val post = Post("1", title, price, firebaseAuth.currentUser?.uid!!, time, type, tagList.toList())
Toast.makeText(this, "Post submitted", Toast.LENGTH_SHORT).show()

FirebaseUtil.addPostToFirebaseDatabase(post)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,32 @@ import android.content.Intent
import android.support.v7.widget.RecyclerView
import android.text.format.DateUtils
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import com.google.android.flexbox.FlexboxLayout
import fisk.chipcloud.ChipCloud
import java.text.SimpleDateFormat
import java.util.*


class PostViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
var name: TextView = itemView.findViewById(R.id.name) as TextView
var price: TextView = itemView.findViewById(R.id.price) as TextView
var flexbox: FlexboxLayout = itemView.findViewById(R.id.flexBox) as FlexboxLayout
var type: TextView = itemView.findViewById(R.id.type) as TextView
var chat: ImageView = itemView.findViewById(R.id.chat) as ImageView
var time: TextView = itemView.findViewById(R.id.time) as TextView
val chipCloud = ChipCloud(itemView.context, flexbox)

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

Toast.makeText(itemView.context, post.toString(), Toast.LENGTH_SHORT).show()

post.tags?.let {
this.chipCloud.addChips(it)
}

this.type.text = post.type.toString()

val sdf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.getDefault())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import android.view.ViewGroup
import com.firebase.ui.database.FirebaseRecyclerAdapter
import com.google.firebase.database.*
import com.google.firebase.database.FirebaseDatabase
import com.google.firebase.database.*
import kotlinx.android.synthetic.main.fragment_home.*


Expand All @@ -33,8 +34,37 @@ class HomeFragment : Fragment() {
PostViewHolder::class.java, mPostReference.child("posts")) {

override fun populateViewHolder(viewHolder: PostViewHolder?, post: Post?, position: Int) {
var tags: List<String>? = listOf()
if (post != null) {
viewHolder?.bindPost(post)
if (post.tags == null) {
mPostReference.child("posts")
.child(post.pid).child("tags")
.addValueEventListener(object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot?) {
val t: GenericTypeIndicator<List<String>> = GenericTypeIndicator()
tags = dataSnapshot?.getValue(t)
if (tags === null) {
System.out.println("No tags")
} else {
System.out.println("The first tag is: " + tags.toString())
}
}

override fun onCancelled(databaseError: DatabaseError?) {
}
})
}

val newPost = Post(
post.pid,
post.name,
post.price,
post.uid,
post.time,
post.type,
tags
)
viewHolder?.bindPost(newPost)
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/java/in/webdevlabs/campuscommerce/model/Post.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ package `in`.webdevlabs.campuscommerce.model
* Created by yolo on 7/4/18.
*/
data class Post(
val pid: String?=null,
val name: String?=null,
val price: Int?=null,
val uid: String?=null,
val time: String?=null,
val type: PostType?=null,
val tags: List<String>?=null
val pid: String? = null,
val name: String? = null,
val price: Int? = null,
val uid: String? = null,
val time: String? = null,
val type: PostType? = null,
val tags: List<String>? = null
)

enum class PostType(val type: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ object FirebaseUtil {
val postRef: DatabaseReference = database.getReference("posts").push()
val key = postRef.key
//pids.add(key)
postRef.child("pid").setValue(key)
postRef.child("name").setValue(post.name)
postRef.child("price").setValue(post.price)
postRef.child("uid").setValue(firebaseAuth.currentUser?.uid)
postRef.child("time").setValue(post.time)
postRef.child("type").setValue(post.type)
postRef.child("tag").setValue(post.tags)
postRef.child("pid").setValue(key)
postRef.child("tags").setValue(post.tags)

val userPostRef = database.getReference("users").child(firebaseAuth.currentUser?.uid).child("posts")
//userPostRef.child("posts").setValue(pids)
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/res/drawable/rounded_corner.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1dp"
android:color="#111111" />

<solid android:color="#ffffff" />

<padding
android:bottom="3dp"
android:left="6dp"
android:right="6dp"
android:top="3dp" />

<corners android:radius="12dp" />
</shape>
4 changes: 3 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize" />
android:layout_height="?android:attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

</android.support.design.widget.AppBarLayout>

Expand Down
32 changes: 24 additions & 8 deletions app/src/main/res/layout/activity_new_post.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -13,7 +14,9 @@
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize" />
android:layout_height="?android:attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

</android.support.design.widget.AppBarLayout>

Expand All @@ -29,28 +32,28 @@
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Title">
android:hint="Title"
android:padding="16dp">

<android.support.design.widget.TextInputEditText
android:id="@+id/text_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="text"
android:padding="16dp" />
android:inputType="text" />

</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Price">
android:hint="Price"
android:padding="16dp">

<android.support.design.widget.TextInputEditText
android:id="@+id/text_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:padding="16dp" />
android:inputType="number" />

</android.support.design.widget.TextInputLayout>

Expand All @@ -59,7 +62,7 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
android:padding="16dp"
android:weightSum="1">

<RadioButton
Expand All @@ -81,6 +84,19 @@
android:textSize="14dp" />
</RadioGroup>

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Tags/Categories"
android:padding="16dp">

<com.hootsuite.nachos.NachoTextView
android:id="@+id/nacho_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>


</LinearLayout>

<android.support.design.widget.FloatingActionButton
Expand Down
60 changes: 34 additions & 26 deletions app/src/main/res/layout/item_post.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,43 @@
android:orientation="vertical"
android:tag="cards main container">

<android.support.v7.widget.CardView
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="10dp"
card_view:cardCornerRadius="3dp"
card_view:cardElevation="5dp"
card_view:cardUseCompatPadding="true">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RelativeLayout
android:id="@+id/name_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/name_time">
android:layout_height="wrap_content">

<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="5dp"
android:textStyle="bold"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceLarge"/>
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />

<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:layout_alignParentRight="true"
android:layout_margin="5dp"
android:layout_marginRight="10dp"
android:text="Time"
android:textAppearance="?android:attr/textAppearanceLarge"/>
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="12sp" />
</RelativeLayout>

<TextView
Expand All @@ -49,28 +50,35 @@
android:layout_height="wrap_content"
android:layout_below="@+id/name_time"
android:layout_margin="5dp"
android:textStyle="italic"
android:text="Price"
android:textAppearance="?android:attr/textAppearanceLarge"/>

<ImageView
android:layout_width="80dp"
android:layout_height="50dp"
android:src="@drawable/chat"
android:id="@+id/chat"
android:layout_below="@+id/price"
android:layout_alignParentRight="true"/>
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="italic" />

<TextView
android:id="@+id/type"
android:layout_width="wrap_content"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sell"
android:layout_below="@+id/price"
android:layout_below="@+id/price">

android:layout_margin="5dp"
android:textAppearance="?android:attr/textAppearanceLarge"/>
<com.google.android.flexbox.FlexboxLayout xmlns:app="http://schemas.android.com/tools"
android:id="@+id/flexBox"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:alignContent="stretch"
app:alignItems="stretch"
app:flexWrap="wrap" />

<TextView
android:id="@+id/type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_margin="8dp"
android:background="@drawable/rounded_corner"
android:text="Sell"
android:textSize="18sp" />

</RelativeLayout>
</RelativeLayout>

</android.support.v7.widget.CardView>
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}

Expand Down

0 comments on commit 4fe6e80

Please sign in to comment.