1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-17 02:44:04 +02:00
Gadgetbridge/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAppAdapter.java

103 lines
3.8 KiB
Java
Raw Normal View History

package nodomain.freeyourgadget.gadgetbridge.adapter;
2016-06-15 19:56:34 +02:00
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
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;
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.
*/
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;
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);
}
@Override
2016-06-15 19:56:34 +02:00
public long getItemId(int position) {
return mItemList.get(position).getUUID().getLeastSignificantBits();
}
2016-06-15 19:56:34 +02:00
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
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);
2016-06-15 19:56:34 +02:00
holder.mDeviceAppVersionAuthorLabel.setText(GBApplication.getContext().getString(R.string.appversion_by_creator, deviceApp.getVersion(), deviceApp.getCreator()));
// 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);
switch (deviceApp.getType()) {
case APP_GENERIC:
2016-06-15 19:56:34 +02:00
holder.mDeviceImageView.setImageResource(R.drawable.ic_watchapp);
break;
case APP_ACTIVITYTRACKER:
2016-06-15 19:56:34 +02:00
holder.mDeviceImageView.setImageResource(R.drawable.ic_activitytracker);
break;
case APP_SYSTEM:
2016-06-15 19:56:34 +02:00
holder.mDeviceImageView.setImageResource(R.drawable.ic_systemapp);
break;
case WATCHFACE:
2016-06-15 19:56:34 +02:00
holder.mDeviceImageView.setImageResource(R.drawable.ic_watchface);
break;
default:
2016-06-15 19:56:34 +02:00
holder.mDeviceImageView.setImageResource(R.drawable.ic_watchapp);
}
2016-06-15 19:56:34 +02: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);
}
}
}