-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHealthFragment.java
More file actions
64 lines (49 loc) · 2.02 KB
/
HealthFragment.java
File metadata and controls
64 lines (49 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com.example.readit;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class HealthFragment extends Fragment {
String apiKey = "14743ceffafd4a93a409776a41a9379f";
ArrayList<ModelClass> modelClassList;
Adapter adapter;
String country = "us";
private String category = "health";
private RecyclerView recyclerViewOfHealth;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState){
View view = inflater.inflate(R.layout.healthfragment, null);
recyclerViewOfHealth = view.findViewById(R.id.recyclerViewOfHealth);
modelClassList = new ArrayList<>();
recyclerViewOfHealth.setLayoutManager(new LinearLayoutManager(getContext()));
adapter = new Adapter(getContext(), modelClassList);
recyclerViewOfHealth.setAdapter(adapter);
findNews();
return view;
}
private void findNews() {
ApiUtilities.getApiInterface().getCategoryNews(country, category, 100, apiKey).enqueue(new Callback<NewsList>() {
@Override
public void onResponse(Call<NewsList> call, Response<NewsList> response) {
if(response.isSuccessful()) {
assert response.body() != null;
modelClassList.addAll(response.body().getNewsList());
adapter.notifyDataSetChanged();
}
}
@Override
public void onFailure(Call<NewsList> call, Throwable t) {
}
});
}
}