Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.scoringtournament.apps;
- import android.os.Bundle;
- import android.support.v4.app.Fragment;
- import android.support.v7.widget.DefaultItemAnimator;
- import android.support.v7.widget.LinearLayoutManager;
- import android.support.v7.widget.RecyclerView;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import com.scoringtournament.apps.Adapter.TabsAdapter;
- import com.scoringtournament.apps.Api.RequestApi;
- import com.scoringtournament.apps.Model.Tab;
- import com.scoringtournament.apps.Model.Value;
- import java.util.ArrayList;
- import java.util.List;
- import okhttp3.OkHttpClient;
- import okhttp3.logging.HttpLoggingInterceptor;
- import retrofit2.Call;
- import retrofit2.Callback;
- import retrofit2.Response;
- import retrofit2.Retrofit;
- import retrofit2.converter.gson.GsonConverterFactory;
- /**
- * A simple {@link Fragment} subclass.
- */
- public class DoneFragment extends Fragment {
- public String id;
- public String jenis;
- public static final String URL = "";
- private List<Tab> result = new ArrayList<>();
- private TabsAdapter viewAdapter;
- public RecyclerView recyclerView;
- public DoneFragment(String id, String jenis) {
- this.id = id;
- this.jenis = jenis;
- }
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- // Inflate the layout for this fragment
- View rootView = inflater.inflate(R.layout.fragment_done, container, false);
- recyclerView = (RecyclerView) rootView.findViewById(R.id.rv_recycler_view);
- recyclerView.setHasFixedSize(true);
- viewAdapter = new TabsAdapter(getActivity(), result);
- recyclerView.setItemAnimator(new DefaultItemAnimator());
- recyclerView.setAdapter(viewAdapter);
- LinearLayoutManager llm = new LinearLayoutManager(getActivity());
- recyclerView.setLayoutManager(llm);
- loadDataHasil();
- return rootView;
- }
- private void loadDataHasil() {
- HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
- // set your desired log level
- logging.setLevel(HttpLoggingInterceptor.Level.BODY);
- OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
- // add your other interceptors …
- // add logging as last interceptor
- httpClient.addInterceptor(logging);
- Retrofit retrofit = new Retrofit.Builder()
- .baseUrl(URL)
- .addConverterFactory(GsonConverterFactory.create())
- .client(httpClient.build())
- .build();
- RequestApi api = retrofit.create(RequestApi.class);
- Call<Value> call = api.done(id, jenis);
- call.enqueue(new Callback<Value>() {
- @Override
- public void onResponse(Call<Value> call, Response<Value> response) {
- String value = response.body().getValue();
- Log.d("erorr", value);
- Log.d("value saya", value);
- if (value.equals("1")) {
- result = response.body().getTabs();
- viewAdapter = new TabsAdapter(getActivity(), result);
- recyclerView.setAdapter(viewAdapter);
- }
- }
- @Override
- public void onFailure(Call<Value> call, Throwable t) {
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment