Я хочу назвать документ FireStore датой, выбранной пользователем из диалогового окна выбора даты ( в виде строки ).
"docRef = db.collection (" Списки временных интервалов") .document ( дата, выбранная пользователем )"
Проблема в том, что вместо получения документа с именем, например "22/02/2019", я получаю то, что показанона снимке экрана ниже.
Создано 2 документа (25 и ноль), затем коллекция с именем (02), затем документ с именем (2019)!!
код:
class ReserveTimeFragment : Fragment() {
private var timeSlotsList: ArrayList<TimeSlot>? = null
private var mRecyclerView: RecyclerView? = null
private var mAdapter: TimeSlotAdapter? = null
private var mLayoutManager: RecyclerView.LayoutManager? = null
private var viewHolder: TimeSlotAdapter.TimeSlotViewHolder? = view?.tag as TimeSlotAdapter.TimeSlotViewHolder?
private lateinit var db: FirebaseFirestore
private val dateFormat = SimpleDateFormat("dd / MM / yyyy")
private var dateString: String? = null
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_reserve_time, container, false)
db = FirebaseFirestore.getInstance()
mRecyclerView = view.findViewById(R.id.recyclerViewLO)
pickDate()
callTimeSlotsList()
return view
}
**private fun pickDate() {
val cal = Calendar.getInstance()
var date: String
val datePick = DatePickerDialog(this.context!!, DatePickerDialog.OnDateSetListener { _, mYear, mMonth, mDay
->
cal.set(Calendar.YEAR, mYear)
cal.set(Calendar.MONTH, mMonth)
cal.set(Calendar.DAY_OF_MONTH, mDay)
dateTV.text = dateFormat.format(cal.time)
dateString = dateFormat.format(cal.time)
Toast.makeText(context!!, "$dateString is selected!", Toast.LENGTH_SHORT).show()
}, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH))
datePick.show()
datePick.setCancelable(false)
}**
private fun callTimeSlotsList(){
val docRef = db.collection("Time Slots List").document("$dateString")
docRef.addSnapshotListener(EventListener<DocumentSnapshot> { documentSnapshot, e ->
if (e != null) {
Log.w(TAG, "Time Slots List Listen failed.", e)
return@EventListener
}
if (documentSnapshot != null && documentSnapshot.exists()) {
docRef.get().addOnSuccessListener { documentSnapshot ->
val listObjectFromFB = documentSnapshot.toObject(ListObjectToFireStore::class.java)
val ListToRVAdaptet = listObjectFromFB?.listToFireStore
timeSlotsList = ListToRVAdaptet
buildRecyclerView()
Log.d(TAG, "FireStore Time Slots List Called Successfully")
}
} else {
Log.d(TAG, "New Time Slots List Loaded!")
loadTimeSlotsList()
buildRecyclerView()
}
})
}
private fun buildRecyclerView() {
mRecyclerView!!.setHasFixedSize(true)
mLayoutManager = LinearLayoutManager(context!!)
mAdapter = TimeSlotAdapter(timeSlotsList!!, context!!, db)
mRecyclerView!!.layoutManager = mLayoutManager
mRecyclerView!!.adapter = mAdapter
viewHolder?.cardview?.setOnClickListener {
}
}
private fun loadTimeSlotsList() {
val timeSlotsListToLoad: ArrayList<TimeSlot> = ArrayList()
timeSlotsListToLoad.add(TimeSlot("07:30", "Available", false, 2))
timeSlotsListToLoad.add(TimeSlot("08:00", "Available", false, 2))
val timeSlotsListToFB = ListObjectToFireStore(timeSlotsListToLoad)
db.collection("Time Slots List").document("$dateString").set(timeSlotsListToFB).addOnSuccessListener {
Log.w(TAG, "time Slots List Uploaded Successfully")
}.addOnFailureListener{
Log.w(TAG, "time Slots List Upload Failed")
}
timeSlotsList = timeSlotsListToLoad
}
Может кто-нибудь помочь мне, пожалуйста?