0
0
mirror of https://github.com/TrianguloY/UrlChecker.git synced 2024-09-19 20:02:16 +02:00

simplify inflater

This commit is contained in:
TrianguloY 2023-04-15 20:41:31 +02:00
parent c45b48c8f4
commit 5ea02273c3
8 changed files with 14 additions and 13 deletions

View File

@ -61,7 +61,7 @@ public class AboutActivity extends Activity {
// create links
ViewGroup v_links = findViewById(R.id.links);
for (var link : LINKS) {
var v_link = Inflater.<TextView>inflate(R.layout.about_link, v_links, this);
var v_link = Inflater.<TextView>inflate(R.layout.about_link, v_links);
v_link.setText(link.first);
AndroidUtils.setAsClickable(v_link);
v_link.setTag(link.second.replace("{package}", getPackageName()));

View File

@ -98,7 +98,7 @@ public class ModulesActivity extends Activity {
final AModuleConfig config = module.getConfig(this);
// inflate
View parent = Inflater.inflate(R.layout.config_module, list, this);
View parent = Inflater.inflate(R.layout.config_module, list);
parent.setTag(module.getId());
Animations.enableAnimations(parent);
@ -142,7 +142,7 @@ public class ModulesActivity extends Activity {
AndroidUtils.longTapForDescription(toggleDecorations);
// configuration of the module
var child = Inflater.inflate(config.getLayoutId(), parent.findViewById(R.id.box), this);
var child = Inflater.inflate(config.getLayoutId(), parent.findViewById(R.id.box));
config.onInitialize(child);
// configure toggleable description

View File

@ -227,7 +227,7 @@ public class MainDialog extends Activity {
// set module block
if (ModuleManager.getDecorationsPrefOfModule(moduleData, this).get()) {
// init decorations
View block = Inflater.inflate(R.layout.dialog_module, ll_mods, this);
View block = Inflater.inflate(R.layout.dialog_module, ll_mods);
final TextView title = block.findViewById(R.id.title);
title.setText(getString(R.string.dd, getString(moduleData.getName())));
parent = block.findViewById(R.id.mod);
@ -237,7 +237,7 @@ public class MainDialog extends Activity {
}
// set module content
child = Inflater.inflate(layoutId, parent, this);
child = Inflater.inflate(layoutId, parent);
views.add(child);
}
@ -261,7 +261,7 @@ public class MainDialog extends Activity {
* Adds a separator component to the list of mods
*/
private View addSeparator() {
return Inflater.inflate(R.layout.separator, ll_mods, this);
return Inflater.inflate(R.layout.separator, ll_mods);
}
/**

View File

@ -230,7 +230,7 @@ class FlagsDialog extends AModuleDialog {
vg.removeAllViews();
for (String flag : flags) {
var checkbox_text = Inflater.inflate(R.layout.dialog_flags_entry, vg, getActivity());
var checkbox_text = Inflater.inflate(R.layout.dialog_flags_entry, vg);
// Checkbox
var checkBox = checkbox_text.<ImageView>findViewById(R.id.state);
@ -368,7 +368,7 @@ class FlagsConfig extends AModuleConfig {
// Fill the box
for (String flag : Flags.getCompatibleFlags().keySet()) {
var entryView = Inflater.inflate(R.layout.flags_editor_entry, vg, getActivity());
var entryView = Inflater.inflate(R.layout.flags_editor_entry, vg);
TextView textView = entryView.findViewById(R.id.text);
textView.setText(flag);

View File

@ -193,7 +193,7 @@ class PatternDialog extends AModuleDialog {
for (Message message : messages) {
// either matches and/or applied is true
View row = Inflater.inflate(R.layout.button_text, box, getActivity());
View row = Inflater.inflate(R.layout.button_text, box);
// text
TextView text = row.findViewById(R.id.text);

View File

@ -105,7 +105,7 @@ class RemoveQueriesDialog extends AModuleDialog {
// for each query, create a button
for (int i = 0; i < parts.queriesSize(); i++) {
var button_text = Inflater.inflate(R.layout.button_text, box, getActivity());
var button_text = Inflater.inflate(R.layout.button_text, box);
// button that removes the query
var queryName = parts.getQueryName(i);

View File

@ -103,6 +103,7 @@ public interface AndroidUtils {
}
}, 0, text.length(), 0);
textview.setText(text);
// TODO: remove underline (set color only). textview.setTextColor(textview.getResources().getColor(R.color.app)); doesn't work
}
/**

View File

@ -1,6 +1,6 @@
package com.trianguloy.urlchecker.utilities;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -12,8 +12,8 @@ public interface Inflater {
* like {@link android.view.LayoutInflater#inflate(int, ViewGroup)}, but returns the inflated view (not the root view)
* Note: root must not be null (otherwise just use the original)
*/
static <T extends View> T inflate(int resource, ViewGroup root, Activity cntx) {
final View view = cntx.getLayoutInflater().inflate(resource, root, false);
static <T extends View> T inflate(int resource, ViewGroup root) {
final View view = LayoutInflater.from(root.getContext()).inflate(resource, root, false);
root.addView(view);
//noinspection unchecked
return ((T) view);