Newer
Older
NemophilaClient / app / src / main / java / com / example / nemophila / viewmodels / FriendViewModel.java
k-suzuki on 4 Jul 2023 1 KB MyPageActivityを作った
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 java.util.Collection;

import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;

public class FriendViewModel extends ViewModel {
    // フィールド
    private final Retrofit retrofit;
    private final FriendsRest friendsRest;
    // ライブデータ
    private final MutableLiveData<String> friendsLiveData;
    private final MutableLiveData<String> requestedLiveData;
    private final MutableLiveData<Collection<Post>> 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<String> getFriendsLiveData() {
        return friendsLiveData;
    }
    public MutableLiveData<String> getRequestedLiveData() {
        return requestedLiveData;
    }
    public MutableLiveData<Collection<Post>> getRequestingLiveData() { return requestingLiveData; }
    public void searchFriend(String uid,String fid, String token) {
        Call<Void> call = accountsRest.deleteAccount(uid, token);
}