This repository has been archived by the owner on Oct 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f1df5f
commit 5001511
Showing
3 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/android/src/com/nordnetab/chcp/main/config/FetchUpdateOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
161
src/android/src/com/nordnetab/chcp/main/updater/UpdateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |