Fixed #287, finally!

This commit is contained in:
Mariotaku Lee 2016-01-21 22:39:13 +08:00
parent d634ecb276
commit b106b5c012
16 changed files with 131 additions and 91 deletions

View File

@ -20,10 +20,14 @@
package org.mariotaku.twidere.api.twitter;
import org.mariotaku.restfu.annotation.method.POST;
import org.mariotaku.restfu.annotation.param.KeyValue;
import org.mariotaku.restfu.annotation.param.Param;
import org.mariotaku.restfu.annotation.param.Params;
import org.mariotaku.restfu.http.BodyType;
import org.mariotaku.restfu.http.mime.Body;
import org.mariotaku.restfu.http.mime.FileBody;
import org.mariotaku.twidere.api.twitter.model.MediaUploadResponse;
import org.mariotaku.twidere.api.twitter.model.ResponseCode;
import java.io.File;
@ -38,4 +42,19 @@ public interface TwitterUpload {
@BodyType(BodyType.MULTIPART)
MediaUploadResponse uploadMedia(@Param("media") FileBody data) throws TwitterException;
@POST("/media/upload.json")
@Params(@KeyValue(key = "command", value = "INIT"))
MediaUploadResponse initUploadMedia(@Param("media_type") String mediaType,
@Param("total_bytes") long totalBytes) throws TwitterException;
@POST("/media/upload.json")
@Params(@KeyValue(key = "command", value = "APPEND"))
ResponseCode initUploadMedia(@Param("media_id") long mediaId,
@Param("segment_index") int segmentIndex,
@Param("media") Body media) throws TwitterException;
@POST("/media/upload.json")
@Params(@KeyValue(key = "command", value = "FINALIZE"))
MediaUploadResponse initUploadMedia(@Param("media_id") long mediaId) throws TwitterException;
}

View File

@ -59,8 +59,6 @@ public abstract class AbsContentRecyclerViewFragment<A extends LoadMoreSupportAd
private SwipeRefreshLayout mSwipeRefreshLayout;
private RecyclerView mRecyclerView;
private View mErrorContainer;
private ImageView mErrorIconView;
private TextView mErrorTextView;
private L mLayoutManager;
private A mAdapter;
@ -272,8 +270,6 @@ public abstract class AbsContentRecyclerViewFragment<A extends LoadMoreSupportAd
mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_layout);
mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
mErrorContainer = view.findViewById(R.id.error_container);
mErrorIconView = (ImageView) view.findViewById(R.id.error_icon);
mErrorTextView = (TextView) view.findViewById(R.id.error_text);
}
@Override
@ -333,16 +329,20 @@ public abstract class AbsContentRecyclerViewFragment<A extends LoadMoreSupportAd
mErrorContainer.setVisibility(View.VISIBLE);
mProgressContainer.setVisibility(View.GONE);
mSwipeRefreshLayout.setVisibility(View.GONE);
mErrorIconView.setImageResource(icon);
mErrorTextView.setText(text);
final ImageView errorIconView = (ImageView) mErrorContainer.findViewById(R.id.error_icon);
final TextView errorTextView = (TextView) mErrorContainer.findViewById(R.id.error_text);
errorIconView.setImageResource(icon);
errorTextView.setText(text);
}
protected final void showEmpty(int icon, CharSequence text) {
mErrorContainer.setVisibility(View.VISIBLE);
mProgressContainer.setVisibility(View.GONE);
mSwipeRefreshLayout.setVisibility(View.VISIBLE);
mErrorIconView.setImageResource(icon);
mErrorTextView.setText(text);
final ImageView errorIconView = (ImageView) mErrorContainer.findViewById(R.id.error_icon);
final TextView errorTextView = (TextView) mErrorContainer.findViewById(R.id.error_text);
errorIconView.setImageResource(icon);
errorTextView.setText(text);
}
protected void updateRefreshProgressOffset() {

View File

@ -93,6 +93,8 @@ import org.mariotaku.twidere.util.io.ContentLengthInputStream.ReadListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -534,31 +536,29 @@ public class BackgroundOperationService extends IntentService implements Constan
status.location(ParcelableLocation.toGeoLocation(statusUpdate.location));
}
if (!mUseUploader && hasMedia) {
final BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
final long[] mediaIds = new long[statusUpdate.media.length];
ContentLengthInputStream is = null;
ContentLengthInputStream cis = null;
try {
for (int i = 0, j = mediaIds.length; i < j; i++) {
final ParcelableMediaUpdate media = statusUpdate.media[i];
final String path = getImagePathFromUri(this, Uri.parse(media.uri));
if (path == null) throw new FileNotFoundException();
BitmapFactory.decodeFile(path, o);
final File file = new File(path);
is = new ContentLengthInputStream(file);
is.setReadListener(new StatusMediaUploadListener(this, mNotificationManager, builder,
final Uri mediaUri = Uri.parse(media.uri);
final String mediaType = mResolver.getType(mediaUri);
final InputStream is = mResolver.openInputStream(mediaUri);
final long length = is.available();
cis = new ContentLengthInputStream(is, length);
cis.setReadListener(new StatusMediaUploadListener(this, mNotificationManager, builder,
statusUpdate));
final ContentType contentType;
if (TextUtils.isEmpty(o.outMimeType)) {
contentType = ContentType.parse("image/*");
if (TextUtils.isEmpty(mediaType)) {
contentType = ContentType.parse("application/octet-stream");
} else {
contentType = ContentType.parse(o.outMimeType);
contentType = ContentType.parse(mediaType);
}
final MediaUploadResponse uploadResp = upload.uploadMedia(
new FileBody(is, file.getName(), file.length(), contentType));
final FileBody body = new FileBody(cis, "attachment", length, contentType);
final MediaUploadResponse uploadResp = upload.uploadMedia(body);
mediaIds[i] = uploadResp.getId();
}
} catch (final FileNotFoundException e) {
} catch (final IOException e) {
Log.w(LOGTAG, e);
} catch (final TwitterException e) {
Log.w(LOGTAG, e);
@ -566,7 +566,7 @@ public class BackgroundOperationService extends IntentService implements Constan
results.add(response);
continue;
} finally {
IoUtils.closeSilently(is);
IoUtils.closeSilently(cis);
}
status.mediaIds(mediaIds);
}

View File

@ -21,6 +21,7 @@ package org.mariotaku.twidere.util;
import android.annotation.SuppressLint;
import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v4.view.MotionEventCompat;
import android.view.InputDevice;
import android.view.MotionEvent;
@ -35,15 +36,14 @@ import android.widget.ScrollView;
public class MouseScrollDirectionDecider {
private final float factor;
private final View verticalView, horizontalView;
@Nullable
private View verticalView, horizontalView;
private int horizontalDirection = 0, verticalDirection = 0;
private float horizontalScroll, verticalScroll;
public MouseScrollDirectionDecider(Context context, float factor) {
public MouseScrollDirectionDecider(float factor) {
this.factor = factor;
this.verticalView = new InternalScrollView(context, this);
this.horizontalView = new InternalHorizontalScrollView(context, this);
}
public float getHorizontalDirection() {
@ -71,6 +71,7 @@ public class MouseScrollDirectionDecider {
}
public boolean guessDirection(MotionEvent event) {
if (verticalView == null || horizontalView == null) return false;
if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
return false;
}
@ -82,6 +83,17 @@ public class MouseScrollDirectionDecider {
return verticalScroll != 0 || horizontalScroll != 0;
}
public void attach(View view) {
final Context context = view.getContext();
verticalView = new InternalScrollView(context, this);
horizontalView = new InternalHorizontalScrollView(context, this);
}
public void detach() {
verticalView = null;
horizontalView = null;
}
@SuppressLint("ViewConstructor")
private static class InternalScrollView extends ScrollView {

View File

@ -39,6 +39,10 @@ public class ContentLengthInputStream extends InputStream {
this(new FileInputStream(file), file.length());
}
public ContentLengthInputStream(final InputStream stream) throws IOException {
this(stream, stream.available());
}
public ContentLengthInputStream(final InputStream stream, final long length) {
this.stream = stream;
this.length = length;

View File

@ -48,7 +48,19 @@ public class ExtendedRecyclerView extends RecyclerView {
public ExtendedRecyclerView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mMouseScrollDirectionDecider = new MouseScrollDirectionDecider(context, getScrollFactorBackport());
mMouseScrollDirectionDecider = new MouseScrollDirectionDecider(getScrollFactorBackport());
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
mMouseScrollDirectionDecider.attach(this);
}
@Override
protected void onDetachedFromWindow() {
mMouseScrollDirectionDecider.detach();
super.onDetachedFromWindow();
}
@Override

View File

@ -18,16 +18,15 @@
-->
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
tools:menu="menu_media_viewer_image_page">
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:menu="menu_media_viewer_image_page">
<org.mariotaku.twidere.view.MediaViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"/>
<LinearLayout
android:id="@+id/media_status_container"
@ -40,13 +39,13 @@
<View
android:layout_width="match_parent"
android:layout_height="@dimen/element_spacing_small"
android:background="@drawable/shadow_top" />
android:background="@drawable/shadow_top"/>
<FrameLayout
android:id="@+id/media_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#80000000" />
android:background="#80000000"/>
</LinearLayout>
</merge>

View File

@ -17,18 +17,17 @@
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
android:layout_height="match_parent">
<include layout="@layout/layout_content_fragment_common" />
<include layout="@layout/layout_content_fragment_common"/>
<org.mariotaku.twidere.view.themed.AccentSwipeRefreshLayout
android:id="@+id/swipe_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:clipToPadding="false">
<ListView
@ -37,7 +36,7 @@
android:layout_height="match_parent"
android:clipToPadding="false"
android:focusable="true"
android:listSelector="?selectableItemBackground" />
android:listSelector="?selectableItemBackground"/>
</org.mariotaku.twidere.view.themed.AccentSwipeRefreshLayout>
</FrameLayout>

View File

@ -20,8 +20,7 @@
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
android:layout_height="match_parent">
<include layout="@layout/layout_content_fragment_common"/>

View File

@ -17,24 +17,24 @@
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
android:layout_height="match_parent">
<FrameLayout
android:visibility="gone"
tools:visibility="visible"
android:id="@+id/list_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:visibility="gone"
tools:visibility="visible">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:visibility="gone" />
tools:visibility="gone"/>
<LinearLayout
android:id="@android:id/empty"
@ -48,7 +48,7 @@
android:id="@+id/empty_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:color="?android:textColorSecondary" />
android:color="?android:textColorSecondary"/>
<TextView
android:id="@+id/empty_text"
@ -57,17 +57,17 @@
android:layout_gravity="center"
android:layout_marginTop="@dimen/element_spacing_normal"
android:gravity="center"
android:textAppearance="?android:textAppearanceMedium" />
android:textAppearance="?android:textAppearanceMedium"/>
</LinearLayout>
</FrameLayout>
<FrameLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/progress_container"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
tools:visibility="gone"
android:layout_height="match_parent">
tools:visibility="gone">
<org.mariotaku.twidere.view.themed.AccentProgressWheel
android:id="@+id/load_progress"

View File

@ -20,8 +20,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
android:layout_height="match_parent">
<pl.droidsonroids.gif.GifTextureView
android:id="@+id/gif_image_view"

View File

@ -18,16 +18,16 @@
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<FrameLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
android:layout_height="match_parent">
<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"/>
<org.mariotaku.twidere.view.themed.AccentProgressWheel
android:id="@+id/load_progress"

View File

@ -23,8 +23,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
@ -41,8 +40,7 @@
android:id="@+id/video_view_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:animateLayoutChanges="true">
android:layout_alignParentBottom="true">
<RelativeLayout
android:id="@+id/video_control"

View File

@ -17,13 +17,13 @@
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout
android:id="@+id/main_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical">
<ScrollView
@ -59,7 +59,7 @@
android:layout_height="@dimen/element_size_mlarge"
android:layout_gravity="center"
android:foreground="?selectableItemBackground"
android:scaleType="centerCrop" />
android:scaleType="centerCrop"/>
<TextView
android:layout_width="wrap_content"
@ -70,7 +70,7 @@
android:textAllCaps="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:textColorPrimary"
android:textStyle="bold" />
android:textStyle="bold"/>
</LinearLayout>
@ -89,7 +89,7 @@
android:layout_height="@dimen/element_size_mlarge"
android:layout_gravity="center"
android:foreground="?selectableItemBackground"
android:scaleType="centerCrop" />
android:scaleType="centerCrop"/>
<TextView
android:layout_width="wrap_content"
@ -100,14 +100,14 @@
android:textAllCaps="true"
android:textAppearance="?android:textAppearanceSmall"
android:textColor="?android:textColorPrimary"
android:textStyle="bold" />
android:textStyle="bold"/>
</LinearLayout>
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="@dimen/element_spacing_normal" />
android:layout_height="@dimen/element_spacing_normal"/>
<LinearLayout
android:layout_width="match_parent"
@ -125,7 +125,7 @@
app:met_baseColor="?android:textColorPrimary"
app:met_floatingLabel="normal"
app:met_floatingLabelText="@string/name"
app:met_maxCharacters="20" />
app:met_maxCharacters="20"/>
<org.mariotaku.twidere.view.themed.BackgroundTintMaterialEditText
android:id="@+id/description"
@ -137,7 +137,7 @@
app:met_baseColor="?android:textColorPrimary"
app:met_floatingLabel="normal"
app:met_floatingLabelText="@string/description"
app:met_maxCharacters="160" />
app:met_maxCharacters="160"/>
<org.mariotaku.twidere.view.themed.BackgroundTintMaterialEditText
android:id="@+id/location"
@ -148,7 +148,7 @@
app:met_baseColor="?android:textColorPrimary"
app:met_floatingLabel="normal"
app:met_floatingLabelText="@string/location"
app:met_maxCharacters="30" />
app:met_maxCharacters="30"/>
<org.mariotaku.twidere.view.themed.BackgroundTintMaterialEditText
android:id="@+id/url"
@ -159,12 +159,12 @@
app:met_baseColor="?android:textColorPrimary"
app:met_floatingLabel="normal"
app:met_floatingLabelText="@string/url"
app:met_maxCharacters="100" />
app:met_maxCharacters="100"/>
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="@dimen/element_spacing_normal" />
android:layout_height="@dimen/element_spacing_normal"/>
<LinearLayout
android:layout_width="match_parent"
@ -185,7 +185,7 @@
android:id="@+id/link_color"
android:layout_width="@dimen/element_size_normal"
android:layout_height="@dimen/element_size_normal"
android:layout_weight="0" />
android:layout_weight="0"/>
<TextView
android:layout_width="match_parent"
@ -197,7 +197,7 @@
android:textAllCaps="true"
android:textAppearance="?android:textAppearanceSmall"
android:textColor="?android:textColorPrimary"
android:textStyle="bold" />
android:textStyle="bold"/>
</LinearLayout>
@ -214,7 +214,7 @@
android:id="@+id/background_color"
android:layout_width="@dimen/element_size_normal"
android:layout_height="@dimen/element_size_normal"
android:layout_weight="0" />
android:layout_weight="0"/>
<TextView
android:layout_width="match_parent"
@ -226,7 +226,7 @@
android:textAllCaps="true"
android:textAppearance="?android:textAppearanceSmall"
android:textColor="?android:textColorPrimary"
android:textStyle="bold" />
android:textStyle="bold"/>
</LinearLayout>

View File

@ -18,10 +18,10 @@
-->
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<FrameLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/progress_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -52,7 +52,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:color="?android:textColorSecondary"
android:src="@drawable/ic_info_error_generic" />
android:src="@drawable/ic_info_error_generic"/>
<TextView
android:id="@+id/error_text"
@ -60,7 +60,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/element_spacing_normal"
android:textAppearance="?android:textAppearanceMedium" />
android:textAppearance="?android:textAppearanceMedium"/>
</LinearLayout>
</merge>

View File

@ -22,8 +22,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/list_container"