mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-21 17:24:14 +00:00
switch spell checker settings to compose
This commit is contained in:
parent
57313a4b79
commit
6dad54b83d
8 changed files with 50 additions and 136 deletions
|
@ -92,8 +92,8 @@ SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
|
|||
</activity>
|
||||
|
||||
<activity android:name=".spellcheck.SpellCheckerSettingsActivity"
|
||||
android:theme="@style/platformActivityTheme"
|
||||
android:label="@string/android_spell_checker_settings"
|
||||
android:theme="@style/platformActivityTheme"
|
||||
android:label="@string/spell_checker_service_name"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
* modified
|
||||
* SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
|
||||
*/
|
||||
|
||||
package helium314.keyboard.latin.spellcheck;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import helium314.keyboard.latin.permissions.PermissionsManager;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
/**
|
||||
* Spell checker preference screen.
|
||||
*/
|
||||
public final class SpellCheckerSettingsActivity extends AppCompatActivity
|
||||
implements ActivityCompat.OnRequestPermissionsResultCallback {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.replace(android.R.id.content, new SpellCheckerSettingsFragment())
|
||||
.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
PermissionsManager.get(this).onRequestPermissionsResult(
|
||||
requestCode, permissions, grantResults);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
package helium314.keyboard.latin.spellcheck
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import helium314.keyboard.settings.SettingsActivity
|
||||
|
||||
// the Settings in SettingsContainer expect to be in a SettingsActivity, so we use a simple way of getting there
|
||||
class SpellCheckerSettingsActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val intent = Intent()
|
||||
intent.setClass(this, SettingsActivity::class.java)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
intent.putExtra("spellchecker", true)
|
||||
startActivity(intent)
|
||||
if (!isFinishing) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
* modified
|
||||
* SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
|
||||
*/
|
||||
|
||||
package helium314.keyboard.latin.spellcheck;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import helium314.keyboard.latin.R;
|
||||
import helium314.keyboard.latin.permissions.PermissionsManager;
|
||||
import helium314.keyboard.latin.permissions.PermissionsUtil;
|
||||
import helium314.keyboard.latin.settings.Settings;
|
||||
import helium314.keyboard.latin.settings.SubScreenFragment;
|
||||
import helium314.keyboard.latin.utils.ActivityThemeUtils;
|
||||
|
||||
/**
|
||||
* Preference screen.
|
||||
*/
|
||||
public final class SpellCheckerSettingsFragment extends SubScreenFragment
|
||||
implements SharedPreferences.OnSharedPreferenceChangeListener,
|
||||
PermissionsManager.PermissionsResultCallback {
|
||||
|
||||
private SwitchPreference mLookupContactsPreference;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.spell_checker_settings);
|
||||
mLookupContactsPreference = findPreference(Settings.PREF_USE_CONTACTS);
|
||||
turnOffLookupContactsIfNoPermission();
|
||||
|
||||
ActivityThemeUtils.setActivityTheme(requireActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (!TextUtils.equals(key, Settings.PREF_USE_CONTACTS) || !sharedPreferences.getBoolean(key, false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for permissions.
|
||||
if (PermissionsUtil.checkAllPermissionsGranted(getContext(), Manifest.permission.READ_CONTACTS)) {
|
||||
return; // all permissions granted, no need to request permissions.
|
||||
}
|
||||
|
||||
PermissionsManager.get(requireContext()).requestPermissions(this, getActivity(), Manifest.permission.READ_CONTACTS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(boolean allGranted) {
|
||||
turnOffLookupContactsIfNoPermission();
|
||||
}
|
||||
|
||||
private void turnOffLookupContactsIfNoPermission() {
|
||||
if (!PermissionsUtil.checkAllPermissionsGranted(
|
||||
getActivity(), Manifest.permission.READ_CONTACTS)) {
|
||||
mLookupContactsPreference.setChecked(false);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,11 +5,13 @@ import android.content.SharedPreferences
|
|||
import android.os.Bundle
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.core.view.isGone
|
||||
import helium314.keyboard.latin.R
|
||||
import helium314.keyboard.latin.settings.Settings
|
||||
import helium314.keyboard.latin.utils.Log
|
||||
import helium314.keyboard.latin.utils.prefs
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
|
||||
|
@ -29,6 +31,8 @@ class SettingsActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferen
|
|||
|
||||
settingsContainer = SettingsContainer(this)
|
||||
|
||||
val spellchecker = intent?.getBooleanExtra("spellchecker", false) ?: false
|
||||
|
||||
// todo: when removing old settings completely, remove settings_activity.xml and supportFragmentManager stuff
|
||||
// val cv = ComposeView(context = this)
|
||||
// setContentView(cv)
|
||||
|
@ -40,14 +44,20 @@ class SettingsActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferen
|
|||
findViewById<ComposeView>(R.id.navHost).setContent {
|
||||
Theme {
|
||||
Surface {
|
||||
SettingsNavHost(
|
||||
onClickBack = {
|
||||
// this.finish() // todo: when removing old settings
|
||||
if (supportFragmentManager.findFragmentById(R.id.settingsFragmentContainer) == null)
|
||||
this.finish()
|
||||
else supportFragmentManager.popBackStack()
|
||||
if (spellchecker)
|
||||
Column { // lazy way of implementing spell checker settings
|
||||
settingsContainer[Settings.PREF_USE_CONTACTS]!!.Preference()
|
||||
settingsContainer[Settings.PREF_BLOCK_POTENTIALLY_OFFENSIVE]!!.Preference()
|
||||
}
|
||||
)
|
||||
else
|
||||
SettingsNavHost(
|
||||
onClickBack = {
|
||||
// this.finish() // todo: when removing old settings
|
||||
if (supportFragmentManager.findFragmentById(R.id.settingsFragmentContainer) == null)
|
||||
this.finish()
|
||||
else supportFragmentManager.popBackStack()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import androidx.compose.material3.Text
|
|||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package helium314.keyboard.settings.screens
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
|
||||
@Composable
|
||||
fun SpellCheckerScreen(
|
||||
|
||||
) {
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2011 The Android Open Source Project
|
||||
modified
|
||||
SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
|
||||
-->
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:title="@string/android_spell_checker_settings"
|
||||
>
|
||||
<SwitchPreference
|
||||
android:key="use_contacts"
|
||||
android:title="@string/use_contacts_for_spellchecking_option_title"
|
||||
android:summary="@string/use_contacts_for_spellchecking_option_summary"
|
||||
android:defaultValue="false"
|
||||
android:persistent="true" />
|
||||
|
||||
<SwitchPreference
|
||||
android:key="block_potentially_offensive"
|
||||
android:title="@string/prefs_block_potentially_offensive_title"
|
||||
android:defaultValue="@bool/config_block_potentially_offensive"
|
||||
android:persistent="true" />
|
||||
</PreferenceScreen>
|
Loading…
Add table
Add a link
Reference in a new issue