Search in sources :

Example 1 with GpodnetServiceException

use of de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException 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 GpodnetServiceException

use of de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException 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 GpodnetServiceException

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

the class PodcastListFragment method loadData.

protected final void loadData() {
    AsyncTask<Void, Void, List<GpodnetPodcast>> loaderTask = new AsyncTask<Void, Void, List<GpodnetPodcast>>() {

        volatile Exception exception = null;

        @Override
        protected List<GpodnetPodcast> doInBackground(Void... params) {
            GpodnetService service = null;
            try {
                service = new GpodnetService();
                return loadPodcastData(service);
            } catch (GpodnetServiceException e) {
                exception = e;
                e.printStackTrace();
                return null;
            } finally {
                if (service != null) {
                    service.shutdown();
                }
            }
        }

        @Override
        protected void onPostExecute(List<GpodnetPodcast> gpodnetPodcasts) {
            super.onPostExecute(gpodnetPodcasts);
            final Context context = getActivity();
            if (context != null && gpodnetPodcasts != null && gpodnetPodcasts.size() > 0) {
                PodcastListAdapter listAdapter = new PodcastListAdapter(context, 0, gpodnetPodcasts);
                gridView.setAdapter(listAdapter);
                listAdapter.notifyDataSetChanged();
                progressBar.setVisibility(View.GONE);
                gridView.setVisibility(View.VISIBLE);
                txtvError.setVisibility(View.GONE);
                butRetry.setVisibility(View.GONE);
            } else if (context != null && gpodnetPodcasts != null) {
                gridView.setVisibility(View.GONE);
                progressBar.setVisibility(View.GONE);
                txtvError.setText(getString(R.string.search_status_no_results));
                txtvError.setVisibility(View.VISIBLE);
                butRetry.setVisibility(View.GONE);
            } else if (context != null) {
                gridView.setVisibility(View.GONE);
                progressBar.setVisibility(View.GONE);
                txtvError.setText(getString(R.string.error_msg_prefix) + exception.getMessage());
                txtvError.setVisibility(View.VISIBLE);
                butRetry.setVisibility(View.VISIBLE);
            }
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            gridView.setVisibility(View.GONE);
            progressBar.setVisibility(View.VISIBLE);
            txtvError.setVisibility(View.GONE);
            butRetry.setVisibility(View.GONE);
        }
    };
    if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
        loaderTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else {
        loaderTask.execute();
    }
}
Also used : GpodnetPodcast(de.danoeh.antennapod.core.gpoddernet.model.GpodnetPodcast) Context(android.content.Context) GpodnetServiceException(de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException) GpodnetService(de.danoeh.antennapod.core.gpoddernet.GpodnetService) AsyncTask(android.os.AsyncTask) List(java.util.List) PodcastListAdapter(de.danoeh.antennapod.adapter.gpodnet.PodcastListAdapter) GpodnetServiceException(de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException)

Example 4 with GpodnetServiceException

use of de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException 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 5 with GpodnetServiceException

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

the class GpodnetAuthenticationActivity method setupDeviceView.

private void setupDeviceView(View view) {
    final EditText deviceID = (EditText) view.findViewById(R.id.etxtDeviceID);
    final EditText caption = (EditText) view.findViewById(R.id.etxtCaption);
    final Button createNewDevice = (Button) view.findViewById(R.id.butCreateNewDevice);
    final Button chooseDevice = (Button) view.findViewById(R.id.butChooseExistingDevice);
    final TextView txtvError = (TextView) view.findViewById(R.id.txtvError);
    final ProgressBar progBarCreateDevice = (ProgressBar) view.findViewById(R.id.progbarCreateDevice);
    final Spinner spinnerDevices = (Spinner) view.findViewById(R.id.spinnerChooseDevice);
    // load device list
    final AtomicReference<List<GpodnetDevice>> devices = new AtomicReference<>();
    new AsyncTask<GpodnetService, Void, List<GpodnetDevice>>() {

        private volatile Exception exception;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            chooseDevice.setEnabled(false);
            spinnerDevices.setEnabled(false);
            createNewDevice.setEnabled(false);
        }

        @Override
        protected void onPostExecute(List<GpodnetDevice> gpodnetDevices) {
            super.onPostExecute(gpodnetDevices);
            if (gpodnetDevices != null) {
                List<String> deviceNames = new ArrayList<>();
                for (GpodnetDevice device : gpodnetDevices) {
                    deviceNames.add(device.getCaption());
                }
                spinnerDevices.setAdapter(new ArrayAdapter<>(GpodnetAuthenticationActivity.this, android.R.layout.simple_spinner_dropdown_item, deviceNames));
                spinnerDevices.setEnabled(true);
                if (!deviceNames.isEmpty()) {
                    chooseDevice.setEnabled(true);
                }
                devices.set(gpodnetDevices);
                deviceID.setText(generateDeviceID(gpodnetDevices));
                createNewDevice.setEnabled(true);
            }
        }

        @Override
        protected List<GpodnetDevice> doInBackground(GpodnetService... params) {
            try {
                return params[0].getDevices(username);
            } catch (GpodnetServiceException e) {
                e.printStackTrace();
                exception = e;
                return null;
            }
        }
    }.execute(service);
    createNewDevice.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (checkDeviceIDText(deviceID, caption, txtvError, devices.get())) {
                final String deviceStr = deviceID.getText().toString();
                final String captionStr = caption.getText().toString();
                new AsyncTask<GpodnetService, Void, GpodnetDevice>() {

                    private volatile Exception exception;

                    @Override
                    protected void onPreExecute() {
                        super.onPreExecute();
                        createNewDevice.setEnabled(false);
                        chooseDevice.setEnabled(false);
                        progBarCreateDevice.setVisibility(View.VISIBLE);
                        txtvError.setVisibility(View.GONE);
                    }

                    @Override
                    protected void onPostExecute(GpodnetDevice result) {
                        super.onPostExecute(result);
                        createNewDevice.setEnabled(true);
                        chooseDevice.setEnabled(true);
                        progBarCreateDevice.setVisibility(View.GONE);
                        if (exception == null) {
                            selectedDevice = result;
                            advance();
                        } else {
                            txtvError.setText(exception.getMessage());
                            txtvError.setVisibility(View.VISIBLE);
                        }
                    }

                    @Override
                    protected GpodnetDevice doInBackground(GpodnetService... params) {
                        try {
                            params[0].configureDevice(username, deviceStr, captionStr, GpodnetDevice.DeviceType.MOBILE);
                            return new GpodnetDevice(deviceStr, captionStr, GpodnetDevice.DeviceType.MOBILE.toString(), 0);
                        } catch (GpodnetServiceException e) {
                            e.printStackTrace();
                            exception = e;
                        }
                        return null;
                    }
                }.execute(service);
            }
        }
    });
    chooseDevice.setOnClickListener(v -> {
        final int position = spinnerDevices.getSelectedItemPosition();
        if (position != AdapterView.INVALID_POSITION) {
            selectedDevice = devices.get().get(position);
            advance();
        }
    });
}
Also used : EditText(android.widget.EditText) GpodnetServiceException(de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException) Spinner(android.widget.Spinner) AsyncTask(android.os.AsyncTask) AtomicReference(java.util.concurrent.atomic.AtomicReference) 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) ArrayList(java.util.ArrayList) List(java.util.List) ProgressBar(android.widget.ProgressBar) ArrayAdapter(android.widget.ArrayAdapter) GpodnetDevice(de.danoeh.antennapod.core.gpoddernet.model.GpodnetDevice)

Aggregations

GpodnetService (de.danoeh.antennapod.core.gpoddernet.GpodnetService)6 GpodnetServiceException (de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException)6 AsyncTask (android.os.AsyncTask)3 TextView (android.widget.TextView)3 List (java.util.List)3 Context (android.content.Context)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 Button (android.widget.Button)2 EditText (android.widget.EditText)2 ProgressBar (android.widget.ProgressBar)2 DownloadRequestException (de.danoeh.antennapod.core.storage.DownloadRequestException)2 InputMethodManager (android.view.inputmethod.InputMethodManager)1 ArrayAdapter (android.widget.ArrayAdapter)1 Spinner (android.widget.Spinner)1 PodcastListAdapter (de.danoeh.antennapod.adapter.gpodnet.PodcastListAdapter)1 TagListAdapter (de.danoeh.antennapod.adapter.gpodnet.TagListAdapter)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