0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-23 11:45:11 +00:00
This commit is contained in:
X1nto 2020-07-11 14:45:39 +04:00
parent 3c6ff26e83
commit 6d24a08075
5 changed files with 19 additions and 4 deletions

View file

@ -5,6 +5,7 @@ import android.app.Service
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.net.Uri
import android.os.IBinder
import androidx.localbroadcastmanager.content.LocalBroadcastManager
@ -28,7 +29,7 @@ class MicrogDownloadService: Service() {
private var downloadId: Long = 0
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
registerReceiver(receiver, null)
registerReceiver(receiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE))
downloadMicrog()
stopSelf()
return START_NOT_STICKY

View file

@ -5,6 +5,7 @@ import android.app.Service
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.net.Uri
import android.os.Build
import android.os.IBinder
@ -31,6 +32,7 @@ class VancedDownloadService: Service() {
private var apkType: String = "arch"
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
registerReceiver(receiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE))
downloadSplits()
stopSelf()
return START_NOT_STICKY

View file

@ -31,7 +31,12 @@ class URLChangeFragment : DialogFragment() {
val prefs = PreferenceManager.getDefaultSharedPreferences(activity)
urlField.hint = prefs.getString("install_url", baseUrl)
view.findViewById<MaterialButton>(R.id.url_save).setOnClickListener {
prefs.edit().putString("install_url", urlField.text.toString()).apply()
if (urlField.text.endsWith("/"))
prefs.edit().putString("install_url", urlField.text.removeSuffix("/").toString()).apply()
if (!urlField.text.startsWith("https://"))
prefs.edit().putString("install_url", "https://${urlField.text}").apply()
dismiss()
}
view.findViewById<MaterialButton>(R.id.url_reset).setOnClickListener {

View file

@ -5,6 +5,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Context.DOWNLOAD_SERVICE
import android.content.Intent
import android.content.IntentFilter
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.net.Uri
@ -45,7 +46,7 @@ class UpdateCheckFragment : DialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
activity?.registerReceiver(receiver, null)
activity?.registerReceiver(receiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE))
checkUpdates()
view.findViewById<Button>(R.id.update_center_dismiss).setOnClickListener { dismiss() }
view.findViewById<MaterialButton>(R.id.update_center_recheck).setOnClickListener{ checkUpdates() }

View file

@ -46,15 +46,17 @@ object InternetTools {
client.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
toReturn = 0
returnVal(toReturn)
}
override fun onResponse(call: Call, response: Response) {
toReturn = JSONObject(response.body?.string()!!).getInt(obj)
returnVal(toReturn)
Log.d("VMResponse", toReturn.toString())
}
})
Log.d("VMResponse", toReturn.toString())
return toReturn
}
@ -80,6 +82,10 @@ object InternetTools {
return toReturn
}
fun returnVal(value: Any): Any {
return value
}
fun isUpdateAvailable(): Boolean {
val checkUrl = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/manager.json")
val remoteVersion = checkUrl.get("versionCode").asInt