mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Added retroactive share editing, minor animation.
This commit is contained in:
parent
fb73307247
commit
1c50d35e44
6 changed files with 109 additions and 36 deletions
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<transition xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<item android:drawable="@color/item_background"/>
|
||||
<item android:drawable="@color/highlight"/>
|
||||
<item android:drawable="@color/item_background"/>
|
||||
|
||||
</transition>
|
|
@ -2,12 +2,12 @@
|
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/item_background"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/item_background"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingBottom="8dp"
|
||||
|
|
|
@ -305,7 +305,11 @@ public class FeedProvider extends ContentProvider {
|
|||
|
||||
// Querying for a stories from a feed
|
||||
case STORY_COMMENTS:
|
||||
selection = DatabaseConstants.COMMENT_STORYID + " = ?";
|
||||
if (selectionArgs.length == 1) {
|
||||
selection = DatabaseConstants.COMMENT_STORYID + " = ?";
|
||||
} else {
|
||||
selection = DatabaseConstants.COMMENT_STORYID + " = ? AND " + DatabaseConstants.COMMENT_USERID + " = ?";
|
||||
}
|
||||
return db.query(DatabaseConstants.COMMENT_TABLE, DatabaseConstants.COMMENT_COLUMNS, selection, selectionArgs, null, null, null);
|
||||
|
||||
// Querying for replies to a comment
|
||||
|
|
|
@ -7,8 +7,10 @@ import android.content.Intent;
|
|||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.TransitionDrawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.TextUtils;
|
||||
|
@ -271,22 +273,46 @@ public class ReadingItemFragment extends Fragment implements ClassifierDialogFra
|
|||
|
||||
|
||||
@Override
|
||||
public void sharedCallback(String sharedText) {
|
||||
public void sharedCallback(String sharedText, boolean hasBeenShared) {
|
||||
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
|
||||
View commentView = inflater.inflate(R.layout.include_comment, null);
|
||||
TextView commentText = (TextView) commentView.findViewById(R.id.comment_text);
|
||||
commentText.setText(sharedText);
|
||||
ImageView commentImage = (ImageView) commentView.findViewById(R.id.comment_user_image);
|
||||
commentImage.setImageBitmap(UIUtils.roundCorners(PrefsUtil.getUserImage(getActivity()), 10f));
|
||||
TextView commentSharedDate = (TextView) commentView.findViewById(R.id.comment_shareddate);
|
||||
commentSharedDate.setText(R.string.now);
|
||||
|
||||
TextView commentUsername = (TextView) commentView.findViewById(R.id.comment_username);
|
||||
commentUsername.setText(user.username);
|
||||
|
||||
((LinearLayout) view.findViewById(R.id.reading_friend_comment_container)).addView(commentView);
|
||||
if (!hasBeenShared) {
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
|
||||
View commentView = inflater.inflate(R.layout.include_comment, null);
|
||||
TextView commentText = (TextView) commentView.findViewById(R.id.comment_text);
|
||||
commentText.setTag("commentBy" + user.id);
|
||||
commentText.setText(sharedText);
|
||||
|
||||
ImageView commentImage = (ImageView) commentView.findViewById(R.id.comment_user_image);
|
||||
commentImage.setImageBitmap(UIUtils.roundCorners(PrefsUtil.getUserImage(getActivity()), 10f));
|
||||
|
||||
TextView commentSharedDate = (TextView) commentView.findViewById(R.id.comment_shareddate);
|
||||
commentSharedDate.setText(R.string.now);
|
||||
|
||||
TextView commentUsername = (TextView) commentView.findViewById(R.id.comment_username);
|
||||
commentUsername.setText(user.username);
|
||||
|
||||
((LinearLayout) view.findViewById(R.id.reading_friend_comment_container)).addView(commentView);
|
||||
} else {
|
||||
View commentViewForUser = view.findViewWithTag(SetupCommentSectionTask.COMMENT_VIEW_BY + user.id);
|
||||
commentViewForUser.setBackgroundResource(R.drawable.transition_edit_background);
|
||||
|
||||
final TransitionDrawable transition = (TransitionDrawable) commentViewForUser.getBackground();
|
||||
transition.startTransition(1000);
|
||||
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
public void run() {
|
||||
transition.reverseTransition(1000);
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
TextView commentText = (TextView) view.findViewWithTag(SetupCommentSectionTask.COMMENT_BY + user.id);
|
||||
commentText.setText(sharedText);
|
||||
|
||||
TextView commentDateText = (TextView) view.findViewWithTag(SetupCommentSectionTask.COMMENT_DATE_BY + user.id);
|
||||
commentDateText.setText(R.string.now);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package com.newsblur.fragment;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.database.Cursor;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
|
@ -16,6 +18,8 @@ import android.widget.TextView;
|
|||
import android.widget.Toast;
|
||||
|
||||
import com.newsblur.R;
|
||||
import com.newsblur.database.FeedProvider;
|
||||
import com.newsblur.domain.Comment;
|
||||
import com.newsblur.domain.Story;
|
||||
import com.newsblur.domain.UserProfile;
|
||||
import com.newsblur.network.APIManager;
|
||||
|
@ -29,6 +33,10 @@ public class ShareDialogFragment extends DialogFragment {
|
|||
private SharedCallbackDialog callback;
|
||||
private Story story;
|
||||
private UserProfile user;
|
||||
private ContentResolver resolver;
|
||||
private boolean hasBeenShared = false;
|
||||
private Cursor commentCursor;
|
||||
private Comment previousComment;
|
||||
|
||||
public static ShareDialogFragment newInstance(final SharedCallbackDialog sharedCallback, final Story story) {
|
||||
ShareDialogFragment frag = new ShareDialogFragment();
|
||||
|
@ -38,7 +46,7 @@ public class ShareDialogFragment extends DialogFragment {
|
|||
frag.setArguments(args);
|
||||
return frag;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.dialog);
|
||||
|
@ -46,46 +54,55 @@ public class ShareDialogFragment extends DialogFragment {
|
|||
story = (Story) getArguments().getSerializable(STORY);
|
||||
callback = (SharedCallbackDialog) getArguments().getSerializable(CALLBACK);
|
||||
user = PrefsUtil.getUserDetails(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
|
||||
final String shareString = getResources().getString(R.string.share_newsblur);
|
||||
boolean hasBeenShared = false;
|
||||
|
||||
|
||||
apiManager = new APIManager(getActivity());
|
||||
resolver = getActivity().getContentResolver();
|
||||
|
||||
for (String sharedUserId : story.sharedUserIds) {
|
||||
if (TextUtils.equals(user.id, sharedUserId)) {
|
||||
hasBeenShared = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
apiManager = new APIManager(getActivity());
|
||||
|
||||
if (hasBeenShared) {
|
||||
commentCursor = resolver.query(FeedProvider.COMMENTS_URI, null, null, new String[] { story.id, user.id }, null);
|
||||
commentCursor.moveToFirst();
|
||||
previousComment = Comment.fromCursor(commentCursor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
|
||||
final String shareString = getResources().getString(R.string.share_newsblur);
|
||||
|
||||
View v = inflater.inflate(R.layout.fragment_dialog, container, false);
|
||||
final TextView message = (TextView) v.findViewById(R.id.dialog_message);
|
||||
final EditText comment = (EditText) v.findViewById(R.id.dialog_share_comment);
|
||||
final EditText commentEditText = (EditText) v.findViewById(R.id.dialog_share_comment);
|
||||
message.setText(String.format(shareString, story.title));
|
||||
|
||||
|
||||
if (hasBeenShared) {
|
||||
Button shareButton = (Button) v.findViewById(R.id.dialog_button_okay);
|
||||
shareButton.setText(R.string.edit);
|
||||
commentEditText.setText(previousComment.commentText);
|
||||
}
|
||||
|
||||
|
||||
Button okayButton = (Button) v.findViewById(R.id.dialog_button_okay);
|
||||
okayButton.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
final String shareComment = comment.getText().toString();
|
||||
final String shareComment = commentEditText.getText().toString();
|
||||
v.setEnabled(false);
|
||||
|
||||
|
||||
new AsyncTask<Void, Void, Boolean>() {
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... arg) {
|
||||
return apiManager.shareStory(story.id, story.feedId, shareComment, story.sourceUserId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean result) {
|
||||
if (result) {
|
||||
callback.sharedCallback(shareComment);
|
||||
callback.sharedCallback(shareComment, hasBeenShared);
|
||||
Toast.makeText(getActivity(), R.string.shared, Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
Toast.makeText(getActivity(), R.string.error_sharing, Toast.LENGTH_LONG).show();
|
||||
|
@ -96,7 +113,7 @@ public class ShareDialogFragment extends DialogFragment {
|
|||
}.execute();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Button cancelButton = (Button) v.findViewById(R.id.dialog_button_cancel);
|
||||
cancelButton.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
|
@ -106,9 +123,17 @@ public class ShareDialogFragment extends DialogFragment {
|
|||
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
if (commentCursor != null && !commentCursor.isClosed()) {
|
||||
commentCursor.close();
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
public interface SharedCallbackDialog extends Serializable{
|
||||
public void sharedCallback(String sharedText);
|
||||
public void sharedCallback(String sharedText, boolean alreadyShared);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,6 +37,10 @@ import com.newsblur.util.PrefsUtil;
|
|||
import com.newsblur.util.UIUtils;
|
||||
|
||||
public class SetupCommentSectionTask extends AsyncTask<Void, Void, Void> {
|
||||
public static final String COMMENT_BY = "commentBy";
|
||||
public static final String COMMENT_DATE_BY = "commentDateBy";
|
||||
public static final String COMMENT_VIEW_BY = "commentViewBy";
|
||||
|
||||
private ArrayList<View> publicCommentViews;
|
||||
private ArrayList<View> friendCommentViews;
|
||||
private final ContentResolver resolver;
|
||||
|
@ -97,11 +101,17 @@ public class SetupCommentSectionTask extends AsyncTask<Void, Void, Void> {
|
|||
while (commentCursor.moveToNext()) {
|
||||
final Comment comment = Comment.fromCursor(commentCursor);
|
||||
View commentView = inflater.inflate(R.layout.include_comment, null);
|
||||
commentView.setTag(COMMENT_VIEW_BY + comment.userId);
|
||||
|
||||
TextView commentText = (TextView) commentView.findViewById(R.id.comment_text);
|
||||
commentText.setText(comment.commentText);
|
||||
commentText.setTag(COMMENT_BY + comment.userId);
|
||||
|
||||
ImageView commentImage = (ImageView) commentView.findViewById(R.id.comment_user_image);
|
||||
|
||||
TextView commentSharedDate = (TextView) commentView.findViewById(R.id.comment_shareddate);
|
||||
commentSharedDate.setText(comment.sharedDate);
|
||||
commentSharedDate.setTag(COMMENT_DATE_BY + comment.userId);
|
||||
|
||||
final LinearLayout favouriteContainer = (LinearLayout) commentView.findViewById(R.id.comment_favourite_avatars);
|
||||
final ImageView favouriteIcon = (ImageView) commentView.findViewById(R.id.comment_favourite_icon);
|
||||
|
|
Loading…
Add table
Reference in a new issue