Skip to content

Commit f3ef6b3

Browse files
Merge pull request #66 from burningthumb/master
Update README.md to reflect v0.4.0
2 parents cabc3a6 + 2053840 commit f3ef6b3

File tree

1 file changed

+124
-42
lines changed

1 file changed

+124
-42
lines changed

README.md

Lines changed: 124 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,113 @@ repositories {
2020
}
2121
2222
dependencies {
23-
implementation "com.github.nextcloud:Android-SingleSignOn:0.3.0"
23+
implementation 'com.google.code.gson:gson:2.8.5'
24+
implementation "com.github.nextcloud:Android-SingleSignOn:0.4.0"
2425
}
2526
```
2627
2) To choose an account, include the following code in your login dialog:
2728

29+
From an Activity
30+
2831
```java
2932
private void openAccountChooser() {
30-
try {
31-
AccountImporter.PickNewAccount(currentFragment);
32-
} catch (NextcloudFilesAppNotInstalledException e) {
33-
UiExceptionManager.ShowDialogForException(getActivity(), e);
34-
}
33+
try {
34+
AccountImporter.pickNewAccount(this);
35+
}
36+
catch (NextcloudFilesAppNotInstalledException e) {
37+
UiExceptionManager.showDialogForException(this, e);
38+
} catch (AndroidGetAccountsPermissionNotGranted e) {
39+
UiExceptionManager.showDialogForException(this, e);
40+
}
41+
}
42+
```
43+
From a Fragment
44+
45+
```java
46+
private void openAccountChooser() {
47+
try {
48+
AccountImporter.pickNewAccount(currentFragment);
49+
} catch (NextcloudFilesAppNotInstalledException e) {
50+
UiExceptionManager.showDialogForException(this, e);
51+
} catch (AndroidGetAccountsPermissionNotGranted e) {
52+
UiExceptionManager.showDialogForException(this, e);
53+
}
3554
}
55+
```
56+
3) To handle the result of the Account Chooser, include the following:
3657

58+
From an Activity
59+
60+
```java
61+
@Override
62+
public void onActivityResult(int requestCode, int resultCode, Intent data) {
63+
super.onActivityResult(requestCode, resultCode, data);
64+
AccountImporter.onActivityResult(requestCode, resultCode, data, this, new AccountImporter.IAccountAccessGranted() {
65+
66+
NextcloudAPI.ApiConnectedListener callback = new NextcloudAPI.ApiConnectedListener() {
67+
@Override
68+
public void onConnected() {
69+
// ignore this one..
70+
}
71+
72+
@Override
73+
public void onError(Exception ex) {
74+
// TODO handle errors
75+
}
76+
};
77+
78+
@Override
79+
public void accountAccessGranted(SingleSignOnAccount account) {
80+
81+
Context l_context = getApplicationContext();
82+
83+
// As this library supports multiple accounts we created some helper methods if you only want to use one.
84+
// The following line stores the selected account as the "default" account which can be queried by using
85+
// the SingleAccountHelper.getCurrentSingleSignOnAccount(context) method
86+
SingleAccountHelper.setCurrentAccount(l_context, account.name);
87+
88+
// Get the "default" account
89+
SingleSignOnAccount ssoAccount = null;
90+
try
91+
{
92+
ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(l_context);
93+
} catch (NextcloudFilesAppAccountNotFoundException e)
94+
{
95+
UiExceptionManager.showDialogForException(l_context, e);
96+
} catch (NoCurrentAccountSelectedException e)
97+
{
98+
UiExceptionManager.showDialogForException(l_context, e);
99+
}
100+
101+
NextcloudAPI nextcloudAPI = new NextcloudAPI(l_context, ssoAccount, new GsonBuilder().create(), callback);
102+
103+
// TODO ... (see code in section 4 and below)
104+
}
105+
});
106+
}
107+
```
108+
109+
From a Fragment
110+
111+
```java
37112
@Override
38113
public void onActivityResult(int requestCode, int resultCode, Intent data) {
39114
super.onActivityResult(requestCode, resultCode, data);
40115

41116
AccountImporter.onActivityResult(requestCode, resultCode, data, LoginDialogFragment.this, new AccountImporter.IAccountAccessGranted() {
117+
118+
NextcloudAPI.ApiConnectedListener callback = new NextcloudAPI.ApiConnectedListener() {
119+
@Override
120+
public void onConnected() {
121+
// ignore this one..
122+
}
123+
124+
@Override
125+
public void onError(Exception ex) {
126+
// TODO handle errors
127+
}
128+
};
129+
42130
@Override
43131
public void accountAccessGranted(SingleSignOnAccount account) {
44132
// As this library supports multiple accounts we created some helper methods if you only want to use one.
@@ -50,23 +138,14 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
50138
SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(context);
51139
NextcloudAPI nextcloudAPI = new NextcloudAPI(context, ssoAccount, new GsonBuilder().create(), callback);
52140

53-
// TODO ... (see code in section 3 and below)
141+
// TODO ... (see code in section 4 and below)
54142
}
55143
});
56-
57-
NextcloudAPI.ApiConnectedListener callback = new NextcloudAPI.ApiConnectedListener() {
58-
@Override
59-
public void onConnected() {
60-
// ignore this one..
61-
}
62-
63-
@Override
64-
public void onError(Exception ex) {
65-
// TODO handle errors
66-
}
67-
}
68144
}
145+
```
146+
From both an Activity and Fragment
69147

148+
```java
70149
@Override
71150
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
72151
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
@@ -77,7 +156,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
77156
// Complete example: https://github.com/nextcloud/news-android/blob/master/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/LoginDialogFragment.java
78157
```
79158

80-
3) How to get account information?
159+
4) How to get account information?
81160

82161
```java
83162
// If you stored the "default" account using setCurrentAccount(...) you can get the account by using the following line:
@@ -92,20 +171,22 @@ AccountImporter.getSingleSignOnAccount(context, accountName);
92171
// ssoAccount.url
93172
```
94173

95-
4) How to make a network request?
174+
5) How to make a network request?
175+
176+
You'll notice that there is an callback parameter in the constructor of the `NextcloudAPI`.
96177

97-
You'll notice that there is an callback parameter in the constructor of the `NextcloudAPI`.
98-
```java
178+
```java
99179
public NextcloudAPI(Context context, SingleSignOnAccount account, Gson gson, ApiConnectedListener callback) {
100-
```
180+
```
181+
101182

102-
You can use this callback to subscribe to errors that might occur during the initialization of the API. You can start making requests to the API as soon as you instantiated the `NextcloudAPI` object. For a minimal example to get started (without retrofit) take a look at section 4.2. The callback method `onConnected` will be called once the connection to the files app is established. You can start making calls to the api before that callback is fired as the library will queue your calls until the connection is established.
183+
You can use this callback to subscribe to errors that might occur during the initialization of the API. You can start making requests to the API as soon as you instantiated the `NextcloudAPI` object. For a minimal example to get started (without retrofit) take a look at section 4.2. The callback method `onConnected` will be called once the connection to the files app is established. You can start making calls to the api before that callback is fired as the library will queue your calls until the connection is established.
103184

104-
4.1) **Using Retrofit**
185+
5.1) **Using Retrofit**
105186

106-
4.1.1) Before using this single sign on library, your interface for your retrofit API might look like this:
187+
5.1.1) Before using this single sign on library, your interface for your retrofit API might look like this:
107188

108-
```java
189+
```java
109190
public interface API {
110191

111192
String mApiEndpoint = "/index.php/apps/news/api/v1-2/";
@@ -121,10 +202,11 @@ AccountImporter.getSingleSignOnAccount(context, accountName);
121202

122203
123204
}
124-
```
205+
```
125206

126-
You might instantiate your retrofit `API` by using something like this:
127-
```java
207+
You might instantiate your retrofit `API` by using something like this:
208+
209+
```java
128210
public class ApiProvider {
129211

130212
private API mApi;
@@ -133,11 +215,11 @@ AccountImporter.getSingleSignOnAccount(context, accountName);
133215
mApi = retrofit.create(API.class);
134216
}
135217
}
136-
```
218+
```
137219

138-
4.1.2) Use of new API using the nextcloud app network stack
220+
5.1.2) Use of new API using the nextcloud app network stack
139221

140-
```java
222+
```java
141223
public class ApiProvider {
142224

143225
private API mApi;
@@ -149,17 +231,17 @@ AccountImporter.getSingleSignOnAccount(context, accountName);
149231

150232
}
151233
}
152-
```
234+
```
153235

154-
Enjoy! If you're already using retrofit, you don't need to modify your application logic. Just exchange the API and you're good to go!
236+
Enjoy! If you're already using retrofit, you don't need to modify your application logic. Just exchange the API and you're good to go!
155237
156-
Note: If you need a different mapping between your json-structure and your java-structure you might want to create a custom type adapter using `new GsonBuilder().create().registerTypeAdapter(...)`. Take a look at [this](https://github.com/nextcloud/news-android/blob/783836390b4c27aba285bad1441b53154df16685/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/GsonConfig.java) example for more information.
238+
Note: If you need a different mapping between your json-structure and your java-structure you might want to create a custom type adapter using `new GsonBuilder().create().registerTypeAdapter(...)`. Take a look at [this](https://github.com/nextcloud/news-android/blob/783836390b4c27aba285bad1441b53154df16685/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/GsonConfig.java) example for more information.
157239
158-
4.2) **Without Retrofit**
240+
5.2) **Without Retrofit**
159241
160-
`NextcloudAPI` provides a method called `performNetworkRequest(NextcloudRequest request)` that allows you to handle the server response yourself.
242+
`NextcloudAPI` provides a method called `performNetworkRequest(NextcloudRequest request)` that allows you to handle the server response yourself.
161243
162-
```java
244+
```java
163245
public class MyActivity extends AppCompatActivity {
164246
165247
private NextcloudAPI mNextcloudAPI;
@@ -224,10 +306,10 @@ AccountImporter.getSingleSignOnAccount(context, accountName);
224306
}
225307
}
226308
}
227-
```
309+
```
228310

229311

230-
5) WebDAV
312+
6) WebDAV
231313

232314
The following WebDAV Methods are supported: `PROPFIND` / `MKCOL`
233315

0 commit comments

Comments
 (0)