From 6be23a0a6fd7ea3ced7efed21c5b8e4b8321a7ec Mon Sep 17 00:00:00 2001 From: bopol Date: Fri, 31 Jan 2020 22:49:43 +0100 Subject: [PATCH] fix wrong language shown many popup dialogs Changed android.R.string.ok, which is "OK", into R.string.finish, which is also OK, but from our strings Then for a small amount of languages that don't have Android translation, it will show the good string. --- .../newpipe/about/LicenseFragmentHelper.java | 15 +++++++----- .../newpipe/download/DownloadDialog.java | 24 +++++++++++-------- .../ImportConfirmationDialog.java | 5 +++- .../settings/ContentSettingsFragment.java | 12 ++++++---- .../settings/DownloadSettingsFragment.java | 10 +++++--- .../giga/ui/adapter/MissionAdapter.java | 2 +- 6 files changed, 43 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/about/LicenseFragmentHelper.java b/app/src/main/java/org/schabi/newpipe/about/LicenseFragmentHelper.java index eeafc1f57..9a11b19cc 100644 --- a/app/src/main/java/org/schabi/newpipe/about/LicenseFragmentHelper.java +++ b/app/src/main/java/org/schabi/newpipe/about/LicenseFragmentHelper.java @@ -3,6 +3,7 @@ package org.schabi.newpipe.about; import android.app.Activity; import android.content.Context; import android.content.DialogInterface; +import android.content.res.Resources; import android.os.AsyncTask; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; @@ -14,6 +15,8 @@ import java.io.BufferedReader; import java.io.InputStreamReader; import java.lang.ref.WeakReference; +import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; + public class LicenseFragmentHelper extends AsyncTask { final WeakReference weakReference; @@ -55,15 +58,15 @@ public class LicenseFragmentHelper extends AsyncTask { wv.loadData(webViewData, "text/html; charset=UTF-8", null); alert.setView(wv); - alert.setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - } - }); + assureCorrectAppLanguage(activity.getApplicationContext()); + alert.setNegativeButton(getFinishString(activity), (dialog, which) -> dialog.dismiss()); alert.show(); } + private static String getFinishString(Activity activity) { + return activity.getApplicationContext().getResources().getString(R.string.finish); + } + /** * @param context the context to use * @param license the license diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java index 44966744b..c78e68597 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java @@ -11,15 +11,6 @@ import android.os.Bundle; import android.os.Environment; import android.os.IBinder; import android.preference.PreferenceManager; -import androidx.annotation.IdRes; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.StringRes; -import androidx.fragment.app.DialogFragment; -import androidx.documentfile.provider.DocumentFile; -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.view.menu.ActionMenuItemView; -import androidx.appcompat.widget.Toolbar; import android.util.Log; import android.util.SparseArray; import android.view.LayoutInflater; @@ -34,6 +25,16 @@ import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.IdRes; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.StringRes; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.view.menu.ActionMenuItemView; +import androidx.appcompat.widget.Toolbar; +import androidx.documentfile.provider.DocumentFile; +import androidx.fragment.app.DialogFragment; + import com.nononsenseapps.filepicker.Utils; import org.schabi.newpipe.MainActivity; @@ -78,6 +79,8 @@ import us.shandian.giga.service.DownloadManagerService; import us.shandian.giga.service.DownloadManagerService.DownloadManagerBinder; import us.shandian.giga.service.MissionState; +import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; + public class DownloadDialog extends DialogFragment implements RadioGroup.OnCheckedChangeListener, AdapterView.OnItemSelectedListener { private static final String TAG = "DialogFragment"; private static final boolean DEBUG = MainActivity.DEBUG; @@ -527,10 +530,11 @@ public class DownloadDialog extends DialogFragment implements RadioGroup.OnCheck } private void showFailedDialog(@StringRes int msg) { + assureCorrectAppLanguage(getContext()); new AlertDialog.Builder(context) .setTitle(R.string.general_error) .setMessage(msg) - .setNegativeButton(android.R.string.ok, null) + .setNegativeButton(getString(R.string.finish), null) .create() .show(); } diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/ImportConfirmationDialog.java b/app/src/main/java/org/schabi/newpipe/local/subscription/ImportConfirmationDialog.java index fbcf5d70e..a44efa1d3 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/ImportConfirmationDialog.java +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/ImportConfirmationDialog.java @@ -15,6 +15,8 @@ import org.schabi.newpipe.util.ThemeHelper; import icepick.Icepick; import icepick.State; +import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; + public class ImportConfirmationDialog extends DialogFragment { @State protected Intent resultServiceIntent; @@ -34,11 +36,12 @@ public class ImportConfirmationDialog extends DialogFragment { @NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { + assureCorrectAppLanguage(getContext()); return new AlertDialog.Builder(getContext(), ThemeHelper.getDialogTheme(getContext())) .setMessage(R.string.import_network_expensive_warning) .setCancelable(true) .setNegativeButton(R.string.cancel, null) - .setPositiveButton(android.R.string.ok, (dialogInterface, i) -> { + .setPositiveButton(R.string.finish, (dialogInterface, i) -> { if (resultServiceIntent != null && getContext() != null) { getContext().startService(resultServiceIntent); } diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java index 88c700582..dc6ccb0a0 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -7,11 +7,12 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; +import android.util.Log; +import android.widget.Toast; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.preference.Preference; -import android.util.Log; -import android.widget.Toast; import com.nononsenseapps.filepicker.Utils; import com.nostra13.universalimageloader.core.ImageLoader; @@ -40,6 +41,8 @@ import java.util.Map; import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; +import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; + public class ContentSettingsFragment extends BasePreferenceFragment { private static final int REQUEST_IMPORT_PATH = 8945; @@ -139,6 +142,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment { @Override public void onActivityResult(int requestCode, int resultCode, @NonNull Intent data) { + assureCorrectAppLanguage(getContext()); super.onActivityResult(requestCode, resultCode, data); if (DEBUG) { Log.d(TAG, "onActivityResult() called with: requestCode = [" + requestCode + "], resultCode = [" + resultCode + "], data = [" + data + "]"); @@ -153,7 +157,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment { } else { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setMessage(R.string.override_current_data) - .setPositiveButton(android.R.string.ok, + .setPositiveButton(getString(R.string.finish), (DialogInterface d, int id) -> importDatabase(path)) .setNegativeButton(android.R.string.cancel, (DialogInterface d, int id) -> d.cancel()); @@ -248,7 +252,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment { // restart app to properly load db System.exit(0); }); - alert.setPositiveButton(android.R.string.yes, (dialog, which) -> { + alert.setPositiveButton(getString(R.string.finish), (dialog, which) -> { dialog.dismiss(); loadSharedPreferences(newpipe_settings); // restart app to properly load db diff --git a/app/src/main/java/org/schabi/newpipe/settings/DownloadSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/DownloadSettingsFragment.java index 8becc79a8..b8ce0ec18 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/DownloadSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/DownloadSettingsFragment.java @@ -8,11 +8,12 @@ import android.content.Intent; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.util.Log; +import android.widget.Toast; + import androidx.annotation.Nullable; import androidx.annotation.StringRes; import androidx.preference.Preference; -import android.util.Log; -import android.widget.Toast; import com.nononsenseapps.filepicker.Utils; @@ -28,6 +29,8 @@ import java.nio.charset.StandardCharsets; import us.shandian.giga.io.StoredDirectoryHelper; +import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; + public class DownloadSettingsFragment extends BasePreferenceFragment { private static final int REQUEST_DOWNLOAD_VIDEO_PATH = 0x1235; private static final int REQUEST_DOWNLOAD_AUDIO_PATH = 0x1236; @@ -159,7 +162,7 @@ public class DownloadSettingsFragment extends BasePreferenceFragment { AlertDialog.Builder msg = new AlertDialog.Builder(ctx); msg.setTitle(title); msg.setMessage(message); - msg.setPositiveButton(android.R.string.ok, null); + msg.setPositiveButton(getString(R.string.finish), null); msg.show(); } @@ -202,6 +205,7 @@ public class DownloadSettingsFragment extends BasePreferenceFragment { @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { + assureCorrectAppLanguage(getContext()); super.onActivityResult(requestCode, resultCode, data); if (DEBUG) { Log.d(TAG, "onActivityResult() called with: requestCode = [" + requestCode + "], " + diff --git a/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java b/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java index aaf7826ef..852c29835 100644 --- a/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java +++ b/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java @@ -534,7 +534,7 @@ public class MissionAdapter extends Adapter implements Handler.Callb ); } - builder.setNegativeButton(android.R.string.ok, (dialog, which) -> dialog.cancel()) + builder.setNegativeButton(R.string.finish, (dialog, which) -> dialog.cancel()) .setTitle(mission.storage.getName()) .create() .show();