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