mirror of https://github.com/tasks/tasks
Refactored tag updates into fragment with wrapper activity, styled for phones
parent
34f0d1c778
commit
bff430ef51
@ -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>
|
Loading…
Reference in New Issue