Yixiao Li 2015-04-25 16:16:15 +09:00
commit 72324e1421
3 changed files with 89 additions and 13 deletions

View File

@ -28,6 +28,7 @@ import android.database.Cursor;
import android.graphics.Rect;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentActivity;
@ -35,6 +36,7 @@ import android.support.v4.app.LoaderManager;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.FixedLinearLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
@ -43,6 +45,7 @@ import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Property;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
@ -113,6 +116,8 @@ import java.util.Collections;
import java.util.List;
import java.util.Locale;
import me.uucky.colorpicker.internal.EffectViewHelper;
import static org.mariotaku.twidere.util.Utils.buildDirectMessageConversationUri;
import static org.mariotaku.twidere.util.Utils.showOkMessage;
@ -125,7 +130,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
private static final String EXTRA_FROM_CACHE = "from_cache";
// Callbacks
// Callbacks and listeners
private LoaderCallbacks<List<ParcelableUser>> mSearchLoadersCallback = new LoaderCallbacks<List<ParcelableUser>>() {
@Override
public Loader<List<ParcelableUser>> onCreateLoader(int id, Bundle args) {
@ -153,6 +158,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
}
};
private PanelShowHideListener mScrollListener;
// Utility classes
private TwidereValidator mValidator;
@ -162,6 +168,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
private ReadStateManager mReadStateManager;
private MediaLoaderWrapper mImageLoader;
private UserColorNameManager mUserColorNameManager;
private EffectViewHelper mEffectHelper;
// Views
private RecyclerView mMessagesListView;
@ -178,6 +185,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
private View mUsersSearchEmpty;
private TextView mUsersSearchEmptyText;
private PopupMenu mPopupMenu;
private View mInputPanelShadowCompat;
// Adapters
private MessageConversationAdapter mAdapter;
@ -192,6 +200,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
private ParcelableAccount mAccount;
private ParcelableUser mRecipient;
private boolean mTextChanged, mQueryTextChanged;
private View mInputPanel;
@Subscribe
public void notifyTaskStateChanged(TaskStateChangedEvent event) {
@ -260,6 +269,20 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
mMessagesListView.setLayoutManager(layoutManager);
mMessagesListView.setAdapter(mAdapter);
final boolean useOutline = Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP;
if (useOutline) {
final float elevation = getResources().getDimension(R.dimen.element_spacing_normal);
final PanelElevationProperty property = new PanelElevationProperty(elevation);
mEffectHelper = new EffectViewHelper(mInputPanel, property, 100);
} else {
mEffectHelper = new EffectViewHelper(mInputPanelShadowCompat, View.ALPHA, 100);
}
mScrollListener = new PanelShowHideListener(mEffectHelper);
mInputPanelShadowCompat.setVisibility(useOutline ? View.GONE : View.VISIBLE);
ViewCompat.setAlpha(mInputPanelShadowCompat, 0);
mUsersSearchAdapter = new SimpleParcelableUsersAdapter(activity);
mUsersSearchList.setAdapter(mUsersSearchAdapter);
mUsersSearchList.setEmptyView(mUsersSearchEmpty);
@ -329,6 +352,8 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
bus.register(this);
updateTextCount();
updateEmptyText();
mMessagesListView.addOnScrollListener(mScrollListener);
mScrollListener.reset();
}
@Override
@ -350,6 +375,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
@Override
public void onStop() {
mMessagesListView.removeOnScrollListener(mScrollListener);
final Bus bus = TwidereApplication.getInstance(getActivity()).getMessageBus();
bus.unregister(this);
if (mPopupMenu != null) {
@ -386,14 +412,15 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
mUsersSearchEmpty = view.findViewById(R.id.users_search_empty);
mUsersSearchEmptyText = (TextView) view.findViewById(R.id.users_search_empty_text);
mMessagesListView = (RecyclerView) view.findViewById(R.id.recycler_view);
final View inputSendContainer = view.findViewById(R.id.input_send_container);
mConversationContainer = view.findViewById(R.id.conversation_container);
mRecipientSelectorContainer = view.findViewById(R.id.recipient_selector_container);
mEditText = (StatusComposeEditText) inputSendContainer.findViewById(R.id.edit_text);
mTextCountView = (StatusTextCountView) inputSendContainer.findViewById(R.id.text_count);
mSendButton = inputSendContainer.findViewById(R.id.send);
mAddImageButton = (ImageView) inputSendContainer.findViewById(R.id.add_image);
mUsersSearchList = (ListView) view.findViewById(R.id.users_search_list);
mRecipientSelectorContainer = view.findViewById(R.id.recipient_selector_container);
mInputPanelShadowCompat = view.findViewById(R.id.input_panel_shadow_compat);
mInputPanel = view.findViewById(R.id.input_panel);
mEditText = (StatusComposeEditText) mInputPanel.findViewById(R.id.edit_text);
mTextCountView = (StatusTextCountView) mInputPanel.findViewById(R.id.text_count);
mSendButton = mInputPanel.findViewById(R.id.send);
mAddImageButton = (ImageView) mInputPanel.findViewById(R.id.add_image);
}
@Override
@ -527,6 +554,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
return false;
}
public void showConversation(final ParcelableAccount account, final ParcelableUser recipient) {
mAccount = account;
mRecipient = recipient;
@ -873,5 +901,47 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
}
}
private static class PanelShowHideListener extends RecyclerView.OnScrollListener {
private final EffectViewHelper mEffectHelper;
private boolean mShowElevation;
PanelShowHideListener(EffectViewHelper helper) {
mEffectHelper = helper;
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
final LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
final boolean showElevation = layoutManager.findLastCompletelyVisibleItemPosition() < layoutManager.getItemCount() - 1;
if (mShowElevation != showElevation) {
mEffectHelper.setState(showElevation);
}
mShowElevation = showElevation;
}
public void reset() {
mEffectHelper.resetState(mShowElevation);
}
}
private static class PanelElevationProperty extends Property<View, Float> {
private final float mElevation;
private PanelElevationProperty(float elevation) {
super(Float.TYPE, null);
mElevation = elevation;
}
@Override
public void set(View object, Float value) {
ViewCompat.setTranslationZ(object, mElevation * value);
}
@Override
public Float get(View object) {
return ViewCompat.getTranslationZ(object) / mElevation;
}
}
}

View File

@ -19,10 +19,10 @@
-->
<org.mariotaku.twidere.view.ExtendedRelativeLayout
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:padding="@dimen/element_spacing_normal">
@ -88,6 +88,7 @@
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:listSelector="?selectableItemBackground"
tools:listitem="@layout/list_item_user"/>
</LinearLayout>

View File

@ -36,7 +36,7 @@
android:id="@+id/list_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/input_send_container">
android:layout_above="@+id/input_panel">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
@ -47,20 +47,23 @@
</FrameLayout>
<View
android:id="@+id/input_panel_shadow_compat"
android:layout_width="match_parent"
android:layout_height="@dimen/element_spacing_small"
android:layout_above="@+id/input_send_container"
android:layout_above="@+id/input_panel"
android:background="@drawable/shadow_top" />
<RelativeLayout
android:id="@+id/input_send_container"
android:id="@+id/input_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="?android:colorBackground"
android:gravity="bottom"
android:orientation="horizontal"
android:padding="@dimen/element_spacing_normal">
android:outlineProvider="bounds"
android:padding="@dimen/element_spacing_normal"
tools:ignore="UnusedAttribute">
<org.mariotaku.twidere.view.ActionIconView
android:id="@+id/add_image"
@ -117,7 +120,9 @@
android:hint="@string/type_to_compose"
android:inputType="textShortMessage|textMultiLine"
android:maxHeight="140dp"
android:singleLine="false">
android:singleLine="false"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="?android:textColorPrimary">
<requestFocus />
</org.mariotaku.twidere.view.StatusComposeEditText>