diff --git a/app_pojavlauncher/src/main/java/com/firefly/feature/UpdateLauncher.java b/app_pojavlauncher/src/main/java/com/firefly/feature/UpdateLauncher.java index 786b49eb7..08b9af97f 100644 --- a/app_pojavlauncher/src/main/java/com/firefly/feature/UpdateLauncher.java +++ b/app_pojavlauncher/src/main/java/com/firefly/feature/UpdateLauncher.java @@ -1,6 +1,7 @@ package com.firefly.feature; import static net.kdt.pojavlaunch.Architecture.*; +import static net.kdt.pojavlaunch.prefs.LauncherPreferences.DEFAULT_PREF; import androidx.core.content.FileProvider; @@ -38,9 +39,11 @@ public class UpdateLauncher { private static final String GITHUB_RELEASE_URL = "github.com/Vera-Firefly/Pojav-Glow-Worm/releases/download/%s/Pojav-Glow-Worm-%s-%s.apk"; private Context context; private int localVersionCode; + File dir; public UpdateLauncher(Context context) { this.context = context; + this.dir = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS); try { String versionCodeString = context.getString(R.string.base_version_code); this.localVersionCode = Integer.parseInt(versionCodeString); @@ -50,49 +53,17 @@ public UpdateLauncher(Context context) { } } - public void checkCachedApk() { - File dir = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS); - File apkFile = new File(dir, "cache.apk"); - File apkVersionFile = new File(dir, "apk_version"); - - if (apkFile.exists() && apkVersionFile.exists()) { - try { - String savedTagName = new String(java.nio.file.Files.readAllBytes(apkVersionFile.toPath())); - int savedVersionCode = Integer.parseInt(savedTagName.replaceAll("[^\\d]", "")); - if (savedVersionCode > localVersionCode) { - new CustomDialog.Builder(context) - .setTitle(context.getString(R.string.pgw_settings_updatelauncher_install_prompt_title)) - .setMessage(context.getString(R.string.pgw_settings_updatelauncher_install_prompt_message, apkFile.getAbsolutePath())) - .setConfirmListener(R.string.pgw_settings_updatelauncher_install, customView -> { - installApk(apkFile); - return true; - }) - .setCancelListener(R.string.alertdialog_cancel, customView -> true) - .setCancelable(false) - .build() - .show(); - } else { - apkFile.delete(); - apkVersionFile.delete(); - checkForUpdates(); - } - } catch (IOException | NumberFormatException e) { - e.printStackTrace(); - } - } else if (apkFile.exists() || apkVersionFile.exists()) { - if (apkFile.exists()) apkFile.delete(); - if (apkVersionFile.exists()) apkVersionFile.delete(); - checkForUpdates(); - } else { - checkForUpdates(); - } - } - - private void checkForUpdates() { - new GetLatestReleaseTask().execute(GITHUB_API); + public void checkForUpdates(boolean ignore) { + new GetLatestReleaseTask(ignore).execute(GITHUB_API); } private class GetLatestReleaseTask extends AsyncTask { + private boolean ignore; + + public GetLatestReleaseTask(boolean ignore) { + this.ignore = ignore; + } + @Override protected JSONObject doInBackground(String... urls) { OkHttpClient client = new OkHttpClient(); @@ -115,8 +86,8 @@ protected void onPostExecute(JSONObject result) { int remoteVersionCode = Integer.parseInt(result.getString("tag_name").replaceAll("[^\\d]", "")); String version = String.valueOf(localVersionCode); if (remoteVersionCode > localVersionCode) { - showUpdateDialog(result); - } else { + checkCachedApk(result, ignore); + } else if (!ignore) { Toast.makeText(context, context.getString(R.string.pgw_settings_updatelauncher_updated, version), Toast.LENGTH_SHORT).show(); } } catch (JSONException e) { @@ -126,27 +97,100 @@ protected void onPostExecute(JSONObject result) { } } - private void showUpdateDialog(JSONObject releaseInfo) { + private void checkCachedApk(JSONObject releaseInfo, boolean ignore) { + boolean INGORE = false; + String tagName; + String versionName; + String releaseNotes; + if (!dir.exists()) { + dir.mkdirs(); + } + File apkFile = new File(dir, "cache.apk"); + File apkVersionFile = new File(dir, "apk_version"); + File ignoreVersionFile = new File(dir, "ignore_version"); + try { - String tagName = releaseInfo.getString("tag_name"); - String versionName = releaseInfo.getString("name"); - String releaseNotes = releaseInfo.getString("body"); - String archModel = getArchModel(); - - CustomDialog.Builder builder = new CustomDialog.Builder(context); - builder.setTitle(context.getString(R.string.pgw_settings_updatelauncher_new_version, versionName)) - .setScrollMessage(releaseNotes) - .setConfirmListener(R.string.pgw_settings_updatelauncher_update, customView -> { - showDownloadSourceDialog(tagName, versionName, archModel); - return true; - }) - .setButton1Listener(context.getString(R.string.pgw_settings_updatelauncher_cancel), customView -> true) - .setCancelListener(R.string.alertdialog_cancel, customView -> true) - .build() - .show(); + tagName = releaseInfo.getString("tag_name"); + versionName = releaseInfo.getString("name"); + releaseNotes = releaseInfo.getString("body"); } catch (JSONException e) { e.printStackTrace(); + return; + } + + if (ignoreVersionFile.exists()) { + try { + String savedIgnoreVersion = new String(java.nio.file.Files.readAllBytes(ignoreVersionFile.toPath())); + String localIgnoreVersion = DEFAULT_PREF.getString("ignoreVersion", null); + if (savedIgnoreVersion.equals(localIgnoreVersion) && savedIgnoreVersion.equals(tagName)) { + if (ignore) INGORE = true; + } else { + ignoreVersionFile.delete(); + } + } catch (IOException | NumberFormatException e) { + e.printStackTrace(); + } } + + if (apkFile.exists() && apkVersionFile.exists()) { + try { + String savedTagName = new String(java.nio.file.Files.readAllBytes(apkVersionFile.toPath())); + int savedVersionCode = Integer.parseInt(savedTagName.replaceAll("[^\\d]", "")); + int releaseVersionCode = Integer.parseInt(tagName.replaceAll("[^\\d]", "")); + if (savedVersionCode > localVersionCode && savedVersionCode >= releaseVersionCode) { + new CustomDialog.Builder(context) + .setTitle(context.getString(R.string.pgw_settings_updatelauncher_install_prompt_title)) + .setMessage(context.getString(R.string.pgw_settings_updatelauncher_install_prompt_message, apkFile.getAbsolutePath())) + .setConfirmListener(R.string.pgw_settings_updatelauncher_install, customView -> { + installApk(apkFile); + return true; + }) + .setCancelListener(R.string.alertdialog_cancel, customView -> true) + .setCancelable(false) + .build() + .show(); + } else { + apkFile.delete(); + apkVersionFile.delete(); + if (!INGORE) showUpdateDialog(tagName, versionName, releaseNotes); + } + } catch (IOException | NumberFormatException e) { + e.printStackTrace(); + } + } else if (apkFile.exists() || apkVersionFile.exists()) { + if (apkFile.exists()) apkFile.delete(); + if (apkVersionFile.exists()) apkVersionFile.delete(); + if (!INGORE) showUpdateDialog(tagName, versionName, releaseNotes); + } else { + if (!INGORE) showUpdateDialog(tagName, versionName, releaseNotes); + } + } + + private void showUpdateDialog(String tagName, String versionName, String releaseNotes) { + String archModel = getArchModel(); + + new CustomDialog.Builder(context) + .setTitle(context.getString(R.string.pgw_settings_updatelauncher_new_version, versionName)) + .setScrollMessage(releaseNotes) + .setConfirmListener(R.string.pgw_settings_updatelauncher_update, customView -> { + showDownloadSourceDialog(tagName, versionName, archModel); + return true; + }) + .setButton1Listener(context.getString(R.string.pgw_settings_updatelauncher_cancel), customView -> { + File ignoreVersion = new File(dir, "ignore_version"); + try (FileOutputStream OutputStream = new FileOutputStream(ignoreVersion)) { + OutputStream.write(tagName.getBytes()); + OutputStream.flush(); + DEFAULT_PREF.edit().putString("ignoreVersion", tagName).apply(); + } catch (IOException e) { + e.printStackTrace(); + return false; + } + return true; + }) + .setCancelListener(R.string.alertdialog_cancel, customView -> true) + .build() + .show(); } private void showDownloadSourceDialog(String tagName, String versionName, String archModel) { @@ -210,7 +254,6 @@ protected File doInBackground(String... urls) { try { Response response = client.newCall(request).execute(); if (response.isSuccessful()) { - File dir = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS); apkFile = new File(dir, "cache.apk"); File apkVersionFile = new File(dir, "apk_version"); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/LauncherActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/LauncherActivity.java index a1dd092f8..21e8109d7 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/LauncherActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/LauncherActivity.java @@ -236,7 +236,7 @@ protected void onCreate(Bundle savedInstanceState) { mProgressLayout.observe(ProgressLayout.DOWNLOAD_VERSION_LIST); // 初始化并调用 UpdateLauncher 进行更新检查 UpdateLauncher updateLauncher = new UpdateLauncher(this); - updateLauncher.checkCachedApk(); + updateLauncher.checkForUpdates(true); } @Override diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceLauncherFragment.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceLauncherFragment.java new file mode 100644 index 000000000..7771455d9 --- /dev/null +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceLauncherFragment.java @@ -0,0 +1,84 @@ +package net.kdt.pojavlaunch.prefs.screens; + +import android.app.Activity; +import android.content.ContentResolver; +import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.net.Uri; +import android.provider.MediaStore; +import android.os.Bundle; + +import android.widget.Toast; +import androidx.preference.Preference; + +import com.firefly.feature.UpdateLauncher; +import com.kdt.pickafile.FileListView; +import net.kdt.pojavlaunch.R; +import net.kdt.pojavlaunch.Tools; +import org.apache.commons.io.IOUtils; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.InputStream; + +public class LauncherPreferenceLauncherFragment extends LauncherPreferenceFragment { + @Override + public void onCreatePreferences(Bundle b, String str) { + addPreferencesFromResource(R.xml.pref_launcher); + + findPreference("control_mouse_setting").setOnPreferenceClickListener((preference) -> { + Intent intent = new Intent(Intent.ACTION_PICK); + intent.setType("image/*"); + startActivityForResult(intent, 1); + return true; + }); + + findPreference("control_mouse_remove").setOnPreferenceClickListener((preference) -> { + File file = new File(Tools.DIR_GAME_HOME, "mouse"); + if (file.exists()) { + file.delete(); + } + Toast.makeText(getContext(), R.string.notif_mouse1, Toast.LENGTH_SHORT).show(); + return true; + }); + + Preference updatePreference = requirePreference("update_launcher"); + updatePreference.setOnPreferenceClickListener(preference -> { + UpdateLauncher updateLauncher = new UpdateLauncher(getContext()); + updateLauncher.checkForUpdates(false); + return true; + }); + + } + + @Override + public void onActivityResult( + int requestCode, int resultCode, final Intent data) { + if (resultCode != Activity.RESULT_OK) { + // Handle error + return; + } + + if (requestCode == 1) {// Get photo picker response for single select. + Uri currentUri = data.getData(); + try { + File file = new File(Tools.DIR_GAME_HOME, "mouse"); + if (file.exists()) { + file.delete(); + } + + InputStream stream1 = getContext().getContentResolver().openInputStream(currentUri); + FileOutputStream stream = new FileOutputStream(file); + + IOUtils.copy(stream1, stream); + stream.close(); + stream1.close(); + Toast.makeText(getContext(), R.string.notif_mouse, Toast.LENGTH_SHORT).show(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } +} diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceMiscellaneousFragment.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceMiscellaneousFragment.java index 34e7cebb1..9cdbf9dc9 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceMiscellaneousFragment.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceMiscellaneousFragment.java @@ -1,26 +1,11 @@ package net.kdt.pojavlaunch.prefs.screens; -import android.app.Activity; -import android.content.ContentResolver; -import android.content.Intent; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.net.Uri; -import android.provider.MediaStore; import android.os.Bundle; -import android.widget.Toast; import androidx.preference.Preference; -import com.kdt.pickafile.FileListView; import net.kdt.pojavlaunch.R; import net.kdt.pojavlaunch.Tools; -import org.apache.commons.io.IOUtils; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.InputStream; public class LauncherPreferenceMiscellaneousFragment extends LauncherPreferenceFragment { @Override @@ -30,50 +15,5 @@ public void onCreatePreferences(Bundle b, String str) { if(!Tools.checkVulkanSupport(driverPreference.getContext().getPackageManager())) { driverPreference.setVisible(false); } - - findPreference("control_mouse_setting").setOnPreferenceClickListener((preference) -> { - Intent intent = new Intent(Intent.ACTION_PICK); - intent.setType("image/*"); - startActivityForResult(intent, 1); - return true; - }); - - findPreference("control_mouse_remove").setOnPreferenceClickListener((preference) -> { - File file = new File(Tools.DIR_GAME_HOME, "mouse"); - if (file.exists()) { - file.delete(); - } - Toast.makeText(getContext(), R.string.notif_mouse1, Toast.LENGTH_SHORT).show(); - return true; - }); - - } - @Override - public void onActivityResult( - int requestCode, int resultCode, final Intent data) { - if (resultCode != Activity.RESULT_OK) { - // Handle error - return; - } - - if (requestCode == 1) {// Get photo picker response for single select. - Uri currentUri = data.getData(); - try { - File file = new File(Tools.DIR_GAME_HOME, "mouse"); - if (file.exists()) { - file.delete(); - } - - InputStream stream1 = getContext().getContentResolver().openInputStream(currentUri); - FileOutputStream stream = new FileOutputStream(file); - - IOUtils.copy(stream1, stream); - stream.close(); - stream1.close(); - Toast.makeText(getContext(), R.string.notif_mouse, Toast.LENGTH_SHORT).show(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } } } diff --git a/app_pojavlauncher/src/main/res/drawable/ic_setting_launcher.xml b/app_pojavlauncher/src/main/res/drawable/ic_setting_launcher.xml new file mode 100644 index 000000000..75330a9ac --- /dev/null +++ b/app_pojavlauncher/src/main/res/drawable/ic_setting_launcher.xml @@ -0,0 +1,13 @@ + + + + + diff --git a/app_pojavlauncher/src/main/res/values-zh-rCN/pgw_strings.xml b/app_pojavlauncher/src/main/res/values-zh-rCN/pgw_strings.xml index 1f68160ae..342e9bf33 100644 --- a/app_pojavlauncher/src/main/res/values-zh-rCN/pgw_strings.xml +++ b/app_pojavlauncher/src/main/res/values-zh-rCN/pgw_strings.xml @@ -125,6 +125,10 @@ 如果需要,您可以自由选择处理方法 选择Mesa图形驱动程序 + 启动器设置 + 启动器个性化 + 获取更新 + 获取启动器更新 已经是最新版本 %s 新版本 %s 可用,准备更新 更新 diff --git a/app_pojavlauncher/src/main/res/values-zh-rTW/pgw_strings.xml b/app_pojavlauncher/src/main/res/values-zh-rTW/pgw_strings.xml index 71d259caf..3b3c068c7 100644 --- a/app_pojavlauncher/src/main/res/values-zh-rTW/pgw_strings.xml +++ b/app_pojavlauncher/src/main/res/values-zh-rTW/pgw_strings.xml @@ -125,6 +125,10 @@ 如果需要,您可以自由選擇處理方法 選擇Mesa圖形驅動程序 + 啟動器設定 + 啟動器個性化 + 取得更新 + 取得啟動器更新 已經是最新版本 %s 新版本 %s 可用,準備更新 更新 diff --git a/app_pojavlauncher/src/main/res/values/pgw_strings.xml b/app_pojavlauncher/src/main/res/values/pgw_strings.xml index 38ae3c18c..4db202942 100644 --- a/app_pojavlauncher/src/main/res/values/pgw_strings.xml +++ b/app_pojavlauncher/src/main/res/values/pgw_strings.xml @@ -125,6 +125,10 @@ If need, you can freely choose processing method Choose Mesa Loader Driver Override + Launcher settings + Launcher Personalization + Get updated + Get updates for the Launcher Is already the latest version %s A new version %s is available for updating Update diff --git a/app_pojavlauncher/src/main/res/xml/pref_launcher.xml b/app_pojavlauncher/src/main/res/xml/pref_launcher.xml new file mode 100644 index 000000000..2306a7052 --- /dev/null +++ b/app_pojavlauncher/src/main/res/xml/pref_launcher.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app_pojavlauncher/src/main/res/xml/pref_main.xml b/app_pojavlauncher/src/main/res/xml/pref_main.xml index 56371ede2..1ef1a4aca 100644 --- a/app_pojavlauncher/src/main/res/xml/pref_main.xml +++ b/app_pojavlauncher/src/main/res/xml/pref_main.xml @@ -37,6 +37,14 @@ android:icon="@drawable/ic_setting_java_runtime" /> + + - - - - - - - - -