2018-02-26 14:27:32 +01:00
|
|
|
/* Copyright (C) 2015-2018 Andreas Shimokawa, Carsten Pfeiffer, Daniele
|
2017-04-26 00:14:25 +02:00
|
|
|
Gobbetti
|
2017-03-10 14:53:19 +01:00
|
|
|
|
|
|
|
This file is part of Gadgetbridge.
|
|
|
|
|
|
|
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Gadgetbridge is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
2015-03-25 22:23:45 +01:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.adapter;
|
|
|
|
|
2017-03-31 18:17:53 +02:00
|
|
|
import android.support.v7.widget.RecyclerView;
|
2015-03-25 22:23:45 +01:00
|
|
|
import android.view.LayoutInflater;
|
2017-03-31 18:17:53 +02:00
|
|
|
import android.view.MotionEvent;
|
2015-03-25 22:23:45 +01:00
|
|
|
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;
|
|
|
|
|
2017-03-31 18:17:53 +02:00
|
|
|
import java.util.Collections;
|
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
|
|
|
|
2017-03-31 18:17:53 +02:00
|
|
|
public class GBDeviceAppAdapter extends RecyclerView.Adapter<GBDeviceAppAdapter.AppViewHolder> {
|
2016-06-15 19:56:34 +02:00
|
|
|
|
|
|
|
private final int mLayoutId;
|
2017-03-31 18:17:53 +02:00
|
|
|
private final List<GBDeviceApp> appList;
|
2016-06-15 22:29:30 +02:00
|
|
|
private final AbstractAppManagerFragment mParentFragment;
|
2015-03-25 22:23:45 +01:00
|
|
|
|
2017-03-31 18:17:53 +02:00
|
|
|
public List<GBDeviceApp> getAppList() {
|
|
|
|
return appList;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GBDeviceAppAdapter(List<GBDeviceApp> list, int layoutId, AbstractAppManagerFragment parentFragment) {
|
2016-06-15 19:56:34 +02:00
|
|
|
mLayoutId = layoutId;
|
2017-03-31 18:17:53 +02:00
|
|
|
appList = list;
|
2016-06-15 19:56:34 +02:00
|
|
|
mParentFragment = parentFragment;
|
2015-03-25 22:23:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-06-15 19:56:34 +02:00
|
|
|
public long getItemId(int position) {
|
2017-03-31 18:17:53 +02:00
|
|
|
return appList.get(position).getUUID().getLeastSignificantBits();
|
2016-06-15 19:56:34 +02:00
|
|
|
}
|
2015-03-25 22:23:45 +01:00
|
|
|
|
2016-06-15 19:56:34 +02:00
|
|
|
@Override
|
2017-03-31 18:17:53 +02:00
|
|
|
public int getItemCount() {
|
|
|
|
return appList.size();
|
|
|
|
}
|
2015-03-25 22:23:45 +01:00
|
|
|
|
2017-03-31 18:17:53 +02:00
|
|
|
@Override
|
|
|
|
public GBDeviceAppAdapter.AppViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
2016-06-15 19:56:34 +02:00
|
|
|
View view = LayoutInflater.from(parent.getContext()).inflate(mLayoutId, parent, false);
|
2017-03-31 18:17:53 +02:00
|
|
|
return new AppViewHolder(view);
|
2016-06-15 19:56:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 18:17:53 +02:00
|
|
|
public void onBindViewHolder(final AppViewHolder holder, int position) {
|
|
|
|
final GBDeviceApp deviceApp = appList.get(position);
|
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();
|
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
|
|
|
}
|
2017-03-31 18:17:53 +02:00
|
|
|
|
|
|
|
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
UUID uuid = deviceApp.getUUID();
|
|
|
|
GBApplication.deviceService().onAppStart(uuid, true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View view) {
|
|
|
|
return mParentFragment.openPopupMenu(view, deviceApp);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
holder.mDragHandle.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View view, MotionEvent motionEvent) {
|
|
|
|
mParentFragment.startDragging(holder);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onItemMove(int from, int to) {
|
|
|
|
Collections.swap(appList, from, to);
|
|
|
|
notifyItemMoved(from, to);
|
2016-06-15 19:56:34 +02:00
|
|
|
}
|
2015-03-25 22:23:45 +01:00
|
|
|
|
2017-03-31 18:17:53 +02:00
|
|
|
public class AppViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
final TextView mDeviceAppVersionAuthorLabel;
|
|
|
|
final TextView mDeviceAppNameLabel;
|
|
|
|
final ImageView mDeviceImageView;
|
|
|
|
final ImageView mDragHandle;
|
2016-06-15 19:56:34 +02:00
|
|
|
|
2017-03-31 18:17:53 +02:00
|
|
|
AppViewHolder(View itemView) {
|
|
|
|
super(itemView);
|
2016-06-15 19:56:34 +02:00
|
|
|
mDeviceAppVersionAuthorLabel = (TextView) itemView.findViewById(R.id.item_details);
|
|
|
|
mDeviceAppNameLabel = (TextView) itemView.findViewById(R.id.item_name);
|
|
|
|
mDeviceImageView = (ImageView) itemView.findViewById(R.id.item_image);
|
2017-03-31 18:17:53 +02:00
|
|
|
mDragHandle = (ImageView) itemView.findViewById(R.id.drag_handle);
|
2016-06-15 19:56:34 +02:00
|
|
|
}
|
2016-06-15 22:29:30 +02:00
|
|
|
|
2015-03-25 22:23:45 +01:00
|
|
|
}
|
2017-03-31 18:17:53 +02:00
|
|
|
|
2015-03-25 22:23:45 +01:00
|
|
|
}
|