1
0
mirror of https://github.com/TwidereProject/Twidere-Android synced 2025-01-31 00:45:00 +01:00

remember timeline position will work

trying to fix "compose now" conflict with samsung devices
fixed some NPE
This commit is contained in:
Mariotaku Lee 2015-03-30 14:08:17 +08:00
parent cf6959c0f2
commit b2bd90dc29
12 changed files with 160 additions and 39 deletions

View File

@ -23,6 +23,7 @@ import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.ActionBar;
import android.view.Menu;
import android.view.MenuItem;
@ -111,7 +112,7 @@ public class OpenStreetMapViewerActivity extends BaseActionBarActivity implement
mMapView.setBuiltInZoomControls(true);
final List<Overlay> overlays = mMapView.getOverlays();
final GeoPoint gp = new GeoPoint((int) (latitude * 1E6), (int) (longitude * 1E6));
final Drawable d = getResources().getDrawable(R.drawable.ic_map_marker);
final Drawable d = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_map_marker, null);
final Itemization markers = new Itemization(d, mMapView.getResourceProxy());
final OverlayItem overlayitem = new OverlayItem("", "", gp);
markers.addOverlay(overlayitem);

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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/>.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/material_light_blue"/>
<stroke
android:color="@android:color/white"
android:width="@dimen/element_spacing_xsmall"/>
<size
android:width="@dimen/element_spacing_large"
android:height="@dimen/element_spacing_large"/>
</shape>

View File

@ -43,6 +43,7 @@ import com.nostra13.universalimageloader.utils.L;
import com.squareup.otto.Bus;
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.activity.AssistLauncherActivity;
import org.mariotaku.twidere.activity.MainActivity;
import org.mariotaku.twidere.activity.MainHondaJOJOActivity;
import org.mariotaku.twidere.service.RefreshService;
@ -223,6 +224,11 @@ public class TwidereApplication extends MultiDexApplication implements Constants
pm.setComponentEnabledSetting(main2, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
}
if (!Utils.isComposeNowSupported()) {
final ComponentName assist = new ComponentName(this, AssistLauncherActivity.class);
pm.setComponentEnabledSetting(assist, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
}
migrateUsageStatisticsPreferences();
startUsageStatisticsServiceIfNeeded(this);

View File

@ -272,21 +272,26 @@ public abstract class AbsStatusesFragment<Data> extends BaseSupportFragment impl
public final void onLoadFinished(Loader<Data> loader, Data data) {
setRefreshing(false);
final SharedPreferences preferences = getSharedPreferences();
final boolean rememberPosition = preferences.getBoolean(KEY_REMEMBER_POSITION, false);
final boolean readFromBottom = preferences.getBoolean(KEY_READ_FROM_BOTTOM, false);
final long lastReadId;
final int lastVisiblePos, lastVisibleTop;
final String tag = getCurrentReadPositionTag();
if (readFromBottom) {
lastVisiblePos = mLayoutManager.findLastVisibleItemPosition();
} else {
lastVisiblePos = mLayoutManager.findFirstVisibleItemPosition();
}
if (lastVisiblePos != -1) {
lastReadId = mAdapter.getItemId(lastVisiblePos);
lastReadId = mAdapter.getStatusId(lastVisiblePos);
if (readFromBottom) {
lastVisibleTop = mLayoutManager.getChildAt(mLayoutManager.getChildCount() - 1).getTop();
} else {
lastVisibleTop = mLayoutManager.getChildAt(0).getTop();
}
} else if (rememberPosition && tag != null) {
lastReadId = mReadStateManager.getPosition(tag);
lastVisibleTop = 0;
} else {
lastReadId = -1;
lastVisibleTop = 0;
@ -295,14 +300,14 @@ public abstract class AbsStatusesFragment<Data> extends BaseSupportFragment impl
if (!(loader instanceof IExtendedLoader) || ((IExtendedLoader) loader).isFromUser()) {
mAdapter.setLoadMoreIndicatorEnabled(hasMoreData(data));
int pos = -1;
for (int i = 0; i < mAdapter.getItemCount(); i++) {
if (lastReadId == mAdapter.getItemId(i)) {
for (int i = 0, j = mAdapter.getItemCount(); i < j; i++) {
if (lastReadId != -1 && lastReadId == mAdapter.getStatusId(i)) {
pos = i;
break;
}
}
if (pos != -1 && mAdapter.isStatus(pos) && (readFromBottom || lastVisiblePos != 0)) {
mLayoutManager.scrollToPositionWithOffset(pos, lastVisibleTop - mLayoutManager.getPaddingTop());
mLayoutManager.scrollToPositionWithOffset(pos, lastVisibleTop);
}
}
if (loader instanceof IExtendedLoader) {
@ -445,6 +450,13 @@ public abstract class AbsStatusesFragment<Data> extends BaseSupportFragment impl
final ParcelableStatus status = mAdapter.getStatus(position);
if (status == null) return;
mReadStateManager.setPosition(readPositionTag, status.id);
mReadStateManager.setPosition(getCurrentReadPositionTag(), status.id, true);
}
private String getCurrentReadPositionTag() {
final String tag = getReadPositionTag();
if (tag == null) return null;
return tag + "_current";
}
private void setListShown(boolean shown) {

View File

@ -6,6 +6,8 @@ import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.TypedArray;
import android.preference.CheckBoxPreference;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
public class ComponentStatePreference extends CheckBoxPreference {
@ -23,12 +25,8 @@ public class ComponentStatePreference extends CheckBoxPreference {
public ComponentStatePreference(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
final TypedArray a = context.obtainStyledAttributes(attrs, new int[]{android.R.attr.name});
final String name = a.getString(0);
a.recycle();
if (name == null) throw new NullPointerException();
mPackageManager = context.getPackageManager();
mComponentName = new ComponentName(context.getPackageName(), name);
mComponentName = getComponentName(context, attrs);
setDefaultValue(isComponentEnabled());
}
@ -39,11 +37,6 @@ public class ComponentStatePreference extends CheckBoxPreference {
return disableDependentsState ? value : !value;
}
@Override
protected boolean getPersistedBoolean(final boolean defaultReturnValue) {
return isComponentEnabled();
}
@Override
protected Object onGetDefaultValue(final TypedArray a, final int index) {
return isComponentEnabled();
@ -54,6 +47,35 @@ public class ComponentStatePreference extends CheckBoxPreference {
setChecked(getPersistedBoolean(true));
}
protected ComponentName getComponentName(Context context, AttributeSet attrs) {
final TypedArray a = context.obtainStyledAttributes(attrs, new int[]{android.R.attr.name});
final String name = a.getString(0);
a.recycle();
if (name == null) throw new NullPointerException();
return new ComponentName(context.getPackageName(), name);
}
protected boolean isComponentAvailable() {
return true;
}
@Override
protected boolean shouldPersist() {
return true;
}
@Override
protected void notifyHierarchyChanged() {
super.notifyHierarchyChanged();
updateEnableState();
}
@Override
protected void onAttachedToHierarchy(@NonNull final PreferenceManager preferenceManager) {
super.onAttachedToHierarchy(preferenceManager);
updateEnableState();
}
@Override
protected boolean persistBoolean(final boolean value) {
final int newState = value ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
@ -63,8 +85,8 @@ public class ComponentStatePreference extends CheckBoxPreference {
}
@Override
protected boolean shouldPersist() {
return true;
protected boolean getPersistedBoolean(final boolean defaultReturnValue) {
return isComponentEnabled();
}
@SuppressLint("InlinedApi")
@ -80,4 +102,8 @@ public class ComponentStatePreference extends CheckBoxPreference {
}
}
private void updateEnableState() {
setEnabled(isComponentAvailable());
}
}

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.preference;
import android.content.ComponentName;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import org.mariotaku.twidere.activity.AssistLauncherActivity;
import org.mariotaku.twidere.util.Utils;
/**
* Created by mariotaku on 15/3/30.
*/
public class ComposeNowPreference extends ComponentStatePreference {
public ComposeNowPreference(Context context) {
super(context);
}
public ComposeNowPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ComposeNowPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected boolean isComponentAvailable() {
return Utils.isComposeNowSupported();
}
@Override
protected ComponentName getComponentName(Context context, AttributeSet attrs) {
return new ComponentName(context, AssistLauncherActivity.class);
}
}

View File

@ -39,7 +39,7 @@ public class StatusLinkClickHandler extends OnLinkClickHandler {
}
private ParcelableMedia findByLink(ParcelableMedia[] media, String link) {
if (link == null) return null;
if (link == null || media == null) return null;
for (ParcelableMedia mediaItem : media) {
if (link.equals(mediaItem.media_url) || link.equals(mediaItem.page_url))
return mediaItem;

View File

@ -91,6 +91,8 @@ import android.transition.TransitionInflater;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
@ -1488,6 +1490,11 @@ public final class Utils implements Constants, TwitterConstants {
return ids;
}
public static boolean isComposeNowSupported() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) return false;
return !KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);
}
public static boolean isOfficialCredentials(final Context context, final ParcelableCredentials account) {
if (account == null) return false;
final boolean isOAuth = account.auth_type == Accounts.AUTH_TYPE_OAUTH

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -41,16 +41,6 @@
<item>@string/profile_images</item>
<item>@string/preview_images</item>
</string-array>
<string-array name="entries_compose_quit_action">
<item>@string/ask</item>
<item>@string/save</item>
<item>@string/discard</item>
</string-array>
<string-array name="values_compose_quit_action">
<item>ask</item>
<item>save</item>
<item>discard</item>
</string-array>
<string-array name="entries_theme">
<item>@string/theme_light</item>
<item>@string/theme_dark</item>
@ -69,13 +59,6 @@
<item>@string/theme_background_solid</item>
<item>@string/theme_background_transparent</item>
</string-array>
<string-array name="dependency_values_actionbar_theme">
<item>twidere</item>
<item>light</item>
</string-array>
<string-array name="dependency_values_theme_background_alpha">
<item>transparent</item>
</string-array>
<string-array name="dependency_values_true">
<item>true</item>
</string-array>
@ -147,6 +130,4 @@
<item>@string/square</item>
</string-array>
<string name="crop">Crop</string>
<string name="scale">Scale</string>
</resources>

View File

@ -736,5 +736,7 @@
<string name="projects_we_took_part">Projects we took part</string>
<string name="activated_accounts">Activated accounts</string>
<string name="search">Search</string>
<string name="crop">Crop</string>
<string name="scale">Scale</string>
</resources>

View File

@ -20,8 +20,7 @@
android:key="twitter_link_handler"
android:title="@string/open_twitter_links"/>
<org.mariotaku.twidere.preference.ComponentStatePreference
android:name="org.mariotaku.twidere.activity.AssistLauncherActivity"
<org.mariotaku.twidere.preference.ComposeNowPreference
android:key="compose_now"
android:summary="@string/compose_now_summary"
android:title="@string/compose_now"/>