Progress bar replaced with Lottie

This commit is contained in:
Sultan Mustafijul Hoque 2023-12-07 14:07:53 +05:30
parent dff2f691a3
commit b4fd784a9e
3 changed files with 20 additions and 10 deletions

View File

@ -11,18 +11,19 @@ import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.airbnb.lottie.LottieAnimationView;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
public class WebViewActivity extends AppCompatActivity implements View.OnClickListener {
private ProgressBar progressBar;
// private ProgressBar progressBar;
private LottieAnimationView lottieAnimationView;
Button scanAgainButton;
Button btnHome;
@ -34,7 +35,8 @@ public class WebViewActivity extends AppCompatActivity implements View.OnClickLi
scanAgainButton = findViewById(R.id.scanAgain);
btnHome = findViewById(R.id.btnHome);
progressBar = findViewById(R.id.progressBar);
// progressBar = findViewById(R.id.progressBar);
lottieAnimationView = findViewById(R.id.lottieAnimationView);
// Retrieve the URL from the intent
String url = getIntent().getStringExtra("url");
@ -46,19 +48,24 @@ public class WebViewActivity extends AppCompatActivity implements View.OnClickLi
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// Show the progress bar when the page starts loading
progressBar.setVisibility(View.VISIBLE);
// progressBar.setVisibility(View.VISIBLE);
// Show the Lottie animation when the page starts loading
lottieAnimationView.setVisibility(View.VISIBLE);
}
@Override
public void onPageFinished(WebView view, String url) {
// Hide the progress bar when the page finishes loading
progressBar.setVisibility(View.INVISIBLE);
// progressBar.setVisibility(View.INVISIBLE);
// Hide the Lottie animation when the page finishes loading
lottieAnimationView.setVisibility(View.INVISIBLE);
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
// Handle page load error
Toast.makeText(WebViewActivity.this, "Failed to load the page", Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.INVISIBLE);
// progressBar.setVisibility(View.INVISIBLE);
lottieAnimationView.setVisibility(View.INVISIBLE);
}
});

View File

@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
tools:context=".WebViewActivity">
<WebView
@ -20,11 +21,11 @@
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/lottieAnimationView"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_width="180dp"
android:layout_height="180dp"
android:layout_centerInParent="true"
app:lottie_autoPlay="true"
app:lottie_fileName="loading.json"
app:lottie_rawRes="@raw/loading2"
app:lottie_loop="true"
android:visibility="invisible" />
@ -34,7 +35,8 @@
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:text="Scan QR"/>
android:backgroundTint="#0F9D58"
android:text="Scan QR Code"/>
<Button
android:id="@+id/btnBack"
android:layout_width="35dp"

File diff suppressed because one or more lines are too long