Skip to content

Commit

Permalink
Fixed issue in Android API >= 25 causing widget listview to scroll to…
Browse files Browse the repository at this point in the history
… top when unintended.

This seems to be caused by behaviour changes in appwidget which are causing the setScrollPosition value
to be persisted across remote view updates. Since this value was only ever set to 0 when a widget feed
refresh was performed, this caused the unintended scrolling behaviour after the first refresh of the feed.
To work around this I replaced setScrollPosition(0) to setRelativeScrollPosition(-1000000) and added
calls to reset the relative position before each call to  notifyAppWidgetViewDataChanged.
  • Loading branch information
micwallace committed Dec 27, 2017
1 parent 58c6cd5 commit 33543a4
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 18 deletions.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Aug 23 19:41:13 AEST 2016
#Fri May 12 22:39:21 AEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
6 changes: 3 additions & 3 deletions reddinator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ android {


dependencies {
compile 'com.android.support:support-v4:25.1.0'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'com.joanzapata.android:android-iconify:1.0.11'
Expand All @@ -60,5 +60,5 @@ dependencies {
compile 'com.sothree.slidinguppanel:library:3.3.1'
compile 'com.gu:option:1.3'
compile 'net.rdrei.android.dirchooser:library:3.2@aar'
compile 'com.android.support:support-vector-drawable:25.1.0'
compile 'com.android.support:support-vector-drawable:25.3.1'
}
20 changes: 10 additions & 10 deletions reddinator/reddinator-reddinator.iml
Original file line number Diff line number Diff line change
Expand Up @@ -106,25 +106,25 @@
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="okio-1.9.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-25.1.0" level="project" />
<orderEntry type="library" exported="" name="android-iconify-1.0.11" level="project" />
<orderEntry type="library" exported="" name="HoloColorPicker-1.5" level="project" />
<orderEntry type="library" exported="" name="support-compat-25.1.0" level="project" />
<orderEntry type="library" exported="" name="support-fragment-25.1.0" level="project" />
<orderEntry type="library" exported="" name="animated-vector-drawable-25.1.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-25.1.0" level="project" />
<orderEntry type="library" exported="" name="support-core-ui-25.3.1" level="project" />
<orderEntry type="library" exported="" name="library-3.3.1" level="project" />
<orderEntry type="library" exported="" name="option-1.3" level="project" />
<orderEntry type="library" exported="" name="ckchangelog-1.2.2" level="project" />
<orderEntry type="library" exported="" name="library-3.2" level="project" />
<orderEntry type="library" exported="" name="support-v4-25.3.1" level="project" />
<orderEntry type="library" exported="" name="support-media-compat-25.3.1" level="project" />
<orderEntry type="library" exported="" name="okhttp-3.4.1" level="project" />
<orderEntry type="library" exported="" name="support-core-ui-25.1.0" level="project" />
<orderEntry type="library" exported="" name="ratethisapp-0.0.4" level="project" />
<orderEntry type="library" exported="" name="commons-lang3-3.4" level="project" />
<orderEntry type="library" exported="" name="support-media-compat-25.1.0" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-23.4.0" level="project" />
<orderEntry type="library" exported="" name="support-vector-drawable-25.1.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-25.1.0" level="project" />
<orderEntry type="library" exported="" name="support-core-utils-25.1.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-25.3.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-25.3.1" level="project" />
<orderEntry type="library" exported="" name="support-vector-drawable-25.3.1" level="project" />
<orderEntry type="library" exported="" name="support-compat-25.3.1" level="project" />
<orderEntry type="library" exported="" name="support-core-utils-25.3.1" level="project" />
<orderEntry type="library" exported="" name="support-fragment-25.3.1" level="project" />
<orderEntry type="library" exported="" name="animated-vector-drawable-25.3.1" level="project" />
</component>
</module>
Binary file modified reddinator/reddinator-release.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions reddinator/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="au.com.wallaceit.reddinator"
android:versionCode="63"
android:versionName="3.21.3">
android:versionCode="64"
android:versionName="3.21.4">

<uses-permission android:name="android.permission.INTERNET" />
<!-- Needed by some activity_webview HTML5 video implementations (Bug report received for Android 4.1) -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ public void onBackPressed() {
RemoteViews views = new RemoteViews(getPackageName(), R.layout.widget);
views.setViewVisibility(R.id.srloader, View.VISIBLE);
views.setViewVisibility(R.id.erroricon, View.INVISIBLE);
views.setRelativeScrollPosition(R.id.adapterview, 0); // Reset scroll offset for API >= 25
// bypass the cached entrys only if the sorting preference has changed
if (needsFeedUpdate) {
global.setBypassCache(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public static void showLoaderAndUpdate(Context context, int widgetId, boolean lo
views.setViewVisibility(R.id.srloader, View.VISIBLE);
views.setViewVisibility(R.id.erroricon, View.INVISIBLE); // make sure we hide the error icon
views.setTextViewText(R.id.subreddittxt, global.getSubredditManager().getCurrentFeedName(widgetId));
// In Android platform >= v25, the last relative scroll position is used, so it must be reset before each call.
views.setRelativeScrollPosition(R.id.adapterview, 0);
// load more text
if (loadmore) {
views.setTextViewText(R.id.loadmoretxt, context.getResources().getString(R.string.loading));
Expand Down Expand Up @@ -125,6 +127,7 @@ public static void showLoaderAndRefreshViews(Context context, int widgetId){
RemoteViews views = new RemoteViews(context.getPackageName(), getWidgetLayoutId(providerClass));
views.setViewVisibility(R.id.srloader, View.VISIBLE);
views.setViewVisibility(R.id.erroricon, View.INVISIBLE); // make sure we hide the error icon
views.setRelativeScrollPosition(R.id.adapterview, 0); // Reset scroll offset for API >= 25
// update view
mgr.partiallyUpdateAppWidget(widgetId, views);
}
Expand All @@ -137,6 +140,7 @@ public static void hideLoaderAndRefreshViews(Context context, int widgetId, bool
RemoteViews views = new RemoteViews(context.getPackageName(), getWidgetLayoutId(providerClass));
views.setViewVisibility(R.id.srloader, View.GONE);
views.setViewVisibility(R.id.erroricon, (showerror ? View.VISIBLE : View.GONE)); // make sure we hide the error icon
views.setRelativeScrollPosition(R.id.adapterview, 0); // Reset scroll offset for API >= 25
// update view
global.setRefreshView();
mgr.notifyAppWidgetViewDataChanged(widgetId, R.id.adapterview);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,8 @@ private void hideWidgetLoader(boolean goToTopOfList, boolean showError, final St
views.setViewVisibility(R.id.srloader, View.INVISIBLE);
// go to the top of the list view
if (providerClass==WidgetCommon.WIDGET_CLASS_LIST && goToTopOfList) {
views.setScrollPosition(R.id.adapterview, 0);
// API >= 25: Relative scroll position must be used since this value is persisted for the next update & only a relative value can be reset to keep the current position.
views.setRelativeScrollPosition(R.id.adapterview, -1000000);
}
if (showError) {
views.setViewVisibility(R.id.erroricon, View.VISIBLE);
Expand Down
3 changes: 3 additions & 0 deletions reddinator/src/main/res/xml/changelog_master.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<changelog>
<release version="3.21.4" versioncode="64">
<change>Fixed Android API >= 25 widget listview scrolling bug.</change>
</release>
<release version="3.21.3" versioncode="63">
<change>Enabled gfycat links in image preview.</change>
<change>Hid Reddit app promo banner.</change>
Expand Down

0 comments on commit 33543a4

Please sign in to comment.