(
34 | inflater,
35 | R.layout.fragment_chat, container, false
36 | ).also {
37 | mBinding = it
38 | mBinding.viewModel = mViewModel
39 | mBinding.lifecycleOwner = this
40 | }.root
41 | }
42 |
43 | private val mChatRoomAdapter: ChatRoomAdapter by lazy { ChatRoomAdapter() }
44 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
45 | super.onViewCreated(view, savedInstanceState)
46 |
47 | mBinding.apply {
48 | mRecyclerView.adapter = mChatRoomAdapter
49 | refreshLayout.setOnRefreshListener { mViewModel.loadChatRooms() }
50 | }
51 |
52 | mViewModel.loadChatRooms()
53 | mViewModel._loadChatRooms.observe(viewLifecycleOwner, _OBSERVER {
54 | mChatRoomAdapter.refreshChatRoom(it)
55 | mBinding.refreshLayout.isRefreshing = false
56 | })
57 |
58 | }
59 |
60 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | WhatsDelete
2 |
3 | A fun, MacGyver application for recovering deleted messages of WhatsApp based on MVVM architecture and Repository Pattern
4 |
5 |
6 |
7 | ## Open-source libraries
8 | - Minimum SDK level 21
9 | - 100% [Kotlin](https://kotlinlang.org/) based
10 | - JetPack
11 | - LiveData - notify domain layer data to views.
12 | - Lifecycle - dispose observing data when lifecycle state changes.
13 | - ViewModel - UI related data holder, lifecycle aware.
14 | - Room Persistence - construct database.
15 | - Architecture
16 | - MVVM Architecture (View - DataBinding - ViewModel - Model)
17 | - Repository pattern
18 | - [Koin](https://github.com/InsertKoinIO/koin) - dependency injection
19 | - [Gson](https://github.com/google/gson) - for serializing and deserializing
20 |
21 |
22 | # License
23 | 
24 | ```
25 | Copyright (c) 2020 TheBotBox
26 |
27 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
28 | documentation files (the "Software"), to deal in the Software without restriction, including without
29 | limitation the rights to use, copy,
30 | modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to
31 | whom the Software is furnished to do so, subject to the following conditions:
32 |
33 | The above copyright notice and this permission notice shall be included in all copies or substantial portions
34 | of the Software.
35 |
36 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
37 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
38 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
39 | CONTRACT, TORT OR OTHERWISE,ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
40 | IN THE SOFTWARE.
41 | ```
42 |
43 | [  ](https://saythanks.io/to/boxforbot%40gmail.com)
44 |
45 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-kapt'
4 | apply plugin: 'kotlin-android-extensions'
5 | apply plugin: "androidx.navigation.safeargs.kotlin"
6 |
7 | android {
8 | compileSdkVersion 29
9 | buildToolsVersion "29.0.3"
10 |
11 | defaultConfig {
12 | applicationId "bot.box.whatsdelete"
13 | minSdkVersion 21
14 | targetSdkVersion 29
15 | versionCode 1
16 | versionName "1.0"
17 |
18 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
19 | }
20 |
21 | dataBinding.enabled = true
22 |
23 | compileOptions {
24 | sourceCompatibility JavaVersion.VERSION_1_8
25 | targetCompatibility JavaVersion.VERSION_1_8
26 | }
27 |
28 | kotlinOptions {
29 | jvmTarget = JavaVersion.VERSION_1_8.toString()
30 | }
31 |
32 | buildTypes {
33 | release {
34 | minifyEnabled false
35 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
36 | }
37 | }
38 | packagingOptions {
39 | exclude 'META-INF/atomicfu.kotlin_module'
40 | }
41 | }
42 |
43 | dependencies {
44 | implementation fileTree(dir: 'libs', include: ['*.jar'])
45 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
46 | implementation 'androidx.appcompat:appcompat:1.1.0'
47 | implementation 'androidx.core:core-ktx:1.2.0'
48 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
49 | testImplementation 'junit:junit:4.12'
50 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
51 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
52 |
53 | //multidex
54 | implementation 'androidx.multidex:multidex:2.0.1'
55 |
56 | //material
57 | implementation 'com.google.android.material:material:1.2.0-alpha06'
58 |
59 | //rx-java
60 | implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
61 | implementation 'io.reactivex.rxjava2:rxjava:2.2.18'
62 |
63 | //picasso
64 | implementation 'com.squareup.picasso:picasso:2.71828'
65 |
66 | //arch components
67 | implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
68 | implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
69 |
70 | //koin
71 | implementation 'org.koin:koin-androidx-viewmodel:2.0.1'
72 | implementation 'org.koin:koin-android:2.0.1'
73 |
74 | //swipe refresh
75 | implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0'
76 |
77 | //navigation controller
78 | implementation "androidx.navigation:navigation-fragment-ktx:2.2.2"
79 | implementation "androidx.navigation:navigation-ui-ktx:2.2.2"
80 |
81 | // Room components
82 | implementation "androidx.room:room-runtime:2.2.5"
83 | kapt "androidx.room:room-compiler:2.2.5"
84 | implementation "androidx.room:room-rxjava2:2.2.5"
85 |
86 | //gson
87 | implementation "com.google.code.gson:gson:2.8.6"
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/app/src/main/java/bot/box/whatsdelete/utils/extension/ActivityExtension.kt:
--------------------------------------------------------------------------------
1 | package bot.box.whatsdelete.utils.extension
2 | /**
3 | * Created by Barry Allen .
4 | * boxforbot@gmail.com
5 | */
6 | import android.app.Activity
7 | import android.app.AlertDialog
8 | import android.app.ProgressDialog
9 | import android.content.Context
10 | import android.content.DialogInterface
11 | import android.content.Intent
12 | import android.graphics.drawable.Drawable
13 | import android.location.LocationManager
14 | import android.net.Uri
15 | import android.view.View
16 | import android.widget.PopupMenu
17 | import androidx.annotation.ColorRes
18 | import androidx.annotation.DrawableRes
19 | import androidx.appcompat.app.AppCompatActivity
20 | import androidx.core.content.ContextCompat
21 | import androidx.fragment.app.*
22 |
23 |
24 | inline fun Activity.startNewActivity() = Intent(
25 | this, T::class.java
26 | ).apply { startActivity(this) }
27 |
28 |
29 | fun showPopUpMenu(menuRes: Int, view: View, listener: PopupMenu.OnMenuItemClickListener) {
30 | val popUp = PopupMenu(view.context, view)
31 | popUp.inflate(menuRes)
32 |
33 | popUp.setOnMenuItemClickListener(listener)
34 | popUp.show()
35 | }
36 |
37 |
38 | fun Activity.getProgressDialog(): ProgressDialog {
39 | return ProgressDialog(this).apply {
40 | setCancelable(false)
41 | setMessage("Please Wait...")
42 | }
43 | }
44 |
45 |
46 | fun Context.getContextCompatDrawable(@DrawableRes drawableResource: Int): Drawable? =
47 | ContextCompat.getDrawable(this, drawableResource)
48 | fun Context.getContextCompatColor(@ColorRes color: Int) = ContextCompat.getColor(this, color)
49 |
50 | fun Activity.getContextCompatDrawable(@DrawableRes drawableResource: Int): Drawable? =
51 | ContextCompat.getDrawable(this, drawableResource)
52 | fun Activity.getContextCompatColor(@ColorRes color: Int) = ContextCompat.getColor(this, color)
53 |
54 |
55 | fun FragmentActivity.showADialog(
56 | message: Int,
57 | buttonPositive: Int,
58 | buttonNegative: Int,
59 | onPositiveButton: () -> Unit,
60 | onNegativeButton: () -> Unit
61 | ) {
62 | showADialog(
63 | this,
64 | this.resources.getString(message),
65 | this.resources.getString(buttonPositive),
66 | this.resources.getString(buttonNegative),
67 | onPositiveButton,
68 | onNegativeButton
69 | )
70 | }
71 |
72 | private fun showADialog(
73 | context: FragmentActivity,
74 | message: String,
75 | buttonPositive: String?,
76 | buttonNegative: String?,
77 | onPositiveButton: () -> Unit,
78 | onNegativeButton: () -> Unit
79 | ) {
80 | val builder =
81 | AlertDialog.Builder(context)
82 | builder.setMessage("" + message)
83 | builder.setCancelable(false)
84 | builder.setPositiveButton(
85 | buttonPositive
86 | ) { dialog: DialogInterface?, _: Int ->
87 | dialog?.dismiss()
88 | onPositiveButton.invoke()
89 | }
90 | builder.setNegativeButton(
91 | buttonNegative
92 | ) { dialog: DialogInterface?, _: Int ->
93 | dialog?.dismiss()
94 | onNegativeButton.invoke()
95 | }
96 | builder.setOnCancelListener { dialog: DialogInterface? ->
97 | dialog?.dismiss()
98 | }
99 | val dialog = builder.create()
100 | try {
101 | dialog.setCanceledOnTouchOutside(false)
102 | if (!context.isFinishing) {
103 | dialog.show()
104 | }
105 | } catch (e: Exception) {
106 | e.printStackTrace()
107 | }
108 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_chatroom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
9 |
10 |
11 |
15 |
16 |
24 |
25 |
31 |
32 |
39 |
40 |
41 |
50 |
51 |
60 |
61 |
62 |
70 |
71 |
72 |
73 |
83 |
84 |
91 |
92 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | xmlns:android
17 |
18 | ^$
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | xmlns:.*
28 |
29 | ^$
30 |
31 |
32 | BY_NAME
33 |
34 |
35 |
36 |
37 |
38 |
39 | .*:id
40 |
41 | http://schemas.android.com/apk/res/android
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | .*:name
51 |
52 | http://schemas.android.com/apk/res/android
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | name
62 |
63 | ^$
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | style
73 |
74 | ^$
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 | .*
84 |
85 | ^$
86 |
87 |
88 | BY_NAME
89 |
90 |
91 |
92 |
93 |
94 |
95 | .*
96 |
97 | http://schemas.android.com/apk/res/android
98 |
99 |
100 | ANDROID_ATTRIBUTE_ORDER
101 |
102 |
103 |
104 |
105 |
106 |
107 | .*
108 |
109 | .*
110 |
111 |
112 | BY_NAME
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
--------------------------------------------------------------------------------
/app/src/main/java/bot/box/whatsdelete/ui/adapter/ChatRoomAdapter.kt:
--------------------------------------------------------------------------------
1 | package bot.box.whatsdelete.ui.adapter
2 |
3 | /**
4 | * Created by Barry Allen .
5 | * boxforbot@gmail.com
6 | */
7 | import android.graphics.BitmapFactory
8 | import android.graphics.drawable.ColorDrawable
9 | import android.os.Build
10 | import android.view.LayoutInflater
11 | import android.view.View
12 | import android.view.ViewGroup
13 | import androidx.core.content.ContextCompat
14 | import androidx.databinding.DataBindingUtil
15 | import androidx.recyclerview.widget.RecyclerView
16 | import bot.box.whatsdelete.R
17 | import bot.box.whatsdelete.data.database.entity.ChatRoom
18 | import bot.box.whatsdelete.databinding.ItemChatroomBinding
19 | import bot.box.whatsdelete.utils.Utils
20 | import bot.box.whatsdelete.utils.extension.getContextCompatColor
21 | import bot.box.whatsdelete.utils.extension.getContextCompatDrawable
22 |
23 | class ChatRoomAdapter : RecyclerView.Adapter() {
24 |
25 | private lateinit var mBinding: ItemChatroomBinding
26 | private var mChatRooms: MutableList? = null
27 | private var mSelectedChat: List = ArrayList()
28 |
29 | fun refreshChatRoom(mList: MutableList) {
30 | this.mChatRooms = mList
31 | notifyDataSetChanged()
32 | }
33 |
34 | fun refreshSelectedChat(mList: List) {
35 | this.mSelectedChat = mList
36 | notifyDataSetChanged()
37 | }
38 |
39 | fun refreshList() {
40 | notifyDataSetChanged()
41 | }
42 |
43 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChatRoomHolder {
44 | return ChatRoomHolder(
45 | DataBindingUtil.inflate(
46 | LayoutInflater.from(parent.context),
47 | R.layout.item_chatroom,
48 | parent,
49 | false
50 | ).also { mBinding = it }
51 | )
52 | }
53 |
54 | override fun getItemCount(): Int = if (!mChatRooms.isNullOrEmpty()) mChatRooms!!.size else 0
55 |
56 | override fun onBindViewHolder(holder: ChatRoomHolder, position: Int) {
57 | mBinding.chatRoom = mChatRooms!![position]
58 |
59 | val colorDrawableSelected =
60 | holder.binding.root.context.getContextCompatDrawable(R.color.foreground_chat_select)
61 | val colorDrawableTransparent =
62 | holder.binding.root.context.getContextCompatDrawable(android.R.color.transparent)
63 |
64 |
65 | if (mSelectedChat.contains(mChatRooms!![position].name)) { // when items are selected
66 |
67 | holder.binding.ivUserIconSelected.visibility = View.VISIBLE // show dp selected icon
68 |
69 |
70 | if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) { // showing foreground selection
71 | holder.binding.parent.foreground = colorDrawableSelected
72 | } else {
73 | holder.binding.parent.apply {
74 | setBackgroundColor(context.getContextCompatColor(R.color.foreground_chat_select))
75 | }
76 | }
77 | } else { // when items are unselected
78 | holder.binding.ivUserIconSelected.visibility = View.GONE // hide dp selected icon
79 |
80 |
81 | if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) { // transparent foreground selection
82 | holder.binding.parent.foreground = colorDrawableTransparent
83 | } else {
84 | holder.binding.parent.apply {
85 | setBackgroundColor(context.getContextCompatColor(android.R.color.transparent))
86 | }
87 | }
88 | }
89 | holder.binding.tvUserName.text = mChatRooms?.get(position)?.name
90 |
91 |
92 | if (mChatRooms?.get(position)?.dp != null) { // set dp
93 | holder.binding.ivUserIcon.setImageBitmap(
94 | BitmapFactory.decodeByteArray(
95 | mChatRooms?.get(position)?.dp,
96 | 0,
97 | mChatRooms!![position].dp.size
98 | )
99 | )
100 | } else {
101 | holder.binding.ivUserIcon.setImageResource(R.drawable.user_icon)
102 | }
103 | }
104 |
105 |
106 | class ChatRoomHolder(val binding: ItemChatroomBinding) : RecyclerView.ViewHolder(binding.root)
107 | }
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/java/bot/box/whatsdelete/ui/service/ChatService.kt:
--------------------------------------------------------------------------------
1 | package bot.box.whatsdelete.ui.service
2 |
3 | /**
4 | * Created by Barry Allen .
5 | * boxforbot@gmail.com
6 | */
7 | import android.app.Notification
8 | import android.app.Service
9 | import android.content.Intent
10 | import android.graphics.Bitmap
11 | import android.graphics.BitmapFactory
12 | import android.os.Bundle
13 | import android.service.notification.NotificationListenerService
14 | import android.service.notification.StatusBarNotification
15 | import android.util.Log
16 | import bot.box.whatsdelete.R
17 | import bot.box.whatsdelete.data.database.entity.Chat
18 | import bot.box.whatsdelete.data.database.entity.ChatRoom
19 | import bot.box.whatsdelete.data.database.entity.Conversation
20 | import bot.box.whatsdelete.data.preference.IPreference
21 | import bot.box.whatsdelete.data.repository.IRepository
22 | import bot.box.whatsdelete.utils.*
23 | import io.reactivex.Completable
24 | import io.reactivex.MaybeObserver
25 | import io.reactivex.Single
26 | import io.reactivex.SingleObserver
27 | import io.reactivex.android.schedulers.AndroidSchedulers
28 | import io.reactivex.disposables.CompositeDisposable
29 | import io.reactivex.disposables.Disposable
30 | import io.reactivex.schedulers.Schedulers
31 | import org.koin.core.KoinComponent
32 | import org.koin.core.inject
33 | import java.io.ByteArrayOutputStream
34 |
35 |
36 | class ChatService : NotificationListenerService(), KoinComponent {
37 | private val TAG = ChatService::class.java.simpleName
38 |
39 |
40 | private val iPreference by inject()
41 | private val iRepository by inject()
42 |
43 | private val disposable = CompositeDisposable()
44 |
45 | override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
46 | return Service.START_STICKY
47 | }
48 |
49 | override fun onListenerConnected() {
50 | super.onListenerConnected()
51 | }
52 |
53 | override fun onListenerDisconnected() {
54 | super.onListenerDisconnected()
55 | }
56 |
57 | override fun onLowMemory() {
58 | super.onLowMemory()
59 | }
60 |
61 | override fun onNotificationPosted(sbn: StatusBarNotification?, rankingMap: RankingMap?) {
62 | super.onNotificationPosted(sbn, rankingMap)
63 | }
64 |
65 | override fun onNotificationPosted(sbn: StatusBarNotification?) {
66 | super.onNotificationPosted(sbn)
67 |
68 | if (!iPreference.isChatRecoveryServiceEnabled()) return
69 | if (sbn!!.notification.flags and Notification.FLAG_GROUP_SUMMARY != 0) return
70 |
71 | if (sbn.packageName == WHATSAPP_PACKAGE) {
72 | val bundle: Bundle = sbn.notification.extras
73 | val name: String? = bundle.getString("android.title")
74 | val message: String? =
75 | if (bundle.getCharSequence("android.text") != null) bundle.getCharSequence("android.text").toString() else ""
76 |
77 | val largeIcon: Bitmap = try {
78 | bundle.get(Notification.EXTRA_LARGE_ICON) as Bitmap
79 | } catch (e: Exception) {
80 | BitmapFactory.decodeResource(resources, R.drawable.user_icon)
81 | }
82 |
83 | if (name != null && message != null) { // do not save these messages in database as these are application generated messages
84 | if (name == WHATSAPP ||
85 | name == WHATSAPP_WEB ||
86 | name == FINISHED_BACKUP ||
87 | name == BACKUP_PROGRESS ||
88 | name == BACKUP_PAUSED ||
89 | name == YOU ||
90 | message == CHECKING_NEW_MESSAGE ||
91 | message == CHECKING_WEB_LOGIN ||
92 | message == BACKUP_INFO ||
93 | message == WAITING_FOR_WIFI ||
94 | message == RESTORE_MEDIA
95 | ) return
96 | }
97 |
98 | /**
99 | * firstly will check if user exist or not in db
100 | * if user does not exist, onError block will be called in that case.
101 | * & if user exist then we will update new message in existing message array
102 | */
103 | disposable.add(
104 | iRepository.fetchChatsOfUser(name).subscribeOn(Schedulers.io())
105 | .observeOn(Schedulers.io())
106 | .subscribe(userFound@{ chat ->
107 | val currentTime = System.currentTimeMillis()
108 | /**
109 | * avoid saving redundant message in db
110 | * Case handled: if message in notification tray is unread
111 | * and a new message comes in, then the unread message get saved again.
112 | */
113 | if (chat.lastMessage == message)
114 | return@userFound
115 |
116 | val chatList = ArrayList()
117 | for (conversation in chat.allMessages) {
118 | chatList.add(conversation)
119 | }
120 |
121 | val conversation = Conversation().apply {
122 | this.message = message ?: ""
123 | this.isDeleted = false
124 | this.time = currentTime
125 | }
126 | chatList.add(conversation)
127 |
128 | val chatModel =
129 | Chat(name!!, message!!, currentTime, chatList, getByteFromDP(largeIcon))
130 |
131 | iRepository.insertMessage(chatModel)
132 | }, {
133 | Log.d(TAG, "User with this name does not exist in db $it")
134 | disposable.add(
135 | Completable.fromAction {
136 | val currentTime = System.currentTimeMillis()
137 | val chatList = ArrayList()
138 | val conversation = Conversation().apply {
139 | this.message = message ?: ""
140 | this.time = currentTime
141 | this.isDeleted = false
142 | }
143 | chatList.add(conversation)
144 |
145 | val chatModel =
146 | Chat(
147 | name!!,
148 | message!!,
149 | currentTime,
150 | chatList,
151 | getByteFromDP(largeIcon)
152 | )
153 |
154 | iRepository.insertMessage(chatModel)
155 | }.subscribeOn(Schedulers.io()).observeOn(Schedulers.io()).subscribe({
156 | Log.d(TAG, "User inserted in db")
157 | }, {
158 | Log.d(TAG, "Error: User is not inserted into db $it")
159 | })
160 | )
161 |
162 | })
163 | )
164 | }
165 | }
166 |
167 | private fun getByteFromDP(dp: Bitmap): ByteArray {
168 | val stream = ByteArrayOutputStream()
169 | dp.compress(Bitmap.CompressFormat.PNG, 100, stream)
170 | return stream.toByteArray()
171 | }
172 |
173 | override fun onDestroy() {
174 | super.onDestroy()
175 | if (!disposable.isDisposed) disposable.dispose()
176 | }
177 | }
--------------------------------------------------------------------------------