android - Firebase database with progressbar -
i have problem. can't attach progressbar
activity when data loading firebase database. tried attach progressbar via asynctask
, put firebase listener asynctask
doinbackground
, set visibility in preexecute
, postexecute
methods, progressbar
doesn't appear. appreciated.
package org.wangjie.wheelview.directionactivity.direction; import android.content.intent; import android.graphics.color; import android.os.asynctask; import android.os.build; import android.os.bundle; import android.support.annotation.requiresapi; import android.support.design.widget.navigationview; import android.support.v7.app.appcompatactivity; import android.support.v7.widget.linearlayoutmanager; import android.support.v7.widget.recyclerview; import android.support.v7.widget.toolbar; import android.util.log; import android.view.view; import android.widget.imageview; import android.widget.progressbar; import android.widget.textview; import com.bumptech.glide.glide; import com.google.firebase.crash.firebasecrash; import com.google.firebase.database.datasnapshot; import com.google.firebase.database.databaseerror; import com.google.firebase.database.databasereference; import com.google.firebase.database.firebasedatabase; import com.mikepenz.materialdrawer.accountheader; import com.mikepenz.materialdrawer.accountheaderbuilder; import com.mikepenz.materialdrawer.drawer; import com.mikepenz.materialdrawer.drawerbuilder; import com.mikepenz.materialdrawer.model.primarydraweritem; import com.mikepenz.materialdrawer.model.secondarydraweritem; import com.mikepenz.materialdrawer.model.interfaces.idraweritem; import org.wangjie.wheelview.r; import org.wangjie.wheelview.gameactivity.sixstep; import org.wangjie.wheelview.sample.timelineactivity; import java.util.arraylist; public class activitymaindirection extends appcompatactivity { arraylist<direction> garray; textview mconception,mdescription,mtools,mdirectiontitle,mtitledirection,mtitleconception,mtitlemethods; progressbar progressbar; imageview mfirstimage; linearlayoutmanager layoutmanager,layoutmanager2 ; private navigationview mnavigationview; databasereference databasereference; int number,i; recyclerview recycler_artist; recyclerview recycler_pictures; textview mtextview; @requiresapi(api = build.version_codes.jelly_bean_mr2) @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.scroll_main_direction); toolbar mtoolbar=findviewbyid(r.id.toolbar); progressbar=findviewbyid(r.id.progressbar); primarydraweritem item1 = new primarydraweritem().withidentifier(1).withname(r.string.drawer_item_home).withselectable(false).withtextcolor(color.black); // secondarydraweritem item2 = new secondarydraweritem().withidentifier(2).withname(r.string.drawer_paintings).withselectable(false).withtextcolor(color.black); secondarydraweritem item3 = new secondarydraweritem().withidentifier(2).withname(r.string.malevichgame).withselectable(false).withtextcolor(color.black); // item1.withname("a new name draweritem").withbadge("19").withbadgestyle(new badgestyle().withtextcolor(color.black)); //notify drawer updated element. take care else1 //create drawer , remember `drawer` result object // create accountheader accountheader headerresult = new accountheaderbuilder() .withactivity(this) .withheaderbackground(r.drawable.i_007) .build(); //now create drawer , pass accountheader.result //additional drawer setup shown above drawer result = new drawerbuilder() .withactivity(this) .withtoolbar(mtoolbar) .adddraweritems( item1, //new dividerdraweritem(), // item2, item3 // new secondarydraweritem().withname(r.string.drawer_item_settings) ).withtranslucentstatusbar(false).withaccountheader(headerresult).withactionbardrawertoggle(true).withactionbardrawertoggleanimated(true).withondraweritemclicklistener(new drawer.ondraweritemclicklistener() { @override public boolean onitemclick(view view, int position, idraweritem draweritem) { // clicked item :d if(position==1){ intent intent=new intent(view.getcontext(), timelineactivity.class); startactivity(intent); } if(position==2){ intent intent=new intent(view.getcontext(), sixstep.class); startactivity(intent); } return false; } }).withselecteditem(-1) .build(); // getsupportactionbar().setdisplayhomeasupenabled(false); // result.getactionbardrawertoggle().setdrawerindicatorenabled(true); firebasedatabase database=firebasedatabase.getinstance(); databasereference=database.getreference(); garray=new arraylist<>(); recycler_artist= (recyclerview) findviewbyid(r.id.horizontal_artist_list); recycler_pictures=(recyclerview) findviewbyid(r.id.horizontal_list); mdescription= (textview) findviewbyid(r.id.mdescription); mconception= (textview) findviewbyid(r.id.mconception); mtools= (textview) findviewbyid(r.id.mtoolstext); mtitleconception=findviewbyid(r.id.titleconception); mtitledirection=findviewbyid(r.id.titledescription); mtitlemethods=findviewbyid(r.id.titlemethods); mfirstimage=(imageview) findviewbyid(r.id.first_image); mdirectiontitle=(textview) findviewbyid(r.id.main_title); view targetview = findviewbyid(r.id.mconceptionlayout); targetview.getparent().requestchildfocus(targetview,targetview); layoutmanager = new linearlayoutmanager(this); layoutmanager.setorientation(linearlayoutmanager.horizontal); //recycler_artist.sethasfixedsize(false); recycler_artist.setlayoutmanager(layoutmanager); layoutmanager2=new linearlayoutmanager(this); layoutmanager2.scrolltopositionwithoffset(2,20); layoutmanager2.setorientation(linearlayoutmanager.horizontal); //recycler_pictures.sethasfixedsize(true); layoutmanager2.scrolltopositionwithoffset(2,20); recycler_pictures.setlayoutmanager(layoutmanager2); firebasecrash.logcat(log.info,"activity direction"," wtf "); new downloader().execute(); // // // // databasereference.addchildeventlistener(new com.google.firebase.database.childeventlistener() { // // @override // public void onchildadded(datasnapshot datasnapshot, string s) { // // log.e("children tag",(datasnapshot).tostring()); // // iterable<datasnapshot> children = datasnapshot.getchildren(); // // (datasnapshot child : children) { // // //log.e("child tag",child.tostring()); // // direction direction = child.getvalue(direction.class); // garray.add(direction); // log.e("new_dir_added", direction.tostring()); // // } // intent intent=getintent(); // string srt=intent.getstringextra("number_in_list"); // // number=integer.parseint(srt); // // log.e("arrsize", garray.size() +" " + number) // ; // // log.e("url image erre",(garray.get(number).tostring())); // log.e("image_url", garray.get(number).getmurlimage()); // // string [] mpicturelist=garray.get(number).getmurlimage().split(","); // // string [] martistlistimage=garray.get(number).getmartistlistimage().split(","); // // // // // recycler_artist.setadapter(new artistadapter(garray,number));// список художников в Направлении // // recycler_pictures.setadapter(new horizontalrvadapter(garray,number)); // список картин в направлении // // recycler_artist.setadapter(new artistadapter(martistlistimage,number)); // recycler_pictures.setadapter(new horizontalrvadapter(mpicturelist,number)); // // mconception.settext(garray.get(number).getconcept()); // mdescription.settext(garray.get(number).getdesc()); // mtools.settext(garray.get(number).gettechnique()); // mdirectiontitle.settext(garray.get(number).getname()); // // glide.with(getapplicationcontext()) // .load(garray.get(number).getimage()) // .placeholder(r.drawable.papiros) // .into(mfirstimage); // } // // @override // public void onchildchanged(datasnapshot datasnapshot, string s) { // // } // // @override // public void onchildremoved(datasnapshot datasnapshot) { // // } // // @override // public void onchildmoved(datasnapshot datasnapshot, string s) { // // } // // @override // public void oncancelled(databaseerror databaseerror) { // // } // }); } class downloader extends asynctask<object, object, void> { private final progressbar progress=findviewbyid(r.id.progressbar); // public downloader(progressbar progress) { // this.progress = progress; // log.e("downloadercons", string.valueof(progress.getid() == r.id.progressbar)); // } @override protected void onpreexecute() { super.onpreexecute(); progress.setvisibility(view.visible); progress.setmax(100); } @override protected void onpostexecute(void avoid) { super.onpostexecute(avoid); progress.setvisibility(view.gone); } @override protected void onprogressupdate(object... values) { super.onprogressupdate(values); progress.setprogress((integer) values[0]); } @override protected void doinbackground(object... voids) { //return null; (i=0 ;i<20;i++){ publishprogress(i); try{ thread.sleep(30); } catch (interruptedexception ie){ ie.printstacktrace(); } databasereference.addchildeventlistener(new com.google.firebase.database.childeventlistener() { @override public void onchildadded(datasnapshot datasnapshot, string s) { log.e("children tag",(datasnapshot).tostring()); iterable<datasnapshot> children = datasnapshot.getchildren(); (datasnapshot child : children) { //log.e("child tag",child.tostring()); direction direction = child.getvalue(direction.class); garray.add(direction); log.e("new_dir_added", direction.tostring()); } intent intent=getintent(); string srt=intent.getstringextra("number_in_list"); number=integer.parseint(srt); log.e("arrsize", garray.size() +" " + number) ; log.e("url image erre",(garray.get(number).tostring())); log.e("image_url", garray.get(number).getmurlimage()); string [] mpicturelist=garray.get(number).getmurlimage().split(","); string [] martistlistimage=garray.get(number).getmartistlistimage().split(","); // recycler_artist.setadapter(new artistadapter(garray,number));// список художников в Направлении // recycler_pictures.setadapter(new horizontalrvadapter(garray,number)); // список картин в направлении recycler_artist.setadapter(new artistadapter(martistlistimage,number)); recycler_pictures.setadapter(new horizontalrvadapter(mpicturelist,number)); mconception.settext(garray.get(number).getconcept()); mdescription.settext(garray.get(number).getdesc()); mtools.settext(garray.get(number).gettechnique()); mdirectiontitle.settext(garray.get(number).getname()); glide.with(getapplicationcontext()) .load(garray.get(number).getimage()) .placeholder(r.drawable.papiros) .into(mfirstimage); } @override public void onchildchanged(datasnapshot datasnapshot, string s) { } @override public void onchildremoved(datasnapshot datasnapshot) { } @override public void onchildmoved(datasnapshot datasnapshot, string s) { } @override public void oncancelled(databaseerror databaseerror) { } }); // } return null; } return null; } }}
here xml
<android.support.design.widget.coordinatorlayout 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" android:background="@android:color/background_light" > <!-- полосу на тулбаре я убрал, теперь баг появился статус бар выпрыгивает во время прокрутки --> <android.support.design.widget.appbarlayout android:id="@+id/main.appbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:fitssystemwindows="true" > <android.support.design.widget.collapsingtoolbarlayout android:id="@+id/main.collapsing" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_scrollflags="scroll|exituntilcollapsed" app:contentscrim="?attr/colorprimary" app:expandedtitlemarginstart="48dp" app:expandedtitlemarginend="64dp" > <imageview android:src="@drawable/papiros" android:id="@+id/first_image" android:layout_margintop="55dp" android:layout_width="match_parent" android:layout_height="220dp" android:scaletype="centercrop" app:layout_collapsemode="parallax" tools:ignore="contentdescription"/> <android.support.v7.widget.toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionbarsize" app:layout_collapsemode="pin" > <relativelayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="0.88"> <textview android:id="@+id/main_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="" android:textcolor="#000000" android:textsize="19sp" android:visibility="visible" tools:ignore="hardcodedtext,rtlhardcoded" android:layout_centervertical="true" android:layout_alignparentleft="true" android:layout_alignparentstart="true"/> </relativelayout> </android.support.v7.widget.toolbar> </android.support.design.widget.collapsingtoolbarlayout> </android.support.design.widget.appbarlayout> <android.support.v4.widget.nestedscrollview android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" > <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <relativelayout android:id="@+id/mconceptionlayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="15dp" android:layout_marginbottom="15dp" > <textview android:id="@+id/mconception" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textcolor="@color/textcolor" android:textsize="15sp" android:layout_margintop="40dp" android:layout_marginleft="20dp" android:layout_marginstart="20dp" /> <textview android:id="@+id/titleconception" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textsize="15sp" android:textcolor="@color/textcolor" android:layout_marginleft="15dp" android:layout_marginstart="15dp" android:layout_margintop="13dp" android:text="Концепция" android:textstyle="bold" tools:ignore="hardcodedtext"/> </relativelayout> <relativelayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_margin="15dp" android:layout_marginbottom="15dp" > <textview android:id="@+id/titledescription" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Описание" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:layout_alignparenttop="true" android:layout_marginleft="15dp" android:layout_marginstart="15dp" android:layout_margintop="13dp" android:textcolor="@color/textcolor" android:textsize="15sp" android:textstyle="bold" tools:ignore="hardcodedtext"/> <textview android:textcolor="@color/textcolor" android:id="@+id/mdescription" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:layout_centervertical="true" android:layout_margintop="70dp" android:layout_marginleft="20dp" android:layout_marginstart="20dp" android:text="" android:textsize="15sp" /> </relativelayout> <relativelayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margintop="10dp" android:layout_marginbottom="15dp"> <android.support.v7.widget.recyclerview android:id="@+id/horizontal_artist_list" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_alignparentleft="true" android:layout_alignparentstart="true"/> </relativelayout> <relativelayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="15dp" > <textview android:id="@+id/titlemethods" android:textcolor="@color/textcolor" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Методы и техники" android:layout_alignparenttop="true" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:layout_marginleft="15dp" android:layout_marginstart="15dp" android:layout_margintop="10dp" android:textsize="15sp" android:textstyle="bold" tools:ignore="hardcodedtext"/> <textview android:id="@+id/mtoolstext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textcolor="@color/textcolor" android:textsize="15sp" android:text=" " android:layout_margintop="40dp" android:layout_marginleft="20dp" android:layout_marginstart="20dp" tools:ignore="hardcodedtext"/> </relativelayout> <linearlayout android:layout_width="match_parent" android:layout_height="250dp" android:layout_margintop="30dp" android:layout_marginbottom="15dp" android:orientation="vertical" > <android.support.v7.widget.recyclerview android:id="@+id/horizontal_list" android:layout_width="match_parent" android:layout_height="220dp" android:layout_gravity="center_vertical" android:orientation="horizontal" /> </linearlayout> </linearlayout> </android.support.v4.widget.nestedscrollview> <progressbar android:id="@+id/progressbar" style="?android:attr/progressbarstyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:indeterminate="true" android:indeterminatetintmode="src_atop" android:indeterminatetint="@color/grey" /> </android.support.design.widget.coordinatorlayout>
i suggest use library afollestad/material-dialogs
before start loading show dialog
materialdialog.builder builder = new materialdialog.builder(this) .title(r.string.title) .content(r.string.content) .positivetext(r.string.agree); materialdialog dialog = builder.build(); dialog.show();
after finising loading data dismis dialog
dialog.dismiss();
Comments
Post a Comment