1

Background

I am calling okhttp newcall(request).enqueue(...) method and if it fails then I renspond back to main activity using a Listener, Where I show textbox and image button to ask user to reload. I am changing view states using RunOnUIThread.

ImageRequester.java

mClient.newCall(request).enqueue(new Callback() {
        @Override
        public void onFailure(Call call, IOException e) {
            mLoadingData = false;
            mLoadingDataFailed = true;
            e.printStackTrace();

           // send exception/fail response to MainActivity
            mResponseListener.recieveException(e);

        }

MainActivity.java

@Override
    public void recieveException(Exception exp) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if(mFirstTime) {
                    mProgressBar.setVisibility(View.VISIBLE);
                    mProgressTextView.setVisibility(View.VISIBLE);
                    reloadButton.setVisibility(View.VISIBLE);
                }
                if (!mFirstTime) {
                    toolbarPbar.setVisibility(View.GONE);
                    mShouldReload = true;
                    invalidateOptionsMenu();
                    Snackbar.make(findViewById(android.R.id.content), "Checking your internet connection might help.", Snackbar.LENGTH_LONG).show();
                }
            }
        });
    }

MainActivity.xml

<TextView
        android:id="@+id/text_progress_fail"
        style="?android:attr/progressBarStyle"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="@string/connectivity"
        android:textAlignment="center"
        android:gravity="center"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.501" />

    <ImageButton
        android:id="@+id/reload_button_main"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@null"
        android:src="@drawable/ic_action_refresh_dark"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/text_progress_fail"
        app:layout_constraintVertical_bias="0.085" />

Issue

The Textview mProgressTextView and ImageButton reloadButton in recieveException(..) method does not show up (settingVisibiltiy(view.VISIBLE)) when I run app on the device. But mProgressBar get visible and conditions are working properly. And Whenever I click a menu view, the mProgressTextView and reloadButton become visible. I tried invalidate and postInvalidate method but all in vain.

I don't know What's bugging around. Please enlighten me.

P.S. I am new to Android

omer
  • 522
  • 1
  • 8
  • 26

0 Answers0