Skip to content

Commit

Permalink
Merging in main.
Browse files Browse the repository at this point in the history
  • Loading branch information
growabeard committed Oct 21, 2024
2 parents c135b81 + 7018590 commit b33b11f
Show file tree
Hide file tree
Showing 17 changed files with 345 additions and 104 deletions.
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Thank you for your pull request! 🚀
<!-- Please replace the empty checkboxes [] below with checked ones [x] accordingly. -->

- [] This pull request is on a [separate branch](https://docs.github.com/en/get-started/quickstart/github-flow) and not the main branch
- [] I have tested my code with the `./gradlew lintKotlin detekt test` command as directed in the [testing section of the contributing guide](https://github.com/scribe-org/Scribe-Data/blob/main/CONTRIBUTING.md#testing)

---

Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/pr_unit_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: pr_unit_test
on:
pull_request:
branches:
- main
types: [opened, reopened, synchronize]

jobs:
unit-test:
runs-on: ubuntu-latest
name: Run unit tests

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup JDK environment
uses: actions/setup-java@v4
with:
distribution: "zulu"
java-version: 17

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

- name: Run tests
run: ./gradlew test
19 changes: 19 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ If you have questions or would like to communicate with the team, please [join u
- [First steps as a contributor](#first-steps)
- [Learning the tech stack](#learning-the-tech)
- [Development environment](#dev-env)
- [Testing](#testing)
- [Issues and projects](#issues-projects)
- [Bug reports](#bug-reports)
- [Feature requests](#feature-requests)
Expand Down Expand Up @@ -119,6 +120,24 @@ git remote add upstream https://github.com/scribe-org/Scribe-Android.git
> [!NOTE]
> Feel free to contact the team in the [Android room on Matrix](https://matrix.to/#/#ScribeAndroid:matrix.org) if you're having problems getting your environment setup!
<a id="testing"></a>

## Testing [``](#contents)

Scribe-Android includes a testing suite that should be ran before all pull requests and subsequent commits. Please run the following in the project root:

```bash
# Run ktlint and detekt:
./gradlew lintKotlin detekt
./gradlew test
```

If you see that there are linting errors above, then please run the following command to hopefully fix them automatically:

```bash
ktlint --format
```

<a id="issues-projects"></a>

# Issues and projects [``](#contents)
Expand Down
15 changes: 13 additions & 2 deletions app/src/main/java/be/scri/activities/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
private var englishKeyboardIME: EnglishKeyboardIME? = null

fun getEnglishKeyboardIME(): EnglishKeyboardIME? = englishKeyboardIME

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
supportActionBar?.displayOptions = androidx.appcompat.app.ActionBar.DISPLAY_SHOW_CUSTOM
Expand Down Expand Up @@ -221,6 +219,19 @@ class MainActivity : AppCompatActivity() {
}
}

override fun onBackPressed() {
super.onBackPressed()
if (viewPager.currentItem == 0) {
if (binding.fragmentContainer.visibility == View.VISIBLE) {
binding.fragmentContainer.visibility = View.GONE
} else {
finish()
}
} else {
viewPager.currentItem = viewPager.currentItem - 1
}
}

fun hideHint() {
val hintLayout = findViewById<View>(R.id.hint_layout)
hintLayout.visibility = View.GONE
Expand Down
12 changes: 9 additions & 3 deletions app/src/main/java/be/scri/extensions/ContextStyling.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ fun Context.getProperPrimaryColor() =
else -> baseConfig.primaryColor
}

fun Context.isBlackAndWhiteTheme() = baseConfig.textColor == Color.WHITE && baseConfig.primaryColor == Color.BLACK && baseConfig.backgroundColor == Color.BLACK

fun Context.isWhiteTheme() = baseConfig.textColor == DARK_GREY && baseConfig.primaryColor == Color.WHITE && baseConfig.backgroundColor == Color.WHITE
fun Context.isBlackAndWhiteTheme() =
baseConfig.textColor == Color.WHITE &&
baseConfig.primaryColor == Color.BLACK &&
baseConfig.backgroundColor == Color.BLACK

fun Context.isWhiteTheme() =
baseConfig.textColor == DARK_GREY &&
baseConfig.primaryColor == Color.WHITE &&
baseConfig.backgroundColor == Color.WHITE

fun Context.isUsingSystemDarkTheme() = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_YES != 0
6 changes: 2 additions & 4 deletions app/src/main/java/be/scri/fragments/AboutFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ class AboutFragment : Fragment() {
),
)

private fun getSecondRecyclerViewData(): List<Any> {
val context = requireContext()
return listOf(
private fun getSecondRecyclerViewData(): List<Any> =
listOf(
ItemsViewModel(
image = R.drawable.star,
text = ItemsViewModel.Text(R.string.app_about_feedback_rate_scribe),
Expand Down Expand Up @@ -177,7 +176,6 @@ class AboutFragment : Fragment() {
action = ::resetHints,
),
)
}

private fun getThirdRecyclerViewData(): List<ItemsViewModel> =
listOf(
Expand Down
55 changes: 45 additions & 10 deletions app/src/main/java/be/scri/fragments/LanguageSettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import be.scri.databinding.FragmentLanguageSettingsBinding
import be.scri.helpers.CustomAdapter
import be.scri.models.SwitchItem

@Suppress("LongMethod")
class LanguageSettingsFragment : Fragment() {
private var _binding: FragmentLanguageSettingsBinding? = null
val binding get() = _binding!!
Expand Down Expand Up @@ -100,7 +101,11 @@ class LanguageSettingsFragment : Fragment() {

private fun setupRecyclerView(language: String) {
binding.functionalityRecyclerView.layoutManager = LinearLayoutManager(context)
binding.functionalityRecyclerView.adapter = CustomAdapter(getFunctionalityRecyclerViewData(language), requireContext())
binding.functionalityRecyclerView.adapter =
CustomAdapter(
getFunctionalityRecyclerViewData(language),
requireContext(),
)

binding.layoutRecyclerView.layoutManager = LinearLayoutManager(context)
binding.layoutRecyclerView.adapter = CustomAdapter(getLayoutRecyclerViewData(language), requireContext())
Expand Down Expand Up @@ -137,9 +142,19 @@ class LanguageSettingsFragment : Fragment() {
"German" -> {
list.add(
SwitchItem(
isChecked = sharedPref.getBoolean("disable_accent_character_$language", false),
title = getString(R.string.app_settings_keyboard_layout_disable_accent_characters),
description = getString(R.string.app_settings_keyboard_layout_disable_accent_characters_description),
isChecked =
sharedPref.getBoolean(
"disable_accent_character_$language",
false,
),
title =
getString(
R.string.app_settings_keyboard_layout_disable_accent_characters,
),
description =
getString(
R.string.app_settings_keyboard_layout_disable_accent_characters_description,
),
action = { disableAccentCharacter(language) },
action2 = { enableAccentCharacters(language) },
),
Expand All @@ -148,9 +163,19 @@ class LanguageSettingsFragment : Fragment() {
"Swedish" -> {
list.add(
SwitchItem(
isChecked = sharedPref.getBoolean("disable_accent_character_$language", false),
title = getString(R.string.app_settings_keyboard_layout_disable_accent_characters),
description = getString(R.string.app_settings_keyboard_layout_disable_accent_characters_description),
isChecked =
sharedPref.getBoolean(
"disable_accent_character_$language",
false,
),
title =
getString(
R.string.app_settings_keyboard_layout_disable_accent_characters,
),
description =
getString(
R.string.app_settings_keyboard_layout_disable_accent_characters_description,
),
action = { disableAccentCharacter(language) },
action2 = { enableAccentCharacters(language) },
),
Expand All @@ -159,9 +184,19 @@ class LanguageSettingsFragment : Fragment() {
"Spanish" -> {
list.add(
SwitchItem(
isChecked = sharedPref.getBoolean("disable_accent_character_$language", false),
title = getString(R.string.app_settings_keyboard_layout_disable_accent_characters),
description = getString(R.string.app_settings_keyboard_layout_disable_accent_characters_description),
isChecked =
sharedPref.getBoolean(
"disable_accent_character_$language",
false,
),
title =
getString(
R.string.app_settings_keyboard_layout_disable_accent_characters,
),
description =
getString(
R.string.app_settings_keyboard_layout_disable_accent_characters_description,
),
action = { disableAccentCharacter(language) },
action2 = { enableAccentCharacters(language) },
),
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/be/scri/fragments/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MainFragment : Fragment() {
// binding.scribeKey.setOnClickListener {
// (requireActivity().getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager).showInputMethodPicker()
// }
binding.keyboardSettings.setOnClickListener {
binding.cardView.setOnClickListener {
openKeyboardSettings()
}
(requireActivity() as MainActivity).unsetActionBarLayoutMargin()
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/be/scri/fragments/PrivacyPolicyFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ class PrivacyPolicyFragment : Fragment() {
(requireActivity() as MainActivity).setActionBarButtonVisible()
(requireActivity() as MainActivity).setActionBarTitle(R.string.app_about_legal_privacy_policy)
(requireActivity() as MainActivity).setActionBarLayoutMargin()
val textView = (requireActivity() as MainActivity).supportActionBar?.customView?.findViewById<TextView>(R.id.name)
val textView =
(requireActivity() as MainActivity)
.supportActionBar
?.customView
?.findViewById<TextView>(R.id.name)

(requireActivity() as MainActivity)
.supportActionBar
?.customView
Expand Down
29 changes: 19 additions & 10 deletions app/src/main/java/be/scri/fragments/SettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.content.res.AppCompatResources.getDrawable
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import be.scri.R
import be.scri.activities.MainActivity
import be.scri.databinding.FragmentSettingsBinding
Expand All @@ -30,6 +31,7 @@ import be.scri.models.TextItem

class SettingsFragment : Fragment() {
private lateinit var binding: FragmentSettingsBinding
private var isDecorationSet: Boolean = false

override fun onCreateView(
inflater: LayoutInflater,
Expand Down Expand Up @@ -141,24 +143,31 @@ class SettingsFragment : Fragment() {
setupItemVisibility()
}
}

val recyclerView = binding.recyclerView2
val adapter = CustomAdapter(getRecyclerViewElements(), requireContext())
recyclerView.layoutManager = LinearLayoutManager(requireContext())
recyclerView.adapter = adapter
recyclerView.suppressLayout(true)
recyclerView.apply {
val itemDecoration =
CustomDividerItemDecoration(
drawable = getDrawable(requireContext(), R.drawable.rv_divider)!!,
width = 1,
marginLeft = 50,
marginRight = 50,
)
addItemDecoration(itemDecoration)

if (!isDecorationSet) {
isDecorationSet = true
recyclerView.apply {
addCustomItemDecoration()
}
}
}

private fun RecyclerView.addCustomItemDecoration() {
val itemDecoration =
CustomDividerItemDecoration(
drawable = getDrawable(requireContext(), R.drawable.rv_divider)!!,
width = 1,
marginLeft = 50,
marginRight = 50,
)
addItemDecoration(itemDecoration)
}

private fun getRecyclerViewElements(): MutableList<TextItem> {
val languages = setupKeyboardLanguage()
val list = mutableListOf<TextItem>()
Expand Down
Loading

0 comments on commit b33b11f

Please sign in to comment.