Skip to content

Commit 9852acd

Browse files
committed
新增功能
1 parent 5e0d39e commit 9852acd

25 files changed

Lines changed: 1687 additions & 14 deletions
-8 Bytes
Binary file not shown.

‎.idea/codeStyles/Project.xml‎

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/dbnavigator.xml‎

Lines changed: 456 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/misc.xml‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎app/build.gradle‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ dependencies {
5050
implementation 'com.android.support:appcompat-v7:27.1.1'
5151
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
5252
implementation 'org.litepal.android:kotlin:3.0.0'
53+
debugImplementation 'com.amitshekhar.android:debug-db:1.0.6'
5354
testImplementation 'junit:junit:4.12'
5455
implementation project(':base-libs')
5556
}

‎app/src/main/assets/litepal.xml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
For example:
2020
<version value="1" />
2121
-->
22-
<version value="1"/>
22+
<version value="2"/>
2323

2424
<!--
2525
Define your models in the list with mapping tag, LitePal will
@@ -34,6 +34,7 @@
3434
<list>
3535
<mapping class="com.tw.example.db.Album"/>
3636
<mapping class="com.tw.example.db.Song"/>
37+
<mapping class="com.tw.example.db.Person"/>
3738
</list>
3839

3940
<!--

‎app/src/main/java/com/tw/example/data/entity/PageBean.kt‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ open class PageBean {
66
var isRefresh = true
77
set(refresh) {
88
field = refresh
9-
if (isRefresh)
10-
pageIndex = 1
9+
pageIndex = if (isRefresh)
10+
1
1111
else
12-
pageIndex = ++pageIndex
12+
++pageIndex
1313
}
1414
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.tw.example.db
2+
3+
import org.litepal.annotation.Column
4+
import org.litepal.crud.LitePalSupport
5+
6+
class Person : LitePalSupport() {
7+
@Column(unique = true, defaultValue = "unknown")
8+
var name: String? = null
9+
10+
var price: Int = 0
11+
}

‎app/src/main/java/com/tw/example/ui/details/DetailsActivity.kt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.tw.baselibs.base.BaseActivity
44
import com.tw.example.R
55
import com.tw.example.data.entity.TestEntity
66
import com.tw.example.databinding.ActivityDetailsBinding
7+
import com.tw.example.ui.main.MainActivity.Companion.DATA_DETAILS
78
import kotlinx.android.synthetic.main.activity_details.*
89

910
class DetailsActivity : BaseActivity<DetailsPresenter, ActivityDetailsBinding>() {
@@ -17,7 +18,7 @@ class DetailsActivity : BaseActivity<DetailsPresenter, ActivityDetailsBinding>()
1718
}
1819

1920
override fun initData() {
20-
var testEntity = intent.getParcelableExtra<TestEntity>("dataDetails")
21+
var testEntity = intent.getParcelableExtra<TestEntity>(DATA_DETAILS)
2122
mViewDataBinding.testEntity = testEntity
2223
}
2324

‎app/src/main/java/com/tw/example/ui/main/MainActivity.kt‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.tw.example.ui.main
33
import android.databinding.ViewDataBinding
44
import android.os.Bundle
55
import android.support.v7.widget.LinearLayoutManager
6+
import com.amitshekhar.DebugDB
67
import com.blankj.utilcode.util.ToastUtils
78
import com.tw.baselibs.base.BaseActivity
89
import com.tw.baselibs.widget.RecyclerViewDivider
@@ -12,8 +13,14 @@ import com.tw.example.data.entity.TestEntity
1213
import com.tw.example.db.Album
1314
import com.tw.example.ui.details.DetailsActivity
1415
import kotlinx.android.synthetic.main.activity_main.*
16+
import org.litepal.LitePal
17+
import org.litepal.extension.findAll
1518

1619
class MainActivity : BaseActivity<MainPresenter, ViewDataBinding>(), MainContract.View {
20+
companion object {
21+
const val DATA_DETAILS = "dataDetails"
22+
const val IS_INIT_DATA = "isInitData"
23+
}
1724

1825
private val dataAdapter by lazy { DataAdapter() }
1926
private val queryWhere by lazy { QueryWhere() }
@@ -34,11 +41,10 @@ class MainActivity : BaseActivity<MainPresenter, ViewDataBinding>(), MainContrac
3441

3542
override fun initData() {
3643
mPresenter?.requestTestData(queryWhere)
44+
var allAlbums = LitePal.findAll<Album>()
45+
ToastUtils.showShort("${allAlbums?.size}")
3746

38-
val album = Album()
39-
album.name = "龙卷风"
40-
album.price = 10.9F
41-
album.saveAsync().listen { success -> if (success) ToastUtils.showShort("成功") else ToastUtils.showShort("失败") }
47+
ToastUtils.showShort(DebugDB.getAddressLog())
4248
}
4349

4450
override fun initListener() {
@@ -50,9 +56,9 @@ class MainActivity : BaseActivity<MainPresenter, ViewDataBinding>(), MainContrac
5056
queryWhere.isRefresh = false
5157
mPresenter?.requestTestData(queryWhere)
5258
}, rvDataList)
53-
dataAdapter.setOnItemClickListener { adapter, view, position ->
54-
var bundle = Bundle()
55-
bundle.putParcelable("dataDetails", dataAdapter.getItem(position))
59+
dataAdapter.setOnItemClickListener { _, _, position ->
60+
val bundle = Bundle()
61+
bundle.putParcelable(DATA_DETAILS, dataAdapter.getItem(position))
5662
startActivity(DetailsActivity::class.java, bundle)
5763
}
5864
}

0 commit comments

Comments
 (0)