Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,60 @@ private void showAddItemDialog(final Context c) {
.show();
}

private void showInstanceDialog(final PeertubeInstance instance, final int position) {
final boolean isSelected = instance.getUrl().equals(selectedInstance.getUrl());
final int itemCount = instanceListAdapter.getCurrentList().size();

final ArrayList<String> options = new ArrayList<>();
if (position > 0) {
options.add(getString(R.string.move_up));
}
if (position < itemCount - 1) {
options.add(getString(R.string.move_down));
}
if (!isSelected) {
options.add(getString(R.string.delete));
}

if (options.isEmpty()) {
return;
}

new AlertDialog.Builder(requireContext())
.setTitle(instance.getName())
.setItems(options.toArray(new String[0]), (dialog, which) -> {
final String selected = options.get(which);
if (selected.equals(getString(R.string.move_up))) {
instanceListAdapter.swapItems(position, position - 1);
} else if (selected.equals(getString(R.string.move_down))) {
instanceListAdapter.swapItems(position, position + 1);
} else if (selected.equals(getString(R.string.delete))) {
showDeleteInstanceDialog(instance, position);
}
})
.setCancelable(true)
.setNegativeButton(R.string.cancel, null)
.show();
}

private void showDeleteInstanceDialog(final PeertubeInstance instance, final int position) {
new AlertDialog.Builder(requireContext())
.setTitle(instance.getName())
.setCancelable(true)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.delete, (dialog, which) -> {
final var list = new ArrayList<>(instanceListAdapter.getCurrentList());
list.remove(position);

if (list.isEmpty()) {
list.add(selectedInstance);
}

instanceListAdapter.submitList(list);
})
.show();
}

private void addInstance(final String url) {
final String cleanUrl = cleanUrl(url);
if (cleanUrl == null) {
Expand Down Expand Up @@ -357,6 +411,16 @@ class TabViewHolder extends RecyclerView.ViewHolder {
TabViewHolder(final ItemInstanceBinding binding) {
super(binding.getRoot());
this.itemBinding = binding;

itemView.setOnLongClickListener(this::onInstanceLongClick);
}

private boolean onInstanceLongClick(final View view) {
final int position = getBindingAdapterPosition();
if (position != RecyclerView.NO_POSITION) {
showInstanceDialog(getItem(position), position);
}
return true;
}

@SuppressLint("ClickableViewAccessibility")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,51 @@ private void restoreDefaults() {
.show();
}

private void showTabDialog(final int position, final String tabName) {
final int itemCount = tabList.size();
final ArrayList<String> options = new ArrayList<>();
if (position > 0) {
options.add(getString(R.string.move_up));
}
if (position < itemCount - 1) {
options.add(getString(R.string.move_down));
}
options.add(getString(R.string.delete));

new AlertDialog.Builder(requireContext())
.setTitle(tabName)
.setItems(options.toArray(new String[0]), (dialog, which) -> {
final String selected = options.get(which);
if (selected.equals(getString(R.string.move_up))) {
selectedTabsAdapter.swapItems(position, position - 1);
} else if (selected.equals(getString(R.string.move_down))) {
selectedTabsAdapter.swapItems(position, position + 1);
} else if (selected.equals(getString(R.string.delete))) {
showDeleteTabDialog(position, tabName);
}
})
.setCancelable(true)
.setNegativeButton(R.string.cancel, null)
.show();
}

private void showDeleteTabDialog(final int position, final String tabName) {
new AlertDialog.Builder(requireContext())
.setTitle(tabName)
.setCancelable(true)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.delete, (dialog, which) -> {
tabList.remove(position);
selectedTabsAdapter.notifyItemRemoved(position);

if (tabList.isEmpty()) {
tabList.add(Tab.Type.BLANK.getTab());
selectedTabsAdapter.notifyItemInserted(0);
}
})
.show();
}

private void initButton(final View rootView) {
final FloatingActionButton fab = rootView.findViewById(R.id.addTabsButton);
fab.setOnClickListener(v -> {
Expand Down Expand Up @@ -375,6 +420,16 @@ class TabViewHolder extends RecyclerView.ViewHolder {
tabNameView = itemView.findViewById(R.id.tabName);
tabIconView = itemView.findViewById(R.id.tabIcon);
handle = itemView.findViewById(R.id.handle);

itemView.setOnLongClickListener(this::onTabLongClick);
}

private boolean onTabLongClick(final View view) {
final int position = getBindingAdapterPosition();
if (position != RecyclerView.NO_POSITION) {
showTabDialog(position, tabNameView.getText().toString());
}
return true;
}

@SuppressLint("ClickableViewAccessibility")
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@
<string name="peertube_instance_add_fail">Could not validate instance</string>
<string name="peertube_instance_add_https_only">Only HTTPS URLs are supported</string>
<string name="peertube_instance_add_exists">Instance already exists</string>
<string name="move_up">Move up</string>
<string name="move_down">Move down</string>
<string name="settings_category_player_title">Player</string>
<string name="settings_category_player_behavior_title">Behavior</string>
<string name="settings_category_video_audio_title">Video and audio</string>
Expand Down Expand Up @@ -404,7 +406,7 @@
<!-- Content -->
<string name="main_page_content">Content of main page</string>
<string name="main_page_content_summary">What tabs are shown on the main page</string>
<string name="main_page_content_swipe_remove">Swipe items to remove them</string>
<string name="main_page_content_swipe_remove">Swipe items to remove them, long press for menu</string>
<string name="blank_page_summary">Blank page</string>
<string name="kiosk_page_summary">Kiosk page</string>
<string name="default_kiosk_page_summary">Default Kiosk</string>
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ teamnewpipe-nanojson = "e9d656ddb49a412a5a0a5d5ef20ca7ef09549996"
# the corresponding commit hash, since JitPack sometimes deletes artifacts.
# If there’s already a git hash, just add more of it to the end (or remove a letter)
# to cause jitpack to regenerate the artifact.
teamnewpipe-newpipe-extractor = "1512cf3222b0c5d87a249e6ac231b98090c42623"
teamnewpipe-newpipe-extractor = "v0.26.2"
webkit = "1.15.0"
work = "2.11.2"

Expand Down
Loading