mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-16 05:03:07 +01:00
Swipe to refresh in WikiActivity.
This commit is contained in:
parent
722760254f
commit
5b29d2c841
@ -24,6 +24,7 @@ import androidx.appcompat.widget.Toolbar;
|
|||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.google.android.material.appbar.AppBarLayout;
|
import com.google.android.material.appbar.AppBarLayout;
|
||||||
@ -78,6 +79,8 @@ public class WikiActivity extends BaseActivity {
|
|||||||
AppBarLayout appBarLayout;
|
AppBarLayout appBarLayout;
|
||||||
@BindView(R.id.toolbar_comment_wiki_activity)
|
@BindView(R.id.toolbar_comment_wiki_activity)
|
||||||
Toolbar toolbar;
|
Toolbar toolbar;
|
||||||
|
@BindView(R.id.swipe_refresh_layout_wiki_activity)
|
||||||
|
SwipeRefreshLayout swipeRefreshLayout;
|
||||||
@BindView(R.id.content_markdown_view_comment_wiki_activity)
|
@BindView(R.id.content_markdown_view_comment_wiki_activity)
|
||||||
RecyclerView markdownRecyclerView;
|
RecyclerView markdownRecyclerView;
|
||||||
@BindView(R.id.fetch_wiki_linear_layout_wiki_activity)
|
@BindView(R.id.fetch_wiki_linear_layout_wiki_activity)
|
||||||
@ -99,6 +102,7 @@ public class WikiActivity extends BaseActivity {
|
|||||||
private String wikiMarkdown;
|
private String wikiMarkdown;
|
||||||
private Markwon markwon;
|
private Markwon markwon;
|
||||||
private MarkwonAdapter markwonAdapter;
|
private MarkwonAdapter markwonAdapter;
|
||||||
|
private boolean isRefreshing = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -140,6 +144,9 @@ public class WikiActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
swipeRefreshLayout.setEnabled(mSharedPreferences.getBoolean(SharedPreferencesUtils.PULL_TO_REFRESH, true));
|
||||||
|
swipeRefreshLayout.setOnRefreshListener(this::loadWiki);
|
||||||
|
|
||||||
int markdownColor = mCustomThemeWrapper.getPrimaryTextColor();
|
int markdownColor = mCustomThemeWrapper.getPrimaryTextColor();
|
||||||
int spoilerBackgroundColor = markdownColor | 0xFF000000;
|
int spoilerBackgroundColor = markdownColor | 0xFF000000;
|
||||||
int linkColor = mCustomThemeWrapper.getLinkColor();
|
int linkColor = mCustomThemeWrapper.getLinkColor();
|
||||||
@ -264,6 +271,13 @@ public class WikiActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadWiki() {
|
private void loadWiki() {
|
||||||
|
if (isRefreshing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
isRefreshing = true;
|
||||||
|
|
||||||
|
swipeRefreshLayout.setRefreshing(true);
|
||||||
|
|
||||||
Glide.with(this).clear(mFetchWikiInfoImageView);
|
Glide.with(this).clear(mFetchWikiInfoImageView);
|
||||||
mFetchWikiInfoLinearLayout.setVisibility(View.GONE);
|
mFetchWikiInfoLinearLayout.setVisibility(View.GONE);
|
||||||
|
|
||||||
@ -286,16 +300,21 @@ public class WikiActivity extends BaseActivity {
|
|||||||
showErrorView(R.string.error_loading_wiki);
|
showErrorView(R.string.error_loading_wiki);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
isRefreshing = false;
|
||||||
|
swipeRefreshLayout.setRefreshing(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||||
showErrorView(R.string.error_loading_wiki);
|
showErrorView(R.string.error_loading_wiki);
|
||||||
|
isRefreshing = false;
|
||||||
|
swipeRefreshLayout.setRefreshing(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showErrorView(int stringResId) {
|
private void showErrorView(int stringResId) {
|
||||||
|
swipeRefreshLayout.setRefreshing(false);
|
||||||
mFetchWikiInfoLinearLayout.setVisibility(View.VISIBLE);
|
mFetchWikiInfoLinearLayout.setVisibility(View.VISIBLE);
|
||||||
mFetchWikiInfoTextView.setText(stringResId);
|
mFetchWikiInfoTextView.setText(stringResId);
|
||||||
Glide.with(this).load(R.drawable.error_image).into(mFetchWikiInfoImageView);
|
Glide.with(this).load(R.drawable.error_image).into(mFetchWikiInfoImageView);
|
||||||
@ -337,6 +356,8 @@ public class WikiActivity extends BaseActivity {
|
|||||||
protected void applyCustomTheme() {
|
protected void applyCustomTheme() {
|
||||||
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
|
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
|
||||||
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
|
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
|
||||||
|
swipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground());
|
||||||
|
swipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent());
|
||||||
mFetchWikiInfoTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor());
|
mFetchWikiInfoTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,13 +32,20 @@
|
|||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
|
android:id="@+id/swipe_refresh_layout_wiki_activity"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/content_markdown_view_comment_wiki_activity"
|
android:id="@+id/content_markdown_view_comment_wiki_activity"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:paddingStart="16dp"
|
android:paddingStart="16dp"
|
||||||
android:paddingEnd="16dp"
|
android:paddingEnd="16dp" />
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
|
||||||
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/fetch_wiki_linear_layout_wiki_activity"
|
android:id="@+id/fetch_wiki_linear_layout_wiki_activity"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user