Skip to content

Commit 5e23f27

Browse files
committed
safeStorageContext refactored
1 parent 33c278d commit 5e23f27

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

app/src/main/kotlin/com/simplemobiletools/keyboard/adapters/ClipsKeyboardAdapter.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import com.simplemobiletools.keyboard.R
1515
import com.simplemobiletools.keyboard.extensions.config
1616
import com.simplemobiletools.keyboard.extensions.getCurrentClip
1717
import com.simplemobiletools.keyboard.extensions.getStrokeColor
18-
import com.simplemobiletools.keyboard.extensions.safeStorageContext
1918
import com.simplemobiletools.keyboard.helpers.ClipsHelper
2019
import com.simplemobiletools.keyboard.helpers.ITEM_CLIP
2120
import com.simplemobiletools.keyboard.helpers.ITEM_SECTION_LABEL
@@ -33,8 +32,8 @@ class ClipsKeyboardAdapter(
3332

3433
private val layoutInflater = LayoutInflater.from(context)
3534

36-
private var textColor = context.safeStorageContext.getProperTextColor()
37-
private var backgroundColor = context.safeStorageContext.getProperBackgroundColor()
35+
private var textColor = context.getProperTextColor()
36+
private var backgroundColor = context.getProperBackgroundColor()
3837

3938
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
4039
val layoutId = when (viewType) {

app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import android.app.KeyguardManager
44
import android.content.ClipboardManager
55
import android.content.Context
66
import android.graphics.Color
7-
import android.os.Build
87
import android.os.IBinder
98
import android.view.*
109
import android.widget.TextView
@@ -29,9 +28,6 @@ val Context.safeStorageContext: Context
2928
this
3029
}
3130

32-
val Context.shouldShowKeyboardToolbar: Boolean
33-
get() = !isDeviceLocked
34-
3531
val Context.isDeviceLocked: Boolean
3632
get() = (getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager).isDeviceLocked
3733

@@ -60,7 +56,7 @@ fun Context.getStrokeColor(): Int {
6056
}
6157
}
6258

63-
fun Context.getKeyboardDialogBuilder() = if (baseConfig.isUsingSystemTheme) {
59+
fun Context.getKeyboardDialogBuilder() = if (safeStorageContext.baseConfig.isUsingSystemTheme) {
6460
MaterialAlertDialogBuilder(this, R.style.MyKeyboard_Alert)
6561
} else {
6662
AlertDialog.Builder(this, R.style.MyKeyboard_Alert)

app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,12 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
225225
mLabelTextSize = resources.getDimension(R.dimen.label_text_size).toInt()
226226
mPreviewHeight = resources.getDimension(R.dimen.key_height).toInt()
227227
mSpaceMoveThreshold = resources.getDimension(R.dimen.medium_margin).toInt()
228-
mTextColor = context.safeStorageContext.getProperTextColor()
229-
mBackgroundColor = context.safeStorageContext.getProperBackgroundColor()
230-
mPrimaryColor = context.safeStorageContext.getProperPrimaryColor()
228+
229+
with (context.safeStorageContext) {
230+
mTextColor = getProperTextColor()
231+
mBackgroundColor = getProperBackgroundColor()
232+
mPrimaryColor = getProperPrimaryColor()
233+
}
231234

232235
mPreviewPopup = PopupWindow(context)
233236
mPreviewText = inflater.inflate(resources.getLayout(R.layout.keyboard_key_preview), null) as TextView
@@ -383,7 +386,6 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
383386
mUsingSystemTheme = config.isUsingSystemTheme
384387
}
385388

386-
387389
val isMainKeyboard = changedView == null || changedView != mini_keyboard_view
388390
mKeyBackground = if (mShowKeyBorders && isMainKeyboard) {
389391
resources.getDrawable(R.drawable.keyboard_key_selector_outlined, context.theme)
@@ -429,7 +431,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
429431
pinned_clipboard_items.applyColorFilter(mTextColor)
430432
clipboard_clear.applyColorFilter(mTextColor)
431433

432-
toolbar_holder.beInvisibleIf(!context.shouldShowKeyboardToolbar)
434+
toolbar_holder.beInvisibleIf(context.isDeviceLocked)
433435
}
434436

435437
mClipboardManagerHolder?.apply {
@@ -1492,7 +1494,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
14921494
}
14931495
}
14941496

1495-
val adapter = ClipsKeyboardAdapter(context, clips, refreshClipsListener) { clip ->
1497+
val adapter = ClipsKeyboardAdapter(context.safeStorageContext, clips, refreshClipsListener) { clip ->
14961498
mOnKeyboardActionListener!!.onText(clip.value)
14971499
vibrateIfNeeded()
14981500
}

0 commit comments

Comments
 (0)