diff --git a/app/src/main/java/com/example/nemophila/viewmodels/FriendViewModel.java b/app/src/main/java/com/example/nemophila/viewmodels/FriendViewModel.java index 5322b9e..58e6151 100644 --- a/app/src/main/java/com/example/nemophila/viewmodels/FriendViewModel.java +++ b/app/src/main/java/com/example/nemophila/viewmodels/FriendViewModel.java @@ -1,65 +1,65 @@ -//package com.example.nemophila.viewmodels; -// -//import androidx.lifecycle.MutableLiveData; -//import androidx.lifecycle.ViewModel; -// -//import com.example.nemophila.entities.Post; -//import com.example.nemophila.resources.AccountsRest; -//import com.example.nemophila.resources.FriendsRest; -// -//import java.util.Collection; -// -//import retrofit2.Call; -//import retrofit2.Callback; -//import retrofit2.Response; -//import retrofit2.Retrofit; -//import retrofit2.converter.jackson.JacksonConverterFactory; -// -//public class FriendViewModel extends ViewModel { -// // フィールド -// private final Retrofit retrofit; -// private final FriendsRest friendsRest; -// // ライブデータ -// private final MutableLiveData friendsLiveData; -// private final MutableLiveData requestedLiveData; -// private final MutableLiveData> requestingLiveData; -// -// // コンストラクタ -// public FriendViewModel() { -// this.retrofit = new Retrofit.Builder() -// .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/nemophila/") -// .addConverterFactory(JacksonConverterFactory.create()) -// .build(); -// this.friendsRest = retrofit.create(FriendsRest.class); -// this.friendsLiveData = new MutableLiveData<>(); -// this.requestedLiveData = new MutableLiveData<>(); -// this.requestingLiveData = new MutableLiveData<>(); -// } -// -// // ライブデータの取得(ゲッター) -// public MutableLiveData getFriendsLiveData() { -// return friendsLiveData; -// } -// public MutableLiveData getRequestedLiveData() { -// return requestedLiveData; -// } -// public MutableLiveData> getRequestingLiveData() { return requestingLiveData; } -// -// public void searchFriend(String uid,String fid, String token) { -// Call call = friendsRest.putFriend (); -// call.enqueue(new Callback() { -// @Override -// public void onResponse(Call call, Response response) { -// if (response.isSuccessful()) { -// System.out.println("Successful"); -// } else { -// System.out.println("ResponseError"); -// } -// } -// @Override -// public void onFailure(Call call, Throwable t) { -// System.out.println(" NetworkError" + t); -// } -// }); -// } -//} +package com.example.nemophila.viewmodels; + +import androidx.lifecycle.MutableLiveData; +import androidx.lifecycle.ViewModel; + +import com.example.nemophila.entities.Post; +import com.example.nemophila.resources.AccountsRest; +import com.example.nemophila.resources.FriendsRest; + +import java.util.Collection; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; +import retrofit2.converter.jackson.JacksonConverterFactory; + +public class FriendViewModel extends ViewModel { + // フィールド + private final Retrofit retrofit; + private final FriendsRest friendsRest; + // ライブデータ + private final MutableLiveData friendsLiveData; + private final MutableLiveData requestedLiveData; + private final MutableLiveData> requestingLiveData; + + // コンストラクタ + public FriendViewModel() { + this.retrofit = new Retrofit.Builder() + .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/nemophila/") + .addConverterFactory(JacksonConverterFactory.create()) + .build(); + this.friendsRest = retrofit.create(FriendsRest.class); + this.friendsLiveData = new MutableLiveData<>(); + this.requestedLiveData = new MutableLiveData<>(); + this.requestingLiveData = new MutableLiveData<>(); + } + + // ライブデータの取得(ゲッター) + public MutableLiveData getFriendsLiveData() { + return friendsLiveData; + } + public MutableLiveData getRequestedLiveData() { + return requestedLiveData; + } + public MutableLiveData> getRequestingLiveData() { return requestingLiveData; } + + public void searchFriend(String uid,String fid, String token) { + Call call = friendsRest.putFriend (); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + System.out.println("Successful"); + } else { + System.out.println("ResponseError"); + } + } + @Override + public void onFailure(Call call, Throwable t) { + System.out.println(" NetworkError" + t); + } + }); + } +}