Skip to content

Commit

Permalink
add support for listview
Browse files Browse the repository at this point in the history
  • Loading branch information
xyczero committed Nov 27, 2016
1 parent fe75703 commit 9810abf
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 10 deletions.
26 changes: 26 additions & 0 deletions magicasakura/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/xyczero/xyczero/android-sdk-macosx/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

-keepnames class android.widget.AbsListView{
android.widget.AbsListView$RecycleBin mRecycler;
}

-keepnames class android.widget.AbsListView$RecycleBin{
void clear();
}

-keepnames class android.support.v7.widget.RecyclerView{
android.support.v7.widget.RecyclerView$Recycler mRecycler;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ private static TypedValue getTypedValue() {
public static boolean isSkipAnimatedSelector() {
if (!hasRecordedVersion) {
final String sdkVersion = Build.VERSION.RELEASE;
isSkipAnimatedSelector = !Build.UNKNOWN.equals(sdkVersion) && "5.0".compareTo(sdkVersion) <= 0 && "5.1".compareTo(sdkVersion) >0;
isSkipAnimatedSelector = !Build.UNKNOWN.equals(sdkVersion) && "5.0".compareTo(sdkVersion) <= 0 && "5.1".compareTo(sdkVersion) > 0;
hasRecordedVersion = true;
}
return isSkipAnimatedSelector;
Expand Down Expand Up @@ -417,8 +417,10 @@ public static void refreshUI(Context context, ExtraRefreshable extraRefreshable)
}
}

private static Field mRecycler;
private static Method mClearMethod;
private static Field sRecycler;
private static Method sRecycleViewClearMethod;
private static Field sRecyclerBin;
private static Method sListViewClearMethod;

private static void refreshView(View view, ExtraRefreshable extraRefreshable) {
if (view == null) return;
Expand All @@ -436,6 +438,28 @@ private static void refreshView(View view, ExtraRefreshable extraRefreshable) {
extraRefreshable.refreshSpecificView(view);
}
if (view instanceof AbsListView) {
try {
if (sRecyclerBin == null) {
sRecyclerBin = AbsListView.class.getDeclaredField("mRecycler");
sRecyclerBin.setAccessible(true);
}
if (sListViewClearMethod == null) {
sListViewClearMethod = Class.forName("android.widget.AbsListView$RecycleBin")
.getDeclaredMethod("clear");
sListViewClearMethod.setAccessible(true);
}
sListViewClearMethod.invoke(sRecyclerBin.get(view));
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
ListAdapter adapter = ((AbsListView) view).getAdapter();
while (adapter instanceof WrapperListAdapter) {
adapter = ((WrapperListAdapter) adapter).getWrappedAdapter();
Expand All @@ -446,16 +470,16 @@ private static void refreshView(View view, ExtraRefreshable extraRefreshable) {
}
if (view instanceof RecyclerView) {
try {
if (mRecycler == null) {
mRecycler = RecyclerView.class.getDeclaredField("mRecycler");
mRecycler.setAccessible(true);
if (sRecycler == null) {
sRecycler = RecyclerView.class.getDeclaredField("mRecycler");
sRecycler.setAccessible(true);
}
if (mClearMethod == null) {
mClearMethod = Class.forName("android.support.v7.widget.RecyclerView$Recycler")
if (sRecycleViewClearMethod == null) {
sRecycleViewClearMethod = Class.forName("android.support.v7.widget.RecyclerView$Recycler")
.getDeclaredMethod("clear");
mClearMethod.setAccessible(true);
sRecycleViewClearMethod.setAccessible(true);
}
mClearMethod.invoke(mRecycler.get(view));
sRecycleViewClearMethod.invoke(sRecycler.get(view));
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
Expand Down

0 comments on commit 9810abf

Please sign in to comment.