Consolidate BasicPreferences

pull/437/head
Alex Baker 8 years ago
parent 659cd0a76b
commit 5df88f2093

@ -23,4 +23,12 @@ public class PurchaseHelper {
public void handleActivityResult(PurchaseHelperCallback callback, int requestCode, int resultCode, Intent data) {
}
public void disposeIabHelper() {
}
public void consumePurchases() {
}
}

@ -1,21 +0,0 @@
package org.tasks.preferences;
import android.os.Bundle;
import org.tasks.R;
import org.tasks.injection.ActivityComponent;
public class BasicPreferences extends BaseBasicPreferences {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requires(R.string.settings_general, false, R.string.synchronization);
}
@Override
public void inject(ActivityComponent component) {
component.inject(this);
}
}

@ -1,5 +1,6 @@
package org.tasks.injection;
import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.dao.MetadataDaoTests;
import com.todoroo.astrid.dao.TaskDaoTests;
import com.todoroo.astrid.model.TaskTest;
@ -16,6 +17,9 @@ import com.todoroo.astrid.sync.NewSyncTestCase;
import org.tasks.scheduling.BackupServiceTests;
public interface BaseTestComponent {
Database getDatabase();
void inject(ReminderServiceTest reminderServiceTest);
void inject(TaskTest taskTest);

@ -1,6 +1,5 @@
package org.tasks.injection;
import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.gtasks.GtasksIndentActionTest;
import com.todoroo.astrid.gtasks.GtasksListServiceTest;
import com.todoroo.astrid.gtasks.GtasksMetadataServiceTest;
@ -15,8 +14,6 @@ import dagger.Component;
@Component(modules = TestModule.class)
public interface TestComponent extends BaseTestComponent {
Database getDatabase();
GtasksMetadataServiceTest.GtasksMetadataServiceTestComponent plus(GtasksMetadataServiceTest.GtasksMetadataServiceTestModule gtasksMetadataServiceTestModule);
void inject(GtasksIndentActionTest gtasksIndentActionTest);

@ -27,4 +27,12 @@ public class PurchaseHelper {
public void handleActivityResult(PurchaseHelperCallback callback, int requestCode, int resultCode, Intent data) {
}
public void disposeIabHelper() {
}
public void consumePurchases() {
}
}

@ -1,34 +0,0 @@
package org.tasks.preferences;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.preference.Preference;
import org.tasks.R;
import org.tasks.injection.ActivityComponent;
public class BasicPreferences extends BaseBasicPreferences {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
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(R.string.settings_general, false, R.string.synchronization);
requires(R.string.get_plugins, false, R.string.p_purchased_tasker, R.string.p_purchased_dashclock);
requires(R.string.privacy, false, R.string.p_collect_statistics);
}
@Override
public void inject(ActivityComponent component) {
component.inject(this);
}
}

@ -1,188 +0,0 @@
package org.tasks.preferences;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.TwoStatePreference;
import org.tasks.BuildConfig;
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.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;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastJellybeanMR1;
public class BasicPreferences extends BaseBasicPreferences implements PurchaseHelperCallback {
private static final int REQUEST_PURCHASE = 10005;
@Inject TeslaUnreadReceiver teslaUnreadReceiver;
@Inject Preferences preferences;
@Inject PurchaseHelper purchaseHelper;
@Inject DialogBuilder dialogBuilder;
@Override
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 List<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.get(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_purchased_themes).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (newValue != null && (boolean) newValue && !preferences.hasPurchase(R.string.p_purchased_themes)) {
purchaseHelper.purchase(dialogBuilder, BasicPreferences.this, getString(R.string.sku_themes), getString(R.string.p_purchased_themes), REQUEST_PURCHASE, BasicPreferences.this);
}
return false;
}
});
getPref(R.string.p_tesla_unread_enabled).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (newValue != null) {
if ((boolean) newValue && !preferences.hasPurchase(R.string.p_purchased_tesla_unread)) {
purchaseHelper.purchase(dialogBuilder, BasicPreferences.this, getString(R.string.sku_tesla_unread), getString(R.string.p_purchased_tesla_unread), REQUEST_PURCHASE, BasicPreferences.this);
} else {
teslaUnreadReceiver.setEnabled((boolean) newValue);
return true;
}
}
return false;
}
});
getPref(R.string.p_purchased_tasker).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (newValue != null && (boolean) newValue && !preferences.hasPurchase(R.string.p_purchased_tasker)) {
purchaseHelper.purchase(dialogBuilder, BasicPreferences.this, getString(R.string.sku_tasker), getString(R.string.p_purchased_tasker), 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);
}
return false;
}
});
if (BuildConfig.DEBUG) {
addPreferencesFromResource(R.xml.preferences_debug);
findPreference(getString(R.string.debug_unlock_purchases)).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
preferences.setBoolean(R.string.p_purchased_dashclock, true);
preferences.setBoolean(R.string.p_purchased_tasker, true);
preferences.setBoolean(R.string.p_purchased_tesla_unread, true);
preferences.setBoolean(R.string.p_purchased_themes, true);
recreate();
return true;
}
});
findPreference(getString(R.string.debug_consume_purchases)).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
purchaseHelper.consumePurchases();
recreate();
return true;
}
});
}
requires(R.string.get_plugins, atLeastJellybeanMR1(), R.string.p_purchased_dashclock);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_PURCHASE) {
purchaseHelper.handleActivityResult(this, requestCode, resultCode, data);
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
@Override
public void inject(ActivityComponent component) {
component.inject(this);
}
@Override
public void purchaseCompleted(final boolean success, final String sku) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (getString(R.string.sku_tasker).equals(sku)) {
((TwoStatePreference) getPref(R.string.p_purchased_tasker)).setChecked(success);
} else if (getString(R.string.sku_tesla_unread).equals(sku)) {
((TwoStatePreference) getPref(R.string.p_tesla_unread_enabled)).setChecked(success);
} else if (getString(R.string.sku_dashclock).equals(sku)) {
((TwoStatePreference) getPref(R.string.p_purchased_dashclock)).setChecked(success);
} else if (getString(R.string.sku_themes).equals(sku)) {
((TwoStatePreference) getPref(R.string.p_purchased_themes)).setChecked(success);
} else {
Timber.d("Unhandled sku: %s", sku);
}
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
if (!isChangingConfigurations()) {
purchaseHelper.disposeIabHelper();
}
}
private List<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;
}
}

@ -1,9 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="gp_key">MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAk8mXRE3dDXwtinUILCEzKjov2rxs3kZbLRzNrcjFWXpG9OEsUzRGLzqEN+WwibVuMRpZLj/+IxbU2sJWq/M0q+90rOhmXn46ZPeNyr77IqX2pWKIAWpzBoWq/mshRwtm9m1FIiGdBNlXrhSE7u3TGB5FuEuuSqKWvWzxeqQ7fHmlM04Lqrh1mN3FaMne8rWv+DWVHDbLrtnXBuC36glOAj17HxrzaE2v6Pv7Df3QefJ3rM1+0fAp/5jNInaP0qHAlG8WTbUmDShQ5kG3urbv3HLByyx6TSqhmNudXUK/6TusvIj50OptAG7x+UFYf956dD3diXhY3yoICvyFWx1sNwIDAQAB</string>
<string name="sku_tasker">tasker</string>
<string name="sku_tesla_unread">tesla_unread</string>
<string name="sku_dashclock">dashclock</string>
<string name="sku_themes">themes</string>
<string name="p_dashclock_filter">dashclock_filter</string>
<string name="tasker_message">If you purchased the stand-alone Tasker plugin please send your Google Play Store transaction ID to support@tasks.org and you will receive a promo code for this in-app purchase. You can find the transaction ID in your Google Play Store order confirmation e-mail or by visiting wallet.google.com</string>

@ -1,8 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="debug_unlock_purchases">Unlock purchases</string>
<string name="debug_consume_purchases">Consume purchases</string>
<string name="debug">Debug</string>
</resources>

@ -0,0 +1,62 @@
package org.tasks.dialogs;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import org.tasks.R;
import org.tasks.billing.PurchaseHelper;
import org.tasks.injection.InjectingNativeDialogFragment;
import org.tasks.injection.NativeDialogFragmentComponent;
import org.tasks.preferences.BasicPreferences;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.inject.Inject;
public class DonationDialog extends InjectingNativeDialogFragment {
public static DonationDialog newDonationDialog() {
return new DonationDialog();
}
@Inject DialogBuilder dialogBuilder;
@Inject PurchaseHelper purchaseHelper;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final List<String> donationValues = getDonationValues();
return dialogBuilder.newDialog()
.setTitle(R.string.select_amount)
.setItems(donationValues, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String value = donationValues.get(which);
Pattern pattern = Pattern.compile("\\$(\\d+) USD");
Matcher matcher = pattern.matcher(value);
//noinspection ResultOfMethodCallIgnored
matcher.matches();
String sku = String.format(java.util.Locale.ENGLISH, "%03d", Integer.parseInt(matcher.group(1)));
purchaseHelper.purchase(dialogBuilder, getActivity(), sku, null, BasicPreferences.REQUEST_PURCHASE, (BasicPreferences) getActivity());
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
}
private List<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;
}
@Override
protected void inject(NativeDialogFragmentComponent component) {
component.inject(this);
}
}

@ -100,8 +100,6 @@ public interface BaseActivityComponent {
void inject(MiscellaneousPreferences miscellaneousPreferences);
void inject(BasicPreferences basicPreferences);
void inject(HelpAndFeedbackActivity helpAndFeedbackActivity);
void inject(DateShortcutPreferences dateShortcutPreferences);
@ -111,4 +109,6 @@ public interface BaseActivityComponent {
void inject(MyFilePickerActivity myFilePickerActivity);
void inject(ColorPickerActivity colorPickerActivity);
void inject(BasicPreferences basicPreferences);
}

@ -1,5 +1,6 @@
package org.tasks.injection;
import org.tasks.dialogs.DonationDialog;
import org.tasks.dialogs.ExportTasksDialog;
import org.tasks.dialogs.ImportTasksDialog;
import org.tasks.dialogs.NativeDatePickerDialog;
@ -19,4 +20,6 @@ public interface BaseNativeDialogFragmentComponent {
void inject(ExportTasksDialog exportTasksDialog);
void inject(ImportTasksDialog importTasksDialog);
void inject(DonationDialog donationDialog);
}

@ -3,8 +3,10 @@ package org.tasks.preferences;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.TwoStatePreference;
import com.google.common.base.Strings;
import com.jakewharton.processphoenix.ProcessPhoenix;
@ -13,15 +15,20 @@ import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.core.OldTaskPreferences;
import com.todoroo.astrid.reminders.ReminderPreferences;
import org.tasks.BuildConfig;
import org.tasks.R;
import org.tasks.activities.ColorPickerActivity;
import org.tasks.analytics.Tracker;
import org.tasks.analytics.Tracking;
import org.tasks.billing.PurchaseHelper;
import org.tasks.billing.PurchaseHelperCallback;
import org.tasks.dialogs.ColorPickerDialog;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.InjectingPreferenceActivity;
import org.tasks.locale.Locale;
import org.tasks.locale.LocalePickerDialog;
import org.tasks.receivers.TeslaUnreadReceiver;
import org.tasks.themes.ThemeAccent;
import org.tasks.themes.ThemeBase;
import org.tasks.themes.ThemeCache;
@ -29,18 +36,23 @@ import org.tasks.themes.ThemeColor;
import javax.inject.Inject;
import timber.log.Timber;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastJellybeanMR1;
import static org.tasks.dialogs.DonationDialog.newDonationDialog;
import static org.tasks.locale.LocalePickerDialog.newLocalePickerDialog;
public abstract class BaseBasicPreferences extends InjectingPreferenceActivity implements
LocalePickerDialog.LocaleSelectionHandler {
public class BasicPreferences extends InjectingPreferenceActivity implements
LocalePickerDialog.LocaleSelectionHandler, PurchaseHelperCallback {
private static final String EXTRA_RESULT = "extra_result";
private static final String FRAG_TAG_LOCALE_PICKER = "frag_tag_locale_picker";
private static final String FRAG_TAG_DONATION = "frag_tag_donation";
private static final int RC_PREFS = 10001;
private static final int REQUEST_THEME_PICKER = 10002;
private static final int REQUEST_COLOR_PICKER = 10003;
private static final int REQUEST_ACCENT_PICKER = 10004;
public static final int REQUEST_PURCHASE = 10005;
@Inject Tracker tracker;
@Inject Preferences preferences;
@ -50,6 +62,8 @@ public abstract class BaseBasicPreferences extends InjectingPreferenceActivity i
@Inject DialogBuilder dialogBuilder;
@Inject Locale locale;
@Inject ThemeCache themeCache;
@Inject TeslaUnreadReceiver teslaUnreadReceiver;
@Inject PurchaseHelper purchaseHelper;
private Bundle result;
@ -63,12 +77,16 @@ public abstract class BaseBasicPreferences extends InjectingPreferenceActivity i
addPreferencesFromResource(R.xml.preferences_addons);
addPreferencesFromResource(R.xml.preferences_privacy);
setupActivity(R.string.EPr_appearance_header, AppearancePreferences.class);
setupActivity(R.string.notifications, ReminderPreferences.class);
setupActivity(R.string.EPr_manage_header, OldTaskPreferences.class);
Preference themePreference = findPreference(getString(R.string.p_theme));
themePreference.setSummary(themeBase.getName());
themePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
startActivityForResult(new Intent(BaseBasicPreferences.this, ColorPickerActivity.class) {{
startActivityForResult(new Intent(BasicPreferences.this, ColorPickerActivity.class) {{
putExtra(ColorPickerActivity.EXTRA_PALETTE, ColorPickerDialog.ColorPalette.THEMES);
}}, REQUEST_THEME_PICKER);
return false;
@ -79,7 +97,7 @@ public abstract class BaseBasicPreferences extends InjectingPreferenceActivity i
colorPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
startActivityForResult(new Intent(BaseBasicPreferences.this, ColorPickerActivity.class) {{
startActivityForResult(new Intent(BasicPreferences.this, ColorPickerActivity.class) {{
putExtra(ColorPickerActivity.EXTRA_PALETTE, ColorPickerDialog.ColorPalette.COLORS);
}}, REQUEST_COLOR_PICKER);
return false;
@ -90,7 +108,7 @@ public abstract class BaseBasicPreferences extends InjectingPreferenceActivity i
accentPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
startActivityForResult(new Intent(BaseBasicPreferences.this, ColorPickerActivity.class) {{
startActivityForResult(new Intent(BasicPreferences.this, ColorPickerActivity.class) {{
putExtra(ColorPickerActivity.EXTRA_PALETTE, ColorPickerDialog.ColorPalette.ACCENTS);
}}, REQUEST_ACCENT_PICKER);
return false;
@ -128,18 +146,103 @@ public abstract class BaseBasicPreferences extends InjectingPreferenceActivity i
}
});
setupActivity(R.string.EPr_appearance_header, AppearancePreferences.class);
setupActivity(R.string.notifications, ReminderPreferences.class);
setupActivity(R.string.EPr_manage_header, OldTaskPreferences.class);
getPref(R.string.TLA_menu_donate).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (BuildConfig.FLAVOR_store.equals("googleplay")) {
newDonationDialog().show(getFragmentManager(), FRAG_TAG_DONATION);
} else {
startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("http://tasks.org/donate")));
}
return false;
}
});
getPref(R.string.p_purchased_themes).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (newValue != null && (boolean) newValue && !preferences.hasPurchase(R.string.p_purchased_themes)) {
purchaseHelper.purchase(dialogBuilder, BasicPreferences.this, getString(R.string.sku_themes), getString(R.string.p_purchased_themes), REQUEST_PURCHASE, BasicPreferences.this);
}
return false;
}
});
getPref(R.string.p_tesla_unread_enabled).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (newValue != null) {
if ((boolean) newValue && !preferences.hasPurchase(R.string.p_purchased_tesla_unread)) {
purchaseHelper.purchase(dialogBuilder, BasicPreferences.this, getString(R.string.sku_tesla_unread), getString(R.string.p_purchased_tesla_unread), REQUEST_PURCHASE, BasicPreferences.this);
} else {
teslaUnreadReceiver.setEnabled((boolean) newValue);
return true;
}
}
return false;
}
});
getPref(R.string.p_purchased_tasker).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (newValue != null && (boolean) newValue && !preferences.hasPurchase(R.string.p_purchased_tasker)) {
purchaseHelper.purchase(dialogBuilder, BasicPreferences.this, getString(R.string.sku_tasker), getString(R.string.p_purchased_tasker), 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);
}
return false;
}
});
if (BuildConfig.DEBUG) {
addPreferencesFromResource(R.xml.preferences_debug);
findPreference(getString(R.string.debug_unlock_purchases)).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
preferences.setBoolean(R.string.p_purchased_dashclock, true);
preferences.setBoolean(R.string.p_purchased_tasker, true);
preferences.setBoolean(R.string.p_purchased_tesla_unread, true);
preferences.setBoolean(R.string.p_purchased_themes, true);
recreate();
return true;
}
});
findPreference(getString(R.string.debug_consume_purchases)).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
purchaseHelper.consumePurchases();
recreate();
return true;
}
});
}
requires(R.string.get_plugins, atLeastJellybeanMR1(), R.string.p_purchased_dashclock);
requires(R.string.settings_localization, atLeastJellybeanMR1(), R.string.p_language, R.string.p_layout_direction);
if (!BuildConfig.FLAVOR_store.equals("googleplay")) {
requires(R.string.settings_general, false, R.string.synchronization);
requires(R.string.get_plugins, false, R.string.p_purchased_tasker, R.string.p_purchased_dashclock);
requires(R.string.privacy, false, R.string.p_collect_statistics);
}
}
private void setupActivity(int key, final Class<?> target) {
findPreference(getString(key)).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
startActivityForResult(new Intent(BaseBasicPreferences.this, target), RC_PREFS);
startActivityForResult(new Intent(BasicPreferences.this, target), RC_PREFS);
return true;
}
});
@ -182,6 +285,8 @@ public abstract class BaseBasicPreferences extends InjectingPreferenceActivity i
if (resultCode == Activity.RESULT_OK && data != null) {
result.putAll(data.getExtras());
}
} else if (requestCode == REQUEST_PURCHASE) {
purchaseHelper.handleActivityResult(this, requestCode, resultCode, data);
} else {
super.onActivityResult(requestCode, resultCode, data);
}
@ -208,7 +313,7 @@ public abstract class BaseBasicPreferences extends InjectingPreferenceActivity i
.setPositiveButton(R.string.restart_now, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
ProcessPhoenix.triggerRebirth(BaseBasicPreferences.this, new Intent(BaseBasicPreferences.this, TaskListActivity.class) {{
ProcessPhoenix.triggerRebirth(BasicPreferences.this, new Intent(BasicPreferences.this, TaskListActivity.class) {{
putExtra(TaskListActivity.OPEN_FILTER, (Filter) null);
}});
}
@ -231,4 +336,38 @@ public abstract class BaseBasicPreferences extends InjectingPreferenceActivity i
super.finish();
}
@Override
public void purchaseCompleted(final boolean success, final String sku) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (getString(R.string.sku_tasker).equals(sku)) {
((TwoStatePreference) getPref(R.string.p_purchased_tasker)).setChecked(success);
} else if (getString(R.string.sku_tesla_unread).equals(sku)) {
((TwoStatePreference) getPref(R.string.p_tesla_unread_enabled)).setChecked(success);
} else if (getString(R.string.sku_dashclock).equals(sku)) {
((TwoStatePreference) getPref(R.string.p_purchased_dashclock)).setChecked(success);
} else if (getString(R.string.sku_themes).equals(sku)) {
((TwoStatePreference) getPref(R.string.p_purchased_themes)).setChecked(success);
} else {
Timber.d("Unhandled sku: %s", sku);
}
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
if (!isChangingConfigurations()) {
purchaseHelper.disposeIabHelper();
}
}
@Override
public void inject(ActivityComponent component) {
component.inject(this);
}
}

@ -324,4 +324,11 @@
<string name="p_widget_show_header">widget-show-header-</string>
<string name="p_widget_show_settings">widget-show-settings-</string>
<string name="sku_tasker">tasker</string>
<string name="sku_tesla_unread">tesla_unread</string>
<string name="sku_dashclock">dashclock</string>
<string name="debug_unlock_purchases">Unlock purchases</string>
<string name="debug_consume_purchases">Consume purchases</string>
<string name="debug">Debug</string>
</resources>

Loading…
Cancel
Save