Search in sources :

Example 1 with FlattrException

use of org.shredzone.flattr4j.exception.FlattrException in project AntennaPod by AntennaPod.

the class FlattrClickWorker method doInBackground.

@Override
protected ExitCode doInBackground(Void... params) {
    if (!FlattrUtils.hasToken()) {
        return ExitCode.NO_TOKEN;
    }
    if (!NetworkUtils.networkAvailable()) {
        return ExitCode.NO_NETWORK;
    }
    final List<FlattrThing> flattrQueue = DBReader.getFlattrQueue();
    if (extraFlattrThing != null) {
        flattrQueue.add(extraFlattrThing);
    } else if (flattrQueue.size() == 1) {
        // if only one item is flattrd, the report can specifically mentioned that this item has failed
        extraFlattrThing = flattrQueue.get(0);
    }
    if (flattrQueue.isEmpty()) {
        return ExitCode.NO_THINGS;
    }
    List<Future<?>> dbFutures = new LinkedList<>();
    for (FlattrThing thing : flattrQueue) {
        if (BuildConfig.DEBUG)
            Log.d(TAG, "Processing " + thing.getTitle());
        try {
            // pop from queue to prevent unflattrable things from getting stuck in flattr queue infinitely
            thing.getFlattrStatus().setUnflattred();
            FlattrUtils.clickUrl(context, thing.getPaymentLink());
            thing.getFlattrStatus().setFlattred();
            publishProgress(R.string.flattr_click_success);
            countSuccess.incrementAndGet();
        } catch (FlattrException e) {
            e.printStackTrace();
            int failed = countFailed.incrementAndGet();
            if (failed == 1) {
                exception = e;
            }
        }
        Future<?> f = DBWriter.setFlattredStatus(context, thing, false);
        if (f != null) {
            dbFutures.add(f);
        }
    }
    for (Future<?> f : dbFutures) {
        try {
            f.get();
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
    }
    return ExitCode.EXIT_NORMAL;
}
Also used : FlattrThing(de.danoeh.antennapod.core.util.flattr.FlattrThing) FlattrException(org.shredzone.flattr4j.exception.FlattrException) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) LinkedList(java.util.LinkedList)

Example 2 with FlattrException

use of org.shredzone.flattr4j.exception.FlattrException in project AntennaPod by AntennaPod.

the class FlattrAuthActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(UserPreferences.getTheme());
    super.onCreate(savedInstanceState);
    singleton = this;
    authSuccessful = false;
    if (BuildConfig.DEBUG)
        Log.d(TAG, "Activity created");
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    setContentView(R.layout.flattr_auth);
    txtvExplanation = (TextView) findViewById(R.id.txtvExplanation);
    butAuthenticate = (Button) findViewById(R.id.but_authenticate);
    butReturn = (Button) findViewById(R.id.but_return_home);
    butReturn.setOnClickListener(v -> {
        Intent intent = new Intent(FlattrAuthActivity.this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
    });
    butAuthenticate.setOnClickListener(v -> {
        try {
            FlattrUtils.startAuthProcess(FlattrAuthActivity.this);
        } catch (FlattrException e) {
            e.printStackTrace();
        }
    });
}
Also used : FlattrException(org.shredzone.flattr4j.exception.FlattrException) Intent(android.content.Intent)

Aggregations

FlattrException (org.shredzone.flattr4j.exception.FlattrException)2 Intent (android.content.Intent)1 FlattrThing (de.danoeh.antennapod.core.util.flattr.FlattrThing)1 LinkedList (java.util.LinkedList)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1