mirror of https://github.com/tasks/tasks
Remove AddOnActivity and AddOnService
parent
7e73c12c53
commit
41f736a6a6
@ -1,184 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.activity;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
import com.actionbarsherlock.app.ActionBar.Tab;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
import com.timsu.astrid.R;
|
||||
import com.todoroo.andlib.service.Autowired;
|
||||
import com.todoroo.andlib.service.DependencyInjectionService;
|
||||
import com.todoroo.astrid.adapter.AddOnAdapter;
|
||||
import com.todoroo.astrid.data.AddOn;
|
||||
import com.todoroo.astrid.service.AddOnService;
|
||||
import com.todoroo.astrid.service.AstridDependencyInjector;
|
||||
import com.todoroo.astrid.service.ThemeService;
|
||||
import com.todoroo.astrid.utility.Constants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* TODO: fix deprecation or get rid of me
|
||||
*
|
||||
* @author Tim Su <tim@todoroo.com>
|
||||
*/
|
||||
public class AddOnActivity extends SherlockFragmentActivity {
|
||||
|
||||
/**
|
||||
* boolean: whether to start on available page
|
||||
*/
|
||||
public static final String TOKEN_START_WITH_AVAILABLE = "av"; //$NON-NLS-1$
|
||||
|
||||
private View installedView;
|
||||
private View availableView;
|
||||
|
||||
@Autowired
|
||||
AddOnService addOnService;
|
||||
|
||||
static {
|
||||
AstridDependencyInjector.initialize();
|
||||
}
|
||||
|
||||
public AddOnActivity() {
|
||||
DependencyInjectionService.getInstance().inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
ThemeService.applyTheme(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(this);
|
||||
installedView = inflater.inflate(R.layout.addon_list_container, null);
|
||||
availableView = inflater.inflate(R.layout.addon_list_container, null);
|
||||
|
||||
ActionBar ab = getSupportActionBar();
|
||||
ab.setDisplayHomeAsUpEnabled(true);
|
||||
ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
||||
ActionBar.Tab installedTab = ab.newTab().setText(" " + getString(R.string.AOA_tab_installed)) //$NON-NLS-1$
|
||||
.setIcon(R.drawable.gl_pencil)
|
||||
.setTabListener(new AddOnTabListener(installedView));
|
||||
|
||||
ActionBar.Tab availableTab = ab.newTab().setText(" " + getString(R.string.AOA_tab_available)) //$NON-NLS-1$
|
||||
.setIcon(R.drawable.gl_more)
|
||||
.setTabListener(new AddOnTabListener(availableView));
|
||||
|
||||
ab.addTab(availableTab);
|
||||
ab.addTab(installedTab);
|
||||
|
||||
setTitle(R.string.AOA_title);
|
||||
|
||||
populate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private class AddOnTabListener implements ActionBar.TabListener {
|
||||
|
||||
private final View mView;
|
||||
|
||||
public AddOnTabListener(View v) {
|
||||
this.mView = v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(Tab tab, FragmentTransaction ft) {
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabSelected(Tab tab, FragmentTransaction ft) {
|
||||
setContentView(mView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
|
||||
//
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void populate() {
|
||||
AddOn[] list = addOnService.getAddOns();
|
||||
if (list == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<AddOn> installed = new ArrayList<AddOn>();
|
||||
ArrayList<AddOn> available = new ArrayList<AddOn>();
|
||||
|
||||
for (AddOn addOn : list) {
|
||||
if (AddOnService.POWER_PACK_PACKAGE.equals(addOn.getPackageName())) {
|
||||
if (addOnService.hasPowerPack()) {
|
||||
installed.add(addOn);
|
||||
} else if (Constants.MARKET_STRATEGY.generateMarketLink(addOn.getPackageName()) != null) {
|
||||
available.add(addOn);
|
||||
}
|
||||
} else {
|
||||
if (addOnService.isInstalled(addOn)) {
|
||||
installed.add(addOn);
|
||||
} else if (Constants.MARKET_STRATEGY.generateMarketLink(addOn.getPackageName()) != null) {
|
||||
available.add(addOn);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ListView installedList = (ListView) installedView.findViewById(R.id.list);
|
||||
installedList.setAdapter(new AddOnAdapter(this, true, installed));
|
||||
if (installed.size() > 0) {
|
||||
installedView.findViewById(R.id.empty).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
ListView availableList = (ListView) availableView.findViewById(R.id.list);
|
||||
availableList.setAdapter(new AddOnAdapter(this, false, available));
|
||||
if (available.size() > 0) {
|
||||
availableView.findViewById(R.id.empty).setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an on click listener
|
||||
*
|
||||
* @param activity
|
||||
* @param finish whether to finish activity
|
||||
* @return
|
||||
*/
|
||||
public static DialogInterface.OnClickListener createAddOnClicker(final Activity activity,
|
||||
final boolean finish) {
|
||||
return new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Intent intent = new Intent(activity,
|
||||
AddOnActivity.class);
|
||||
intent.putExtra(AddOnActivity.TOKEN_START_WITH_AVAILABLE, true);
|
||||
activity.startActivity(intent);
|
||||
if (finish) {
|
||||
activity.finish();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,179 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.service;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
|
||||
import com.timsu.astrid.R;
|
||||
import com.todoroo.andlib.service.ContextManager;
|
||||
import com.todoroo.andlib.utility.AndroidUtilities;
|
||||
import com.todoroo.andlib.utility.Preferences;
|
||||
import com.todoroo.astrid.data.AddOn;
|
||||
import com.todoroo.astrid.utility.Constants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Astrid Service for managing add-ons
|
||||
*
|
||||
* @author Tim Su <tim@todoroo.com>
|
||||
*/
|
||||
|
||||
public class AddOnService {
|
||||
|
||||
/**
|
||||
* OEM preference key
|
||||
*/
|
||||
private static final String PREF_OEM = "poem";
|
||||
|
||||
/**
|
||||
* Astrid Power Pack package
|
||||
*/
|
||||
public static final String POWER_PACK_PACKAGE = "com.todoroo.astrid.ppack";
|
||||
|
||||
/**
|
||||
* Astrid Locale package
|
||||
*/
|
||||
public static final String LOCALE_PACKAGE = "com.todoroo.astrid.locale";
|
||||
|
||||
/**
|
||||
* Astrid Power Pack label
|
||||
*/
|
||||
public static final String POWER_PACK_LABEL = "Astrid Power Pack";
|
||||
|
||||
/**
|
||||
* Checks whether power pack should be enabled
|
||||
*/
|
||||
public boolean hasPowerPack() {
|
||||
if (Preferences.getBoolean(PREF_OEM, false)) {
|
||||
return true;
|
||||
} else if (isInstalled(POWER_PACK_PACKAGE, true)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether locale plugin should be enabled
|
||||
*/
|
||||
public boolean hasLocalePlugin() {
|
||||
if (Preferences.getBoolean(PREF_OEM, false)) {
|
||||
return true;
|
||||
} else if (isInstalled(LOCALE_PACKAGE, true)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Record that a version was an OEM install
|
||||
*/
|
||||
public static void recordOem() {
|
||||
Preferences.setBoolean(PREF_OEM, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a given add-on is installed
|
||||
*
|
||||
* @param addOn
|
||||
* @return
|
||||
*/
|
||||
public boolean isInstalled(AddOn addOn) {
|
||||
// it isnt installed if it is null...
|
||||
if (addOn == null) {
|
||||
return false;
|
||||
}
|
||||
return isInstalled(addOn.getPackageName(), addOn.isInternal());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether an external add-on is installed
|
||||
*
|
||||
* @param packageName
|
||||
* @return
|
||||
*/
|
||||
public boolean isInstalled(String packageName) {
|
||||
return isInstalled(packageName, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a given add-on is installed
|
||||
*
|
||||
* @param addOn
|
||||
* @param internal whether to do api sig check
|
||||
* @return
|
||||
*/
|
||||
private boolean isInstalled(String packageName, boolean internal) {
|
||||
if (Constants.PACKAGE.equals(packageName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Context context = ContextManager.getContext();
|
||||
|
||||
String packageSignature = AndroidUtilities.getSignature(context, packageName);
|
||||
if (packageSignature == null) {
|
||||
return false;
|
||||
}
|
||||
if (!internal) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String astridSignature = AndroidUtilities.getSignature(context, Constants.PACKAGE);
|
||||
return packageSignature.equals(astridSignature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one AddOn-descriptor by packageName and title.
|
||||
*
|
||||
* @param packageName could be Constants.PACKAGE or one of AddOnService-constants
|
||||
* @param title the descriptive title, as in "Astrid Power Pack"
|
||||
* @return the addon-descriptor, if it is available (registered here in getAddOns), otherwise null
|
||||
*/
|
||||
public AddOn getAddOn(String packageName, String title) {
|
||||
if (title == null || packageName == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
AddOn addon = null;
|
||||
AddOn[] addons = getAddOns();
|
||||
for (AddOn addon1 : addons) {
|
||||
if (packageName.equals(addon1.getPackageName()) && title.equals(addon1.getTitle())) {
|
||||
addon = addon1;
|
||||
}
|
||||
}
|
||||
return addon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of add-ons
|
||||
*
|
||||
* @return available add-ons
|
||||
*/
|
||||
public AddOn[] getAddOns() {
|
||||
Resources r = ContextManager.getContext().getResources();
|
||||
|
||||
// temporary temporary
|
||||
ArrayList<AddOn> list = new ArrayList<AddOn>(3);
|
||||
if (Constants.MARKET_STRATEGY.includesPowerPack()) {
|
||||
list.add(new AddOn(false, true, r.getString(R.string.AOA_ppack_title), null,
|
||||
r.getString(R.string.AOA_ppack_description),
|
||||
POWER_PACK_PACKAGE,
|
||||
((BitmapDrawable) r.getDrawable(R.drawable.icon_pp)).getBitmap()));
|
||||
}
|
||||
|
||||
if (Constants.MARKET_STRATEGY.includesLocalePlugin()) {
|
||||
list.add(new AddOn(false, true, r.getString(R.string.AOA_locale_title), null,
|
||||
r.getString(R.string.AOA_locale_description),
|
||||
LOCALE_PACKAGE,
|
||||
((BitmapDrawable) r.getDrawable(R.drawable.icon_locale)).getBitmap()));
|
||||
}
|
||||
|
||||
return list.toArray(new AddOn[list.size()]);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue