Instead of disabling or enabling market strategy, create a mechanism to swap different markets.

pull/14/head
Tim Su 14 years ago
parent 72a52cb436
commit 28067d440b

@ -59,7 +59,7 @@
message="Cannot run two different modes at the same time. If you are running more than one debug/release/instrument type targets, call them from different Ant calls." />
</target>
<target name="-pre-build" depends="get-version, copy-sources, updatekeys, updatekeys-release, disable-market">
<target name="-pre-build" depends="get-version, copy-sources, updatekeys, updatekeys-release, update-market-strategy">
<mkdir dir="gen" />
<property name="proguard.jar" location="antlib/proguard.jar" />
<taskdef name="proguard" classname="proguard.ant.ProGuardTask" classpath="${proguard.jar}" />
@ -158,13 +158,13 @@
<property name="has.keystore" value="true" />
</target>
<target name="disable-market" if="custom.market.disabled">
<echo message="Disabling android market links" />
<target name="update-market-strategy" if="custom.market.strategy">
<echo message="Changing market strategy to ${custom.market.strategy}" />
<replace token="market://" value="disabled://"
dir="${source.dir}" />
<replaceregexp file="${source.dir}/com/todoroo/astrid/utility/Constants.java"
match="(MARKET_DISABLED.*=).*"
replace="\1 true;" />
match="AndroidMarketStrategy"
replace="${custom.market.strategy}" />
</target>
<target name="obfuscate" depends="-set-debug-files, -set-debug-mode, nodeps, -build-setup,

@ -422,10 +422,9 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
ThemeService.getDrawable(R.drawable.icn_menu_filters, isTablet ? ThemeService.FLAG_INVERT : 0), MENU_NEW_FILTER_ID, true);
// --- addons
if (!Constants.MARKET_DISABLED) {
if(Constants.MARKET_STRATEGY.showAddonMenu())
addMenuItem(menu, R.string.TLA_menu_addons,
ThemeService.getDrawable(R.drawable.icn_menu_plugins, isTablet ? ThemeService.FLAG_FORCE_DARK : 0), MENU_ADDONS_ID, false);
}
ThemeService.getDrawable(R.drawable.icn_menu_plugins, isTablet ? ThemeService.FLAG_FORCE_DARK : 0), MENU_ADDONS_ID, false);
// ask about plug-ins
Intent queryIntent = new Intent(

@ -24,6 +24,7 @@ import android.widget.TextView;
import com.timsu.astrid.R;
import com.todoroo.astrid.data.AddOn;
import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.utility.Constants;
/**
* Adapter for {@link AddOn}s
@ -124,9 +125,7 @@ public class AddOnAdapter extends ArrayAdapter<AddOn> {
} else {
viewHolder.market.setVisibility(View.VISIBLE);
viewHolder.installedIcon.setVisibility(View.GONE);
Intent marketIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("market://search?q=pname:" + //$NON-NLS-1$
item.getPackageName()));
Intent marketIntent = Constants.MARKET_STRATEGY.generateMarketLink(item.getPackageName());
viewHolder.market.setTag(new ButtonTag("market-" + item.getPackageName(), //$NON-NLS-1$
marketIntent));
Drawable icon = getIntentIcon(marketIntent);

@ -1,12 +1,12 @@
package com.todoroo.astrid.service;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import com.timsu.astrid.R;
import com.todoroo.andlib.service.ContextManager;
@ -71,9 +71,7 @@ public class AddOnService {
@Override
public void onClick(DialogInterface arg0, int arg1) {
context.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("market://search?q=pname:" + //$NON-NLS-1$
packageName)));
context.startActivity(Constants.MARKET_STRATEGY.generateMarketLink(packageName));
if(context instanceof Activity)
((Activity)context).finish();
}
@ -159,23 +157,25 @@ public class AddOnService {
Resources r = ContextManager.getContext().getResources();
// temporary temporary
AddOn[] list = new AddOn[3];
list[0] = new AddOn(false, true, "Astrid Power Pack", null,
ArrayList<AddOn> list = new ArrayList<AddOn>(3);
if(Constants.MARKET_STRATEGY.includesPowerPack())
list.add(new AddOn(false, true, "Astrid Power Pack", null,
"Support Astrid and get more productive with the Astrid Power Pack. 4x2 and 4x4 widgets and voice integration. Power up today!",
POWER_PACK_PACKAGE, "http://www.weloveastrid.com/store",
((BitmapDrawable)r.getDrawable(R.drawable.icon_pp)).getBitmap());
((BitmapDrawable)r.getDrawable(R.drawable.icon_pp)).getBitmap()));
list[1] = new AddOn(false, true, "Astrid Locale Plugin", null,
if(Constants.MARKET_STRATEGY.includesLocalePlugin())
list.add(new AddOn(false, true, "Astrid Locale Plugin", null,
"Allows Astrid to make use of the Locale application to send you notifications based on filter conditions. Requires Locale.",
LOCALE_PACKAGE, "http://www.weloveastrid.com/store",
((BitmapDrawable)r.getDrawable(R.drawable.icon_locale)).getBitmap());
((BitmapDrawable)r.getDrawable(R.drawable.icon_locale)).getBitmap()));
list[2] = new AddOn(true, true, "Producteev", null,
list.add(new AddOn(true, true, "Producteev", null,
"Synchronize with Producteev service. Also changes Astrid's importance levels to stars.",
Constants.PACKAGE, "http://www.producteev.com",
((BitmapDrawable)r.getDrawable(R.drawable.icon_producteev)).getBitmap());
((BitmapDrawable)r.getDrawable(R.drawable.icon_producteev)).getBitmap()));
return list;
return list.toArray(new AddOn[list.size()]);
}
}

@ -0,0 +1,62 @@
package com.todoroo.astrid.service;
import android.content.Intent;
import android.net.Uri;
public abstract class MarketStrategy {
/**
* @param packageName
* @return an intent to launch market with this package
*/
abstract public Intent generateMarketLink(String packageName);
/**
* @return if this market has power pack
*/
public boolean includesPowerPack() {
return true;
}
/**
* @return if this market has locale plugin
*/
public boolean includesLocalePlugin() {
return true;
}
/**
* @return true if addons should be shown
*/
public boolean showAddonMenu() {
return true;
}
public static class AndroidMarketStrategy extends MarketStrategy {
@Override
public Intent generateMarketLink(String packageName) {
return new Intent(Intent.ACTION_VIEW,
Uri.parse("market://search?q=pname:" + //$NON-NLS-1$
packageName));
}
}
public static class AmazonMarketStrategy extends MarketStrategy {
@Override
public Intent generateMarketLink(String packageName) {
return new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.amazon.com/gp/mas/dl/android?p=" + //$NON-NLS-1$
packageName));
}
@Override
public boolean includesLocalePlugin() {
return false;
}
}
}

@ -110,7 +110,8 @@ public class StartupService {
if(!StatisticsService.dontCollectStatistics()) {
Crittercism.init(context.getApplicationContext(), Constants.CRITTERCISM_APP_ID);
Crittercism.setShouldUseAmazonMarket(Constants.MARKET_DISABLED);
Crittercism.setShouldUseAmazonMarket(Constants.MARKET_STRATEGY.getClass() ==
MarketStrategy.AmazonMarketStrategy.class);
}
try {
@ -217,6 +218,10 @@ public class StartupService {
hasStartedUp = true;
}
/**
* @param context
* @param e error that was raised
*/
public static void handleSQLiteColumnMissing(Context context, final SQLiteException e) {
new AlertDialog.Builder(context)
.setTitle(R.string.DB_corrupted_title)

@ -1,5 +1,7 @@
package com.todoroo.astrid.utility;
import com.todoroo.astrid.service.MarketStrategy;
@SuppressWarnings("nls")
public final class Constants {
@ -21,9 +23,9 @@ public final class Constants {
public static final boolean OEM = false;
/**
* Whether this is an Android Market-disabled build
* Market selection strategy
*/
public static final boolean MARKET_DISABLED = false;
public static final MarketStrategy MARKET_STRATEGY = new MarketStrategy.AndroidMarketStrategy();
/**
* Interval to update the widget (in order to detect hidden tasks

@ -11,7 +11,6 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.speech.RecognizerIntent;
import android.support.v4.app.Fragment;
import android.util.Log;
@ -25,6 +24,7 @@ import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.utility.Constants;
/**
* This class handles taking voice-input and appends the text to the registered EditText-instance.
@ -312,8 +312,7 @@ public class VoiceInputAssistant {
packageName = "com.google.android.voicesearch";
// User wants to install voice search, take them to the market
Intent marketIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("market://search?q=pname:" + packageName)); //$NON-NLS-1$
Intent marketIntent = Constants.MARKET_STRATEGY.generateMarketLink(packageName);
if (activity != null) {
try {
activity.startActivity(marketIntent);

@ -48,7 +48,7 @@
<subant>
<fileset file="astrid/build.xml" />
<property name="custom.version.name" value=".1000" />
<property name="custom.market.disabled" value="true" />
<property name="custom.market.strategy" value="AmazonMarketStrategy" />
<target name="release-custom" />
</subant>
</target>

Loading…
Cancel
Save