Skip to content

Commit

Permalink
Clean up AdbConfigurationPref
Browse files Browse the repository at this point in the history
Issue: n/a
  • Loading branch information
mlopatkin committed May 15, 2024
1 parent b068f03 commit 296c86a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
4 changes: 4 additions & 0 deletions src/name/mlopatkin/andlogview/config/SimpleClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public SimpleClient(String name, TypeToken<T> type, Supplier<? extends T> defaul
this.defaultSupplier = defaultSupplier;
}

public SimpleClient(String name, Class<T> type, Supplier<? extends T> defaultSupplier) {
this(name, TypeToken.get(type), defaultSupplier);
}

@Override
public T fromJson(Gson gson, JsonElement element) throws InvalidJsonContentException {
return gson.fromJson(element, type);
Expand Down
35 changes: 11 additions & 24 deletions src/name/mlopatkin/andlogview/preferences/AdbConfigurationPref.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@
import name.mlopatkin.andlogview.config.ConfigStorage;
import name.mlopatkin.andlogview.config.ConfigStorageClient;
import name.mlopatkin.andlogview.config.Configuration;
import name.mlopatkin.andlogview.config.NamedClient;
import name.mlopatkin.andlogview.config.Preference;
import name.mlopatkin.andlogview.config.SimpleClient;
import name.mlopatkin.andlogview.device.AdbLocation;
import name.mlopatkin.andlogview.utils.SystemPathResolver;

import com.google.common.base.MoreObjects;
import com.google.gson.Gson;
import com.google.gson.JsonElement;

import org.checkerframework.checker.nullness.qual.Nullable;

Expand All @@ -46,34 +44,23 @@ private static class AdbConfiguration {
final String location;
final boolean isAutoReconnectEnabled;

@SuppressWarnings("deprecation")
public AdbConfiguration() {
// Default configuration values
this(MoreObjects.firstNonNull(
Configuration.adb.executable(),
Configuration.adb.DEFAULT_EXECUTABLE),
Configuration.adb.isAutoReconnectEnabled());
}

public AdbConfiguration(String location, boolean isAutoReconnectEnabled) {
this.location = location;
this.isAutoReconnectEnabled = isAutoReconnectEnabled;
}
}

private static final ConfigStorageClient<AdbConfiguration> STORAGE_CLIENT =
new NamedClient<>("adb") {
@Override
public AdbConfiguration fromJson(Gson gson, JsonElement element) {
return gson.fromJson(element, AdbConfiguration.class);
}

@Override
@SuppressWarnings("deprecation")
public AdbConfiguration getDefault() {
return new AdbConfiguration(
MoreObjects.firstNonNull(
Configuration.adb.executable(),
Configuration.adb.DEFAULT_EXECUTABLE),
Configuration.adb.isAutoReconnectEnabled());
}

@Override
public JsonElement toJson(Gson gson, AdbConfiguration value) {
return gson.toJsonTree(value);
}
};
new SimpleClient<>("adb", AdbConfiguration.class, AdbConfiguration::new);

private final Preference<AdbConfiguration> preference;
private final SystemPathResolver systemPathResolver;
Expand Down

0 comments on commit 296c86a

Please sign in to comment.