mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 21:55:10 +00:00
Use view binding in the classes in the 'List' package.
This commit is contained in:
committed by
Nicolas Fella
parent
5073f5e3dd
commit
fcae39846e
@@ -22,20 +22,17 @@ package org.kde.kdeconnect.UserInterface.List;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.kde.kdeconnect_tp.R;
|
||||
import org.kde.kdeconnect_tp.databinding.ListItemEntryBinding;
|
||||
|
||||
public class EntryItem implements ListAdapter.Item {
|
||||
|
||||
protected final String title;
|
||||
protected final String subtitle;
|
||||
|
||||
public EntryItem(String title) {
|
||||
this.title = title;
|
||||
this.subtitle = null;
|
||||
this(title, null);
|
||||
}
|
||||
|
||||
protected EntryItem(String title, String subtitle) {
|
||||
@@ -45,21 +42,16 @@ public class EntryItem implements ListAdapter.Item {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View inflateView(LayoutInflater layoutInflater) {
|
||||
View v = layoutInflater.inflate(R.layout.list_item_entry, null);
|
||||
public View inflateView(@NonNull LayoutInflater layoutInflater) {
|
||||
final ListItemEntryBinding binding = ListItemEntryBinding.inflate(layoutInflater);
|
||||
|
||||
TextView titleView = v.findViewById(R.id.list_item_entry_title);
|
||||
if (titleView != null) titleView.setText(title);
|
||||
binding.listItemEntryTitle.setText(title);
|
||||
|
||||
if (subtitle != null) {
|
||||
TextView subtitleView = v.findViewById(R.id.list_item_entry_summary);
|
||||
if (subtitleView != null) {
|
||||
subtitleView.setVisibility(View.VISIBLE);
|
||||
subtitleView.setText(subtitle);
|
||||
}
|
||||
binding.listItemEntrySummary.setVisibility(View.VISIBLE);
|
||||
binding.listItemEntrySummary.setText(subtitle);
|
||||
}
|
||||
|
||||
return v;
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -27,30 +27,26 @@ import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ListAdapter extends ArrayAdapter<ListAdapter.Item> {
|
||||
|
||||
public interface Item {
|
||||
@NonNull
|
||||
View inflateView(LayoutInflater layoutInflater);
|
||||
View inflateView(@NonNull LayoutInflater layoutInflater);
|
||||
}
|
||||
|
||||
private final List<? extends Item> items;
|
||||
private final LayoutInflater layoutInflater;
|
||||
|
||||
public ListAdapter(Context context, List<? extends Item> items) {
|
||||
super(context, 0, (List<Item>) items);
|
||||
this.items = items;
|
||||
layoutInflater = ContextCompat.getSystemService(context, LayoutInflater.class);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
|
||||
final Item i = items.get(position);
|
||||
return i.inflateView(layoutInflater);
|
||||
return i.inflateView(LayoutInflater.from(parent.getContext()));
|
||||
}
|
||||
}
|
||||
|
@@ -22,13 +22,12 @@ package org.kde.kdeconnect.UserInterface.List;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.kde.kdeconnect.Device;
|
||||
import org.kde.kdeconnect_tp.R;
|
||||
import org.kde.kdeconnect_tp.databinding.ListItemWithIconEntryBinding;
|
||||
|
||||
public class PairingDeviceItem implements ListAdapter.Item {
|
||||
|
||||
@@ -50,36 +49,31 @@ public class PairingDeviceItem implements ListAdapter.Item {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View inflateView(LayoutInflater layoutInflater) {
|
||||
final View v = layoutInflater.inflate(R.layout.list_item_with_icon_entry, null);
|
||||
public View inflateView(@NonNull LayoutInflater layoutInflater) {
|
||||
final ListItemWithIconEntryBinding binding = ListItemWithIconEntryBinding.inflate(layoutInflater);
|
||||
|
||||
ImageView icon = v.findViewById(R.id.list_item_entry_icon);
|
||||
icon.setImageDrawable(device.getIcon());
|
||||
|
||||
TextView titleView = v.findViewById(R.id.list_item_entry_title);
|
||||
titleView.setText(device.getName());
|
||||
binding.listItemEntryIcon.setImageDrawable(device.getIcon());
|
||||
binding.listItemEntryTitle.setText(device.getName());
|
||||
|
||||
if (device.compareProtocolVersion() != 0) {
|
||||
TextView summaryView = v.findViewById(R.id.list_item_entry_summary);
|
||||
|
||||
if (device.compareProtocolVersion() > 0) {
|
||||
summaryView.setText(R.string.protocol_version_newer);
|
||||
summaryView.setVisibility(View.VISIBLE);
|
||||
binding.listItemEntrySummary.setText(R.string.protocol_version_newer);
|
||||
binding.listItemEntrySummary.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
//FIXME: Uncoment when we decide old versions are old enough to notify the user.
|
||||
summaryView.setVisibility(View.GONE);
|
||||
binding.listItemEntrySummary.setVisibility(View.GONE);
|
||||
/*
|
||||
summaryView.setText(R.string.protocol_version_older);
|
||||
summaryView.setVisibility(View.VISIBLE);
|
||||
*/
|
||||
}
|
||||
} else {
|
||||
v.findViewById(R.id.list_item_entry_summary).setVisibility(View.GONE);
|
||||
binding.listItemEntrySummary.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
v.setOnClickListener(v1 -> callback.pairingClicked(device));
|
||||
binding.getRoot().setOnClickListener(v1 -> callback.pairingClicked(device));
|
||||
|
||||
return v;
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -29,9 +29,9 @@ import androidx.annotation.NonNull;
|
||||
|
||||
import org.kde.kdeconnect.Plugins.Plugin;
|
||||
import org.kde.kdeconnect_tp.R;
|
||||
import org.kde.kdeconnect_tp.databinding.ListItemWithIconEntryBinding;
|
||||
|
||||
public class PluginItem implements ListAdapter.Item {
|
||||
|
||||
private final Plugin plugin;
|
||||
private final View.OnClickListener clickListener;
|
||||
|
||||
@@ -40,21 +40,15 @@ public class PluginItem implements ListAdapter.Item {
|
||||
this.clickListener = clickListener;
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View inflateView(final LayoutInflater layoutInflater) {
|
||||
View v = layoutInflater.inflate(R.layout.list_item_with_icon_entry, null);
|
||||
public View inflateView(@NonNull LayoutInflater layoutInflater) {
|
||||
final ListItemWithIconEntryBinding binding = ListItemWithIconEntryBinding.inflate(layoutInflater);
|
||||
|
||||
TextView titleView = v.findViewById(R.id.list_item_entry_title);
|
||||
titleView.setText(plugin.getActionName());
|
||||
binding.listItemEntryTitle.setText(plugin.getActionName());
|
||||
binding.listItemEntryIcon.setImageDrawable(plugin.getIcon());
|
||||
binding.getRoot().setOnClickListener(clickListener);
|
||||
|
||||
ImageView imageView = v.findViewById(R.id.list_item_entry_icon);
|
||||
imageView.setImageDrawable(plugin.getIcon());
|
||||
|
||||
v.setOnClickListener(clickListener);
|
||||
|
||||
return v;
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -26,10 +26,9 @@ import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.kde.kdeconnect_tp.R;
|
||||
import org.kde.kdeconnect_tp.databinding.ListItemPluginHeaderBinding;
|
||||
|
||||
public class PluginListHeaderItem implements ListAdapter.Item {
|
||||
|
||||
private final int text;
|
||||
|
||||
public PluginListHeaderItem(int text) {
|
||||
@@ -38,12 +37,11 @@ public class PluginListHeaderItem implements ListAdapter.Item {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View inflateView(LayoutInflater layoutInflater) {
|
||||
TextView v = (TextView) layoutInflater.inflate(R.layout.list_item_plugin_header, null);
|
||||
v.setText(text);
|
||||
v.setOnClickListener(null);
|
||||
v.setOnLongClickListener(null);
|
||||
return v;
|
||||
public View inflateView(@NonNull LayoutInflater layoutInflater) {
|
||||
TextView textView = ListItemPluginHeaderBinding.inflate(layoutInflater).getRoot();
|
||||
textView.setText(text);
|
||||
textView.setOnClickListener(null);
|
||||
textView.setOnLongClickListener(null);
|
||||
return textView;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -22,14 +22,12 @@ package org.kde.kdeconnect.UserInterface.List;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.kde.kdeconnect_tp.R;
|
||||
import org.kde.kdeconnect_tp.databinding.ListItemCategoryBinding;
|
||||
|
||||
public class SectionItem implements ListAdapter.Item {
|
||||
|
||||
private final String title;
|
||||
public boolean isEmpty;
|
||||
|
||||
@@ -40,22 +38,19 @@ public class SectionItem implements ListAdapter.Item {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View inflateView(LayoutInflater layoutInflater) {
|
||||
|
||||
View v = layoutInflater.inflate(R.layout.list_item_category, null);
|
||||
public View inflateView(@NonNull LayoutInflater layoutInflater) {
|
||||
final ListItemCategoryBinding binding = ListItemCategoryBinding.inflate(layoutInflater);
|
||||
|
||||
//Make it not selectable
|
||||
v.setOnClickListener(null);
|
||||
v.setOnLongClickListener(null);
|
||||
binding.getRoot().setOnClickListener(null);
|
||||
binding.getRoot().setOnLongClickListener(null);
|
||||
|
||||
TextView sectionView = v.findViewById(R.id.list_item_category_text);
|
||||
sectionView.setText(title);
|
||||
binding.listItemCategoryText.setText(title);
|
||||
|
||||
if (isEmpty) {
|
||||
v.findViewById(R.id.list_item_category_empty_placeholder).setVisibility(View.VISIBLE);
|
||||
binding.listItemCategoryEmptyPlaceholder.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
return v;
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
}
|
||||
|
@@ -30,15 +30,9 @@ import androidx.annotation.NonNull;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
public class SmallEntryItem implements ListAdapter.Item {
|
||||
|
||||
private final String title;
|
||||
private final View.OnClickListener clickListener;
|
||||
|
||||
public SmallEntryItem(String title) {
|
||||
this.title = title;
|
||||
this.clickListener = null;
|
||||
}
|
||||
|
||||
SmallEntryItem(String title, View.OnClickListener clickListener) {
|
||||
this.title = title;
|
||||
this.clickListener = clickListener;
|
||||
@@ -46,14 +40,10 @@ public class SmallEntryItem implements ListAdapter.Item {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View inflateView(LayoutInflater layoutInflater) {
|
||||
public View inflateView(@NonNull LayoutInflater layoutInflater) {
|
||||
View v = layoutInflater.inflate(android.R.layout.simple_list_item_1, null);
|
||||
v.setPadding(
|
||||
((int) (28 * layoutInflater.getContext().getResources().getDisplayMetrics().density)),
|
||||
0,
|
||||
((int) (28 * layoutInflater.getContext().getResources().getDisplayMetrics().density)),
|
||||
0
|
||||
);
|
||||
final int padding = (int) (28 * layoutInflater.getContext().getResources().getDisplayMetrics().density);
|
||||
v.setPadding(padding, 0, padding, 0);
|
||||
|
||||
TextView titleView = v.findViewById(android.R.id.text1);
|
||||
if (titleView != null) {
|
||||
@@ -66,5 +56,4 @@ public class SmallEntryItem implements ListAdapter.Item {
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user