[update]paintのmodel用パッケージの追加
1 parent 236f851 commit 6924f24aeb3639f91f7da09a951346cbb6cc0fa0
k-fujii authored on 9 Jul 2021
Showing 5 changed files
View
64
app/src/main/java/org/ntlab/acanthus_client/views/paint/InvitesConnectionModel.java 100644 → 0
package org.ntlab.acanthus_client.views.paint;
 
import org.ntlab.acanthus_client.Acanthus;
import org.ntlab.acanthus_client.resources.gallery.InvitesRest;
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 InvitesConnectionModel {
private Retrofit retrofit;
private Acanthus acanthus;
 
//-----------------------------------------------------------------
//
public InvitesConnectionModel(Acanthus acanthus) {
init(acanthus);
}
 
//-----------------------------------------------------------------
//-----------------------------------------------------------------
// init
public void init(Acanthus acanthus) {
this.acanthus = acanthus;
this.retrofit = new Retrofit.Builder()
.baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/acanthus/")
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(JacksonConverterFactory.create())
.build();
}
 
//-----------------------------------------------------------------
// 新しい編集者の追加(POST)
public void inviteNewEditor(Integer invitedUid) {
final InvitesRest invitesRest = retrofit.create(InvitesRest.class);
Integer owner = 1;
String token = "abc0";
int dummy = 1111;
 
//-----------------------------------------------------------------
// 招待リクエストを送るAPI
Call<String> call = invitesRest.addInvite(dummy, owner.toString(), invitedUid.toString(), token);
call.enqueue(new Callback<String>() {
@Override
public void onResponse(Call<String> call, Response<String> response) {
if(response.isSuccessful());
}
 
@Override
public void onFailure(Call<String> call, Throwable t) {
 
}
});
}
//-----------------------------------------------------------------
 
}
View
176
app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintConnectionModel.java 100644 → 0
package org.ntlab.acanthus_client.views.paint;
 
import android.util.Log;
 
import androidx.lifecycle.MutableLiveData;
import androidx.navigation.ActivityNavigator;
 
import org.ntlab.acanthus_client.Acanthus;
import org.ntlab.acanthus_client.entities.Animation;
import org.ntlab.acanthus_client.entities.Position;
import org.ntlab.acanthus_client.entities.Stroke;
import org.ntlab.acanthus_client.resources.gallery.GalleryRest;
import org.ntlab.acanthus_client.resources.gallery.StrokesRest;
 
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
 
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;
 
//-----------------------------------------------------------------
// 描画通信
public class PaintConnectionModel {
private Animation editedAnimation;
private Integer currentStrokeNo;
private Retrofit retrofit;
private Acanthus acanthus;
private Collection getPaint;
 
//-----------------------------------------------------------------
//-----------------------------------------------------------------
//
public PaintConnectionModel(Acanthus acanthus) {
init(acanthus);
}
 
//-----------------------------------------------------------------
// 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;
this.getPaint = new ArrayList();
this.retrofit = new Retrofit.Builder()
.baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/acanthus/")
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(JacksonConverterFactory.create())
.build();
}
 
//-----------------------------------------------------------------
//-----------------------------------------------------------------
// ローカルでのストロークの追加(POST)
public void addLocalStroke() {
final StrokesRest strokesRest = retrofit.create(StrokesRest.class);
 
//-----------------------------------------------------------------
// ストローク追加API
Call<Integer> call = strokesRest.addStroke(
acanthus.getAid(), acanthus.getPreferenceUid(), acanthus.getPreferenceToken(),
0, 0, 10);
 
// strokeNoを更新
call.enqueue(new Callback<Integer>() {
@Override
public void onResponse(Call<Integer> call, Response<Integer> response) {
if (response.isSuccessful()) setCurrentStrokeNo(response.body());
}
 
@Override
public void onFailure(Call<Integer> call, Throwable t) {
 
}
});
}
 
//-----------------------------------------------------------------
// ローカルでの筆跡追加(POST)
public void addPosition(float x, float y) {
final StrokesRest strokesRest = retrofit.create(StrokesRest.class);
 
//-----------------------------------------------------------------
// 筆跡追加API
Call<Integer> call = strokesRest.addPositions(acanthus.getAid(), this.currentStrokeNo, x, y);
call.enqueue(new Callback<Integer>() {
@Override
public void onResponse(Call<Integer> call, Response<Integer> response) {
 
}
 
@Override
public void onFailure(Call<Integer> call, Throwable t) {
 
}
});
}
 
//-----------------------------------------------------------------
//Getを追加
public void apiGetPosition(MutableLiveData<Collection<Position>> paintPosition, int num) {
final StrokesRest strokesRest = retrofit.create(StrokesRest.class);
 
//-----------------------------------------------------------------
// 筆跡追加API
Call<Collection<Position>> call = strokesRest.getPositions(acanthus.getAid(), num);
call.enqueue(new Callback<Collection<Position>>() {
@Override
public void onResponse(Call<Collection<Position>> call, Response<Collection<Position>> response) {
if (response.isSuccessful()) paintPosition.setValue(response.body());
}
 
@Override
public void onFailure(Call<Collection<Position>> call, Throwable t) {
 
}
});
 
}
 
//-----------------------------------------------------------------
//Getを追加
public void getStrokeSize(MutableLiveData<Collection<Stroke>> strokes) {
final StrokesRest strokesRest = retrofit.create(StrokesRest.class);
 
//-----------------------------------------------------------------
// 筆跡追加API
Call<Collection<Stroke>> call = strokesRest.getStrokes(acanthus.getAid());
call.enqueue(new Callback<Collection<Stroke>>() {
@Override
public void onResponse(Call<Collection<Stroke>> call, Response<Collection<Stroke>> response) {
if (response.isSuccessful()) strokes.setValue(response.body());
}
 
@Override
public void onFailure(Call<Collection<Stroke>> call, Throwable t) {
 
}
});
 
}
 
//-----------------------------------------------------------------
//DELETE
public void deleteStrokes() {
final StrokesRest strokesRest = retrofit.create(StrokesRest.class);
 
//-----------------------------------------------------------------
// 筆跡をすべて削除する
Call<String> call = strokesRest.deleteStrokes(acanthus.getAid(), acanthus.getPreferenceUid());
call.enqueue(new Callback<String>() {
@Override
public void onResponse(Call<String> call, Response<String> response) {
}
 
@Override
public void onFailure(Call<String> call, Throwable t) {
}
});
}
//-----------------------------------------------------------------
 
}
View
2
■■■
app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintModelContainer.java
package org.ntlab.acanthus_client.views.paint;
 
import org.ntlab.acanthus_client.Acanthus;
import org.ntlab.acanthus_client.views.paint.models.InvitesConnectionModel;
import org.ntlab.acanthus_client.views.paint.models.PaintConnectionModel;
 
//-----------------------------------------------------------------
// 各種モデルの保持者
public class PaintModelContainer {
View
64
app/src/main/java/org/ntlab/acanthus_client/views/paint/models/InvitesConnectionModel.java 0 → 100644
package org.ntlab.acanthus_client.views.paint.models;
 
import org.ntlab.acanthus_client.Acanthus;
import org.ntlab.acanthus_client.resources.gallery.InvitesRest;
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 InvitesConnectionModel {
private Retrofit retrofit;
private Acanthus acanthus;
 
//-----------------------------------------------------------------
//
public InvitesConnectionModel(Acanthus acanthus) {
init(acanthus);
}
 
//-----------------------------------------------------------------
//-----------------------------------------------------------------
// init
public void init(Acanthus acanthus) {
this.acanthus = acanthus;
this.retrofit = new Retrofit.Builder()
.baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/acanthus/")
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(JacksonConverterFactory.create())
.build();
}
 
//-----------------------------------------------------------------
// 新しい編集者の追加(POST)
public void inviteNewEditor(Integer invitedUid) {
final InvitesRest invitesRest = retrofit.create(InvitesRest.class);
Integer owner = 1;
String token = "abc0";
int dummy = 1111;
 
//-----------------------------------------------------------------
// 招待リクエストを送るAPI
Call<String> call = invitesRest.addInvite(dummy, owner.toString(), invitedUid.toString(), token);
call.enqueue(new Callback<String>() {
@Override
public void onResponse(Call<String> call, Response<String> response) {
if(response.isSuccessful());
}
 
@Override
public void onFailure(Call<String> call, Throwable t) {
 
}
});
}
//-----------------------------------------------------------------
 
}
View
176
app/src/main/java/org/ntlab/acanthus_client/views/paint/models/PaintConnectionModel.java 0 → 100644
package org.ntlab.acanthus_client.views.paint.models;
 
import android.util.Log;
 
import androidx.lifecycle.MutableLiveData;
import androidx.navigation.ActivityNavigator;
 
import org.ntlab.acanthus_client.Acanthus;
import org.ntlab.acanthus_client.entities.Animation;
import org.ntlab.acanthus_client.entities.Position;
import org.ntlab.acanthus_client.entities.Stroke;
import org.ntlab.acanthus_client.resources.gallery.GalleryRest;
import org.ntlab.acanthus_client.resources.gallery.StrokesRest;
 
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
 
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;
 
//-----------------------------------------------------------------
// 描画通信
public class PaintConnectionModel {
private Animation editedAnimation;
private Integer currentStrokeNo;
private Retrofit retrofit;
private Acanthus acanthus;
private Collection getPaint;
 
//-----------------------------------------------------------------
//-----------------------------------------------------------------
//
public PaintConnectionModel(Acanthus acanthus) {
init(acanthus);
}
 
//-----------------------------------------------------------------
// 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;
this.getPaint = new ArrayList();
this.retrofit = new Retrofit.Builder()
.baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/acanthus/")
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(JacksonConverterFactory.create())
.build();
}
 
//-----------------------------------------------------------------
//-----------------------------------------------------------------
// ローカルでのストロークの追加(POST)
public void addLocalStroke() {
final StrokesRest strokesRest = retrofit.create(StrokesRest.class);
 
//-----------------------------------------------------------------
// ストローク追加API
Call<Integer> call = strokesRest.addStroke(
acanthus.getAid(), acanthus.getPreferenceUid(), acanthus.getPreferenceToken(),
0, 0, 10);
 
// strokeNoを更新
call.enqueue(new Callback<Integer>() {
@Override
public void onResponse(Call<Integer> call, Response<Integer> response) {
if (response.isSuccessful()) setCurrentStrokeNo(response.body());
}
 
@Override
public void onFailure(Call<Integer> call, Throwable t) {
 
}
});
}
 
//-----------------------------------------------------------------
// ローカルでの筆跡追加(POST)
public void addPosition(float x, float y) {
final StrokesRest strokesRest = retrofit.create(StrokesRest.class);
 
//-----------------------------------------------------------------
// 筆跡追加API
Call<Integer> call = strokesRest.addPositions(acanthus.getAid(), this.currentStrokeNo, x, y);
call.enqueue(new Callback<Integer>() {
@Override
public void onResponse(Call<Integer> call, Response<Integer> response) {
 
}
 
@Override
public void onFailure(Call<Integer> call, Throwable t) {
 
}
});
}
 
//-----------------------------------------------------------------
//Getを追加
public void apiGetPosition(MutableLiveData<Collection<Position>> paintPosition, int num) {
final StrokesRest strokesRest = retrofit.create(StrokesRest.class);
 
//-----------------------------------------------------------------
// 筆跡追加API
Call<Collection<Position>> call = strokesRest.getPositions(acanthus.getAid(), num);
call.enqueue(new Callback<Collection<Position>>() {
@Override
public void onResponse(Call<Collection<Position>> call, Response<Collection<Position>> response) {
if (response.isSuccessful()) paintPosition.setValue(response.body());
}
 
@Override
public void onFailure(Call<Collection<Position>> call, Throwable t) {
 
}
});
 
}
 
//-----------------------------------------------------------------
//Getを追加
public void getStrokeSize(MutableLiveData<Collection<Stroke>> strokes) {
final StrokesRest strokesRest = retrofit.create(StrokesRest.class);
 
//-----------------------------------------------------------------
// 筆跡追加API
Call<Collection<Stroke>> call = strokesRest.getStrokes(acanthus.getAid());
call.enqueue(new Callback<Collection<Stroke>>() {
@Override
public void onResponse(Call<Collection<Stroke>> call, Response<Collection<Stroke>> response) {
if (response.isSuccessful()) strokes.setValue(response.body());
}
 
@Override
public void onFailure(Call<Collection<Stroke>> call, Throwable t) {
 
}
});
 
}
 
//-----------------------------------------------------------------
//DELETE
public void deleteStrokes() {
final StrokesRest strokesRest = retrofit.create(StrokesRest.class);
 
//-----------------------------------------------------------------
// 筆跡をすべて削除する
Call<String> call = strokesRest.deleteStrokes(acanthus.getAid(), acanthus.getPreferenceUid());
call.enqueue(new Callback<String>() {
@Override
public void onResponse(Call<String> call, Response<String> response) {
}
 
@Override
public void onFailure(Call<String> call, Throwable t) {
}
});
}
//-----------------------------------------------------------------
 
}