diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2014-07-26 14:42:59 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2014-07-26 14:42:59 +0200 |
commit | 583b2adaae5769fb8bee4d63e4ef10846d7de1b6 (patch) | |
tree | 2dfe8481d75fc7a68cee495c3e91bce0a4e5b0c0 /src/de/danoeh/antennapod/dialog | |
parent | 1673f6eaf83606a78ce3928b2d7c33d4ff0de862 (diff) | |
parent | 460e061d35e45268d3dcfebeba00e7231ce8cfd0 (diff) | |
download | AntennaPod-583b2adaae5769fb8bee4d63e4ef10846d7de1b6.zip |
Merge branch 'develop'0.9.9.2
Conflicts:
submodules/dslv
Diffstat (limited to 'src/de/danoeh/antennapod/dialog')
3 files changed, 274 insertions, 131 deletions
diff --git a/src/de/danoeh/antennapod/dialog/AutoFlattrPreferenceDialog.java b/src/de/danoeh/antennapod/dialog/AutoFlattrPreferenceDialog.java new file mode 100644 index 000000000..d1ed795dc --- /dev/null +++ b/src/de/danoeh/antennapod/dialog/AutoFlattrPreferenceDialog.java @@ -0,0 +1,107 @@ +package de.danoeh.antennapod.dialog; + +import android.annotation.SuppressLint; +import android.app.Activity; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.view.View; +import android.widget.CheckBox; +import android.widget.SeekBar; +import android.widget.TextView; + +import org.apache.commons.lang3.Validate; + +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.preferences.UserPreferences; + +/** + * Creates a new AlertDialog that displays preferences for auto-flattring to the user. + */ +public class AutoFlattrPreferenceDialog { + + private AutoFlattrPreferenceDialog() { + } + + public static void newAutoFlattrPreferenceDialog(final Activity activity, final AutoFlattrPreferenceDialogInterface callback) { + Validate.notNull(activity); + Validate.notNull(callback); + + AlertDialog.Builder builder = new AlertDialog.Builder(activity); + + @SuppressLint("InflateParams") View view = activity.getLayoutInflater().inflate(R.layout.autoflattr_preference_dialog, null); + final CheckBox chkAutoFlattr = (CheckBox) view.findViewById(R.id.chkAutoFlattr); + final SeekBar skbPercent = (SeekBar) view.findViewById(R.id.skbPercent); + final TextView txtvStatus = (TextView) view.findViewById(R.id.txtvStatus); + + chkAutoFlattr.setChecked(UserPreferences.isAutoFlattr()); + skbPercent.setEnabled(chkAutoFlattr.isChecked()); + txtvStatus.setEnabled(chkAutoFlattr.isChecked()); + + final int initialValue = (int) (UserPreferences.getAutoFlattrPlayedDurationThreshold() * 100.0f); + setStatusMsgText(activity, txtvStatus, initialValue); + skbPercent.setProgress(initialValue); + + chkAutoFlattr.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + skbPercent.setEnabled(chkAutoFlattr.isChecked()); + txtvStatus.setEnabled(chkAutoFlattr.isChecked()); + } + }); + + skbPercent.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + setStatusMsgText(activity, txtvStatus, progress); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + + } + }); + + builder.setTitle(R.string.pref_auto_flattr_title) + .setView(view) + .setPositiveButton(R.string.confirm_label, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + float progDouble = ((float) skbPercent.getProgress()) / 100.0f; + callback.onConfirmed(chkAutoFlattr.isChecked(), progDouble); + dialog.dismiss(); + } + }) + .setNegativeButton(R.string.cancel_label, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + callback.onCancelled(); + dialog.dismiss(); + } + }) + .setCancelable(false).show(); + } + + private static void setStatusMsgText(Context context, TextView txtvStatus, int progress) { + if (progress == 0) { + txtvStatus.setText(R.string.auto_flattr_ater_beginning); + } else if (progress == 100) { + txtvStatus.setText(R.string.auto_flattr_ater_end); + } else { + txtvStatus.setText(context.getString(R.string.auto_flattr_after_percent, progress)); + } + } + + public static interface AutoFlattrPreferenceDialogInterface { + public void onCancelled(); + + public void onConfirmed(boolean autoFlattrEnabled, float autoFlattrValue); + } + + +} diff --git a/src/de/danoeh/antennapod/dialog/FeedItemDialog.java b/src/de/danoeh/antennapod/dialog/FeedItemDialog.java index 4a130af6e..7384463de 100644 --- a/src/de/danoeh/antennapod/dialog/FeedItemDialog.java +++ b/src/de/danoeh/antennapod/dialog/FeedItemDialog.java @@ -1,5 +1,6 @@ package de.danoeh.antennapod.dialog; +import android.annotation.TargetApi; import android.app.Dialog; import android.content.ActivityNotFoundException; import android.content.Context; @@ -21,6 +22,14 @@ import android.webkit.WebViewClient; import android.widget.ImageButton; import android.widget.TextView; import android.widget.Toast; + +import org.apache.commons.lang3.StringEscapeUtils; +import org.apache.commons.lang3.Validate; + +import java.util.Collection; +import java.util.List; +import java.util.concurrent.Callable; + import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.adapter.DefaultActionButtonCallback; @@ -34,11 +43,6 @@ import de.danoeh.antennapod.storage.DownloadRequester; import de.danoeh.antennapod.util.QueueAccess; import de.danoeh.antennapod.util.ShownotesProvider; import de.danoeh.antennapod.util.menuhandler.FeedItemMenuHandler; -import org.apache.commons.lang3.StringEscapeUtils; - -import java.util.Collection; -import java.util.List; -import java.util.concurrent.Callable; /** * Shows information about a specific FeedItem and provides actions like playing, downloading, etc. @@ -58,7 +62,7 @@ public class FeedItemDialog extends Dialog { private PopupMenu popupMenu; public static FeedItemDialog newInstance(Context context, FeedItemDialogSavedInstance savedInstance) { - if (savedInstance == null) throw new IllegalArgumentException("savedInstance = null"); + Validate.notNull(savedInstance); FeedItemDialog dialog = newInstance(context, savedInstance.item, savedInstance.queueAccess); if (savedInstance.isShowing) { dialog.show(); @@ -76,8 +80,8 @@ public class FeedItemDialog extends Dialog { public FeedItemDialog(Context context, int theme, FeedItem item, QueueAccess queue) { super(context, theme); - if (item == null) throw new IllegalArgumentException("item = null"); - if (queue == null) throw new IllegalArgumentException("queue = null"); + Validate.notNull(item); + Validate.notNull(queue); this.item = item; this.queue = queue; } @@ -95,6 +99,7 @@ public class FeedItemDialog extends Dialog { && UserPreferences.getTheme() != R.style.Theme_AntennaPod_Dark; } + @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -147,12 +152,9 @@ public class FeedItemDialog extends Dialog { @Override public void onClick(View v) { - FeedMedia media = item.getMedia(); - if (media == null) { - return; - } actionButtonCallback.onActionButtonPressed(item); - if (media.isDownloaded()) { + FeedMedia media = item.getMedia(); + if (media != null && media.isDownloaded()) { // playback was started, dialog should close itself dismiss(); } @@ -166,16 +168,17 @@ public class FeedItemDialog extends Dialog { { @Override public void onClick(View v) { - FeedMedia media = item.getMedia(); - if (media == null) { - return; - } - - if (!media.isDownloaded()) { - DBTasks.playMedia(getContext(), media, true, true, true); - dismiss(); - } else { - DBWriter.deleteFeedMediaOfItem(getContext(), media.getId()); + if (item.hasMedia()) { + FeedMedia media = item.getMedia(); + if (!media.isDownloaded()) { + DBTasks.playMedia(getContext(), media, true, true, true); + dismiss(); + } else { + DBWriter.deleteFeedMediaOfItem(getContext(), media.getId()); + } + } else if (item.getLink() != null) { + Uri uri = Uri.parse(item.getLink()); + getContext().startActivity(new Intent(Intent.ACTION_VIEW, uri)); } } } @@ -186,7 +189,13 @@ public class FeedItemDialog extends Dialog { public void onClick(View v) { popupMenu.getMenu().clear(); popupMenu.inflate(R.menu.feeditem_dialog); - FeedItemMenuHandler.onPrepareMenu(popupMenuInterface, item, true, queue); + if (item.hasMedia()) { + FeedItemMenuHandler.onPrepareMenu(popupMenuInterface, item, true, queue); + } else { + // these are already available via button1 and button2 + FeedItemMenuHandler.onPrepareMenu(popupMenuInterface, item, true, queue, + R.id.mark_read_item, R.id.visit_website_item); + } popupMenu.show(); } } @@ -228,9 +237,26 @@ public class FeedItemDialog extends Dialog { } FeedMedia media = item.getMedia(); if (media == null) { - header.setVisibility(View.GONE); + TypedArray drawables = getContext().obtainStyledAttributes(new int[]{R.attr.navigation_accept, + R.attr.location_web_site}); + + if (!item.isRead()) { + butAction1.setImageDrawable(drawables.getDrawable(0)); + butAction1.setContentDescription(getContext().getString(R.string.mark_read_label)); + butAction1.setVisibility(View.VISIBLE); + } else { + butAction1.setVisibility(View.INVISIBLE); + } + + if (item.getLink() != null) { + butAction2.setImageDrawable(drawables.getDrawable(1)); + butAction2.setContentDescription(getContext().getString(R.string.visit_website_label)); + } else { + butAction2.setEnabled(false); + } + + drawables.recycle(); } else { - header.setVisibility(View.VISIBLE); boolean isDownloading = DownloadRequester.getInstance().isDownloadingFile(media); TypedArray drawables = getContext().obtainStyledAttributes(new int[]{R.attr.av_play, R.attr.av_download, R.attr.action_stream, R.attr.content_discard, R.attr.navigation_cancel}); @@ -348,7 +374,7 @@ public class FeedItemDialog extends Dialog { public void setItem(FeedItem item) { - if (item == null) throw new IllegalArgumentException("item = null"); + Validate.notNull(item); this.item = item; } @@ -369,7 +395,7 @@ public class FeedItemDialog extends Dialog { } public void setQueue(QueueAccess queue) { - if (queue == null) throw new IllegalArgumentException("queue = null"); + Validate.notNull(queue); this.queue = queue; } @@ -387,7 +413,7 @@ public class FeedItemDialog extends Dialog { /** * Used to save the FeedItemDialog's state across configuration changes - * */ + */ public static class FeedItemDialogSavedInstance { final FeedItem item; final QueueAccess queueAccess; diff --git a/src/de/danoeh/antennapod/dialog/TimeDialog.java b/src/de/danoeh/antennapod/dialog/TimeDialog.java index cb3ebf0ab..bbd514640 100644 --- a/src/de/danoeh/antennapod/dialog/TimeDialog.java +++ b/src/de/danoeh/antennapod/dialog/TimeDialog.java @@ -8,6 +8,7 @@ import android.text.TextWatcher; import android.util.Log; import android.view.View; import android.view.Window; +import android.view.inputmethod.InputMethodManager; import android.widget.*; import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; @@ -15,114 +16,123 @@ import de.danoeh.antennapod.R; import java.util.concurrent.TimeUnit; public abstract class TimeDialog extends Dialog { - private static final String TAG = "TimeDialog"; + private static final String TAG = "TimeDialog"; - private static final int DEFAULT_SPINNER_POSITION = 1; + private static final int DEFAULT_SPINNER_POSITION = 1; - private Context context; + private Context context; - private EditText etxtTime; - private Spinner spTimeUnit; - private Button butConfirm; - private Button butCancel; + private EditText etxtTime; + private Spinner spTimeUnit; + private Button butConfirm; + private Button butCancel; - private TimeUnit[] units = { TimeUnit.SECONDS, TimeUnit.MINUTES, - TimeUnit.HOURS }; + private TimeUnit[] units = {TimeUnit.SECONDS, TimeUnit.MINUTES, + TimeUnit.HOURS}; - public TimeDialog(Context context, int titleTextId, int leftButtonTextId) { - super(context); - this.context = context; - } + public TimeDialog(Context context, int titleTextId, int leftButtonTextId) { + super(context); + this.context = context; + } - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - requestWindowFeature(Window.FEATURE_NO_TITLE); + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + requestWindowFeature(Window.FEATURE_NO_TITLE); String[] spinnerContent = new String[]{context.getString(R.string.time_unit_seconds), - context.getString(R.string.time_unit_minutes), - context.getString(R.string.time_unit_hours)}; - - setContentView(R.layout.time_dialog); - etxtTime = (EditText) findViewById(R.id.etxtTime); - spTimeUnit = (Spinner) findViewById(R.id.spTimeUnit); - butConfirm = (Button) findViewById(R.id.butConfirm); - butCancel = (Button) findViewById(R.id.butCancel); - - butConfirm.setText(R.string.set_sleeptimer_label); - butCancel.setText(R.string.cancel_label); - setTitle(R.string.set_sleeptimer_label); - ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>( - this.getContext(), android.R.layout.simple_spinner_item, - spinnerContent); - spinnerAdapter - .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - spTimeUnit.setAdapter(spinnerAdapter); - spTimeUnit.setSelection(DEFAULT_SPINNER_POSITION); - butCancel.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View v) { - dismiss(); - } - }); - butConfirm.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View v) { - try { - long input = readTimeMillis(); - onTimeEntered(input); - dismiss(); - } catch (NumberFormatException e) { - e.printStackTrace(); - Toast toast = Toast.makeText(context, - R.string.time_dialog_invalid_input, - Toast.LENGTH_LONG); - toast.show(); - } - } - }); - etxtTime.addTextChangedListener(new TextWatcher() { - - @Override - public void afterTextChanged(Editable s) { - checkInputLength(s.length()); - } - - @Override - public void beforeTextChanged(CharSequence s, int start, int count, - int after) { - - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, - int count) { - - } - }); - checkInputLength(etxtTime.getText().length()); - - } - - private void checkInputLength(int length) { - if (length > 0) { - if (BuildConfig.DEBUG) - Log.d(TAG, "Length is larger than 0, enabling confirm button"); - butConfirm.setEnabled(true); - } else { - if (BuildConfig.DEBUG) - Log.d(TAG, "Length is smaller than 0, disabling confirm button"); - butConfirm.setEnabled(false); - } - } - - public abstract void onTimeEntered(long millis); - - private long readTimeMillis() { - TimeUnit selectedUnit = units[spTimeUnit.getSelectedItemPosition()]; - long value = Long.valueOf(etxtTime.getText().toString()); - return selectedUnit.toMillis(value); - } + context.getString(R.string.time_unit_minutes), + context.getString(R.string.time_unit_hours)}; + + setContentView(R.layout.time_dialog); + etxtTime = (EditText) findViewById(R.id.etxtTime); + spTimeUnit = (Spinner) findViewById(R.id.spTimeUnit); + butConfirm = (Button) findViewById(R.id.butConfirm); + butCancel = (Button) findViewById(R.id.butCancel); + + butConfirm.setText(R.string.set_sleeptimer_label); + butCancel.setText(R.string.cancel_label); + setTitle(R.string.set_sleeptimer_label); + ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>( + this.getContext(), android.R.layout.simple_spinner_item, + spinnerContent); + spinnerAdapter + .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spTimeUnit.setAdapter(spinnerAdapter); + spTimeUnit.setSelection(DEFAULT_SPINNER_POSITION); + butCancel.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + dismiss(); + } + }); + butConfirm.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + try { + long input = readTimeMillis(); + onTimeEntered(input); + dismiss(); + } catch (NumberFormatException e) { + e.printStackTrace(); + Toast toast = Toast.makeText(context, + R.string.time_dialog_invalid_input, + Toast.LENGTH_LONG); + toast.show(); + } + } + }); + etxtTime.addTextChangedListener(new TextWatcher() { + + @Override + public void afterTextChanged(Editable s) { + checkInputLength(s.length()); + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, + int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, + int count) { + + } + }); + checkInputLength(etxtTime.getText().length()); + etxtTime.postDelayed(new Runnable() { + @Override + public void run() { + InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); + imm.showSoftInput(etxtTime, InputMethodManager.SHOW_IMPLICIT); + } + }, 100); + + + + } + + private void checkInputLength(int length) { + if (length > 0) { + if (BuildConfig.DEBUG) + Log.d(TAG, "Length is larger than 0, enabling confirm button"); + butConfirm.setEnabled(true); + } else { + if (BuildConfig.DEBUG) + Log.d(TAG, "Length is smaller than 0, disabling confirm button"); + butConfirm.setEnabled(false); + } + } + + public abstract void onTimeEntered(long millis); + + private long readTimeMillis() { + TimeUnit selectedUnit = units[spTimeUnit.getSelectedItemPosition()]; + long value = Long.valueOf(etxtTime.getText().toString()); + return selectedUnit.toMillis(value); + } } |