#3451 Delete CompatTextView - remove all references to CompatTextView (#3709)

This commit is contained in:
Seán Mac Gillicuddy 2020-04-25 21:21:19 +01:00 committed by GitHub
parent 82bf2d757f
commit 36a31a96dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 129 deletions

View file

@ -48,7 +48,6 @@ import fr.free.nrw.commons.delete.DeleteHelper;
import fr.free.nrw.commons.delete.ReasonBuilder; import fr.free.nrw.commons.delete.ReasonBuilder;
import fr.free.nrw.commons.depictions.WikidataItemDetailsActivity; import fr.free.nrw.commons.depictions.WikidataItemDetailsActivity;
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment; import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
import fr.free.nrw.commons.ui.widget.CompatTextView;
import fr.free.nrw.commons.ui.widget.HtmlTextView; import fr.free.nrw.commons.ui.widget.HtmlTextView;
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem; import fr.free.nrw.commons.upload.structure.depictions.DepictedItem;
import fr.free.nrw.commons.utils.ViewUtilWrapper; import fr.free.nrw.commons.utils.ViewUtilWrapper;
@ -596,7 +595,7 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
*/ */
private View buildDepictLabel(String depictionName, String entityId, LinearLayout depictionContainer) { private View buildDepictLabel(String depictionName, String entityId, LinearLayout depictionContainer) {
final View item = LayoutInflater.from(getContext()).inflate(R.layout.detail_category_item, depictionContainer, false); final View item = LayoutInflater.from(getContext()).inflate(R.layout.detail_category_item, depictionContainer, false);
final CompatTextView textView = item.findViewById(R.id.mediaDetailCategoryItemText); final TextView textView = item.findViewById(R.id.mediaDetailCategoryItemText);
textView.setText(depictionName); textView.setText(depictionName);
if (depictionLoaded) { if (depictionLoaded) {
@ -613,7 +612,7 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
private View buildCatLabel(final String catName, ViewGroup categoryContainer) { private View buildCatLabel(final String catName, ViewGroup categoryContainer) {
final View item = LayoutInflater.from(getContext()).inflate(R.layout.detail_category_item, categoryContainer, false); final View item = LayoutInflater.from(getContext()).inflate(R.layout.detail_category_item, categoryContainer, false);
final CompatTextView textView = item.findViewById(R.id.mediaDetailCategoryItemText); final TextView textView = item.findViewById(R.id.mediaDetailCategoryItemText);
textView.setText(catName); textView.setText(catName);
if (categoriesLoaded && categoriesPresent) { if (categoriesLoaded && categoriesPresent) {

View file

@ -1,101 +0,0 @@
package fr.free.nrw.commons.ui.widget;
/*
*Created by mikel on 07/08/2017.
*/
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatDrawableManager;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.core.view.ViewCompat;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.utils.UiUtils;
/**
* a text view compatible with older versions of the platform
*/
public class CompatTextView extends AppCompatTextView {
/**
* Constructs a new instance of CompatTextView
*
* @param context the view context
*/
public CompatTextView(Context context) {
super(context);
init(null);
}
/**
* Constructs a new instance of CompatTextView
*
* @param context the view context
* @param attrs the set of attributes for the view
*/
public CompatTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs);
}
/**
* Constructs a new instance of CompatTextView
*
* @param context
* @param attrs
* @param defStyleAttr
*/
public CompatTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(attrs);
}
/**
* initializes the view
*
* @param attrs the attribute set of the view, which can be null
*/
private void init(@Nullable AttributeSet attrs) {
if (attrs != null) {
Context context = getContext();
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CompatTextView);
// Obtain DrawableManager used to pull Drawables safely, and check if we're in RTL
AppCompatDrawableManager dm = AppCompatDrawableManager.get();
boolean rtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
// Grab the compat drawable padding from the XML
float drawablePadding = a.getDimension(R.styleable.CompatTextView_drawablePadding, 0);
// Grab the compat drawable resources from the XML
int startDrawableRes = a.getResourceId(R.styleable.CompatTextView_drawableStart, 0);
int topDrawableRes = a.getResourceId(R.styleable.CompatTextView_drawableTop, 0);
int endDrawableRes = a.getResourceId(R.styleable.CompatTextView_drawableEnd, 0);
int bottomDrawableRes = a.getResourceId(R.styleable.CompatTextView_drawableBottom, 0);
// Load the used drawables, fall back to whatever was set in an "android:"
Drawable[] currentDrawables = getCompoundDrawables();
Drawable left = startDrawableRes != 0
? dm.getDrawable(context, startDrawableRes) : currentDrawables[0];
Drawable right = endDrawableRes != 0
? dm.getDrawable(context, endDrawableRes) : currentDrawables[1];
Drawable top = topDrawableRes != 0
? dm.getDrawable(context, topDrawableRes) : currentDrawables[2];
Drawable bottom = bottomDrawableRes != 0
? dm.getDrawable(context, bottomDrawableRes) : currentDrawables[3];
// Account for RTL and apply the compound Drawables
Drawable start = rtl ? right : left;
Drawable end = rtl ? left : right;
setCompoundDrawablesWithIntrinsicBounds(start, top, end, bottom);
setCompoundDrawablePadding((int) UiUtils.convertDpToPixel(drawablePadding, getContext()));
a.recycle();
}
}
}

View file

@ -1,12 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="wrap_content">
android:layout_height="wrap_content"
>
<fr.free.nrw.commons.ui.widget.CompatTextView <TextView
android:id="@+id/mediaDetailCategoryItemText" android:id="@+id/mediaDetailCategoryItemText"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -17,8 +15,8 @@
android:padding="@dimen/small_gap" android:padding="@dimen/small_gap"
android:textColor="?attr/mediaDetailsText" android:textColor="?attr/mediaDetailsText"
android:textSize="@dimen/description_text_size" android:textSize="@dimen/description_text_size"
app:drawablePadding="@dimen/tiny_gap" android:drawablePadding="@dimen/tiny_gap"
app:drawableStart="?attr/iconInfo24" android:drawableStart="?attr/iconInfo24"
/> />
</LinearLayout> </LinearLayout>

View file

@ -171,7 +171,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:text="@string/media_detail_license" /> android:text="@string/media_detail_license" />
<fr.free.nrw.commons.ui.widget.CompatTextView <TextView
android:id="@+id/mediaDetailLicense" android:id="@+id/mediaDetailLicense"
android:layout_width="@dimen/widget_margin" android:layout_width="@dimen/widget_margin"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -182,8 +182,8 @@
android:padding="@dimen/small_gap" android:padding="@dimen/small_gap"
android:textColor="?attr/mediaDetailsText" android:textColor="?attr/mediaDetailsText"
android:textSize="@dimen/description_text_size" android:textSize="@dimen/description_text_size"
app:drawablePadding="@dimen/tiny_gap" android:drawablePadding="@dimen/tiny_gap"
app:drawableStart="?attr/iconInfo24" android:drawableStart="?attr/iconInfo24"
tools:text="License link" /> tools:text="License link" />
</LinearLayout> </LinearLayout>
@ -199,7 +199,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:text="@string/media_detail_coordinates" /> android:text="@string/media_detail_coordinates" />
<fr.free.nrw.commons.ui.widget.CompatTextView <TextView
android:id="@+id/mediaDetailCoordinates" android:id="@+id/mediaDetailCoordinates"
android:layout_width="@dimen/widget_margin" android:layout_width="@dimen/widget_margin"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -210,8 +210,8 @@
android:padding="@dimen/small_gap" android:padding="@dimen/small_gap"
android:textColor="?attr/mediaDetailsText" android:textColor="?attr/mediaDetailsText"
android:textSize="@dimen/description_text_size" android:textSize="@dimen/description_text_size"
app:drawablePadding="@dimen/tiny_gap" android:drawablePadding="@dimen/tiny_gap"
app:drawableStart="?attr/iconMap24" android:drawableStart="?attr/iconMap24"
tools:text="Coordinates link" /> tools:text="Coordinates link" />
</LinearLayout> </LinearLayout>

View file

@ -34,19 +34,10 @@
<attr name="mediaDetailSpacerColor" format="reference" /> <attr name="mediaDetailSpacerColor" format="reference" />
<attr name="icon" format="reference"/> <attr name="icon" format="reference"/>
<attr name="aboutIconsColor" format="reference"/> <attr name="aboutIconsColor" format="reference"/>
<declare-styleable name="CompatTextView">
<attr name="drawablePadding" format="dimension"/>
<attr name="drawableStart" format="reference"/>
<attr name="drawableTop" format="reference"/>
<attr name="drawableEnd" format="reference"/>
<attr name="drawableBottom" format="reference"/>
</declare-styleable>
<declare-styleable name="Badge"> <declare-styleable name="Badge">
<attr name="boundary" format="color"/> <attr name="boundary" format="color"/>
<attr name="camera" format="color"/> <attr name="camera" format="color"/>
<attr name="centerRegion" format="color"/> <attr name="centerRegion" format="color"/>
</declare-styleable> </declare-styleable>
</resources> </resources>