Skip to content

Commit

Permalink
Merge pull request #14 from Esarve/develop
Browse files Browse the repository at this point in the history
Merge Develop
  • Loading branch information
Esarve authored Mar 24, 2023
2 parents 5c627b0 + 9df20ca commit f545209
Show file tree
Hide file tree
Showing 28 changed files with 1,998 additions and 1,094 deletions.
34 changes: 20 additions & 14 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId "dev.souravdas.hush"
minSdk 22
targetSdk 33
versionCode 1
versionName "1.0"
versionCode 2
versionName "0.2-alpha"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -90,23 +90,14 @@ dependencies {
implementation 'androidx.compose.ui:ui-graphics'
implementation 'androidx.compose.ui:ui-tooling-preview'
implementation 'androidx.compose.material3:material3:1.1.0-alpha07'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.0'
implementation 'androidx.activity:activity-compose:1.6.1'
implementation 'androidx.compose.material:material:1.3.1'
testImplementation 'junit:junit:4.13.2'
testImplementation 'junit:junit:4.13.2'
implementation 'com.jakewharton.timber:timber:5.0.1'
implementation 'com.google.accompanist:accompanist-drawablepainter:0.28.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation platform('androidx.compose:compose-bom:2023.01.00')
androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
debugImplementation 'androidx.compose.ui:ui-tooling'
debugImplementation 'androidx.compose.ui:ui-test-manifest'
implementation 'com.jakewharton.threetenabp:threetenabp:1.4.4'
implementation "com.maxkeppeler.sheets-compose-dialogs:core:1.1.0"
implementation "com.maxkeppeler.sheets-compose-dialogs:clock:1.1.0"
// implementation "com.maxkeppeler.sheets-compose-dialogs:date_time:1.1.0"

def room_version = "2.5.0"

Expand All @@ -122,7 +113,22 @@ dependencies {
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3'
implementation "androidx.activity:activity-ktx:1.6.1"

implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.6.0-rc01"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.5.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.6.0"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.6.0"

def nav_version = "2.5.3"

implementation "androidx.navigation:navigation-compose:$nav_version"
implementation("androidx.hilt:hilt-navigation-compose:1.0.0")


implementation "com.github.bumptech.glide:compose:1.0.0-alpha.1"

androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation platform('androidx.compose:compose-bom:2023.01.00')
androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
debugImplementation 'androidx.compose.ui:ui-tooling'
debugImplementation 'androidx.compose.ui:ui-test-manifest'

}
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
Expand All @@ -22,7 +25,7 @@
android:hardwareAccelerated="true"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:name=".activities.MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Hush">
Expand Down
64 changes: 41 additions & 23 deletions app/src/main/java/dev/souravdas/hush/activities/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.souravdas.hush
package dev.souravdas.hush.activities

import android.app.Activity
import android.content.Context
Expand All @@ -14,13 +14,17 @@ import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.core.app.NotificationManagerCompat
import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import dagger.hilt.android.AndroidEntryPoint
import dev.sourav.emptycompose.ui.theme.HushTheme
import dev.souravdas.hush.activities.UIKit
import dev.souravdas.hush.arch.MainActivityVM
import dev.souravdas.hush.nav.NavGraph
import dev.souravdas.hush.nav.Screens
import dev.souravdas.hush.others.Utils
import dev.souravdas.hush.services.KeepAliveService
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject

@AndroidEntryPoint
Expand All @@ -30,18 +34,23 @@ class MainActivity : ComponentActivity() {
lateinit var utils: Utils
private val viewModel: MainActivityVM by viewModels()
private var doubleBackToExitPressedOnce = false
private lateinit var navController: NavHostController

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
viewModel.getSelectedApp()

navController = rememberNavController()

HushTheme() {
UIKit().MainActivityScreen(onNotificationPermissionGet = {
openNotificationAccessSettingsIfNeeded(this)
}, checkNotificationPermission = {
isNotificationListenerEnabled(this)
})
NavGraph(
navController = navController,
onNotificationPermissionGet = {
openNotificationAccessSettingsIfNeeded(this)
}, checkNotificationPermission = {
isNotificationListenerEnabled(this)
})
}
}

Expand All @@ -50,14 +59,19 @@ class MainActivity : ComponentActivity() {

private fun checkService() {
lifecycleScope.launch {
viewModel.getHushStatusAsFlow().collect() {value ->
if (value){
viewModel.getHushStatusAsFlow().collect() { value ->
if (value) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(Intent(this@MainActivity, KeepAliveService::class.java))
}else{
startForegroundService(
Intent(
this@MainActivity,
KeepAliveService::class.java
)
)
} else {
startService(Intent(this@MainActivity, KeepAliveService::class.java))
}
}else{
} else {
stopService(Intent(this@MainActivity, KeepAliveService::class.java))
}
}
Expand All @@ -76,21 +90,25 @@ class MainActivity : ComponentActivity() {
return enabledPackages.contains(packageName)
}

@Deprecated("Deprecated in Java")
override fun onBackPressed() {
if (doubleBackToExitPressedOnce) {
viewModel.removeIncompleteApp()
finishAffinity()
return
}
if (navController.currentDestination!!.route == Screens.MainScreen.route){
if (doubleBackToExitPressedOnce) {
viewModel.removeIncompleteApp()
finishAffinity()
return
}

this.doubleBackToExitPressedOnce = true
Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show()
this.doubleBackToExitPressedOnce = true
Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show()

Handler(Looper.getMainLooper()).postDelayed(Runnable { doubleBackToExitPressedOnce = false }, 2000)
Handler(Looper.getMainLooper()).postDelayed(Runnable {
doubleBackToExitPressedOnce = false
}, 2000)
}else{
super.onBackPressed()
}
}

override fun onDestroy() {
super.onDestroy()
}
}

Loading

0 comments on commit f545209

Please sign in to comment.