Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在数据列表页面增加了刷新按钮 #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions glance/src/main/java/com/glance/guolindev/ui/data/DataActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import android.content.Intent
import android.graphics.Typeface
import android.os.Bundle
import android.view.Gravity
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.EditText
Expand Down Expand Up @@ -86,6 +87,11 @@ class DataActivity : AppCompatActivity() {
*/
private var editDialog: AlertDialog? = null

/**
* Prevent refreshing data frequently
*/
private var loadCompletableState = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = GlanceLibraryActivityDataBinding.inflate(layoutInflater)
Expand Down Expand Up @@ -116,6 +122,7 @@ class DataActivity : AppCompatActivity() {
binding.progressBar.visibility = View.INVISIBLE
}
viewModel.columnsLiveData.observe(this) {
loadCompletableState = true
initAdapter(table, it)
}
viewModel.updateDataLiveData.observe(this) {
Expand All @@ -134,6 +141,12 @@ class DataActivity : AppCompatActivity() {
if (viewModel.columnsLiveData.value == null) {
viewModel.getColumnsInTable(table)
}

}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.glance_menu_item, menu)
return true
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
Expand All @@ -142,6 +155,13 @@ class DataActivity : AppCompatActivity() {
finish()
return true
}
R.id.action_refresh -> {
if(loadCompletableState){
loadCompletableState = loadCompletableState.not()
viewModel.getColumnsInTable(table)
}
return true
}
}
return super.onOptionsItemSelected(item)
}
Expand Down Expand Up @@ -215,6 +235,7 @@ class DataActivity : AppCompatActivity() {
adapter.addLoadStateListener { loadState ->
when (loadState.refresh) {
is LoadState.NotLoading -> {
binding.recyclerView.scrollToPosition(0)
binding.horizontalScroller.visibility = View.VISIBLE
binding.progressBar.visibility = View.INVISIBLE
if (loadStarted) {
Expand Down Expand Up @@ -264,6 +285,7 @@ class DataActivity : AppCompatActivity() {
* Build a TableRowLayout as a row to show the columns of a table as title.
*/
private fun buildTableTitle(columns: List<Column>, rowWidth: Int) {
binding.rowTitleLayout.removeAllViews()
val param = binding.rowTitleLayout.layoutParams
param.width = rowWidth
columns.forEachIndexed { index, column ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.glance.guolindev.ui.db

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.DiffUtil
Expand Down
4 changes: 4 additions & 0 deletions glance/src/main/res/drawable/ic_glance_refresh.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<vector android:height="21.333334dp" android:viewportHeight="1024"
android:viewportWidth="1152" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFFFFFFF" android:pathData="M1034.11,515.07l0.06,-5.7C1034.24,256.77 828.67,51.2 576,51.2a456.96,456.96 0,0 0,-240 67.84,67.26 67.26,0 1,0 70.59,114.56A322.75,322.75 0,0 1,576 185.66a324.03,324.03 0,0 1,323.58 329.34h-114.5l183.49,262.72L1152,515.07h-117.89zM783.68,774.14c-13.7,0 -27.01,4.16 -38.27,11.9A322.75,322.75 0,0 1,576 833.92a324.03,324.03 0,0 1,-323.65 -329.34h114.56L183.42,241.86 0,504.58h117.89v5.7c0,252.61 205.44,458.18 458.11,458.18a456.96,456.96 0,0 0,240 -67.84,67.26 67.26,0 0,0 -32.32,-126.46z"/>
</vector>
10 changes: 10 additions & 0 deletions glance/src/main/res/menu/glance_menu_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_refresh"
android:title="Refresh"
android:icon="@drawable/ic_glance_refresh"
app:showAsAction="always" />

</menu>