diff --git a/src/main/java/org/kde/kdeconnect/UserInterface/DeviceActivity.java b/src/main/java/org/kde/kdeconnect/UserInterface/DeviceActivity.java index 90904e52..d74cd276 100644 --- a/src/main/java/org/kde/kdeconnect/UserInterface/DeviceActivity.java +++ b/src/main/java/org/kde/kdeconnect/UserInterface/DeviceActivity.java @@ -9,8 +9,6 @@ import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.TextView; @@ -19,15 +17,16 @@ import org.kde.kdeconnect.BackgroundService; import org.kde.kdeconnect.Device; import org.kde.kdeconnect.Plugins.Plugin; import org.kde.kdeconnect.UserInterface.List.ButtonItem; +import org.kde.kdeconnect.UserInterface.List.CustomItem; import org.kde.kdeconnect.UserInterface.List.ListAdapter; import org.kde.kdeconnect.UserInterface.List.SectionItem; +import org.kde.kdeconnect.UserInterface.List.SmallEntryItem; import org.kde.kdeconnect.UserInterface.List.TextItem; import org.kde.kdeconnect_tp.R; import java.util.ArrayList; import java.util.Collection; import java.util.ConcurrentModificationException; -import java.util.HashMap; public class DeviceActivity extends ActionBarActivity { @@ -47,55 +46,10 @@ public class DeviceActivity extends ActionBarActivity { public void run() { try { - - //Errors list - final HashMap failedPlugins = device.getFailedPlugins(); - final String[] ids = failedPlugins.keySet().toArray(new String[failedPlugins.size()]); - String[] names = new String[failedPlugins.size()]; - for(int i = 0; i < ids.length; i++) { - Plugin p = failedPlugins.get(ids[i]); - names[i] = p.getDisplayName(); - } - ListView errorList = (ListView)findViewById(R.id.errors_list); - if (!failedPlugins.isEmpty()) { - if (errorList.getHeaderViewsCount() == 0) { - if (errorHeader == null) { - errorHeader = new TextView(DeviceActivity.this); - errorHeader.setPadding(0,24,0,0); - errorHeader.setOnClickListener(null); - errorHeader.setOnLongClickListener(null); - - errorHeader.setText(getResources().getString(R.string.plugins_failed_to_load)); - } - errorList.addHeaderView(errorHeader); - } - } else { - errorList.removeHeaderView(errorHeader); - } - errorList.setAdapter(new ArrayAdapter(DeviceActivity.this, android.R.layout.simple_list_item_1, names)); - errorList.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView adapterView, View view, int position, long id) { - if (position == 0) return; - Plugin p = failedPlugins.get(ids[position - 1]); //Header is position 0, so we have to subtract one - p.getErrorDialog(DeviceActivity.this).show(); - - } - }); - - //Buttons list ArrayList items = new ArrayList(); - if (device.isReachable()) { - final Collection plugins = device.getLoadedPlugins().values(); - for (Plugin p : plugins) { - Button b = p.getInterfaceButton(DeviceActivity.this); - if (b != null) { - items.add(new SectionItem(p.getDisplayName())); - items.add(new ButtonItem(b)); - } - } - } else { + if (!device.isReachable()) { + //Not reachable, show unpair button Button b = new Button(DeviceActivity.this); b.setText(R.string.device_menu_unpair); b.setOnClickListener(new View.OnClickListener() { @@ -107,10 +61,42 @@ public class DeviceActivity extends ActionBarActivity { }); items.add(new TextItem(getString(R.string.device_not_reachable))); items.add(new ButtonItem(b)); + } else { + //Plugins button list + final Collection plugins = device.getLoadedPlugins().values(); + for (Plugin p : plugins) { + Button b = p.getInterfaceButton(DeviceActivity.this); + if (b != null) { + items.add(new SectionItem(p.getDisplayName())); + items.add(new ButtonItem(b)); + } + } + + //Failed plugins List + final Collection failed = device.getFailedPlugins().values(); + if (!failed.isEmpty()) { + if (errorHeader == null) { + errorHeader = new TextView(DeviceActivity.this); + errorHeader.setPadding(0, 48, 0, 0); + errorHeader.setOnClickListener(null); + errorHeader.setOnLongClickListener(null); + errorHeader.setText(getResources().getString(R.string.plugins_failed_to_load)); + } + items.add(new CustomItem(errorHeader)); + for (final Plugin p : failed) { + items.add(new SmallEntryItem(p.getDisplayName(), new View.OnClickListener() { + @Override + public void onClick(View v) { + p.getErrorDialog(DeviceActivity.this).show(); + } + })); + } + } } ListView buttonsList = (ListView)findViewById(R.id.buttons_list); - buttonsList.setAdapter(new ListAdapter(DeviceActivity.this, items)); + ListAdapter adapter = new ListAdapter(DeviceActivity.this, items); + buttonsList.setAdapter(adapter); } catch(ConcurrentModificationException e) { Log.e("DeviceActivity", "ConcurrentModificationException"); diff --git a/src/main/java/org/kde/kdeconnect/UserInterface/List/CustomItem.java b/src/main/java/org/kde/kdeconnect/UserInterface/List/CustomItem.java new file mode 100644 index 00000000..b0b97852 --- /dev/null +++ b/src/main/java/org/kde/kdeconnect/UserInterface/List/CustomItem.java @@ -0,0 +1,20 @@ +package org.kde.kdeconnect.UserInterface.List; + +import android.view.LayoutInflater; +import android.view.View; +import android.widget.Button; + +public class CustomItem implements ListAdapter.Item { + + private final View view; + + public CustomItem(View v) { + this.view = v; + } + + @Override + public View inflateView(LayoutInflater layoutInflater) { + return view; + } + +} diff --git a/src/main/java/org/kde/kdeconnect/UserInterface/List/SmallEntryItem.java b/src/main/java/org/kde/kdeconnect/UserInterface/List/SmallEntryItem.java new file mode 100644 index 00000000..ef8bbfa5 --- /dev/null +++ b/src/main/java/org/kde/kdeconnect/UserInterface/List/SmallEntryItem.java @@ -0,0 +1,40 @@ +package org.kde.kdeconnect.UserInterface.List; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import org.kde.kdeconnect_tp.R; + +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; + } + + public SmallEntryItem(String title, View.OnClickListener clickListener) { + this.title = title; + this.clickListener = clickListener; + } + + @Override + public View inflateView(LayoutInflater layoutInflater) { + View v = layoutInflater.inflate(android.R.layout.simple_list_item_1, null); + + TextView titleView = (TextView)v.findViewById(android.R.id.text1); + if (titleView != null) titleView.setText(title); + if (clickListener != null) { + titleView.setOnClickListener(clickListener); + v.setBackgroundDrawable(layoutInflater.getContext().getResources().getDrawable(R.drawable.kitkatcompatselector_list_selector_holo_dark)); + + } + + return v; + } + +} diff --git a/src/main/res/layout/activity_device.xml b/src/main/res/layout/activity_device.xml index 0188d17a..77e2899e 100644 --- a/src/main/res/layout/activity_device.xml +++ b/src/main/res/layout/activity_device.xml @@ -1,26 +1,13 @@ - - - - - - - + /> \ No newline at end of file