Auto-Update hinzugefügt
parent
d40965a44c
commit
9a9fb2b52d
@ -0,0 +1,65 @@
|
|||||||
|
package com.cyb3rko.techniklogger.utils
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.app.AlertDialog
|
||||||
|
import android.app.Dialog
|
||||||
|
import android.app.DownloadManager
|
||||||
|
import android.content.Context.DOWNLOAD_SERVICE
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.graphics.Typeface
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.os.Environment
|
||||||
|
import android.view.Gravity
|
||||||
|
import android.webkit.URLUtil
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.appcompat.app.AppCompatDialogFragment
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.view.setPadding
|
||||||
|
import com.cyb3rko.techniklogger.BuildConfig
|
||||||
|
import es.dmoral.toasty.Toasty
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
|
class Updater : AppCompatDialogFragment() {
|
||||||
|
|
||||||
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
|
val sharedPref = activity!!.getSharedPreferences("Safe", 0)
|
||||||
|
|
||||||
|
val builder: AlertDialog.Builder = AlertDialog.Builder(context)
|
||||||
|
|
||||||
|
val titleView = TextView(context)
|
||||||
|
titleView.setPadding(32)
|
||||||
|
titleView.gravity = Gravity.CENTER_HORIZONTAL
|
||||||
|
titleView.typeface = Typeface.DEFAULT_BOLD
|
||||||
|
titleView.textSize = 22f
|
||||||
|
titleView.text = "Neues Update verfügbar"
|
||||||
|
|
||||||
|
val messageView = TextView(context)
|
||||||
|
messageView.setPadding(32)
|
||||||
|
messageView.gravity = Gravity.CENTER_HORIZONTAL
|
||||||
|
messageView.textSize = 16f
|
||||||
|
messageView.text = "Das Update '${sharedPref.getString("neuesteVersion", "")}' steht zum Download bereit!\n\nAktuell installierte Version: " +
|
||||||
|
"'${BuildConfig.VERSION_NAME}'"
|
||||||
|
|
||||||
|
builder.setView(messageView)
|
||||||
|
.setCancelable(false)
|
||||||
|
.setCustomTitle(titleView)
|
||||||
|
.setPositiveButton("Herunterladen") { _, _ ->
|
||||||
|
if (ContextCompat.checkSelfPermission(context!!, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
val link = "https://cdn.cyb3rko.de/Apps/Technik-Logger/Technik-Logger%20v${sharedPref.getString("neuesteVersion", "")}.apk"
|
||||||
|
val request = DownloadManager.Request(Uri.parse(link))
|
||||||
|
.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(link, null, null))
|
||||||
|
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
|
||||||
|
|
||||||
|
val downloadManager: DownloadManager = activity!!.getSystemService(DOWNLOAD_SERVICE) as DownloadManager
|
||||||
|
downloadManager.enqueue(request)
|
||||||
|
} else {
|
||||||
|
Toasty.error(context!!, "Fehlende Berechtigung, erteilen Sie diese beim nächsten App-Start", Toasty.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.setNegativeButton("Abbrechen") { _, _ -> }
|
||||||
|
|
||||||
|
return builder.create()
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue