i trying develop android app need send data firebase db having it's schema mentioned below:
{ "usercart": { "unique_id": { "book": [ "book_id1" : { "book_title": "abc", "book_url": "imageurl", "chapters_purchased": [ // multiple chapters "chapter_3": { "chapter_title":"title3", "chapter_page_count":"16" }, "chapter_4": { "chapter_title":"title4", "chapter_page_count":"18" } ] }, "book_id2" : { "book_title": "pqr", "book_url": "imageurl2", "chapters_purchased": [ // multiple chapters "chapter_5": { "chapter_title":"title3", "chapter_page_count":"16" }, "chapter_9": { "chapter_title":"title4", "chapter_page_count":"18" } ] } ] } }
i have bookdetailactivity, in i'm showing chapters in recyclerview. so, can "unique_id" & "book_id" bookdetailactivity. after clicking on chapters' recyclerview, need send values specified in above schema.
also, need retrieve values in activity.
the java code mentioned chapters' recyclerview, present in bookdetailactivity mentioned below:
firebaserecycleradapter<chapters, chapterholder> chapter_name_adapter = new firebaserecycleradapter<chapters, chapterholder>( chapters.class, r.layout.simple_chapters_horizontal_list, chapterholder.class, refforbookname.child("chapter")) { @override protected void populateviewholder(chapterholder viewholder, final chapters model, final int position) { viewholder.setchaptername(model.gettitle()); viewholder.buy_or_view_botton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { databasereference refforcart = firebasedatabase.getinstance().getreference().child("usercart").child(uniqueid + "").child("book"); calendar c = calendar.getinstance(); system.out.println("current time => " + c.gettime()); simpledateformat df = new simpledateformat("dd-mm-yyyy hh:mm:ss"); string formatteddate = df.format(c.gettime()); bookcartofchapters bookcartofchapters = new bookcartofchapters(); bookcartofchapters.setbookurl(bookimageurl); bookcartofchapters.setbooktitle(booktitle); chapters_purchased chapters = new chapters_purchased(); chapters.setchapter_title(model.gettitle()); chapters.setdatetime(formatteddate); chapters.setpage_count(model.getpage_count()); chapters.setprice(model.getprice()); chapters_purchased.add(chapters); bookcartofchapters.setchapters_purchased(chapters_purchased); //refforcart.child(bookid+"").setvalue(book); refforcart.child(bookid + "").setvalue(bookcartofchapters); } }); viewholder.chapterslayout.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent tochaptersactivity = new intent(bookdetailactivity.this, folioactivity.class); tochaptersactivity.putextra(folioactivity.intent_epub_source_type, folioactivity.epubsourcetype.assets); tochaptersactivity.putextra(folioactivity.intent_epub_source_path, "epub/one amazing thing - chitra banerjee divakaruni.mobi"); startactivity(tochaptersactivity); } }); } };
help me in achieving same.
Comments
Post a Comment