Remove AddOnActivity

pull/46/head
Alex Baker 11 years ago
parent b47a92fd95
commit d9cdb57b81

@ -162,11 +162,6 @@
</intent-filter> </intent-filter>
</activity> </activity>
<!-- Activity that selects and installs add-ons -->
<activity
android:name="com.todoroo.astrid.activity.AddOnActivity"
android:windowSoftInputMode="stateHidden" />
<!-- Activity for preferences --> <!-- Activity for preferences -->
<activity <activity
android:name="com.todoroo.astrid.activity.EditPreferences" android:name="com.todoroo.astrid.activity.EditPreferences"

@ -1,182 +0,0 @@
/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.activity;
import java.util.ArrayList;
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 org.tasks.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;
/**
* 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,156 +0,0 @@
/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.adapter;
import java.util.List;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import org.tasks.R;
import com.todoroo.astrid.data.AddOn;
import com.todoroo.astrid.utility.Constants;
/**
* Adapter for {@link AddOn}s
*
* @author Tim Su <tim@todoroo.com>
*
*/
public class AddOnAdapter extends ArrayAdapter<AddOn> {
// --- instance variables
private final Activity activity;
private final LayoutInflater inflater;
private final boolean installed;
public AddOnAdapter(Activity activity, boolean installed, List<AddOn> objects) {
super(activity, R.id.title, objects);
this.installed = installed;
this.activity = activity;
inflater = (LayoutInflater) activity.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
}
// --- view construction
View.OnClickListener intentClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
ButtonTag buttonTag = (ButtonTag) v.getTag();
if(buttonTag != null) {
try {
activity.startActivity(buttonTag.intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(activity, R.string.market_unavailable, Toast.LENGTH_LONG).show();
}
}
}
};
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) {
convertView = inflater.inflate(R.layout.addon_adapter_row, parent, false);
ViewHolder viewHolder = new ViewHolder();
viewHolder.icon = (ImageView) convertView.findViewById(R.id.icon);
viewHolder.free = (TextView) convertView.findViewById(R.id.free);
viewHolder.title = (TextView) convertView.findViewById(R.id.title);
viewHolder.description = (TextView) convertView.findViewById(R.id.description);
viewHolder.market = (ImageButton) convertView.findViewById(R.id.button_market);
viewHolder.installedIcon = (ImageView) convertView.findViewById(R.id.check);
convertView.setTag(viewHolder);
viewHolder.market.setOnClickListener(intentClickListener);
}
((ViewHolder)convertView.getTag()).item = getItem(position);
initializeView(convertView);
return convertView;
}
private class ViewHolder {
public AddOn item;
public ImageView icon;
public TextView free;
public TextView title;
public TextView description;
public ImageButton market;
public ImageView installedIcon;
}
private class ButtonTag {
String event;
Intent intent;
public ButtonTag(String message, Intent intent) {
this.event = message;
this.intent = intent;
}
}
private void initializeView(View convertView) {
ViewHolder viewHolder = (ViewHolder) convertView.getTag();
AddOn item = viewHolder.item;
viewHolder.icon.setImageBitmap(item.getIcon());
viewHolder.title.setText(item.getTitle());
viewHolder.description.setText(item.getDescription());
viewHolder.free.setVisibility(item.isFree() && !installed ? View.VISIBLE : View.GONE);
// populate buttons
if(installed) {
viewHolder.market.setVisibility(View.GONE);
viewHolder.installedIcon.setVisibility(View.VISIBLE);
} else {
viewHolder.market.setVisibility(View.VISIBLE);
viewHolder.installedIcon.setVisibility(View.GONE);
Intent marketIntent = Constants.MARKET_STRATEGY.generateMarketLink(item.getPackageName());
if (marketIntent == null) {
convertView.setVisibility(View.GONE);
} else {
convertView.setVisibility(View.VISIBLE);
viewHolder.market.setTag(new ButtonTag("market-" + item.getPackageName(), //$NON-NLS-1$
marketIntent));
Drawable icon = getIntentIcon(marketIntent);
if(icon == null) {
viewHolder.market.setImageResource(
android.R.drawable.stat_sys_download);
} else {
viewHolder.market.setImageDrawable(icon);
}
}
}
}
public Drawable getIntentIcon(Intent intent) {
PackageManager pm = activity.getPackageManager();
List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(intent, 0);
// if options > 1, display open with...
if(resolveInfoList.size() > 0) {
return resolveInfoList.get(0).activityInfo.loadIcon(pm);
}
return null;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 460 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 650 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 290 B

@ -1,86 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
** Copyright (c) 2012 Todoroo Inc
**
** See the file "LICENSE" for the full license governing this code.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@android:drawable/list_selector_background"
android:paddingTop="4dip"
android:paddingBottom="4dip"
android:paddingLeft="4dip"
android:paddingRight="4dip">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dip"
android:orientation="vertical">
<!-- icon -->
<ImageView android:id="@+id/icon"
android:layout_width="48dip"
android:layout_height="48dip"
android:gravity="center"
android:scaleType="fitCenter"/>
<!-- free -->
<TextView android:id="@+id/free"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="10sp"
android:textColor="#00ff00"
android:text="@string/AOA_free" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="100"
android:paddingLeft="8dip"
android:paddingRight="3dip"
android:orientation="vertical">
<!-- add-on name -->
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/icon"
android:singleLine="true"
style="@style/TextAppearance.TAd_ItemTitle"/>
<!-- description -->
<TextView android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:layout_toRightOf="@id/icon"
android:singleLine="false"
android:textSize="11sp"
style="@style/TextAppearance.TAd_ItemDetails"/>
</LinearLayout>
<!-- buttons -->
<ImageButton android:id="@+id/button_market"
android:layout_width="48dip"
android:layout_height="48dip"
android:scaleType="fitCenter"
android:layout_gravity="center" />
<ImageView android:id="@+id/check"
android:layout_width="48dip"
android:layout_height="48dip"
android:scaleType="center"
android:layout_gravity="center"
android:src="@android:drawable/checkbox_on_background"/>
</LinearLayout>

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
** Copyright (c) 2012 Todoroo Inc
**
** See the file "LICENSE" for the full license governing this code.
-->
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tab_installed"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
style="@style/Content">
<TextView android:id="@+id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="@string/AOA_no_addons"
style="@style/TextAppearance.TLA_NoItems" />
<com.todoroo.astrid.ui.ErrorCatchingListView android:id="@+id/list"
android:paddingRight="8dip"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
android:cacheColorHint="#00000000"/>
</FrameLayout>

@ -639,24 +639,9 @@
<!-- ==================================================== AddOnActivity == --> <!-- ==================================================== AddOnActivity == -->
<!-- Add Ons Activity Title -->
<string name="AOA_title">Add-ons</string>
<!-- Add-on Activity: author for internal authors --> <!-- Add-on Activity: author for internal authors -->
<string name="AOA_internal_author">Tasks Team</string> <string name="AOA_internal_author">Tasks Team</string>
<!-- Add-on Activity: installed add-ons tab -->
<string name="AOA_tab_installed">Installed</string>
<!-- Add-on Activity - available add-ons tab -->
<string name="AOA_tab_available">Available</string>
<!-- Add-on Activity - free add-ons label -->
<string name="AOA_free">Free</string>
<!-- Add-on Activity - when list is empty -->
<string name="AOA_no_addons">Empty List!</string>
<!-- ====================================================== TasksWidget == --> <!-- ====================================================== TasksWidget == -->
<!-- Widget text when loading tasks --> <!-- Widget text when loading tasks -->

Loading…
Cancel
Save