On Android Turbolinks, how to create custom progressView to replace default spinner?

206 views Asked by At

On Android using Turbolinks 5, I am not getting the classic Turbolinks transition (without any intervening white page and with horizontal progress bar on top). So I think I need my own progressView but I may be wrong

I have this in my MainActivity.java

        progressView = new ProgressBar(turbolinksView.getContext());
        TurbolinksSession.getDefault(this)
                .activity(this)
                .adapter(this)
                .view(turbolinksView)
                .progressView(progressView, R.id.indeterminateBar, 300)
                .visit(location);

and this in my activity_main.xml

    <ProgressBar
    android:id="@+id/indeterminateBar"
    android:layout_width="wrap_content"
    style="@android:style/Widget.ProgressBar.Horizontal"
    android:layout_height="wrap_content"
    />

gradle settings are

compileSdkVersion 26
minSdkVersion 19
targetSdkVersion 22

when I run the above I get IllegalArgumentException "A progress indicator view must be provided in your custom progressView." so I tried

.progressView(progressView, progressView.getId(), 300)

but I still get IllegalArgumentException "A progress indicator view must be provided in your custom progressView."

Obviously I am unable to instantiate the right progressView, my question is what how do I get/create the right progressView ??

Apologies in advance for cross posting the question from Turbolinks-Android the only reason I posted it here too is I have been stuck on it for days

2

There are 2 answers

0
Jemshit On

It is here. Your progressView should be some Layout like FrameLayout and it has to contain R.id.indeterminateBar inside. So it would be something like:

<FrameLayout
    android:id="@+id/progressView"
    android:width="match_parent"
    android:height="match_parent"
    android:background="#FFFFFF">
    <ProgressBar
        android:id="@+id/indeterminateBar"
        android:layout_width="wrap_content"
        style="@android:style/Widget.ProgressBar.Horizontal"
        android:layout_height="wrap_content" />
<FrameLayout/>
0
Renan Nery On

I was checking Turbolinks-Android repository and I noticed that the possible cause of this exception is because your progressView object doesn't have R.id.indeterminateBar as a child view.

Long story short, you could try that:

on your activity_main.xml:

<FrameLayout
    android:id="@+id/frameLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ProgressBar
        android:id="@+id/indeterminateBar"
        style="@android:style/Widget.ProgressBar.Horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:indeterminate="true"/>
</FrameLayout>

on your MainActivity.java:

View progressView = (View) findViewById(R.id.frameLayout);
TurbolinksSession.getDefault(this)
     .activity(this)
     .adapter(this)
     .view(turbolinksView)
     .progressView(progressView, R.id.indeterminateBar, 300)
     .visit(location);