diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-08-02 09:34:44 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-08-02 09:34:44 +0000 |
commit | 722760254f0f0239b9aa23e65416cfede2204884 (patch) | |
tree | bb4e368ffa80ede2f9e50c65fe6fb0c251a82806 /app | |
parent | c84f8ed2a38ea4238c8ded4bebabdb5dc59157e5 (diff) | |
download | infinity-for-reddit-722760254f0f0239b9aa23e65416cfede2204884.tar infinity-for-reddit-722760254f0f0239b9aa23e65416cfede2204884.tar.gz infinity-for-reddit-722760254f0f0239b9aa23e65416cfede2204884.tar.bz2 infinity-for-reddit-722760254f0f0239b9aa23e65416cfede2204884.tar.lz infinity-for-reddit-722760254f0f0239b9aa23e65416cfede2204884.tar.xz infinity-for-reddit-722760254f0f0239b9aa23e65416cfede2204884.tar.zst infinity-for-reddit-722760254f0f0239b9aa23e65416cfede2204884.zip |
Show error message in WikiActivity.
Diffstat (limited to '')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java | 29 | ||||
-rw-r--r-- | app/src/main/res/layout/activity_wiki.xml | 27 | ||||
-rw-r--r-- | app/src/main/res/values/strings.xml | 3 |
3 files changed, 58 insertions, 1 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java index 492553dc..5da77551 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -15,6 +15,8 @@ import android.view.MenuItem; import android.view.View; import android.view.Window; import android.view.WindowManager; +import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; @@ -23,6 +25,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.bumptech.glide.Glide; import com.google.android.material.appbar.AppBarLayout; import com.r0adkll.slidr.Slidr; import com.r0adkll.slidr.model.SlidrInterface; @@ -77,6 +80,13 @@ public class WikiActivity extends BaseActivity { Toolbar toolbar; @BindView(R.id.content_markdown_view_comment_wiki_activity) RecyclerView markdownRecyclerView; + @BindView(R.id.fetch_wiki_linear_layout_wiki_activity) + LinearLayout mFetchWikiInfoLinearLayout; + @BindView(R.id.fetch_wiki_image_view_wiki_activity) + ImageView mFetchWikiInfoImageView; + @BindView(R.id.fetch_wiki_text_view_wiki_activity) + TextView mFetchWikiInfoTextView; + @Inject @Named("no_oauth") Retrofit retrofit; @@ -254,6 +264,9 @@ public class WikiActivity extends BaseActivity { } private void loadWiki() { + Glide.with(this).clear(mFetchWikiInfoImageView); + mFetchWikiInfoLinearLayout.setVisibility(View.GONE); + retrofit.create(RedditAPI.class).getWiki(getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME)).enqueue(new Callback<String>() { @Override public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { @@ -264,17 +277,30 @@ public class WikiActivity extends BaseActivity { markwonAdapter.notifyDataSetChanged(); } catch (JSONException e) { e.printStackTrace(); + showErrorView(R.string.error_loading_wiki); + } + } else { + if (response.code() == 404 || response.code() == 403) { + showErrorView(R.string.no_wiki); + } else { + showErrorView(R.string.error_loading_wiki); } } } @Override public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) { - + showErrorView(R.string.error_loading_wiki); } }); } + private void showErrorView(int stringResId) { + mFetchWikiInfoLinearLayout.setVisibility(View.VISIBLE); + mFetchWikiInfoTextView.setText(stringResId); + Glide.with(this).load(R.drawable.error_image).into(mFetchWikiInfoImageView); + } + @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { if (item.getItemId() == android.R.id.home) { @@ -311,6 +337,7 @@ public class WikiActivity extends BaseActivity { protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + mFetchWikiInfoTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); } @Subscribe diff --git a/app/src/main/res/layout/activity_wiki.xml b/app/src/main/res/layout/activity_wiki.xml index 0a09d748..778cc76b 100644 --- a/app/src/main/res/layout/activity_wiki.xml +++ b/app/src/main/res/layout/activity_wiki.xml @@ -40,4 +40,31 @@ android:paddingEnd="16dp" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> + <LinearLayout + android:id="@+id/fetch_wiki_linear_layout_wiki_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" + app:layout_behavior="@string/appbar_scrolling_view_behavior" > + + <ImageView + android:id="@+id/fetch_wiki_image_view_wiki_activity" + android:layout_width="150dp" + android:layout_height="wrap_content" /> + + <TextView + android:id="@+id/fetch_wiki_text_view_wiki_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>
\ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e5da66e3..7d528f8e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1158,4 +1158,7 @@ <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> + <string name="error_loading_wiki">Error loading wiki</string> + <string name="no_wiki">This subreddit has no wiki page</string> + </resources> |