aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-07-18 14:59:08 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-07-18 14:59:08 +0000
commit1208a2d4f89c5f9d885092a6976fbae33feddb15 (patch)
treea1ec9484a6a30bcd524333f5dc4fe47629d5e973 /app/src/main/java
parent3ecb39bc3edbccfb1fccf2a097a77bf3361d3ac8 (diff)
downloadinfinity-for-reddit-1208a2d4f89c5f9d885092a6976fbae33feddb15.tar
infinity-for-reddit-1208a2d4f89c5f9d885092a6976fbae33feddb15.tar.gz
infinity-for-reddit-1208a2d4f89c5f9d885092a6976fbae33feddb15.tar.bz2
infinity-for-reddit-1208a2d4f89c5f9d885092a6976fbae33feddb15.tar.lz
infinity-for-reddit-1208a2d4f89c5f9d885092a6976fbae33feddb15.tar.xz
infinity-for-reddit-1208a2d4f89c5f9d885092a6976fbae33feddb15.tar.zst
infinity-for-reddit-1208a2d4f89c5f9d885092a6976fbae33feddb15.zip
Refreshing trending searches is now available.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java23
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TrendingSearchRecyclerViewAdapter.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java1
3 files changed, 29 insertions, 5 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java
index 0bfe7efe..a75f28c6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java
@@ -15,6 +15,7 @@ import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
+import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
@@ -62,6 +63,8 @@ public class TrendingActivity extends BaseActivity {
AppBarLayout appBarLayout;
@BindView(R.id.toolbar_trending_activity)
Toolbar toolbar;
+ @BindView(R.id.swipe_refresh_layout_trending_activity)
+ SwipeRefreshLayout swipeRefreshLayout;
@BindView(R.id.recycler_view_trending_activity)
RecyclerView recyclerView;
@Inject
@@ -154,10 +157,16 @@ public class TrendingActivity extends BaseActivity {
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
+ swipeRefreshLayout.setEnabled(mSharedPreferences.getBoolean(SharedPreferencesUtils.PULL_TO_REFRESH, true));
+ swipeRefreshLayout.setOnRefreshListener(this::loadTrendingSearches);
+
loadTrendingSearches();
}
private void loadTrendingSearches() {
+ swipeRefreshLayout.setRefreshing(true);
+ trendingSearches = null;
+ adapter.setTrendingSearches(null);
Handler handler = new Handler();
mOauthRetrofit.create(RedditAPI.class).getTrendingSearches(APIUtils.getOAuthHeader(mAccessToken)).enqueue(new Callback<String>() {
@Override
@@ -190,20 +199,28 @@ public class TrendingActivity extends BaseActivity {
handler.post(() -> {
trendingSearches = trendingSearchList;
+ swipeRefreshLayout.setRefreshing(false);
adapter.setTrendingSearches(trendingSearches);
});
} catch (JSONException e) {
e.printStackTrace();
+ handler.post(() -> {
+ swipeRefreshLayout.setRefreshing(false);
+ });
}
});
} else {
-
+ handler.post(() -> {
+ swipeRefreshLayout.setRefreshing(false);
+ });
}
}
@Override
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
-
+ handler.post(() -> {
+ swipeRefreshLayout.setRefreshing(false);
+ });
}
});
}
@@ -222,6 +239,8 @@ public class TrendingActivity extends BaseActivity {
protected void applyCustomTheme() {
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
+ swipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground());
+ swipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent());
}
@Subscribe
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TrendingSearchRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TrendingSearchRecyclerViewAdapter.java
index b550b91e..8ab40aff 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TrendingSearchRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TrendingSearchRecyclerViewAdapter.java
@@ -180,8 +180,14 @@ public class TrendingSearchRecyclerViewAdapter extends RecyclerView.Adapter<Recy
}
public void setTrendingSearches(ArrayList<TrendingSearch> trendingSearches) {
- this.trendingSearches = trendingSearches;
- notifyDataSetChanged();
+ if (trendingSearches != null) {
+ this.trendingSearches = trendingSearches;
+ notifyItemRangeInserted(0, trendingSearches.size());
+ } else {
+ int size = this.trendingSearches == null ? 0 : this.trendingSearches.size();
+ this.trendingSearches = null;
+ notifyItemRangeRemoved(0, size);
+ }
}
class TrendingSearchViewHolder extends RecyclerView.ViewHolder {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java
index 5c8260cb..420b90a2 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java
@@ -363,7 +363,6 @@ public interface RedditAPI {
@POST("/api/submit_gallery_post.json?resubmit=true&raw_json=1")
Call<String> submitGalleryPost(@HeaderMap Map<String, String> headers, @Body String body);
- //https://www.reddit.com/search.json?q=Olympics&source=trending
@GET("/api/trending_searches_v1.json?withAds=0&raw_json=1&gilding_detail=1")
Call<String> getTrendingSearches(@HeaderMap Map<String, String> headers);
}