mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-24 00:00:47 +02:00
make appmanager usable again
This commit is contained in:
parent
b5693bcb45
commit
7690ad3af6
@ -10,12 +10,12 @@ import android.support.annotation.Nullable;
|
|||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.view.ContextMenu;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
import android.widget.PopupMenu;
|
||||||
|
|
||||||
import com.woxthebox.draglistview.DragListView;
|
import com.woxthebox.draglistview.DragListView;
|
||||||
|
|
||||||
@ -95,7 +95,6 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
|||||||
|
|
||||||
protected final List<GBDeviceApp> appList = new ArrayList<>();
|
protected final List<GBDeviceApp> appList = new ArrayList<>();
|
||||||
private GBDeviceAppAdapter mGBDeviceAppAdapter;
|
private GBDeviceAppAdapter mGBDeviceAppAdapter;
|
||||||
private GBDeviceApp selectedApp = null;
|
|
||||||
protected GBDevice mGBDevice = null;
|
protected GBDevice mGBDevice = null;
|
||||||
|
|
||||||
protected List<GBDeviceApp> getSystemApps() {
|
protected List<GBDeviceApp> getSystemApps() {
|
||||||
@ -175,18 +174,28 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
|||||||
|
|
||||||
DragListView appListView = (DragListView) (rootView.findViewById(R.id.appListView));
|
DragListView appListView = (DragListView) (rootView.findViewById(R.id.appListView));
|
||||||
appListView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
appListView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||||
mGBDeviceAppAdapter = new GBDeviceAppAdapter(appList, R.layout.item_with_details, R.id.item_image, true, this);
|
mGBDeviceAppAdapter = new GBDeviceAppAdapter(appList, R.layout.item_with_details, R.id.item_image, this.getContext(), this);
|
||||||
appListView.setAdapter(mGBDeviceAppAdapter, false);
|
appListView.setAdapter(mGBDeviceAppAdapter, false);
|
||||||
//registerForContextMenu(appListView);
|
appListView.setCanDragHorizontally(false);
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void removeAppFromList(UUID uuid) {
|
||||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
for (final ListIterator<GBDeviceApp> iter = appList.listIterator(); iter.hasNext(); ) {
|
||||||
super.onCreateContextMenu(menu, v, menuInfo);
|
final GBDeviceApp app = iter.next();
|
||||||
getActivity().getMenuInflater().inflate(R.menu.appmanager_context, menu);
|
if (app.getUUID().equals(uuid)) {
|
||||||
AdapterView.AdapterContextMenuInfo acmi = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
iter.remove();
|
||||||
selectedApp = appList.get(acmi.position);
|
mGBDeviceAppAdapter.notifyDataSetChanged();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean openPopupMenu(View view, int position) {
|
||||||
|
PopupMenu popupMenu = new PopupMenu(getContext(), view);
|
||||||
|
popupMenu.getMenuInflater().inflate(R.menu.appmanager_context, popupMenu.getMenu());
|
||||||
|
Menu menu = popupMenu.getMenu();
|
||||||
|
final GBDeviceApp selectedApp = appList.get(position);
|
||||||
|
|
||||||
if (!selectedApp.isInCache()) {
|
if (!selectedApp.isInCache()) {
|
||||||
menu.removeItem(R.id.appmanager_app_reinstall);
|
menu.removeItem(R.id.appmanager_app_reinstall);
|
||||||
@ -202,25 +211,21 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
|||||||
if (!selectedApp.isConfigurable()) {
|
if (!selectedApp.isConfigurable()) {
|
||||||
menu.removeItem(R.id.appmanager_app_configure);
|
menu.removeItem(R.id.appmanager_app_configure);
|
||||||
}
|
}
|
||||||
if (mGBDevice != null && !mGBDevice.getFirmwareVersion().startsWith("v3")) {
|
if (!mGBDevice.getFirmwareVersion().startsWith("v3")) {
|
||||||
menu.removeItem(R.id.appmanager_app_move_to_top);
|
menu.removeItem(R.id.appmanager_app_move_to_top);
|
||||||
}
|
}
|
||||||
menu.setHeaderTitle(selectedApp.getName());
|
//menu.setHeaderTitle(selectedApp.getName());
|
||||||
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
return onContextItemSelected(item, selectedApp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
popupMenu.show();
|
||||||
|
return false; // FIXME: whats that for?
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeAppFromList(UUID uuid) {
|
public boolean onContextItemSelected(MenuItem item, GBDeviceApp selectedApp) {
|
||||||
for (final ListIterator<GBDeviceApp> iter = appList.listIterator(); iter.hasNext(); ) {
|
|
||||||
final GBDeviceApp app = iter.next();
|
|
||||||
if (app.getUUID().equals(uuid)) {
|
|
||||||
iter.remove();
|
|
||||||
mGBDeviceAppAdapter.notifyDataSetChanged();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.appmanager_health_deactivate:
|
case R.id.appmanager_health_deactivate:
|
||||||
case R.id.appmanager_app_delete_cache:
|
case R.id.appmanager_app_delete_cache:
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.adapter;
|
package nodomain.freeyourgadget.gadgetbridge.adapter;
|
||||||
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.content.Context;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -25,16 +25,17 @@ public class GBDeviceAppAdapter extends DragItemAdapter<GBDeviceApp, GBDeviceApp
|
|||||||
|
|
||||||
private final int mLayoutId;
|
private final int mLayoutId;
|
||||||
private final int mGrabHandleId;
|
private final int mGrabHandleId;
|
||||||
private final Fragment mParentFragment;
|
private final Context mContext;
|
||||||
|
private final AbstractAppManagerFragment mParentFragment;
|
||||||
|
|
||||||
public GBDeviceAppAdapter(List<GBDeviceApp> list, int layoutId, int grabHandleId, boolean dragOnLongPress, Fragment parentFragment) {
|
public GBDeviceAppAdapter(List<GBDeviceApp> list, int layoutId, int grabHandleId, Context context, AbstractAppManagerFragment parentFragment) {
|
||||||
super(dragOnLongPress);
|
super(true); // longpress
|
||||||
mLayoutId = layoutId;
|
mLayoutId = layoutId;
|
||||||
mGrabHandleId = grabHandleId;
|
mGrabHandleId = grabHandleId;
|
||||||
|
mContext = context;
|
||||||
mParentFragment = parentFragment;
|
mParentFragment = parentFragment;
|
||||||
setHasStableIds(true);
|
setHasStableIds(true);
|
||||||
setItemList(list);
|
setItemList(list);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -93,10 +94,16 @@ public class GBDeviceAppAdapter extends DragItemAdapter<GBDeviceApp, GBDeviceApp
|
|||||||
mDeviceAppNameLabel = (TextView) itemView.findViewById(R.id.item_name);
|
mDeviceAppNameLabel = (TextView) itemView.findViewById(R.id.item_name);
|
||||||
mDeviceImageView = (ImageView) itemView.findViewById(R.id.item_image);
|
mDeviceImageView = (ImageView) itemView.findViewById(R.id.item_image);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemClicked(View view) {
|
public void onItemClicked(View view) {
|
||||||
UUID uuid = mItemList.get(getAdapterPosition()).getUUID();
|
UUID uuid = mItemList.get(getAdapterPosition()).getUUID();
|
||||||
GBApplication.deviceService().onAppStart(uuid, true);
|
GBApplication.deviceService().onAppStart(uuid, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onItemLongClicked(View view) {
|
||||||
|
return mParentFragment.openPopupMenu(view, getAdapterPosition());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user