Search in sources :

Example 1 with GpodnetService

use of de.danoeh.antennapod.core.gpoddernet.GpodnetService in project AntennaPod by AntennaPod.

the class GpodnetSyncService method syncSubscriptionChanges.

private synchronized void syncSubscriptionChanges() {
    final long timestamp = GpodnetPreferences.getLastSubscriptionSyncTimestamp();
    try {
        final List<String> localSubscriptions = DBReader.getFeedListDownloadUrls();
        Collection<String> localAdded = GpodnetPreferences.getAddedFeedsCopy();
        Collection<String> localRemoved = GpodnetPreferences.getRemovedFeedsCopy();
        GpodnetService service = tryLogin();
        // first sync: download all subscriptions...
        GpodnetSubscriptionChange subscriptionChanges = service.getSubscriptionChanges(GpodnetPreferences.getUsername(), GpodnetPreferences.getDeviceID(), timestamp);
        long newTimeStamp = subscriptionChanges.getTimestamp();
        Log.d(TAG, "Downloaded subscription changes: " + subscriptionChanges);
        processSubscriptionChanges(localSubscriptions, localAdded, localRemoved, subscriptionChanges);
        if (timestamp == 0) {
            // this is this apps first sync with gpodder:
            // only submit changes gpodder has not just sent us
            localAdded = localSubscriptions;
            localAdded.removeAll(subscriptionChanges.getAdded());
            localRemoved.removeAll(subscriptionChanges.getRemoved());
        }
        if (localAdded.size() > 0 || localRemoved.size() > 0) {
            Log.d(TAG, String.format("Uploading subscriptions, Added: %s\nRemoved: %s", localAdded, localRemoved));
            GpodnetUploadChangesResponse uploadResponse = service.uploadChanges(GpodnetPreferences.getUsername(), GpodnetPreferences.getDeviceID(), localAdded, localRemoved);
            newTimeStamp = uploadResponse.timestamp;
            Log.d(TAG, "Upload changes response: " + uploadResponse);
            GpodnetPreferences.removeAddedFeeds(localAdded);
            GpodnetPreferences.removeRemovedFeeds(localRemoved);
        }
        GpodnetPreferences.setLastSubscriptionSyncTimestamp(newTimeStamp);
        GpodnetPreferences.setLastSyncAttempt(true, System.currentTimeMillis());
        clearErrorNotifications();
    } catch (GpodnetServiceException e) {
        e.printStackTrace();
        updateErrorNotification(e);
    } catch (DownloadRequestException e) {
        e.printStackTrace();
    }
}
Also used : GpodnetSubscriptionChange(de.danoeh.antennapod.core.gpoddernet.model.GpodnetSubscriptionChange) GpodnetServiceException(de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException) GpodnetService(de.danoeh.antennapod.core.gpoddernet.GpodnetService) GpodnetUploadChangesResponse(de.danoeh.antennapod.core.gpoddernet.model.GpodnetUploadChangesResponse) DownloadRequestException(de.danoeh.antennapod.core.storage.DownloadRequestException)

Example 2 with GpodnetService

use of de.danoeh.antennapod.core.gpoddernet.GpodnetService in project AntennaPod by AntennaPod.

the class GpodnetSyncService method syncEpisodeActions.

private synchronized void syncEpisodeActions() {
    final long timestamp = GpodnetPreferences.getLastEpisodeActionsSyncTimestamp();
    Log.d(TAG, "last episode actions sync timestamp: " + timestamp);
    try {
        GpodnetService service = tryLogin();
        // download episode actions
        GpodnetEpisodeActionGetResponse getResponse = service.getEpisodeChanges(timestamp);
        long lastUpdate = getResponse.getTimestamp();
        Log.d(TAG, "Downloaded episode actions: " + getResponse);
        List<GpodnetEpisodeAction> remoteActions = getResponse.getEpisodeActions();
        List<GpodnetEpisodeAction> localActions = GpodnetPreferences.getQueuedEpisodeActions();
        processEpisodeActions(localActions, remoteActions);
        // upload local actions
        if (localActions.size() > 0) {
            Log.d(TAG, "Uploading episode actions: " + localActions);
            GpodnetEpisodeActionPostResponse postResponse = service.uploadEpisodeActions(localActions);
            lastUpdate = postResponse.timestamp;
            Log.d(TAG, "Upload episode response: " + postResponse);
            GpodnetPreferences.removeQueuedEpisodeActions(localActions);
        }
        GpodnetPreferences.setLastEpisodeActionsSyncTimestamp(lastUpdate);
        GpodnetPreferences.setLastSyncAttempt(true, System.currentTimeMillis());
        clearErrorNotifications();
    } catch (GpodnetServiceException e) {
        e.printStackTrace();
        updateErrorNotification(e);
    } catch (DownloadRequestException e) {
        e.printStackTrace();
    }
}
Also used : GpodnetServiceException(de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException) GpodnetService(de.danoeh.antennapod.core.gpoddernet.GpodnetService) GpodnetEpisodeAction(de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction) GpodnetEpisodeActionGetResponse(de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeActionGetResponse) DownloadRequestException(de.danoeh.antennapod.core.storage.DownloadRequestException) GpodnetEpisodeActionPostResponse(de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeActionPostResponse)

Example 3 with GpodnetService

use of de.danoeh.antennapod.core.gpoddernet.GpodnetService in project AntennaPod by AntennaPod.

the class GpodnetAuthenticationActivity method setupLoginView.

private void setupLoginView(View view) {
    final EditText username = (EditText) view.findViewById(R.id.etxtUsername);
    final EditText password = (EditText) view.findViewById(R.id.etxtPassword);
    final Button login = (Button) view.findViewById(R.id.butLogin);
    final TextView txtvError = (TextView) view.findViewById(R.id.txtvError);
    final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progBarLogin);
    password.setOnEditorActionListener((v, actionID, event) -> actionID == EditorInfo.IME_ACTION_GO && login.performClick());
    login.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final String usernameStr = username.getText().toString();
            final String passwordStr = password.getText().toString();
            if (BuildConfig.DEBUG)
                Log.d(TAG, "Checking login credentials");
            AsyncTask<GpodnetService, Void, Void> authTask = new AsyncTask<GpodnetService, Void, Void>() {

                volatile Exception exception;

                @Override
                protected void onPreExecute() {
                    super.onPreExecute();
                    login.setEnabled(false);
                    progressBar.setVisibility(View.VISIBLE);
                    txtvError.setVisibility(View.GONE);
                    // hide the keyboard
                    InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    inputManager.hideSoftInputFromWindow(login.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                }

                @Override
                protected void onPostExecute(Void aVoid) {
                    super.onPostExecute(aVoid);
                    login.setEnabled(true);
                    progressBar.setVisibility(View.GONE);
                    if (exception == null) {
                        advance();
                    } else {
                        txtvError.setText(exception.getCause().getMessage());
                        txtvError.setVisibility(View.VISIBLE);
                    }
                }

                @Override
                protected Void doInBackground(GpodnetService... params) {
                    try {
                        params[0].authenticate(usernameStr, passwordStr);
                        GpodnetAuthenticationActivity.this.username = usernameStr;
                        GpodnetAuthenticationActivity.this.password = passwordStr;
                    } catch (GpodnetServiceException e) {
                        e.printStackTrace();
                        exception = e;
                    }
                    return null;
                }
            };
            if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
                authTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, service);
            } else {
                authTask.execute();
            }
        }
    });
}
Also used : EditText(android.widget.EditText) GpodnetServiceException(de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException) AsyncTask(android.os.AsyncTask) InputMethodManager(android.view.inputmethod.InputMethodManager) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) GpodnetServiceException(de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException) GpodnetService(de.danoeh.antennapod.core.gpoddernet.GpodnetService) Button(android.widget.Button) TextView(android.widget.TextView) ProgressBar(android.widget.ProgressBar)

Example 4 with GpodnetService

use of de.danoeh.antennapod.core.gpoddernet.GpodnetService in project AntennaPod by AntennaPod.

the class GpodnetSyncService method tryLogin.

private synchronized GpodnetService tryLogin() throws GpodnetServiceException {
    if (service == null) {
        service = new GpodnetService();
        service.authenticate(GpodnetPreferences.getUsername(), GpodnetPreferences.getPassword());
    }
    return service;
}
Also used : GpodnetService(de.danoeh.antennapod.core.gpoddernet.GpodnetService)

Example 5 with GpodnetService

use of de.danoeh.antennapod.core.gpoddernet.GpodnetService in project AntennaPod by AntennaPod.

the class GPodnetServiceTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    service = new GpodnetService();
}
Also used : GpodnetService(de.danoeh.antennapod.core.gpoddernet.GpodnetService)

Aggregations

GpodnetService (de.danoeh.antennapod.core.gpoddernet.GpodnetService)7 GpodnetServiceException (de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException)4 View (android.view.View)3 AdapterView (android.widget.AdapterView)3 TextView (android.widget.TextView)3 AsyncTask (android.os.AsyncTask)2 Button (android.widget.Button)2 EditText (android.widget.EditText)2 ProgressBar (android.widget.ProgressBar)2 DownloadRequestException (de.danoeh.antennapod.core.storage.DownloadRequestException)2 LayoutInflater (android.view.LayoutInflater)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 ArrayAdapter (android.widget.ArrayAdapter)1 Spinner (android.widget.Spinner)1 GpodnetDevice (de.danoeh.antennapod.core.gpoddernet.model.GpodnetDevice)1 GpodnetEpisodeAction (de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction)1 GpodnetEpisodeActionGetResponse (de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeActionGetResponse)1 GpodnetEpisodeActionPostResponse (de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeActionPostResponse)1 GpodnetSubscriptionChange (de.danoeh.antennapod.core.gpoddernet.model.GpodnetSubscriptionChange)1 GpodnetUploadChangesResponse (de.danoeh.antennapod.core.gpoddernet.model.GpodnetUploadChangesResponse)1