Skip to content

Commit

Permalink
Complete methods
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiredPlanck committed Jun 20, 2021
1 parent bf6a97e commit 42ab107
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Expand Up @@ -64,6 +64,7 @@ dependencies {
implementation 'org.ocpsoft.prettytime:prettytime:5.0.1.Final'
implementation "androidx.core:core-ktx:1.3.2"
implementation "androidx.appcompat:appcompat:1.3.0"
implementation "androidx.preference:preference-ktx:1.1.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2'
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -31,7 +31,8 @@
<application android:label="@string/ime_name"
android:icon="@drawable/icon"
android:requestLegacyExternalStorage="true"
android:allowBackup="false" >
android:allowBackup="false"
android:theme="@style/PreferenceTheme">

<service android:name="Trime" android:label="@string/ime_name"
android:permission="android.permission.BIND_INPUT_METHOD">
Expand All @@ -40,13 +41,21 @@
</intent-filter>
<meta-data android:name="android.view.im" android:resource="@xml/method" />
</service>

<!--
<activity android:name="Pref" android:label="@string/ime_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> -->

<activity android:name=".settings.PrefMainActivity" android:label="@string/ime_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
34 changes: 33 additions & 1 deletion app/src/main/java/com/osfans/trime/settings/PrefMainActivity.kt
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import androidx.preference.PreferenceFragmentCompat
import com.osfans.trime.R
import com.osfans.trime.databinding.PrefActivityBinding

Expand All @@ -20,12 +21,43 @@ class PrefMainActivity: AppCompatActivity() {

val toolbar = findViewById<Toolbar>(R.id.toolbar)
setSupportActionBar(toolbar)

if (savedInstanceState == null) {
loadFragment(PrefFragment())
} else {
title = savedInstanceState.getCharSequence(FRAGMENT_TAG)
}
supportFragmentManager.addOnBackStackChangedListener {
if (supportFragmentManager.backStackEntryCount == 0) {
setTitle(R.string.ime_name)
}
}

supportActionBar?.setDisplayHomeAsUpEnabled(true)
}


override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putCharSequence(FRAGMENT_TAG, title)
}

override fun onSupportNavigateUp(): Boolean {
if (supportFragmentManager.popBackStackImmediate()) {
return true
}
return super.onSupportNavigateUp()
}

private fun loadFragment(fragment: Fragment) {
supportFragmentManager
.beginTransaction()
.replace(binding.preference.id, fragment, FRAGMENT_TAG)
.commit()
}

class PrefFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.prefs, rootKey)
}
}
}
9 changes: 9 additions & 0 deletions app/src/main/res/values/styles.xml
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="PreferenceTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:colorAccent" tools:targetApi="lollipop">@color/colorAccent</item>
</style>
</resources>

0 comments on commit 42ab107

Please sign in to comment.