Skip to content

Commit

Permalink
- Moved setup code to a more standard MVVM type structure using Koin …
Browse files Browse the repository at this point in the history
…and ViewModels, with Flow and LiveData

- Switched setup to use View Binding instead of Synthetics as is recommended nowadays
- Rewrote Accessibility, Foreground and core Columbus service code to hopefully be more stable and reliable with no duplications. Both Accessibility and Foreground services are now used solely to keep the code running, and executing actions / powering gates (accessibility)
- Removed unused tensorflow jni lib & xposed_init left over from pre-alpha days
- Began splitting out Extensions into seperate classe
  • Loading branch information
KieronQuinn committed Feb 7, 2021
1 parent 7e31a5b commit 313c9c3
Show file tree
Hide file tree
Showing 99 changed files with 2,505 additions and 1,968 deletions.
3 changes: 2 additions & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 25 additions & 12 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'koin'
apply plugin: "androidx.navigation.safeargs.kotlin"

apply plugin: 'com.google.android.gms.oss-licenses-plugin'

Expand Down Expand Up @@ -50,6 +52,10 @@ android {
aaptOptions {
noCompress "tflite", 'so'
}

buildFeatures {
viewBinding true
}
}

allprojects {
Expand All @@ -63,21 +69,22 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

//AndroidX
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.fragment:fragment-ktx:1.3.0-alpha08'
implementation 'androidx.fragment:fragment-ktx:1.3.0-rc01'
implementation "androidx.lifecycle:lifecycle-common-java8:2.2.0"
implementation "androidx.lifecycle:lifecycle-service:2.2.0"
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0"
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation "androidx.work:work-runtime-ktx:2.4.0"
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.browser:browser:1.2.0'
implementation "androidx.navigation:navigation-fragment-ktx:2.3.0"
implementation "androidx.navigation:navigation-ui-ktx:2.3.0"
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation 'androidx.browser:browser:1.3.0'
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

//Core Library Desugaring: https://developer.android.com/studio/write/java8-support#library-desugaring
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.10'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.1'

//Google
kapt 'com.google.dagger:dagger-compiler:2.28.3'
Expand All @@ -86,22 +93,28 @@ dependencies {
implementation 'com.google.android.gms:play-services-oss-licenses:17.0.0'
implementation 'com.google.dagger:dagger:2.28.3'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly'
implementation 'org.tensorflow:tensorflow-lite:2.1.0'

//Koin
implementation "org.koin:koin-android:$koin_version"
implementation "org.koin:koin-android-scope:$koin_version"
implementation "org.koin:koin-android-viewmodel:$koin_version"

//Third Party
implementation "dev.chrisbanes:insetter-ktx:0.3.0"
implementation "dev.chrisbanes:insetter-ktx:0.3.1"
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.joaomgcd:taskerpluginlibrary:0.3.2'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.afollestad.material-dialogs:bottomsheets:3.3.0'
implementation "com.airbnb.android:lottie:3.4.0"
implementation "com.airbnb.android:lottie:3.5.0"
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.19'
implementation 'me.saket:better-link-movement-method:2.2.0'
implementation 'com.github.judemanutd:autostarter:1.0.8'
implementation 'com.github.tfcporciuncula.flow-preferences:flow-preferences:1.3.3'

//Testing
testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
Binary file modified app/libs/columbus.jar
Binary file not shown.
8 changes: 4 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<activity android:name=".activities.ModalActivity" />

<service
android:name=".services.TapAccessibilityService"
android:name="com.kieronquinn.app.taptap.core.services.TapAccessibilityService"
android:label="@string/accessibility_service_label"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
Expand All @@ -53,7 +53,7 @@
</service>

<service
android:name=".services.TapGestureAccessibilityService"
android:name="com.kieronquinn.app.taptap.core.services.TapGestureAccessibilityService"
android:label="@string/accessibility_service_label_gesture"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
Expand Down Expand Up @@ -99,9 +99,9 @@
android:name=".activities.ReachabilityActivity"
android:theme="@style/ReachabilityTheme" />

<service android:name=".services.TapForegroundService" />
<service android:name="com.kieronquinn.app.taptap.core.services.TapForegroundService" />
<service
android:name=".services.TapQSTile"
android:name="com.kieronquinn.app.taptap.core.services.TapQSTile"
android:icon="@drawable/ic_taptap_logo"
android:label="@string/app_name"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
Expand Down
Binary file removed app/src/main/assets/libtensorflowlite_jni.so
Binary file not shown.
1 change: 0 additions & 1 deletion app/src/main/assets/xposed_init

This file was deleted.

59 changes: 53 additions & 6 deletions app/src/main/java/com/kieronquinn/app/taptap/TapTapApplication.kt
Original file line number Diff line number Diff line change
@@ -1,24 +1,71 @@
package com.kieronquinn.app.taptap

import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.kieronquinn.app.taptap.services.TapAccessibilityService
import com.kieronquinn.app.taptap.services.TapGestureAccessibilityService
import android.content.Context
import com.google.android.systemui.columbus.ColumbusContentObserver
import com.google.android.systemui.columbus.ContentResolverWrapper
import com.google.android.systemui.columbus.PowerManagerWrapper
import com.google.android.systemui.columbus.sensors.GestureSensor
import com.google.android.systemui.columbus.sensors.config.Adjustment
import com.google.android.systemui.columbus.sensors.config.GestureConfiguration
import com.kieronquinn.app.taptap.core.TapGestureSensorImpl
import com.kieronquinn.app.taptap.core.TapColumbusService
import com.kieronquinn.app.taptap.core.TapServiceContainer
import com.kieronquinn.app.taptap.core.TapSharedPreferences
import com.kieronquinn.app.taptap.utils.AppIconRequestHandler
import com.kieronquinn.app.taptap.utils.activityManagerNative
import com.kieronquinn.app.taptap.v2.ui.screens.modal.ModalNoGyroscopeViewModel
import com.kieronquinn.app.taptap.v2.ui.screens.setup.accessibility.SetupAccessibilityViewModel
import com.kieronquinn.app.taptap.v2.ui.screens.setup.battery.SetupBatteryViewModel
import com.kieronquinn.app.taptap.v2.ui.screens.setup.configuration.SetupConfigurationViewModel
import com.kieronquinn.app.taptap.v2.ui.screens.setup.configuration.preference.SetupConfigurationPreferenceViewModel
import com.kieronquinn.app.taptap.v2.ui.screens.setup.landing.SetupLandingViewModel
import com.kieronquinn.app.taptap.v2.ui.screens.setup.foss.SetupFossInfoViewModel
import com.squareup.picasso.Picasso
import org.koin.android.ext.android.inject
import org.koin.android.ext.koin.androidContext
import org.koin.android.viewmodel.dsl.viewModel
import org.koin.core.context.startKoin
import org.koin.dsl.module

class TapTapApplication : Application() {

var accessibilityService: MutableLiveData<TapAccessibilityService?> = MutableLiveData(null)
var gestureAccessibilityService: MutableLiveData<TapGestureAccessibilityService?> = MutableLiveData(null)

var disableWake = false

override fun onCreate() {
super.onCreate()
Picasso.setSingletonInstance(Picasso.Builder(this)
.addRequestHandler(AppIconRequestHandler(this))
.build())
startKoin {
androidContext(this@TapTapApplication)
val modules = module {
//Tap Service Dependencies
single { TapSharedPreferences(get()) }
single<GestureSensor> { TapGestureSensorImpl(get(), get(), createGestureConfiguration(get(), activityManagerNative)) }
single { PowerManagerWrapper(get()) }
//Tap Service
single { TapColumbusService(get(), get(), get(), get()) }
single { TapServiceContainer() }
//Setup flow
viewModel { SetupLandingViewModel(get()) }
viewModel { SetupConfigurationViewModel(get()) }
viewModel { SetupConfigurationPreferenceViewModel(get()) }
viewModel { SetupFossInfoViewModel() }
viewModel { SetupAccessibilityViewModel() }
viewModel { SetupBatteryViewModel(get()) }
//No gyroscope modal
viewModel { ModalNoGyroscopeViewModel() }
}
modules(modules)
}
}

private fun createGestureConfiguration(context: Context, activityManager: Any): GestureConfiguration {
val contentResolverWrapper = ContentResolverWrapper(context)
val factory = ColumbusContentObserver.Factory::class.java.constructors.first()
.newInstance(contentResolverWrapper, activityManager) as ColumbusContentObserver.Factory
return GestureConfiguration(context, emptySet<Adjustment>(), factory)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class ReachabilityActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if(!sharedPreferences.contains(KEY_REACHABILITY_LEFT_HANDED)){
if(sharedPreferences?.contains(KEY_REACHABILITY_LEFT_HANDED) == false){
Toast.makeText(this, R.string.reachability_left_handed_info, Toast.LENGTH_LONG).show()
sharedPreferences.edit().putBoolean(KEY_REACHABILITY_LEFT_HANDED, isLeftHanded).apply()
sharedPreferences?.edit()?.putBoolean(KEY_REACHABILITY_LEFT_HANDED, isLeftHanded)?.apply()
}
isLeftHanded = sharedPreferences.getBoolean(KEY_REACHABILITY_LEFT_HANDED, false)
isLeftHanded = sharedPreferences?.getBoolean(KEY_REACHABILITY_LEFT_HANDED, false) ?: false
sendBroadcast(Intent(LaunchReachability.INTENT_ACTION_START_SPLIT_SCREEN).apply {
setPackage(packageName)
})
Expand All @@ -56,7 +56,7 @@ class ReachabilityActivity : AppCompatActivity() {
})
}
reachability_notifications.setOnLongClickListener {
sharedPreferences.edit().putBoolean(KEY_REACHABILITY_LEFT_HANDED, !isLeftHanded).apply()
sharedPreferences?.edit()?.putBoolean(KEY_REACHABILITY_LEFT_HANDED, !isLeftHanded)?.apply()
isLeftHanded = !isLeftHanded
updateHandedness()
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ import androidx.navigation.findNavController
import com.airbnb.lottie.LottieProperty
import com.airbnb.lottie.model.KeyPath
import com.kieronquinn.app.taptap.R
import com.kieronquinn.app.taptap.core.TapSharedPreferences
import com.kieronquinn.app.taptap.core.TapSharedPreferences.Companion.SHARED_PREFERENCES_KEY_MAIN_SWITCH
import com.kieronquinn.app.taptap.core.TapSharedPreferences.Companion.SHARED_PREFERENCES_KEY_TRIPLE_TAP_SWITCH
import com.kieronquinn.app.taptap.fragments.BaseFragment
import com.kieronquinn.app.taptap.fragments.bottomsheets.MaterialBottomSheetDialogFragment
import com.kieronquinn.app.taptap.fragments.bottomsheets.UpdateBottomSheetFragment
import com.kieronquinn.app.taptap.fragments.setup.BaseSetupFragment
import com.kieronquinn.app.taptap.utils.*
import com.kieronquinn.app.taptap.workers.UpdateCheckWorker
import dev.chrisbanes.insetter.Insetter
Expand All @@ -44,6 +46,7 @@ import dev.chrisbanes.insetter.applySystemWindowInsetsToPadding
import dev.chrisbanes.insetter.setEdgeToEdgeSystemUiFlags
import kotlinx.android.synthetic.main.activity_settings.*
import kotlinx.android.synthetic.main.activity_setup.*
import org.koin.android.ext.android.inject
import kotlin.math.max

class SettingsActivity : AppCompatActivity(), NavController.OnDestinationChangedListener, SharedPreferences.OnSharedPreferenceChangeListener {
Expand All @@ -70,6 +73,8 @@ class SettingsActivity : AppCompatActivity(), NavController.OnDestinationChanged
findNavController(R.id.nav_host_fragment)
}

private val tapSharedPreferences by inject<TapSharedPreferences>()

private var isFirstStart = true

val updateChecker by lazy { UpdateChecker() }
Expand All @@ -84,7 +89,7 @@ class SettingsActivity : AppCompatActivity(), NavController.OnDestinationChanged
finish()
return
}
if(hasSeenSetup && !forceRerunSetup){
if(tapSharedPreferences.hasSeenSetup && !forceRerunSetup){
showSettingsUi()
}else{
startSetupFlow(savedInstanceState)
Expand All @@ -106,8 +111,8 @@ class SettingsActivity : AppCompatActivity(), NavController.OnDestinationChanged
toolbar.applySystemWindowInsetsToPadding(top = true)
switch_main.applySystemWindowInsetsToMargin(top = true)
setToolbarElevationEnabled(false)
sharedPreferences.registerOnSharedPreferenceChangeListener(this)
switch_main.isChecked = isMainEnabled
sharedPreferences?.registerOnSharedPreferenceChangeListener(this)
switch_main.isChecked = tapSharedPreferences.isMainEnabled
switch_main.setOnCheckedChangeListener(checkListener)
updateChecker.getLatestRelease { success, updateChecker ->
if(success){
Expand Down Expand Up @@ -234,20 +239,20 @@ class SettingsActivity : AppCompatActivity(), NavController.OnDestinationChanged
private val checkListener =
CompoundButton.OnCheckedChangeListener { buttonView, isChecked ->
if(buttonView.tag == TAG_SWITCH_MAIN) {
sharedPreferences.edit().putBoolean(SHARED_PREFERENCES_KEY_MAIN_SWITCH, isChecked).apply()
sharedPreferences?.edit()?.putBoolean(SHARED_PREFERENCES_KEY_MAIN_SWITCH, isChecked)?.apply()
}else{
sharedPreferences.edit().putBoolean(SHARED_PREFERENCES_KEY_TRIPLE_TAP_SWITCH, isChecked).apply()
sharedPreferences?.edit()?.putBoolean(SHARED_PREFERENCES_KEY_TRIPLE_TAP_SWITCH, isChecked)?.apply()
}
}

override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
if(key == SHARED_PREFERENCES_KEY_MAIN_SWITCH && switch_main?.tag == TAG_SWITCH_MAIN) {
switch_main.setOnCheckedChangeListener(null)
switch_main.isChecked = isMainEnabled
switch_main.isChecked = tapSharedPreferences.isMainEnabled
switch_main.setOnCheckedChangeListener(checkListener)
}else if(key == SHARED_PREFERENCES_KEY_TRIPLE_TAP_SWITCH && switch_main?.tag == TAG_SWITCH_TRIPLE_TAP) {
switch_main.setOnCheckedChangeListener(null)
switch_main.isChecked = isTripleTapEnabled
switch_main.isChecked = tapSharedPreferences.isTripleTapEnabled
switch_main.setOnCheckedChangeListener(checkListener)
}
}
Expand Down Expand Up @@ -279,23 +284,6 @@ class SettingsActivity : AppCompatActivity(), NavController.OnDestinationChanged
outState.putBoolean(HAS_RUN_ANIMATION, true)
}

private fun onHomeAsUpPressed(){
val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment)
if (navHostFragment?.childFragmentManager != null) {
val currentFragment = navHostFragment.childFragmentManager.fragments[0]
val result = (currentFragment as? BaseSetupFragment)?.onHomeAsUpPressed()
if (result != true){
if(!findNavController(R.id.nav_host_fragment).navigateUp()){
finishAfterTransition()
}
}
} else {
if(!findNavController(R.id.nav_host_fragment).navigateUp()){
finishAfterTransition()
}
}
}

private fun doesDeviceHaveGyroscope(): Boolean {
val sensorManager = getSystemService(Context.SENSOR_SERVICE) as SensorManager
return sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE) != null
Expand Down
Loading

0 comments on commit 313c9c3

Please sign in to comment.