Skip to content

Commit 03167a1

Browse files
Merge pull request #11234 from TeamNewPipe/dev
Merge dev to refactor
2 parents d479f29 + 1f30985 commit 03167a1

8 files changed

Lines changed: 96 additions & 112 deletions

File tree

.github/CONTRIBUTING.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ You'll see *exactly* what is sent, be able to add **your comments**, and then se
4242
* Create PRs that cover only **one specific issue/solution/bug**. Do not create PRs that are huge monoliths and could have been split into multiple independent contributions.
4343
* NewPipe uses [NewPipeExtractor](https://github.com/TeamNewPipe/NewPipeExtractor) to fetch data from services. If you need to change something there, you must test your changes in NewPipe. Telling NewPipe to use your extractor version can be accomplished by editing the `app/build.gradle` file: the comments under the "NewPipe libraries" section of `dependencies` will help you out.
4444

45-
### Kotlin in NewPipe
46-
* NewPipe will remain mostly Java for time being
47-
* Contributions containing a simple conversion from Java to Kotlin should be avoided. Conversions to Kotlin should only be done if Kotlin actually brings improvements like bug fixes or better performance which are not, or only with much more effort, implementable in Java. The core team sees Java as an easier to learn and generally well adopted programming language.
48-
4945
### Creating a Pull Request (PR)
5046

5147
* Make changes on a **separate branch** with a meaningful name, not on the _master_ branch or the _dev_ branch. This is commonly known as *feature branch workflow*. You may then send your changes as a pull request (PR) on GitHub.

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
branches:
77
- dev
88
- master
9+
- refactor
910
- release**
1011
paths-ignore:
1112
- 'README.md'

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ dependencies {
287287
implementation "com.jakewharton.rxbinding4:rxbinding:4.0.0"
288288

289289
// Date and time formatting
290-
implementation "org.ocpsoft.prettytime:prettytime:5.0.7.Final"
290+
implementation "org.ocpsoft.prettytime:prettytime:5.0.8.Final"
291291

292292
// Jetpack Compose
293293
implementation(platform('androidx.compose:compose-bom:2024.02.01'))

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@
367367
<data android:host="tilvids.com" />
368368
<data android:host="video.lqdn.fr" />
369369
<data android:host="video.ploud.fr" />
370+
<data android:host="subscribeto.me" />
370371

371372
<data android:pathPrefix="/videos/" /> <!-- it contains playlists -->
372373
<data android:pathPrefix="/w/" /> <!-- short video URLs -->

app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java

Lines changed: 68 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import androidx.annotation.Nullable;
2323
import androidx.core.content.ContextCompat;
2424
import androidx.core.graphics.ColorUtils;
25+
import androidx.core.view.MenuProvider;
2526
import androidx.preference.PreferenceManager;
2627

2728
import com.google.android.material.snackbar.Snackbar;
@@ -99,6 +100,7 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo>
99100
private MenuItem menuRssButton;
100101
private MenuItem menuNotifyButton;
101102
private SubscriptionEntity channelSubscription;
103+
private MenuProvider menuProvider;
102104

103105
public static ChannelFragment getInstance(final int serviceId, final String url,
104106
final String name) {
@@ -121,7 +123,62 @@ private void setInitialData(final int sid, final String u, final String title) {
121123
@Override
122124
public void onCreate(final Bundle savedInstanceState) {
123125
super.onCreate(savedInstanceState);
124-
setHasOptionsMenu(true);
126+
menuProvider = new MenuProvider() {
127+
@Override
128+
public void onCreateMenu(@NonNull final Menu menu,
129+
@NonNull final MenuInflater inflater) {
130+
inflater.inflate(R.menu.menu_channel, menu);
131+
132+
if (DEBUG) {
133+
Log.d(TAG, "onCreateOptionsMenu() called with: "
134+
+ "menu = [" + menu + "], inflater = [" + inflater + "]");
135+
}
136+
137+
}
138+
139+
@Override
140+
public void onPrepareMenu(@NonNull final Menu menu) {
141+
menuRssButton = menu.findItem(R.id.menu_item_rss);
142+
menuNotifyButton = menu.findItem(R.id.menu_item_notify);
143+
updateRssButton();
144+
updateNotifyButton(channelSubscription);
145+
}
146+
147+
@Override
148+
public boolean onMenuItemSelected(@NonNull final MenuItem item) {
149+
switch (item.getItemId()) {
150+
case R.id.menu_item_notify:
151+
final boolean value = !item.isChecked();
152+
item.setEnabled(false);
153+
setNotify(value);
154+
break;
155+
case R.id.action_settings:
156+
NavigationHelper.openSettings(requireContext());
157+
break;
158+
case R.id.menu_item_rss:
159+
if (currentInfo != null) {
160+
ShareUtils.openUrlInApp(requireContext(), currentInfo.getFeedUrl());
161+
}
162+
break;
163+
case R.id.menu_item_openInBrowser:
164+
if (currentInfo != null) {
165+
ShareUtils.openUrlInBrowser(requireContext(),
166+
currentInfo.getOriginalUrl());
167+
}
168+
break;
169+
case R.id.menu_item_share:
170+
if (currentInfo != null) {
171+
ShareUtils.shareText(requireContext(), name,
172+
currentInfo.getOriginalUrl(), currentInfo.getAvatars());
173+
}
174+
break;
175+
default:
176+
return false;
177+
}
178+
return true;
179+
}
180+
};
181+
activity.addMenuProvider(menuProvider);
125182
}
126183

127184
@Override
@@ -183,67 +240,10 @@ public void onDestroy() {
183240
}
184241
disposables.clear();
185242
binding = null;
243+
activity.removeMenuProvider(menuProvider);
244+
menuProvider = null;
186245
}
187246

188-
189-
/*//////////////////////////////////////////////////////////////////////////
190-
// Menu
191-
//////////////////////////////////////////////////////////////////////////*/
192-
193-
@Override
194-
public void onCreateOptionsMenu(@NonNull final Menu menu,
195-
@NonNull final MenuInflater inflater) {
196-
super.onCreateOptionsMenu(menu, inflater);
197-
inflater.inflate(R.menu.menu_channel, menu);
198-
199-
if (DEBUG) {
200-
Log.d(TAG, "onCreateOptionsMenu() called with: "
201-
+ "menu = [" + menu + "], inflater = [" + inflater + "]");
202-
}
203-
}
204-
205-
@Override
206-
public void onPrepareOptionsMenu(@NonNull final Menu menu) {
207-
super.onPrepareOptionsMenu(menu);
208-
menuRssButton = menu.findItem(R.id.menu_item_rss);
209-
menuNotifyButton = menu.findItem(R.id.menu_item_notify);
210-
updateNotifyButton(channelSubscription);
211-
}
212-
213-
@Override
214-
public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
215-
switch (item.getItemId()) {
216-
case R.id.menu_item_notify:
217-
final boolean value = !item.isChecked();
218-
item.setEnabled(false);
219-
setNotify(value);
220-
break;
221-
case R.id.action_settings:
222-
NavigationHelper.openSettings(requireContext());
223-
break;
224-
case R.id.menu_item_rss:
225-
if (currentInfo != null) {
226-
ShareUtils.openUrlInApp(requireContext(), currentInfo.getFeedUrl());
227-
}
228-
break;
229-
case R.id.menu_item_openInBrowser:
230-
if (currentInfo != null) {
231-
ShareUtils.openUrlInBrowser(requireContext(), currentInfo.getOriginalUrl());
232-
}
233-
break;
234-
case R.id.menu_item_share:
235-
if (currentInfo != null) {
236-
ShareUtils.shareText(requireContext(), name, currentInfo.getOriginalUrl(),
237-
currentInfo.getAvatars());
238-
}
239-
break;
240-
default:
241-
return super.onOptionsItemSelected(item);
242-
}
243-
return true;
244-
}
245-
246-
247247
/*//////////////////////////////////////////////////////////////////////////
248248
// Channel Subscription
249249
//////////////////////////////////////////////////////////////////////////*/
@@ -408,6 +408,13 @@ private void updateSubscribeButton(final boolean isSubscribed) {
408408
animate(binding.channelSubscribeButton, true, 100, AnimationType.LIGHT_SCALE_AND_ALPHA);
409409
}
410410

411+
private void updateRssButton() {
412+
if (menuRssButton == null || currentInfo == null) {
413+
return;
414+
}
415+
menuRssButton.setVisible(!TextUtils.isEmpty(currentInfo.getFeedUrl()));
416+
}
417+
411418
private void updateNotifyButton(@Nullable final SubscriptionEntity subscription) {
412419
if (menuNotifyButton == null) {
413420
return;
@@ -610,9 +617,7 @@ public void handleResult(@NonNull final ChannelInfo result) {
610617
binding.subChannelAvatarView.setVisibility(View.VISIBLE);
611618
}
612619

613-
if (menuRssButton != null) {
614-
menuRssButton.setVisible(!TextUtils.isEmpty(result.getFeedUrl()));
615-
}
620+
updateRssButton();
616621

617622
channelContentNotSupported = false;
618623
for (final Throwable throwable : result.getErrors()) {

app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ public void handleResult(@NonNull final PlaylistInfo result) {
352352
});
353353
ellipsizer.setContent(description);
354354
headerBinding.playlistDescriptionReadMore.setOnClickListener(v -> ellipsizer.toggle());
355+
headerBinding.playlistDescription.setOnClickListener(v -> ellipsizer.toggle());
355356
} else {
356357
headerBinding.playlistDescription.setVisibility(View.GONE);
357358
headerBinding.playlistDescriptionReadMore.setVisibility(View.GONE);

app/src/main/java/org/schabi/newpipe/info_list/holder/CommentInfoItemHolder.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package org.schabi.newpipe.info_list.holder;
22

33
import static org.schabi.newpipe.util.ServiceHelper.getServiceById;
4+
import static org.schabi.newpipe.util.text.TouchUtils.getOffsetForHorizontalLine;
45

6+
import android.text.Spanned;
57
import android.text.method.LinkMovementMethod;
8+
import android.text.style.ClickableSpan;
69
import android.text.style.URLSpan;
10+
import android.view.MotionEvent;
711
import android.view.View;
812
import android.view.ViewGroup;
913
import android.widget.Button;
@@ -25,7 +29,6 @@
2529
import org.schabi.newpipe.util.external_communication.ShareUtils;
2630
import org.schabi.newpipe.util.image.ImageStrategy;
2731
import org.schabi.newpipe.util.image.PicassoHelper;
28-
import org.schabi.newpipe.util.text.CommentTextOnTouchListener;
2932
import org.schabi.newpipe.util.text.TextEllipsizer;
3033

3134
public class CommentInfoItemHolder extends InfoItemHolder {
@@ -128,7 +131,26 @@ public void updateFromItem(final InfoItem infoItem,
128131
textEllipsizer.ellipsize();
129132

130133
//noinspection ClickableViewAccessibility
131-
itemContentView.setOnTouchListener(CommentTextOnTouchListener.INSTANCE);
134+
itemContentView.setOnTouchListener((v, event) -> {
135+
final CharSequence text = itemContentView.getText();
136+
if (text instanceof Spanned buffer) {
137+
final int action = event.getAction();
138+
139+
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
140+
final int offset = getOffsetForHorizontalLine(itemContentView, event);
141+
final var links = buffer.getSpans(offset, offset, ClickableSpan.class);
142+
143+
if (links.length != 0) {
144+
if (action == MotionEvent.ACTION_UP) {
145+
links[0].onClick(itemContentView);
146+
}
147+
// we handle events that intersect links, so return true
148+
return true;
149+
}
150+
}
151+
}
152+
return false;
153+
});
132154

133155
itemView.setOnClickListener(view -> {
134156
textEllipsizer.toggle();

app/src/main/java/org/schabi/newpipe/util/text/CommentTextOnTouchListener.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)