Skip to content

Commit

Permalink
feat:Removed additional functions from helpers directory
Browse files Browse the repository at this point in the history
  • Loading branch information
angrezichatterbox committed Oct 16, 2024
1 parent b4f068b commit a071a8f
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 107 deletions.
2 changes: 0 additions & 2 deletions app/src/main/java/be/scri/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package be.scri

import android.app.Application
import androidx.appcompat.app.AppCompatDelegate
import be.scri.extensions.checkUseEnglish
import be.scri.extensions.config

class App : Application() {
Expand All @@ -15,6 +14,5 @@ class App : Application() {
},
)
super.onCreate()
checkUseEnglish()
}
}
42 changes: 0 additions & 42 deletions app/src/main/java/be/scri/extensions/CommonsContext.kt
Original file line number Diff line number Diff line change
@@ -1,51 +1,9 @@
package be.scri.extensions

import android.app.Activity
import android.content.Context
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.view.View
import android.view.WindowManager
import android.widget.Toast
import be.scri.helpers.BaseConfig
import be.scri.helpers.PREFS_KEY
import be.scri.helpers.isOnMainThread

fun Context.getSharedPrefs() = getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)

val Context.isRTLLayout: Boolean get() = resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_RTL

fun Context.toast(
msg: String,
length: Int = Toast.LENGTH_SHORT,
) {
try {
val showToast = { doToast(this, msg, length) }
if (isOnMainThread()) {
showToast()
} else {
Handler(Looper.getMainLooper()).post(showToast)
}
} catch (e: IllegalArgumentException) {
Log.e("ToastError", "Invalid argument while showing toast: ${e.message}", e)
}
}

private fun doToast(
context: Context,
message: String,
length: Int,
) {
if (context is Activity) {
if (!context.isFinishing && !context.isDestroyed) {
Toast.makeText(context, message, length).show()
}
} else {
Toast.makeText(context, message, length).show()
}
}

val Context.baseConfig: BaseConfig get() = BaseConfig.newInstance(this)

val Context.windowManager: WindowManager get() = getSystemService(Context.WINDOW_SERVICE) as WindowManager
12 changes: 0 additions & 12 deletions app/src/main/java/be/scri/extensions/View.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package be.scri.extensions

import android.view.HapticFeedbackConstants
import android.view.View
import android.view.ViewTreeObserver

fun View.beVisibleIf(beVisible: Boolean) = if (beVisible) beVisible() else beGone()

Expand All @@ -16,15 +15,4 @@ fun View.beGone() {
visibility = View.GONE
}

fun View.onGlobalLayout(callback: () -> Unit) {
viewTreeObserver.addOnGlobalLayoutListener(
object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
viewTreeObserver.removeOnGlobalLayoutListener(this)
callback()
}
},
)
}

fun View.performHapticFeedback() = performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY)
14 changes: 0 additions & 14 deletions app/src/main/java/be/scri/helpers/CommonsConstants.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
package be.scri.helpers

import android.os.Build
import android.os.Looper
import androidx.annotation.ChecksSdkIntAtLeast

val DARK_GREY = 0xFF333333.toInt()

const val MEDIUM_ALPHA = 0.5f

// shared preferences
const val PREFS_KEY = "Prefs"
const val TEXT_COLOR = "text_color"
Expand All @@ -18,11 +12,3 @@ const val ACCENT_COLOR = "accent_color"
const val USE_ENGLISH = "use_english"
const val WAS_USE_ENGLISH_TOGGLED = "was_use_english_toggled"
const val IS_USING_SYSTEM_THEME = "is_using_system_theme"

fun isOnMainThread() = Looper.myLooper() == Looper.getMainLooper()

@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.N)
fun isNougatPlus() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N

@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.R)
fun isRPlus() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
22 changes: 0 additions & 22 deletions app/src/main/java/be/scri/helpers/Config.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package be.scri.helpers

import android.content.Context
import java.util.Locale

class Config(
context: Context,
Expand All @@ -22,28 +21,7 @@ class Config(
get() = prefs.getBoolean(DARK_THEME, true)
set(darkTheme) = prefs.edit().putBoolean(DARK_THEME, darkTheme).apply()

var lastExportedClipsFolder: String
get() = prefs.getString(LAST_EXPORTED_CLIPS_FOLDER, "")!!
set(lastExportedClipsFolder) = prefs.edit().putString(LAST_EXPORTED_CLIPS_FOLDER, lastExportedClipsFolder).apply()

var keyboardLanguage: Int
get() = prefs.getInt(KEYBOARD_LANGUAGE, getDefaultLanguage())
set(keyboardLanguage) = prefs.edit().putInt(KEYBOARD_LANGUAGE, keyboardLanguage).apply()

var periodOnDoubleTap: Boolean
get() = prefs.getBoolean(PERIOD_ON_DOUBLE_TAP, true)
set(periodOnDoubleTap) = prefs.edit().putBoolean(PERIOD_ON_DOUBLE_TAP, periodOnDoubleTap).apply()

private fun getDefaultLanguage(): Int {
val conf = context.resources.configuration
return if (conf.locale
.toString()
.lowercase(Locale.getDefault())
.startsWith("ru_")
) {
LANGUAGE_RUSSIAN
} else {
LANGUAGE_ENGLISH_QWERTY
}
}
}
15 changes: 0 additions & 15 deletions app/src/main/java/be/scri/helpers/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,5 @@ const val MAX_KEYS_PER_MINI_ROW = 9
// shared prefs
const val VIBRATE_ON_KEYPRESS = "vibrate_on_keypress"
const val SHOW_POPUP_ON_KEYPRESS = "show_popup_on_keypress"
const val LAST_EXPORTED_CLIPS_FOLDER = "last_exported_clips_folder"
const val KEYBOARD_LANGUAGE = "keyboard_language"
const val DARK_THEME = "dark_theme"
const val PERIOD_ON_DOUBLE_TAP = "period_on_double_tap"

// differentiate current and pinned clips at the keyboards' Clipboard section
const val ITEM_SECTION_LABEL = 0
const val ITEM_CLIP = 1

const val LANGUAGE_ENGLISH_QWERTY = 0
const val LANGUAGE_FRENCH = 1
const val LANGUAGE_GERMAN = 2
const val LANGUAGE_ITALIAN = 3
const val LANGUAGE_PORTUGUESE = 4
const val LANGUAGE_RUSSIAN = 5
const val LANGUAGE_SPANISH = 6
const val LANGUAGE_SWEDISH = 7

0 comments on commit a071a8f

Please sign in to comment.