Remove DonationActivity

pull/384/head
Alex Baker 9 years ago
parent f763c242d6
commit aef5ae7cb1

@ -2,12 +2,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.tasks">
<application>
<activity
android:name=".activities.DonationActivity"
android:theme="@style/DialogBase" />
</application>
<application/>
</manifest>

@ -1,15 +0,0 @@
package org.tasks.activities;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
public class DonationActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("http://tasks.org/donate")));
finish();
}
}

@ -1,7 +1,9 @@
package org.tasks.preferences;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceScreen;
import android.preference.Preference;
import org.tasks.R;
import org.tasks.injection.ActivityComponent;
@ -12,12 +14,17 @@ public class BasicPreferences extends BaseBasicPreferences {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceScreen preferenceScreen = getPreferenceScreen();
preferenceScreen.removePreference(findPreference(getString(R.string.synchronization)));
preferenceScreen.removePreference(findPreference(getString(R.string.p_tesla_unread_enabled)));
preferenceScreen.removePreference(findPreference(getString(R.string.p_purchased_tasker)));
preferenceScreen.removePreference(findPreference(getString(R.string.p_purchased_dashclock)));
preferenceScreen.removePreference(findPreference(getString(R.string.p_collect_statistics)));
getPref(R.string.TLA_menu_donate).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("http://tasks.org/donate")));
return false;
}
});
requires(false, R.string.synchronization);
requires(R.string.get_plugins, false, R.string.p_tesla_unread_enabled, R.string.p_purchased_tasker, R.string.p_purchased_dashclock);
requires(R.string.privacy, false, R.string.p_collect_statistics);
}
@Override

@ -38,10 +38,6 @@
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyBq82FiK4U8Ke2TV_F8UjDZwgtSy8K9cyQ"/>
<activity
android:name=".activities.DonationActivity"
android:theme="@style/DialogBase" />
<service android:name=".location.GeofenceTransitionsIntentService"/>
<activity

@ -1,97 +0,0 @@
package org.tasks.activities;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import org.tasks.R;
import org.tasks.billing.PurchaseHelper;
import org.tasks.billing.PurchaseHelperCallback;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.InjectingAppCompatActivity;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.inject.Inject;
public class DonationActivity extends InjectingAppCompatActivity implements PurchaseHelperCallback {
private static final int RC_REQUEST = 10001;
private boolean itemSelected;
@Inject DialogBuilder dialogBuilder;
@Inject PurchaseHelper purchaseHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final String[] donationValues = getValues();
dialogBuilder.newDialog()
.setTitle(R.string.select_amount)
.setItems(donationValues, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
itemSelected = true;
String value = donationValues[which];
Pattern pattern = Pattern.compile("\\$(\\d+) USD");
Matcher matcher = pattern.matcher(value);
//noinspection ResultOfMethodCallIgnored
matcher.matches();
String sku = String.format(Locale.ENGLISH, "%03d", Integer.parseInt(matcher.group(1)));
purchaseHelper.purchase(dialogBuilder, DonationActivity.this, sku, null, RC_REQUEST, DonationActivity.this);
}
})
.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (!itemSelected) {
finish();
}
}
})
.show();
}
@Override
public void inject(ActivityComponent component) {
component.inject(this);
}
private String[] getValues() {
List<String> values = new ArrayList<>();
for (int i = 1 ; i <= 100 ; i++) {
values.add(String.format("$%s USD", Integer.toString(i)));
}
return values.toArray(new String[values.size()]);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RC_REQUEST) {
purchaseHelper.handleActivityResult(this, requestCode, resultCode, data);
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (!isChangingConfigurations()) {
purchaseHelper.disposeIabHelper();
}
}
@Override
public void purchaseCompleted(boolean success, String sku) {
finish();
}
}

@ -1,5 +1,6 @@
package org.tasks.preferences;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
@ -15,6 +16,12 @@ import org.tasks.dialogs.DialogBuilder;
import org.tasks.injection.ActivityComponent;
import org.tasks.receivers.TeslaUnreadReceiver;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.inject.Inject;
import timber.log.Timber;
@ -35,6 +42,29 @@ public class BasicPreferences extends BaseBasicPreferences implements PurchaseHe
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getPref(R.string.TLA_menu_donate).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
final String[] donationValues = getDonationValues();
dialogBuilder.newDialog()
.setTitle(R.string.select_amount)
.setItems(donationValues, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String value = donationValues[which];
Pattern pattern = Pattern.compile("\\$(\\d+) USD");
Matcher matcher = pattern.matcher(value);
//noinspection ResultOfMethodCallIgnored
matcher.matches();
String sku = String.format(Locale.ENGLISH, "%03d", Integer.parseInt(matcher.group(1)));
purchaseHelper.purchase(dialogBuilder, BasicPreferences.this, sku, null, REQUEST_PURCHASE, BasicPreferences.this);
}
})
.show();
return false;
}
});
getPref(R.string.p_tesla_unread_enabled).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
@ -60,21 +90,15 @@ public class BasicPreferences extends BaseBasicPreferences implements PurchaseHe
}
});
Preference dashClock = getPref(R.string.p_purchased_dashclock);
if (atLeastJellybeanMR1()) {
dashClock.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (newValue != null && (boolean) newValue && !preferences.hasPurchase(R.string.p_purchased_dashclock)) {
purchaseHelper.purchase(dialogBuilder, BasicPreferences.this, getString(R.string.sku_dashclock), getString(R.string.p_purchased_dashclock), REQUEST_PURCHASE, BasicPreferences.this);
}
return false;
getPref(R.string.p_purchased_dashclock).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (newValue != null && (boolean) newValue && !preferences.hasPurchase(R.string.p_purchased_dashclock)) {
purchaseHelper.purchase(dialogBuilder, BasicPreferences.this, getString(R.string.sku_dashclock), getString(R.string.p_purchased_dashclock), REQUEST_PURCHASE, BasicPreferences.this);
}
});
} else {
PreferenceCategory iapCategory = (PreferenceCategory) findPreference(getString(R.string.get_plugins));
iapCategory.removePreference(dashClock);
}
return false;
}
});
findPreference(getString(R.string.p_collect_statistics)).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
@ -108,6 +132,8 @@ public class BasicPreferences extends BaseBasicPreferences implements PurchaseHe
}
});
}
requires(R.string.get_plugins, atLeastJellybeanMR1(), R.string.p_purchased_dashclock);
}
@Override
@ -136,7 +162,7 @@ public class BasicPreferences extends BaseBasicPreferences implements PurchaseHe
} else if (getString(R.string.sku_dashclock).equals(sku)) {
((TwoStatePreference) getPref(R.string.p_purchased_dashclock)).setChecked(success);
} else {
Timber.e("Unhandled sku: %s", sku);
Timber.d("Unhandled sku: %s", sku);
}
}
});
@ -151,7 +177,11 @@ public class BasicPreferences extends BaseBasicPreferences implements PurchaseHe
}
}
private Preference getPref(int resId) {
return findPreference(getString(resId));
private String[] getDonationValues() {
List<String> values = new ArrayList<>();
for (int i = 1 ; i <= 100 ; i++) {
values.add(String.format("$%s USD", Integer.toString(i)));
}
return values.toArray(new String[values.size()]);
}
}

@ -26,7 +26,6 @@ import org.tasks.activities.DatePickerActivity;
import org.tasks.activities.DeleteAllCalendarEventsActivity;
import org.tasks.activities.DeleteCompletedActivity;
import org.tasks.activities.DeleteCompletedEventsActivity;
import org.tasks.activities.DonationActivity;
import org.tasks.activities.ExportTaskActivity;
import org.tasks.activities.FilterSelectionActivity;
import org.tasks.activities.ImportTaskActivity;
@ -114,8 +113,6 @@ public interface BaseActivityComponent {
void inject(VoiceCommandActivity voiceCommandActivity);
void inject(DonationActivity donationActivity);
void inject(ClearGtaskDataActivity clearGtaskDataActivity);
void inject(ReminderPreferences reminderPreferences);

@ -2,6 +2,9 @@ package org.tasks.injection;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.widget.Toolbar;
@ -69,12 +72,25 @@ public abstract class InjectingPreferenceActivity extends AppCompatPreferenceAct
tracker.showScreen(getClass().getSimpleName());
}
protected void requires(int prefGroup, boolean passesCheck, int... resIds) {
if (!passesCheck) {
remove((PreferenceCategory) findPreference(getString(prefGroup)), resIds);
}
}
protected void requires(boolean passesCheck, int... resIds) {
if (!passesCheck) {
PreferenceScreen preferenceScreen = getPreferenceScreen();
for (int resId : resIds) {
preferenceScreen.removePreference(findPreference(getString(resId)));
}
remove(getPreferenceScreen(), resIds);
}
}
private void remove(PreferenceGroup preferenceGroup, int[] resIds) {
for (int resId : resIds) {
preferenceGroup.removePreference(getPref(resId));
}
}
protected Preference getPref(int resId) {
return findPreference(getString(resId));
}
}

@ -858,7 +858,7 @@ File %1$s contained %2$s.\n\n
<string name="no_title">(No title)</string>
<string name="back_button_saves_task">Back button saves task</string>
<string name="default_list">Default list</string>
<string name="plugin_description">Tasks is an open source project maintained by a single developer. Niche features are offered as in-app purchases in order to support their development.</string>
<string name="plugin_description">Tasks is an open source project maintained by one developer. Some features are offered as in-app purchases in order to support development.</string>
<string name="tesla_unread_description">Display a badge for the number of active tasks in your default list. Requires TeslaUnread for Nova Launcher</string>
<string name="tasker_description">Context-aware list notifications. Requires Tasker or Locale</string>
<string name="donate_summary">Donations are greatly appreciated</string>

@ -2,40 +2,36 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="@string/get_plugins"
android:key="@string/get_plugins">
android:key="@string/get_plugins"
android:title="@string/get_plugins">
<Preference
android:selectable="false"
android:summary="@string/plugin_description"/>
android:summary="@string/plugin_description" />
<Preference
android:title="@string/TLA_menu_donate"
android:summary="@string/donate_summary">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="org.tasks"
android:targetClass="org.tasks.activities.DonationActivity" />
</Preference>
android:key="@string/TLA_menu_donate"
android:summary="@string/donate_summary"
android:title="@string/TLA_menu_donate" />
<CheckBoxPreference
android:key="@string/p_purchased_dashclock"
android:title="@string/dashclock"
android:dependency="@string/p_purchased_dashclock"
android:disableDependentsState="true"
android:summary="@string/dashclock_purchase_description" />
android:key="@string/p_purchased_dashclock"
android:summary="@string/dashclock_purchase_description"
android:title="@string/dashclock" />
<CheckBoxPreference
android:key="@string/p_purchased_tasker"
android:title="@string/tasker_locale"
android:dependency="@string/p_purchased_tasker"
android:disableDependentsState="true"
android:summary="@string/tasker_description"/>
android:key="@string/p_purchased_tasker"
android:summary="@string/tasker_description"
android:title="@string/tasker_locale" />
<CheckBoxPreference
android:key="@string/p_tesla_unread_enabled"
android:title="@string/tesla_unread"
android:summary="@string/tesla_unread_description"/>
android:summary="@string/tesla_unread_description"
android:title="@string/tesla_unread" />
</PreferenceCategory>

@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/privacy">
<PreferenceCategory
android:key="@string/privacy"
android:title="@string/privacy">
<Preference android:title="@string/privacy_policy">
<intent

Loading…
Cancel
Save