1
0
mirror of https://github.com/TwidereProject/Twidere-Android synced 2025-02-07 15:28:51 +01:00

improved remember position

This commit is contained in:
Mariotaku Lee 2016-03-22 18:00:12 +08:00
parent 56703df643
commit 21bc95e054
14 changed files with 76 additions and 42 deletions

View File

@ -163,10 +163,10 @@ public interface TwidereDataStore {
PROFILE_BANNER_URL, COLOR, IS_ACTIVATED, SORT_POSITION, ACCOUNT_TYPE, ACCOUNT_EXTRAS, PROFILE_BANNER_URL, COLOR, IS_ACTIVATED, SORT_POSITION, ACCOUNT_TYPE, ACCOUNT_EXTRAS,
ACCOUNT_USER}; ACCOUNT_USER};
String[] TYPES = {TYPE_PRIMARY_KEY, TYPE_TEXT_NOT_NULL, TYPE_TEXT_NOT_NULL, TYPE_TEXT_NOT_NULL, String[] TYPES = {TYPE_PRIMARY_KEY, 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_TEXT_NOT_NULL_UNIQUE, TYPE_INT, 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, TYPE_BOOLEAN, TYPE_BOOLEAN, TYPE_TEXT, TYPE_TEXT,
TYPE_TEXT, TYPE_TEXT, TYPE_TEXT}; TYPE_INT, TYPE_BOOLEAN, TYPE_INT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT};
} }

View File

@ -34,7 +34,7 @@ import static org.mariotaku.twidere.annotation.PreferenceType.STRING;
public interface Constants extends TwidereConstants { public interface Constants extends TwidereConstants {
String DATABASES_NAME = "twidere.sqlite"; String DATABASES_NAME = "twidere.sqlite";
int DATABASES_VERSION = 137; int DATABASES_VERSION = 138;
int MENU_GROUP_STATUS_EXTENSION = 10; int MENU_GROUP_STATUS_EXTENSION = 10;
int MENU_GROUP_COMPOSE_EXTENSION = 11; int MENU_GROUP_COMPOSE_EXTENSION = 11;

View File

@ -276,7 +276,14 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo
if (accountKey == null) { if (accountKey == null) {
accountKey = defaultId; 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) { if (mAccountActionProvider != null) {
mAccountActionProvider.setExclusive(false); mAccountActionProvider.setExclusive(false);
@ -563,7 +570,7 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo
final Editor editor = mPreferences.edit(); final Editor editor = mPreferences.edit();
editor.putString(KEY_DEFAULT_ACCOUNT_KEY, account.account_key.toString()); editor.putString(KEY_DEFAULT_ACCOUNT_KEY, account.account_key.toString());
editor.apply(); editor.apply();
mAccountsAdapter.setSelectedAccountKey(account.account_key); mAccountsAdapter.setSelectedAccount(account);
updateAccountActions(); updateAccountActions();
updateAccountOptionsSeparatorLabel(clickedDrawable); updateAccountOptionsSeparatorLabel(clickedDrawable);
snapshotView.setVisibility(View.INVISIBLE); snapshotView.setVisibility(View.INVISIBLE);
@ -759,10 +766,10 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo
return selectedAccount.account_key; return selectedAccount.account_key;
} }
public void setSelectedAccountKey(@Nullable UserKey accountKey) { public void setSelectedAccount(@Nullable ParcelableAccount account) {
final ParcelableAccount selectedAccount = getSelectedAccount(); final ParcelableAccount selectedAccount = getSelectedAccount();
if (selectedAccount == null || accountKey == null) return; if (selectedAccount == null || account == null) return;
swap(accountKey, selectedAccount.account_key); swap(account, selectedAccount);
} }
@Override @Override
@ -821,14 +828,14 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo
return mInternalAccounts; return mInternalAccounts;
} }
private void swap(UserKey fromId, UserKey toId) { private void swap(@NonNull ParcelableAccount from, @NonNull ParcelableAccount to) {
int fromIdx = -1, toIdx = -1; int fromIdx = -1, toIdx = -1;
for (int i = 0, j = mInternalAccounts.length; i < j; i++) { for (int i = 0, j = mInternalAccounts.length; i < j; i++) {
final ParcelableAccount account = mInternalAccounts[i]; final ParcelableAccount account = mInternalAccounts[i];
if (fromId.equals(account.account_key)) { if (from.id == account.id) {
fromIdx = i; fromIdx = i;
} }
if (toId.equals(account.account_key)) { if (to.id == account.id) {
toIdx = i; toIdx = i;
} }
} }

View File

@ -22,7 +22,6 @@ package org.mariotaku.twidere.fragment;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.database.ContentObserver; import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
@ -33,7 +32,6 @@ import android.support.v4.content.Loader;
import com.squareup.otto.Subscribe; import com.squareup.otto.Subscribe;
import org.mariotaku.library.objectcursor.ObjectCursor;
import org.mariotaku.sqliteqb.library.ArgsArray; import org.mariotaku.sqliteqb.library.ArgsArray;
import org.mariotaku.sqliteqb.library.Columns.Column; import org.mariotaku.sqliteqb.library.Columns.Column;
import org.mariotaku.sqliteqb.library.Expression; 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.ParcelableStatusesAdapter;
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition; import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition;
import org.mariotaku.twidere.loader.ExtendedObjectCursorLoader; import org.mariotaku.twidere.loader.ExtendedObjectCursorLoader;
import org.mariotaku.twidere.model.ParcelableAccount;
import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableStatus;
import org.mariotaku.twidere.model.ParcelableStatusCursorIndices; import org.mariotaku.twidere.model.ParcelableStatusCursorIndices;
import org.mariotaku.twidere.model.SimpleRefreshTaskParam; 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.StatusDestroyedEvent;
import org.mariotaku.twidere.model.message.StatusListChangedEvent; import org.mariotaku.twidere.model.message.StatusListChangedEvent;
import org.mariotaku.twidere.model.message.StatusRetweetedEvent; 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.Accounts;
import org.mariotaku.twidere.provider.TwidereDataStore.Filters; import org.mariotaku.twidere.provider.TwidereDataStore.Filters;
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses; import org.mariotaku.twidere.provider.TwidereDataStore.Statuses;
@ -138,7 +134,7 @@ public abstract class CursorStatusesFragment extends AbsStatusesFragment {
if (!event.uri.equals(getContentUri())) return; if (!event.uri.equals(getContentUri())) return;
setRefreshing(event.running); setRefreshing(event.running);
if (!event.running) { if (!event.running) {
setLoadMoreIndicatorPosition(IndicatorPosition.END); setLoadMoreIndicatorPosition(IndicatorPosition.NONE);
setRefreshEnabled(true); setRefreshEnabled(true);
onLoadingFinished(); onLoadingFinished();
} }

View File

@ -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();
}
}

View File

@ -20,7 +20,6 @@
package org.mariotaku.twidere.preference; package org.mariotaku.twidere.preference;
import android.content.Context; import android.content.Context;
import android.support.v7.preference.PreferenceViewHolder;
import android.text.SpannableString; import android.text.SpannableString;
import android.util.AttributeSet; import android.util.AttributeSet;
@ -28,7 +27,7 @@ import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.R; import org.mariotaku.twidere.R;
import org.mariotaku.twidere.text.TwidereHighLightStyle; 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, private static final int[] ENTRIES_RES = {R.string.none, R.string.highlight, R.string.underline,
R.string.highlight_and_underline}; R.string.highlight_and_underline};
@ -52,14 +51,6 @@ public class LinkHighlightPreference extends ThemedListPreference implements Con
setEntryValues(VALUES); 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) { private static CharSequence getStyledEntry(final int option, final CharSequence entry) {
final SpannableString str = new SpannableString(entry); final SpannableString str = new SpannableString(entry);
str.setSpan(new TwidereHighLightStyle(option), 0, str.length(), 0); str.setSpan(new TwidereHighLightStyle(option), 0, str.length(), 0);

View File

@ -28,7 +28,7 @@ import android.util.AttributeSet;
import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.R; 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, private static final int[] ENTRIES_RES = {R.string.font_family_regular, R.string.font_family_condensed,
R.string.font_family_light}; R.string.font_family_light};

View File

@ -199,7 +199,7 @@ public abstract class GetStatusesTask extends AbstractTask<RefreshTaskParam,
false); false);
ParcelableStatusUtils.updateExtraInformation(status, credentials, manager); ParcelableStatusUtils.updateExtraInformation(status, credentials, manager);
status.position_key = getPositionKey(status.timestamp, status.sort_id, lastSortId, status.position_key = getPositionKey(status.timestamp, status.sort_id, lastSortId,
sortDiff); sortDiff, i, j);
values[i] = ParcelableStatusValuesCreator.create(status); values[i] = ParcelableStatusValuesCreator.create(status);
values[i].put(Statuses.INSERTED_DATE, System.currentTimeMillis()); values[i].put(Statuses.INSERTED_DATE, System.currentTimeMillis());
if (minIdx == -1 || item.compareTo(statuses.get(minIdx)) < 0) { 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; 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;
} }
} }

View File

@ -51,7 +51,7 @@
android:summary="@string/proxy_summary" android:summary="@string/proxy_summary"
android:title="@string/proxy"/> android:title="@string/proxy"/>
<org.mariotaku.twidere.preference.ThemedListPreference <org.mariotaku.twidere.preference.EntrySummaryListPreference
android:defaultValue="http" android:defaultValue="http"
android:dependency="enable_proxy" android:dependency="enable_proxy"
android:entries="@array/entries_proxy_type" android:entries="@array/entries_proxy_type"

View File

@ -36,7 +36,7 @@
android:value="true"/> android:value="true"/>
</SwitchPreferenceCompat> </SwitchPreferenceCompat>
<org.mariotaku.twidere.preference.ThemedListPreference <org.mariotaku.twidere.preference.EntrySummaryListPreference
android:defaultValue="@string/default_profile_image_style" android:defaultValue="@string/default_profile_image_style"
android:entries="@array/entries_profile_image_style" android:entries="@array/entries_profile_image_style"
android:entryValues="@array/values_profile_image_style" android:entryValues="@array/values_profile_image_style"
@ -46,7 +46,7 @@
<extra <extra
android:name="notify_change" android:name="notify_change"
android:value="true"/> android:value="true"/>
</org.mariotaku.twidere.preference.ThemedListPreference> </org.mariotaku.twidere.preference.EntrySummaryListPreference>
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:defaultValue="false" android:defaultValue="false"

View File

@ -18,6 +18,7 @@
~ along with this program. If not, see <http://www.gnu.org/licenses/>. ~ along with this program. If not, see <http://www.gnu.org/licenses/>.
--> -->
<!--suppress AndroidElementNotAllowed -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<SwitchPreferenceCompat <SwitchPreferenceCompat
@ -37,7 +38,7 @@
android:summary="@string/compose_now_summary" android:summary="@string/compose_now_summary"
android:title="@string/compose_now"/> android:title="@string/compose_now"/>
<org.mariotaku.twidere.preference.ThemedListPreference <org.mariotaku.twidere.preference.EntrySummaryListPreference
android:defaultValue="compose" android:defaultValue="compose"
android:dependency="compose_now" android:dependency="compose_now"
android:entries="@array/entries_compose_now_action" android:entries="@array/entries_compose_now_action"

View File

@ -14,7 +14,7 @@
<PreferenceCategory <PreferenceCategory
android:key="cat_general" android:key="cat_general"
android:title="@string/general"> android:title="@string/general">
<org.mariotaku.twidere.preference.ThemedListPreference <org.mariotaku.twidere.preference.EntrySummaryListPreference
android:defaultValue="15" android:defaultValue="15"
android:entries="@array/entries_refresh_interval" android:entries="@array/entries_refresh_interval"
android:entryValues="@array/values_refresh_interval" android:entryValues="@array/values_refresh_interval"

View File

@ -20,7 +20,7 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<org.mariotaku.twidere.preference.ThemedListPreference <org.mariotaku.twidere.preference.EntrySummaryListPreference
android:defaultValue="crop" android:defaultValue="crop"
android:entries="@array/entries_media_preview_style" android:entries="@array/entries_media_preview_style"
android:entryValues="@array/values_media_preview_style" android:entryValues="@array/values_media_preview_style"
@ -29,7 +29,7 @@
<extra <extra
android:name="notify_change" android:name="notify_change"
android:value="true"/> android:value="true"/>
</org.mariotaku.twidere.preference.ThemedListPreference> </org.mariotaku.twidere.preference.EntrySummaryListPreference>
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:defaultValue="false" android:defaultValue="false"
android:key="show_absolute_time" android:key="show_absolute_time"
@ -48,7 +48,7 @@
android:value="true"/> android:value="true"/>
</SwitchPreferenceCompat> </SwitchPreferenceCompat>
<org.mariotaku.twidere.preference.ThemedListPreference <org.mariotaku.twidere.preference.EntrySummaryListPreference
android:defaultValue="@string/default_tab_display_option" android:defaultValue="@string/default_tab_display_option"
android:entries="@array/entries_tab_display_option" android:entries="@array/entries_tab_display_option"
android:entryValues="@array/values_tab_display_option" android:entryValues="@array/values_tab_display_option"

View File

@ -5,7 +5,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:title="@string/theme"> android:title="@string/theme">
<org.mariotaku.twidere.preference.ThemedListPreference <org.mariotaku.twidere.preference.EntrySummaryListPreference
android:defaultValue="light" android:defaultValue="light"
android:entries="@array/entries_theme" android:entries="@array/entries_theme"
android:entryValues="@array/values_theme" android:entryValues="@array/values_theme"
@ -15,7 +15,7 @@
<extra <extra
android:name="recreate_activity" android:name="recreate_activity"
android:value="true"/> android:value="true"/>
</org.mariotaku.twidere.preference.ThemedListPreference> </org.mariotaku.twidere.preference.EntrySummaryListPreference>
<org.mariotaku.twidere.preference.ThemeBackgroundPreference <org.mariotaku.twidere.preference.ThemeBackgroundPreference
android:defaultValue="default" android:defaultValue="default"