diff --git a/app/src/main/java/org/ntlab/acanthus_client/Acanthus.java b/app/src/main/java/org/ntlab/acanthus_client/Acanthus.java index 5331097..4cf6c47 100644 --- a/app/src/main/java/org/ntlab/acanthus_client/Acanthus.java +++ b/app/src/main/java/org/ntlab/acanthus_client/Acanthus.java @@ -21,7 +21,7 @@ private String preferenceToken; //----------------------------------------------------------------- private Integer aid; - private Integer editingPageNo; + private Integer editingPageNo = 0; private Animation currentAnimation; private Collection animationJsonList = new ArrayList<>(); @@ -76,6 +76,7 @@ } public Integer getEditingPageNo() { + if (editingPageNo == null) editingPageNo = 0; return editingPageNo; } diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintModelContainer.java b/app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintModelContainer.java index c4d21e3..2ea0c4f 100644 --- a/app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintModelContainer.java +++ b/app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintModelContainer.java @@ -1,9 +1,11 @@ package org.ntlab.acanthus_client.views.paint; import org.ntlab.acanthus_client.Acanthus; +import org.ntlab.acanthus_client.entities.Page; import org.ntlab.acanthus_client.resources.gallery.PagesRest; import org.ntlab.acanthus_client.views.paint.models.InvitesConnectionModel; import org.ntlab.acanthus_client.views.paint.models.PageConnectionModel; +import org.ntlab.acanthus_client.views.paint.models.PageOperationModel; import org.ntlab.acanthus_client.views.paint.models.PaintConnectionModel; //----------------------------------------------------------------- @@ -12,6 +14,7 @@ private PaintConnectionModel paintConnectionModel; private InvitesConnectionModel invitesConnectionModel; private PageConnectionModel pageConnectionModel; + private PageOperationModel pageOperationModel; //----------------------------------------------------------------- //----------------------------------------------------------------- @@ -20,6 +23,7 @@ this.paintConnectionModel = new PaintConnectionModel(acanthus); this.invitesConnectionModel = new InvitesConnectionModel(acanthus); this.pageConnectionModel = new PageConnectionModel(acanthus); + this.pageOperationModel = new PageOperationModel(acanthus); } //----------------------------------------------------------------- @@ -36,5 +40,8 @@ return pageConnectionModel; } + public PageOperationModel getPageOperationModel() { + return pageOperationModel; + } //----------------------------------------------------------------- } diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintViewModel.java b/app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintViewModel.java index 0670a5a..a279ac3 100644 --- a/app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintViewModel.java +++ b/app/src/main/java/org/ntlab/acanthus_client/views/paint/PaintViewModel.java @@ -1,16 +1,12 @@ package org.ntlab.acanthus_client.views.paint; -import android.util.Log; import android.view.MotionEvent; -import android.view.VelocityTracker; import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; -import org.jetbrains.annotations.NotNull; import org.ntlab.acanthus_client.Acanthus; -import org.ntlab.acanthus_client.entities.Position; import org.ntlab.acanthus_client.entities.Stroke; import java.util.ArrayList; @@ -25,9 +21,11 @@ private PaintModelContainer paintModelContainer; + private MutableLiveData mPageLength = new MutableLiveData<>(); private MutableLiveData mPageNo = new MutableLiveData<>(); private MutableLiveData mStrokeNo = new MutableLiveData<>(); private MutableLiveData> mStrokes = new MutableLiveData<>(); + private ScheduledThreadPoolExecutor thread = new ScheduledThreadPoolExecutor(1); //----------------------------------------------------------------- @@ -40,10 +38,18 @@ return this.mStrokeNo; } + public LiveData getPageLength() { + return this.mPageLength; + } + public LiveData getPageNo() { return this.mPageNo; } + public PaintModelContainer getPaintModelContainer() { + return paintModelContainer; + } + //----------------------------------------------------------------- //----------------------------------------------------------------- // init @@ -81,9 +87,15 @@ } //----------------------------------------------------------------- + // + public void updatePageNo(MotionEvent event) { + paintModelContainer.getPageOperationModel().updatePageNo(event, mPageNo); + } + + //----------------------------------------------------------------- // ページの追加通信リクエスト public void addPageRequest() { - paintModelContainer.getPageConnectionModel().addPage(mPageNo); + paintModelContainer.getPageConnectionModel().addPage(mPageLength); } //----------------------------------------------------------------- diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/paint/models/PageOperationModel.java b/app/src/main/java/org/ntlab/acanthus_client/views/paint/models/PageOperationModel.java index 61d23a6..7f2940d 100644 --- a/app/src/main/java/org/ntlab/acanthus_client/views/paint/models/PageOperationModel.java +++ b/app/src/main/java/org/ntlab/acanthus_client/views/paint/models/PageOperationModel.java @@ -1,4 +1,77 @@ package org.ntlab.acanthus_client.views.paint.models; +import android.preference.SwitchPreference; +import android.view.MotionEvent; +import android.view.VelocityTracker; + +import androidx.lifecycle.MutableLiveData; + +import org.ntlab.acanthus_client.Acanthus; + +//----------------------------------------------------------------- +// + public class PageOperationModel { + //----------------------------------------------------------------- + // スワイプの向き + public enum SwipeDirectionType { + LEFT, RIGHT + } + + //----------------------------------------------------------------- + //----------------------------------------------------------------- + private Acanthus acanthus; + private VelocityTracker velocityTracker; + + //----------------------------------------------------------------- + //----------------------------------------------------------------- + public PageOperationModel(Acanthus acanthus) { + this.acanthus = acanthus; + } + + //----------------------------------------------------------------- + //----------------------------------------------------------------- + public void updatePageNo(MotionEvent event, MutableLiveData mPageNo) { + if (getVelocityDirection(event).equals(SwipeDirectionType.RIGHT)) incrementPageNo(mPageNo); + if (getVelocityDirection(event).equals(SwipeDirectionType.LEFT)) decrementPageNo(mPageNo); + } + + //----------------------------------------------------------------- + //----------------------------------------------------------------- + // + public void incrementPageNo(MutableLiveData mPageNo) { +// if(acanthus.getEditingPageNo()) + Integer editingNo = acanthus.getEditingPageNo(); + + acanthus.setEditingPageNo(editingNo + 1); + mPageNo.setValue(acanthus.getEditingPageNo()); + } + + //-----------------------------------------------------------------s + // + private void decrementPageNo(MutableLiveData mPageNo) { + Integer editingNo = acanthus.getEditingPageNo(); + if (0 < editingNo ) { + acanthus.setEditingPageNo(acanthus.getEditingPageNo() - 1); + mPageNo.setValue(acanthus.getEditingPageNo()); + } + } + + + //----------------------------------------------------------------- + // 操作からスワイプの向きを取得する + private SwipeDirectionType getVelocityDirection(MotionEvent event) { + if (velocityTracker == null) velocityTracker = VelocityTracker.obtain(); + else velocityTracker.clear(); + + velocityTracker.addMovement(event); + velocityTracker.computeCurrentVelocity(1000); + + if (velocityTracker.getXVelocity() < 0) return SwipeDirectionType.LEFT; + else return SwipeDirectionType.RIGHT; + } + + //----------------------------------------------------------------- + //----------------------------------------------------------------- + } diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/paint/page/PageActivity.java b/app/src/main/java/org/ntlab/acanthus_client/views/paint/page/PageActivity.java index d355000..2d6856f 100644 --- a/app/src/main/java/org/ntlab/acanthus_client/views/paint/page/PageActivity.java +++ b/app/src/main/java/org/ntlab/acanthus_client/views/paint/page/PageActivity.java @@ -5,20 +5,18 @@ import androidx.lifecycle.ViewModelProvider; import android.os.Bundle; -import android.util.Log; import android.view.MotionEvent; -import android.view.VelocityTracker; import android.view.View; import org.ntlab.acanthus_client.Acanthus; import org.ntlab.acanthus_client.R; import org.ntlab.acanthus_client.databinding.ActivityPageBinding; -import org.ntlab.acanthus_client.databinding.ActivityPaintBinding; import org.ntlab.acanthus_client.views.paint.PaintViewModel; //----------------------------------------------------------------- // ページ編集画面 public class PageActivity extends AppCompatActivity { + private Acanthus acanthus; private PaintViewModel paintViewModel; private ActivityPageBinding binding; @@ -33,6 +31,7 @@ initView(); } + //----------------------------------------------------------------- // public void onClickAddPage(View view) { @@ -43,23 +42,24 @@ // @Override public boolean onTouchEvent(MotionEvent event) { - int index = event.getActionIndex(); int action = event.getActionMasked(); //----------------------------------------------------------------- switch (action) { case MotionEvent.ACTION_MOVE: - onSlideAddPage(); + slidePage(event); + break; } + return true; } //----------------------------------------------------------------- //----------------------------------------------------------------- private void init() { - Acanthus acanthus = (Acanthus) getApplication(); + this.acanthus = (Acanthus) getApplication(); paintViewModel = new ViewModelProvider(this).get(PaintViewModel.class); paintViewModel.init(acanthus); @@ -68,27 +68,34 @@ //----------------------------------------------------------------- // - public void onSlideAddPage() { - paintViewModel.addPageRequest(); + public void slidePage(MotionEvent event) { + paintViewModel.updatePageNo(event); } - //----------------------------------------------------------------- // private void initView() { binding = ActivityPageBinding.inflate(getLayoutInflater()); setContentView(binding.getRoot()); + } //----------------------------------------------------------------- // private void startObserve() { - paintViewModel.getPageNo().observe(this, new Observer() { + paintViewModel.getPageLength().observe(this, new Observer() { @Override public void onChanged(Integer i) { binding.buttonAddPage.setText(String.valueOf(i)); } }); + + paintViewModel.getPageNo().observe(this, new Observer() { + @Override + public void onChanged(Integer pageNo) { + binding.textPageNo.setText(String.valueOf(pageNo)); + } + }); } //----------------------------------------------------------------- } \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/paint/page/SwipeDirectionType.java b/app/src/main/java/org/ntlab/acanthus_client/views/paint/page/SwipeDirectionType.java new file mode 100644 index 0000000..0a105de --- /dev/null +++ b/app/src/main/java/org/ntlab/acanthus_client/views/paint/page/SwipeDirectionType.java @@ -0,0 +1,6 @@ +package org.ntlab.acanthus_client.views.paint.page; + +//----------------------------------------------------------------- +// +public enum SwipeDirectionType { +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_page.xml b/app/src/main/res/layout/activity_page.xml index 6b22c3e..ea819b4 100644 --- a/app/src/main/res/layout/activity_page.xml +++ b/app/src/main/res/layout/activity_page.xml @@ -21,7 +21,7 @@ app:layout_constraintHorizontal_bias="0.498" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - app:layout_constraintVertical_bias="0.59" /> + app:layout_constraintVertical_bias="0.802" /> + + + +