mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-01-31 08:54:57 +01:00
improved remember position
This commit is contained in:
parent
56703df643
commit
21bc95e054
@ -163,10 +163,10 @@ public interface TwidereDataStore {
|
||||
PROFILE_BANNER_URL, COLOR, IS_ACTIVATED, SORT_POSITION, ACCOUNT_TYPE, ACCOUNT_EXTRAS,
|
||||
ACCOUNT_USER};
|
||||
|
||||
String[] TYPES = {TYPE_PRIMARY_KEY, TYPE_TEXT_NOT_NULL, TYPE_TEXT_NOT_NULL, TYPE_TEXT_NOT_NULL,
|
||||
TYPE_INT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT,
|
||||
TYPE_BOOLEAN, TYPE_BOOLEAN, TYPE_TEXT, TYPE_TEXT, TYPE_INT, TYPE_BOOLEAN, TYPE_INT,
|
||||
TYPE_TEXT, TYPE_TEXT, TYPE_TEXT};
|
||||
String[] TYPES = {TYPE_PRIMARY_KEY, TYPE_TEXT_NOT_NULL, TYPE_TEXT_NOT_NULL,
|
||||
TYPE_TEXT_NOT_NULL_UNIQUE, TYPE_INT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT,
|
||||
TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_BOOLEAN, TYPE_BOOLEAN, TYPE_TEXT, TYPE_TEXT,
|
||||
TYPE_INT, TYPE_BOOLEAN, TYPE_INT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT};
|
||||
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ import static org.mariotaku.twidere.annotation.PreferenceType.STRING;
|
||||
public interface Constants extends TwidereConstants {
|
||||
|
||||
String DATABASES_NAME = "twidere.sqlite";
|
||||
int DATABASES_VERSION = 137;
|
||||
int DATABASES_VERSION = 138;
|
||||
|
||||
int MENU_GROUP_STATUS_EXTENSION = 10;
|
||||
int MENU_GROUP_COMPOSE_EXTENSION = 11;
|
||||
|
@ -276,7 +276,14 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo
|
||||
if (accountKey == null) {
|
||||
accountKey = defaultId;
|
||||
}
|
||||
mAccountsAdapter.setSelectedAccountKey(accountKey);
|
||||
ParcelableAccount selectedAccount = null;
|
||||
for (ParcelableAccount account : accounts) {
|
||||
if (account.account_key.equals(accountKey)) {
|
||||
selectedAccount = account;
|
||||
break;
|
||||
}
|
||||
}
|
||||
mAccountsAdapter.setSelectedAccount(selectedAccount);
|
||||
|
||||
if (mAccountActionProvider != null) {
|
||||
mAccountActionProvider.setExclusive(false);
|
||||
@ -563,7 +570,7 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo
|
||||
final Editor editor = mPreferences.edit();
|
||||
editor.putString(KEY_DEFAULT_ACCOUNT_KEY, account.account_key.toString());
|
||||
editor.apply();
|
||||
mAccountsAdapter.setSelectedAccountKey(account.account_key);
|
||||
mAccountsAdapter.setSelectedAccount(account);
|
||||
updateAccountActions();
|
||||
updateAccountOptionsSeparatorLabel(clickedDrawable);
|
||||
snapshotView.setVisibility(View.INVISIBLE);
|
||||
@ -759,10 +766,10 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo
|
||||
return selectedAccount.account_key;
|
||||
}
|
||||
|
||||
public void setSelectedAccountKey(@Nullable UserKey accountKey) {
|
||||
public void setSelectedAccount(@Nullable ParcelableAccount account) {
|
||||
final ParcelableAccount selectedAccount = getSelectedAccount();
|
||||
if (selectedAccount == null || accountKey == null) return;
|
||||
swap(accountKey, selectedAccount.account_key);
|
||||
if (selectedAccount == null || account == null) return;
|
||||
swap(account, selectedAccount);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -821,14 +828,14 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo
|
||||
return mInternalAccounts;
|
||||
}
|
||||
|
||||
private void swap(UserKey fromId, UserKey toId) {
|
||||
private void swap(@NonNull ParcelableAccount from, @NonNull ParcelableAccount to) {
|
||||
int fromIdx = -1, toIdx = -1;
|
||||
for (int i = 0, j = mInternalAccounts.length; i < j; i++) {
|
||||
final ParcelableAccount account = mInternalAccounts[i];
|
||||
if (fromId.equals(account.account_key)) {
|
||||
if (from.id == account.id) {
|
||||
fromIdx = i;
|
||||
}
|
||||
if (toId.equals(account.account_key)) {
|
||||
if (to.id == account.id) {
|
||||
toIdx = i;
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ package org.mariotaku.twidere.fragment;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@ -33,7 +32,6 @@ import android.support.v4.content.Loader;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.mariotaku.library.objectcursor.ObjectCursor;
|
||||
import org.mariotaku.sqliteqb.library.ArgsArray;
|
||||
import org.mariotaku.sqliteqb.library.Columns.Column;
|
||||
import org.mariotaku.sqliteqb.library.Expression;
|
||||
@ -43,7 +41,6 @@ import org.mariotaku.twidere.adapter.ListParcelableStatusesAdapter;
|
||||
import org.mariotaku.twidere.adapter.ParcelableStatusesAdapter;
|
||||
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition;
|
||||
import org.mariotaku.twidere.loader.ExtendedObjectCursorLoader;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount;
|
||||
import org.mariotaku.twidere.model.ParcelableStatus;
|
||||
import org.mariotaku.twidere.model.ParcelableStatusCursorIndices;
|
||||
import org.mariotaku.twidere.model.SimpleRefreshTaskParam;
|
||||
@ -54,7 +51,6 @@ import org.mariotaku.twidere.model.message.GetStatusesTaskEvent;
|
||||
import org.mariotaku.twidere.model.message.StatusDestroyedEvent;
|
||||
import org.mariotaku.twidere.model.message.StatusListChangedEvent;
|
||||
import org.mariotaku.twidere.model.message.StatusRetweetedEvent;
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Accounts;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Filters;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses;
|
||||
@ -138,7 +134,7 @@ public abstract class CursorStatusesFragment extends AbsStatusesFragment {
|
||||
if (!event.uri.equals(getContentUri())) return;
|
||||
setRefreshing(event.running);
|
||||
if (!event.running) {
|
||||
setLoadMoreIndicatorPosition(IndicatorPosition.END);
|
||||
setLoadMoreIndicatorPosition(IndicatorPosition.NONE);
|
||||
setRefreshEnabled(true);
|
||||
onLoadingFinished();
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
package org.mariotaku.twidere.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 16/3/22.
|
||||
*/
|
||||
public class EntrySummaryListPreference extends ThemedListPreference {
|
||||
public EntrySummaryListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
public EntrySummaryListPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
public EntrySummaryListPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public EntrySummaryListPreference(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return getEntry();
|
||||
}
|
||||
}
|
@ -20,7 +20,6 @@
|
||||
package org.mariotaku.twidere.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.text.SpannableString;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
@ -28,7 +27,7 @@ import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.text.TwidereHighLightStyle;
|
||||
|
||||
public class LinkHighlightPreference extends ThemedListPreference implements Constants {
|
||||
public class LinkHighlightPreference extends EntrySummaryListPreference implements Constants {
|
||||
|
||||
private static final int[] ENTRIES_RES = {R.string.none, R.string.highlight, R.string.underline,
|
||||
R.string.highlight_and_underline};
|
||||
@ -52,14 +51,6 @@ public class LinkHighlightPreference extends ThemedListPreference implements Con
|
||||
setEntryValues(VALUES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
// final TextView summary = (TextView) holder.findViewById(android.R.id.summary);
|
||||
// summary.setVisibility(View.VISIBLE);
|
||||
// summary.setText(getStyledEntry(Utils.getLinkHighlightingStyleInt(getValue()), getEntry()));
|
||||
}
|
||||
|
||||
private static CharSequence getStyledEntry(final int option, final CharSequence entry) {
|
||||
final SpannableString str = new SpannableString(entry);
|
||||
str.setSpan(new TwidereHighLightStyle(option), 0, str.length(), 0);
|
||||
|
@ -28,7 +28,7 @@ import android.util.AttributeSet;
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.R;
|
||||
|
||||
public class ThemeFontFamilyPreference extends ThemedListPreference implements Constants {
|
||||
public class ThemeFontFamilyPreference extends EntrySummaryListPreference implements Constants {
|
||||
|
||||
private static final int[] ENTRIES_RES = {R.string.font_family_regular, R.string.font_family_condensed,
|
||||
R.string.font_family_light};
|
||||
|
@ -199,7 +199,7 @@ public abstract class GetStatusesTask extends AbstractTask<RefreshTaskParam,
|
||||
false);
|
||||
ParcelableStatusUtils.updateExtraInformation(status, credentials, manager);
|
||||
status.position_key = getPositionKey(status.timestamp, status.sort_id, lastSortId,
|
||||
sortDiff);
|
||||
sortDiff, i, j);
|
||||
values[i] = ParcelableStatusValuesCreator.create(status);
|
||||
values[i].put(Statuses.INSERTED_DATE, System.currentTimeMillis());
|
||||
if (minIdx == -1 || item.compareTo(statuses.get(minIdx)) < 0) {
|
||||
@ -260,9 +260,18 @@ public abstract class GetStatusesTask extends AbstractTask<RefreshTaskParam,
|
||||
}
|
||||
}
|
||||
|
||||
public static long getPositionKey(long timestamp, long sortId, long lastSortId, long sortDiff) {
|
||||
public static long getPositionKey(long timestamp, long sortId, long lastSortId, long sortDiff,
|
||||
int position, int count) {
|
||||
if (sortDiff == 0) return timestamp;
|
||||
return timestamp + (sortId - lastSortId) * 499 / sortDiff;
|
||||
int extraValue;
|
||||
if (sortDiff > 0) {
|
||||
// descent sorted by time
|
||||
extraValue = count - 1 - position;
|
||||
} else {
|
||||
// ascent sorted by time
|
||||
extraValue = position;
|
||||
}
|
||||
return timestamp + (sortId - lastSortId) * (499 - count) / sortDiff + extraValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -51,7 +51,7 @@
|
||||
android:summary="@string/proxy_summary"
|
||||
android:title="@string/proxy"/>
|
||||
|
||||
<org.mariotaku.twidere.preference.ThemedListPreference
|
||||
<org.mariotaku.twidere.preference.EntrySummaryListPreference
|
||||
android:defaultValue="http"
|
||||
android:dependency="enable_proxy"
|
||||
android:entries="@array/entries_proxy_type"
|
||||
|
@ -36,7 +36,7 @@
|
||||
android:value="true"/>
|
||||
</SwitchPreferenceCompat>
|
||||
|
||||
<org.mariotaku.twidere.preference.ThemedListPreference
|
||||
<org.mariotaku.twidere.preference.EntrySummaryListPreference
|
||||
android:defaultValue="@string/default_profile_image_style"
|
||||
android:entries="@array/entries_profile_image_style"
|
||||
android:entryValues="@array/values_profile_image_style"
|
||||
@ -46,7 +46,7 @@
|
||||
<extra
|
||||
android:name="notify_change"
|
||||
android:value="true"/>
|
||||
</org.mariotaku.twidere.preference.ThemedListPreference>
|
||||
</org.mariotaku.twidere.preference.EntrySummaryListPreference>
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
|
@ -18,6 +18,7 @@
|
||||
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<!--suppress AndroidElementNotAllowed -->
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
@ -37,7 +38,7 @@
|
||||
android:summary="@string/compose_now_summary"
|
||||
android:title="@string/compose_now"/>
|
||||
|
||||
<org.mariotaku.twidere.preference.ThemedListPreference
|
||||
<org.mariotaku.twidere.preference.EntrySummaryListPreference
|
||||
android:defaultValue="compose"
|
||||
android:dependency="compose_now"
|
||||
android:entries="@array/entries_compose_now_action"
|
||||
|
@ -14,7 +14,7 @@
|
||||
<PreferenceCategory
|
||||
android:key="cat_general"
|
||||
android:title="@string/general">
|
||||
<org.mariotaku.twidere.preference.ThemedListPreference
|
||||
<org.mariotaku.twidere.preference.EntrySummaryListPreference
|
||||
android:defaultValue="15"
|
||||
android:entries="@array/entries_refresh_interval"
|
||||
android:entryValues="@array/values_refresh_interval"
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<org.mariotaku.twidere.preference.ThemedListPreference
|
||||
<org.mariotaku.twidere.preference.EntrySummaryListPreference
|
||||
android:defaultValue="crop"
|
||||
android:entries="@array/entries_media_preview_style"
|
||||
android:entryValues="@array/values_media_preview_style"
|
||||
@ -29,7 +29,7 @@
|
||||
<extra
|
||||
android:name="notify_change"
|
||||
android:value="true"/>
|
||||
</org.mariotaku.twidere.preference.ThemedListPreference>
|
||||
</org.mariotaku.twidere.preference.EntrySummaryListPreference>
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:key="show_absolute_time"
|
||||
@ -48,7 +48,7 @@
|
||||
android:value="true"/>
|
||||
</SwitchPreferenceCompat>
|
||||
|
||||
<org.mariotaku.twidere.preference.ThemedListPreference
|
||||
<org.mariotaku.twidere.preference.EntrySummaryListPreference
|
||||
android:defaultValue="@string/default_tab_display_option"
|
||||
android:entries="@array/entries_tab_display_option"
|
||||
android:entryValues="@array/values_tab_display_option"
|
||||
|
@ -5,7 +5,7 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:title="@string/theme">
|
||||
|
||||
<org.mariotaku.twidere.preference.ThemedListPreference
|
||||
<org.mariotaku.twidere.preference.EntrySummaryListPreference
|
||||
android:defaultValue="light"
|
||||
android:entries="@array/entries_theme"
|
||||
android:entryValues="@array/values_theme"
|
||||
@ -15,7 +15,7 @@
|
||||
<extra
|
||||
android:name="recreate_activity"
|
||||
android:value="true"/>
|
||||
</org.mariotaku.twidere.preference.ThemedListPreference>
|
||||
</org.mariotaku.twidere.preference.EntrySummaryListPreference>
|
||||
|
||||
<org.mariotaku.twidere.preference.ThemeBackgroundPreference
|
||||
android:defaultValue="default"
|
||||
|
Loading…
x
Reference in New Issue
Block a user