mirror of
https://github.com/revanced/revanced-patches
synced 2025-02-23 16:11:10 +01:00
62 lines
2.0 KiB
Java
62 lines
2.0 KiB
Java
|
package fi.vanced.libraries.youtube.ui;
|
||
|
|
||
|
import static fi.razerman.youtube.XGlobals.debug;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import android.util.Log;
|
||
|
import android.view.LayoutInflater;
|
||
|
import android.view.View;
|
||
|
import android.view.ViewGroup;
|
||
|
import android.widget.ImageView;
|
||
|
import android.widget.TextView;
|
||
|
|
||
|
import fi.vanced.utils.VancedUtils;
|
||
|
|
||
|
public abstract class SlimButton implements View.OnClickListener {
|
||
|
private static final String TAG = "VI - Slim - Button";
|
||
|
public static int SLIM_METADATA_BUTTON_ID;
|
||
|
public final View view;
|
||
|
public final Context context;
|
||
|
private final ViewGroup container;
|
||
|
protected final ImageView button_icon;
|
||
|
protected final TextView button_text;
|
||
|
|
||
|
static {
|
||
|
SLIM_METADATA_BUTTON_ID = VancedUtils.getIdentifier("slim_metadata_button", "layout");
|
||
|
}
|
||
|
|
||
|
public SlimButton(Context context, ViewGroup container, int id, boolean visible) {
|
||
|
if (debug) {
|
||
|
Log.d(TAG, "Adding button with id " + id + " and visibility of " + visible);
|
||
|
}
|
||
|
this.context = context;
|
||
|
this.container = container;
|
||
|
view = LayoutInflater.from(context).inflate(id, container, false);
|
||
|
button_icon = (ImageView)view.findViewById(VancedUtils.getIdentifier("button_icon", "id"));
|
||
|
button_text = (TextView)view.findViewById(VancedUtils.getIdentifier("button_text", "id"));
|
||
|
|
||
|
view.setOnClickListener(this);
|
||
|
setVisible(visible);
|
||
|
|
||
|
container.addView(view);
|
||
|
}
|
||
|
|
||
|
public void setVisible(boolean visible) {
|
||
|
view.setVisibility(visible ? View.VISIBLE : View.GONE);
|
||
|
setContainerVisibility();
|
||
|
}
|
||
|
|
||
|
private void setContainerVisibility() {
|
||
|
if (container == null) return;
|
||
|
|
||
|
for (int i = 0; i < container.getChildCount(); i++) {
|
||
|
if (container.getChildAt(i).getVisibility() == View.VISIBLE) {
|
||
|
container.setVisibility(View.VISIBLE);
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
container.setVisibility(View.GONE);
|
||
|
}
|
||
|
}
|