Appearance
Android SDK
Setup
- Add this parameters to gradle.properties (Global Properties): It should be the same username and password that you use to log in on Stash or Jira.
username correllinkArtifactoryUsername
password correllinkArtifactoryPassword
- Add the dependency and repositories to your gradle.
compile 'com.correllink.vasat:android-sdk:1.9.3'
repositories {
mavenCentral()
maven {
url "https://dev.correllink.com/artifactory/libs-release-local"
credentials {
username correllinkArtifactoryUsername
password correllinkArtifactoryPassword
}
}
maven {
url "https://dev.correllink.com/artifactory/ext-release-local"
credentials {
username correllinkArtifactoryUsername
password correllinkArtifactoryPassword
}
}
}
- Also, because Vasat uses Active Android you need to add this to the manifest file.
xml
<meta-data
android:name="AA_DB_NAME"
android:value="your_db_name.db" />
<meta-data
android:name="AA_DB_VERSION"
android:value="1" />
- Create a class called App that extends Application class:
java
import android.app.Application;
import com.correllink.android.vasat.Vasat;
public class App extends Application {
@Override
public void onCreate() {
Vasat.init(this);
}
}
Also add android:name=".App" in the application tag on manifest file.
Initialize Vasat with the Vasat.init() method. This is an overloaded method so you can use either:
- Vasat.init( Application app )
- Vasat.init( Application app, String clientID, String clientSecret, String host ) If you use option 1. set the clientID, clientSecret and host in strings.xml. Use vasat_client_id, vasat_client_secret, vasat_hostname as the names in the strings.xml file.
xml
<string name="vasat_client_id">token</string>
<string name="vasat_client_secret">secret</string>
<string name="vasat_hostname">url (e.g: https://dev.correllink.com/vdog/) </string>
- If you use the second option you can pass in parameters as you please. For example, one way to store these values would be in the BuildConfig in your gradle.
buildTypes {
def STRING = "String"
def API_HOST = "API_HOST"
def CLIENT_ID = "CLIENT_ID"
def CLIENT_SECRET = "CLIENT_SECRET"
release AND/OR debug {
buildConfigField STRING, API_HOST, "the host name"
buildConfigField STRING, CLIENT_ID, "the client id"
buildConfigField STRING, CLIENT_SECRET, "the client secret"
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
- Then use these like this:
java
Vasat.init( Application app, BuildConfig.CLIENT_ID, BuildConfig.CLIENT_SECRET, BuildConfig.API_HOST );
- Create models. Your model class must extend BaseModel. It has by default some fields that you don't have to add like: name, desc, dateMate, etc.
java
public class Article extends BaseModel {
@Column(name = "key_col")
String key_col;
@Column(name = "textCol")
String text;
@Column(name = "owner")
User user;
}
Next we register the models that we would like to sync to the server. There are a number of ways this can be done.
Method chaining with: registerModel( Class<? extends BaseModel> model ) || registerModel( Class<? extends BaseModel> model, String searchQuery ). The 'searchQuery' is a SQLite query that you can use to filter the rows that you sync to and from the server. In the case where you do not set String Query, it is set to "".
javaVasat.init( app ) .registerModel( YourModel.class ) .registerModel( YourOtherModel.class, yourSearchQuery );
Passing a List of Pair with: registerModels(List<Pair<Class<? extends BaseModel>, String>> registeredModels)
javaList<Pair<Class<? extends BaseModel>, String>> modelList = new ArrayList(); modelList.add( new Pair( yourModel.class, yourSearchQuery ) ); modelList.add( new Pair( yourOtherModel.class, yourOtherSearchQuery ) ); Vasat.init( app ).registerModels(modelList);
Registering and Logging in
You can register a new user using the Vasat.signUpUser(). This is again, an overloaded method, and at minimum you are required to pass through:
String username, String password, String name, String email, and Resp<Session> callback.
The other method only requires one more additional parameter:
java
Map<String, String> properties.
Logging in
There are a couple of ways that you can login:
loginDevice() Logs you in as your device.
loginWithRemote() Login using OAuth.
loginUser() Login with a username and password.
Logging Out
Logout using the logOut() method. You can pass in a boolean to remove local data. Removing local data deletes your registered models and app files.
Changing Password
Change password using changePassword() method. This method takes a minimum of three parameters. String oldPass, String newPass and String confirmPass. The optional parameter is
Resp<JsonElement> callback.
Request Password Reset
You can request to reset the password using the requestPasswordReset() method. This method takes in two parameters:
String email and Resp<JsonElement> callback.
Syncing
Syncing to remote
Syncing to remote can be done with the syncToRemote() method. This method either takes:
java
syncToRemote( Resp<Map<Long, Pair<String, String>>> callback )
syncToRemote( Set<Class<? extends BaseModel>> classModels, Resp<Map<Long, Pair<String, String>>> callback )
If you use the first method, it syncs the models that have been registered using the registerModel() method earlier.
Otherwise if you use the second Method you can pass in a Set of the registered Models that you wish to sync.
java
Vasat.syncToRemote( new HashSet<Class<? extends BaseModel>>(Arrays.asList( YourModel.class, YourOtherModel.class ) ), new Resp<Map<Long, Pair<String, String>>>() {
@Override
protected void ok( Map<Long, Pair<String, String>> longPairMap ) {
//Do something when successful
}
@Override
protected void error() {
//Do something when error occurs
});
Syncing from remote
This method is overloaded and has many different combinations of parameters. The parameters this method takes are:
boolean expand - set to true if you want to get more data.
boolean force - set to true if you want to force the sync. Otherwise it will sync depending on when you have last synced.
boolean zipFile - set to true if you want the data as a zip.
List<Pair<Class<? extends BaseModel>, String>> classModels - List of classes that you wish to sync from the server. If this is not specified, the models that have already been registered using the registerModel() method will be synced.
Resp<Object> callback - a Resp Object.