Skip to content

Commit

Permalink
Merge pull request #2 from Esarve/new_ux
Browse files Browse the repository at this point in the history
Merge new UX and all feature
  • Loading branch information
Esarve authored Mar 15, 2023
2 parents 0876059 + 001ecae commit 06c87aa
Show file tree
Hide file tree
Showing 64 changed files with 1,526 additions and 579 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
.externalNativeBuild
.cxx
local.properties
/.idea/inspectionProfiles/
32 changes: 0 additions & 32 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

4 changes: 3 additions & 1 deletion app/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/build
/build
/release/
/schemas/
26 changes: 17 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,18 @@ android {

buildTypes {
release {
minifyEnabled false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}

debug {
versionNameSuffix '-test'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
Expand All @@ -48,7 +53,7 @@ android {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.3.2'
kotlinCompilerExtensionVersion '1.4.3'
}
packagingOptions {
resources {
Expand All @@ -65,6 +70,9 @@ kapt {
dependencies {

implementation 'androidx.appcompat:appcompat-resources:1.6.1'
implementation 'androidx.datastore:datastore-core:1.0.0'
implementation "androidx.datastore:datastore-preferences:1.0.0"

constraints {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") {
because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")
Expand All @@ -77,11 +85,11 @@ dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.activity:activity-compose:1.6.1'
implementation platform('androidx.compose:compose-bom:2022.10.00')
implementation platform('androidx.compose:compose-bom:2023.01.00')
implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.ui:ui-graphics'
implementation 'androidx.compose.ui:ui-tooling-preview'
implementation 'androidx.compose.material3:material3:1.1.0-alpha06'
implementation 'androidx.compose.material3:material3:1.1.0-alpha07'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.activity:activity-compose:1.6.1'
implementation 'androidx.compose.material:material:1.3.1'
Expand All @@ -91,11 +99,11 @@ dependencies {
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:2022.10.00')
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.3.0'
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"
Expand All @@ -111,7 +119,7 @@ dependencies {
kapt 'com.google.dagger:hilt-compiler:2.45'
kapt 'com.google.dagger:dagger-android-processor:2.45'

implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
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"
Expand Down
19 changes: 18 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<application
android:name=".HushApp"
Expand All @@ -17,6 +18,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Hush"
android:hardwareAccelerated="true"
tools:targetApi="31">
<activity
android:name=".MainActivity"
Expand All @@ -31,13 +33,28 @@
</activity>

<service
android:name=".HushService"
android:name=".services.HushService"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"
android:exported="true">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>

<receiver
android:name=".broadcastreceivers.BootReceiver"
android:enabled="true"
android:exported="false"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

<service android:name=".services.KeepAliveService"
android:foregroundServiceType="dataSync|location|mediaPlayback">
</service>

</application>

</manifest>
Binary file added app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 0 additions & 17 deletions app/src/main/java/dev/souravdas/hush/activities/HushService.kt

This file was deleted.

98 changes: 45 additions & 53 deletions app/src/main/java/dev/souravdas/hush/activities/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,88 +1,63 @@
package dev.souravdas.hush

import android.app.Activity
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.os.Bundle
import android.os.*
import android.provider.Settings
import android.view.WindowManager
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import androidx.lifecycle.lifecycleScope
import dagger.hilt.android.AndroidEntryPoint
import dev.sourav.emptycompose.ui.theme.HushTheme
import dev.souravdas.hush.services.KeepAliveService
import dev.souravdas.hush.activities.UIKit
import dev.souravdas.hush.arch.MainActivityVM
import dev.souravdas.hush.ui.theme.HushTheme
import dev.souravdas.hush.models.InstalledPackageInfo
import kotlinx.coroutines.launch

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
val viewModel: MainActivityVM by viewModels()
@OptIn(ExperimentalMaterialApi::class)
private val viewModel: MainActivityVM by viewModels()
private var doubleBackToExitPressedOnce = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
//remember states or other shit BS
val sheetState = rememberBottomSheetState(initialValue = BottomSheetValue.Collapsed)
val scope = rememberCoroutineScope()
val showDialog = remember { mutableStateOf(false) }
val selectedApp = remember { mutableStateOf(InstalledPackageInfo()) }
viewModel.getSelectedApp()

HushTheme {
UIKit().MainActivityScreen(
sheetState,
scope,
showDialog,
selectedApp,
onItemClick = {
scope.launch {
sheetState.collapse()
showDialog.value = true
selectedApp.value = it
}
},
onItemSelected = {
viewModel.addSelectedApp(it)
Toast.makeText(applicationContext, "APP ADDED", Toast.LENGTH_SHORT).show()
showDialog.value = false
}
)
UIKit().MainActivityScreen()
}
}
updateStatusBarColor()
viewModel.getSelectedApp()
}

private fun updateStatusBarColor() {
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.statusBarColor = ContextCompat.getColor(this, R.color.whiteBG)
// make icons white
checkService();
openNotificationAccessSettingsIfNeeded(this)
}

@Suppress("Deprecation")
private fun getPackageList(): List<InstalledPackageInfo> {
val pm: PackageManager = this.packageManager
val packages: MutableList<ApplicationInfo> = pm.getInstalledApplications(0)
val packageNames = mutableListOf<InstalledPackageInfo>()

for (packageInfo in packages) {
if (packageInfo.enabled && pm.getLaunchIntentForPackage(packageInfo.packageName) != null)
packageNames.add(
InstalledPackageInfo(
packageInfo.loadLabel(pm).toString(),
packageInfo.packageName,
packageInfo.loadIcon(pm)
)
)
private fun checkService() {
lifecycleScope.launch {
viewModel.getHushStatusAsFlow().collect() {value ->
if (value){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(Intent(this@MainActivity, KeepAliveService::class.java))
}else{
startService(Intent(this@MainActivity, KeepAliveService::class.java))
}
}else{
stopService(Intent(this@MainActivity, KeepAliveService::class.java))
}
}
}
return packageNames

}

private fun openNotificationAccessSettingsIfNeeded(activity: Activity) {
Expand All @@ -101,5 +76,22 @@ class MainActivity : ComponentActivity() {
val enabledPackages = NotificationManagerCompat.getEnabledListenerPackages(context)
return enabledPackages.contains(packageName)
}

override fun onBackPressed() {
if (doubleBackToExitPressedOnce) {
viewModel.removeIncompleteApp()
finishAffinity()
return
}

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

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

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

Loading

0 comments on commit 06c87aa

Please sign in to comment.