| | package org.ntlab.acanthus_client.views.Main_menu_ui.home; |
---|
| | |
---|
| | import android.os.Bundle; |
---|
| | import android.widget.EditText; |
---|
| | |
---|
| | import org.ntlab.acanthus_client.R; |
---|
| | import org.ntlab.acanthus_client.entities.AccountTokenJson; |
---|
| | import org.ntlab.acanthus_client.resources.accounts.HelloWorldRest; |
---|
| | import org.ntlab.acanthus_client.resources.accounts.LoginRest; |
---|
| | |
---|
| | import androidx.lifecycle.LiveData; |
---|
| | import androidx.lifecycle.MutableLiveData; |
---|
| | import androidx.lifecycle.ViewModel; |
---|
| | import okhttp3.ResponseBody; |
---|
| | import retrofit2.Call; |
---|
| | import retrofit2.Callback; |
---|
| | import retrofit2.Response; |
---|
| | import retrofit2.Retrofit; |
---|
| | import retrofit2.converter.jackson.JacksonConverterFactory; |
---|
| | import retrofit2.converter.scalars.ScalarsConverterFactory; |
---|
| | |
---|
| | public class HomeViewModel extends ViewModel { |
---|
| | private EditText editEmailTextView; |
---|
| | private MutableLiveData<String> mText; |
---|
| | |
---|
| | private MutableLiveData<String> mText; |
---|
| | |
---|
| | public HomeViewModel() { |
---|
| | mText = new MutableLiveData<>(); |
---|
| | mText.setValue("This is home fragment"); |
---|
| | Retrofit retrofit = new Retrofit.Builder() |
---|
| | .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/acanthus/") |
---|
| | .addConverterFactory(ScalarsConverterFactory.create()) |
---|
| | .addConverterFactory(JacksonConverterFactory.create()) |
---|
| | .build(); |
---|
| | final HelloWorldRest helloworld = retrofit.create(HelloWorldRest.class); |
---|
| | Call<String> call = helloworld.getHelloWorld(); |
---|
| | call.enqueue(new Callback<String>() { |
---|
| | @Override |
---|
| | public void onResponse(Call<String> call, Response<String> response) { |
---|
| | if(response.isSuccessful()) { |
---|
| | String res = response.body(); |
---|
| | mText.setValue(res.toString()); |
---|
| | }else{ |
---|
| | mText.setValue("False helloworld"); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | @Override |
---|
| | public void onFailure(Call<String> call, Throwable t) { |
---|
| | mText.setValue("みす helloworld"); |
---|
| | } |
---|
| | }); |
---|
| | |
---|
| | |
---|
| | } |
---|
| | |
---|
| | public LiveData<String> getText() { |
---|
| | return mText; |
---|
| | |