Skip to content

Commit e9e2afa

Browse files
authored
Merge pull request #7061 from TiA4f8R/custom-textview-edittext
Use custom TextViews and EditTexts in all XML resources
2 parents 7067deb + ddaafb6 commit e9e2afa

File tree

73 files changed

+459
-301
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+459
-301
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.schabi.newpipe.util;
2+
3+
import android.content.Context;
4+
import android.text.Selection;
5+
import android.text.Spannable;
6+
import android.widget.TextView;
7+
8+
import androidx.annotation.NonNull;
9+
import androidx.annotation.Nullable;
10+
11+
import org.schabi.newpipe.util.external_communication.ShareUtils;
12+
import org.schabi.newpipe.views.NewPipeEditText;
13+
import org.schabi.newpipe.views.NewPipeTextView;
14+
15+
public final class NewPipeTextViewHelper {
16+
private NewPipeTextViewHelper() {
17+
}
18+
19+
/**
20+
* Share the selected text of {@link NewPipeTextView NewPipeTextViews} and
21+
* {@link NewPipeEditText NewPipeEditTexts} with
22+
* {@link ShareUtils#shareText(Context, String, String)}.
23+
*
24+
* <p>
25+
* This allows EMUI users to get the Android share sheet instead of the EMUI share sheet when
26+
* using the {@code Share} command of the popup menu which appears when selecting text.
27+
* </p>
28+
*
29+
* @param textView the {@link TextView} on which sharing the selected text. It should be a
30+
* {@link NewPipeTextView} or a {@link NewPipeEditText} (even if
31+
* {@link TextView standard TextViews} are supported).
32+
*/
33+
public static void shareSelectedTextWithShareUtils(@NonNull final TextView textView) {
34+
final CharSequence textViewText = textView.getText();
35+
shareSelectedTextIfNotNullAndNotEmpty(textView, getSelectedText(textView, textViewText));
36+
if (textViewText instanceof Spannable) {
37+
Selection.setSelection((Spannable) textViewText, textView.getSelectionEnd());
38+
}
39+
}
40+
41+
@Nullable
42+
private static CharSequence getSelectedText(@NonNull final TextView textView,
43+
@Nullable final CharSequence text) {
44+
if (!textView.hasSelection() || text == null) {
45+
return null;
46+
}
47+
48+
final int start = textView.getSelectionStart();
49+
final int end = textView.getSelectionEnd();
50+
return String.valueOf(start > end ? text.subSequence(end, start)
51+
: text.subSequence(start, end));
52+
}
53+
54+
private static void shareSelectedTextIfNotNullAndNotEmpty(
55+
@NonNull final TextView textView,
56+
@Nullable final CharSequence selectedText) {
57+
if (selectedText != null && selectedText.length() != 0) {
58+
ShareUtils.shareText(textView.getContext(), "", selectedText.toString());
59+
}
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.schabi.newpipe.views;
2+
3+
import android.content.Context;
4+
import android.util.AttributeSet;
5+
6+
import androidx.annotation.NonNull;
7+
import androidx.annotation.Nullable;
8+
import androidx.appcompat.widget.AppCompatEditText;
9+
10+
import org.schabi.newpipe.util.NewPipeTextViewHelper;
11+
import org.schabi.newpipe.util.external_communication.ShareUtils;
12+
13+
/**
14+
* An {@link AppCompatEditText} which uses {@link ShareUtils#shareText(Context, String, String)}
15+
* when sharing selected text by using the {@code Share} command of the floating actions.
16+
* <p>
17+
* This allows NewPipe to show Android share sheet instead of EMUI share sheet when sharing text
18+
* from {@link AppCompatEditText} on EMUI devices.
19+
* </p>
20+
*/
21+
public class NewPipeEditText extends AppCompatEditText {
22+
23+
public NewPipeEditText(@NonNull final Context context) {
24+
super(context);
25+
}
26+
27+
public NewPipeEditText(@NonNull final Context context, @Nullable final AttributeSet attrs) {
28+
super(context, attrs);
29+
}
30+
31+
public NewPipeEditText(@NonNull final Context context,
32+
@Nullable final AttributeSet attrs,
33+
final int defStyleAttr) {
34+
super(context, attrs, defStyleAttr);
35+
}
36+
37+
@Override
38+
public boolean onTextContextMenuItem(final int id) {
39+
if (id == android.R.id.shareText) {
40+
NewPipeTextViewHelper.shareSelectedTextWithShareUtils(this);
41+
return true;
42+
}
43+
return super.onTextContextMenuItem(id);
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.schabi.newpipe.views;
2+
3+
import android.content.Context;
4+
import android.util.AttributeSet;
5+
6+
import androidx.annotation.NonNull;
7+
import androidx.annotation.Nullable;
8+
import androidx.appcompat.widget.AppCompatTextView;
9+
10+
import org.schabi.newpipe.util.NewPipeTextViewHelper;
11+
import org.schabi.newpipe.util.external_communication.ShareUtils;
12+
13+
/**
14+
* An {@link AppCompatTextView} which uses {@link ShareUtils#shareText(Context, String, String)}
15+
* when sharing selected text by using the {@code Share} command of the floating actions.
16+
* <p>
17+
* This allows NewPipe to show Android share sheet instead of EMUI share sheet when sharing text
18+
* from {@link AppCompatTextView} on EMUI devices.
19+
* </p>
20+
*/
21+
public class NewPipeTextView extends AppCompatTextView {
22+
23+
public NewPipeTextView(@NonNull final Context context) {
24+
super(context);
25+
}
26+
27+
public NewPipeTextView(@NonNull final Context context, @Nullable final AttributeSet attrs) {
28+
super(context, attrs);
29+
}
30+
31+
public NewPipeTextView(@NonNull final Context context,
32+
@Nullable final AttributeSet attrs,
33+
final int defStyleAttr) {
34+
super(context, attrs, defStyleAttr);
35+
}
36+
37+
@Override
38+
public boolean onTextContextMenuItem(final int id) {
39+
if (id == android.R.id.shareText) {
40+
NewPipeTextViewHelper.shareSelectedTextWithShareUtils(this);
41+
return true;
42+
}
43+
return super.onTextContextMenuItem(id);
44+
}
45+
}

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

+6-6
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

+20-20
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"

0 commit comments

Comments
 (0)