Skip to content

Commit 71e30c9

Browse files
ashb155andrewtavis
andauthored
feat/download data empty state button (#599)
* - empty state download button * - formatting fixes * - design fixes --------- Co-authored-by: Andrew Tavis McAllister <andrew.t.mcallister@gmail.com>
1 parent 11a8450 commit 71e30c9

3 files changed

Lines changed: 101 additions & 0 deletions

File tree

app/src/main/java/be/scri/services/GeneralKeyboardIME.kt

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package be.scri.services
55
import DataContract
66
import android.R.color.white
77
import android.content.Context
8+
import android.content.Intent
89
import android.database.sqlite.SQLiteException
910
import android.graphics.Color
1011
import android.graphics.drawable.GradientDrawable
@@ -29,11 +30,13 @@ import android.view.inputmethod.InputConnection
2930
import android.widget.Button
3031
import androidx.core.content.ContextCompat
3132
import androidx.core.content.edit
33+
import androidx.core.graphics.ColorUtils
3234
import androidx.core.graphics.toColorInt
3335
import androidx.core.view.ViewCompat
3436
import androidx.core.view.WindowCompat
3537
import androidx.core.view.WindowInsetsCompat
3638
import be.scri.R
39+
import be.scri.activities.MainActivity
3740
import be.scri.databinding.InputMethodViewBinding
3841
import be.scri.helpers.AnnotationTextUtils.handleColorAndTextForNounType
3942
import be.scri.helpers.AnnotationTextUtils.handleTextForCaseAnnotation
@@ -289,6 +292,7 @@ abstract class GeneralKeyboardIME(
289292
keyboardMode = keyboardSymbols
290293
R.xml.keys_symbols
291294
}
295+
292296
else -> {
293297
keyboardMode = keyboardLetters
294298
getKeyboardLayoutXML()
@@ -323,6 +327,57 @@ abstract class GeneralKeyboardIME(
323327

324328
moveToIdleState()
325329

330+
val languageAlias = getLanguageAlias(language)
331+
val dbFile = applicationContext.getDatabasePath("${languageAlias}LanguageData.sqlite")
332+
val hasData = dbFile.exists()
333+
val banner = binding.root.findViewById<Button>(R.id.empty_state_banner)
334+
banner.visibility =
335+
if (hasData) View.GONE else View.VISIBLE
336+
binding.commandOptionsBar.visibility =
337+
if (hasData) View.VISIBLE else View.GONE
338+
val isDarkMode = getIsDarkModeOrNot(applicationContext)
339+
val bannerColor = if (isDarkMode) R.color.dark_tutorial_button_color else R.color.light_tutorial_button_color
340+
val bannerTextColor = if (isDarkMode) R.color.dark_button_outline_color else R.color.light_text_color
341+
banner.setTextColor(ContextCompat.getColor(applicationContext, bannerTextColor))
342+
banner.post {
343+
val iconColor = ContextCompat.getColor(applicationContext, bannerTextColor)
344+
banner.compoundDrawables.forEach { drawable ->
345+
drawable?.setTint(iconColor)
346+
}
347+
}
348+
val border = GradientDrawable()
349+
border.cornerRadius = 12f * resources.displayMetrics.density
350+
border.setColor(ContextCompat.getColor(applicationContext, bannerColor))
351+
352+
if (isDarkMode) {
353+
border.setStroke((2f * resources.displayMetrics.density).toInt(), ContextCompat.getColor(applicationContext, bannerTextColor))
354+
}
355+
356+
val rippleColor =
357+
ColorUtils.setAlphaComponent(
358+
ContextCompat.getColor(applicationContext, bannerTextColor),
359+
51,
360+
)
361+
362+
val ripple =
363+
RippleDrawable(
364+
android.content.res.ColorStateList
365+
.valueOf(rippleColor),
366+
border,
367+
null,
368+
)
369+
banner.background = ripple
370+
371+
banner.setOnClickListener {
372+
val intent =
373+
Intent(applicationContext, MainActivity::class.java)
374+
.apply {
375+
flags = Intent.FLAG_ACTIVITY_NEW_TASK
376+
}
377+
378+
startActivity(intent)
379+
}
380+
326381
applyNavBarColor()
327382

328383
// Set initial shift state for empty text fields.
@@ -434,6 +489,7 @@ abstract class GeneralKeyboardIME(
434489
handleModeChange(keyboardMode, keyboardView, this)
435490
}
436491
}
492+
437493
KeyboardBase.KEYCODE_ENTER -> handleKeycodeEnter()
438494
KeyboardBase.KEYCODE_MODE_CHANGE -> handleModeChange(keyboardMode, keyboardView, this)
439495
else -> {
@@ -759,14 +815,17 @@ abstract class GeneralKeyboardIME(
759815
refreshUI()
760816
return
761817
}
818+
762819
null -> ""
763820
else -> if (isAllCaps) pluralResult.uppercase() else pluralResult
764821
}
765822
}
823+
766824
ScribeState.TRANSLATE -> {
767825
val translation = getTranslation(language, rawInput)
768826
if (isAllCaps) translation.uppercase() else translation
769827
}
828+
770829
else -> ""
771830
}
772831

@@ -1272,10 +1331,12 @@ abstract class GeneralKeyboardIME(
12721331
handleMultipleNounFormats(nounTypeSuggestion, "noun")
12731332
true
12741333
}
1334+
12751335
((nounTypeSuggestion?.size ?: 0) > 1) -> {
12761336
handleMultipleNounFormats(nounTypeSuggestion, "noun")
12771337
true
12781338
}
1339+
12791340
handlePluralIfNeeded(isPlural) -> true
12801341
handleSingleNounSuggestion(nounTypeSuggestion) -> true
12811342
handleMultipleCases(caseAnnotationSuggestion) -> true
@@ -1543,9 +1604,11 @@ abstract class GeneralKeyboardIME(
15431604
"noun" ->
15441605
handleColorAndTextForNounType(leftType, language, applicationContext) to
15451606
handleColorAndTextForNounType(rightType, language, applicationContext)
1607+
15461608
"preposition" ->
15471609
handleTextForCaseAnnotation(leftType, language, applicationContext) to
15481610
handleTextForCaseAnnotation(rightType, language, applicationContext)
1611+
15491612
else -> null
15501613
}
15511614
}
@@ -1594,9 +1657,11 @@ abstract class GeneralKeyboardIME(
15941657
hasLinguisticSuggestions && emojiCount != 0 -> {
15951658
uiManager.updateButtonVisibility(currentState, true, autoSuggestEmojis)
15961659
}
1660+
15971661
hasLinguisticSuggestions && emojiCount == 0 -> {
15981662
setSuggestionButton(uiManager.pluralBtn!!, suggestion2)
15991663
}
1664+
16001665
else -> {
16011666
setSuggestionButton(uiManager.binding.translateBtn, suggestion2)
16021667
setSuggestionButton(uiManager.pluralBtn!!, suggestion3)
@@ -1744,6 +1809,7 @@ abstract class GeneralKeyboardIME(
17441809
keyboardView?.setKeyLabel(flattenList[1], "HI", KeyboardBase.CODE_2X1_BOTTOM)
17451810
subsequentAreaRequired = false
17461811
}
1812+
17471813
DATA_CONSTANT_3 -> {
17481814
keyboardView?.setKeyLabel(flattenList[0], "HI", KeyboardBase.CODE_1X3_RIGHT)
17491815
keyboardView?.setKeyLabel(flattenList[1], "HI", KeyboardBase.CODE_1X3_CENTER)
@@ -1786,6 +1852,7 @@ abstract class GeneralKeyboardIME(
17861852
}
17871853
}
17881854
}
1855+
17891856
else -> {
17901857
getKeyboardLayoutXML()
17911858
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item
4+
android:drawable="@drawable/clouddownload"
5+
android:width="24dp"
6+
android:height="24dp"
7+
android:left="52dp" />
8+
</layer-list>

app/src/main/res/layout/input_method_view.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,32 @@
671671
android:padding="0dp" />
672672
</FrameLayout>
673673

674+
<Button
675+
android:id="@+id/empty_state_banner"
676+
android:layout_width="0dp"
677+
android:layout_height="wrap_content"
678+
android:layout_marginStart="8dp"
679+
android:layout_marginEnd="8dp"
680+
android:layout_marginTop="6dp"
681+
android:layout_marginBottom="6dp"
682+
android:text="Please download language data"
683+
android:textSize="16sp"
684+
android:minHeight="0dp"
685+
android:paddingTop="8dp"
686+
android:paddingBottom="8dp"
687+
android:paddingStart="24dp"
688+
android:paddingEnd="36dp"
689+
android:background="@null"
690+
android:stateListAnimator="@null"
691+
android:drawableStart="@drawable/clouddownload_keyboard"
692+
android:drawablePadding="4dp"
693+
android:gravity="center"
694+
android:visibility="gone"
695+
app:layout_constraintBottom_toTopOf="@+id/keyboard_view"
696+
app:layout_constraintEnd_toEndOf="parent"
697+
app:layout_constraintStart_toStartOf="parent"
698+
app:layout_constraintTop_toTopOf="parent" />
699+
674700
<be.scri.views.KeyboardView
675701
android:id="@+id/keyboard_view"
676702
style="@style/KeyboardView"

0 commit comments

Comments
 (0)