-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ea14cb
commit b7057fd
Showing
15 changed files
with
330 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
app/src/main/java/com/werb/moretype/diff/DiffDataActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package com.werb.moretype.diff | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.support.v7.app.AppCompatActivity | ||
import android.support.v7.widget.LinearLayoutManager | ||
import android.view.View | ||
import android.widget.AdapterView | ||
import com.werb.library.MoreAdapter | ||
import com.werb.library.link.RegisterItem | ||
import com.werb.moretype.R | ||
import com.werb.moretype.TitleViewHolder | ||
import com.werb.moretype.anim.AnimViewHolder | ||
import com.werb.moretype.complete.CompleteViewHolder | ||
import com.werb.moretype.data.DataServer | ||
import com.werb.moretype.main.MainCard | ||
import kotlinx.android.synthetic.main.activity_diff.* | ||
import android.support.v7.widget.DefaultItemAnimator | ||
|
||
|
||
|
||
/** | ||
* Created by wanbo on 2017/12/19. | ||
*/ | ||
class DiffDataActivity : AppCompatActivity() { | ||
|
||
private val adapter = MoreAdapter() | ||
private val newList = mutableListOf<Any>() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_diff) | ||
|
||
toolbar.setNavigationIcon(R.mipmap.ic_close_white_24dp) | ||
toolbar.setNavigationOnClickListener { finish() } | ||
|
||
diff_list.layoutManager = LinearLayoutManager(this) | ||
adapter.apply { | ||
userSoleRegister() | ||
register(RegisterItem(R.layout.item_view_title, TitleViewHolder::class.java)) | ||
register(RegisterItem(R.layout.item_view_anim, AnimViewHolder::class.java)) | ||
register(RegisterItem(R.layout.item_view_complete, CompleteViewHolder::class.java)) | ||
attachTo(diff_list) | ||
} | ||
|
||
adapter.loadData(MainCard("Diff Data", "Diff data when refresh and loadMore")) | ||
adapter.loadData(DataServer.getDiffData1()) | ||
(diff_list.itemAnimator as DefaultItemAnimator).supportsChangeAnimations = false | ||
|
||
//refresh | ||
refresh.setOnRefreshListener { | ||
adapter.refresh(1, newList, DiffDataCallback::class.java) | ||
refresh.isRefreshing = false | ||
} | ||
|
||
spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { | ||
|
||
override fun onNothingSelected(p0: AdapterView<*>?) { | ||
|
||
} | ||
|
||
override fun onItemSelected(p0: AdapterView<*>?, view: View?, position: Int, p3: Long) { | ||
when (position) { | ||
0 -> { | ||
newList.clear() | ||
newList.addAll(DataServer.getDiffData1()) | ||
} | ||
1 -> { | ||
newList.clear() | ||
newList.addAll(DataServer.getDiffData2()) | ||
} | ||
2 -> { | ||
newList.clear() | ||
newList.addAll(DataServer.getDiffData3()) | ||
} | ||
3 -> { | ||
newList.clear() | ||
newList.addAll(adapter.list.subList(1, adapter.itemCount)) | ||
} | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
companion object { | ||
fun startActivity(activity: Activity) { | ||
activity.startActivity(Intent(activity, DiffDataActivity::class.java)) | ||
} | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
app/src/main/java/com/werb/moretype/diff/DiffDataCallback.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.werb.moretype.diff | ||
|
||
import com.werb.library.link.XDiffCallback | ||
import com.werb.moretype.anim.AnimType | ||
import com.werb.moretype.complete.Complete | ||
import com.werb.moretype.main.MainCard | ||
|
||
/** | ||
* Created by wanbo on 2017/12/19. | ||
*/ | ||
class DiffDataCallback(oldItem: List<Any>, newItem: List<Any>) : XDiffCallback(oldItem, newItem) { | ||
|
||
override fun getOldListSize(): Int = oldItem.size | ||
|
||
override fun getNewListSize(): Int = newItem.size | ||
|
||
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { | ||
val old = oldItem[oldItemPosition] | ||
val new = newItem[newItemPosition] | ||
if (old is Complete && new is Complete) { | ||
return old.name == new.name | ||
} else if (old is AnimType && new is AnimType) { | ||
return old.title == new.title | ||
} else if (old is MainCard && new is MainCard) { | ||
return old.cardTitle == new.cardTitle | ||
} | ||
|
||
return false | ||
} | ||
|
||
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { | ||
val old = oldItem[oldItemPosition] | ||
val new = newItem[newItemPosition] | ||
if (old is Complete && new is Complete) { | ||
return old.desc == new.desc | ||
} else if (old is AnimType && new is AnimType) { | ||
return old.thumb == new.thumb | ||
} else if (old is MainCard && new is MainCard) { | ||
return old.cardDesc == new.cardDesc | ||
} | ||
|
||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@color/colorBackground" | ||
android:orientation="vertical"> | ||
|
||
<android.support.design.widget.AppBarLayout | ||
android:id="@+id/appbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="?attr/actionBarSize" | ||
app:elevation="0dp"> | ||
|
||
<RelativeLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<android.support.v7.widget.Toolbar | ||
android:id="@+id/toolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="?attr/actionBarSize" | ||
android:background="@color/colorPrimary"/> | ||
|
||
<Spinner | ||
android:id="@+id/spinner" | ||
android:layout_width="wrap_content" | ||
android:layout_height="match_parent" | ||
android:layout_centerVertical="true" | ||
android:layout_alignParentRight="true" | ||
android:theme="@style/SpinnerStyle" | ||
android:entries="@array/DiffData"/> | ||
|
||
</RelativeLayout> | ||
|
||
</android.support.design.widget.AppBarLayout> | ||
|
||
<android.support.v4.widget.SwipeRefreshLayout | ||
android:id="@+id/refresh" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<android.support.v7.widget.RecyclerView | ||
android:id="@+id/diff_list" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@color/colorTextLight" /> | ||
</android.support.v4.widget.SwipeRefreshLayout> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.