diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintModel.java b/app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintModel.java new file mode 100644 index 0000000..d03cf13 --- /dev/null +++ b/app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintModel.java @@ -0,0 +1,127 @@ +package org.ntlab.acanthus_client.views.paint; + +import androidx.navigation.ActivityNavigator; + +import org.ntlab.acanthus_client.Acanthus; +import org.ntlab.acanthus_client.entities.Animation; +import org.ntlab.acanthus_client.resources.gallery.GalleryRest; +import org.ntlab.acanthus_client.resources.gallery.StrokesRest; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; +import retrofit2.converter.jackson.JacksonConverterFactory; +import retrofit2.converter.scalars.ScalarsConverterFactory; + +//----------------------------------------------------------------- +// +public class PaintModel { + private Animation editedAnimation; + private Acanthus acanthus; + private Integer currentStrokeNo; + + private Retrofit retrofit; + + //----------------------------------------------------------------- + //----------------------------------------------------------------- + // + public PaintModel() { + Retrofit retrofit = new Retrofit.Builder() + .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/acanthus/") + .addConverterFactory(ScalarsConverterFactory.create()) + .addConverterFactory(JacksonConverterFactory.create()) + .build(); + } + + + //----------------------------------------------------------------- + // setter + public void setEditedAnimation(Animation editedAnimation) { + this.editedAnimation = editedAnimation; + } + + private void setCurrentStrokeNo(int strokeNo) { + this.currentStrokeNo = strokeNo; + } + + //----------------------------------------------------------------- + //----------------------------------------------------------------- + // init + public void init(Acanthus acanthus){ + this.acanthus = acanthus; + + final GalleryRest galleryRest = retrofit.create(GalleryRest.class); +// //----------------------------------------------------------------- +// // ストローク追加API +// Call call = strokesRest.addStroke( +// acanthus.getAid(), acanthus.getPreferenceUid(), acanthus.getPreferenceToken(), +// 0, 0, 10); +// +// // strokeNoを更新 +// call.enqueue(new Callback() { +// @Override +// public void onResponse(Call call, Response response) { +// if (response.isSuccessful()) setCurrentStrokeNo(response.body()); +// } +// +// @Override +// public void onFailure(Call call, Throwable t) { +// +// } +// }); + } + + //----------------------------------------------------------------- + //----------------------------------------------------------------- + // ローカルでのストロークの追加(POST) + public void addLocalStroke() { + final StrokesRest strokesRest = retrofit.create(StrokesRest.class); + + //----------------------------------------------------------------- + // ストローク追加API + Call call = strokesRest.addStroke( + acanthus.getAid(), acanthus.getPreferenceUid(), acanthus.getPreferenceToken(), + 0, 0, 10); + + // strokeNoを更新 + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) setCurrentStrokeNo(response.body()); + } + + @Override + public void onFailure(Call call, Throwable t) { + + } + }); + } + + //----------------------------------------------------------------- + // ローカルでの筆跡追加(POST) + public void addPosition(float x, float y) { + final StrokesRest strokesRest = retrofit.create(StrokesRest.class); + + //----------------------------------------------------------------- + // 筆跡追加API + Call call = strokesRest.addPositions(acanthus.getAid(), this.currentStrokeNo, x, y); + + // 筆跡を更新 + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + + } + } + + @Override + public void onFailure(Call call, Throwable t) { + + } + }); + } + //----------------------------------------------------------------- + +}