2015-03-25 22:23:45 +01:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.adapter;
|
|
|
|
|
2016-06-15 19:56:34 +02:00
|
|
|
import android.support.v4.app.Fragment;
|
2015-03-25 22:23:45 +01:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2015-03-31 23:34:19 +02:00
|
|
|
import android.widget.ImageView;
|
2015-03-25 22:23:45 +01:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2016-06-15 19:56:34 +02:00
|
|
|
import com.woxthebox.draglistview.DragItemAdapter;
|
|
|
|
|
2015-05-01 01:49:43 +02:00
|
|
|
import java.util.List;
|
2016-06-15 19:56:34 +02:00
|
|
|
import java.util.UUID;
|
2015-05-01 01:49:43 +02:00
|
|
|
|
2016-06-15 19:56:34 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
2015-05-01 01:49:43 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
2016-06-15 19:56:34 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.appmanager.AbstractAppManagerFragment;
|
2015-09-24 14:45:21 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp;
|
2015-05-01 01:49:43 +02:00
|
|
|
|
2015-10-26 23:32:03 +01:00
|
|
|
/**
|
|
|
|
* Adapter for displaying GBDeviceApp instances.
|
|
|
|
*/
|
2015-03-25 22:23:45 +01:00
|
|
|
|
2016-06-15 19:56:34 +02:00
|
|
|
public class GBDeviceAppAdapter extends DragItemAdapter<GBDeviceApp, GBDeviceAppAdapter.ViewHolder> {
|
|
|
|
|
|
|
|
private final int mLayoutId;
|
|
|
|
private final int mGrabHandleId;
|
|
|
|
private final Fragment mParentFragment;
|
2015-03-25 22:23:45 +01:00
|
|
|
|
2016-06-15 19:56:34 +02:00
|
|
|
public GBDeviceAppAdapter(List<GBDeviceApp> list, int layoutId, int grabHandleId, boolean dragOnLongPress, Fragment parentFragment) {
|
|
|
|
super(dragOnLongPress);
|
|
|
|
mLayoutId = layoutId;
|
|
|
|
mGrabHandleId = grabHandleId;
|
|
|
|
mParentFragment = parentFragment;
|
|
|
|
setHasStableIds(true);
|
|
|
|
setItemList(list);
|
2015-03-25 22:23:45 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-06-15 19:56:34 +02:00
|
|
|
public long getItemId(int position) {
|
|
|
|
return mItemList.get(position).getUUID().getLeastSignificantBits();
|
|
|
|
}
|
2015-03-25 22:23:45 +01:00
|
|
|
|
2016-06-15 19:56:34 +02:00
|
|
|
@Override
|
|
|
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
2015-03-25 22:23:45 +01:00
|
|
|
|
2016-06-15 19:56:34 +02:00
|
|
|
View view = LayoutInflater.from(parent.getContext()).inflate(mLayoutId, parent, false);
|
|
|
|
return new ViewHolder(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(ViewHolder holder, int position) {
|
|
|
|
super.onBindViewHolder(holder, position);
|
|
|
|
GBDeviceApp deviceApp = mItemList.get(position);
|
2015-03-31 23:34:19 +02:00
|
|
|
|
2016-05-22 22:48:45 +02:00
|
|
|
|
2016-06-15 19:56:34 +02:00
|
|
|
holder.mDeviceAppVersionAuthorLabel.setText(GBApplication.getContext().getString(R.string.appversion_by_creator, deviceApp.getVersion(), deviceApp.getCreator()));
|
2016-05-22 22:48:45 +02:00
|
|
|
// FIXME: replace with small icons
|
|
|
|
String appNameLabelText = deviceApp.getName();
|
|
|
|
if (deviceApp.isInCache() || deviceApp.isOnDevice()) {
|
|
|
|
appNameLabelText += " (" + (deviceApp.isInCache() ? "C" : "")
|
|
|
|
+ (deviceApp.isOnDevice() ? "D" : "") + ")";
|
|
|
|
}
|
2016-06-15 19:56:34 +02:00
|
|
|
holder.mDeviceAppNameLabel.setText(appNameLabelText);
|
2016-05-22 22:48:45 +02:00
|
|
|
|
2015-03-31 23:34:19 +02:00
|
|
|
switch (deviceApp.getType()) {
|
2015-12-12 11:59:52 +01:00
|
|
|
case APP_GENERIC:
|
2016-06-15 19:56:34 +02:00
|
|
|
holder.mDeviceImageView.setImageResource(R.drawable.ic_watchapp);
|
2015-12-12 11:59:52 +01:00
|
|
|
break;
|
2015-04-10 22:26:52 +02:00
|
|
|
case APP_ACTIVITYTRACKER:
|
2016-06-15 19:56:34 +02:00
|
|
|
holder.mDeviceImageView.setImageResource(R.drawable.ic_activitytracker);
|
2015-04-10 22:26:52 +02:00
|
|
|
break;
|
2015-12-12 11:59:52 +01:00
|
|
|
case APP_SYSTEM:
|
2016-06-15 19:56:34 +02:00
|
|
|
holder.mDeviceImageView.setImageResource(R.drawable.ic_systemapp);
|
2015-12-12 11:59:52 +01:00
|
|
|
break;
|
2015-03-31 23:34:19 +02:00
|
|
|
case WATCHFACE:
|
2016-06-15 19:56:34 +02:00
|
|
|
holder.mDeviceImageView.setImageResource(R.drawable.ic_watchface);
|
2015-03-31 23:34:19 +02:00
|
|
|
break;
|
|
|
|
default:
|
2016-06-15 19:56:34 +02:00
|
|
|
holder.mDeviceImageView.setImageResource(R.drawable.ic_watchapp);
|
2015-03-31 23:34:19 +02:00
|
|
|
}
|
2016-06-15 19:56:34 +02:00
|
|
|
}
|
2015-03-25 22:23:45 +01:00
|
|
|
|
2016-06-15 19:56:34 +02:00
|
|
|
public class ViewHolder extends DragItemAdapter<GBDeviceApp, GBDeviceAppAdapter.ViewHolder>.ViewHolder {
|
|
|
|
TextView mDeviceAppVersionAuthorLabel;
|
|
|
|
TextView mDeviceAppNameLabel;
|
|
|
|
ImageView mDeviceImageView;
|
|
|
|
|
|
|
|
public ViewHolder(final View itemView) {
|
|
|
|
super(itemView, mGrabHandleId);
|
|
|
|
mDeviceAppVersionAuthorLabel = (TextView) itemView.findViewById(R.id.item_details);
|
|
|
|
mDeviceAppNameLabel = (TextView) itemView.findViewById(R.id.item_name);
|
|
|
|
mDeviceImageView = (ImageView) itemView.findViewById(R.id.item_image);
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void onItemClicked(View view) {
|
|
|
|
UUID uuid = mItemList.get(getAdapterPosition()).getUUID();
|
|
|
|
GBApplication.deviceService().onAppStart(uuid, true);
|
|
|
|
}
|
2015-03-25 22:23:45 +01:00
|
|
|
}
|
|
|
|
}
|