Skip to content

Commit 8af08c5

Browse files
update version 1.2
1 parent 2d57471 commit 8af08c5

File tree

4 files changed

+70
-6
lines changed

4 files changed

+70
-6
lines changed

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ android {
1616
applicationId = "com.ahmadrezagh671.pixabay"
1717
minSdk = 28
1818
targetSdk = 35
19-
versionCode = 2
20-
versionName = "1.1"
19+
versionCode = 3
20+
versionName = "1.2"
2121

2222
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2323

app/src/main/java/com/ahmadrezagh671/pixabay/FragmentExplore.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.ahmadrezagh671.pixabay;
22

3+
import static android.view.View.GONE;
4+
import static android.view.View.VISIBLE;
5+
36
import android.content.Intent;
47
import android.os.Bundle;
58

@@ -20,6 +23,7 @@
2023
import android.widget.ImageButton;
2124
import android.widget.LinearLayout;
2225
import android.widget.SearchView;
26+
import android.widget.TextView;
2327
import android.widget.Toast;
2428

2529
import com.ahmadrezagh671.pixabay.Adapters.AdapterPosts;
@@ -57,6 +61,9 @@ public class FragmentExplore extends Fragment implements SwipeRefreshLayout.OnRe
5761
ConstraintLayout topDiscoverLayout;
5862
LinearLayout topFilterLayout;
5963

64+
Button tryAgainButton;
65+
TextView errorTV;
66+
6067
boolean latestEnable = false;
6168

6269
public FragmentExplore() {
@@ -109,6 +116,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
109116
latestBTN = view.findViewById(R.id.latestBTN);
110117
latestBTN.setOnClickListener(this::onClickLatestBTN);
111118

119+
tryAgainButton = view.findViewById(R.id.tryAgainButton);
120+
tryAgainButton.setOnClickListener(v -> reload());
121+
122+
errorTV = view.findViewById(R.id.errorTV);
123+
112124
final int[] state = new int[1];
113125

114126
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@@ -179,6 +191,11 @@ public void onResponse(JSONObject response) {
179191
posts.add(item);
180192
}
181193

194+
if (posts.isEmpty()) {
195+
errorTV.setText("Nothing Found");
196+
errorTV.setVisibility(VISIBLE);
197+
}
198+
182199
if(adapterPosts == null) {
183200
adapterPosts = new AdapterPosts(posts, getContext(), getActivity());
184201
recyclerView.setAdapter(adapterPosts);
@@ -188,15 +205,20 @@ public void onResponse(JSONObject response) {
188205
}
189206

190207
} catch (JSONException e) {
191-
throw new RuntimeException(e);
208+
//throw new RuntimeException(e);
209+
if (posts.isEmpty()) {
210+
errorTV.setText("Something is wrong");
211+
errorTV.setVisibility(VISIBLE);
212+
}
192213
}
193214
refreshing(false);
194215
}
195216
}, new Response.ErrorListener() {
196217
@Override
197218
public void onErrorResponse(VolleyError error) {
198219
refreshing(false);
199-
Toast.makeText(getActivity(), error.getMessage(), Toast.LENGTH_SHORT).show();
220+
//Toast.makeText(getActivity(), error.getMessage(), Toast.LENGTH_SHORT).show();
221+
tryAgainButton.setVisibility(VISIBLE);
200222
}
201223
});
202224

@@ -291,6 +313,8 @@ private void topItemsVisible(boolean b) {
291313

292314
private void reload(){
293315
requestPostsFromApi(getSearchViewQuery());
316+
tryAgainButton.setVisibility(GONE);
317+
errorTV.setVisibility(GONE);
294318
}
295319

296320
public void setCategory(String string){

app/src/main/res/layout/fragment_explore.xml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,46 @@
160160

161161
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
162162

163+
164+
<LinearLayout
165+
android:layout_width="wrap_content"
166+
android:layout_height="wrap_content"
167+
android:layout_marginTop="14dp"
168+
app:layout_constraintBottom_toBottomOf="parent"
169+
app:layout_constraintEnd_toEndOf="parent"
170+
app:layout_constraintStart_toStartOf="parent"
171+
app:layout_constraintTop_toBottomOf="@+id/topSearchAndFilterLayout"
172+
android:orientation="vertical"
173+
android:gravity="center"
174+
>
175+
176+
<TextView
177+
tools:visibility="visible"
178+
android:visibility="gone"
179+
android:id="@+id/errorTV"
180+
android:layout_width="wrap_content"
181+
android:layout_height="wrap_content"
182+
android:text="Network Error"
183+
android:layout_marginBottom="16dp"
184+
android:textColor="@color/text_color_white"
185+
/>
186+
187+
<androidx.appcompat.widget.AppCompatButton
188+
tools:visibility="visible"
189+
android:visibility="gone"
190+
android:id="@+id/tryAgainButton"
191+
android:layout_width="wrap_content"
192+
android:layout_height="wrap_content"
193+
android:text="Try Again"
194+
android:textAllCaps="false"
195+
android:background="@drawable/shape_rounded_gradient"
196+
android:textColor="@color/text_color_white"
197+
android:paddingHorizontal="24dp"
198+
android:stateListAnimator="@null"
199+
android:singleLine="true"
200+
/>
201+
</LinearLayout>
202+
163203
</androidx.constraintlayout.widget.ConstraintLayout>
164204

165205

app/src/main/res/values-notnight/colors.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
<color name="black">#FF000000</color>
44
<color name="white">#FFFFFFFF</color>
55

6-
<color name="primaryColor">#5492f7</color>
6+
<color name="primaryColor">#74A4F6</color>
77
<color name="notPrimaryColor">#9ca3af</color>
8-
<color name="secondaryColor">#403dce</color>
8+
<color name="secondaryColor">#6A67C7</color>
99
<color name="BackgroundColor">#eff5ff</color>
1010
<color name="DarkBackgroundColor">#ffffff</color>
1111
<color name="LightBackgroundColor">#ffffff</color>

0 commit comments

Comments
 (0)