This commit is contained in:
Mariotaku Lee 2016-03-29 20:35:54 +08:00
parent 94ba474690
commit 48e12f8983
5 changed files with 222 additions and 126 deletions

View File

@ -119,6 +119,7 @@ dependencies {
compile 'com.android.support:preference-v14:23.2.1'
compile 'com.twitter:twitter-text:1.13.0'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.4.1'
compile 'com.squareup:otto:1.3.8'
compile 'dnsjava:dnsjava:2.1.7'
compile 'com.commonsware.cwac:merge:1.1.1'
@ -144,8 +145,8 @@ dependencies {
compile 'com.lnikkila:extendedtouchview:0.1.0'
compile 'com.google.dagger:dagger:2.1'
compile 'org.attoparser:attoparser:1.4.0.RELEASE'
compile 'com.github.mariotaku.MediaViewerLibrary:base:0.9.13'
compile 'com.github.mariotaku.MediaViewerLibrary:subsample-image-view:0.9.13'
compile 'com.github.mariotaku.MediaViewerLibrary:base:0.9.14-SNAPSHOT'
compile 'com.github.mariotaku.MediaViewerLibrary:subsample-image-view:0.9.14-SNAPSHOT'
compile 'com.github.mariotaku.SQLiteQB:library:0.9.6'
compile 'com.github.mariotaku.ObjectCursor:core:0.9.6'
compile 'com.github.mariotaku:MultiValueSwitch:0.9.4'

View File

@ -27,6 +27,11 @@ public class MediaDownloadEvent extends BaseEvent implements Parcelable {
String mediaUrl;
@JsonField(name = "size")
long size;
@JsonField(name = "network_type")
int networkType;
long nonce;
@JsonField(name = "opened_time")
long openedTime;
public void setMedia(ParcelableMedia media) {
this.type = media.type;
@ -38,6 +43,22 @@ public class MediaDownloadEvent extends BaseEvent implements Parcelable {
this.size = size;
}
public void setOpenedTime(long openedTime) {
this.openedTime = openedTime;
}
public void setNetworkType(int networkType) {
this.networkType = networkType;
}
public long getNonce() {
return nonce;
}
public void setNonce(long nonce) {
this.nonce = nonce;
}
@NonNull
@Override
public String getLogFileName() {
@ -61,26 +82,32 @@ public class MediaDownloadEvent extends BaseEvent implements Parcelable {
", url='" + url + '\'' +
", mediaUrl='" + mediaUrl + '\'' +
", size=" + size +
", networkType=" + networkType +
", nonce=" + nonce +
", openedTime=" + openedTime +
"} " + super.toString();
}
public static MediaDownloadEvent create(Context context, ParcelableMedia media, long nonce) {
final MediaDownloadEvent event = new MediaDownloadEvent();
event.markStart(context);
event.setMedia(media);
event.setNonce(nonce);
event.setNetworkType(NetworkEvent.getActivateNetworkType(context));
return event;
}
public static final Creator<MediaDownloadEvent> CREATOR = new Creator<MediaDownloadEvent>() {
@Override
public MediaDownloadEvent createFromParcel(Parcel source) {
MediaDownloadEvent target = new MediaDownloadEvent();
MediaDownloadEventParcelablePlease.readFromParcel(target, source);
return target;
}
@Override
public MediaDownloadEvent[] newArray(int size) {
return new MediaDownloadEvent[size];
}
};
public static MediaDownloadEvent create(Context context, ParcelableMedia media, long total) {
final MediaDownloadEvent event = new MediaDownloadEvent();
event.markStart(context);
event.setMedia(media);
event.setSize(total);
return event;
}
}

View File

@ -45,11 +45,7 @@ public class NetworkEvent extends BaseEvent implements Parcelable {
public static NetworkEvent create(Context context) {
final NetworkEvent event = new NetworkEvent();
event.markStart(context);
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
final NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo();
if (activeNetworkInfo != null) {
event.setNetworkType(activeNetworkInfo.getType());
}
event.setNetworkType(getActivateNetworkType(context));
return event;
}
@ -74,13 +70,29 @@ public class NetworkEvent extends BaseEvent implements Parcelable {
NetworkEventParcelablePlease.writeToParcel(this, dest, flags);
}
public static int getActivateNetworkType(Context context) {
try {
final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
final NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo();
if (activeNetworkInfo != null) {
return activeNetworkInfo.getType();
}
return -1;
} catch (SecurityException e) {
return -1;
}
}
public static final Creator<NetworkEvent> CREATOR = new Creator<NetworkEvent>() {
@Override
public NetworkEvent createFromParcel(Parcel source) {
NetworkEvent target = new NetworkEvent();
NetworkEventParcelablePlease.readFromParcel(target, source);
return target;
}
@Override
public NetworkEvent[] newArray(int size) {
return new NetworkEvent[size];
}

View File

@ -957,20 +957,29 @@ public final class MediaViewerActivity extends AbsMediaViewerActivity implements
}
@Override
public void onDownloadStart(long total) {
super.onDownloadStart(total);
public void onDownloadRequested(long nonce) {
super.onDownloadRequested(nonce);
final Context context = getContext();
if (context != null) {
mMediaDownloadEvent = MediaDownloadEvent.create(context, getMedia(), total);
mMediaDownloadEvent = MediaDownloadEvent.create(context, getMedia(), nonce);
} else {
mMediaDownloadEvent = null;
}
}
@Override
public void onDownloadFinished() {
super.onDownloadFinished();
if (mMediaDownloadEvent != null) {
public void onDownloadStart(long total, long nonce) {
super.onDownloadStart(total, nonce);
if (mMediaDownloadEvent != null && mMediaDownloadEvent.getNonce() == nonce) {
mMediaDownloadEvent.setOpenedTime(System.currentTimeMillis());
mMediaDownloadEvent.setSize(nonce);
}
}
@Override
public void onDownloadFinished(long nonce) {
super.onDownloadFinished(nonce);
if (mMediaDownloadEvent != null && mMediaDownloadEvent.getNonce() == nonce) {
mMediaDownloadEvent.markEnd();
HotMobiLogger.getInstance(getContext()).log(getAccountKey(), mMediaDownloadEvent);
mMediaDownloadEvent = null;
@ -981,6 +990,7 @@ public final class MediaViewerActivity extends AbsMediaViewerActivity implements
public static class GifPageFragment extends CacheDownloadMediaViewerFragment {
private GifTextureView mGifView;
private MediaDownloadEvent mMediaDownloadEvent;
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
@ -1037,6 +1047,45 @@ public final class MediaViewerActivity extends AbsMediaViewerActivity implements
protected void recycleMedia() {
mGifView.setInputSource(null);
}
private ParcelableMedia getMedia() {
return getArguments().getParcelable(EXTRA_MEDIA);
}
private UserKey getAccountKey() {
return getArguments().getParcelable(EXTRA_ACCOUNT_KEY);
}
@Override
public void onDownloadRequested(long nonce) {
super.onDownloadRequested(nonce);
final Context context = getContext();
if (context != null) {
mMediaDownloadEvent = MediaDownloadEvent.create(context, getMedia(), nonce);
} else {
mMediaDownloadEvent = null;
}
}
@Override
public void onDownloadStart(long total, long nonce) {
super.onDownloadStart(total, nonce);
if (mMediaDownloadEvent != null && mMediaDownloadEvent.getNonce() == nonce) {
mMediaDownloadEvent.setOpenedTime(System.currentTimeMillis());
mMediaDownloadEvent.setSize(nonce);
}
}
@Override
public void onDownloadFinished(long nonce) {
super.onDownloadFinished(nonce);
if (mMediaDownloadEvent != null && mMediaDownloadEvent.getNonce() == nonce) {
mMediaDownloadEvent.markEnd();
HotMobiLogger.getInstance(getContext()).log(getAccountKey(), mMediaDownloadEvent);
mMediaDownloadEvent = null;
}
}
}
public static class VideoPageFragment extends CacheDownloadMediaViewerFragment
@ -1298,22 +1347,34 @@ public final class MediaViewerActivity extends AbsMediaViewerActivity implements
return inflater.inflate(R.layout.layout_media_viewer_texture_video_view, container, false);
}
@Override
public void onDownloadStart(long total) {
super.onDownloadStart(total);
public void onDownloadRequested(long nonce) {
super.onDownloadRequested(nonce);
final Context context = getContext();
if (context != null) {
mMediaDownloadEvent = MediaDownloadEvent.create(context, getMedia(), total);
mMediaDownloadEvent = MediaDownloadEvent.create(context, getMedia(), nonce);
} else {
mMediaDownloadEvent = null;
}
}
@Override
public void onDownloadFinished() {
super.onDownloadFinished();
if (mMediaDownloadEvent != null) {
public void onDownloadStart(long total, long nonce) {
super.onDownloadStart(total, nonce);
if (mMediaDownloadEvent != null && mMediaDownloadEvent.getNonce() == nonce) {
mMediaDownloadEvent.setOpenedTime(System.currentTimeMillis());
mMediaDownloadEvent.setSize(nonce);
}
}
@Override
public void onDownloadFinished(long nonce) {
super.onDownloadFinished(nonce);
if (mMediaDownloadEvent != null && mMediaDownloadEvent.getNonce() == nonce) {
mMediaDownloadEvent.markEnd();
HotMobiLogger.getInstance(getContext()).log(getAccountKey(), mMediaDownloadEvent);
mMediaDownloadEvent = null;
}
}

View File

@ -19,7 +19,6 @@
package org.mariotaku.twidere.fragment;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
@ -33,7 +32,6 @@ import android.support.v7.widget.PopupMenu;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -57,7 +55,6 @@ import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.EditTextEnterHandler;
import org.mariotaku.twidere.util.LinkCreator;
import org.mariotaku.twidere.util.MenuUtils;
import org.mariotaku.twidere.util.ThemeUtils;
import org.mariotaku.twidere.util.TwidereValidator;
import org.mariotaku.twidere.view.ComposeEditText;
import org.mariotaku.twidere.view.StatusTextCountView;
@ -76,34 +73,28 @@ public class RetweetQuoteDialogFragment extends BaseSupportDialogFragment implem
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
final Context context = builder.getContext();
final LayoutInflater inflater = LayoutInflater.from(context);
@SuppressLint("InflateParams") final View view = inflater.inflate(R.layout.dialog_status_quote_retweet, null);
final DummyItemAdapter adapter = new DummyItemAdapter(context);
adapter.setShouldShowAccountsColor(true);
final IStatusViewHolder holder = new StatusViewHolder(adapter, view.findViewById(R.id.item_content));
final ParcelableStatus status = getStatus();
assert status != null;
final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(getContext(),
status.account_key);
assert credentials != null;
builder.setView(view);
builder.setView(R.layout.dialog_status_quote_retweet);
builder.setTitle(R.string.retweet_quote_confirm_title);
if (isMyRetweet(status)) {
builder.setPositiveButton(R.string.cancel_retweet, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
builder.setPositiveButton(R.string.retweet, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
final Dialog dialog = (Dialog) dialogInterface;
final ComposeEditText editComment = (ComposeEditText) dialog.findViewById(R.id.edit_comment);
if (editComment.length() > 0) {
retweetOrQuote(mTwitterWrapper, credentials, status);
} else if (isMyRetweet(status)) {
mTwitterWrapper.cancelRetweetAsync(status.account_key, status.id, status.my_retweet_id);
}
});
} else if (!status.user_is_protected) {
builder.setPositiveButton(R.string.retweet, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
} else if (!status.user_is_protected) {
retweetOrQuote(mTwitterWrapper, credentials, status);
}
});
}
}
});
builder.setNeutralButton(R.string.quote, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
@ -117,91 +108,95 @@ public class RetweetQuoteDialogFragment extends BaseSupportDialogFragment implem
});
builder.setNegativeButton(android.R.string.cancel, null);
holder.displayStatus(status, false, true);
final StatusTextCountView textCountView = (StatusTextCountView) view.findViewById(R.id.comment_text_count);
textCountView.setMaxLength(TwidereValidator.getTextLimit(credentials));
view.findViewById(R.id.item_menu).setVisibility(View.GONE);
view.findViewById(R.id.action_buttons).setVisibility(View.GONE);
view.findViewById(R.id.item_content).setFocusable(false);
view.findViewById(R.id.comment_container).setVisibility(status.user_is_protected ? View.GONE : View.VISIBLE);
final ComposeEditText editComment = (ComposeEditText) view.findViewById(R.id.edit_comment);
editComment.setAccountKey(status.account_key);
final boolean sendByEnter = mPreferences.getBoolean(KEY_QUICK_SEND);
final EditTextEnterHandler enterHandler = EditTextEnterHandler.attach(editComment, new EditTextEnterHandler.EnterListener() {
@Override
public boolean shouldCallListener() {
return true;
}
@Override
public boolean onHitEnter() {
final AsyncTwitterWrapper twitter = mTwitterWrapper;
final ParcelableStatus status = getStatus();
if (twitter == null || status == null) return false;
retweetOrQuote(twitter, credentials, status);
dismiss();
return true;
}
}, sendByEnter);
enterHandler.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
updateTextCount(getDialog(), s, status, credentials);
}
@Override
public void afterTextChanged(Editable s) {
}
});
final View commentMenu = view.findViewById(R.id.comment_menu);
mPopupMenu = new PopupMenu(context, commentMenu, Gravity.NO_GRAVITY,
R.attr.actionOverflowMenuStyle, 0);
commentMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mPopupMenu.show();
}
});
commentMenu.setOnTouchListener(mPopupMenu.getDragToOpenListener());
mPopupMenu.inflate(R.menu.menu_dialog_comment);
final Menu menu = mPopupMenu.getMenu();
MenuUtils.setMenuItemAvailability(menu, R.id.quote_original_status,
status.retweet_id != null || status.quoted_id != null);
mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (item.isCheckable()) {
item.setChecked(!item.isChecked());
return true;
}
return false;
}
});
final Dialog dialog = builder.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
updateTextCount(dialog, editComment.getText(), status, credentials);
public void onShow(DialogInterface dialogInterface) {
Dialog dialog = (Dialog) dialogInterface;
final DummyItemAdapter adapter = new DummyItemAdapter(context);
adapter.setShouldShowAccountsColor(true);
final IStatusViewHolder holder = new StatusViewHolder(adapter, dialog.findViewById(R.id.item_content));
holder.displayStatus(status, false, true);
final StatusTextCountView textCountView = (StatusTextCountView) dialog.findViewById(R.id.comment_text_count);
textCountView.setMaxLength(TwidereValidator.getTextLimit(credentials));
dialog.findViewById(R.id.item_menu).setVisibility(View.GONE);
dialog.findViewById(R.id.action_buttons).setVisibility(View.GONE);
dialog.findViewById(R.id.item_content).setFocusable(false);
dialog.findViewById(R.id.comment_container).setVisibility(status.user_is_protected ? View.GONE : View.VISIBLE);
final ComposeEditText editComment = (ComposeEditText) dialog.findViewById(R.id.edit_comment);
editComment.setAccountKey(status.account_key);
final boolean sendByEnter = mPreferences.getBoolean(KEY_QUICK_SEND);
final EditTextEnterHandler enterHandler = EditTextEnterHandler.attach(editComment, new EditTextEnterHandler.EnterListener() {
@Override
public boolean shouldCallListener() {
return true;
}
@Override
public boolean onHitEnter() {
final AsyncTwitterWrapper twitter = mTwitterWrapper;
final ParcelableStatus status = getStatus();
if (twitter == null || status == null) return false;
retweetOrQuote(twitter, credentials, status);
dismiss();
return true;
}
}, sendByEnter);
enterHandler.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
updateTextCount(getDialog(), s, status);
}
@Override
public void afterTextChanged(Editable s) {
}
});
final View commentMenu = dialog.findViewById(R.id.comment_menu);
mPopupMenu = new PopupMenu(context, commentMenu, Gravity.NO_GRAVITY,
R.attr.actionOverflowMenuStyle, 0);
commentMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mPopupMenu.show();
}
});
commentMenu.setOnTouchListener(mPopupMenu.getDragToOpenListener());
mPopupMenu.inflate(R.menu.menu_dialog_comment);
final Menu menu = mPopupMenu.getMenu();
MenuUtils.setMenuItemAvailability(menu, R.id.quote_original_status,
status.retweet_id != null || status.quoted_id != null);
mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (item.isCheckable()) {
item.setChecked(!item.isChecked());
return true;
}
return false;
}
});
updateTextCount(dialog, editComment.getText(), status);
}
});
return dialog;
}
private void updateTextCount(DialogInterface dialog, CharSequence s, ParcelableStatus status,
ParcelableAccount account) {
private void updateTextCount(DialogInterface dialog, CharSequence s, ParcelableStatus status) {
if (!(dialog instanceof AlertDialog)) return;
final AlertDialog alertDialog = (AlertDialog) dialog;
final Button positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
@ -226,7 +221,7 @@ public class RetweetQuoteDialogFragment extends BaseSupportDialogFragment implem
private void retweetOrQuote(AsyncTwitterWrapper twitter, ParcelableAccount account, ParcelableStatus status) {
final Dialog dialog = getDialog();
if (dialog == null) return;
final EditText editComment = ((EditText) dialog.findViewById(R.id.edit_comment));
final EditText editComment = (EditText) dialog.findViewById(R.id.edit_comment);
if (useQuote(editComment.length() > 0, account)) {
final Menu menu = mPopupMenu.getMenu();
final MenuItem itemQuoteOriginalStatus = menu.findItem(R.id.quote_original_status);