From d780eedafe71cc46aae175e434e7b4d2650d98e0 Mon Sep 17 00:00:00 2001 From: babaliaris Date: Fri, 13 Nov 2020 15:00:05 +0200 Subject: [PATCH 1/7] Implemented dragable bookmarks. --- app/build.gradle | 1 + .../bookmarks/BookmarksAdapter.java | 180 ++++++++++++++++++ .../bookmarks/BookmarksFragment.java | 108 ++++++----- .../main/res/layout/fragment_bookmarks.xml | 45 ++--- .../res/layout/fragment_bookmarks_row.xml | 88 +++++---- build.gradle | 2 + 6 files changed, 309 insertions(+), 115 deletions(-) create mode 100644 app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksAdapter.java diff --git a/app/build.gradle b/app/build.gradle index 0c95158c..9ceb69fd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -118,4 +118,5 @@ dependencies { testImplementation 'org.powermock:powermock-module-junit4:2.0.2' testImplementation 'org.powermock:powermock-api-mockito2:2.0.2' testImplementation 'net.lachlanmckee:timber-junit-rule:1.0.1' + implementation 'com.github.woxthebox:draglistview:1.7.2' } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksAdapter.java new file mode 100644 index 00000000..0049cdc1 --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksAdapter.java @@ -0,0 +1,180 @@ +package gr.thmmy.mthmmy.activities.bookmarks; + +import android.app.Activity; +import android.graphics.drawable.Drawable; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.NonNull; + +import com.woxthebox.draglistview.DragItemAdapter; + +import java.util.ArrayList; + +import gr.thmmy.mthmmy.R; +import gr.thmmy.mthmmy.model.Bookmark; + + + + +public class BookmarksAdapter extends DragItemAdapter, BookmarksAdapter.BookmarksViewHolder> +{ + private final BookmarksFragment m_fragment; + private final ArrayList m_bookMarks; + private final Drawable m_notificationsEnabled; + private final Drawable m_notificationsDisabled; + + public BookmarksAdapter(BookmarksFragment fragment, ArrayList bookmarks, Drawable noteEnabled, Drawable noteDisabled) + { + this.m_fragment = fragment; + this.m_bookMarks = bookmarks; + this.m_notificationsEnabled = noteEnabled; + this.m_notificationsDisabled = noteDisabled; + } + + @Override + public long getUniqueItemId(int position) + { + return m_bookMarks.get(position).getId().hashCode(); + } + + @NonNull + @Override + public BookmarksAdapter.BookmarksViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) + { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_bookmarks_row, parent, false); + return new BookmarksViewHolder(view, view.findViewById(R.id.bookmark_dragable).getId(), true); + } + + @Override + public void onBindViewHolder(@NonNull BookmarksViewHolder holder, int position) + { + super.onBindViewHolder(holder, position); + + //Check if bookMarks ArrayList Exists and is not empty. + if(m_bookMarks != null && !m_bookMarks.isEmpty()) + { + //Check if the current bookmark exists and has a title. + if (m_bookMarks.get(position) != null && m_bookMarks.get(position).getTitle() != null) + { + + //Set the title. + holder.m_textView.setText(m_bookMarks.get(position).getTitle()); + + //Set Notifications Enabled Image Indicator. + if (m_bookMarks.get(position).isNotificationsEnabled()) + holder.m_noteView.setImageDrawable(m_notificationsEnabled); + + //Set Notifications Disabled Image Indicator. + else + holder.m_noteView.setImageDrawable(m_notificationsDisabled); + + + //On Bookmark Click. + holder.mGrabView.setOnClickListener(v -> { + + //Get the activity. + Activity activity = m_fragment.getActivity(); + + //Go to the bookmarked activity. + if (activity instanceof BookmarksActivity) + ((BookmarksActivity) activity).onFragmentRowInteractionListener( + m_fragment.type, + m_fragment.interactionClick, + m_bookMarks.get(position)); + }); + + + //On Notifications Toggle. + holder.m_noteView.setOnClickListener(v -> { + + //Toggle the current local instance. + m_bookMarks.get(position).toggleNotificationsEnabled(); + + //Get the fragment activity. + Activity activity = m_fragment.getActivity(); + + //Check if it is indeed the fragment activity. + if (activity instanceof BookmarksActivity) + { + + //Trigger the toggle functionality and set the Enabled notifications image. + if (((BookmarksActivity) activity).onFragmentRowInteractionListener( + m_fragment.type, + m_fragment.interactionToggle, + m_bookMarks.get(position))) + { + holder.m_noteView.setImageDrawable(m_notificationsEnabled); + } + + //Trigger returned false, so set the notifications disabled image. + else + holder.m_noteView.setImageDrawable(m_notificationsDisabled); + } + }); + + + //Remove Item. + holder.m_removeView.setOnClickListener(v -> { + + //Get fragment's activity. + Activity activity = m_fragment.getActivity(); + + if (activity instanceof BookmarksActivity) + { + + //Trigger the bookmark remove functionality. + ((BookmarksActivity) activity).onFragmentRowInteractionListener( + m_fragment.type, + m_fragment.interactionRemove, + m_bookMarks.get(position)); + { + notifyItemRemoved(position); + notifyItemRangeChanged(position, m_bookMarks.size()); + m_bookMarks.remove(m_bookMarks.get(position)); + } + } + + //If the bookmarks are empty then show nothing marked. + if (m_bookMarks.isEmpty()) + { + m_fragment.showNothingBookmarked(); + } + + }); + } + } + } + + @Override + public int getItemCount() + { + if (m_bookMarks != null) + return m_bookMarks.size(); + + return 0; + } + + //View Holder. + static class BookmarksViewHolder extends DragItemAdapter.ViewHolder + { + + public final TextView m_textView; + public final ImageView m_noteView; + public final ImageView m_removeView; + public final View m_thisView; + + public BookmarksViewHolder(View itemView, int handleResId, boolean dragOnLongPress) + { + super(itemView, handleResId, dragOnLongPress); + this.m_textView = itemView.findViewById(R.id.bookmark_title); + this.m_noteView = itemView.findViewById(R.id.toggle_notification); + this.m_removeView = itemView.findViewById(R.id.remove_bookmark); + this.m_thisView = itemView; + } + } +} diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java index cdd6f714..94a49b69 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java @@ -1,20 +1,22 @@ package gr.thmmy.mthmmy.activities.bookmarks; -import android.app.Activity; + import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageButton; -import android.widget.LinearLayout; import android.widget.TextView; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat; +import com.woxthebox.draglistview.DragListView; + import java.util.ArrayList; import gr.thmmy.mthmmy.R; @@ -37,8 +39,8 @@ public class BookmarksFragment extends Fragment { private TextView nothingBookmarkedTextView; private ArrayList bookmarks = null; - private Type type; - private String interactionClick, interactionToggle, interactionRemove; + public Type type; + public String interactionClick, interactionToggle, interactionRemove; private Drawable notificationsEnabledButtonImage; private Drawable notificationsDisabledButtonImage; @@ -100,66 +102,70 @@ public class BookmarksFragment extends Fragment { Bundle savedInstanceState) { // Inflates the layout for this fragment final View rootView = layoutInflater.inflate(R.layout.fragment_bookmarks, container, false); - //bookmarks container - final LinearLayout bookmarksLinearView = rootView.findViewById(R.id.bookmarks_container); + + //Get the nothing bookmarked text view. nothingBookmarkedTextView = rootView.findViewById(R.id.nothing_bookmarked); - if(this.bookmarks != null && !this.bookmarks.isEmpty()) { - hideNothingBookmarked(); - for (final Bookmark bookmark : bookmarks) { - if (bookmark != null && bookmark.getTitle() != null) { - final LinearLayout row = (LinearLayout) layoutInflater.inflate( - R.layout.fragment_bookmarks_row, bookmarksLinearView, false); - row.setOnClickListener(view -> { - Activity activity = getActivity(); - if (activity instanceof BookmarksActivity) - ((BookmarksActivity) activity).onFragmentRowInteractionListener(type, interactionClick, bookmark); - }); - ((TextView) row.findViewById(R.id.bookmark_title)).setText(bookmark.getTitle()); - - final ImageButton notificationsEnabledButton = row.findViewById(R.id.toggle_notification); - if (!bookmark.isNotificationsEnabled()) { - notificationsEnabledButton.setImageDrawable(notificationsDisabledButtonImage); - } - - notificationsEnabledButton.setOnClickListener(view -> { - Activity activity = getActivity(); - if (activity instanceof BookmarksActivity) { - if (((BookmarksActivity) activity).onFragmentRowInteractionListener(type, interactionToggle, bookmark)) - notificationsEnabledButton.setImageDrawable(notificationsEnabledButtonImage); - else - notificationsEnabledButton.setImageDrawable(notificationsDisabledButtonImage); - } - }); - - (row.findViewById(R.id.remove_bookmark)).setOnClickListener(view -> { - Activity activity = getActivity(); - if (activity instanceof BookmarksActivity){ - ((BookmarksActivity) activity).onFragmentRowInteractionListener(type, interactionRemove, bookmark); - bookmarks.remove(bookmark); - } - row.setVisibility(View.GONE); - - if (bookmarks.isEmpty()){ - showNothingBookmarked(); - } - }); - bookmarksLinearView.addView(row); + DragListView mDragListView = (DragListView) rootView.findViewById(R.id.fragment_bookmarks_dragList); + + mDragListView.setDragListListener(new DragListView.DragListListener() + { + @Override + public void onItemDragStarted(int position) + { + } + + @Override + public void onItemDragging(int itemPosition, float x, float y) + { + + } + + @Override + public void onItemDragEnded(int fromPosition, int toPosition) + { + + //TODO: This only works locally. If the user exit the bookmarks + // or closes the app, the order of the bookmarks will be lost. + // make sure after the following swapping, to apply the changes + // in the actual data model of the bookmarks. + + if (fromPosition != toPosition) + { + Bookmark from = bookmarks.get(fromPosition); + + bookmarks.set(fromPosition, bookmarks.get(toPosition)); + bookmarks.set(toPosition, from); } } - } else + }); + + mDragListView.setLayoutManager(new LinearLayoutManager(getActivity())); + BookmarksAdapter adapter = new BookmarksAdapter(this, bookmarks, notificationsEnabledButtonImage, notificationsDisabledButtonImage); + mDragListView.setAdapter(adapter, false); + mDragListView.setCanDragHorizontally(false); + + //Hide Nothing Bookmarked. + if(this.bookmarks != null && !this.bookmarks.isEmpty()) + { + hideNothingBookmarked(); + } + + //Show Nothing Bookmarked. + else { showNothingBookmarked(); + } return rootView; } - private void showNothingBookmarked() { + public void showNothingBookmarked() { if(nothingBookmarkedTextView!=null) nothingBookmarkedTextView.setVisibility(View.VISIBLE); } - private void hideNothingBookmarked(){ + public void hideNothingBookmarked(){ if(nothingBookmarkedTextView!=null) nothingBookmarkedTextView.setVisibility(View.INVISIBLE); } diff --git a/app/src/main/res/layout/fragment_bookmarks.xml b/app/src/main/res/layout/fragment_bookmarks.xml index aa1bbaab..65101e44 100644 --- a/app/src/main/res/layout/fragment_bookmarks.xml +++ b/app/src/main/res/layout/fragment_bookmarks.xml @@ -1,36 +1,33 @@ - + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + > + + - - - - \ No newline at end of file + android:visibility="invisible" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_bookmarks_row.xml b/app/src/main/res/layout/fragment_bookmarks_row.xml index b3e17ebe..07ca07b2 100644 --- a/app/src/main/res/layout/fragment_bookmarks_row.xml +++ b/app/src/main/res/layout/fragment_bookmarks_row.xml @@ -1,50 +1,58 @@ - + > - + android:background="?android:attr/selectableItemBackground" + android:clickable="true" + android:focusable="true" + android:gravity="center_vertical" + android:orientation="horizontal"> + + - + - - \ No newline at end of file + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index a861f527..45116ef0 100644 --- a/build.gradle +++ b/build.gradle @@ -5,6 +5,7 @@ buildscript { repositories { google() jcenter() + mavenCentral() maven { url "https://jitpack.io" } } dependencies { @@ -21,6 +22,7 @@ allprojects { maven { url "https://maven.google.com" } google() jcenter() + mavenCentral() maven { url "https://jitpack.io" } } } From f1cd0435c98c90c72cfe3d9cb247cda12658ced5 Mon Sep 17 00:00:00 2001 From: babaliaris Date: Fri, 13 Nov 2020 19:58:30 +0200 Subject: [PATCH 2/7] Added TODO comments --- .../gr/thmmy/mthmmy/activities/bookmarks/BookmarksAdapter.java | 2 ++ .../gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java | 1 + 2 files changed, 3 insertions(+) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksAdapter.java index 0049cdc1..30d7aaf9 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksAdapter.java @@ -119,6 +119,8 @@ public class BookmarksAdapter extends DragItemAdapter, Bookm //Remove Item. + //TODO: AFTER DELETION, UPDATE THE ORDER IN THE PREFERENCES OF ALL + // ALL THE BOOKMARKS UNDER THIS ONE THAT HAS BEEN DELETED! holder.m_removeView.setOnClickListener(v -> { //Get fragment's activity. diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java index 94a49b69..d319f3ad 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java @@ -129,6 +129,7 @@ public class BookmarksFragment extends Fragment { // or closes the app, the order of the bookmarks will be lost. // make sure after the following swapping, to apply the changes // in the actual data model of the bookmarks. + // AFTER SWAPPING UPDATE THE ORDER OF THOSE TWO IN THE PREFERENCES. if (fromPosition != toPosition) { From 1fc14228bf6976a0b11de3416f63d7fba471a153 Mon Sep 17 00:00:00 2001 From: babaliaris Date: Sat, 14 Nov 2020 13:16:16 +0200 Subject: [PATCH 3/7] Finished updating the preferences after reordering --- .../bookmarks/BookmarksActivity.java | 6 ++ .../bookmarks/BookmarksFragment.java | 27 ++++-- .../gr/thmmy/mthmmy/base/BaseActivity.java | 82 +++++++++++++++++++ 3 files changed, 109 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksActivity.java index dcf2ea84..6a281d92 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksActivity.java @@ -77,6 +77,12 @@ public class BookmarksActivity extends BaseActivity { return false; } + + public void swapBookmarksAfterReorder(Bookmark first, Bookmark second) + { + this.swapBookmarks(first, second); + } + private boolean onTopicInteractionListener(String interactionType, Bookmark bookmarkedTopic) { switch (interactionType) { case BookmarksFragment.INTERACTION_CLICK_TOPIC_BOOKMARK: diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java index d319f3ad..d3c801d4 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java @@ -1,6 +1,7 @@ package gr.thmmy.mthmmy.activities.bookmarks; +import android.app.Activity; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; @@ -125,26 +126,39 @@ public class BookmarksFragment extends Fragment { public void onItemDragEnded(int fromPosition, int toPosition) { - //TODO: This only works locally. If the user exit the bookmarks - // or closes the app, the order of the bookmarks will be lost. - // make sure after the following swapping, to apply the changes - // in the actual data model of the bookmarks. - // AFTER SWAPPING UPDATE THE ORDER OF THOSE TWO IN THE PREFERENCES. - + //If the drag and drop is not the same item. if (fromPosition != toPosition) { + + //Get the from bookmark. Bookmark from = bookmarks.get(fromPosition); + //Swap the from and to bookmarks. bookmarks.set(fromPosition, bookmarks.get(toPosition)); bookmarks.set(toPosition, from); + + //Get the fragments activity. + Activity unknownActivity = getActivity(); + + //Update the order of the bookmarks in the preferences. + if (unknownActivity instanceof BookmarksActivity) + { + //Cast to BookmarksActivity. + BookmarksActivity activity = (BookmarksActivity)unknownActivity; + + //Call the swapBookmarksAfterReorder to apply the swapping changes to the preferences. + activity.swapBookmarksAfterReorder( bookmarks.get(fromPosition), bookmarks.get(toPosition) ); + } } } }); + //====================================This is the code for the Drag and Drop Functionality====================================// mDragListView.setLayoutManager(new LinearLayoutManager(getActivity())); BookmarksAdapter adapter = new BookmarksAdapter(this, bookmarks, notificationsEnabledButtonImage, notificationsDisabledButtonImage); mDragListView.setAdapter(adapter, false); mDragListView.setCanDragHorizontally(false); + //====================================This is the code for the Drag and Drop Functionality====================================// //Hide Nothing Bookmarked. if(this.bookmarks != null && !this.bookmarks.isEmpty()) @@ -157,6 +171,7 @@ public class BookmarksFragment extends Fragment { showNothingBookmarked(); } + return rootView; } diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java index 9d71710b..1c7d38c9 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -48,6 +48,7 @@ import net.gotev.uploadservice.UploadService; import java.io.File; import java.util.ArrayList; +import gr.thmmy.mthmmy.BuildConfig; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.AboutActivity; import gr.thmmy.mthmmy.activities.LoginActivity; @@ -689,6 +690,87 @@ public abstract class BaseActivity extends AppCompatActivity { Timber.w("No bookmark match exists!"); return false; } + + + //TODO: Abstract reusable code: find the index of the first and second bookmark. + protected void swapBookmarks(Bookmark first, Bookmark second) + { + + //No need to check is second is a topics bookmark. + //because there is no way to drag and drop between topic and board. + if ( first.matchExists(topicsBookmarked) ) + { + //Find the index of the first and second bookmark. + int firstIndex = -1, secondIndex = -1; + for (int i = 0; i < topicsBookmarked.size(); i++) + { + + //Find the first index. + if (first.getId().equals(topicsBookmarked.get(i).getId())) + firstIndex = i; + + //Find the second index. + else if (second.getId().equals(topicsBookmarked.get(i).getId())) + secondIndex = i; + + //If both indexes found, stop. + if (firstIndex != -1 && secondIndex != -1) + break; + } + + //Assert, both indexes should have been found. + if (BuildConfig.DEBUG && !(firstIndex != -1 && secondIndex != -1)) { + throw new AssertionError("firstIndex and secondIndex must exist!"); + } + + //Temp store the first bookmark. + Bookmark firstBookmark = topicsBookmarked.get(firstIndex); + + //Swap the bookmarks. + topicsBookmarked.set(firstIndex, topicsBookmarked.get(secondIndex)); + topicsBookmarked.set(secondIndex, firstBookmark); + + //Update the bookmarks. + updateTopicBookmarks(); + } + + //Swap on Board Bookmarks. + else if ( first.matchExists(boardsBookmarked) ) + { + //Find the index of the first and second bookmark. + int firstIndex = -1, secondIndex = -1; + for (int i = 0; i < boardsBookmarked.size(); i++) + { + + //Find the first index. + if (first.getId().equals(boardsBookmarked.get(i).getId())) + firstIndex = i; + + + //Find the second index. + else if (second.getId().equals(boardsBookmarked.get(i).getId())) + secondIndex = i; + + //If both indexes found, stop. + if (firstIndex != -1 && secondIndex != -1) + break; + } + + if (BuildConfig.DEBUG && !(firstIndex != -1 && secondIndex != -1)) { + throw new AssertionError("firstIndex and secondIndex must exist!"); + } + + //Temp store the first bookmark. + Bookmark firstBookmark = boardsBookmarked.get(firstIndex); + + //Swap the bookmarks. + boardsBookmarked.set(firstIndex, boardsBookmarked.get(secondIndex)); + boardsBookmarked.set(secondIndex, firstBookmark); + + //Update the bookmarks. + updateBoardBookmarks(); + } + } //-------------------------------------------BOOKMARKS END------------------------------------------ //-------PERMS--------- From b6637cf73401c409d56d930fca6e8f51adfe2820 Mon Sep 17 00:00:00 2001 From: babaliaris Date: Sat, 14 Nov 2020 13:31:11 +0200 Subject: [PATCH 4/7] Added rounded corners background --- app/src/main/res/drawable/bookmark_row_bg.xml | 7 ++++ .../res/layout/fragment_bookmarks_row.xml | 34 +++++++++++-------- 2 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 app/src/main/res/drawable/bookmark_row_bg.xml diff --git a/app/src/main/res/drawable/bookmark_row_bg.xml b/app/src/main/res/drawable/bookmark_row_bg.xml new file mode 100644 index 00000000..acac08e0 --- /dev/null +++ b/app/src/main/res/drawable/bookmark_row_bg.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_bookmarks_row.xml b/app/src/main/res/layout/fragment_bookmarks_row.xml index 07ca07b2..4ca5f8bc 100644 --- a/app/src/main/res/layout/fragment_bookmarks_row.xml +++ b/app/src/main/res/layout/fragment_bookmarks_row.xml @@ -12,47 +12,51 @@ android:id="@+id/bookmark_dragable" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="?android:attr/selectableItemBackground" + android:background="@drawable/bookmark_row_bg" android:clickable="true" android:focusable="true" android:gravity="center_vertical" - android:orientation="horizontal"> + android:orientation="horizontal" + android:layout_marginTop="24dp" + android:layout_marginStart="8dp" + android:layout_marginEnd="8dp" + > + android:textSize="18sp" /> + android:paddingStart="6dp" + android:paddingTop="3dp" + android:paddingEnd="6dp" + android:paddingBottom="3dp" + app:srcCompat="@drawable/ic_notification_on" /> + android:paddingStart="6dp" + android:paddingTop="3dp" + android:paddingEnd="6dp" + android:paddingBottom="3dp" + app:srcCompat="@drawable/ic_delete_accent_24dp" /> \ No newline at end of file From eb9b6483e92164b64a432869f332bf5eeb60a6e3 Mon Sep 17 00:00:00 2001 From: babaliaris Date: Sat, 14 Nov 2020 16:06:12 +0200 Subject: [PATCH 5/7] Fixed drag and dropping using indicators --- .../bookmarks/BookmarksActivity.java | 4 +- .../bookmarks/BookmarksAdapter.java | 40 ++++---- .../bookmarks/BookmarksFragment.java | 96 +++++++++++++++---- .../gr/thmmy/mthmmy/base/BaseActivity.java | 93 +++++------------- .../res/drawable/bookmark_row_dashed_bg.xml | 12 +++ 5 files changed, 142 insertions(+), 103 deletions(-) create mode 100644 app/src/main/res/drawable/bookmark_row_dashed_bg.xml diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksActivity.java index 6a281d92..e5654e4b 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksActivity.java @@ -78,9 +78,9 @@ public class BookmarksActivity extends BaseActivity { } - public void swapBookmarksAfterReorder(Bookmark first, Bookmark second) + public void updateBookmarks(ArrayList update_bookmarks) { - this.swapBookmarks(first, second); + this.updateBookmarksOnReorder(update_bookmarks); } private boolean onTopicInteractionListener(String interactionType, Bookmark bookmarkedTopic) { diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksAdapter.java index 30d7aaf9..5ab65ee7 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksAdapter.java @@ -24,14 +24,12 @@ import gr.thmmy.mthmmy.model.Bookmark; public class BookmarksAdapter extends DragItemAdapter, BookmarksAdapter.BookmarksViewHolder> { private final BookmarksFragment m_fragment; - private final ArrayList m_bookMarks; private final Drawable m_notificationsEnabled; private final Drawable m_notificationsDisabled; - public BookmarksAdapter(BookmarksFragment fragment, ArrayList bookmarks, Drawable noteEnabled, Drawable noteDisabled) + public BookmarksAdapter(BookmarksFragment fragment, Drawable noteEnabled, Drawable noteDisabled) { this.m_fragment = fragment; - this.m_bookMarks = bookmarks; this.m_notificationsEnabled = noteEnabled; this.m_notificationsDisabled = noteDisabled; } @@ -39,7 +37,7 @@ public class BookmarksAdapter extends DragItemAdapter, Bookm @Override public long getUniqueItemId(int position) { - return m_bookMarks.get(position).getId().hashCode(); + return m_fragment.bookmarks.get(position).getId().hashCode(); } @NonNull @@ -55,18 +53,26 @@ public class BookmarksAdapter extends DragItemAdapter, Bookm { super.onBindViewHolder(holder, position); + //If this is a drop indicator, use the dashed corner background. + if (m_fragment.bookmarks.get(position).getId().equals("-1")) + { + holder.itemView.findViewById(R.id.bookmark_dragable).setBackgroundResource(R.drawable.bookmark_row_dashed_bg); + holder.itemView.findViewById(R.id.toggle_notification).setVisibility(View.GONE); + holder.itemView.findViewById(R.id.remove_bookmark).setVisibility(View.GONE); + } + //Check if bookMarks ArrayList Exists and is not empty. - if(m_bookMarks != null && !m_bookMarks.isEmpty()) + if(m_fragment.bookmarks != null && !m_fragment.bookmarks.isEmpty()) { //Check if the current bookmark exists and has a title. - if (m_bookMarks.get(position) != null && m_bookMarks.get(position).getTitle() != null) + if (m_fragment.bookmarks.get(position) != null && m_fragment.bookmarks.get(position).getTitle() != null) { //Set the title. - holder.m_textView.setText(m_bookMarks.get(position).getTitle()); + holder.m_textView.setText(m_fragment.bookmarks.get(position).getTitle()); //Set Notifications Enabled Image Indicator. - if (m_bookMarks.get(position).isNotificationsEnabled()) + if (m_fragment.bookmarks.get(position).isNotificationsEnabled()) holder.m_noteView.setImageDrawable(m_notificationsEnabled); //Set Notifications Disabled Image Indicator. @@ -85,7 +91,7 @@ public class BookmarksAdapter extends DragItemAdapter, Bookm ((BookmarksActivity) activity).onFragmentRowInteractionListener( m_fragment.type, m_fragment.interactionClick, - m_bookMarks.get(position)); + m_fragment.bookmarks.get(position)); }); @@ -93,7 +99,7 @@ public class BookmarksAdapter extends DragItemAdapter, Bookm holder.m_noteView.setOnClickListener(v -> { //Toggle the current local instance. - m_bookMarks.get(position).toggleNotificationsEnabled(); + m_fragment.bookmarks.get(position).toggleNotificationsEnabled(); //Get the fragment activity. Activity activity = m_fragment.getActivity(); @@ -106,7 +112,7 @@ public class BookmarksAdapter extends DragItemAdapter, Bookm if (((BookmarksActivity) activity).onFragmentRowInteractionListener( m_fragment.type, m_fragment.interactionToggle, - m_bookMarks.get(position))) + m_fragment.bookmarks.get(position))) { holder.m_noteView.setImageDrawable(m_notificationsEnabled); } @@ -133,16 +139,16 @@ public class BookmarksAdapter extends DragItemAdapter, Bookm ((BookmarksActivity) activity).onFragmentRowInteractionListener( m_fragment.type, m_fragment.interactionRemove, - m_bookMarks.get(position)); + m_fragment.bookmarks.get(position)); { notifyItemRemoved(position); - notifyItemRangeChanged(position, m_bookMarks.size()); - m_bookMarks.remove(m_bookMarks.get(position)); + notifyItemRangeChanged(position, m_fragment.bookmarks.size()); + m_fragment.bookmarks.remove(m_fragment.bookmarks.get(position)); } } //If the bookmarks are empty then show nothing marked. - if (m_bookMarks.isEmpty()) + if (m_fragment.bookmarks.isEmpty()) { m_fragment.showNothingBookmarked(); } @@ -155,8 +161,8 @@ public class BookmarksAdapter extends DragItemAdapter, Bookm @Override public int getItemCount() { - if (m_bookMarks != null) - return m_bookMarks.size(); + if (m_fragment.bookmarks != null) + return m_fragment.bookmarks.size(); return 0; } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java index d3c801d4..673c1393 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java @@ -39,7 +39,7 @@ public class BookmarksFragment extends Fragment { private TextView nothingBookmarkedTextView; - private ArrayList bookmarks = null; + public ArrayList bookmarks = null; public Type type; public String interactionClick, interactionToggle, interactionRemove; @@ -107,13 +107,40 @@ public class BookmarksFragment extends Fragment { //Get the nothing bookmarked text view. nothingBookmarkedTextView = rootView.findViewById(R.id.nothing_bookmarked); + //Create the adapter. + BookmarksAdapter adapter = new BookmarksAdapter(this, notificationsEnabledButtonImage, notificationsDisabledButtonImage); + + //Get the drag list view. DragListView mDragListView = (DragListView) rootView.findViewById(R.id.fragment_bookmarks_dragList); + //Set the Drag List Listener. mDragListView.setDragListListener(new DragListView.DragListListener() { @Override public void onItemDragStarted(int position) { + //Create a new array of bookmarks. + ArrayList new_bookmarks = new ArrayList(); + + //For each bookmark in the current bookmarks array. + for (int i = 0; i < bookmarks.size(); i++) + { + //Create an indicator bookmark. + Bookmark indicator = new Bookmark("Drop Here", "-1", true); + + //Add the indicator followed by the current actual bookmark. + new_bookmarks.add(indicator); + new_bookmarks.add(bookmarks.get(i)); + } + + //Replace the bookmarks with the new bookmarks that contains the indicators. + bookmarks = new_bookmarks; + + //Add one last indicator. + bookmarks.add(new Bookmark("Drop Here", "-1", true)); + + //Notify the adapter that the bookmarks array has changed! + adapter.notifyDataSetChanged(); } @Override @@ -126,36 +153,71 @@ public class BookmarksFragment extends Fragment { public void onItemDragEnded(int fromPosition, int toPosition) { + //This is VERY IMPORTANT: Because I added indicator boxes + //in the onItemDragStarted, I need to recalculate the actual position + //of the started item (fromPosition) because it has changed!!! + int offset = fromPosition + 1; + int actualPos = fromPosition + offset; + //If the drag and drop is not the same item. - if (fromPosition != toPosition) + if (actualPos != toPosition) { //Get the from bookmark. - Bookmark from = bookmarks.get(fromPosition); + Bookmark from = bookmarks.get(actualPos); + Bookmark to = bookmarks.get(toPosition); - //Swap the from and to bookmarks. - bookmarks.set(fromPosition, bookmarks.get(toPosition)); - bookmarks.set(toPosition, from); + //You can only drop items in the indicator boxes!!! + //Indicator boxes are Bookmark objects with id "-1". + if (to.getId().equals("-1")) + { + //Swap the indicator with the actual. + bookmarks.set(actualPos, to); + bookmarks.set(toPosition, from); + + //Get the fragments activity. + Activity unknownActivity = getActivity(); + + //Update the order of the bookmarks in the preferences. + if (unknownActivity instanceof BookmarksActivity) + { + //Cast to BookmarksActivity. + BookmarksActivity activity = (BookmarksActivity)unknownActivity; + + //Update the preferences. + activity.updateBookmarks(bookmarks); + } + } - //Get the fragments activity. - Activity unknownActivity = getActivity(); + //------------------------Clean up the indicator boxes------------------------// + } - //Update the order of the bookmarks in the preferences. - if (unknownActivity instanceof BookmarksActivity) - { - //Cast to BookmarksActivity. - BookmarksActivity activity = (BookmarksActivity)unknownActivity; + //Find all the indicator boxes in the bookmarks array. + ArrayList books_to_delete = new ArrayList(); + for (int i = 0; i < bookmarks.size(); i++) + { + Bookmark book = bookmarks.get(i); - //Call the swapBookmarksAfterReorder to apply the swapping changes to the preferences. - activity.swapBookmarksAfterReorder( bookmarks.get(fromPosition), bookmarks.get(toPosition) ); - } + if (book.getId().equals("-1")) + books_to_delete.add(book); + } + + + //Remove all the indicators. + for (int i = 0; i < books_to_delete.size(); i++) + { + bookmarks.remove(books_to_delete.get(i)); } + + //------------------------Clean up the indicator boxes------------------------// + + //Notify the adapter, because I made changes to the bookmarks array. + adapter.notifyDataSetChanged(); } }); //====================================This is the code for the Drag and Drop Functionality====================================// mDragListView.setLayoutManager(new LinearLayoutManager(getActivity())); - BookmarksAdapter adapter = new BookmarksAdapter(this, bookmarks, notificationsEnabledButtonImage, notificationsDisabledButtonImage); mDragListView.setAdapter(adapter, false); mDragListView.setCanDragHorizontally(false); //====================================This is the code for the Drag and Drop Functionality====================================// diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java index 1c7d38c9..dbfdde58 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -692,84 +692,43 @@ public abstract class BaseActivity extends AppCompatActivity { } - //TODO: Abstract reusable code: find the index of the first and second bookmark. - protected void swapBookmarks(Bookmark first, Bookmark second) + /* + * This method should only be called after reordering the bookmarks. + * It Re-creates the topicsBookmarked and boardsBookmarked arrays + * with the reordered bookmarks. + * */ + protected void updateBookmarksOnReorder(ArrayList updated_bookmarks) { + //Define to empty arrays. + ArrayList newTopicBookmarks = new ArrayList(); + ArrayList newBoardBookmarks = new ArrayList(); - //No need to check is second is a topics bookmark. - //because there is no way to drag and drop between topic and board. - if ( first.matchExists(topicsBookmarked) ) + //For each bookmark in updated_bookmarks. + for (int i = 0; i < updated_bookmarks.size(); i++) { - //Find the index of the first and second bookmark. - int firstIndex = -1, secondIndex = -1; - for (int i = 0; i < topicsBookmarked.size(); i++) - { - - //Find the first index. - if (first.getId().equals(topicsBookmarked.get(i).getId())) - firstIndex = i; - - //Find the second index. - else if (second.getId().equals(topicsBookmarked.get(i).getId())) - secondIndex = i; - - //If both indexes found, stop. - if (firstIndex != -1 && secondIndex != -1) - break; - } - - //Assert, both indexes should have been found. - if (BuildConfig.DEBUG && !(firstIndex != -1 && secondIndex != -1)) { - throw new AssertionError("firstIndex and secondIndex must exist!"); - } + //Get the current updated bookamrk. + Bookmark book = updated_bookmarks.get(i); - //Temp store the first bookmark. - Bookmark firstBookmark = topicsBookmarked.get(firstIndex); + //Is it a topics bookmark? + if ( book.matchExists(topicsBookmarked) ) + newTopicBookmarks.add(book); - //Swap the bookmarks. - topicsBookmarked.set(firstIndex, topicsBookmarked.get(secondIndex)); - topicsBookmarked.set(secondIndex, firstBookmark); - //Update the bookmarks. - updateTopicBookmarks(); + //Is it a board bookmark? + else if ( book.matchExists(boardsBookmarked) ) + newBoardBookmarks.add(book); } - //Swap on Board Bookmarks. - else if ( first.matchExists(boardsBookmarked) ) - { - //Find the index of the first and second bookmark. - int firstIndex = -1, secondIndex = -1; - for (int i = 0; i < boardsBookmarked.size(); i++) - { - - //Find the first index. - if (first.getId().equals(boardsBookmarked.get(i).getId())) - firstIndex = i; - - - //Find the second index. - else if (second.getId().equals(boardsBookmarked.get(i).getId())) - secondIndex = i; - //If both indexes found, stop. - if (firstIndex != -1 && secondIndex != -1) - break; - } - - if (BuildConfig.DEBUG && !(firstIndex != -1 && secondIndex != -1)) { - throw new AssertionError("firstIndex and secondIndex must exist!"); - } - - //Temp store the first bookmark. - Bookmark firstBookmark = boardsBookmarked.get(firstIndex); + if (newTopicBookmarks.size() > 0) + topicsBookmarked = newTopicBookmarks; - //Swap the bookmarks. - boardsBookmarked.set(firstIndex, boardsBookmarked.get(secondIndex)); - boardsBookmarked.set(secondIndex, firstBookmark); + if (newBoardBookmarks.size() > 0) + boardsBookmarked = newBoardBookmarks; - //Update the bookmarks. - updateBoardBookmarks(); - } + //Update the bookmarks. + updateTopicBookmarks(); + updateBoardBookmarks(); } //-------------------------------------------BOOKMARKS END------------------------------------------ diff --git a/app/src/main/res/drawable/bookmark_row_dashed_bg.xml b/app/src/main/res/drawable/bookmark_row_dashed_bg.xml new file mode 100644 index 00000000..7eb0a45c --- /dev/null +++ b/app/src/main/res/drawable/bookmark_row_dashed_bg.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file From 5daec6aa320458408c3dbf4a4e603722d3c50c6b Mon Sep 17 00:00:00 2001 From: babaliaris Date: Sat, 14 Nov 2020 16:18:15 +0200 Subject: [PATCH 6/7] Added an ImageView to indicate this item is draggable --- app/src/main/assets/images/draggable_icon.png | Bin 0 -> 1519 bytes .../activities/bookmarks/BookmarksAdapter.java | 1 + .../main/res/drawable-hdpi/draggable_icon.png | Bin 0 -> 275 bytes .../main/res/drawable-mdpi/draggable_icon.png | Bin 0 -> 215 bytes .../main/res/drawable-xhdpi/draggable_icon.png | Bin 0 -> 395 bytes .../main/res/drawable-xxhdpi/draggable_icon.png | Bin 0 -> 537 bytes .../main/res/drawable-xxxhdpi/draggable_icon.png | Bin 0 -> 730 bytes .../main/res/layout/fragment_bookmarks_row.xml | 7 +++++++ 8 files changed, 8 insertions(+) create mode 100644 app/src/main/assets/images/draggable_icon.png create mode 100644 app/src/main/res/drawable-hdpi/draggable_icon.png create mode 100644 app/src/main/res/drawable-mdpi/draggable_icon.png create mode 100644 app/src/main/res/drawable-xhdpi/draggable_icon.png create mode 100644 app/src/main/res/drawable-xxhdpi/draggable_icon.png create mode 100644 app/src/main/res/drawable-xxxhdpi/draggable_icon.png diff --git a/app/src/main/assets/images/draggable_icon.png b/app/src/main/assets/images/draggable_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ef8638bd9fc6dc727eb5829f08a5f3b9f1b8e975 GIT binary patch literal 1519 zcmaJ>c~BE)6b}SQ!ZjKu5+Ep&HBqaQay3Fh1QIu*43`KLl*l213XwYs1(YKYz(lm= zs0sthVS#dpq5~ml5EZ2;9w;hCG+uy6p^c(_OaJk&?(FV2@BOZ~Gv9t9FV9T|x~94~ z9L|7;y8FO-4SR?>@cuoZ@gyu-@vb~SB3y@v;dxM#;?Tf&98S*&do*xm6;vEfTf%eS z=$BIQe$@NGBYP@m?2hN0Ss~bb=wpth|dTqT_#=9(=|4hd$P26 zQskR^RytWw{gpV_WmU>HtgDzZRdh^x^rFbKeKf9Rn(;&*AL+atN6VF{TI8Rev&bQy ze+SUGRX2#mSNX`uj+AwV^gqwb*9)kk^G3G{d(pPSK_;}OU7xbW?l*M9K(dx8#sD!3 z0Pj@(evr4g76LqeBnWiZiFQgBd8=_WM3phlEzXrhU1;_P5?@{haHn1j0B;!Y08l0H zn?QG#bWp)Zgh3A+A*okx2N`Jr7cfb(-hFW|I^!`m0?IGjS%8Q1fFfBNB1S2I*$(T? zcgw5}&yGvePdVZ0tnm^iOr5dkeY0g^oIwKP$=({_FS`2CY2ZjFPVto)Nq_+~{ za?CYJQxVhDnR~|edEtM#$lnq^?3rLC^f93vcgYg?bsRz(bjac`ipQpwT^2oT|JJ=o zgElm_d2m~NutrBP(x3$mV-HS?D>RZ?w;;oKlH!ks6_#~0lvOl(ytq0VfX1o>gaUxT zE`naS1b~LsCcGL52@bi4)`Nvx(`Js(@}r?NbzmtPNr1-O@x1UzkS6REBCVPvMde(n zX}=gGs<1O0YX_hTZ457Kv{|S@X%YS9>aA^9v_!MEEGD4QL`XXn# z^nS-w(#M}}A6HuCs@0ocp+ZbJpIBJE9Wrb^J5V7ug)&j};vG0eoxDR|Zvz=+lXuZu zx(GG*4STKB1{*`@DSGh`D7B4e>8T8$)KAu-OAUZ>??W6?jJdo`T`7GSKU6dHYfMK8ZgZGFC#MIP`~C(V_I zBBrq-lJ5^asO>Eu-~F*!lG^SS%SPfrFu!L0!KrcB$RDDvP~&5XW^y_;6Q>vr0Hec_C%_EM@@Q~S^6ZBFlFR91c09*vrDt6u4E zIA`j#tQvOU&64;c6QeVx+^XWzBv-&iISir@0oPh`MqM&5OB+MWz(sqqQ};2O`FwX9zPhB*EVO?9-9J*zRL*SZhY4 z_ESoV@X-WKZcFR5z-1mxlG@y9&6tT}Aj2>KOr+*(D1>tq;9fsbfWN1wB@X9!C^TYp zKqQS&W+dV@=z%>$0@(-z_?oU=h|Nk3g zF32cF-5rpSTl2jtyR@E36$w;cEV6R2G89o%y7i!9w_JHUeGfG^eR;5rG)JKNP2O$^ zrSr;QI#zDvPok!ZN@lhbM)D-j=2!D+4uKCau=ZGU5@MkA+RY!pI2+|b5?is`;cPq1 zfI(WYW$4*q!hGU_Yd&cK%h!!xXzImd%q5Ez+##0XT83Bz-a&pUGhQ#d?ZO}vBBG4O z9%J4EM;55|l#>O(83|5VgAHdX@52n%F)mwSWtCh2;|yNS{)Ek;`2=%)%^b56=Lk?Z hQ;vRnk|O(F?%dgDTmCqJJP0Q?j>qwIZ*&dK`WLeUgZlsg literal 0 HcmV?d00001 diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksAdapter.java index 5ab65ee7..4fb82c25 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksAdapter.java @@ -57,6 +57,7 @@ public class BookmarksAdapter extends DragItemAdapter, Bookm if (m_fragment.bookmarks.get(position).getId().equals("-1")) { holder.itemView.findViewById(R.id.bookmark_dragable).setBackgroundResource(R.drawable.bookmark_row_dashed_bg); + holder.itemView.findViewById(R.id.bookmark_drag_icon).setVisibility(View.GONE); holder.itemView.findViewById(R.id.toggle_notification).setVisibility(View.GONE); holder.itemView.findViewById(R.id.remove_bookmark).setVisibility(View.GONE); } diff --git a/app/src/main/res/drawable-hdpi/draggable_icon.png b/app/src/main/res/drawable-hdpi/draggable_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..d30285ec1e08038e3ce97a8762990b99a0b89be6 GIT binary patch literal 275 zcmV+u0qp*XP)rnZe6Ft2^`f8tXL9vT9B(&IB-CDo&9LDVPxIG^c3v(KO{`4|nRHGpbH`!0uhe z5Y(qvWg0-gEaw94p1!5DrGR!tLKu2dK%2ue4n1KYUU;TTn?90M-!>~C*Oz;r9SMxk zlTtoBxuGYetW$76a8m~PQ$v}1CrJ1>)c#D-6j(O* zp>|pxQ*u`HqJ1^%ru^D8bM}>KXRVkIDVTZmROz`J$y^oUs%7F9D>?jdT7dD6E7Q*T zG)wcP1ivW?(p9*nz9B*JCR0)qx8>FeS&Rp-v`&n2U{gxG`qVi6(31l>CY5_ub_ZlB ziYBv&pVeJZDR5DB(#uIcFDG4m5fpM^>xRXdg}&3d+Vw)!Vzp|E7#Viyb-q|DB_9QJ ODTAl0pUXO@geCyNO;LOR literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/draggable_icon.png b/app/src/main/res/drawable-xhdpi/draggable_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..bd8c3a1d7bf5161ce78d9ab8917ae9c378a6b5c7 GIT binary patch literal 395 zcmV;60d)R}P)R;3oUU#4P{G18m_z>> zz)ip*)!qc6mD9K8V-tvTCM30qP9V5CDQXj)Ku~qk*n>?71hE|}-ex-jJ|qm@20)nN z(iLa1uGiRy9_DQ8{k@aL+rUnmVgkQnr^TFoy^nYD@iwu;s!k!i%@!n9GeMpJ`4VDr zh*`)eix(LSE5X9dv9QxDK4@5cQtr1B*a)z=*dl$k$l`LB#q~Oi1_z54lS!S(H2HMu pM6S)MW`bm+TlO_%!SBOud;s^96Aw?*S6~1D002ovPDHLkV1l$+s-FM= literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/draggable_icon.png b/app/src/main/res/drawable-xxhdpi/draggable_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..f5ee0e30bc284cfe3becfe85d1f59e9f14821591 GIT binary patch literal 537 zcmV+!0_OdRP)&! zBg5(#PM7jqt~KeQe!pGsitk=H|0!*xZGJVUD)%lpR_?Q@Nphp>s{9xM=dUL<|4AN_ z43&{R=cFekJKUt$`qUhsnv`7OK8V08;n+{NWF)|e2n>}eh{;|N7!cB8dy-QG1{`k5 zib=CAUYr1$Hu=7400=+;@-4{P0I4b5od{G1NQ0QPMW8xBbBoDi5vUT-Tw?N^2viFw zwwUa50#yTwWP+MLjCMR`c(6Oaf+UNv}G zjkb&iy92`v%N5gJgK5vS4-Juf0y-2or~0Vt-JWD#d1<00000NkvXXu0mjfzU1#Y literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxxhdpi/draggable_icon.png b/app/src/main/res/drawable-xxxhdpi/draggable_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..3fe3ba1dfe181cadda381fbfe2e3f0812b8c482c GIT binary patch literal 730 zcmV<00ww*4P)F6n&=1U3r3<+H)f0lm~$zOj( z@fi|2O#bC`{Qi^tO~`kU&~?k-4|+n&1^4@zzb=U-g}Fi84Tq=MWF*O7RY?9eR&tG8 zO9pG;W5Onr$TiPfvh^dJFV9Q3Udjr zpGW6cFZo;5q{?sQ8Zrj~5C9+m0(w2p_fCM@(b0CO>74+VL)72ej(Y;UX-E4r+yn^l zGh_Zw+ev}|58BZoZ6_51O!tIi+D=jgSk#Wnd^-seV8?e<#kZ3v0s6k9s@9Q&3DC2= zg!pz6C!l*0LVY_uAfP+nQH*a#5>YpbG5BpZ$rqJZxr*P)HBH>xjPEGcw=UIE-6u#>@;?Pdh@}(d-Gdd{ylTZAY~*Q*d=jAo&0Q004->C$iq!0EtdzjsO4v M07*qoM6N<$f+4g_SO5S3 literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout/fragment_bookmarks_row.xml b/app/src/main/res/layout/fragment_bookmarks_row.xml index 4ca5f8bc..f128d068 100644 --- a/app/src/main/res/layout/fragment_bookmarks_row.xml +++ b/app/src/main/res/layout/fragment_bookmarks_row.xml @@ -22,6 +22,13 @@ android:layout_marginEnd="8dp" > + + Date: Sat, 14 Nov 2020 17:32:30 +0200 Subject: [PATCH 7/7] Fixed unessesary drop inrdicators --- .../bookmarks/BookmarksFragment.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java index 673c1393..086fde5f 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksFragment.java @@ -129,16 +129,19 @@ public class BookmarksFragment extends Fragment { Bookmark indicator = new Bookmark("Drop Here", "-1", true); //Add the indicator followed by the current actual bookmark. - new_bookmarks.add(indicator); + if (position != i-1 && position != i) + new_bookmarks.add(indicator); + new_bookmarks.add(bookmarks.get(i)); } + //Add one last indicator. + if (position != bookmarks.size() - 1) + new_bookmarks.add(new Bookmark("Drop Here", "-1", true)); + //Replace the bookmarks with the new bookmarks that contains the indicators. bookmarks = new_bookmarks; - //Add one last indicator. - bookmarks.add(new Bookmark("Drop Here", "-1", true)); - //Notify the adapter that the bookmarks array has changed! adapter.notifyDataSetChanged(); } @@ -152,12 +155,12 @@ public class BookmarksFragment extends Fragment { @Override public void onItemDragEnded(int fromPosition, int toPosition) { + //It's hard to explain what this does. + int actualPos = fromPosition; - //This is VERY IMPORTANT: Because I added indicator boxes - //in the onItemDragStarted, I need to recalculate the actual position - //of the started item (fromPosition) because it has changed!!! - int offset = fromPosition + 1; - int actualPos = fromPosition + offset; + //It's hard to explain what this does. + if (fromPosition != 0) + actualPos = 2 * fromPosition; //If the drag and drop is not the same item. if (actualPos != toPosition)