Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1ef95694 authored by Stefan Niedermann's avatar Stefan Niedermann
Browse files

Format and update README.md

parent eb4b1f20
Loading
Loading
Loading
Loading
+154 −169
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ repositories {
}

dependencies {
	implementation "com.github.nextcloud:Android-SingleSignOn:0.4.1"
    implementation "com.github.nextcloud:Android-SingleSignOn:0.5.1"
}

compileOptions {
@@ -39,10 +39,7 @@ From an Activity
private void openAccountChooser() {
    try {
        AccountImporter.pickNewAccount(this);
        } 
        catch (NextcloudFilesAppNotInstalledException e) {
            UiExceptionManager.showDialogForException(this, e);
        } catch (AndroidGetAccountsPermissionNotGranted e) {
    } catch (NextcloudFilesAppNotInstalledException | AndroidGetAccountsPermissionNotGranted e) {
        UiExceptionManager.showDialogForException(this, e);
    }
}
@@ -53,9 +50,7 @@ From a Fragment
private void openAccountChooser() {
    try {
        AccountImporter.pickNewAccount(currentFragment);
        } catch (NextcloudFilesAppNotInstalledException e) {
            UiExceptionManager.showDialogForException(this, e);
        } catch (AndroidGetAccountsPermissionNotGranted e) {
    } catch (NextcloudFilesAppNotInstalledException | AndroidGetAccountsPermissionNotGranted e) {
        UiExceptionManager.showDialogForException(this, e);
    }
}
@@ -73,7 +68,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
        NextcloudAPI.ApiConnectedListener callback = new NextcloudAPI.ApiConnectedListener() {
            @Override
            public void onConnected() {
                            // ignore this one..
                // ignore this one… see 5)
            }

            @Override
@@ -84,7 +79,6 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {

        @Override
        public void accountAccessGranted(SingleSignOnAccount account) {

            Context l_context = getApplicationContext();

            // As this library supports multiple accounts we created some helper methods if you only want to use one.
@@ -94,14 +88,9 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {

            // Get the "default" account
            SingleSignOnAccount ssoAccount = null;
                        try
                        {
            try {
                ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(l_context);
                        } catch (NextcloudFilesAppAccountNotFoundException e)
                        {
                            UiExceptionManager.showDialogForException(l_context, e);
                        } catch (NoCurrentAccountSelectedException e)
                        {
            } catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) {
                UiExceptionManager.showDialogForException(l_context, e);
            }
            
@@ -125,7 +114,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
        NextcloudAPI.ApiConnectedListener callback = new NextcloudAPI.ApiConnectedListener() {
            @Override
            public void onConnected() { 
            // ignore this one..
                // ignore this one… see 5)
            }
    
            @Override
@@ -160,22 +149,22 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
    AccountImporter.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
}

// Complete example: https://github.com/nextcloud/news-android/blob/master/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/LoginDialogFragment.java
// Complete example: https://github.com/nextcloud/news-android/blob/890828441ba0c8a9b90afe56f3e08ed63366ece5/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/LoginDialogActivity.java#L470-L475
```

4) How to get account information?

```java
// If you stored the "default" account using setCurrentAccount(...) you can get the account by using the following line:
// If you stored the "default" account using setCurrentAccount() you can get the account by using the following line:
SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(context);

// Otherwise (for multi-account support): (you'll have to keep track of the account names yourself. Note: this has to be the name of SingleSignOnAccount.name)
AccountImporter.getSingleSignOnAccount(context, accountName);

// ssoAccount.name // Name of the account used in the android account manager
// ssoAccount.username
// ssoAccount.token
// ssoAccount.url
ssoAccount.name; // Name of the account used in the android account manager
ssoAccount.username;
ssoAccount.token;
ssoAccount.url;
```

5) How to make a network request?
@@ -186,7 +175,6 @@ AccountImporter.getSingleSignOnAccount(context, accountName);
public NextcloudAPI(Context context, SingleSignOnAccount account, Gson gson, ApiConnectedListener callback) {
```

    
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 5.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.

5.1) **Using Retrofit**
@@ -207,7 +195,7 @@ AccountImporter.getSingleSignOnAccount(context, accountName);
    @DELETE("feeds/{feedId}")
    Completable deleteFeed(@Path("feedId") long feedId);

        
    //
}
```

@@ -235,7 +223,6 @@ AccountImporter.getSingleSignOnAccount(context, accountName);
       SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(context);
       NextcloudAPI nextcloudAPI = new NextcloudAPI(context, ssoAccount, new GsonBuilder().create(), callback);
       mApi = new NextcloudRetrofitApiBuilder(nextcloudAPI, API.mApiEndpoint).create(API.class);

   }
}
```
@@ -267,9 +254,7 @@ AccountImporter.getSingleSignOnAccount(context, accountName);
                    downloadFile();
                }
            }.start();
            } catch (NextcloudFilesAppAccountNotFoundException e) {
                // TODO handle errors
            } catch (NoCurrentAccountSelectedException e) {
        } catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) {
            // TODO handle errors
        }
    }
@@ -285,7 +270,7 @@ AccountImporter.getSingleSignOnAccount(context, accountName);
    private NextcloudAPI.ApiConnectedListener apiCallback = new NextcloudAPI.ApiConnectedListener() {
        @Override
        public void onConnected() {
                // ignore this one..
            // ignore this one… see 5)
        }

        @Override
@@ -366,7 +351,7 @@ if (VersionCheckHelper.verifyMinVersion(context, MIN_NEXTCLOUD_FILES_APP_VERSION
    - [Login](https://github.com/stefan-niedermann/nextcloud-notes/blob/master/app/src/main/java/it/niedermann/owncloud/notes/util/SSOUtil.java#L31)
- [Nextcloud Deck app](https://github.com/stefan-niedermann/nextcloud-deck/)
    - [API](https://github.com/stefan-niedermann/nextcloud-deck/blob/master/app/src/main/java/it/niedermann/nextcloud/deck/api/DeckAPI.java)
    - [Login](https://github.com/stefan-niedermann/nextcloud-deck/blob/master/app/src/main/java/it/niedermann/nextcloud/deck/ui/DrawerActivity.java#L288) 
    - [Login](https://github.com/stefan-niedermann/nextcloud-deck/blob/master/app/src/main/java/it/niedermann/nextcloud/deck/ui/ImportAccountActivity.java#L76)



@@ -375,7 +360,7 @@ if (VersionCheckHelper.verifyMinVersion(context, MIN_NEXTCLOUD_FILES_APP_VERSION

Note that the "Make network request" section in the diagram only shows the workflow if you use the "retrofit" api.

![](doc/NextcloudSingleSignOn.png)
![Flow Diagram](doc/NextcloudSingleSignOn.png)

# Translations
We manage translations via [Transifex](https://www.transifex.com/nextcloud/nextcloud/android-singlesignon/). So just request joining the translation team for Android on the site and start translating. All translations will then be automatically pushed to this repository, there is no need for any pull request for translations.