fix crash when rotating screen in AppManager
This commit is contained in:
parent
45fa930ac3
commit
1a9c40e790
|
@ -6,7 +6,6 @@ import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
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;
|
||||||
|
@ -40,7 +39,6 @@ import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.PebbleUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.PebbleUtils;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
|
||||||
|
|
||||||
|
|
||||||
public abstract class AbstractAppManagerFragment extends Fragment {
|
public abstract class AbstractAppManagerFragment extends Fragment {
|
||||||
|
@ -68,9 +66,7 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
if (action.equals(GBApplication.ACTION_QUIT)) {
|
if (action.equals(ACTION_REFRESH_APPLIST)) {
|
||||||
// finish();
|
|
||||||
} else if (action.equals(ACTION_REFRESH_APPLIST)) {
|
|
||||||
if (intent.hasExtra("app_count")) {
|
if (intent.hasExtra("app_count")) {
|
||||||
int appCount = intent.getIntExtra("app_count", 0);
|
int appCount = intent.getIntExtra("app_count", 0);
|
||||||
for (Integer i = 0; i < appCount; i++) {
|
for (Integer i = 0; i < appCount; i++) {
|
||||||
|
@ -103,8 +99,6 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private Prefs prefs;
|
|
||||||
|
|
||||||
protected final List<GBDeviceApp> appList = new ArrayList<>();
|
protected final List<GBDeviceApp> appList = new ArrayList<>();
|
||||||
private GBDeviceAppAdapter mGBDeviceAppAdapter;
|
private GBDeviceAppAdapter mGBDeviceAppAdapter;
|
||||||
protected GBDevice mGBDevice = null;
|
protected GBDevice mGBDevice = null;
|
||||||
|
@ -207,21 +201,16 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
|
super.onActivityCreated(savedInstanceState);
|
||||||
mGBDevice = ((AppManagerActivity) getActivity()).getGBDevice();
|
mGBDevice = ((AppManagerActivity) getActivity()).getGBDevice();
|
||||||
|
|
||||||
prefs = GBApplication.getPrefs();
|
|
||||||
|
|
||||||
refreshList();
|
|
||||||
IntentFilter filter = new IntentFilter();
|
IntentFilter filter = new IntentFilter();
|
||||||
filter.addAction(GBApplication.ACTION_QUIT);
|
|
||||||
filter.addAction(ACTION_REFRESH_APPLIST);
|
filter.addAction(ACTION_REFRESH_APPLIST);
|
||||||
|
|
||||||
LocalBroadcastManager.getInstance(getContext()).registerReceiver(mReceiver, filter);
|
LocalBroadcastManager.getInstance(getContext()).registerReceiver(mReceiver, filter);
|
||||||
|
|
||||||
GBApplication.deviceService().onAppInfoReq();
|
GBApplication.deviceService().onAppInfoReq();
|
||||||
|
refreshList();
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -252,7 +241,7 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sendOrderToDevice(String concatFilename) {
|
protected void sendOrderToDevice(String concatFilename) {
|
||||||
ArrayList<UUID> uuids = new ArrayList<UUID>();
|
ArrayList<UUID> uuids = new ArrayList<>();
|
||||||
for (GBDeviceApp gbDeviceApp : mGBDeviceAppAdapter.getItemList()) {
|
for (GBDeviceApp gbDeviceApp : mGBDeviceAppAdapter.getItemList()) {
|
||||||
uuids.add(gbDeviceApp.getUUID());
|
uuids.add(gbDeviceApp.getUUID());
|
||||||
}
|
}
|
||||||
|
@ -263,17 +252,6 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
||||||
GBApplication.deviceService().onAppReorder(uuids.toArray(new UUID[uuids.size()]));
|
GBApplication.deviceService().onAppReorder(uuids.toArray(new UUID[uuids.size()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeAppFromList(UUID uuid) {
|
|
||||||
for (final ListIterator<GBDeviceApp> iter = appList.listIterator(); iter.hasNext(); ) {
|
|
||||||
final GBDeviceApp app = iter.next();
|
|
||||||
if (app.getUUID().equals(uuid)) {
|
|
||||||
iter.remove();
|
|
||||||
mGBDeviceAppAdapter.notifyDataSetChanged();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean openPopupMenu(View view, int position) {
|
public boolean openPopupMenu(View view, int position) {
|
||||||
PopupMenu popupMenu = new PopupMenu(getContext(), view);
|
PopupMenu popupMenu = new PopupMenu(getContext(), view);
|
||||||
popupMenu.getMenuInflater().inflate(R.menu.appmanager_context, popupMenu.getMenu());
|
popupMenu.getMenuInflater().inflate(R.menu.appmanager_context, popupMenu.getMenu());
|
||||||
|
@ -288,7 +266,7 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
||||||
menu.removeItem(R.id.appmanager_health_activate);
|
menu.removeItem(R.id.appmanager_health_activate);
|
||||||
menu.removeItem(R.id.appmanager_health_deactivate);
|
menu.removeItem(R.id.appmanager_health_deactivate);
|
||||||
}
|
}
|
||||||
if (selectedApp.getType() == GBDeviceApp.Type.APP_SYSTEM) {
|
if (selectedApp.getType() == GBDeviceApp.Type.APP_SYSTEM || selectedApp.getType() == GBDeviceApp.Type.WATCHFACE_SYSTEM) {
|
||||||
menu.removeItem(R.id.appmanager_app_delete);
|
menu.removeItem(R.id.appmanager_app_delete);
|
||||||
}
|
}
|
||||||
if (!selectedApp.isConfigurable()) {
|
if (!selectedApp.isConfigurable()) {
|
||||||
|
@ -362,7 +340,6 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
LocalBroadcastManager.getInstance(getContext()).unregisterReceiver(mReceiver);
|
LocalBroadcastManager.getInstance(getContext()).unregisterReceiver(mReceiver);
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
package nodomain.freeyourgadget.gadgetbridge.activities.appmanager;
|
package nodomain.freeyourgadget.gadgetbridge.activities.appmanager;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.NavUtils;
|
import android.support.v4.app.NavUtils;
|
||||||
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
|
@ -19,6 +24,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractFragmentPagerAdapter;
|
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractFragmentPagerAdapter;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBFragmentActivity;
|
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBFragmentActivity;
|
||||||
|
@ -32,6 +38,18 @@ public class AppManagerActivity extends AbstractGBFragmentActivity {
|
||||||
|
|
||||||
private GBDevice mGBDevice = null;
|
private GBDevice mGBDevice = null;
|
||||||
|
|
||||||
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
String action = intent.getAction();
|
||||||
|
switch (action) {
|
||||||
|
case GBApplication.ACTION_QUIT:
|
||||||
|
finish();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public GBDevice getGBDevice() {
|
public GBDevice getGBDevice() {
|
||||||
return mGBDevice;
|
return mGBDevice;
|
||||||
}
|
}
|
||||||
|
@ -50,11 +68,17 @@ public class AppManagerActivity extends AbstractGBFragmentActivity {
|
||||||
throw new IllegalArgumentException("Must provide a device when invoking this activity");
|
throw new IllegalArgumentException("Must provide a device when invoking this activity");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IntentFilter filterLocal = new IntentFilter();
|
||||||
|
filterLocal.addAction(GBApplication.ACTION_QUIT);
|
||||||
|
filterLocal.addAction(GBDevice.ACTION_DEVICE_CHANGED);
|
||||||
|
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
|
||||||
|
|
||||||
// Set up the ViewPager with the sections adapter.
|
// Set up the ViewPager with the sections adapter.
|
||||||
ViewPager viewPager = (ViewPager) findViewById(R.id.appmanager_pager);
|
ViewPager viewPager = (ViewPager) findViewById(R.id.appmanager_pager);
|
||||||
|
if (viewPager != null) {
|
||||||
viewPager.setAdapter(getPagerAdapter());
|
viewPager.setAdapter(getPagerAdapter());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractFragmentPagerAdapter createFragmentPagerAdapter(FragmentManager fragmentManager) {
|
protected AbstractFragmentPagerAdapter createFragmentPagerAdapter(FragmentManager fragmentManager) {
|
||||||
|
@ -154,4 +178,10 @@ public class AppManagerActivity extends AbstractGBFragmentActivity {
|
||||||
}
|
}
|
||||||
return uuids;
|
return uuids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue