-
Notifications
You must be signed in to change notification settings - Fork 1
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
83f92be
commit 27b9b13
Showing
16 changed files
with
368 additions
and
36 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
31 changes: 31 additions & 0 deletions
31
app/src/main/java/cn/jingzhuan/tableview/demo/lesson9/Lesson9Activity.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,31 @@ | ||
package cn.jingzhuan.tableview.demo.lesson9 | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.databinding.DataBindingUtil | ||
import androidx.lifecycle.ViewModelProviders | ||
import cn.jingzhuan.tableview.demo.R | ||
import cn.jingzhuan.tableview.demo.databinding.ActivityLesson9Binding | ||
|
||
class Lesson9Activity : AppCompatActivity() { | ||
|
||
private lateinit var binding: ActivityLesson9Binding | ||
private lateinit var viewModel: Lesson9ViewModel | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
title = "Lesson 9" | ||
binding = DataBindingUtil.setContentView(this, R.layout.activity_lesson_9) | ||
viewModel = ViewModelProviders.of(this)[Lesson9ViewModel::class.java] | ||
|
||
binding.tableView.updateTableSize(15, 1, 3) | ||
|
||
viewModel.liveData.observe(this) { | ||
binding.tableView.setHeaderRow(it) | ||
binding.tableView.notifyDataSetChanged() | ||
} | ||
|
||
viewModel.fetch(this, 100, 15) | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/cn/jingzhuan/tableview/demo/lesson9/Lesson9ViewColumn.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,15 @@ | ||
package cn.jingzhuan.tableview.demo.lesson9 | ||
|
||
import cn.jingzhuan.tableview.demo.R | ||
import cn.jingzhuan.tableview.demo.databinding.LayoutLesson9ViewColumnBinding | ||
import cn.jingzhuan.tableview.element.DataBindingViewColumn | ||
import cn.jingzhuan.tableview.element.Row | ||
|
||
class Lesson9ViewColumn: DataBindingViewColumn<LayoutLesson9ViewColumnBinding>() { | ||
|
||
override fun layoutId() = R.layout.layout_lesson_9_view_column | ||
|
||
override fun onBind(binding: LayoutLesson9ViewColumnBinding, row: Row<*>) { | ||
|
||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
app/src/main/java/cn/jingzhuan/tableview/demo/lesson9/Lesson9ViewModel.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,68 @@ | ||
package cn.jingzhuan.tableview.demo.lesson9 | ||
|
||
import android.content.Context | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import cn.jingzhuan.tableview.demo.elements.* | ||
import cn.jingzhuan.tableview.element.Column | ||
import io.reactivex.Flowable | ||
import io.reactivex.disposables.Disposable | ||
import io.reactivex.schedulers.Schedulers | ||
|
||
class Lesson9ViewModel : ViewModel() { | ||
|
||
val liveData = MutableLiveData<TitleRow>() | ||
private var disposable: Disposable? = null | ||
|
||
fun fetch(context: Context, rowsCount: Int, columnsCount: Int) { | ||
disposable = Flowable.fromCallable { columnsCount } | ||
.map { | ||
|
||
val titleColumns = mutableListOf<Column>() | ||
titleColumns.add(TitleHeaderColumn()) | ||
for (i in 0 until columnsCount) { | ||
val titleColumn = TitleColumn(i) | ||
when (i) { | ||
0 -> titleColumn.weight = 1 | ||
1 -> titleColumn.weight = 1 | ||
2 -> titleColumn.weight = 0 | ||
} | ||
titleColumn.rightMargin = 10 | ||
titleColumns.add(titleColumn) | ||
} | ||
val titleRow = TitleRow(titleColumns) | ||
|
||
for (rowIndex in 0 until rowsCount) { | ||
val rowColumns = mutableListOf<Column>() | ||
rowColumns.add(SimpleHeaderColumn("Row${rowIndex + 1}")) | ||
for (columnIndex in 0 until columnsCount) { | ||
if(columnIndex == 1) { | ||
val column = Lesson9ViewColumn() | ||
rowColumns.add(column) | ||
} else { | ||
val column = SimpleColumn("${rowIndex + 1} - ${columnIndex + 1}") | ||
column.leftMargin = 40 | ||
column.rightMargin = 10 | ||
rowColumns.add(column) | ||
} | ||
} | ||
titleRow.rows.add(SimpleRow(rowColumns)) | ||
} | ||
|
||
// titleRow.preMeasureAllRows(context) | ||
titleRow | ||
} | ||
.subscribeOn(Schedulers.computation()) | ||
.subscribe({ | ||
liveData.postValue(it) | ||
}, { | ||
|
||
}) | ||
} | ||
|
||
override fun onCleared() { | ||
super.onCleared() | ||
disposable?.dispose() | ||
} | ||
|
||
} |
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,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<cn.jingzhuan.tableview.TableView | ||
android:id="@+id/table_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
|
||
</layout> |
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,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="60dp" | ||
android:gravity="center_vertical" | ||
android:orientation="horizontal" | ||
tools:ignore="UseCompoundDrawables"> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginLeft="15dp" | ||
android:text="Lesson 9" | ||
tools:ignore="RtlHardcoded" /> | ||
|
||
<ImageView | ||
android:id="@+id/image_view" | ||
android:layout_width="40dp" | ||
android:layout_height="40dp" | ||
android:layout_marginLeft="8dp" | ||
android:layout_marginRight="4dp" | ||
android:src="@drawable/lion" | ||
tools:ignore="ContentDescription,RtlHardcoded" /> | ||
|
||
</LinearLayout> | ||
|
||
</layout> |
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
Oops, something went wrong.