Skip to content

Commit

Permalink
Add progress layout and img error check
Browse files Browse the repository at this point in the history
  • Loading branch information
FongMi committed Jun 27, 2022
1 parent 5392e20 commit cf93f74
Show file tree
Hide file tree
Showing 15 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.room:room-runtime:2.4.2'
implementation 'com.github.androidprogresslayout:library:2.0.2@aar'
implementation 'com.github.bumptech.glide:glide:4.13.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'com.google.android.exoplayer:exoplayer:2.18.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,14 @@ private void setRecyclerView() {

private void setViewModel() {
mSiteViewModel = new ViewModelProvider(this).get(SiteViewModel.class);
mSiteViewModel.mResult.observe(this, result -> mVodAdapter.addAll(result.getList()));
mSiteViewModel.mResult.observe(this, result -> {
mVodAdapter.addAll(result.getList());
mBinding.updateLayout.showContent();
});
}

private void homeContent() {
mBinding.updateLayout.showProgress();
mSiteViewModel.homeContent(ApiConfig.get().getHome().getKey());
}

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/fongmi/bear/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.fongmi.bear.App;
import com.fongmi.bear.R;
import com.google.android.exoplayer2.util.Util;

public class Utils {
Expand Down Expand Up @@ -62,7 +63,7 @@ static boolean isRightKey(KeyEvent event) {
}

public static void loadImage(String url, ImageView view) {
Glide.with(App.get()).load(url).transform(new CenterCrop(), new RoundedCorners(ResUtil.dp2px(8))).into(view);
Glide.with(App.get()).load(url).placeholder(R.drawable.ic_img_loading).error(R.drawable.ic_img_error).transform(new CenterCrop(), new RoundedCorners(ResUtil.dp2px(8))).into(view);
}

public static boolean hasPIP() {
Expand Down
Binary file added app/src/main/res/drawable-hdpi/ic_img_error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/ic_img_loading.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_img_error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_img_loading.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_img_error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/ic_img_error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 12 additions & 5 deletions app/src/main/res/layout/activity_home.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:fillViewport="true">

<LinearLayout
android:layout_width="match_parent"
Expand Down Expand Up @@ -44,11 +45,17 @@
android:textColor="@color/white"
android:textSize="24sp" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/update"
<com.github.androidprogresslayout.ProgressLayout
android:id="@+id/updateLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp" />
android:layout_height="match_parent"
android:layout_marginTop="16dp">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/update"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</com.github.androidprogresslayout.ProgressLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
jcenter()
google()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
jcenter()
google()
}
}
Expand Down

0 comments on commit cf93f74

Please sign in to comment.