Skip to content

Commit

Permalink
🎨 ui大改,支持夜间模式
Browse files Browse the repository at this point in the history
  • Loading branch information
Szzrain committed Mar 18, 2023
1 parent 2b3417e commit ba0e154
Show file tree
Hide file tree
Showing 25 changed files with 202 additions and 46 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "com.sealdice.dice"
minSdk 26
targetSdk 28
versionCode 19
versionName "0.3.2-rc"
versionCode 20
versionName "0.4.0-rc"

testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
Expand Down
62 changes: 46 additions & 16 deletions app/src/main/java/com/sealdice/dice/FirstFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.net.Uri
import android.os.Bundle
import android.util.Log
Expand All @@ -16,6 +17,7 @@ import androidx.core.app.ActivityCompat.finishAffinity
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.preference.PreferenceManager
import com.google.android.material.snackbar.Snackbar
import com.sealdice.dice.common.ExtractAssets
import com.sealdice.dice.common.FileWrite
import com.sealdice.dice.databinding.FragmentFirstBinding
Expand Down Expand Up @@ -52,7 +54,14 @@ class FirstFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
var isrun = false
val packageManager = this.activity?.packageManager
val packageName = this.activity?.packageName
val packageInfo = packageName?.let { packageManager?.getPackageInfo(it, 0) }
val versionName = packageInfo?.versionName
val sharedPreferences = context?.let { PreferenceManager.getDefaultSharedPreferences(it) }
val nightModeFlags = context?.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK)
val isNightMode = nightModeFlags == Configuration.UI_MODE_NIGHT_YES
binding.textviewFirst.text = StringBuilder(binding.textviewFirst.text).append("\nApp Version: $versionName")
binding.buttonThird.setOnClickListener {
val address = sharedPreferences?.getString("ui_address", "http://127.0.0.1:3211")
if (sharedPreferences?.getBoolean("use_internal_webview", true) == true) {
Expand All @@ -74,7 +83,7 @@ class FirstFragment : Fragment() {
binding.buttonConsole.setOnClickListener {
val alertDialogBuilder = context?.let { it1 ->
AlertDialog.Builder(
it1
it1, R.style.Theme_Mshell_DialogOverlay
)
}
alertDialogBuilder?.setTitle("控制台")
Expand All @@ -86,17 +95,21 @@ class FirstFragment : Fragment() {
binding.buttonReset.setOnClickListener {
val alertDialogBuilder = context?.let { it1 ->
AlertDialog.Builder(
it1
it1, R.style.Theme_Mshell_DialogOverlay
)
}
alertDialogBuilder?.setTitle("警告")
alertDialogBuilder?.setMessage("此操作将抹除本地存储的所有数据并且无法恢复\n如果你不明白此按钮的作用请点取消\n返回请按”取消“ 继续请按”确定“")
alertDialogBuilder?.setNegativeButton("取消") {_: DialogInterface, _: Int ->}
alertDialogBuilder?.setPositiveButton("确定") { _: DialogInterface, _: Int ->
context?.let { it1 -> FileWrite.getPrivateFileDir(it1)+"sealdice/" }?.let { it2 -> delete(it2) }
Toast.makeText(
context, "清除成功", Toast.LENGTH_SHORT
).show()
context?.let { it1 ->
this.view?.let { it2 ->
Snackbar.make(
it1, it2,"清除成功", Toast.LENGTH_SHORT
).show()
}
}
}

alertDialogBuilder?.create()?.show()
Expand All @@ -107,7 +120,7 @@ class FirstFragment : Fragment() {
context?.let { it1 -> ContextCompat.checkSelfPermission(it1, Manifest.permission.WRITE_EXTERNAL_STORAGE) }
if (permissionState == PackageManager.PERMISSION_GRANTED) {
// Toast.makeText(context, "已授权!", Toast.LENGTH_LONG).show()
val builder: AlertDialog.Builder? = context?.let { it1 -> AlertDialog.Builder(it1) }
val builder: AlertDialog.Builder? = context?.let { it1 -> AlertDialog.Builder(it1, R.style.Theme_Mshell_DialogOverlay) }
builder?.setCancelable(false) // if you want user to wait for some process to finish,
builder?.setView(R.layout.layout_loading_dialog)
val dialog = builder?.create()
Expand All @@ -119,7 +132,7 @@ class FirstFragment : Fragment() {
dialog?.dismiss()
val alertDialogBuilder = context?.let { it1 ->
AlertDialog.Builder(
it1
it1, R.style.Theme_Mshell_DialogOverlay
)
}
alertDialogBuilder?.setTitle("提示")
Expand All @@ -130,7 +143,14 @@ class FirstFragment : Fragment() {
}
}
} else {
Toast.makeText(context, "未获得文件权限!", Toast.LENGTH_LONG).show()
// Toast.makeText(context, "未获得文件权限!", Toast.LENGTH_LONG).show()
this.view?.let { it2 ->
context?.let { it1 ->
Snackbar.make(
it1, it2,"未获得文件权限!", Toast.LENGTH_SHORT
).show()
}
}
this.activity?.let { it1 -> ActivityCompat.requestPermissions(it1, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.READ_EXTERNAL_STORAGE), 1) }
val alertDialogBuilder = context?.let { it1 ->
AlertDialog.Builder(
Expand All @@ -146,7 +166,7 @@ class FirstFragment : Fragment() {
binding.buttonInput.setOnClickListener {
val alertDialogBuilder = context?.let { it1 ->
AlertDialog.Builder(
it1
it1, R.style.Theme_Mshell_DialogOverlay
)
}
alertDialogBuilder?.setTitle("警告")
Expand All @@ -173,17 +193,27 @@ class FirstFragment : Fragment() {
}
dialog?.dismiss()
withContext(Dispatchers.Main) {
Toast.makeText(
context, "导入了${FileWrite.FileCount}个文件", Toast.LENGTH_LONG
).show()
// Toast.makeText(
// context, "导入了${FileWrite.FileCount}个文件", Toast.LENGTH_LONG
// ).show()
context?.let { it1 ->
Snackbar.make(
it1, view,"导入了${FileWrite.FileCount}个文件", Toast.LENGTH_SHORT
).show()
}
}
}
} else {
Toast.makeText(context, "未获得文件权限!", Toast.LENGTH_LONG).show()
// Toast.makeText(context, "未获得文件权限!", Toast.LENGTH_LONG).show()
context?.let { it1 ->
Snackbar.make(
it1, view,"未获得文件权限!", Toast.LENGTH_SHORT
).show()
}
this.activity?.let { it1 -> ActivityCompat.requestPermissions(it1, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.READ_EXTERNAL_STORAGE), 1) }
val alertDialogBuilder2 = context?.let { it1 ->
AlertDialog.Builder(
it1
it1, R.style.Theme_Mshell_DialogOverlay
)
}
alertDialogBuilder2?.setTitle("提示")
Expand All @@ -200,7 +230,7 @@ class FirstFragment : Fragment() {
shellLogs += "sealdice is running"
val alertDialogBuilder = context?.let { it1 ->
AlertDialog.Builder(
it1
it1, R.style.Theme_Mshell_DialogOverlay
)
}
alertDialogBuilder?.setTitle("提示")
Expand All @@ -225,7 +255,7 @@ class FirstFragment : Fragment() {
if (!launchAliveService(context)) {
val alertDialogBuilder = context?.let { it1 ->
AlertDialog.Builder(
it1
it1, R.style.Theme_Mshell_DialogOverlay
)
}
alertDialogBuilder?.setTitle("提示")
Expand Down
17 changes: 10 additions & 7 deletions app/src/main/java/com/sealdice/dice/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.sealdice.dice

import android.content.Intent
import android.graphics.Color
import android.net.Uri
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.MenuItemCompat
import androidx.core.view.forEach
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
Expand Down Expand Up @@ -38,7 +43,6 @@ class MainActivity : AppCompatActivity() {
QbSdk.initTbsSettings(map)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

setSupportActionBar(binding.toolbar)
val packageManager = this.packageManager
val packageName = this.packageName
Expand All @@ -47,12 +51,11 @@ class MainActivity : AppCompatActivity() {
val navController = findNavController(R.id.nav_host_fragment_content_main)
appBarConfiguration = AppBarConfiguration(navController.graph)
setupActionBarWithNavController(navController, appBarConfiguration)
binding.fab.setOnClickListener { view ->
Snackbar.make(view, "SealDice for Android $versionName\nSpecial Thanks: 木末君(logs404)", Snackbar.LENGTH_LONG)
.setAction("Action", null).show()
// ExtractAssets(this).extractResources("sealdice")
}

// binding.fab.setOnClickListener { view ->
// Snackbar.make(view, "SealDice for Android $versionName\nSpecial Thanks: 木末君(logs404)", Snackbar.LENGTH_LONG)
// .setAction("Action", null).show()
//// ExtractAssets(this).extractResources("sealdice")
// }

}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/sealdice/dice/NotificationService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.sealdice.dice
import android.app.*
import android.content.Context
import android.content.Intent
import android.graphics.drawable.Icon
import android.os.IBinder


Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/com/sealdice/dice/SettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ package com.sealdice.dice

import android.content.SharedPreferences
import android.os.Bundle

import android.widget.SeekBar
import android.widget.SeekBar.OnSeekBarChangeListener
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SeekBarPreference


class SettingsFragment : PreferenceFragmentCompat() {
private lateinit var sharedPreferences: SharedPreferences
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.prefrences, rootKey)
sharedPreferences = preferenceScreen.sharedPreferences!!
val mySeekBarPreference : SeekBarPreference? = findPreference<SeekBarPreference>("launch_waiting_time")
}
}
2 changes: 0 additions & 2 deletions app/src/main/java/com/sealdice/dice/utils/ViewModelMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package com.sealdice.dice.utils
import androidx.lifecycle.MutableLiveData

object ViewModelMain {
var isShowWindow = MutableLiveData<Boolean>()
//悬浮窗口创建 移除

var isShowSuspendWindow = MutableLiveData<Boolean>()

//悬浮窗口显示 隐藏
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/btn_normal.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<!-- 圆角的半径 -->
<corners android:radius="10dp"/>

<!-- 填充颜色 -->
<solid android:color="@color/grey_white_light"/>

</shape>
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/btn_normal_dark.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<!-- 圆角的半径 -->
<corners android:radius="10dp"/>

<!-- 填充颜色 -->
<solid android:color="@color/grey_light"/>

</shape>
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/btn_pressed.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<!-- 圆角的半径 -->
<corners android:radius="10dp"/>

<!-- 填充颜色 -->
<solid android:color="@color/grey_white_light_pressed"/>

</shape>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/btn_pressed_dark.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<!-- 圆角的半径 -->
<corners android:radius="10dp"/>

<!-- 填充颜色 -->
<solid android:color="@color/grey"/>

</shape>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/btn_select.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/btn_normal" android:state_pressed="false"/>
<item android:drawable="@drawable/btn_pressed" android:state_pressed="true"/>
</selector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/btn_select_dark.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/btn_normal_dark" android:state_pressed="false"/>
<item android:drawable="@drawable/btn_pressed_dark" android:state_pressed="true"/>
</selector>
Binary file added app/src/main/res/drawable/ic_settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/ic_settings_black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 10 additions & 9 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/backgroundColor"
tools:context=".MainActivity">

<com.google.android.material.appbar.AppBarLayout
Expand All @@ -16,19 +17,19 @@
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/Theme.Mshell.PopupOverlay" />
app:popupTheme="@style/Theme.Mshell" />

</com.google.android.material.appbar.AppBarLayout>

<include layout="@layout/content_main" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginEnd="@dimen/fab_margin"
android:layout_marginBottom="16dp"
app:srcCompat="@android:drawable/ic_dialog_email" />
<!-- <com.google.android.material.floatingactionbutton.FloatingActionButton-->
<!-- android:id="@+id/fab"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_gravity="bottom|end"-->
<!-- android:layout_marginEnd="@dimen/fab_margin"-->
<!-- android:layout_marginBottom="16dp"-->
<!-- app:srcCompat="@android:drawable/ic_dialog_info" />-->

</androidx.coordinatorlayout.widget.CoordinatorLayout>
Loading

0 comments on commit ba0e154

Please sign in to comment.