Skip to content

Commit

Permalink
更新
Browse files Browse the repository at this point in the history
  • Loading branch information
Vera-Firefly committed Sep 7, 2024
1 parent ec3bfa9 commit 7d53270
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@ public class UpdateLauncher {
private Context context;
private int localVersionCode;

// 构造函数直接获取资源中的 base_version_code
public UpdateLauncher(Context context) {
this.context = context;
// 从资源中获取 base_version_code(处理为 string 并转换为 int)
try {
String versionCodeString = context.getString(R.string.base_version_code);
this.localVersionCode = Integer.parseInt(versionCodeString);
} catch (NumberFormatException e) {
e.printStackTrace();
this.localVersionCode = 0; // 转换失败
this.localVersionCode = 0;
}
}

Expand Down Expand Up @@ -73,11 +71,11 @@ protected void onPostExecute(JSONObject result) {
if (result != null) {
try {
int remoteVersionCode = Integer.parseInt(result.getString("tag_name").replaceAll("[^\\d]", ""));
// 比较 GitHub 获取的版本号和本地版本号
String version = String.valueOf(localVersionCode);
if (remoteVersionCode > localVersionCode) {
showUpdateDialog(result);
} else {
Toast.makeText(context, "已经是最新版本", Toast.LENGTH_SHORT).show();
Toast.makeText(context, context.getString(R.string.pgw_settings_updatelauncher_updated, version), Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
Expand All @@ -94,11 +92,11 @@ private void showUpdateDialog(JSONObject releaseInfo) {
String archModel = getArchModel();

AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("检测到更新" + versionName)
builder.setTitle(context.getString(R.string.pgw_settings_updatelauncher_new_version, versionName))
.setMessage(releaseNotes)
.setCancelable(true)
.setPositiveButton("更新", (dialog, id) -> showDownloadSourceDialog(tagName, versionName, archModel))
.setNegativeButton("忽略", (dialog, id) -> dialog.cancel())
.setPositiveButton(R.string.pgw_settings_updatelauncher_update, (dialog, id) -> showDownloadSourceDialog(tagName, versionName, archModel))
.setNegativeButton(R.string.pgw_settings_updatelauncher_cancel, (dialog, id) -> dialog.cancel())
.show();
} catch (JSONException e) {
e.printStackTrace();
Expand All @@ -110,7 +108,7 @@ private void showDownloadSourceDialog(String tagName, String versionName, String
String githubUrl = String.format(GITHUB_RELEASE_URL, tagName, versionName, archModel);

AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("选择下载源")
builder.setTitle(R.string.pgw_settings_updatelauncher_source)
.setCancelable(false)
.setSingleChoiceItems(downloadSources, -1, (dialog, which) -> {
String selectedSource = downloadSources[which];
Expand All @@ -131,7 +129,7 @@ private void showDownloadSourceDialog(String tagName, String versionName, String
startDownload(apkUrl);
}
})
.setNegativeButton("取消", (dialog, id) -> dialog.cancel())
.setNegativeButton(R.string.alertdialog_cancel, (dialog, id) -> dialog.cancel())
.show();
}

Expand All @@ -146,7 +144,7 @@ private class DownloadApkTask extends AsyncTask<String, Integer, File> {
protected void onPreExecute() {
progressDialog = new ProgressDialog(context);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setTitle("下载更新");
progressDialog.setTitle(R.string.pgw_settings_updatelauncher_downloading);
progressDialog.setCancelable(false);
progressDialog.show();
}
Expand Down Expand Up @@ -197,7 +195,7 @@ protected void onPostExecute(File apkFile) {
if (apkFile != null) {
installApk(apkFile);
} else {
Toast.makeText(context, "下载失败", Toast.LENGTH_SHORT).show();
Toast.makeText(context, context.getString(R.string.pgw_settings_updatelauncher_download_fail), Toast.LENGTH_SHORT).show();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ private void loadMesaList() {
private void downloadMesa(String version) {
AlertDialog dialog = new AlertDialog.Builder(requireContext())
.setMessage(R.string.preference_rendererexp_mesa_downloading)
.setCancelable(false)
.show();
PojavApplication.sExecutorService.execute(() -> {
boolean data = MesaUtils.INSTANCE.downloadMesa(version);
Expand Down
8 changes: 8 additions & 0 deletions app_pojavlauncher/src/main/res/values-zh-rCN/pgw_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,13 @@
<string name="osm_enable_cmldo">允许自定义Mesa图形驱动程序(目前仅Freedreno)</string>
<string name="osm_enable_cmldo_desc">如果需要,您可以自由选择处理方法</string>
<string name="osm_choose_cmldo">选择Mesa图形驱动程序</string>
<!-- Update Launcher -->
<string name="pgw_settings_updatelauncher_updated">已经是最新版本 %s</string>
<string name="pgw_settings_updatelauncher_new_version">新版本 %s 可用,准备更新</string>
<string name="pgw_settings_updatelauncher_update">更新</string>
<string name="pgw_settings_updatelauncher_cancel">忽略</string>
<string name="pgw_settings_updatelauncher_source">选择更新源</string>
<string name="pgw_settings_updatelauncher_downloading">正在下载安装包</string>
<string name="pgw_settings_updatelauncher_download_fail">下载失败</string>

</resources>
8 changes: 8 additions & 0 deletions app_pojavlauncher/src/main/res/values-zh-rTW/pgw_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,13 @@
<string name="osm_enable_cmldo">允許自訂Mesa圖形驅動程序(目前僅Freedreno)</string>
<string name="osm_enable_cmldo_desc">如果需要,您可以自由選擇處理方法</string>
<string name="osm_choose_cmldo">選擇Mesa圖形驅動程序</string>
<!-- Update Launcher -->
<string name="pgw_settings_updatelauncher_updated">已經是最新版本 %s</string>
<string name="pgw_settings_updatelauncher_new_version">新版本 %s 可用,準備更新</string>
<string name="pgw_settings_updatelauncher_update">更新</string>
<string name="pgw_settings_updatelauncher_cancel">忽略</string>
<string name="pgw_settings_updatelauncher_source">選擇更新來源</string>
<string name="pgw_settings_updatelauncher_downloading">正在下載安裝包</string>
<string name="pgw_settings_updatelauncher_download_fail">下載失敗</string>

</resources>
8 changes: 8 additions & 0 deletions app_pojavlauncher/src/main/res/values/pgw_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,13 @@
<string name="osm_enable_cmldo">Enable Custom Mesa Load Driver Override(Only for Freedreno)</string>
<string name="osm_enable_cmldo_desc">If need, you can freely choose processing method</string>
<string name="osm_choose_cmldo">Choose Mesa Loader Driver Override</string>
<!-- Update Launcher -->
<string name="pgw_settings_updatelauncher_updated">Is already the latest version %s</string>
<string name="pgw_settings_updatelauncher_new_version">A new version %s is available for updating</string>
<string name="pgw_settings_updatelauncher_update">Update</string>
<string name="pgw_settings_updatelauncher_cancel">Ignore</string>
<string name="pgw_settings_updatelauncher_source">Select Update Source</string>
<string name="pgw_settings_updatelauncher_downloading">Downloading installation package</string>
<string name="pgw_settings_updatelauncher_download_fail">Download failed</string>

</resources>

0 comments on commit 7d53270

Please sign in to comment.