Refactored tag updates into fragment with wrapper activity, styled for phones

pull/14/head
Sam Bosley 13 years ago
parent 34f0d1c778
commit bff430ef51

@ -1,187 +1,28 @@
package com.todoroo.astrid.actfm;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import android.support.v4.app.ActionBar;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import com.timsu.astrid.R;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.actfm.ActFmCameraModule.CameraResultCallback;
import com.todoroo.astrid.actfm.ActFmCameraModule.ClearImageCallback;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.actfm.sync.ActFmSyncService;
import com.todoroo.astrid.adapter.UpdateAdapter;
import com.todoroo.astrid.dao.UpdateDao;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.helper.ProgressBarSyncResultCallback;
import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.service.TagDataService;
import com.todoroo.astrid.activity.AstridActivity;
import com.todoroo.astrid.service.ThemeService;
import com.todoroo.astrid.utility.Flags;
public class TagUpdatesActivity extends ListActivity {
private TagData tagData;
private UpdateAdapter updateAdapter;
private EditText addCommentField;
private ImageButton pictureButton;
private Bitmap picture = null;
private static final int MENU_REFRESH_ID = Menu.FIRST;
@Autowired ActFmPreferenceService actFmPreferenceService;
@Autowired TagDataService tagDataService;
@Autowired UpdateDao updateDao;
@Autowired ActFmSyncService actFmSyncService;
public TagUpdatesActivity() {
DependencyInjectionService.getInstance().inject(this);
}
public class TagUpdatesActivity extends AstridActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
ThemeService.applyTheme(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.tag_updates_activity);
tagData = getIntent().getParcelableExtra(TagViewFragment.EXTRA_TAG_DATA);
OnTouchListener onTouch = new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.requestFocusFromTouch();
return false;
}
};
addCommentField = (EditText) findViewById(R.id.commentField);
addCommentField.setOnTouchListener(onTouch);
setUpUpdateList();
}
protected void setUpUpdateList() {
((TextView) findViewById(R.id.listLabel)).setText(this.getString(R.string.tag_updates_title, tagData.getValue(TagData.NAME)));
final ImageButton commentButton = (ImageButton) findViewById(R.id.commentButton);
addCommentField = (EditText) findViewById(R.id.commentField);
addCommentField.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
if(actionId == EditorInfo.IME_NULL && addCommentField.getText().length() > 0) {
addComment();
return true;
}
return false;
}
});
addCommentField.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
commentButton.setVisibility((s.length() > 0) ? View.VISIBLE : View.GONE);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
//
}
});
commentButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addComment();
}
});
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
final ClearImageCallback clearImage = new ClearImageCallback() {
@Override
public void clearImage() {
picture = null;
resetPictureButton();
}
};
pictureButton = (ImageButton) findViewById(R.id.picture);
pictureButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (picture != null)
ActFmCameraModule.showPictureLauncher(TagUpdatesActivity.this, clearImage);
else
ActFmCameraModule.showPictureLauncher(TagUpdatesActivity.this, null);
}
});
refreshUpdatesList();
refreshActivity(false); // start a pull in the background
}
private void resetPictureButton() {
TypedValue tv = new TypedValue();
getTheme().resolveAttribute(R.attr.asCameraButtonImg, tv, false);
pictureButton.setImageResource(tv.data);
}
private void refreshUpdatesList() {
if(!actFmPreferenceService.isLoggedIn() || tagData.getValue(Task.REMOTE_ID) <= 0)
return;
if(updateAdapter == null) {
TodorooCursor<Update> currentCursor = tagDataService.getUpdates(tagData);
startManagingCursor(currentCursor);
updateAdapter = new UpdateAdapter(this, R.layout.update_adapter_row,
currentCursor, false, null);
((ListView)findViewById(android.R.id.list)).setAdapter(updateAdapter);
} else {
Cursor cursor = updateAdapter.getCursor();
cursor.requery();
startManagingCursor(cursor);
}
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
if(menu.size() > 0)
return true;
MenuItem item;
if(actFmPreferenceService.isLoggedIn()) {
item = menu.add(Menu.NONE, MENU_REFRESH_ID, Menu.NONE,
R.string.ENA_refresh_comments);
item.setIcon(R.drawable.ic_menu_refresh);
}
return true;
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setCustomView(R.layout.header_title_view);
((TextView) actionBar.getCustomView().findViewById(R.id.title)).setText(R.string.TAd_contextEditTask);
}
@Override
@ -189,110 +30,4 @@ public class TagUpdatesActivity extends ListActivity {
super.finish();
AndroidUtilities.callOverridePendingTransition(this, R.anim.slide_right_in, R.anim.slide_right_out);
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
// handle my own menus
switch (item.getItemId()) {
case MENU_REFRESH_ID: {
refreshActivity(true);
return true;
}
default: return false;
}
}
private void refreshActivity(boolean manual) {
final ProgressBarSyncResultCallback callback = new ProgressBarSyncResultCallback(
this, R.id.progressBar, new Runnable() {
@Override
public void run() {
refreshUpdatesList();
}
});
callback.started();
callback.incrementMax(100);
actFmSyncService.fetchUpdatesForTag(tagData, manual, new Runnable() {
@Override
public void run() {
callback.incrementProgress(50);
callback.finished();
}
});
callback.incrementProgress(50);
}
@SuppressWarnings("nls")
private void addComment() {
if(tagData.getValue(TagData.REMOTE_ID) == 0L)
return;
Update update = new Update();
update.setValue(Update.MESSAGE, addCommentField.getText().toString());
update.setValue(Update.ACTION_CODE, "tag_comment");
update.setValue(Update.USER_ID, 0L);
update.setValue(Update.TAGS, "," + tagData.getValue(TagData.REMOTE_ID) + ",");
update.setValue(Update.CREATION_DATE, DateUtilities.now());
if (picture != null) {
update.setValue(Update.PICTURE, Update.PICTURE_LOADING);
}
Flags.set(Flags.ACTFM_SUPPRESS_SYNC);
updateDao.createNew(update);
final long updateId = update.getId();
final Bitmap tempPicture = picture;
new Thread() {
@Override
public void run() {
actFmSyncService.pushUpdate(updateId, tempPicture);
}
}.start();
addCommentField.setText(""); //$NON-NLS-1$
picture = null;
resetPictureButton();
refreshUpdatesList();
StatisticsService.reportEvent(StatisticsConstants.ACTFM_TAG_COMMENT);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
CameraResultCallback callback = new CameraResultCallback() {
@Override
public void handleCameraResult(Bitmap bitmap) {
picture = bitmap;
pictureButton.setImageBitmap(picture);
}
};
if (ActFmCameraModule.activityResult(this, requestCode, resultCode, data, callback)) {
//Handled
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
@Override
protected void onStop() {
StatisticsService.sessionStop(this);
super.onStop();
}
@Override
protected void onResume() {
super.onResume();
StatisticsService.sessionStart(this);
}
@Override
protected void onPause() {
super.onPause();
StatisticsService.sessionPause();
}
}

@ -0,0 +1,290 @@
package com.todoroo.astrid.actfm;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.app.ActionBar;
import android.support.v4.app.ListFragment;
import android.support.v4.view.Menu;
import android.support.v4.view.MenuItem;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import com.timsu.astrid.R;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.actfm.ActFmCameraModule.CameraResultCallback;
import com.todoroo.astrid.actfm.ActFmCameraModule.ClearImageCallback;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.actfm.sync.ActFmSyncService;
import com.todoroo.astrid.activity.AstridActivity;
import com.todoroo.astrid.adapter.UpdateAdapter;
import com.todoroo.astrid.dao.UpdateDao;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.helper.ProgressBarSyncResultCallback;
import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.service.TagDataService;
import com.todoroo.astrid.utility.Flags;
public class TagUpdatesFragment extends ListFragment {
private TagData tagData;
private UpdateAdapter updateAdapter;
private EditText addCommentField;
private ImageButton pictureButton;
private Bitmap picture = null;
private static final int MENU_REFRESH_ID = Menu.FIRST;
@Autowired ActFmPreferenceService actFmPreferenceService;
@Autowired TagDataService tagDataService;
@Autowired UpdateDao updateDao;
@Autowired ActFmSyncService actFmSyncService;
public TagUpdatesFragment() {
DependencyInjectionService.getInstance().inject(this);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View v = inflater.inflate(R.layout.tag_updates_fragment, container, false);
return v;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setHasOptionsMenu(true);
tagData = getActivity().getIntent().getParcelableExtra(TagViewFragment.EXTRA_TAG_DATA);
OnTouchListener onTouch = new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.requestFocusFromTouch();
return false;
}
};
addCommentField = (EditText) getView().findViewById(R.id.commentField);
addCommentField.setOnTouchListener(onTouch);
setUpUpdateList();
}
protected void setUpUpdateList() {
ActionBar ab = ((AstridActivity) getActivity()).getSupportActionBar();
((TextView) ab.getCustomView().findViewById(R.id.title)).setText(this.getString(R.string.tag_updates_title, tagData.getValue(TagData.NAME)));
final ImageButton commentButton = (ImageButton) getView().findViewById(R.id.commentButton);
addCommentField = (EditText) getView().findViewById(R.id.commentField);
addCommentField.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
if(actionId == EditorInfo.IME_NULL && addCommentField.getText().length() > 0) {
addComment();
return true;
}
return false;
}
});
addCommentField.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
commentButton.setVisibility((s.length() > 0) ? View.VISIBLE : View.GONE);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
//
}
});
commentButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addComment();
}
});
final ClearImageCallback clearImage = new ClearImageCallback() {
@Override
public void clearImage() {
picture = null;
resetPictureButton();
}
};
pictureButton = (ImageButton) getView().findViewById(R.id.picture);
pictureButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (picture != null)
ActFmCameraModule.showPictureLauncher(TagUpdatesFragment.this, clearImage);
else
ActFmCameraModule.showPictureLauncher(TagUpdatesFragment.this, null);
}
});
refreshUpdatesList();
refreshActivity(false); // start a pull in the background
}
private void resetPictureButton() {
TypedValue tv = new TypedValue();
getActivity().getTheme().resolveAttribute(R.attr.asCameraButtonImg, tv, false);
pictureButton.setImageResource(tv.data);
}
private void refreshUpdatesList() {
if(!actFmPreferenceService.isLoggedIn() || tagData.getValue(Task.REMOTE_ID) <= 0)
return;
if(updateAdapter == null) {
TodorooCursor<Update> currentCursor = tagDataService.getUpdates(tagData);
getActivity().startManagingCursor(currentCursor);
updateAdapter = new UpdateAdapter(this, R.layout.update_adapter_row,
currentCursor, false, null);
((ListView) getView().findViewById(android.R.id.list)).setAdapter(updateAdapter);
} else {
Cursor cursor = updateAdapter.getCursor();
cursor.requery();
getActivity().startManagingCursor(cursor);
}
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
if(menu.size() > 0)
return;
MenuItem item;
if(actFmPreferenceService.isLoggedIn()) {
item = menu.add(Menu.NONE, MENU_REFRESH_ID, Menu.NONE,
R.string.ENA_refresh_comments);
item.setIcon(R.drawable.ic_menu_refresh);
}
}
// @Override
// public void finish() {
// super.finish();
// AndroidUtilities.callOverridePendingTransition(this, R.anim.slide_right_in, R.anim.slide_right_out);
// }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// handle my own menus
switch (item.getItemId()) {
case MENU_REFRESH_ID: {
refreshActivity(true);
return true;
}
default: return false;
}
}
private void refreshActivity(boolean manual) {
final ProgressBarSyncResultCallback callback = new ProgressBarSyncResultCallback(
getActivity(), R.id.progressBar, new Runnable() {
@Override
public void run() {
refreshUpdatesList();
}
});
callback.started();
callback.incrementMax(100);
actFmSyncService.fetchUpdatesForTag(tagData, manual, new Runnable() {
@Override
public void run() {
callback.incrementProgress(50);
callback.finished();
}
});
callback.incrementProgress(50);
}
@SuppressWarnings("nls")
private void addComment() {
if(tagData.getValue(TagData.REMOTE_ID) == 0L)
return;
Update update = new Update();
update.setValue(Update.MESSAGE, addCommentField.getText().toString());
update.setValue(Update.ACTION_CODE, "tag_comment");
update.setValue(Update.USER_ID, 0L);
update.setValue(Update.TAGS, "," + tagData.getValue(TagData.REMOTE_ID) + ",");
update.setValue(Update.CREATION_DATE, DateUtilities.now());
if (picture != null) {
update.setValue(Update.PICTURE, Update.PICTURE_LOADING);
}
Flags.set(Flags.ACTFM_SUPPRESS_SYNC);
updateDao.createNew(update);
final long updateId = update.getId();
final Bitmap tempPicture = picture;
new Thread() {
@Override
public void run() {
actFmSyncService.pushUpdate(updateId, tempPicture);
}
}.start();
addCommentField.setText(""); //$NON-NLS-1$
picture = null;
resetPictureButton();
refreshUpdatesList();
StatisticsService.reportEvent(StatisticsConstants.ACTFM_TAG_COMMENT);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
CameraResultCallback callback = new CameraResultCallback() {
@Override
public void handleCameraResult(Bitmap bitmap) {
picture = bitmap;
pictureButton.setImageBitmap(picture);
}
};
if (ActFmCameraModule.activityResult(getActivity(), requestCode, resultCode, data, callback)) {
//Handled
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
}

@ -1,100 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/Content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
style="@style/Header"
android:layout_width="fill_parent"
android:layout_height="43dip"
android:layout_weight="1"
android:orientation="horizontal" >
<!-- List Label -->
<TextView
android:id="@+id/listLabel"
style="@style/TextAppearance.TLA_Header"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="100"
android:ellipsize="start"
android:gravity="center"
android:singleLine="true" />
</LinearLayout>
<ProgressBar
android:id="@+id/progressBar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="5dip"
android:layout_weight="1"
android:visibility="gone" />
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="100" />
<!-- Footer -->
<LinearLayout
android:id="@+id/updatesFooter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/footer_background"
android:minHeight="47dip"
android:orientation="horizontal"
android:padding="3dip" >
<!-- Voice Add Button -->
<ImageButton
android:id="@+id/picture"
android:layout_width="39dip"
android:layout_height="39dip"
android:layout_gravity="top"
android:layout_marginRight="3dip"
android:layout_weight="1"
android:background="#00000000"
android:paddingBottom="2dip"
android:paddingLeft="7dip"
android:paddingRight="7dip"
android:scaleType="centerInside"
android:src="?attr/asCameraButtonImg" />
<!-- Quick Add Task -->
<EditText
android:id="@+id/commentField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="1dip"
android:layout_marginLeft="1dip"
android:paddingLeft="10dip"
android:layout_weight="100"
android:autoText="true"
android:background="@drawable/footer_comment_edittext"
android:capitalize="sentences"
android:hint="@string/TVA_add_comment"
android:textSize="16sp" />
<!-- Extended Add Button -->
<ImageButton
android:id="@+id/commentButton"
android:layout_width="wrap_content"
android:layout_height="39dip"
android:layout_gravity="top"
android:layout_marginRight="3dip"
android:layout_weight="1"
android:background="@drawable/footer_button"
android:scaleType="center"
android:src="@drawable/ic_footer_add" />
</LinearLayout>
</LinearLayout>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tag_updates_fragment_container">
<fragment
android:name="com.todoroo.astrid.actfm.TagUpdatesFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="tagupdates_fragment">
</fragment>
</FrameLayout>

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/Content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ProgressBar
android:id="@+id/progressBar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="5dip"
android:layout_weight="1"
android:visibility="gone" />
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="100" />
<!-- Footer -->
<LinearLayout
android:id="@+id/updatesFooter"
style="@style/Content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:minHeight="50dip"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="3dip"
android:paddingBottom="5dip">
<!-- Voice Add Button -->
<ImageButton
android:id="@+id/picture"
android:layout_width="39dip"
android:layout_height="39dip"
android:layout_gravity="top"
android:layout_marginRight="3dip"
android:layout_weight="1"
android:background="#00000000"
android:paddingBottom="2dip"
android:paddingLeft="7dip"
android:paddingRight="7dip"
android:scaleType="centerInside"
android:src="?attr/asCameraButtonImg" />
<!-- Quick Add Task -->
<EditText
android:id="@+id/commentField"
android:layout_width="wrap_content"
android:layout_height="39dip"
android:layout_marginLeft="1dip"
android:layout_marginRight="1dip"
android:layout_marginBottom="2dip"
android:layout_weight="100"
android:autoText="true"
android:background="@drawable/footer_comment_edittext"
android:capitalize="sentences"
android:hint="@string/TVA_add_comment"
android:paddingLeft="10dip"
android:textSize="16sp" />
<!-- Extended Add Button -->
<ImageButton
android:id="@+id/commentButton"
android:layout_width="39dip"
android:layout_height="39dip"
android:layout_gravity="top"
android:layout_marginLeft="3dip"
android:layout_weight="1"
android:background="?attr/asAddButtonImg"
android:scaleType="center"/>
</LinearLayout>
</LinearLayout>

@ -1021,7 +1021,8 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
// update title
filter.title = getString(R.string.TLA_custom);
((TextView) getView().findViewById(R.id.listLabel)).setText(filter.title);
if (getActivity() instanceof TaskListActivity)
((TaskListActivity) getActivity()).setListsTitle(filter.title);
// try selecting again
for (int i = 0; i < currentCursor.getCount(); i++) {

@ -5,11 +5,11 @@ import greendroid.widget.AsyncImageView;
import org.json.JSONObject;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.database.Cursor;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.view.LayoutInflater;
@ -38,7 +38,7 @@ public class UpdateAdapter extends CursorAdapter {
// --- instance variables
protected final ListActivity activity;
protected final Fragment fragment;
private final int resource;
private final LayoutInflater inflater;
@ -55,17 +55,17 @@ public class UpdateAdapter extends CursorAdapter {
* @param onCompletedTaskListener
* goal listener. can be null
*/
public UpdateAdapter(ListActivity activity, int resource,
public UpdateAdapter(Fragment fragment, int resource,
Cursor c, boolean autoRequery,
OnCompletedTaskListener onCompletedTaskListener) {
super(activity, c, autoRequery);
super(fragment.getActivity(), c, autoRequery);
DependencyInjectionService.getInstance().inject(this);
inflater = (LayoutInflater) activity.getSystemService(
inflater = (LayoutInflater) fragment.getActivity().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
this.resource = resource;
this.activity = activity;
this.fragment = fragment;
}
/* ======================================================================
@ -100,7 +100,7 @@ public class UpdateAdapter extends CursorAdapter {
@SuppressWarnings("nls")
public synchronized void setFieldContentsAndVisibility(View view, Update update) {
JSONObject user = ActFmPreferenceService.userFromModel(update);
Resources r = activity.getResources();
Resources r = fragment.getResources();
// picture
final AsyncImageView pictureView = (AsyncImageView)view.findViewById(R.id.picture); {
@ -118,15 +118,15 @@ public class UpdateAdapter extends CursorAdapter {
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog image = new AlertDialog.Builder(activity).create();
AsyncImageView imageView = new AsyncImageView(activity);
AlertDialog image = new AlertDialog.Builder(fragment.getActivity()).create();
AsyncImageView imageView = new AsyncImageView(fragment.getActivity());
imageView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
imageView.setDefaultImageResource(android.R.drawable.ic_menu_gallery);
imageView.setUrl(updatePicture);
image.setView(imageView);
image.setMessage(message);
image.setButton(activity.getString(R.string.DLG_close), new DialogInterface.OnClickListener() {
image.setButton(fragment.getString(R.string.DLG_close), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
return;

Loading…
Cancel
Save