Skip to content

Commit a55acd3

Browse files
committed
Use a custom TextView everywhere to be able to share with ShareUtils the selected text
This TextView class extends the AppCompatTextView class from androidx. These changes (only in XML ressources) allow us to share the selected text by using ShareUtils.shareText, which opens the Android system chooser instead of the Huawei system chooser on EMUI devices.
1 parent 7edef8d commit a55acd3

69 files changed

Lines changed: 362 additions & 295 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.schabi.newpipe.views;
2+
3+
import android.content.Context;
4+
import android.text.Selection;
5+
import android.text.Spannable;
6+
import android.util.AttributeSet;
7+
8+
import androidx.annotation.NonNull;
9+
import androidx.annotation.Nullable;
10+
import androidx.appcompat.widget.AppCompatTextView;
11+
12+
import org.schabi.newpipe.util.external_communication.ShareUtils;
13+
14+
public class NewPipeTextView extends AppCompatTextView {
15+
16+
public NewPipeTextView(@NonNull final Context context) {
17+
super(context);
18+
}
19+
20+
public NewPipeTextView(@NonNull final Context context, @Nullable final AttributeSet attrs) {
21+
super(context, attrs);
22+
}
23+
24+
public NewPipeTextView(@NonNull final Context context,
25+
@Nullable final AttributeSet attrs,
26+
final int defStyleAttr) {
27+
super(context, attrs, defStyleAttr);
28+
}
29+
30+
@Override
31+
public boolean onTextContextMenuItem(final int id) {
32+
final CharSequence text = getText();
33+
if (id == android.R.id.shareText) {
34+
final String selectedText = getSelectedText(text).toString();
35+
if (!selectedText.isEmpty()) {
36+
ShareUtils.shareText(getContext(), "", selectedText);
37+
}
38+
final Spannable spannable = (text instanceof Spannable) ? (Spannable) text : null;
39+
Selection.setSelection(spannable, getSelectionEnd());
40+
return true;
41+
} else {
42+
return super.onTextContextMenuItem(id);
43+
}
44+
}
45+
46+
@NonNull
47+
private CharSequence getSelectedText(@NonNull final CharSequence charSequence) {
48+
int min = 0;
49+
int max = charSequence.length();
50+
51+
if (isFocused()) {
52+
final int selStart = getSelectionStart();
53+
final int selEnd = getSelectionEnd();
54+
55+
min = Math.max(0, Math.min(selStart, selEnd));
56+
max = Math.max(0, Math.max(selStart, selEnd));
57+
}
58+
return charSequence.subSequence(min, max);
59+
}
60+
}

app/src/main/res/layout-land/activity_player_queue_control.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
android:padding="8dp"
6161
tools:ignore="RtlHardcoded,RtlSymmetry">
6262

63-
<TextView
63+
<org.schabi.newpipe.views.NewPipeTextView
6464
android:id="@+id/song_name"
6565
style="@android:style/TextAppearance.StatusBar.EventContent.Title"
6666
android:layout_width="match_parent"
@@ -71,7 +71,7 @@
7171
android:textSize="14sp"
7272
tools:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis nec aliquam augue, eget cursus est. Ut id tristique enim, ut scelerisque tellus. Sed ultricies ipsum non mauris ultricies, commodo malesuada velit porta." />
7373

74-
<TextView
74+
<org.schabi.newpipe.views.NewPipeTextView
7575
android:id="@+id/artist_name"
7676
style="@android:style/TextAppearance.StatusBar.EventContent"
7777
android:layout_width="match_parent"
@@ -82,7 +82,7 @@
8282
tools:text="Duis posuere arcu condimentum lobortis mattis." />
8383
</LinearLayout>
8484

85-
<TextView
85+
<org.schabi.newpipe.views.NewPipeTextView
8686
android:id="@+id/seek_display"
8787
android:layout_width="wrap_content"
8888
android:layout_height="wrap_content"
@@ -269,7 +269,7 @@
269269
android:paddingLeft="16dp"
270270
android:paddingRight="16dp">
271271

272-
<TextView
272+
<org.schabi.newpipe.views.NewPipeTextView
273273
android:id="@+id/current_time"
274274
android:layout_width="wrap_content"
275275
android:layout_height="match_parent"
@@ -291,7 +291,7 @@
291291
tools:progress="25"
292292
tools:secondaryProgress="50" />
293293

294-
<TextView
294+
<org.schabi.newpipe.views.NewPipeTextView
295295
android:id="@+id/end_time"
296296
android:layout_width="wrap_content"
297297
android:layout_height="match_parent"
@@ -301,7 +301,7 @@
301301
tools:ignore="HardcodedText"
302302
tools:text="1:23:49" />
303303

304-
<TextView
304+
<org.schabi.newpipe.views.NewPipeTextView
305305
android:id="@+id/live_sync"
306306
android:layout_width="wrap_content"
307307
android:layout_height="match_parent"

app/src/main/res/layout-large-land/fragment_video_detail.xml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
tools:ignore="ContentDescription"
7171
tools:visibility="visible" />
7272

73-
<TextView
73+
<org.schabi.newpipe.views.NewPipeTextView
7474
android:id="@+id/touch_append_detail"
7575
android:layout_width="wrap_content"
7676
android:layout_height="wrap_content"
@@ -88,7 +88,7 @@
8888
tools:ignore="RtlHardcoded"
8989
tools:visibility="visible" />
9090

91-
<TextView
91+
<org.schabi.newpipe.views.NewPipeTextView
9292
android:id="@+id/detail_duration_view"
9393
android:layout_width="wrap_content"
9494
android:layout_height="wrap_content"
@@ -113,7 +113,7 @@
113113
tools:text="12:38"
114114
tools:visibility="visible" />
115115

116-
<TextView
116+
<org.schabi.newpipe.views.NewPipeTextView
117117
android:id="@+id/detail_position_view"
118118
android:layout_width="wrap_content"
119119
android:layout_height="wrap_content"
@@ -179,7 +179,7 @@
179179
android:paddingStart="12dp"
180180
tools:ignore="RtlSymmetry">
181181

182-
<TextView
182+
<org.schabi.newpipe.views.NewPipeTextView
183183
android:id="@+id/detail_video_title_view"
184184
android:layout_width="match_parent"
185185
android:layout_height="match_parent"
@@ -291,7 +291,7 @@
291291
android:gravity="center_vertical"
292292
android:orientation="vertical">
293293

294-
<TextView
294+
<org.schabi.newpipe.views.NewPipeTextView
295295
android:id="@+id/detail_sub_channel_text_view"
296296
android:layout_width="match_parent"
297297
android:layout_height="wrap_content"
@@ -307,7 +307,7 @@
307307
tools:ignore="RtlHardcoded"
308308
tools:text="Channel" />
309309

310-
<TextView
310+
<org.schabi.newpipe.views.NewPipeTextView
311311
android:id="@+id/detail_uploader_text_view"
312312
android:layout_width="match_parent"
313313
android:layout_height="wrap_content"
@@ -348,7 +348,7 @@
348348
android:paddingLeft="6dp"
349349
android:paddingRight="6dp">
350350

351-
<TextView
351+
<org.schabi.newpipe.views.NewPipeTextView
352352
android:id="@+id/detail_view_count_view"
353353
android:layout_width="wrap_content"
354354
android:layout_height="wrap_content"
@@ -369,7 +369,7 @@
369369
android:contentDescription="@string/detail_likes_img_view_description"
370370
app:srcCompat="@drawable/ic_thumb_up" />
371371

372-
<TextView
372+
<org.schabi.newpipe.views.NewPipeTextView
373373
android:id="@+id/detail_thumbs_up_count_view"
374374
android:layout_width="wrap_content"
375375
android:layout_height="@dimen/video_item_detail_like_image_height"
@@ -394,7 +394,7 @@
394394
app:srcCompat="@drawable/ic_thumb_down"
395395
tools:ignore="RtlHardcoded" />
396396

397-
<TextView
397+
<org.schabi.newpipe.views.NewPipeTextView
398398
android:id="@+id/detail_thumbs_down_count_view"
399399
android:layout_width="wrap_content"
400400
android:layout_height="@dimen/video_item_detail_like_image_height"
@@ -408,7 +408,7 @@
408408
tools:ignore="RtlHardcoded"
409409
tools:text="10K" />
410410

411-
<TextView
411+
<org.schabi.newpipe.views.NewPipeTextView
412412
android:id="@+id/detail_thumbs_disabled_view"
413413
android:layout_width="wrap_content"
414414
android:layout_height="@dimen/video_item_detail_like_image_height"
@@ -436,7 +436,7 @@
436436
android:orientation="horizontal"
437437
android:padding="@dimen/detail_control_padding">
438438

439-
<TextView
439+
<org.schabi.newpipe.views.NewPipeTextView
440440
android:id="@+id/detail_controls_playlist_append"
441441
android:layout_width="@dimen/detail_control_width"
442442
android:layout_height="@dimen/detail_control_height"
@@ -452,7 +452,7 @@
452452
android:textSize="@dimen/detail_control_text_size"
453453
app:drawableTopCompat="@drawable/ic_playlist_add" />
454454

455-
<TextView
455+
<org.schabi.newpipe.views.NewPipeTextView
456456
android:id="@+id/detail_controls_background"
457457
android:layout_width="@dimen/detail_control_width"
458458
android:layout_height="@dimen/detail_control_height"
@@ -468,7 +468,7 @@
468468
android:textSize="@dimen/detail_control_text_size"
469469
app:drawableTopCompat="@drawable/ic_headset" />
470470

471-
<TextView
471+
<org.schabi.newpipe.views.NewPipeTextView
472472
android:id="@+id/detail_controls_popup"
473473
android:layout_width="@dimen/detail_control_width"
474474
android:layout_height="@dimen/detail_control_height"
@@ -484,7 +484,7 @@
484484
android:textSize="@dimen/detail_control_text_size"
485485
app:drawableTopCompat="@drawable/ic_picture_in_picture" />
486486

487-
<TextView
487+
<org.schabi.newpipe.views.NewPipeTextView
488488
android:id="@+id/detail_controls_download"
489489
android:layout_width="@dimen/detail_control_width"
490490
android:layout_height="@dimen/detail_control_height"
@@ -515,7 +515,7 @@
515515
android:visibility="gone"
516516
tools:visibility="visible">
517517

518-
<TextView
518+
<org.schabi.newpipe.views.NewPipeTextView
519519
android:id="@+id/detail_controls_share"
520520
android:layout_width="@dimen/detail_control_width"
521521
android:layout_height="@dimen/detail_control_height"
@@ -531,7 +531,7 @@
531531
android:textSize="@dimen/detail_control_text_size"
532532
app:drawableTopCompat="@drawable/ic_share" />
533533

534-
<TextView
534+
<org.schabi.newpipe.views.NewPipeTextView
535535
android:id="@+id/detail_controls_open_in_browser"
536536
android:layout_width="@dimen/detail_control_width"
537537
android:layout_height="@dimen/detail_control_height"
@@ -547,7 +547,7 @@
547547
android:textSize="@dimen/detail_control_text_size"
548548
app:drawableTopCompat="@drawable/ic_language" />
549549

550-
<TextView
550+
<org.schabi.newpipe.views.NewPipeTextView
551551
android:id="@+id/detail_controls_play_with_kodi"
552552
android:layout_width="@dimen/detail_control_width"
553553
android:layout_height="@dimen/detail_control_height"
@@ -573,7 +573,7 @@
573573
android:layout_marginRight="8dp"
574574
android:background="?attr/separator_color" />
575575

576-
<TextView
576+
<org.schabi.newpipe.views.NewPipeTextView
577577
android:id="@+id/detail_meta_info_text_view"
578578
android:layout_width="match_parent"
579579
android:layout_height="wrap_content"
@@ -654,7 +654,7 @@
654654
android:orientation="vertical"
655655
tools:ignore="RtlHardcoded">
656656

657-
<TextView
657+
<org.schabi.newpipe.views.NewPipeTextView
658658
android:id="@+id/overlay_title_text_view"
659659
android:layout_width="match_parent"
660660
android:layout_height="wrap_content"
@@ -668,7 +668,7 @@
668668
tools:ignore="RtlHardcoded"
669669
tools:text="The Video Title LONG very LONVideo Title LONG very LONG" />
670670

671-
<TextView
671+
<org.schabi.newpipe.views.NewPipeTextView
672672
android:id="@+id/overlay_channel_text_view"
673673
android:layout_width="match_parent"
674674
android:layout_height="wrap_content"

app/src/main/res/layout-large-land/player.xml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
android:orientation="vertical"
119119
tools:ignore="RtlHardcoded">
120120

121-
<TextView
121+
<org.schabi.newpipe.views.NewPipeTextView
122122
android:id="@+id/titleTextView"
123123
android:layout_width="match_parent"
124124
android:layout_height="wrap_content"
@@ -133,7 +133,7 @@
133133
tools:ignore="RtlHardcoded"
134134
tools:text="The Video Title LONG very LONG" />
135135

136-
<TextView
136+
<org.schabi.newpipe.views.NewPipeTextView
137137
android:id="@+id/channelTextView"
138138
android:layout_width="match_parent"
139139
android:layout_height="wrap_content"
@@ -147,7 +147,7 @@
147147
tools:text="The Video Artist LONG very LONG very Long" />
148148
</LinearLayout>
149149

150-
<TextView
150+
<org.schabi.newpipe.views.NewPipeTextView
151151
android:id="@+id/qualityTextView"
152152
android:layout_width="wrap_content"
153153
android:layout_height="35dp"
@@ -161,7 +161,7 @@
161161
tools:ignore="HardcodedText,RtlHardcoded"
162162
tools:text="720p" />
163163

164-
<TextView
164+
<org.schabi.newpipe.views.NewPipeTextView
165165
android:id="@+id/playbackSpeed"
166166
android:layout_width="wrap_content"
167167
android:layout_height="35dp"
@@ -237,7 +237,7 @@
237237
tools:ignore="RtlHardcoded"
238238
tools:visibility="visible">
239239

240-
<TextView
240+
<org.schabi.newpipe.views.NewPipeTextView
241241
android:id="@+id/resizeTextView"
242242
android:layout_width="wrap_content"
243243
android:layout_height="35dp"
@@ -257,7 +257,7 @@
257257
android:layout_height="wrap_content"
258258
android:layout_weight="3">
259259

260-
<TextView
260+
<org.schabi.newpipe.views.NewPipeTextView
261261
android:id="@+id/captionTextView"
262262
android:layout_width="wrap_content"
263263
android:layout_height="wrap_content"
@@ -369,7 +369,7 @@
369369
android:orientation="vertical"
370370
android:paddingBottom="12dp">
371371

372-
<TextView
372+
<org.schabi.newpipe.views.NewPipeTextView
373373
android:id="@+id/currentDisplaySeek"
374374
android:layout_width="wrap_content"
375375
android:layout_height="wrap_content"
@@ -409,7 +409,7 @@
409409
android:paddingLeft="@dimen/player_main_controls_padding"
410410
android:paddingRight="@dimen/player_main_controls_padding">
411411

412-
<TextView
412+
<org.schabi.newpipe.views.NewPipeTextView
413413
android:id="@+id/playbackCurrentTime"
414414
android:layout_width="wrap_content"
415415
android:layout_height="match_parent"
@@ -433,7 +433,7 @@
433433
tools:progress="25"
434434
tools:secondaryProgress="50" />
435435

436-
<TextView
436+
<org.schabi.newpipe.views.NewPipeTextView
437437
android:id="@+id/playbackEndTime"
438438
android:layout_width="wrap_content"
439439
android:layout_height="match_parent"
@@ -443,7 +443,7 @@
443443
tools:ignore="HardcodedText"
444444
tools:text="1:23:49" />
445445

446-
<TextView
446+
<org.schabi.newpipe.views.NewPipeTextView
447447
android:id="@+id/playbackLiveSync"
448448
android:layout_width="wrap_content"
449449
android:layout_height="match_parent"

0 commit comments

Comments
 (0)