Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Commit

Permalink
Added models for update request.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikDemyankov committed Jun 2, 2016
1 parent 9f1df5f commit 5001511
Show file tree
Hide file tree
Showing 3 changed files with 226 additions and 0 deletions.
2 changes: 2 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
<source-file src="src/android/src/com/nordnetab/chcp/main/config/ChcpXmlConfig.java" target-dir="src/com/nordnetab/chcp/main/config"/>
<source-file src="src/android/src/com/nordnetab/chcp/main/config/ChcpXmlConfigParser.java" target-dir="src/com/nordnetab/chcp/main/config"/>
<source-file src="src/android/src/com/nordnetab/chcp/main/config/XmlTags.java" target-dir="src/com/nordnetab/chcp/main/config"/>
<source-file src="src/android/src/com/nordnetab/chcp/main/config/FetchUpdateOptions.java" target-dir="src/com/nordnetab/chcp/main/config"/>

<!-- sources for package: com.nordnetab.chcp.events -->
<source-file src="src/android/src/com/nordnetab/chcp/main/events/AssetsInstallationErrorEvent.java" target-dir="src/com/nordnetab/chcp/main/events"/>
Expand Down Expand Up @@ -240,6 +241,7 @@
<source-file src="src/android/src/com/nordnetab/chcp/main/updater/UpdatesInstaller.java" target-dir="src/com/nordnetab/chcp/main/updater"/>
<source-file src="src/android/src/com/nordnetab/chcp/main/updater/UpdatesLoader.java" target-dir="src/com/nordnetab/chcp/main/updater"/>
<source-file src="src/android/src/com/nordnetab/chcp/main/updater/WorkerTask.java" target-dir="src/com/nordnetab/chcp/main/updater"/>
<source-file src="src/android/src/com/nordnetab/chcp/main/updater/UpdateRequest.java" target-dir="src/com/nordnetab/chcp/main/updater"/>

<!-- sources for package: com.nordnetab.chcp.js -->
<source-file src="src/android/src/com/nordnetab/chcp/main/js/PluginResultHelper.java" target-dir="src/com/nordnetab/chcp/main/js"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.nordnetab.chcp.main.config;

import java.util.Map;

/**
* Created by Nikolay Demyankov on 02.06.16.
* <p/>
* Model for fetch update options.
*/
public class FetchUpdateOptions {

private String configURL;
private Map<String, String> requestHeaders;

/**
* Constructor.
*
* @param configURL chcp.json config url on the server
* @param requestHeaders additional request headers.
*/
public FetchUpdateOptions(final String configURL, final Map<String, String> requestHeaders) {
this.configURL = configURL;
this.requestHeaders = requestHeaders;
}

/**
* Getter for chcp.json config url.
*
* @return config url
*/
public String getConfigURL() {
return configURL;
}

/**
* Setter for chcp.json config url.
* Use it in the child class to make object mutable, if needed so.
*
* @param configURL config url
*/
protected void setConfigURL(String configURL) {
this.configURL = configURL;
}

/**
* Getter for additional request headers.
*
* @return request headers
*/
public Map<String, String> getRequestHeaders() {
return requestHeaders;
}

/**
* Setter for request headers.
* Use it in the child class to make object mutable, if needed so.
*
* @param requestHeaders request headers
*/
protected void setRequestHeaders(Map<String, String> requestHeaders) {
this.requestHeaders = requestHeaders;
}
}
161 changes: 161 additions & 0 deletions src/android/src/com/nordnetab/chcp/main/updater/UpdateRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package com.nordnetab.chcp.main.updater;

import android.content.Context;

import com.nordnetab.chcp.main.model.PluginFilesStructure;

import java.util.Map;

/**
* Created by Nikolay Demyankov on 01.06.16.
* <p/>
* Model for update request parameters.
*/
public class UpdateRequest {

private String configURL;
private PluginFilesStructure currentReleaseFS;
private int currentNativeVersion;
private Map<String, String> requestHeaders;

/**
* Constructor.
*
* @param context application context
* @param configURL chcp.json url
* @param currentReleaseVersion current web content version
* @param currentNativeVersion current native interface version
* @param requestHeaders additional request headers, which will be added to all requests
*/
public UpdateRequest(final Context context,
final String configURL,
final String currentReleaseVersion,
final int currentNativeVersion,
final Map<String, String> requestHeaders) {
this.configURL = configURL;
this.currentNativeVersion = currentNativeVersion;
this.requestHeaders = requestHeaders;
this.currentReleaseFS = new PluginFilesStructure(context, currentReleaseVersion);
}

/**
* Get class builder.
*
* @param context application context
* @return builder
*/
public static Builder builder(final Context context) {
return new Builder(context);
}

/**
* URL to chcp.json config on the server.
*
* @return url to config
*/
public String getConfigURL() {
return configURL;
}

/**
* File structure of the current web release.
*
* @return file structure
*/
public PluginFilesStructure getCurrentReleaseFileStructure() {
return currentReleaseFS;
}

/**
* Current native interface version.
*
* @return native interface version.
*/
public int getCurrentNativeVersion() {
return currentNativeVersion;
}

/**
* Additional request headers.
*
* @return request headers
*/
public Map<String, String> getRequestHeaders() {
return requestHeaders;
}

// region Builder pattern

public static final class Builder {

private Context mContext;
private String configURL;
private String currentReleaseVersion;
private int currentNativeVersion;
private Map<String, String> requestHeaders;

/**
* Constructor.
*
* @param context application context
*/
public Builder(final Context context) {
mContext = context;
}

/**
* Setter for config url.
*
* @param configURL chcp.json config url
* @return builder
*/
public Builder setConfigURL(final String configURL) {
this.configURL = configURL;
return this;
}

/**
* Setter for current web release version.
*
* @param currentReleaseVersion version
* @return builder
*/
public Builder setCurrentReleaseVersion(final String currentReleaseVersion) {
this.currentReleaseVersion = currentReleaseVersion;
return this;
}

/**
* Setter for additional request headers.
*
* @param requestHeaders request headers.
* @return builder
*/
public Builder setRequestHeaders(final Map<String, String> requestHeaders) {
this.requestHeaders = requestHeaders;
return this;
}

/**
* Setter for current native interface version.
*
* @param currentNativeVersion native interface
* @return builder
*/
public Builder setCurrentNativeVersion(final int currentNativeVersion) {
this.currentNativeVersion = currentNativeVersion;
return this;
}

/**
* Build the actual object.
*
* @return update request instance
*/
public UpdateRequest build() {
return new UpdateRequest(mContext, configURL, currentReleaseVersion, currentNativeVersion, requestHeaders);
}
}

// endregion
}

0 comments on commit 5001511

Please sign in to comment.