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

UI improvement. #161

Merged
merged 4 commits into from
May 4, 2022
Merged
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
2 changes: 2 additions & 0 deletions README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<img alt="GitHub release (latest by date)" src="https://img.shields.io/github/v/release/rosuh/easywatermark">
</p>

<a href="https://app.fossa.com/projects/git%2Bgithub.com%2FrosuH%2FEasyWatermark?ref=badge_small" alt="FOSSA Status"><img src="https://app.fossa.com/api/projects/git%2Bgithub.com%2FrosuH%2FEasyWatermark.svg?type=small"/></a>

<p align="center">
安全、简单、快速地为你的敏感照片添加水印,防止被小人泄露、利用。
</br>
Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,21 @@ dependencies {
kapt("com.google.dagger:hilt-compiler:2.40.4")
implementation("com.github.bumptech.glide:glide:4.13.1")
kapt("com.github.bumptech.glide:compiler:4.13.1")
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.6.10")
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.6.20")
implementation("androidx.appcompat:appcompat:1.4.1")
implementation("id.zelory:compressor:3.0.1")
implementation("com.google.android.material:material:1.6.0-alpha03")
implementation("androidx.fragment:fragment-ktx:1.4.0")
implementation("androidx.activity:activity-ktx:1.4.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2")
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.4.0")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0")
implementation("com.github.skydoves:colorpickerview:2.2.3")
implementation("androidx.viewpager2:viewpager2:1.0.0")
implementation("androidx.recyclerview:recyclerview:1.2.1")
implementation("androidx.constraintlayout:constraintlayout:2.1.3")
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.6.10")
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.6.20")
implementation("androidx.exifinterface:exifinterface:1.3.3")
implementation("androidx.palette:palette-ktx:1.0.0")

Expand Down
80 changes: 21 additions & 59 deletions app/src/main/java/me/rosuh/easywatermark/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.content.Intent.ACTION_SEND
import android.content.Intent.ACTION_VIEW
import android.content.pm.PackageManager
import android.content.res.ColorStateList
import android.graphics.Color
Expand All @@ -26,9 +25,6 @@ import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.content.edit
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.core.view.forEach
import androidx.fragment.app.commit
import androidx.lifecycle.lifecycleScope
Expand Down Expand Up @@ -128,7 +124,7 @@ class MainActivity : AppCompatActivity() {
}

private val funcAdapter by lazy {
FuncPanelAdapter(ArrayList(styleFunList)).apply {
FuncPanelAdapter(ArrayList(contentFunList)).apply {
setHasStableIds(true)
}
}
Expand Down Expand Up @@ -224,34 +220,6 @@ class MainActivity : AppCompatActivity() {
if (MyApp.recoveryMode) {
return
}
if (hasFocus) {
hideSystemUI()
}
}

private fun hideSystemUI() {
// Enables regular immersive mode.
// For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
// Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
WindowCompat.setDecorFitsSystemWindows(window, false)
WindowInsetsControllerCompat(window, launchView).let { controller ->
controller.hide(WindowInsetsCompat.Type.systemBars())
controller.systemBarsBehavior =
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
} else {
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE
// Set the content to appear under the system bars so that the
// content doesn't resize when the system bars hide and show.
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
// Hide the nav bar and status bar
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_FULLSCREEN)
}

}

private fun registerResultCallback() {
Expand Down Expand Up @@ -391,9 +359,9 @@ class MainActivity : AppCompatActivity() {
) {
val c = it.animatedValue as Int
if (launchView.isEdit()) {
launchView.rvPanel.setBackgroundColor(it.animatedValue as Int)
setActivityBackground(c)
setStatusBarColor(c, isInEditMode = true)
doApplyBgChanged(c)
} else {
doApplyBgChanged()
}
}
funcAdapter.textColor.toColor(titleTextColor) {
Expand All @@ -418,8 +386,7 @@ class MainActivity : AppCompatActivity() {

@SuppressLint("ClickableViewAccessibility")
private fun initView() {
setActivityBackground(ContextCompat.getColor(this, R.color.md_theme_dark_background))
setStatusBarColor(ContextCompat.getColor(this, R.color.md_theme_dark_background), false)
doApplyBgChanged()
// prepare MotionLayout
launchView.setListener {
onModeChange { _, newMode ->
Expand Down Expand Up @@ -547,11 +514,10 @@ class MainActivity : AppCompatActivity() {
val adapter = (launchView.rvPanel.adapter as? FuncPanelAdapter)
when (tab.position) {
0 -> {
launchView.rvPanel.smoothScrollToPosition(0)
adapter?.also {
it.seNewData(styleFunList, 0)
post { handleFuncItem(it.dataSet[0]) }
}
val curPos =
if (launchView.ivPhoto.config?.markMode == WaterMarkRepository.MarkMode.Text) 0 else 1
adapter?.seNewData(contentFunList, curPos)
manuallySelectedItem(curPos)
}
2 -> {
launchView.rvPanel.smoothScrollToPosition(0)
Expand All @@ -561,21 +527,18 @@ class MainActivity : AppCompatActivity() {
}
}
else -> {
val curPos =
if (launchView.ivPhoto.config?.markMode == WaterMarkRepository.MarkMode.Text) 0 else 1
adapter?.seNewData(contentFunList, curPos)
manuallySelectedItem(curPos)
launchView.rvPanel.smoothScrollToPosition(0)
adapter?.also {
it.seNewData(styleFunList, 0)
post { handleFuncItem(it.dataSet[0]) }
}
}
}
}

override fun onTabUnselected(tab: TabLayout.Tab?) {}

override fun onTabReselected(tab: TabLayout.Tab?) {
val adapter = (launchView.rvPanel.adapter as? FuncPanelAdapter)
adapter?.also {
post { handleFuncItem(it.dataSet[0]) }
}
}
})
}
Expand Down Expand Up @@ -804,18 +767,17 @@ class MainActivity : AppCompatActivity() {
viewModel.clearData()
launchView.ivPhoto.reset()
bgTransformAnimator?.cancel()
(launchView.background as? ColorDrawable?)?.color?.toColor(
ContextCompat.getColor(this, R.color.md_theme_dark_background)
) {
val c = it.animatedValue as Int
setActivityBackground(c)
setStatusBarColor(c, isInEditMode = false)
}
doApplyBgChanged()
hideDetailPanel()
}

private fun setActivityBackground(color: Int) {
private fun doApplyBgChanged(color: Int = ContextCompat.getColor(this, R.color.md_theme_dark_background)) {
(launchView.parent as? View?)?.setBackgroundColor(color)
window?.navigationBarColor = Color.TRANSPARENT
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
window?.navigationBarDividerColor = Color.TRANSPARENT
}
setStatusBarColor(color, true)
}

private fun selectTab(index: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class AboutActivity : AppCompatActivity() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.setDecorFitsSystemWindows(false)
}
window?.navigationBarColor = Color.TRANSPARENT
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
window?.navigationBarDividerColor = Color.TRANSPARENT
}
}

private fun changeStatusBarStyle(color: Int = colorSurface) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ class LaunchView : CustomViewGroup {
it.text = context.getString(R.string.title_layout)
}

addTab(styleTab)
addTab(contentTab)
addTab(styleTab)
addTab(layoutTab)
}
}
Expand Down