mirror of https://github.com/ThmmyNoLife/mTHMMY
committed by
GitHub
16 changed files with 488 additions and 116 deletions
After Width: | Height: | Size: 1.5 KiB |
@ -0,0 +1,189 @@ |
|||
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<ArrayList<Bookmark>, BookmarksAdapter.BookmarksViewHolder> |
|||
{ |
|||
private final BookmarksFragment m_fragment; |
|||
private final Drawable m_notificationsEnabled; |
|||
private final Drawable m_notificationsDisabled; |
|||
|
|||
public BookmarksAdapter(BookmarksFragment fragment, Drawable noteEnabled, Drawable noteDisabled) |
|||
{ |
|||
this.m_fragment = fragment; |
|||
this.m_notificationsEnabled = noteEnabled; |
|||
this.m_notificationsDisabled = noteDisabled; |
|||
} |
|||
|
|||
@Override |
|||
public long getUniqueItemId(int position) |
|||
{ |
|||
return m_fragment.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); |
|||
|
|||
//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.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); |
|||
} |
|||
|
|||
//Check if bookMarks ArrayList Exists and is not empty.
|
|||
if(m_fragment.bookmarks != null && !m_fragment.bookmarks.isEmpty()) |
|||
{ |
|||
//Check if the current bookmark exists and has a title.
|
|||
if (m_fragment.bookmarks.get(position) != null && m_fragment.bookmarks.get(position).getTitle() != null) |
|||
{ |
|||
|
|||
//Set the title.
|
|||
holder.m_textView.setText(m_fragment.bookmarks.get(position).getTitle()); |
|||
|
|||
//Set Notifications Enabled Image Indicator.
|
|||
if (m_fragment.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_fragment.bookmarks.get(position)); |
|||
}); |
|||
|
|||
|
|||
//On Notifications Toggle.
|
|||
holder.m_noteView.setOnClickListener(v -> { |
|||
|
|||
//Toggle the current local instance.
|
|||
m_fragment.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_fragment.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.
|
|||
//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.
|
|||
Activity activity = m_fragment.getActivity(); |
|||
|
|||
if (activity instanceof BookmarksActivity) |
|||
{ |
|||
|
|||
//Trigger the bookmark remove functionality.
|
|||
((BookmarksActivity) activity).onFragmentRowInteractionListener( |
|||
m_fragment.type, |
|||
m_fragment.interactionRemove, |
|||
m_fragment.bookmarks.get(position)); |
|||
{ |
|||
notifyItemRemoved(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_fragment.bookmarks.isEmpty()) |
|||
{ |
|||
m_fragment.showNothingBookmarked(); |
|||
} |
|||
|
|||
}); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public int getItemCount() |
|||
{ |
|||
if (m_fragment.bookmarks != null) |
|||
return m_fragment.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; |
|||
} |
|||
} |
|||
} |
After Width: | Height: | Size: 275 B |
After Width: | Height: | Size: 215 B |
After Width: | Height: | Size: 395 B |
After Width: | Height: | Size: 537 B |
After Width: | Height: | Size: 730 B |
@ -0,0 +1,7 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> |
|||
<solid android:color="@color/background"/> |
|||
<stroke android:width="2dp" android:color="#B1BCBE" /> |
|||
<corners android:radius="10dp"/> |
|||
<padding android:left="8dp" android:top="8dp" android:right="8dp" android:bottom="8dp" /> |
|||
</shape> |
@ -0,0 +1,12 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> |
|||
<solid android:color="@color/background"/> |
|||
<stroke |
|||
android:width="2dp" |
|||
android:color="#B1BCBE" |
|||
android:dashWidth="10px" |
|||
android:dashGap="10px" |
|||
/> |
|||
<corners android:radius="10dp"/> |
|||
<padding android:left="8dp" android:top="8dp" android:right="8dp" android:bottom="8dp" /> |
|||
</shape> |
@ -1,36 +1,36 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|||
|
|||
<androidx.constraintlayout.widget.ConstraintLayout |
|||
xmlns:android="http://schemas.android.com/apk/res/android" |
|||
xmlns:app="http://schemas.android.com/apk/res-auto" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="match_parent"> |
|||
android:layout_height="match_parent" |
|||
android:orientation="vertical" |
|||
> |
|||
|
|||
<com.woxthebox.draglistview.DragListView |
|||
android:id="@+id/fragment_bookmarks_dragList" |
|||
android:layout_width="0dp" |
|||
android:layout_height="0dp" |
|||
app:layout_constraintBottom_toBottomOf="parent" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintStart_toStartOf="parent" |
|||
app:layout_constraintTop_toTopOf="parent" /> |
|||
|
|||
<androidx.core.widget.NestedScrollView |
|||
android:id="@+id/bookmarks_nested_scroll" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="match_parent" |
|||
android:layout_gravity="top|start" |
|||
android:background="@color/primary_lighter" |
|||
android:scrollbars="none" |
|||
app:layout_behavior="@string/appbar_scrolling_view_behavior"> |
|||
|
|||
<LinearLayout |
|||
android:id="@+id/bookmarks_container" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="match_parent" |
|||
android:orientation="vertical" |
|||
android:showDividers="middle" |
|||
android:divider="?android:listDivider" |
|||
android:dividerPadding="16dp" /> |
|||
</androidx.core.widget.NestedScrollView> |
|||
|
|||
<TextView |
|||
android:id="@+id/nothing_bookmarked" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" |
|||
android:layout_gravity="center" |
|||
android:visibility="invisible" |
|||
android:textIsSelectable="false" |
|||
android:text="@string/nothing_bookmarked_here" |
|||
android:textColor="@color/accent" |
|||
android:textSize="@dimen/medium_text" /> |
|||
</FrameLayout> |
|||
|
|||
android:textIsSelectable="false" |
|||
android:textSize="@dimen/medium_text" |
|||
android:visibility="invisible" |
|||
app:layout_constraintBottom_toBottomOf="parent" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintStart_toStartOf="parent" |
|||
app:layout_constraintTop_toTopOf="parent" /> |
|||
</androidx.constraintlayout.widget.ConstraintLayout> |
@ -1,49 +1,72 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|||
|
|||
|
|||
<FrameLayout |
|||
xmlns:android="http://schemas.android.com/apk/res/android" |
|||
|
|||
xmlns:app="http://schemas.android.com/apk/res-auto" |
|||
android:id="@+id/bookmark_row" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="wrap_content" |
|||
android:background="?android:attr/selectableItemBackground" |
|||
android:clickable="true" |
|||
android:focusable="true" |
|||
android:gravity="center_vertical" |
|||
android:orientation="horizontal"> |
|||
|
|||
<TextView |
|||
android:id="@+id/bookmark_title" |
|||
android:layout_width="0dp" |
|||
> |
|||
|
|||
<LinearLayout |
|||
android:id="@+id/bookmark_dragable" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="wrap_content" |
|||
android:layout_weight="1" |
|||
android:paddingBottom="8dp" |
|||
android:paddingTop="6dp" |
|||
android:paddingStart="16dp" |
|||
android:paddingEnd="0dp" |
|||
android:textColor="@color/primary_text" |
|||
android:textSize="18sp" /> |
|||
|
|||
<ImageButton |
|||
android:id="@+id/toggle_notification" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="match_parent" |
|||
android:paddingBottom="3dp" |
|||
android:paddingTop="3dp" |
|||
android:paddingStart="6dp" |
|||
android:paddingEnd="6dp" |
|||
android:background="@android:color/transparent" |
|||
android:contentDescription="@string/toggle_notification" |
|||
app:srcCompat="@drawable/ic_notification_on" /> |
|||
|
|||
<ImageButton |
|||
android:id="@+id/remove_bookmark" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="match_parent" |
|||
android:paddingBottom="3dp" |
|||
android:paddingTop="3dp" |
|||
android:paddingStart="6dp" |
|||
android:paddingEnd="6dp" |
|||
android:layout_marginEnd="12dp" |
|||
android:background="@android:color/transparent" |
|||
android:contentDescription="@string/remove_bookmark" |
|||
app:srcCompat="@drawable/ic_delete_accent_24dp" /> |
|||
</LinearLayout> |
|||
|
|||
android:background="@drawable/bookmark_row_bg" |
|||
android:clickable="true" |
|||
android:focusable="true" |
|||
android:gravity="center_vertical" |
|||
android:orientation="horizontal" |
|||
android:layout_marginTop="24dp" |
|||
android:layout_marginStart="8dp" |
|||
android:layout_marginEnd="8dp" |
|||
> |
|||
|
|||
<ImageView |
|||
android:id="@+id/bookmark_drag_icon" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="match_parent" |
|||
app:srcCompat="@drawable/draggable_icon" |
|||
/> |
|||
|
|||
<TextView |
|||
android:id="@+id/bookmark_title" |
|||
android:layout_width="0dp" |
|||
android:layout_height="wrap_content" |
|||
android:layout_weight="1" |
|||
android:paddingStart="16dp" |
|||
android:paddingTop="6dp" |
|||
android:paddingEnd="0dp" |
|||
android:paddingBottom="8dp" |
|||
android:textColor="@color/primary_text" |
|||
android:textSize="18sp" /> |
|||
|
|||
<ImageButton |
|||
android:id="@+id/toggle_notification" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="match_parent" |
|||
android:background="@android:color/transparent" |
|||
android:contentDescription="@string/toggle_notification" |
|||
android:paddingStart="6dp" |
|||
android:paddingTop="3dp" |
|||
android:paddingEnd="6dp" |
|||
android:paddingBottom="3dp" |
|||
app:srcCompat="@drawable/ic_notification_on" /> |
|||
|
|||
<ImageButton |
|||
android:id="@+id/remove_bookmark" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="match_parent" |
|||
android:layout_marginEnd="12dp" |
|||
android:background="@android:color/transparent" |
|||
android:contentDescription="@string/remove_bookmark" |
|||
android:paddingStart="6dp" |
|||
android:paddingTop="3dp" |
|||
android:paddingEnd="6dp" |
|||
android:paddingBottom="3dp" |
|||
app:srcCompat="@drawable/ic_delete_accent_24dp" /> |
|||
</LinearLayout> |
|||
</FrameLayout> |
Loading…
Reference in new issue