Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/306/feature to add custom package #340

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ae0dbd2
refactor move App class to logs package
spuday90 Jul 9, 2021
341af96
convert App class to Room Entity
spuday90 Jul 9, 2021
2414229
create interface to read and write supported app data to db
spuday90 Jul 9, 2021
42562ee
read/write supported app data from db
spuday90 Jul 9, 2021
01fa773
bugfix use packagename itself as primary key
spuday90 Jul 9, 2021
7ce7765
implement feature to add custom app
spuday90 Jul 9, 2021
f935927
allow enabling the custom package with option to install the app
spuday90 Jul 10, 2021
398f0c3
no need to check app install from google play
spuday90 Jul 12, 2021
128c9e5
show install option for all the apps
spuday90 Jul 12, 2021
615becb
check if the entered package already exists
spuday90 Jul 12, 2021
be3e78c
move add custom apps to EnabledAppsFragment
spuday90 Jul 13, 2021
877b838
on saving finish the activity to will show the updated list immediately
spuday90 Jul 13, 2021
420449d
replace custom apps editbox with recyclerview
spuday90 Jul 23, 2021
01d7a18
fetch installed apps list and display in recyclerview, also handle se…
spuday90 Jul 23, 2021
b5fef14
add shimmer effect for apps loading
spuday90 Jul 23, 2021
315e29c
add support to remove app from db
spuday90 Jul 23, 2021
43eab31
add fab to save the selection changes
spuday90 Jul 23, 2021
07b5870
change design to checkboxes, also add/remove app to db immediately
spuday90 Jul 24, 2021
ce66641
remove unnecessary interface and methods
spuday90 Jul 24, 2021
1edfb9d
bugfix use onclicklistener instead of checkchange listener as it gets…
spuday90 Jul 24, 2021
07598f0
Merge branch 'main' into feature/306/feature_to_add_custom_package
spuday90 Jul 24, 2021
51dde6e
refactor remove unused strings
spuday90 Jul 24, 2021
abb51ae
show beta feature warning
spuday90 Jul 26, 2021
f781d2f
filter out officially supported apps from list
spuday90 Jul 26, 2021
b8d314b
sort the list selected apps first
spuday90 Jul 26, 2021
6e19f99
use separate textview and checkbox to avoid rtl issue
spuday90 Jul 27, 2021
2e6356c
bugfix change title color to support dark theme
spuday90 Jul 28, 2021
124894a
bugfix handle couldn't detect app
spuday90 Jul 28, 2021
52e9cd0
refactor remove unused value
spuday90 Jul 28, 2021
2139603
Merge branch 'main' into feature/306/feature_to_add_custom_package
hegocre Nov 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,16 @@ dependencies {
annotationProcessor 'androidx.room:room-compiler:2.3.0'
implementation "androidx.core:core-ktx:1.6.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.9.0'
implementation "com.squareup.okhttp3:logging-interceptor:4.7.2"
implementation 'com.github.transferwise:sequence-layout:1.1.1'
implementation "androidx.browser:browser:1.3.0"
implementation 'com.facebook.shimmer:shimmer:0.1.0@aar'
}
repositories {
mavenCentral()
Expand Down
149 changes: 149 additions & 0 deletions app/schemas/com.parishod.watomatic.model.logs.MessageLogsDB/3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
{
"formatVersion": 1,
"database": {
"version": 3,
"identityHash": "7e7d32963dbe325d983a4c069be65e75",
"entities": [
{
"tableName": "message_logs",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `index` INTEGER NOT NULL, `notif_id` TEXT, `notif_title` TEXT, `notif_arrived_time` INTEGER NOT NULL, `notif_is_replied` INTEGER NOT NULL, `notif_replied_msg` TEXT, `notif_reply_time` INTEGER NOT NULL, FOREIGN KEY(`index`) REFERENCES `app_packages`(`index`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "index",
"columnName": "index",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "notifId",
"columnName": "notif_id",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "notifTitle",
"columnName": "notif_title",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "notifArrivedTime",
"columnName": "notif_arrived_time",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "notifIsReplied",
"columnName": "notif_is_replied",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "notifRepliedMsg",
"columnName": "notif_replied_msg",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "notifReplyTime",
"columnName": "notif_reply_time",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [
{
"name": "index_message_logs_index",
"unique": false,
"columnNames": [
"index"
],
"createSql": "CREATE INDEX IF NOT EXISTS `index_message_logs_index` ON `${TABLE_NAME}` (`index`)"
}
],
"foreignKeys": [
{
"table": "app_packages",
"onDelete": "CASCADE",
"onUpdate": "NO ACTION",
"columns": [
"index"
],
"referencedColumns": [
"index"
]
}
]
},
{
"tableName": "app_packages",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`index` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `package_name` TEXT)",
"fields": [
{
"fieldPath": "index",
"columnName": "index",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "packageName",
"columnName": "package_name",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"index"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "supported_apps",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`app_name` TEXT NOT NULL, `package_name` TEXT NOT NULL, PRIMARY KEY(`package_name`))",
"fields": [
{
"fieldPath": "name",
"columnName": "app_name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "packageName",
"columnName": "package_name",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"package_name"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '7e7d32963dbe325d983a4c069be65e75')"
]
}
}
13 changes: 8 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.READ_CONTACTS" />

<permission android:name="android.permission.QUERY_ALL_PACKAGES" />

<queries>
<!-- Specific apps Watomatic interacts with. Required for Android 11+ -->
<package android:name="com.whatsapp" />
<package android:name="com.facebook.orca" />
<package android:name="com.facebook.mlite" />
<intent>
<action android:name="android.intent.action.MAIN" />
</intent>
</queries>

<application
Expand Down Expand Up @@ -87,6 +86,10 @@
android:label="@string/donations_activity_title"
android:parentActivityName=".activity.main.MainActivity"/>

<activity android:name=".activity.customapp.CustomAppsAdditionActivity"
android:label="@string/custom_apps_activity_title"
android:parentActivityName=".activity.advancedsettings.AdvancedSettingsActivity"/>

<service
android:name="com.parishod.watomatic.NotificationService"
android:label="@string/service_name"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.parishod.watomatic.activity.customapp

import android.os.Bundle
import com.parishod.watomatic.R
import com.parishod.watomatic.activity.BaseActivity

class CustomAppsAdditionActivity: BaseActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_custom_apps)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.parishod.watomatic.adapter

import android.content.pm.PackageManager
import android.graphics.ColorMatrix
import android.graphics.ColorMatrixColorFilter
import android.graphics.drawable.Drawable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.CheckBox
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import com.parishod.watomatic.R
import com.parishod.watomatic.model.logs.App
import com.parishod.watomatic.model.utils.DbUtils
import kotlinx.android.synthetic.main.installed_apps_list.view.*
import kotlinx.android.synthetic.main.supported_apps_list.view.appIcon


class InstalledAppsAdapter(private var installedAppsList: List<App>): RecyclerView.Adapter<InstalledAppsAdapter.AppsViewHolder>() {
lateinit var dbUtils: DbUtils
var newlyAddedApps: MutableList<App> = ArrayList()

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AppsViewHolder {
val itemView = LayoutInflater.from(parent.context)
.inflate(R.layout.installed_apps_list, parent, false)

dbUtils = DbUtils(parent.context)
newlyAddedApps = ArrayList<App>(dbUtils.supportedApps)

return AppsViewHolder(itemView)
}

override fun onBindViewHolder(holder: AppsViewHolder, position: Int) {
holder.setData(installedAppsList[position])
}

override fun getItemCount(): Int {
return installedAppsList.size
}

inner class AppsViewHolder(view: View) : RecyclerView.ViewHolder(view){

fun setData(app: App){
try {
val icon: Drawable = itemView.context.packageManager.getApplicationIcon(app.packageName)
itemView.appIcon.setImageDrawable(icon)
} catch (e: PackageManager.NameNotFoundException) {
e.printStackTrace()
val matrix = ColorMatrix()
matrix.setSaturation(0f) //0 means grayscale
val cf = ColorMatrixColorFilter(matrix)
itemView.appIcon.colorFilter = cf
}
itemView.appName.text = app.name
itemView.appNameCheckBox.tag = app
itemView.appNameCheckBox.isChecked = newlyAddedApps.contains(app)
itemView.appNameCheckBox.setOnClickListener{
val view = it as CheckBox
if(view.isChecked){
addToList(view.tag as App)
}else{
removeFromList(view.tag as App)
}
}
itemView.setOnClickListener {
val view = itemView.appNameCheckBox as CheckBox
view.isChecked = !view.isChecked //Toggle checkbox
if(view.isChecked){
addToList(view.tag as App)
}else{
removeFromList(view.tag as App)
}
}
}

fun addToList(app: App){
if(!dbUtils.isPackageAlreadyAdded(app.packageName)) {
dbUtils.insertSupportedApp(app)
itemView.context?.let {
Toast.makeText(it, "${app.name} added to list.", Toast.LENGTH_SHORT).show()
}
}
}

fun removeFromList(app: App){
dbUtils.removeSupportedApp(app)
itemView.context?.let {
Toast.makeText(it, "${app.name} removed from list.", Toast.LENGTH_SHORT).show()
}
}
}
}
Loading