improving dm ui

This commit is contained in:
Mariotaku Lee 2015-04-25 02:13:50 +08:00
parent 9c24a984dc
commit 8dbacf5528
9 changed files with 207 additions and 129 deletions

View File

@ -28,7 +28,6 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView.ScaleType;
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.R;
@ -40,24 +39,30 @@ import org.mariotaku.twidere.util.DirectMessageOnLinkClickHandler;
import org.mariotaku.twidere.util.MediaLoaderWrapper;
import org.mariotaku.twidere.util.MediaLoadingHandler;
import org.mariotaku.twidere.util.MultiSelectManager;
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
import org.mariotaku.twidere.util.ThemeUtils;
import org.mariotaku.twidere.util.TwidereLinkify;
import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.view.holder.MessageConversationViewHolder;
import org.mariotaku.twidere.view.ShapedImageView;
import org.mariotaku.twidere.view.holder.IncomingMessageViewHolder;
import org.mariotaku.twidere.view.holder.MessageViewHolder;
public class MessageConversationAdapter extends Adapter<ViewHolder>
implements Constants, IDirectMessagesAdapter, OnClickListener {
public class MessageConversationAdapter extends Adapter<ViewHolder> implements Constants,
IDirectMessagesAdapter, OnClickListener {
private static final int ITEM_VIEW_TYPE_MESSAGE_OUTGOING = 1;
private static final int ITEM_VIEW_TYPE_MESSAGE_INCOMING = 2;
private final int mOutgoingMessageColor;
private final int mIncomingMessageColor;
private final boolean mDisplayProfileImage;
private ScaleType mImagePreviewScaleType;
@ShapedImageView.ShapeStyle
private final int mProfileImageStyle;
private final int mMediaPreviewStyle;
private final Context mContext;
private final LayoutInflater mInflater;
private final MediaLoaderWrapper mImageLoader;
private final MediaLoaderWrapper mMediaLoader;
private final MultiSelectManager mMultiSelectManager;
private final MediaLoadingHandler mMediaLoadingHandler;
@ -71,7 +76,12 @@ public class MessageConversationAdapter extends Adapter<ViewHolder>
final TwidereApplication app = TwidereApplication.getInstance(context);
mLinkify = new TwidereLinkify(new DirectMessageOnLinkClickHandler(context, null));
mMultiSelectManager = app.getMultiSelectManager();
mImageLoader = app.getMediaLoaderWrapper();
mMediaLoader = app.getMediaLoaderWrapper();
final SharedPreferencesWrapper preferences = SharedPreferencesWrapper.getInstance(context,
SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
mDisplayProfileImage = preferences.getBoolean(KEY_DISPLAY_PROFILE_IMAGE, true);
mProfileImageStyle = Utils.getProfileImageStyle(preferences.getString(KEY_PROFILE_IMAGE_STYLE, null));
mMediaPreviewStyle = Utils.getMediaPreviewStyle(preferences.getString(KEY_MEDIA_PREVIEW_STYLE, null));
mMediaLoadingHandler = new MediaLoadingHandler(R.id.media_preview_progress);
mIncomingMessageColor = ThemeUtils.getUserAccentColor(context);
mOutgoingMessageColor = ThemeUtils.getCardBackgroundColor(context, ThemeUtils.getThemeBackgroundOption(context), ThemeUtils.getUserThemeBackgroundAlpha(context));
@ -82,8 +92,9 @@ public class MessageConversationAdapter extends Adapter<ViewHolder>
return mContext;
}
public MediaLoaderWrapper getImageLoader() {
return mImageLoader;
@Override
public MediaLoaderWrapper getMediaLoader() {
return mMediaLoader;
}
public TwidereLinkify getLinkify() {
@ -95,13 +106,13 @@ public class MessageConversationAdapter extends Adapter<ViewHolder>
switch (viewType) {
case ITEM_VIEW_TYPE_MESSAGE_INCOMING: {
final View view = mInflater.inflate(R.layout.card_item_message_conversation_incoming, parent, false);
final MessageConversationViewHolder holder = new MessageConversationViewHolder(this, view);
final MessageViewHolder holder = new IncomingMessageViewHolder(this, view);
holder.setMessageColor(mIncomingMessageColor);
return holder;
}
case ITEM_VIEW_TYPE_MESSAGE_OUTGOING: {
final View view = mInflater.inflate(R.layout.card_item_message_conversation_outgoing, parent, false);
final MessageConversationViewHolder holder = new MessageConversationViewHolder(this, view);
final MessageViewHolder holder = new MessageViewHolder(this, view);
holder.setMessageColor(mOutgoingMessageColor);
return holder;
}
@ -116,7 +127,7 @@ public class MessageConversationAdapter extends Adapter<ViewHolder>
case ITEM_VIEW_TYPE_MESSAGE_OUTGOING: {
final Cursor c = mCursor;
c.moveToPosition(getCursorPosition(position));
((MessageConversationViewHolder) holder).displayMessage(c, mIndices);
((MessageViewHolder) holder).displayMessage(c, mIndices);
}
}
}
@ -151,6 +162,16 @@ public class MessageConversationAdapter extends Adapter<ViewHolder>
return null;
}
@Override
public final int getProfileImageStyle() {
return mProfileImageStyle;
}
@Override
public boolean isProfileImageEnabled() {
return mDisplayProfileImage;
}
public ParcelableDirectMessage getDirectMessage(final int position) {
final Cursor c = mCursor;
if (c == null || c.isClosed()) return null;
@ -178,27 +199,8 @@ public class MessageConversationAdapter extends Adapter<ViewHolder>
}
@Override
public void setDisplayImagePreview(final boolean display) {
// Images in DM are always enabled
}
@Override
public void setImagePreviewScaleType(final String scaleTypeString) {
final ScaleType scaleType;
switch (Utils.getMediaPreviewStyle(scaleTypeString)) {
case VALUE_MEDIA_PREVIEW_STYLE_CODE_CROP: {
scaleType = ScaleType.CENTER_CROP;
break;
}
case VALUE_MEDIA_PREVIEW_STYLE_CODE_SCALE: {
scaleType = ScaleType.CENTER_INSIDE;
break;
}
default: {
return;
}
}
mImagePreviewScaleType = scaleType;
public final int getMediaPreviewStyle() {
return mMediaPreviewStyle;
}
public void setCursor(final Cursor cursor) {

View File

@ -40,12 +40,12 @@ public interface IContentCardAdapter extends ILoadMoreSupportAdapter {
@ShapeStyle
int getProfileImageStyle();
boolean isProfileImageEnabled();
float getTextSize();
@NonNull
AsyncTwitterWrapper getTwitterWrapper();
boolean isProfileImageEnabled();
MediaLoaderWrapper getMediaLoader();
}

View File

@ -20,12 +20,19 @@
package org.mariotaku.twidere.adapter.iface;
import org.mariotaku.twidere.model.ParcelableDirectMessage;
import org.mariotaku.twidere.util.MediaLoaderWrapper;
import org.mariotaku.twidere.view.ShapedImageView;
public interface IDirectMessagesAdapter {
public ParcelableDirectMessage findItem(long id);
public void setDisplayImagePreview(boolean display);
@ShapedImageView.ShapeStyle
int getProfileImageStyle();
public void setImagePreviewScaleType(String scaleType);
boolean isProfileImageEnabled();
int getMediaPreviewStyle();
MediaLoaderWrapper getMediaLoader();
}

View File

@ -31,14 +31,11 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManagerTrojan;
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.util.Pair;
import android.support.v4.view.LayoutInflaterCompat;
import android.support.v4.view.LayoutInflaterFactory;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.FixedLinearLayoutManager;
@ -61,7 +58,6 @@ import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
@ -77,7 +73,6 @@ import org.mariotaku.querybuilder.Expression;
import org.mariotaku.querybuilder.OrderBy;
import org.mariotaku.querybuilder.RawItemArray;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.activity.iface.IThemedActivity;
import org.mariotaku.twidere.activity.support.BaseAppCompatActivity;
import org.mariotaku.twidere.activity.support.ImagePickerActivity;
import org.mariotaku.twidere.adapter.AccountsSpinnerAdapter;
@ -107,7 +102,6 @@ import org.mariotaku.twidere.util.MediaLoaderWrapper;
import org.mariotaku.twidere.util.ParseUtils;
import org.mariotaku.twidere.util.ReadStateManager;
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
import org.mariotaku.twidere.util.ThemedLayoutInflaterFactory;
import org.mariotaku.twidere.util.TwidereValidator;
import org.mariotaku.twidere.util.UserColorNameManager;
import org.mariotaku.twidere.util.Utils;
@ -344,10 +338,6 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
@Override
public void onResume() {
super.onResume();
final String previewScaleType = Utils.getNonEmptyString(mPreferences, KEY_MEDIA_PREVIEW_STYLE,
ScaleType.CENTER_CROP.name());
mAdapter.setImagePreviewScaleType(previewScaleType);
mAdapter.notifyDataSetChanged();
updateAddImageButton();
}

View File

@ -48,11 +48,16 @@ public class UserAgentUtils {
constructor.setAccessible(false);
}
} catch (Exception e) {
final WebView webView = new WebView(context);
WebView webView = null;
try {
webView = new WebView(context);
return webView.getSettings().getUserAgentString();
} catch (Exception e2) {
return System.getProperty("http.agent");
} finally {
webView.destroy();
if (webView != null) {
webView.destroy();
}
}
}
}

View File

@ -0,0 +1,57 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.view.holder;
import android.database.Cursor;
import android.view.View;
import android.widget.ImageView;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.adapter.MessageConversationAdapter;
import org.mariotaku.twidere.model.ParcelableDirectMessage;
import org.mariotaku.twidere.util.MediaLoaderWrapper;
/**
* Created by mariotaku on 15/4/25.
*/
public class IncomingMessageViewHolder extends MessageViewHolder {
private final ImageView profileImageView;
public IncomingMessageViewHolder(MessageConversationAdapter adapter, View itemView) {
super(adapter, itemView);
profileImageView = (ImageView) itemView.findViewById(R.id.profile_image);
}
@Override
public void displayMessage(Cursor cursor, ParcelableDirectMessage.CursorIndices indices) {
super.displayMessage(cursor, indices);
final MediaLoaderWrapper wrapper = adapter.getMediaLoader();
if (adapter.isProfileImageEnabled()) {
profileImageView.setVisibility(View.VISIBLE);
wrapper.displayProfileImage(profileImageView, cursor.getString(indices.sender_profile_image_url));
} else {
profileImageView.setVisibility(View.GONE);
wrapper.cancelDisplayTask(profileImageView);
}
}
}

View File

@ -41,19 +41,18 @@ import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.view.CardMediaContainer;
import org.mariotaku.twidere.view.CardMediaContainer.OnMediaClickListener;
public class MessageConversationViewHolder extends ViewHolder implements OnMediaClickListener {
public class MessageViewHolder extends ViewHolder implements OnMediaClickListener {
public final CardMediaContainer mediaContainer;
public final TextView text, time;
private final MessageBubbleView messageContent;
private final MessageConversationAdapter adapter;
protected final MessageConversationAdapter adapter;
private final int textColorPrimary, textColorPrimaryInverse, textColorSecondary, textColorSecondaryInverse;
private float textSize;
public MessageConversationViewHolder(final MessageConversationAdapter adapter, final View itemView) {
public MessageViewHolder(final MessageConversationAdapter adapter, final View itemView) {
super(itemView);
this.adapter = adapter;
final Context context = itemView.getContext();
@ -74,7 +73,7 @@ public class MessageConversationViewHolder extends ViewHolder implements OnMedia
public void displayMessage(Cursor cursor, CursorIndices indices) {
final Context context = adapter.getContext();
final TwidereLinkify linkify = adapter.getLinkify();
final MediaLoaderWrapper loader = adapter.getImageLoader();
final MediaLoaderWrapper loader = adapter.getMediaLoader();
final long accountId = cursor.getLong(indices.account_id);
final long timestamp = cursor.getLong(indices.message_timestamp);
@ -118,11 +117,8 @@ public class MessageConversationViewHolder extends ViewHolder implements OnMedia
}
public void setTextSize(final float textSize) {
if (this.textSize != textSize) {
this.textSize = textSize;
text.setTextSize(textSize);
time.setTextSize(textSize * 0.75f);
}
text.setTextSize(textSize);
time.setTextSize(textSize * 0.75f);
}
}

View File

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Twidere - Twitter client for Android
~
~ Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
@ -18,18 +17,25 @@
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout 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="wrap_content"
android:padding="8dp">
<org.mariotaku.twidere.view.ShapedImageView
android:id="@+id/profile_image"
style="?profileImageStyle"
android:layout_width="@dimen/icon_size_card_list_item"
android:layout_height="@dimen/icon_size_card_list_item"
android:layout_alignTop="@+id/message_content" />
<org.mariotaku.messagebubbleview.library.MessageBubbleView
android:id="@+id/message_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_toRightOf="@+id/profile_image"
android:clickable="true"
app:bubbleColor="?colorAccent"
app:caretHeight="8dp"
@ -37,7 +43,7 @@
app:caretWidth="8dp"
app:cornerRadius="2dp">
<include layout="@layout/card_item_message_conversation_common"/>
<include layout="@layout/card_item_message_conversation_common" />
</org.mariotaku.messagebubbleview.library.MessageBubbleView>
</FrameLayout>
</RelativeLayout>

View File

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Twidere - Twitter client for Android
~
~ Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
@ -18,8 +17,8 @@
~ 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:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_content"
android:layout_width="match_parent"
@ -30,7 +29,7 @@
android:id="@+id/conversation_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="?android:dividerVertical"
android:divider="?dividerVertical"
android:orientation="vertical"
android:showDividers="middle"
android:visibility="gone"
@ -45,82 +44,98 @@
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent" />
</FrameLayout>
<LinearLayout
<RelativeLayout
android:id="@+id/input_send_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="?android:colorBackground"
android:gravity="bottom"
android:orientation="horizontal">
android:orientation="horizontal"
android:padding="@dimen/element_spacing_normal">
<org.mariotaku.twidere.view.ActionIconView
android:id="@+id/add_image"
android:layout_width="?android:actionBarSize"
android:layout_height="?android:actionBarSize"
android:layout_weight="0"
android:background="?selectableItemBackgroundBorderless"
android:layout_width="@dimen/element_size_normal"
android:layout_height="@dimen/element_size_normal"
android:layout_alignParentLeft="true"
android:background="?selectableItemBackground"
android:clickable="true"
android:color="?android:textColorSecondary"
android:contentDescription="@string/add_image"
android:padding="0dp"
android:scaleType="centerInside"
android:src="@drawable/ic_action_gallery"/>
android:src="@drawable/ic_action_gallery" />
<org.mariotaku.twidere.view.StatusComposeEditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:completionThreshold="1"
android:focusable="true"
android:gravity="left|bottom"
android:hint="@string/type_to_compose"
android:inputType="textShortMessage|textMultiLine"
android:maxHeight="140dp"
android:minHeight="?android:actionBarSize"
android:singleLine="false">
<requestFocus/>
</org.mariotaku.twidere.view.StatusComposeEditText>
<FrameLayout
<org.mariotaku.twidere.view.ActionIconView
android:id="@+id/send"
android:layout_width="?android:actionBarSize"
android:layout_height="?android:actionBarSize"
android:layout_weight="0"
android:background="?selectableItemBackgroundBorderless"
android:layout_width="@dimen/element_size_normal"
android:layout_height="@dimen/element_size_normal"
android:layout_alignParentRight="true"
android:background="?selectableItemBackground"
android:clickable="true"
android:padding="0dp">
android:color="?android:textColorSecondary"
android:contentDescription="@string/send"
android:scaleType="centerInside"
android:src="@drawable/ic_action_send" />
<org.mariotaku.twidere.view.ActionIconView
<org.mariotaku.messagebubbleview.library.MessageBubbleView
android:id="@+id/edit_text_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_toLeftOf="@+id/send"
android:layout_toRightOf="@+id/add_image"
android:clickable="true"
app:bubbleColor="?messageBubbleColor"
app:caretHeight="8dp"
app:caretPosition="topRight"
app:caretWidth="8dp"
app:cornerRadius="2dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:color="?android:textColorSecondary"
android:contentDescription="@string/send"
android:scaleType="centerInside"
android:src="@drawable/ic_action_send"/>
<org.mariotaku.twidere.view.StatusTextCountView
android:id="@+id/text_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginBottom="@dimen/element_spacing_small"
android:layout_marginRight="@dimen/element_spacing_small"
android:fontFamily="sans-serif-light"
android:singleLine="true"
android:textAllCaps="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/text_size_extra_small"
tools:ignore="UnusedAttribute"
tools:text="140"/>
</FrameLayout>
</LinearLayout>
android:padding="@dimen/element_spacing_normal">
<org.mariotaku.twidere.view.StatusComposeEditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:completionThreshold="1"
android:focusable="true"
android:layout_gravity="center"
android:gravity="left|center_vertical"
android:hint="@string/type_to_compose"
android:inputType="textShortMessage|textMultiLine"
android:maxHeight="140dp"
android:singleLine="false">
<requestFocus />
</org.mariotaku.twidere.view.StatusComposeEditText>
<org.mariotaku.twidere.view.StatusTextCountView
android:id="@+id/text_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="@dimen/element_spacing_small"
android:fontFamily="sans-serif-light"
android:singleLine="true"
android:textAllCaps="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/text_size_extra_small"
tools:ignore="UnusedAttribute"
tools:text="140" />
</FrameLayout>
</org.mariotaku.messagebubbleview.library.MessageBubbleView>
</RelativeLayout>
</LinearLayout>
<FrameLayout
@ -136,7 +151,7 @@
android:layout_height="match_parent"
android:paddingLeft="@dimen/element_spacing_normal"
android:paddingRight="@dimen/element_spacing_normal"
android:scrollbarStyle="outsideInset"/>
android:scrollbarStyle="outsideInset" />
<LinearLayout
android:id="@+id/users_search_empty"
@ -151,7 +166,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:color="?android:textColorSecondary"
android:src="@drawable/ic_info_search"/>
android:src="@drawable/ic_info_search" />
<TextView
android:id="@+id/users_search_empty_text"
@ -160,7 +175,7 @@
android:layout_gravity="center"
android:layout_marginTop="@dimen/element_spacing_normal"
android:gravity="center"
android:textAppearance="?android:textAppearanceMedium"/>
android:textAppearance="?android:textAppearanceMedium" />
</LinearLayout>
<ProgressBar
@ -169,7 +184,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone"/>
android:visibility="gone" />
</FrameLayout>
</FrameLayout>