Skip to content

Commit

Permalink
Updater
Browse files Browse the repository at this point in the history
  • Loading branch information
Corewala committed Mar 13, 2022
1 parent 8d70218 commit d7a2cde
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
21 changes: 20 additions & 1 deletion app/src/main/java/corewala/buran/ui/GemActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.content.SharedPreferences
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand All @@ -23,6 +22,7 @@ import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.snackbar.Snackbar
import corewala.*
import corewala.buran.BuildConfig
import corewala.buran.Buran
import corewala.buran.OmniTerm
import corewala.buran.R
Expand All @@ -32,6 +32,7 @@ import corewala.buran.io.database.BuranDatabase
import corewala.buran.io.database.bookmarks.BookmarksDatasource
import corewala.buran.io.gemini.Datasource
import corewala.buran.io.gemini.GeminiResponse
import corewala.buran.io.update.BuranUpdates
import corewala.buran.ui.bookmarks.BookmarkDialog
import corewala.buran.ui.bookmarks.BookmarksDialog
import corewala.buran.ui.content_image.ImageDialog
Expand Down Expand Up @@ -154,6 +155,24 @@ class GemActivity : AppCompatActivity() {
)
}

if(PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
"check_for_updates",
false
)) {
val updates = BuranUpdates()
val latestVersion = updates.getLatestVersion()

if (latestVersion == BuildConfig.VERSION_NAME){
println("No new version available")
} else {
println("New version available")

Snackbar.make(binding.root, getString(R.string.new_version_available), Snackbar.LENGTH_LONG).setAction(getString(R.string.update)) {
updates.installUpdate(this, latestVersion)
}.show()
}
}

binding.addressEdit.setOnEditorActionListener { _, actionId, _ ->
when (actionId) {
EditorInfo.IME_ACTION_GO -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
}
appCategory.addPreference(homePreference)

//Home - Certificates
//Updates ---------------------------------------------
val checkForUpdates = SwitchPreferenceCompat(context)
checkForUpdates.setDefaultValue(true)
checkForUpdates.key = "check_for_updates"
checkForUpdates.title = getString(R.string.check_for_updates)
appCategory.addPreference(checkForUpdates)

//Home - Certificates - Updates
buildClientCertificateSection(context, appCategory)

//Appearance --------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
<string name="no_password">Pas de mot de passe</string>
<string name="use_client_certificate">Utiliser un Certificat Client</string>
<string name="set_home_capsule">Choisir comme capsule d\'accueil</string>
<string name="check_for_updates">Rechercher des nouvelles versions</string>
<string name="new_version_available">Nouvelle version disponible</string>
<string name="history_cleared">Historique vidé</string>
<string name="runtime_cache_cleared">Cache d\'exécution vidé</string>
<string name="show_inline_icons">Icônes de lien en ligne</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
<string name="no_password">No Password</string>
<string name="use_client_certificate">Use Client Certificate</string>
<string name="set_home_capsule">Set home capsule</string>
<string name="check_for_updates">Check for updates</string>
<string name="new_version_available">New version available</string>
<string name="history_cleared">History cleared</string>
<string name="runtime_cache_cleared">Runtime cache cleared</string>
<string name="show_inline_icons">Inline link icons</string>
Expand Down

0 comments on commit d7a2cde

Please sign in to comment.