private void getData() {
    // final Gson gson = new GsonBuilder()

    // .create();
    Retrofit retrofit =
        new Retrofit.Builder()
            .baseUrl("http://api.androidhive.info/")
            .addConverterFactory(GsonConverterFactory.create())
            .build();
    MovieService service = retrofit.create(MovieService.class);
    Call<List<MovieModel>> modelCall = service.getDealModel();
    modelCall.enqueue(
        new Callback<List<MovieModel>>() {
          @Override
          public void onResponse(Response<List<MovieModel>> response) {
            if (response.isSuccess()) {

              list = response.body();
              MovieModelAdapter adapter = new MovieModelAdapter(Main2Activity.this, list);
              recyclerView.setAdapter(adapter);
            }
          }

          @Override
          public void onFailure(Throwable t) {}
        });
  }
    public static RemoteService makeRemoteService() {

      HttpLoggingInterceptor logging =
          new HttpLoggingInterceptor(
              new HttpLoggingInterceptor.Logger() {
                @Override
                public void log(String message) {
                  LogUtils.d(TAG, message);
                }
              });
      logging.setLevel(
          BuildConfig.DEBUG
              ? HttpLoggingInterceptor.Level.BODY
              : HttpLoggingInterceptor.Level.NONE);

      OkHttpClient okHttpClient =
          new OkHttpClient.Builder()
              .addInterceptor(new SpecialInterceptor())
              .addInterceptor(logging)
              .build();

      Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").create();
      Retrofit retrofit =
          new Retrofit.Builder()
              .baseUrl(RemoteService.ENDPOINT)
              .client(okHttpClient)
              .addConverterFactory(GsonConverterFactory.create(gson))
              .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
              .build();
      return retrofit.create(RemoteService.class);
    }
 private static Retrofit getRetrofit() {
   Retrofit retrofit =
       new Retrofit.Builder()
           .baseUrl(Config.URL_END_POINT)
           .addConverterFactory(GsonConverterFactory.create())
           .build();
   return retrofit;
 }
 @Override
 protected void processLogic(Bundle savedInstanceState) {
   mRemoteServerEngine =
       new Retrofit.Builder()
           .baseUrl("http://7xk9dj.com1.z0.glb.clouddn.com/")
           .addConverterFactory(GsonConverterFactory.create())
           .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
           .build()
           .create(RemoteServerEngine.class);
 }
Exemple #5
0
  public static Service getService() {
    if (service == null) {
      Retrofit retrofit =
          new Retrofit.Builder()
              .baseUrl("http://maps.googleapis.com/maps/api/geocode/")
              .addConverterFactory(GsonConverterFactory.create())
              .build();

      service = retrofit.create(Service.class);
    }

    return service;
  }
 @Override
 public void onCreate() {
   super.onCreate();
   mInstantce = this;
   mEngine =
       new Retrofit.Builder()
           .baseUrl("http://7xk9dj.com1.z0.glb.clouddn.com/")
           .addConverterFactory(GsonConverterFactory.create())
           .build()
           .create(Engine.class);
   initThridLogin();
   initImageLoader(this);
 }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_review_index, container, false);
    swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_layout);
    recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    recyclerView.setHasFixedSize(true);
    layoutManager = new LinearLayoutManager(getContext());
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.addItemDecoration(new ItemDivider(getContext(), R.drawable.light_divider));
    adapter = new ReviewIndexAdapter(getActivity(), Collections.EMPTY_LIST);
    recyclerView.setAdapter(adapter);
    Retrofit retrofit =
        new Retrofit.Builder()
            .baseUrl(SaojuService.BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build();
    service = retrofit.create(SaojuService.class);
    swipeRefreshLayout.setOnRefreshListener(
        new SwipeRefreshLayout.OnRefreshListener() {
          @Override
          public void onRefresh() {
            refresh();
          }
        });
    recyclerView.setOnScrollListener(
        new RecyclerView.OnScrollListener() {
          @Override
          public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            if (newState == RecyclerView.SCROLL_STATE_IDLE
                && adapter != null
                && adapter.getItemCount() == layoutManager.findLastVisibleItemPosition() + 1) {
              loadMore();
            }
          }

          @Override
          public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
          }
        });
    isPrepared = true;
    return view;
  }
Exemple #8
0
 public static Converter.Factory factoryWithExpose() {
   return GsonConverterFactory.create(withExpose());
 }