mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 12:47:26 +01:00
Show error view in TrendingActivity.
This commit is contained in:
parent
1208a2d4f8
commit
03d8cf497d
@ -9,6 +9,9 @@ import android.util.DisplayMetrics;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
@ -17,6 +20,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
|||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
|
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
import com.google.android.material.appbar.AppBarLayout;
|
import com.google.android.material.appbar.AppBarLayout;
|
||||||
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
||||||
import com.r0adkll.slidr.Slidr;
|
import com.r0adkll.slidr.Slidr;
|
||||||
@ -67,6 +71,12 @@ public class TrendingActivity extends BaseActivity {
|
|||||||
SwipeRefreshLayout swipeRefreshLayout;
|
SwipeRefreshLayout swipeRefreshLayout;
|
||||||
@BindView(R.id.recycler_view_trending_activity)
|
@BindView(R.id.recycler_view_trending_activity)
|
||||||
RecyclerView recyclerView;
|
RecyclerView recyclerView;
|
||||||
|
@BindView(R.id.fetch_trending_search_linear_layout_trending_activity)
|
||||||
|
LinearLayout errorLinearLayout;
|
||||||
|
@BindView(R.id.fetch_trending_search_image_view_trending_activity)
|
||||||
|
ImageView errorImageView;
|
||||||
|
@BindView(R.id.fetch_trending_search_text_view_trending_activity)
|
||||||
|
TextView errorTextView;
|
||||||
@Inject
|
@Inject
|
||||||
@Named("oauth")
|
@Named("oauth")
|
||||||
Retrofit mOauthRetrofit;
|
Retrofit mOauthRetrofit;
|
||||||
@ -164,6 +174,8 @@ public class TrendingActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadTrendingSearches() {
|
private void loadTrendingSearches() {
|
||||||
|
errorLinearLayout.setVisibility(View.GONE);
|
||||||
|
Glide.with(this).clear(errorImageView);
|
||||||
swipeRefreshLayout.setRefreshing(true);
|
swipeRefreshLayout.setRefreshing(true);
|
||||||
trendingSearches = null;
|
trendingSearches = null;
|
||||||
adapter.setTrendingSearches(null);
|
adapter.setTrendingSearches(null);
|
||||||
@ -206,12 +218,14 @@ public class TrendingActivity extends BaseActivity {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
handler.post(() -> {
|
handler.post(() -> {
|
||||||
swipeRefreshLayout.setRefreshing(false);
|
swipeRefreshLayout.setRefreshing(false);
|
||||||
|
showErrorView(R.string.error_parse_trending_search);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
handler.post(() -> {
|
handler.post(() -> {
|
||||||
swipeRefreshLayout.setRefreshing(false);
|
swipeRefreshLayout.setRefreshing(false);
|
||||||
|
showErrorView(R.string.error_fetch_trending_search);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -220,11 +234,18 @@ public class TrendingActivity extends BaseActivity {
|
|||||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||||
handler.post(() -> {
|
handler.post(() -> {
|
||||||
swipeRefreshLayout.setRefreshing(false);
|
swipeRefreshLayout.setRefreshing(false);
|
||||||
|
showErrorView(R.string.error_fetch_trending_search);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showErrorView(int stringId) {
|
||||||
|
errorLinearLayout.setVisibility(View.VISIBLE);
|
||||||
|
Glide.with(this).load(R.drawable.error_image).into(errorImageView);
|
||||||
|
errorTextView.setText(stringId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SharedPreferences getDefaultSharedPreferences() {
|
protected SharedPreferences getDefaultSharedPreferences() {
|
||||||
return mSharedPreferences;
|
return mSharedPreferences;
|
||||||
@ -241,6 +262,7 @@ public class TrendingActivity extends BaseActivity {
|
|||||||
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
|
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
|
||||||
swipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground());
|
swipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground());
|
||||||
swipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent());
|
swipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent());
|
||||||
|
errorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
|
@ -46,4 +46,30 @@
|
|||||||
|
|
||||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/fetch_trending_search_linear_layout_trending_activity"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginTop="48dp"
|
||||||
|
android:layout_marginBottom="48dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/fetch_trending_search_image_view_trending_activity"
|
||||||
|
android:layout_width="150dp"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/fetch_trending_search_text_view_trending_activity"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textSize="?attr/font_default"
|
||||||
|
android:fontFamily="?attr/font_family" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
@ -1146,4 +1146,8 @@
|
|||||||
|
|
||||||
<string name="please_wait_image_is_uploading">An image is still being uploaded. Please wait.</string>
|
<string name="please_wait_image_is_uploading">An image is still being uploaded. Please wait.</string>
|
||||||
|
|
||||||
|
<string name="error_fetch_trending_search">Fetch trending searches failed.\nTap to retry.</string>
|
||||||
|
<string name="error_parse_trending_search">Parse trending searches failed.\nTap to retry.</string>
|
||||||
|
<string name="no_trending_search">No trending searches found.\nTap to retry.</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user