Skip to content

Commit

Permalink
feat(android): add openFile to utils (#6895)
Browse files Browse the repository at this point in the history
* feat(android): add openFile to utils

* tests: move test_openFile() test to apps/ui-tests-app

Small changes to openFile() method
  • Loading branch information
Vados authored and ADjenkov committed Mar 5, 2019
1 parent 333db62 commit f8eee40
Show file tree
Hide file tree
Showing 13 changed files with 375 additions and 161 deletions.
11 changes: 11 additions & 0 deletions apps/app/App_Resources/Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true" >
<meta-data android:name="debugLayouts" android:value="true" />

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="org.nativescript.apps.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>

<activity
android:name="com.tns.NativeScriptActivity"
android:label="@string/title_activity_kimera"
Expand Down
4 changes: 4 additions & 0 deletions apps/app/App_Resources/Android/xml/provider_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
17 changes: 17 additions & 0 deletions apps/app/ui-tests-app/intent/main-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { EventData } from "tns-core-modules/data/observable";
import { SubMainPageViewModel } from "../sub-main-page-view-model";
import { WrapLayout } from "tns-core-modules/ui/layouts/wrap-layout";
import { Page } from "tns-core-modules/ui/page";

export function pageLoaded(args: EventData) {
const page = <Page>args.object;
const wrapLayout = <WrapLayout>page.getViewById("wrapLayoutWithExamples");
page.bindingContext = new SubMainPageViewModel(wrapLayout, loadExamples());
}

export function loadExamples() {
const examples = new Map<string, string>();
examples.set("open-file", "intent/open-file");

return examples;
}
6 changes: 6 additions & 0 deletions apps/app/ui-tests-app/intent/main-page.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Page loaded="pageLoaded">
<ScrollView orientation="vertical" row="1">
<WrapLayout id="wrapLayoutWithExamples"/>
</ScrollView>
</Page>
15 changes: 15 additions & 0 deletions apps/app/ui-tests-app/intent/open-file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { isIOS, isAndroid } from "tns-core-modules/platform";
import * as fs from "tns-core-modules/file-system/file-system";
import * as utils from "tns-core-modules/utils/utils";

export function openFile() {
let directory;
if (isIOS) {
directory = fs.knownFolders.ios.downloads();
} else if (isAndroid) {
directory = android.os.Environment.getExternalStorageDirectory().getAbsolutePath().toString();
}

const filePath = fs.path.join(directory, "Test_File_Open.txt");
utils.openFile(filePath);
}
5 changes: 5 additions & 0 deletions apps/app/ui-tests-app/intent/open-file.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Page navigatingTo="navigatingTo">
<GridLayout id="root">
<Button text="Open File" tap="openFile" height="40"></Button>
</GridLayout>
</Page>
1 change: 1 addition & 0 deletions apps/app/ui-tests-app/main-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function pageLoaded(args: EventData) {
examples.set("progress-bar", "progress-bar/main-page");
examples.set("date-picker", "date-picker/date-picker");
examples.set("nested-frames", "nested-frames/main-page");
examples.set("intent", "intent/main-page");
page.bindingContext = new MainPageViewModel(wrapLayout, examples);

const parent = page.getViewById("parentLayout");
Expand Down
1 change: 1 addition & 0 deletions tests/app/App_Resources/Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/AppTheme" >

<activity
android:name="com.tns.NativeScriptActivity"
android:label="@string/title_activity_kimera"
Expand Down
2 changes: 1 addition & 1 deletion tests/app/app/mainPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let executeTests = true;
trace.enable();
trace.addCategories(trace.categories.Test + "," + trace.categories.Error);

// When debugging
// // When debugging
// trace.setCategories(trace.categories.concat(
// trace.categories.Test,
// trace.categories.Navigation,
Expand Down

0 comments on commit f8eee40

Please sign in to comment.