Coder Social home page Coder Social logo

afollestad / arctic-icon-request Goto Github PK

View Code? Open in Web Editor NEW
59.0 12.0 11.0 5.92 MB

An easy to use Icon Request API for Kotlin, with traditional email capabilities plus the Arctic Manager API.

Home Page: https://af.codes

License: Apache License 2.0

Kotlin 100.00%
android icon-requests icon-packs email servers icon-request kotlin arctic-manager arctic

arctic-icon-request's Introduction

Icon Request

This library allows icon pack dashboards to easily send icon requests either traditionally via email, or through the Arctic Manager system.


Gradle Dependency

Download Build Status Codacy Badge License

Add this to your module's build.gradle file (make sure the version matches the jCenter badge above):

dependencies {
  ...
  implementation 'com.afollestad:icon-request:4.1.0'
}

Table of Contents

  1. Creating a Request
  2. Options
    1. Saved Instance State
    2. UriTransformer
    3. ArcticConfig
  3. Load Unthemed Apps
  4. Selecting Apps
  5. Sending a Request
  6. Cleanup

Creating a Request

To create a new Request object, you use the simple constructor. The only required parameter is a Context.

val request = ArcticRequest(this)

Options

There are more optional parameters that you can pass:

val request = ArcticRequest(
  context = this,
  savedInstanceState = savedInstanceState,
  config = config,
  uriTransformer = uriTransformer,
  onLoading = { },
  onLoadError = {
     // `it` is a Throwable
  },
  onLoaded = {
    // `it` is a List<AppModel>
  },
  onSelectionChange = {
    // `it` is a AppModel
  },
  onSending = { },
  onSendError = {
    // `it` is a Throwable
  },
  onSent = {
    // `it` is an Int (how many apps were sent)
  }
)

Saved Instance State

Above, savedInstanceState is a Bundle received from onCreate(...) in your Activity or Fragment which is used to restore your appfilter and app list state when recreating your UI (e.g. after screen rotation). But you also need to make use of saveInstanceState in order for that to work.

override fun onSaveInstanceState(outState: Bundle) {
  request.saveInstance(outState)
  super.onSaveInstanceState(outState)
}

UriTransformer

The uriTransformer allows you to modify the Uri pointing to a generated ZIP file before it gets passed through an Intent to an email client. On newer versions of Android, apps can only share files through FileProvider Uris. Here's an example of how you can convert a Uri of a local file into a FileProvider Uri which external apps can use, this is backwards compatible as well.

{ file ->
  FileProvider.getUriForFile(
      this,
      BuildConfig.APPLICATION_ID + ".fileProvider",
      File(file.path)
  )
}

In order to use FileProvider, you'll need a file in /res/xml called filepaths.xml:

<?xml version="1.0" encoding="utf-8"?>
<paths>
  <cache-path name="cache" path="/"/>
  <external-path name="external_cache" path="/"/>
</paths>

Which is registered in your AndroidManifest.xml:

<application ...>
  <provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="${applicationId}.fileProvider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
      android:name="android.support.FILE_PROVIDER_PATHS"
      android:resource="@xml/filepaths"/>
  </provider>
</application>

ArcticConfig

The config takes an ArcticConfig instance which has various optional parameters:

val config = ArcticConfig(
    cacheFolder = File(externalCacheDir, "com.afollestad.arctic"),
    appFilterName = "appfilter.xml",
    emailRecipient = "[email protected]",
    emailSubject = "Icon Request",
    emailHeader = "These apps aren't themed on my device!",
    emailFooter = "Hello world",
    includeDeviceInfo = true,
    errorOnInvalidDrawables = true,
    apiHost = "arcticmanager.com",
    apiKey = "ojtopiu23rp9u34p0iu43-9i4"
)

You can pass an apiHost and apiKey to integrate with Arctic Request Manager.


Loading Unthemed Apps

With a configured ArcticRequest instance, you can load unthemed apps:

// Rely on only the onLoad and onLoadError callbacks passed into ArcticRequest(...).
// If onLoadError isn't set, an error will result in a thrown RuntimeException.
request.performLoad()

// You will still receive onLoad and onLoadError notifications, but the result is also passed
// into the parameterized lambda.
request.performLoad { list, throwable ->  }

Your onLoaded callback will receive a List of unthemed apps. If an error occurs, the onLoadError callback is invoked.

After onLoaded, the loaded apps List will be populated:

val apps = request.loadedApps

Selecting Apps

Once you've loaded apps, you can select/deselect apps that are sent in a request:

request.toggleSelection(app);

request.select(app);
request.deselect(app);

request.selectAll();
request.deselectAll();

You can retrieve a List of selected apps:

// List<AppModel>
val apps = request.selectedApps

Keep in mind this method is doing a computation with every get performed on it, returning a new filtered list based off the list of all loaded apps.


Sending a Request

Once you've selected apps, you can send a request:

// Rely on only the onSent and onSendError callbacks passed into ArcticRequest(...).
// If onSendError isn't set, an error will result in a thrown RuntimeException.
request.performSend()

// You will still receive onSent and onSendError notifications, but the result is also passed
// into the parameterized lambda.
request.performSend { count, throwable ->  }

Your onSent callback will be invoked if all is well; your onSendError callback is invoked if an error occurs.

You can retrieve a List of requested apps:

// List<AppModel>
val apps = request.requestedApps

Keep in mind this method is doing a computation with every get performed on it, returning a new filtered list based off the list of all loaded apps.


Cleanup

When appropriate, you should call dispose() on your request object. This will let go of any pending actions that could result in memory leaks, or accessing your UI views after your app is in the background.

override fun onPause() {
  request.dispose()
  super.onPause()
}

arctic-icon-request's People

Contributors

afollestad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arctic-icon-request's Issues

Can not get AppModel List java.lang.Exception: Failed to read appfilter.xml arctic-icon-request

I am integrate arctic icon request lib, here is my code

PolarConfig config = PolarConfig.create(getActivity())
//.apiHost("https://your-server.com") // optional, specify for Request Manager usage
.apiKey("API_KEY") // optional, specify for Request Manager usage
.emailRecipient(getResources().getString(R.string.dev_email)) // required IF you don't specify an API key
.appFilterName("appfilter.xml")
.cacheFolder(getActivity().getCacheDir().getAbsolutePath())
.errorOnInvalidDrawables(true)
.includeDeviceInfo(true)
.emailSubject("New Icon Request")
.emailHeader("These apps are unthemed!")
.emailFooter("Thank you!")
.build();

    request =
            PolarRequest.make(getActivity(), savedInstanceState)
                    .config(config)
                    .uriTransformer(
                            uri ->
                                    FileProvider.getUriForFile(
                                            getActivity(),
                                            BuildConfig.APPLICATION_ID + ".fileProvider",
                                            new File(uri.getPath())));

    request.loaded()
            .subscribe(loadResult -> {
                if (loadResult.success()) {
                    List<AppModel> apps = loadResult.apps();
                    // Use apps
                } else {
                    Exception error = loadResult.error();
                    // Use error
                }
            });

in Expectation i got below one
java.lang.Exception: Failed to read appfilter.xml arctic-icon-request

Thanks in Advance

Sample giving error 429 on sending requests

  • I have verified there are no duplicate active or recent bugs, questions, or requests
  • I have verified that I am using the latest version of this library.
  • I have given my issue a non-generic title.
Include the following:
  • Library version: 4.0.3
  • Device OS version: 6.0.1
  • Device Manufacturer: Huawei
  • Device Name: Nexus 6P
Reproduction Steps
  1. Created package on arcticmanager.com
  2. changed sample project same as arcticmanager.com
  3. added API key received from arcticmanager.com
Expected Result

icon request gets synced with arcticmanger.com

Actual Result

Error 429

Failed to resolve 'com.afollestad:icon-request:4.0.3'

  • [ Y] I have verified there are no duplicate active or recent bugs, questions, or requests
  • [Y ] I have verified that I am using the latest version of this library.
  • [ Y] I have given my issue a non-generic title.
Include the following:
  • Library version: 4.0.3
  • Device OS version: 8.1.0
  • Device Manufacturer: Huawei
  • Device Name: Nexus 6P

Also, please wrap Java with correct syntax highlighting.

Reproduction Steps
  1. add "compile 'com.afollestad:icon-request:4.0.3' " in dependencies
Expected Result

library gets synced

Actual Result

Error stating "Failed to resolve 'com.afollestad:icon-request:4.0.3'"

Can't build with gradle

After adding

dependencies { compile 'com.afollestad:icon-request:1.3.8' }

The project is unable to build as it "Could not find com.afollestad:icon-request:1.3.8."

Full error log:

`Error:A problem occurred configuring project ':app'.

Could not resolve all dependencies for configuration ':app:_debugCompile'.
Could not find com.afollestad:icon-request:1.3.8.
Searched in the following locations:
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/afollestad/icon-request/1.3.8/icon-request-1.3.8.pom
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/afollestad/icon-request/1.3.8/icon-request-1.3.8.pom
https://jcenter.bintray.com/com/afollestad/icon-request/1.3.8/icon-request-1.3.8.pom
https://jcenter.bintray.com/com/afollestad/icon-request/1.3.8/icon-request-1.3.8.pom
file:/C:/Users/User 1/AppData/Local/Android/Sdk/extras/android/m2repository/com/afollestad/icon-request/1.3.8/icon-request-1.3.8.pom
file:/C:/Users/User 1/AppData/Local/Android/Sdk/extras/android/m2repository/com/afollestad/icon-request/1.3.8/icon-request-1.3.8.pom
file:/C:/Users/User 1/AppData/Local/Android/Sdk/extras/google/m2repository/com/afollestad/icon-request/1.3.8/icon-request-1.3.8.pom
file:/C:/Users/User 1/AppData/Local/Android/Sdk/extras/google/m2repository/com/afollestad/icon-request/1.3.8/icon-request-1.3.8.pom
Required by:
Android-Navigation-Drawer-master:app:unspecified`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.