-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from YuS1aN/dev
merge
- Loading branch information
Showing
26 changed files
with
266 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package me.kbai.zhenxunui.model | ||
|
||
data class GetSqlLog( | ||
val index: Int = 1, | ||
val size: Int = 5 | ||
) { | ||
companion object { | ||
val DEFAULT = GetSqlLog() | ||
} | ||
} |
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,6 @@ | ||
package me.kbai.zhenxunui.model | ||
|
||
data class SqlLogPage( | ||
val total: Int, | ||
val data: List<SqlLog> | ||
) |
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
88 changes: 88 additions & 0 deletions
88
app/src/main/java/me/kbai/zhenxunui/ui/db/SqlLogPopupWindow.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,88 @@ | ||
package me.kbai.zhenxunui.ui.db | ||
|
||
import android.view.Gravity | ||
import android.view.View | ||
import android.view.ViewGroup.LayoutParams | ||
import android.view.WindowManager | ||
import android.view.inputmethod.InputMethodManager | ||
import android.widget.ArrayAdapter | ||
import android.widget.PopupWindow | ||
import androidx.core.view.isVisible | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.viewModels | ||
import androidx.lifecycle.Observer | ||
import me.kbai.zhenxunui.R | ||
import me.kbai.zhenxunui.databinding.PopupSqlLogBinding | ||
import me.kbai.zhenxunui.model.SqlLog | ||
import me.kbai.zhenxunui.viewmodel.SqlLogViewModel | ||
|
||
|
||
class SqlLogPopupWindow(host: Fragment) : PopupWindow( | ||
View.inflate(host.requireContext(), R.layout.popup_sql_log, null) | ||
) { | ||
private val mBinding = PopupSqlLogBinding.bind(contentView) | ||
private val mViewModel by host.viewModels<SqlLogViewModel>() | ||
|
||
private val mObserver: Observer<List<SqlLog>> | ||
|
||
private val mWindowManager = host.requireActivity().windowManager | ||
|
||
private var mOnItemSelectedListener: ((SqlLogPopupWindow, SqlLog) -> Unit)? = null | ||
|
||
init { | ||
isFocusable = true | ||
isOutsideTouchable = true | ||
animationStyle = R.style.PopupAnim | ||
|
||
mObserver = Observer { list -> | ||
mBinding.lvSql.apply { | ||
adapter = ArrayAdapter( | ||
mBinding.root.context, R.layout.item_sql_log, 0, list.map { it.sql } | ||
) | ||
setOnItemClickListener { _, _, position, _ -> | ||
mOnItemSelectedListener?.invoke(this@SqlLogPopupWindow, list[position]) | ||
} | ||
} | ||
mBinding.pbWaiting.isVisible = false | ||
} | ||
mViewModel.logs.observeForever(mObserver) | ||
} | ||
|
||
fun setOnItemSelectedListener(listener: (popup: SqlLogPopupWindow, sqlLog: SqlLog) -> Unit): SqlLogPopupWindow { | ||
mOnItemSelectedListener = listener | ||
return this | ||
} | ||
|
||
fun show(anchor: View) { | ||
anchor.context.getSystemService(InputMethodManager::class.java) | ||
.hideSoftInputFromWindow(anchor.windowToken, 0) | ||
|
||
width = anchor.width | ||
height = LayoutParams.WRAP_CONTENT | ||
showAsDropDown(anchor, 0, 0, Gravity.BOTTOM) | ||
|
||
val container: View = contentView.parent.let { | ||
if (it is View) it else contentView | ||
} | ||
val params = (container.layoutParams as WindowManager.LayoutParams).apply { | ||
flags = flags or WindowManager.LayoutParams.FLAG_DIM_BEHIND | ||
dimAmount = 0.1f | ||
} | ||
mWindowManager.updateViewLayout(container, params) | ||
} | ||
|
||
override fun dismiss() { | ||
mViewModel.logs.removeObserver(mObserver) | ||
|
||
val container: View = contentView.parent.let { | ||
if (it is View) it else contentView | ||
} | ||
val params = (container.layoutParams as WindowManager.LayoutParams).apply { | ||
flags = flags and WindowManager.LayoutParams.FLAG_DIM_BEHIND.inv() | ||
dimAmount = 0f | ||
} | ||
mWindowManager.updateViewLayout(container, params) | ||
|
||
super.dismiss() | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
app/src/main/java/me/kbai/zhenxunui/viewmodel/SqlLogViewModel.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,30 @@ | ||
package me.kbai.zhenxunui.viewmodel | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import kotlinx.coroutines.launch | ||
import me.kbai.zhenxunui.extends.apiCollect | ||
import me.kbai.zhenxunui.model.SqlLog | ||
import me.kbai.zhenxunui.repository.ApiRepository | ||
import me.kbai.zhenxunui.tool.GlobalToast | ||
|
||
class SqlLogViewModel : ViewModel() { | ||
private val _logs: MutableLiveData<List<SqlLog>> = MutableLiveData() | ||
val logs: LiveData<List<SqlLog>> = _logs | ||
|
||
init { | ||
requestSqlLog() | ||
} | ||
|
||
fun requestSqlLog() = viewModelScope.launch { | ||
ApiRepository.getSqlLog().apiCollect { | ||
if (it.success() && it.data != null) { | ||
_logs.value = it.data.data | ||
} else { | ||
GlobalToast.showToast(it.message) | ||
} | ||
} | ||
} | ||
} |
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"?> | ||
<scale xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:duration="200" | ||
android:fromXScale="1.0" | ||
android:fromYScale="0.0" | ||
android:pivotX="50" | ||
android:pivotY="0" | ||
android:toXScale="1.0" | ||
android:toYScale="1.0" /> |
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"?> | ||
<scale xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:duration="200" | ||
android:fromXScale="1.0" | ||
android:fromYScale="1.0" | ||
android:pivotX="50" | ||
android:pivotY="0" | ||
android:toXScale="1.0" | ||
android:toYScale="0.0" /> |
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,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<solid android:color="@color/dn_white_gray" /> | ||
<corners | ||
android:bottomLeftRadius="@dimen/list_item_round" | ||
android:bottomRightRadius="@dimen/list_item_round" /> | ||
</shape> |
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.