Skip to content

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kolbasa committed Dec 10, 2021
1 parent a1e5c63 commit 0883294
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class HomePage {
}
```

([**Complete code sample**](https://github.com/kolbasa/cordova-plugin-apkupdater/wiki/Sample-Implementation))
([**Complete code sample**](doc/sample/Implementation.md))

### Cordova

Expand Down Expand Up @@ -393,7 +393,7 @@ export class HomePage {
}
```

([**Complete code sample**](https://github.com/kolbasa/cordova-plugin-apkupdater/wiki/Sample-Versioning))
([**Complete code sample**](doc/sample/Versioning.md))

<br>

Expand Down
55 changes: 55 additions & 0 deletions doc/sample/Implementation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
This is a sample implementation in a fresh `Ionic + Angular` Project:

`ionic info`:
```
Ionic:
Ionic CLI : 6.17.0
Ionic Framework : @ionic/angular 5.6.14
@angular-devkit/build-angular : 12.1.4
@angular-devkit/schematics : 12.2.2
@angular/cli : 12.1.4
@ionic/angular-toolkit : 4.0.0
Cordova:
Cordova CLI : 10.0.0
Cordova Platforms : android 9.1.0
```

`src/app/home/home.page.spec.ts`:

```ts
import {Platform} from '@ionic/angular';
import {Component} from '@angular/core';

import ApkUpdater from 'cordova-plugin-apkupdater';

@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})

export class HomePage {

remote = 'https://raw.githubusercontent.com/kolbasa/cordova-plugin-apkupdater-demo/master/update';

constructor(public platform: Platform) {
platform.ready().then(this.update.bind(this)).catch(console.error);
}

async update() {
await ApkUpdater.download(
this.remote + '/update.zip',
{
zipPassword: 'aDzEsCceP3BPO5jy',
onDownloadProgress: console.log,
onUnzipProgress: console.log
}
);
await ApkUpdater.install();
}

}
```
86 changes: 86 additions & 0 deletions doc/sample/Versioning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
This is a sample implementation in a fresh `Ionic + Angular` Project:

`ionic info`:
```
Ionic:
Ionic CLI : 6.17.0
Ionic Framework : @ionic/angular 5.6.14
@angular-devkit/build-angular : 12.1.4
@angular-devkit/schematics : 12.2.2
@angular/cli : 12.1.4
@ionic/angular-toolkit : 4.0.0
Cordova:
Cordova CLI : 10.0.0
Cordova Platforms : android 9.1.0
```

`src/app/home/home.page.spec.ts`:

```ts
import {Platform} from '@ionic/angular';
import {Component} from '@angular/core';
import {HttpClient} from '@angular/common/http';

import ApkUpdater, {Update} from 'cordova-plugin-apkupdater';

@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})

export class HomePage {

remote = 'https://raw.githubusercontent.com/kolbasa/cordova-plugin-apkupdater-demo/master/update';

constructor(private http: HttpClient, public platform: Platform) {
platform.ready().then(this.update.bind(this)).catch(console.error);
}

async update() {
const manifest = await this.http.get<Update>(this.remote + '/update.json').toPromise();

const remoteVersion = manifest.app.version.code;
const installedVersion = (await ApkUpdater.getInstalledVersion()).version.code;

if (remoteVersion > installedVersion) {
await ApkUpdater.download(
this.remote + '/update.zip',
{
zipPassword: 'aDzEsCceP3BPO5jy',
onDownloadProgress: console.log,
onUnzipProgress: console.log
}
);
await ApkUpdater.install();
}
}

}
```

`src/app/app.module.ts`:
```js
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';

import { IonicModule, IonicRouteStrategy } from '@ionic/angular';

import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';

import { HttpClientModule } from '@angular/common/http';

@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule, HttpClientModule],
providers: [{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }],
bootstrap: [AppComponent],
})
export class AppModule {}
```

0 comments on commit 0883294

Please sign in to comment.