Search in sources :

Example 6 with GpodnetService

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

the class GpodnetAuthenticationActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(UserPreferences.getTheme());
    super.onCreate(savedInstanceState);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    setContentView(R.layout.gpodnetauth_activity);
    service = new GpodnetService();
    viewFlipper = (ViewFlipper) findViewById(R.id.viewflipper);
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    views = new View[] { inflater.inflate(R.layout.gpodnetauth_credentials, viewFlipper, false), inflater.inflate(R.layout.gpodnetauth_device, viewFlipper, false), inflater.inflate(R.layout.gpodnetauth_finish, viewFlipper, false) };
    for (View view : views) {
        viewFlipper.addView(view);
    }
    advance();
}
Also used : GpodnetService(de.danoeh.antennapod.core.gpoddernet.GpodnetService) LayoutInflater(android.view.LayoutInflater) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView)

Example 7 with GpodnetService

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