mirror of https://github.com/tasks/tasks
Flavor specific injections
parent
5ab3cbaf4f
commit
df6a64cf7a
@ -1,12 +0,0 @@
|
||||
package com.todoroo.astrid.gtasks;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class GtasksIndentActionTest extends AndroidTestCase {
|
||||
@Inject
|
||||
public GtasksIndentActionTest() {
|
||||
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package com.todoroo.astrid.gtasks;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class GtasksListServiceTest extends AndroidTestCase {
|
||||
@Inject
|
||||
public GtasksListServiceTest() {
|
||||
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package com.todoroo.astrid.gtasks;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class GtasksTaskListUpdaterTest extends AndroidTestCase {
|
||||
@Inject
|
||||
public GtasksTaskListUpdaterTest() {
|
||||
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package com.todoroo.astrid.gtasks;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class GtasksTaskMovingTest extends AndroidTestCase {
|
||||
@Inject
|
||||
public GtasksTaskMovingTest() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package org.tasks.injection;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Component;
|
||||
|
||||
@Singleton
|
||||
@Component(modules = TestModule.class)
|
||||
public interface TestComponent extends BaseTestComponent {
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package org.tasks.injection;
|
||||
|
||||
import com.todoroo.astrid.gtasks.GtasksIndentActionTest;
|
||||
import com.todoroo.astrid.gtasks.GtasksListServiceTest;
|
||||
import com.todoroo.astrid.gtasks.GtasksMetadataServiceTest;
|
||||
import com.todoroo.astrid.gtasks.GtasksTaskListUpdaterTest;
|
||||
import com.todoroo.astrid.gtasks.GtasksTaskMovingTest;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Component;
|
||||
|
||||
@Singleton
|
||||
@Component(modules = TestModule.class)
|
||||
public interface TestComponent extends BaseTestComponent {
|
||||
|
||||
GtasksMetadataServiceTest.GtasksMetadataServiceTestComponent plus(GtasksMetadataServiceTest.GtasksMetadataServiceTestModule gtasksMetadataServiceTestModule);
|
||||
|
||||
void inject(GtasksIndentActionTest gtasksIndentActionTest);
|
||||
|
||||
void inject(GtasksTaskMovingTest gtasksTaskMovingTest);
|
||||
|
||||
void inject(GtasksListServiceTest gtasksListServiceTest);
|
||||
|
||||
void inject(GtasksTaskListUpdaterTest gtasksTaskListUpdaterTest);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package com.todoroo.astrid.gtasks;
|
||||
|
||||
import com.todoroo.astrid.activity.TaskListFragment;
|
||||
import com.todoroo.astrid.subtasks.SubtasksListFragment;
|
||||
|
||||
public class GtasksListFragment extends TaskListFragment {
|
||||
public class GtasksListFragment extends SubtasksListFragment {
|
||||
public static final String TOKEN_STORE_ID = "storeId";
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
package com.todoroo.astrid.gtasks;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class GtasksMetadataService {
|
||||
@Inject
|
||||
public GtasksMetadataService() {
|
||||
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package com.todoroo.astrid.gtasks;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class GtasksPreferences {
|
||||
@Inject
|
||||
public GtasksPreferences() {
|
||||
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package com.todoroo.astrid.gtasks;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class GtasksTaskListUpdater {
|
||||
@Inject
|
||||
public GtasksTaskListUpdater() {
|
||||
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package com.todoroo.astrid.gtasks.auth;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class GtasksLoginActivity {
|
||||
@Inject
|
||||
public GtasksLoginActivity() {
|
||||
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.todoroo.astrid.gtasks.sync;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class GtasksSyncService {
|
||||
@Inject
|
||||
public GtasksSyncService() {
|
||||
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package org.tasks;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class FlavorSetup {
|
||||
@Inject
|
||||
public FlavorSetup() {
|
||||
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package org.tasks.injection;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Subcomponent;
|
||||
|
||||
@Singleton
|
||||
@Subcomponent(modules = ActivityModule.class)
|
||||
public interface ActivityComponent extends BaseActivityComponent {
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package org.tasks.injection;
|
||||
|
||||
import dagger.Subcomponent;
|
||||
|
||||
@Subcomponent(modules = BroadcastModule.class)
|
||||
public interface BroadcastComponent extends BaseBroadcastComponent {
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package org.tasks.preferences;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceScreen;
|
||||
|
||||
import org.tasks.R;
|
||||
import org.tasks.injection.ActivityComponent;
|
||||
|
||||
public class BasicPreferences extends BaseBasicPreferences {
|
||||
|
||||
@Override
|
||||
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_tasker_enabled)));
|
||||
preferenceScreen.removePreference(findPreference(getString(R.string.p_collect_statistics)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inject(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package org.tasks;
|
||||
|
||||
import com.todoroo.astrid.gtasks.GtasksPreferenceService;
|
||||
import com.todoroo.astrid.gtasks.GtasksTaskListUpdater;
|
||||
import com.todoroo.astrid.gtasks.sync.GtasksSyncService;
|
||||
|
||||
import org.tasks.billing.IabHelper;
|
||||
import org.tasks.preferences.Preferences;
|
||||
import org.tasks.receivers.TeslaUnreadReceiver;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class FlavorSetup {
|
||||
|
||||
private final Preferences preferences;
|
||||
private final GtasksSyncService gtasksSyncService;
|
||||
private final GtasksPreferenceService gtasksPreferenceService;
|
||||
private final TeslaUnreadReceiver teslaUnreadReceiver;
|
||||
private final IabHelper iabHelper;
|
||||
|
||||
@Inject
|
||||
public FlavorSetup(Preferences preferences,
|
||||
@SuppressWarnings("UnusedParameters") GtasksTaskListUpdater gtasksTaskListUpdater,
|
||||
GtasksSyncService gtasksSyncService, GtasksPreferenceService gtasksPreferenceService,
|
||||
TeslaUnreadReceiver teslaUnreadReceiver, IabHelper iabHelper) {
|
||||
this.preferences = preferences;
|
||||
this.gtasksSyncService = gtasksSyncService;
|
||||
this.gtasksPreferenceService = gtasksPreferenceService;
|
||||
this.teslaUnreadReceiver = teslaUnreadReceiver;
|
||||
this.iabHelper = iabHelper;
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
iabHelper.startSetup();
|
||||
teslaUnreadReceiver.setEnabled(preferences.getBoolean(R.string.p_tesla_unread_enabled, false));
|
||||
gtasksPreferenceService.stopOngoing(); // if sync ongoing flag was set, clear it
|
||||
gtasksSyncService.initialize();
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package org.tasks.injection;
|
||||
|
||||
import com.todoroo.astrid.gtasks.GtasksPreferences;
|
||||
import com.todoroo.astrid.gtasks.auth.GtasksLoginActivity;
|
||||
|
||||
import org.tasks.locale.ui.activity.TaskerSettingsActivity;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Subcomponent;
|
||||
|
||||
@Singleton
|
||||
@Subcomponent(modules = ActivityModule.class)
|
||||
public interface ActivityComponent extends BaseActivityComponent {
|
||||
void inject(GtasksPreferences gtasksPreferences);
|
||||
|
||||
void inject(TaskerSettingsActivity taskerSettingsActivity);
|
||||
|
||||
void inject(GtasksLoginActivity gtasksLoginActivity);
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package org.tasks.injection;
|
||||
|
||||
import org.tasks.receivers.TeslaUnreadReceiver;
|
||||
|
||||
import dagger.Subcomponent;
|
||||
|
||||
@Subcomponent(modules = BroadcastModule.class)
|
||||
public interface BroadcastComponent extends BaseBroadcastComponent {
|
||||
void inject(TeslaUnreadReceiver teslaUnreadReceiver);
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
package org.tasks.preferences;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
|
||||
import org.tasks.BuildConfig;
|
||||
import org.tasks.R;
|
||||
import org.tasks.analytics.Tracker;
|
||||
import org.tasks.billing.IabHelper;
|
||||
import org.tasks.billing.IabResult;
|
||||
import org.tasks.billing.Purchase;
|
||||
import org.tasks.injection.ActivityComponent;
|
||||
import org.tasks.receivers.TeslaUnreadReceiver;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class BasicPreferences extends BaseBasicPreferences implements IabHelper.OnIabPurchaseFinishedListener {
|
||||
|
||||
private static final int REQUEST_PURCHASE_TESLA_UNREAD = 10002;
|
||||
private static final int REQUEST_PURCHASE_TASKER = 10003;
|
||||
|
||||
@Inject Tracker tracker;
|
||||
@Inject IabHelper iabHelper;
|
||||
@Inject TeslaUnreadReceiver teslaUnreadReceiver;
|
||||
@Inject Preferences preferences;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
findPreference(getString(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.getBoolean(R.string.p_purchased_tesla_unread, BuildConfig.DEBUG)) {
|
||||
iabHelper.launchPurchaseFlow(BasicPreferences.this, getString(R.string.sku_tesla_unread), REQUEST_PURCHASE_TESLA_UNREAD, BasicPreferences.this);
|
||||
} else {
|
||||
teslaUnreadReceiver.setEnabled((boolean) newValue);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
findPreference(getString(R.string.p_tasker_enabled)).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if (newValue != null) {
|
||||
if ((boolean) newValue && !preferences.getBoolean(R.string.p_purchased_tasker, BuildConfig.DEBUG)) {
|
||||
iabHelper.launchPurchaseFlow(BasicPreferences.this, getString(R.string.sku_tasker), REQUEST_PURCHASE_TASKER, BasicPreferences.this);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
findPreference(getString(R.string.p_collect_statistics)).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if (newValue != null) {
|
||||
tracker.setTrackingEnabled((boolean) newValue);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIabPurchaseFinished(IabResult result, final Purchase info) {
|
||||
if (result.isSuccess()) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (info.getSku().equals(getString(R.string.sku_tasker))) {
|
||||
preferences.setBoolean(R.string.p_purchased_tasker, true);
|
||||
findPreference(getString(R.string.p_tasker_enabled)).setEnabled(true);
|
||||
} else if (info.getSku().equals(getString(R.string.sku_tesla_unread))) {
|
||||
preferences.setBoolean(R.string.p_purchased_tesla_unread, true);
|
||||
findPreference(getString(R.string.p_tesla_unread_enabled)).setEnabled(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == REQUEST_PURCHASE_TASKER || requestCode == REQUEST_PURCHASE_TESLA_UNREAD) {
|
||||
iabHelper.handleActivityResult(requestCode, resultCode, data);
|
||||
} else {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inject(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package org.tasks.preferences;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceScreen;
|
||||
|
||||
import com.todoroo.astrid.core.OldTaskPreferences;
|
||||
import com.todoroo.astrid.reminders.ReminderPreferences;
|
||||
|
||||
import org.tasks.R;
|
||||
import org.tasks.injection.InjectingPreferenceActivity;
|
||||
|
||||
public abstract class BaseBasicPreferences extends InjectingPreferenceActivity {
|
||||
|
||||
private static final String EXTRA_RESULT = "extra_result";
|
||||
private static final int RC_PREFS = 10001;
|
||||
|
||||
private Bundle result;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
result = savedInstanceState == null ? new Bundle() : savedInstanceState.getBundle(EXTRA_RESULT);
|
||||
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putBundle(EXTRA_RESULT, result);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == RC_PREFS) {
|
||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||
result.putAll(data.getExtras());
|
||||
setResult(Activity.RESULT_OK, new Intent() {{
|
||||
putExtras(result);
|
||||
}});
|
||||
}
|
||||
} else {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,160 +0,0 @@
|
||||
package org.tasks.preferences;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
|
||||
import com.todoroo.astrid.core.OldTaskPreferences;
|
||||
import com.todoroo.astrid.reminders.ReminderPreferences;
|
||||
|
||||
import org.tasks.BuildConfig;
|
||||
import org.tasks.R;
|
||||
import org.tasks.analytics.Tracker;
|
||||
import org.tasks.billing.IabHelper;
|
||||
import org.tasks.billing.IabResult;
|
||||
import org.tasks.billing.Purchase;
|
||||
import org.tasks.injection.ActivityComponent;
|
||||
import org.tasks.injection.InjectingPreferenceActivity;
|
||||
import org.tasks.receivers.TeslaUnreadReceiver;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class BasicPreferences extends InjectingPreferenceActivity implements IabHelper.OnIabPurchaseFinishedListener {
|
||||
|
||||
private static final String EXTRA_RESULT = "extra_result";
|
||||
private static final int RC_PREFS = 10001;
|
||||
private static final int REQUEST_PURCHASE_TESLA_UNREAD = 10002;
|
||||
private static final int REQUEST_PURCHASE_TASKER = 10003;
|
||||
|
||||
private Bundle result;
|
||||
|
||||
@Inject Tracker tracker;
|
||||
@Inject TeslaUnreadReceiver teslaUnreadReceiver;
|
||||
@Inject Preferences preferences;
|
||||
@Inject IabHelper iabHelper;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
result = savedInstanceState == null ? new Bundle() : savedInstanceState.getBundle(EXTRA_RESULT);
|
||||
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
if (!getResources().getBoolean(R.bool.sync_supported)) {
|
||||
getPreferenceScreen().removePreference(findPreference(getString(R.string.synchronization)));
|
||||
}
|
||||
if (getResources().getBoolean(R.bool.google_play_store_available)) {
|
||||
addPreferencesFromResource(R.xml.preferences_addons);
|
||||
addPreferencesFromResource(R.xml.preferences_privacy);
|
||||
|
||||
findPreference(getString(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.getBoolean(R.string.p_purchased_tesla_unread, BuildConfig.DEBUG)) {
|
||||
iabHelper.launchPurchaseFlow(BasicPreferences.this, getString(R.string.sku_tesla_unread), REQUEST_PURCHASE_TESLA_UNREAD, BasicPreferences.this);
|
||||
} else {
|
||||
teslaUnreadReceiver.setEnabled((boolean) newValue);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
findPreference(getString(R.string.p_tasker_enabled)).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if (newValue != null) {
|
||||
if ((boolean) newValue && !preferences.getBoolean(R.string.p_purchased_tasker, BuildConfig.DEBUG)) {
|
||||
iabHelper.launchPurchaseFlow(BasicPreferences.this, getString(R.string.sku_tasker), REQUEST_PURCHASE_TASKER, BasicPreferences.this);
|
||||
} else {
|
||||
toggleTasker(BasicPreferences.this, (boolean) newValue);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
findPreference(getString(R.string.p_collect_statistics)).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if (newValue != null) {
|
||||
tracker.setTrackingEnabled((boolean) newValue);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
setupActivity(R.string.EPr_appearance_header, AppearancePreferences.class);
|
||||
setupActivity(R.string.notifications, ReminderPreferences.class);
|
||||
setupActivity(R.string.EPr_manage_header, OldTaskPreferences.class);
|
||||
}
|
||||
|
||||
public static void toggleTasker(Context context, boolean enabled) {
|
||||
ComponentName componentName = new ComponentName(context, "com.twofortyfouram.locale.example.setting.toast.ui.activity.PluginActivity");
|
||||
int state = enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
|
||||
context.getPackageManager().setComponentEnabledSetting(componentName, state, PackageManager.DONT_KILL_APP);
|
||||
}
|
||||
|
||||
private void setupActivity(int key, final Class<?> target) {
|
||||
findPreference(getString(key)).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
startActivityForResult(new Intent(BasicPreferences.this, target), RC_PREFS);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putBundle(EXTRA_RESULT, result);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == RC_PREFS) {
|
||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||
result.putAll(data.getExtras());
|
||||
setResult(Activity.RESULT_OK, new Intent() {{
|
||||
putExtras(result);
|
||||
}});
|
||||
}
|
||||
} else if (requestCode == REQUEST_PURCHASE_TESLA_UNREAD || requestCode == REQUEST_PURCHASE_TASKER) {
|
||||
iabHelper.handleActivityResult(requestCode, resultCode, data);
|
||||
} else {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inject(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIabPurchaseFinished(IabResult result, final Purchase info) {
|
||||
if (result.isSuccess()) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (info.getSku().equals(getString(R.string.sku_tasker))) {
|
||||
preferences.setBoolean(R.string.p_purchased_tasker, true);
|
||||
findPreference(getString(R.string.p_tasker_enabled)).setEnabled(true);
|
||||
} else if (info.getSku().equals(getString(R.string.sku_tesla_unread))) {
|
||||
preferences.setBoolean(R.string.p_purchased_tesla_unread, true);
|
||||
findPreference(getString(R.string.p_tesla_unread_enabled)).setEnabled(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue