Skip to content

Commit

Permalink
global: remove notifications UI/listener/permission-request/service
Browse files Browse the repository at this point in the history
  • Loading branch information
iTaysonLab committed Apr 17, 2020
1 parent 9f0f034 commit 944cfce
Show file tree
Hide file tree
Showing 12 changed files with 8 additions and 529 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "ua.itaysonlab.homefeeder"
minSdkVersion 21
targetSdkVersion 29
versionCode 6
versionName "pre-alpha 6"
versionCode 7
versionName "pre-alpha 7"
}
buildTypes {
release {
Expand Down
8 changes: 0 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@
android:name="service.api.version"
android:value="7" />
</service>
<service
android:name=".overlay.notification.NotificationListener"
android:label="@string/service_label"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
package ua.itaysonlab.homefeeder.activites

import android.Manifest
import android.content.ComponentName
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import com.google.android.material.bottomnavigation.BottomNavigationView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.android.synthetic.main.activity_main.*
import ua.itaysonlab.homefeeder.HFApplication
import ua.itaysonlab.homefeeder.R
import ua.itaysonlab.homefeeder.kt.isNotificationServiceGranted
import ua.itaysonlab.homefeeder.overlay.notification.NotificationListener

class MainActivity : AppCompatActivity() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (!isNotificationServiceGranted()) {
requestNotificationPermission()
} else {
findNavController(R.id.nav_host_fragment).navigate(R.id.navigation_settings)
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Expand All @@ -46,7 +32,6 @@ class MainActivity : AppCompatActivity() {
setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)

if (!isNotificationServiceGranted()) requestNotificationPermission()
checkStoragePermission()
}

Expand All @@ -70,19 +55,6 @@ class MainActivity : AppCompatActivity() {
}
}

fun requestNotificationPermission() {
MaterialAlertDialogBuilder(this, R.style.MDialog).apply {
setTitle(R.string.allow_notify_pref)
setMessage(R.string.allow_notify_desc)
setPositiveButton(R.string.allow_notify_to_settings) { _, _ ->
startActivityForResult(Intent(HFApplication.ACTION_MANAGE_LISTENERS).putExtra(
":settings:fragment_args_key", ComponentName(context, NotificationListener::class.java).flattenToString()
), 1)
}
setNeutralButton(R.string.cancel, null)
}.show()
}

private fun showStorageAlert() {
MaterialAlertDialogBuilder(this, R.style.MDialog).apply {
setTitle(R.string.storage_alert)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,16 @@ import ua.itaysonlab.homefeeder.HFApplication
import ua.itaysonlab.homefeeder.R
import ua.itaysonlab.homefeeder.activites.MainActivity
import ua.itaysonlab.homefeeder.fragments.base.FixedPreferencesFragment
import ua.itaysonlab.homefeeder.kt.isNotificationServiceGranted
import ua.itaysonlab.homefeeder.prefui.HFElementPreview

class PreferenceFragment : FixedPreferencesFragment() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.pref_general, rootKey)

bindPermissionHeader()
bindAppearance()
if (BuildConfig.DEBUG) bindDebug()
}

private fun bindPermissionHeader() {
val permission = findPreference<Preference>("hf_permission")!!
if (activity!!.isNotificationServiceGranted()) {
permission.setIcon(R.drawable.ic_notifications_24)
permission.setSummary(R.string.allow_notify_pref_granted)
} else {
permission.setOnPreferenceClickListener {
(activity as MainActivity).requestNotificationPermission()
true
}
}
}

private fun bindAppearance() {
val summaryProviderInstance = ListPreference.SimpleSummaryProvider.getInstance()

Expand Down
5 changes: 0 additions & 5 deletions app/src/main/java/ua/itaysonlab/homefeeder/kt/KtExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ const val LIGHT_BORDER = 0.5f
fun Int.isLight() = ColorUtils.calculateLuminance(this) > LIGHT_BORDER
fun Int.isDark() = ColorUtils.calculateLuminance(this) < LIGHT_BORDER

fun Context.isNotificationServiceGranted(): Boolean {
val enabledNotificationListeners = Settings.Secure.getString(contentResolver, "enabled_notification_listeners")
return !(enabledNotificationListeners == null || !enabledNotificationListeners.contains(packageName))
}

fun Bundle.dump(tag: String) {
keySet().forEach {
val item = get(it)
Expand Down
22 changes: 5 additions & 17 deletions app/src/main/java/ua/itaysonlab/homefeeder/overlay/OverlayKt.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package ua.itaysonlab.homefeeder.overlay

import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.content.res.ColorStateList
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.os.IBinder
import android.view.View
import androidx.appcompat.view.ContextThemeWrapper
import androidx.recyclerview.widget.LinearLayoutManager
Expand All @@ -16,19 +13,15 @@ import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.overlay_header.view.*
import kotlinx.android.synthetic.main.overlay_layout.view.*
import ua.itaysonlab.hfsdk.FeedItem
import ua.itaysonlab.hfsdk.IFeedInterfaceCallback
import ua.itaysonlab.homefeeder.HFApplication
import ua.itaysonlab.homefeeder.R
import ua.itaysonlab.homefeeder.activites.MainActivity
import ua.itaysonlab.homefeeder.kt.clearLightFlags
import ua.itaysonlab.homefeeder.kt.isDark
import ua.itaysonlab.homefeeder.kt.isNotificationServiceGranted
import ua.itaysonlab.homefeeder.kt.setLightFlags
import ua.itaysonlab.homefeeder.overlay.feed.FeedAdapter
import ua.itaysonlab.homefeeder.overlay.launcherapi.LauncherAPI
import ua.itaysonlab.homefeeder.overlay.launcherapi.OverlayThemeHolder
import ua.itaysonlab.homefeeder.overlay.notification.NotificationListener
import ua.itaysonlab.homefeeder.overlay.notification.NotificationWrapper
import ua.itaysonlab.homefeeder.pluginsystem.PluginConnector
import ua.itaysonlab.homefeeder.preferences.HFPreferences
import ua.itaysonlab.homefeeder.theming.Theming
Expand All @@ -38,10 +31,6 @@ import ua.itaysonlab.replica.vkpopup.DialogActionsVcByPopup
import ua.itaysonlab.replica.vkpopup.PopupItem

class OverlayKt(val context: Context): OverlayController(context, R.style.AppTheme, R.style.WindowTheme), OverlayBridge.OverlayBridgeCallback {
override fun getNotificationListener(): NotificationListener {
return mService
}

companion object {
const val LOG_TAG = "OverlayKt"
}
Expand All @@ -51,8 +40,6 @@ class OverlayKt(val context: Context): OverlayController(context, R.style.AppThe

private lateinit var rootView: View
private lateinit var adapter: FeedAdapter
private lateinit var mService: NotificationListener
private var mBound = false

private val list = mutableListOf<FeedItem>()

Expand Down Expand Up @@ -84,14 +71,15 @@ class OverlayKt(val context: Context): OverlayController(context, R.style.AppThe
}

private fun updateStubUi() {
if (!this.isNotificationServiceGranted()) {
// TODO: make stub for no datasources
/*if (!this.isNotificationServiceGranted()) {
rootView.nas_title.setTextColor(themeHolder.currentTheme.get(Theming.Colors.TEXT_COLOR_PRIMARY.position))
rootView.nas_text.setTextColor(themeHolder.currentTheme.get(Theming.Colors.TEXT_COLOR_SECONDARY.position))
rootView.nas_icon.imageTintList = ColorStateList.valueOf(themeHolder.currentTheme.get(Theming.Colors.TEXT_COLOR_PRIMARY.position))
rootView.nas_reload.setTextColor(themeHolder.currentTheme.get(Theming.Colors.TEXT_COLOR_PRIMARY.position))
rootView.nas_action.setBackgroundColor(themeHolder.currentTheme.get(Theming.Colors.TEXT_COLOR_PRIMARY.position))
rootView.nas_action.setTextColor(themeHolder.currentTheme.get(Theming.Colors.CARD_BG.position))
}
}*/

val theme = if (themeHolder.currentTheme.get(Theming.Colors.OVERLAY_BG.position).isDark()) Theming.defaultDarkThemeColors else Theming.defaultLightThemeColors
rootView.header_preferences.imageTintList = ColorStateList.valueOf(theme.get(Theming.Colors.TEXT_COLOR_PRIMARY.position))
Expand Down Expand Up @@ -160,13 +148,13 @@ class OverlayKt(val context: Context): OverlayController(context, R.style.AppThe
startActivity(Intent(HFApplication.ACTION_MANAGE_LISTENERS))
}
rootView.nas_reload.setOnClickListener {
if (this.isNotificationServiceGranted()) {
/*if (this.isNotificationServiceGranted()) {
//bindService()
rootView.overlay_root.visibility = View.VISIBLE
rootView.no_access_stub.visibility = View.GONE
} else {
Snackbar.make(rootView.user_root, R.string.overlay_no_permission_snackbar, Snackbar.LENGTH_LONG).show()
}
}*/
}
}

Expand Down
Loading

0 comments on commit 944cfce

Please sign in to comment.