81 lines
2.8 KiB
Kotlin
81 lines
2.8 KiB
Kotlin
/*
|
|
* Copyright 2016 Hippo Seven
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
package com.hippo.ehviewer.ui
|
|
|
|
import android.os.Bundle
|
|
import android.view.MenuItem
|
|
import android.widget.TextView
|
|
import androidx.annotation.StringRes
|
|
import androidx.fragment.app.FragmentTransaction
|
|
import com.google.android.material.appbar.AppBarLayout
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
|
import com.google.android.material.snackbar.Snackbar
|
|
import com.hippo.ehviewer.R
|
|
import com.hippo.ehviewer.ui.fragment.SettingsFragment
|
|
import com.hippo.ehviewer.ui.scene.BaseScene
|
|
|
|
class SettingsActivity : EhActivity() {
|
|
private var mFab: FloatingActionButton? = null
|
|
private var mContentText: TextView? = null
|
|
private var mAppbarLayout: AppBarLayout? = null
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
setContentView(R.layout.activity_preference)
|
|
setSupportActionBar(findViewById(R.id.toolbar))
|
|
mContentText = findViewById(R.id.tip)
|
|
mFab = findViewById(R.id.fab)
|
|
mAppbarLayout = findViewById(R.id.appbar)
|
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
|
if (savedInstanceState == null) {
|
|
supportFragmentManager
|
|
.beginTransaction()
|
|
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_MATCH_ACTIVITY_OPEN)
|
|
.replace(R.id.fragment, SettingsFragment())
|
|
.commitAllowingStateLoss()
|
|
}
|
|
}
|
|
|
|
fun showTip(@StringRes id: Int, length: Int) {
|
|
showTip(getString(id), length)
|
|
}
|
|
|
|
fun showTip(message: CharSequence?, length: Int) {
|
|
Snackbar.make(
|
|
findViewById(R.id.snackbar), message!!,
|
|
if (length == BaseScene.LENGTH_LONG) Snackbar.LENGTH_LONG else Snackbar.LENGTH_SHORT
|
|
).show()
|
|
}
|
|
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
if (item.itemId == android.R.id.home) {
|
|
onBackPressedDispatcher.onBackPressed()
|
|
return true
|
|
}
|
|
return super.onOptionsItemSelected(item)
|
|
}
|
|
|
|
fun getMFab(): FloatingActionButton {
|
|
return mFab!!
|
|
}
|
|
|
|
fun getMContentText(): TextView {
|
|
return mContentText!!
|
|
}
|
|
|
|
fun resetAppbarLiftStatus() {
|
|
mAppbarLayout?.setExpanded(true)
|
|
}
|
|
} |