Skip to content

Commit

Permalink
app: remove updater
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanndroid committed Jun 15, 2022
1 parent 0193b8b commit 1f79e12
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 168 deletions.
12 changes: 5 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'com.google.gms.google-services'
}

android {
Expand All @@ -11,8 +10,8 @@ android {
applicationId "de.dlyt.yanndroid.notinotes"
minSdk 26
targetSdk 31
versionCode 5
versionName "1.3.1"
versionCode 6
versionName "1.3.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -34,10 +33,9 @@ android {

dependencies {

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.google.firebase:firebase-database-ktx:20.0.4'
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.code.gson:gson:2.9.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand Down
Binary file added app/release/app-release.aab
Binary file not shown.
Binary file modified app/release/app-release.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 5,
"versionName": "1.3.1",
"versionCode": 6,
"versionName": "1.3.2",
"outputFile": "app-release.apk"
}
],
Expand Down
12 changes: 0 additions & 12 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

<uses-permission android:name="android.permission.BROADCAST_CLOSE_SYSTEM_DIALOGS" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />

<application
android:icon="@mipmap/ic_launcher"
Expand All @@ -23,16 +21,6 @@
</intent-filter>
</service>

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>

</application>

</manifest>
115 changes: 0 additions & 115 deletions app/src/main/java/de/dlyt/yanndroid/notinotes/QSTile.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package de.dlyt.yanndroid.notinotes

import android.annotation.SuppressLint
import android.app.DownloadManager
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.PackageManager
import android.content.res.ColorStateList
import android.graphics.PixelFormat
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.provider.Settings
import android.service.quicksettings.TileService
import android.util.Log
Expand All @@ -25,14 +22,8 @@ import android.view.WindowManager
import android.widget.*
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.FileProvider
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
import com.google.firebase.database.FirebaseDatabase
import com.google.firebase.database.ValueEventListener
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import java.io.File
import java.io.Serializable
import java.util.stream.Collectors

Expand All @@ -48,10 +39,6 @@ class QSTile : TileService() {
private val ACTION_SHOW_NOTE = "de.dlyt.yanndroid.notinotes.SHOW_NOTE"
private val EXTRA_NOTE = "intent_note"

private val ACTION_APP_UPDATE = "de.dlyt.yanndroid.notinotes.UPDATE"
private val EXTRA_UPDATE_URL = "UPDATE_URL"
private val EXTRA_UPDATE_VNM = "UPDATE_VNM"

var COLORS = intArrayOf(
R.color.color_1,
R.color.color_2,
Expand All @@ -77,14 +64,6 @@ class QSTile : TileService() {
private var notes: ArrayList<Note> = ArrayList()
private val mBroadcastReceiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == ACTION_APP_UPDATE) {
installUpdate(
intent.getStringExtra(EXTRA_UPDATE_URL),
intent.getStringExtra(EXTRA_UPDATE_VNM)
)
return
}

val note: Note = (intent.getSerializableExtra(EXTRA_NOTE) ?: return) as Note
when (intent.action) {
ACTION_EDIT_DIALOG -> editNotePopup(note)
Expand Down Expand Up @@ -129,10 +108,7 @@ class QSTile : TileService() {
it.addAction(ACTION_DELETE_DIALOG)
it.addAction(ACTION_DELETE_NOTE)
it.addAction(ACTION_SHOW_NOTE)
it.addAction(ACTION_APP_UPDATE)
})

checkForUpdate()
}

override fun onTileAdded() {
Expand Down Expand Up @@ -410,97 +386,6 @@ class QSTile : TileService() {

}

/** #### App update #### **/

private fun checkForUpdate() {
FirebaseDatabase.getInstance().reference.child(context.getString(R.string.firebase_childName))
.addValueEventListener(object : ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
try {
val hashMap = HashMap<String?, String?>()
for (child in snapshot.children) hashMap[child.key] = child.value.toString()

if ((hashMap[context.getString(R.string.firebase_versionCode)]?.toInt()
?: 0) > context.packageManager.getPackageInfo(
context.packageName,
0
).versionCode
) showUpdateNoti(
hashMap[context.getString(R.string.firebase_apk)]!!,
hashMap[context.getString(R.string.firebase_versionName)]!!
)
} catch (e: PackageManager.NameNotFoundException) {
Log.e("checkForUpdate", e.message)
}
}

override fun onCancelled(error: DatabaseError) {
Log.e("checkForUpdate", error.message)
}
})
}

@SuppressLint("LaunchActivityFromNotification")
private fun showUpdateNoti(url: String, versionName: String) {
val pendingIntent = PendingIntent.getBroadcast(
context,
-2,
Intent(ACTION_APP_UPDATE).also {
it.putExtra(EXTRA_UPDATE_URL, url).putExtra(EXTRA_UPDATE_VNM, versionName)
},
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)

NotificationManagerCompat.from(this)
.notify(
-2, NotificationCompat.Builder(context, NOTIFICATION_CHANNEL)
.setSmallIcon(R.drawable.ic_note)
.setContentTitle(getString(R.string.update_available))
.setContentText(getString(R.string.update_available_desc, versionName))
.addAction(
R.drawable.ic_download,
getString(R.string.download),
pendingIntent
)
.setContentIntent(pendingIntent)
.build()
)
}

private fun installUpdate(url: String, versionName: String) {
val destination = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
.toString() + "/" + context.getString(R.string.app_name) + "_" + versionName + ".apk"

val file = File(destination)
if (file.exists()) file.delete()

val request = DownloadManager.Request(Uri.parse(url))
request.setMimeType("application/vnd.android.package-archive")
request.setTitle(context.getString(R.string.app_name).toString() + " Update")
request.setDescription(versionName)
request.setDestinationUri(Uri.parse("file://$destination"))

val onComplete: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(ctxt: Context, intent: Intent) {
val apkFileUri = FileProvider.getUriForFile(
context,
context.applicationContext.packageName + ".provider",
File(destination)
)
val install = Intent(Intent.ACTION_VIEW)
install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
install.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true)
install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
install.setDataAndType(apkFileUri, "application/vnd.android.package-archive")
startActivityAndCollapse(install)
context.unregisterReceiver(this)
}
}
context.registerReceiver(onComplete, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE))
(context.getSystemService(DOWNLOAD_SERVICE) as DownloadManager).enqueue(request)
}


/** #### Detail view (samsung only) #### **/

fun semGetSettingsIntent(): Intent =
Expand Down
11 changes: 0 additions & 11 deletions app/src/main/res/drawable-v24/ic_download.xml

This file was deleted.

8 changes: 0 additions & 8 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
<resources>
<string name="firebase_childName" translatable="false">NotiNotes</string>
<string name="firebase_versionCode" translatable="false">versionCode</string>
<string name="firebase_versionName" translatable="false">versionName</string>
<string name="firebase_apk" translatable="false">apk</string>

<string name="app_name">NotiNotes</string>
<string name="edit">Edit</string>
<string name="del">Delete</string>
Expand All @@ -15,9 +10,6 @@
<string name="notes">Notes</string>
<string name="del_x">Delete %s ?</string>
<string name="permission_toast">Enable NotiNotes here</string>
<string name="update_available">Update available</string>
<string name="download">Download</string>
<string name="update_available_desc">A new version is available: %s</string>
<string name="hide_on_lockscreen">Hide on Lockscreen</string>
<string name="locked">Lock in Notifications</string>
</resources>
12 changes: 0 additions & 12 deletions app/src/main/res/xml/file_provider_paths.xml

This file was deleted.

1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ buildscript {
dependencies {
classpath "com.android.tools.build:gradle:7.0.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
classpath 'com.google.gms:google-services:4.3.10'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down

0 comments on commit 1f79e12

Please sign in to comment.