Skip to content

Commit

Permalink
RestApi: Add MinDiskFreeSerializer, MinDiskFreeDeserializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Catfriend1 committed Jan 26, 2019
1 parent d2a10e3 commit 3922f24
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
import com.nutomic.syncthingandroid.model.FolderStatus;
import com.nutomic.syncthingandroid.model.Gui;
import com.nutomic.syncthingandroid.model.IgnoredFolder;
import com.nutomic.syncthingandroid.model.MinDiskFree;
import com.nutomic.syncthingandroid.model.MinDiskFreeDeserializer;
import com.nutomic.syncthingandroid.model.MinDiskFreeSerializer;
import com.nutomic.syncthingandroid.model.Options;
import com.nutomic.syncthingandroid.model.PendingDevice;
import com.nutomic.syncthingandroid.model.PendingFolder;
Expand Down Expand Up @@ -215,7 +218,11 @@ public void reloadConfig() {
private void onReloadConfigComplete(String result) {
Boolean configParseSuccess;
synchronized(mConfigLock) {
mConfig = new Gson().fromJson(result, Config.class);
Gson gson = new GsonBuilder()
.registerTypeAdapter(MinDiskFree.class, new MinDiskFreeDeserializer())
.registerTypeAdapter(MinDiskFree.class, new MinDiskFreeSerializer())
.create();
mConfig = gson.fromJson(result, Config.class);
configParseSuccess = mConfig != null;
}
if (!configParseSuccess) {
Expand Down Expand Up @@ -420,10 +427,20 @@ public String getVersion() {

public List<Folder> getFolders() {
List<Folder> folders;
if (mConfig.folders.size() > 0) {
if (mConfig.folders.get(0).minDiskFree != null) {
Log.v(TAG, "A " + mConfig.folders.get(0).minDiskFree.unit);
}
}
synchronized (mConfigLock) {
folders = deepCopy(mConfig.folders, new TypeToken<List<Folder>>(){}.getType());
}
Collections.sort(folders, FOLDERS_COMPARATOR);
if (folders.size() > 0) {
if (folders.get(0).minDiskFree != null) {
Log.v(TAG, "B" + folders.get(0).minDiskFree.unit);
}
}
return folders;
}

Expand Down Expand Up @@ -589,7 +606,10 @@ public void editSettings(Gui newGui, Options newOptions) {
* This method uses Gson and only works with objects that can be converted with Gson.
*/
private <T> T deepCopy(T object, Type type) {
Gson gson = new Gson();
Gson gson = new GsonBuilder()
//.registerTypeAdapter(MinDiskFree.class, new MinDiskFreeSerializer())
//.registerTypeAdapter(MinDiskFree.class, new MinDiskFreeDeserializer())
.create();
return gson.fromJson(gson.toJson(object, type), type);
}

Expand Down

0 comments on commit 3922f24

Please sign in to comment.