Skip to content

Commit

Permalink
fix for store resuming pos
Browse files Browse the repository at this point in the history
  • Loading branch information
Xlythe committed May 8, 2014
1 parent f7af601 commit f762fbf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
Expand All @@ -15,6 +16,8 @@
import com.xlythe.engine.theme.App;
import com.xlythe.engine.theme.Theme;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.List;

/**
Expand Down Expand Up @@ -100,7 +103,7 @@ protected void onCancelled() {

}

public void onListItemClick(GridView g, View v, int position, long id) {
public void onListItemClick(int position) {
if (App.doesPackageExists(getContext(), mThemes.get(position).getPackageName())) {
String appName = mThemes.get(position).getPackageName();

Expand All @@ -115,7 +118,6 @@ public void onListItemClick(GridView g, View v, int position, long id) {
int itemPosition = mGridView.getFirstVisiblePosition();
View child = mGridView.getChildAt(0);
int itemOffset = child != null ? child.getTop() : 0;
itemOffset -= mGridView.getScrollY();

intent.putExtra(EXTRA_LIST_POSITION, itemPosition);
intent.putExtra(EXTRA_LIST_VIEW_OFFSET, itemOffset);
Expand All @@ -136,7 +138,7 @@ public void onListItemClick(GridView g, View v, int position, long id) {

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
onListItemClick(mGridView, mGridView.getChildAt(position), position, mGridView.getChildAt(position).getId());
onListItemClick(position);
}

@Override
Expand All @@ -147,7 +149,18 @@ public void onStart() {
final Bundle args = getArguments();
if (args != null) {
mGridView.setSelection(args.getInt(EXTRA_LIST_POSITION, 0));
mGridView.scrollBy(0, -1*args.getInt(EXTRA_LIST_VIEW_OFFSET, 0));
// Hack to scroll to the previous offset
mGridView.post(new Runnable() {
@Override
public void run() {
try {
Method m = AbsListView.class.getDeclaredMethod("trackMotionScroll", Integer.TYPE, Integer.TYPE);
m.setAccessible(true);
m.invoke(mGridView, args.getInt(EXTRA_LIST_VIEW_OFFSET, 0), args.getInt(EXTRA_LIST_VIEW_OFFSET, 0));
}
catch(Exception e){}
}
});
}
}

Expand Down
9 changes: 9 additions & 0 deletions ThemeEngine/src/main/java/com/xlythe/engine/theme/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,13 @@ public String getPackageName() {
public void setPackageName(String packageName) {
this.packageName = packageName;
}

@Override
public App clone() {
try {
return (App) super.clone();
}catch(CloneNotSupportedException e){
return null;
}
}
}

0 comments on commit f762fbf

Please sign in to comment.