1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 21:06:50 +01:00

Xiaomi: Keep only watchface tab in app management

This commit is contained in:
José Rebelo 2023-10-22 11:06:27 +01:00
parent a895a6aae7
commit 1b645f44d7
4 changed files with 66 additions and 10 deletions

View File

@ -45,6 +45,7 @@ import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractFragmentPagerAdapter;
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBFragmentActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.FwAppInstallerActivity;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
@ -56,6 +57,8 @@ public class AppManagerActivity extends AbstractGBFragmentActivity {
private GBDevice mGBDevice = null;
private List<String> enabledTabsList;
public GBDevice getGBDevice() {
return mGBDevice;
}
@ -75,6 +78,20 @@ public class AppManagerActivity extends AbstractGBFragmentActivity {
throw new IllegalArgumentException("Must provide a device when invoking this activity");
}
final DeviceCoordinator coordinator = mGBDevice.getDeviceCoordinator();
enabledTabsList = new ArrayList<>();
if (coordinator.supportsCachedAppManagement(mGBDevice)) {
enabledTabsList.add("cache");
}
if (coordinator.supportsInstalledAppManagement(mGBDevice)) {
enabledTabsList.add("apps");
}
if (coordinator.supportsWatchfaceManagement(mGBDevice)) {
enabledTabsList.add("watchfaces");
}
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
assert fab != null;
fab.setOnClickListener(new View.OnClickListener() {
@ -114,12 +131,12 @@ public class AppManagerActivity extends AbstractGBFragmentActivity {
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
switch (position) {
case 0:
switch (enabledTabsList.get(position)) {
case "cache":
return new AppManagerFragmentCache();
case 1:
case "apps":
return new AppManagerFragmentInstalledApps();
case 2:
case "watchfaces":
return new AppManagerFragmentInstalledWatchfaces();
}
return null;
@ -127,19 +144,18 @@ public class AppManagerActivity extends AbstractGBFragmentActivity {
@Override
public int getCount() {
return 3;
return enabledTabsList.toArray().length;
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
switch (enabledTabsList.get(position)) {
case "cache":
return getString(R.string.appmanager_cached_watchapps_watchfaces);
case 1:
case "apps":
return getString(R.string.appmanager_installed_watchapps);
case 2:
case "watchfaces":
return getString(R.string.appmanager_installed_watchfaces);
case 3:
}
return super.getPageTitle(position);
}

View File

@ -314,6 +314,27 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator {
return false;
}
@Override
public boolean supportsCachedAppManagement(final GBDevice device) {
try {
return supportsAppsManagement(device) && getAppCacheDir() != null;
} catch (final Exception e) {
// we failed, but still tried, so it's supported..
LOG.error("Failed to get app cache dir", e);
return true;
}
}
@Override
public boolean supportsInstalledAppManagement(final GBDevice device) {
return supportsAppsManagement(device);
}
@Override
public boolean supportsWatchfaceManagement(final GBDevice device) {
return supportsAppsManagement(device);
}
@Nullable
@Override
public Class<? extends Activity> getAppsManagementActivity() {

View File

@ -353,6 +353,10 @@ public interface DeviceCoordinator {
*/
boolean supportsAppsManagement(GBDevice device);
boolean supportsCachedAppManagement(GBDevice device);
boolean supportsInstalledAppManagement(GBDevice device);
boolean supportsWatchfaceManagement(GBDevice device);
/**
* Returns the Activity class that will be used to manage device apps.
*

View File

@ -134,6 +134,21 @@ public abstract class XiaomiCoordinator extends AbstractBLEDeviceCoordinator {
return true;
}
@Override
public boolean supportsCachedAppManagement(GBDevice device) {
return false;
}
@Override
public boolean supportsInstalledAppManagement(GBDevice device) {
return false;
}
@Override
public boolean supportsWatchfaceManagement(GBDevice device) {
return supportsAppsManagement(device);
}
@Override
public Class<? extends Activity> getAppsManagementActivity() {
return AppManagerActivity.class;