Made automatic flattr threshold configurable
This commit is contained in:
parent
0513302c78
commit
f97a71d2f9
|
@ -0,0 +1,35 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/chkAutoFlattr"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:text="@string/auto_flattr_enable"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="@dimen/text_size_small" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/skbPercent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
android:max="100" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvStatus"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
android:ellipsize="end"
|
||||
android:lines="2"
|
||||
android:text="@string/auto_flattr_after_percent"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="@dimen/text_size_small" />
|
||||
|
||||
</LinearLayout>
|
|
@ -223,7 +223,7 @@
|
|||
<string name="pref_revokeAccess_title">Revoke access</string>
|
||||
<string name="pref_revokeAccess_sum">Revoke the access permission to your flattr account for this app.</string>
|
||||
<string name="pref_auto_flattr_title">Automatic Flattr</string>
|
||||
<string name="pref_auto_flattr_sum">Flattr episodes of which 80% have been played.</string>
|
||||
<string name="pref_auto_flattr_sum">Configure automatic flattring</string>
|
||||
<string name="user_interface_label">User Interface</string>
|
||||
<string name="pref_set_theme_title">Select theme</string>
|
||||
<string name="pref_set_theme_sum">Change the appearance of AntennaPod.</string>
|
||||
|
@ -250,7 +250,12 @@
|
|||
<string name="pref_seek_delta_sum">Seek this many seconds when rewinding or fast-forwarding</string>
|
||||
<string name="pref_gpodnet_sethostname_title">Set hostname</string>
|
||||
<string name="pref_gpodnet_sethostname_use_default_host">Use default host</string>
|
||||
|
||||
|
||||
<!-- Auto-Flattr dialog -->
|
||||
<string name="auto_flattr_enable">Enable automatic flattring</string>
|
||||
<string name="auto_flattr_after_percent">Flattr episode as soon as %d percent have been played</string>
|
||||
<string name="auto_flattr_ater_beginning">Flattr episode when playback starts</string>
|
||||
<string name="auto_flattr_ater_end">Flattr episode when playback ends</string>
|
||||
|
||||
<!-- Search -->
|
||||
<string name="search_hint">Search for Feeds or Episodes</string>
|
||||
|
|
|
@ -92,10 +92,8 @@
|
|||
<intent android:action=".activities.FlattrAuthActivity"/>
|
||||
</PreferenceScreen>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:enabled="false"
|
||||
android:key="pref_auto_flattr"
|
||||
<Preference
|
||||
android:key="prefAutoFlattrPrefs"
|
||||
android:summary="@string/pref_auto_flattr_sum"
|
||||
android:title="@string/pref_auto_flattr_title" />
|
||||
<Preference
|
||||
|
|
|
@ -15,7 +15,6 @@ import android.preference.Preference;
|
|||
import android.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.preference.Preference.OnPreferenceClickListener;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.support.v4.app.NavUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
@ -25,6 +24,7 @@ import de.danoeh.antennapod.R;
|
|||
import de.danoeh.antennapod.asynctask.FlattrClickWorker;
|
||||
import de.danoeh.antennapod.asynctask.OpmlExportWorker;
|
||||
import de.danoeh.antennapod.dialog.AuthenticationDialog;
|
||||
import de.danoeh.antennapod.dialog.AutoFlattrPreferenceDialog;
|
||||
import de.danoeh.antennapod.dialog.GpodnetSetHostnameDialog;
|
||||
import de.danoeh.antennapod.dialog.VariableSpeedDialog;
|
||||
import de.danoeh.antennapod.preferences.GpodnetPreferences;
|
||||
|
@ -47,7 +47,7 @@ public class PreferenceActivity extends android.preference.PreferenceActivity {
|
|||
private static final String PREF_FLATTR_THIS_APP = "prefFlattrThisApp";
|
||||
private static final String PREF_FLATTR_AUTH = "pref_flattr_authenticate";
|
||||
private static final String PREF_FLATTR_REVOKE = "prefRevokeAccess";
|
||||
private static final String PREF_AUTO_FLATTR = "pref_auto_flattr";
|
||||
private static final String PREF_AUTO_FLATTR_PREFS = "prefAutoFlattrPrefs";
|
||||
private static final String PREF_OPML_EXPORT = "prefOpmlExport";
|
||||
private static final String PREF_ABOUT = "prefAbout";
|
||||
private static final String PREF_CHOOSE_DATA_DIR = "prefChooseDataDir";
|
||||
|
@ -247,6 +247,26 @@ public class PreferenceActivity extends android.preference.PreferenceActivity {
|
|||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
findPreference(PREF_AUTO_FLATTR_PREFS).setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
AutoFlattrPreferenceDialog.newAutoFlattrPreferenceDialog(PreferenceActivity.this,
|
||||
new AutoFlattrPreferenceDialog.AutoFlattrPreferenceDialogInterface() {
|
||||
@Override
|
||||
public void onCancelled() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfirmed(boolean autoFlattrEnabled, float autoFlattrValue) {
|
||||
UserPreferences.setAutoFlattrSettings(PreferenceActivity.this, autoFlattrEnabled, autoFlattrValue);
|
||||
checkItemVisibility();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
});
|
||||
buildUpdateIntervalPreference();
|
||||
buildAutodownloadSelectedNetworsPreference();
|
||||
setSelectedNetworksEnabled(UserPreferences
|
||||
|
@ -314,7 +334,7 @@ public class PreferenceActivity extends android.preference.PreferenceActivity {
|
|||
|
||||
findPreference(PREF_FLATTR_AUTH).setEnabled(!hasFlattrToken);
|
||||
findPreference(PREF_FLATTR_REVOKE).setEnabled(hasFlattrToken);
|
||||
findPreference(PREF_AUTO_FLATTR).setEnabled(hasFlattrToken);
|
||||
findPreference(PREF_AUTO_FLATTR_PREFS).setEnabled(hasFlattrToken);
|
||||
|
||||
findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER)
|
||||
.setEnabled(UserPreferences.isEnableAutodownload());
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -763,13 +763,12 @@ public class PlaybackService extends Service {
|
|||
m.setPlayedDuration(m.getPlayedDuration() + ((int)(deltaPlayedDuration * playbackSpeed)));
|
||||
// Auto flattr
|
||||
if (FlattrUtils.hasToken() && UserPreferences.isAutoFlattr() && item.getPaymentLink() != null && item.getFlattrStatus().getUnflattred() &&
|
||||
(m.getPlayedDuration() > UserPreferences.getPlayedDurationAutoflattrThreshold() * duration)) {
|
||||
(m.getPlayedDuration() > UserPreferences.getAutoFlattrPlayedDurationThreshold() * duration)) {
|
||||
|
||||
if (BuildConfig.DEBUG)
|
||||
Log.d(TAG, "saveCurrentPosition: performing auto flattr since played duration " + Integer.toString(m.getPlayedDuration())
|
||||
+ " is " + UserPreferences.getPlayedDurationAutoflattrThreshold() * 100 + "% of file duration " + Integer.toString(duration));
|
||||
item.getFlattrStatus().setFlattrQueue();
|
||||
DBWriter.setFeedItemFlattrStatus(PodcastApp.getInstance(), item, false);
|
||||
+ " is " + UserPreferences.getAutoFlattrPlayedDurationThreshold() * 100 + "% of file duration " + Integer.toString(duration));
|
||||
DBTasks.flattrItemIfLoggedIn(this, item);
|
||||
}
|
||||
}
|
||||
playable.saveCurrentPosition(PreferenceManager
|
||||
|
|
Loading…
Reference in New Issue