#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.depictions.WikidataItemDetailsActivity;
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.upload.structure.depictions.DepictedItem;
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) {
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);
if (depictionLoaded) {
@ -613,7 +612,7 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
private View buildCatLabel(final String catName, ViewGroup categoryContainer) {
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);
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();
}
}
}