diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 06d0cce..33eb738 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -19,7 +19,6 @@ tools:ignore="GoogleAppIndexingWarning"> diff --git a/app/src/main/ic_launcher-playstore.png b/app/src/main/ic_launcher-playstore.png new file mode 100644 index 0000000..92d0c4a Binary files /dev/null and b/app/src/main/ic_launcher-playstore.png differ diff --git a/app/src/main/java/com/codedead/deadhash/domain/utils/LocaleHelper.java b/app/src/main/java/com/codedead/deadhash/domain/utils/LocaleHelper.java index 1361fa4..b09fc51 100644 --- a/app/src/main/java/com/codedead/deadhash/domain/utils/LocaleHelper.java +++ b/app/src/main/java/com/codedead/deadhash/domain/utils/LocaleHelper.java @@ -1,11 +1,9 @@ package com.codedead.deadhash.domain.utils; -import android.annotation.TargetApi; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; -import android.os.Build; import androidx.preference.PreferenceManager; @@ -45,11 +43,6 @@ public static Context onAttach(final Context context, final String defaultLangua */ public static Context setLocale(final Context context, final String language) { persist(context, language); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - return updateResources(context, language); - } - return updateResourcesLegacy(context, language); } @@ -79,24 +72,6 @@ private static void persist(final Context context, final String language) { editor.apply(); } - /** - * Update the resources of a specific Context - * - * @param context The Context that should be updated to contain the proper resources - * @param language The language code that should be set - * @return The Context that contains the correct resources and locale - */ - @TargetApi(Build.VERSION_CODES.N) - private static Context updateResources(final Context context, final String language) { - final Locale locale = new Locale(language); - Locale.setDefault(locale); - - final Configuration configuration = context.getResources().getConfiguration(); - configuration.setLocale(locale); - - return context.createConfigurationContext(configuration); - } - /** * Update the resources of a specific Context * diff --git a/app/src/main/java/com/codedead/deadhash/gui/MainActivity.java b/app/src/main/java/com/codedead/deadhash/gui/MainActivity.java index 1d9d10d..062e581 100644 --- a/app/src/main/java/com/codedead/deadhash/gui/MainActivity.java +++ b/app/src/main/java/com/codedead/deadhash/gui/MainActivity.java @@ -10,8 +10,9 @@ import android.os.CountDownTimer; import android.os.Handler; +import androidx.activity.result.ActivityResultLauncher; +import androidx.activity.result.contract.ActivityResultContracts; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatDelegate; import androidx.core.app.ActivityCompat; import androidx.core.app.ShareCompat; @@ -106,6 +107,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On private CheckBox ChbCRC32; private final String tmpFile = "tmpFile"; + private ActivityResultLauncher activityResultLauncher; @Override protected void onCreate(final Bundle savedInstanceState) { @@ -163,6 +165,35 @@ protected void onCreate(final Bundle savedInstanceState) { loadSettingsContent(); loadAlertContent(); + + this.activityResultLauncher = registerForActivityResult( + new ActivityResultContracts.StartActivityForResult(), + result -> { + if (result.getData() != null) { + final Uri selectedFileUri = result.getData().getData(); + if (selectedFileUri != null) { + try (final InputStream selectedFileStream = getContentResolver().openInputStream(selectedFileUri)) { + final File outputFile = new File(getApplicationContext().getCacheDir(), tmpFile); + + try (final FileOutputStream outputStream = new FileOutputStream(outputFile, false)) { + if (selectedFileStream != null) { + StreamUtility.copyStream(selectedFileStream, outputStream); + edtFilePath.setText(selectedFileUri.getPath()); + } else { + Toast.makeText(getApplicationContext(), R.string.error_open_file, Toast.LENGTH_SHORT).show(); + } + } catch (final IOException ex) { + Toast.makeText(getApplicationContext() + , R.string.error_copy_file, Toast.LENGTH_SHORT).show(); + } + } catch (final IOException ex) { + Toast.makeText(getApplicationContext(), R.string.error_open_file, Toast.LENGTH_SHORT).show(); + } + } else { + Toast.makeText(getApplicationContext(), R.string.error_open_file, Toast.LENGTH_SHORT).show(); + } + } + }); } /** @@ -297,7 +328,7 @@ private void loadFileHashContent(final Bundle savedInstance) { .setAction(Intent.ACTION_GET_CONTENT) .addCategory(Intent.CATEGORY_OPENABLE); - startActivityForResult(Intent.createChooser(intent, getString(R.string.dialog_select_file)), 123); + activityResultLauncher.launch(Intent.createChooser(intent, getString(R.string.dialog_select_file))); } }); @@ -455,7 +486,7 @@ private void loadHelpContent() { btnWebsite.setOnClickListener(v -> IntentUtils.openSite(v.getContext(), "http://codedead.com/")); - btnSupport.setOnClickListener(v -> ShareCompat.IntentBuilder.from(MainActivity.this) + btnSupport.setOnClickListener(v -> new ShareCompat.IntentBuilder(MainActivity.this) .setType("message/rfc822") .addEmailTo("admin@codedead.com") .setSubject("DeadHash - Android") @@ -577,7 +608,6 @@ private void loadSettingsContent() { lang = "ru"; } - final int checkedRadioButtonId = group.getCheckedRadioButtonId(); int themeIndex = 0; if (checkedRadioButtonId == R.id.RdbLightTheme) { @@ -683,34 +713,4 @@ public boolean onNavigationItemSelected(@NonNull final MenuItem item) { drawer.closeDrawer(GravityCompat.START); return true; } - - @Override - protected void onActivityResult(final int requestCode, final int resultCode, @Nullable final Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (requestCode == 123 && resultCode == RESULT_OK) { - if (data != null) { - final Uri selectedFileUri = data.getData(); - if (selectedFileUri != null) { - try (final InputStream selectedFileStream = getContentResolver().openInputStream(selectedFileUri)) { - final File outputFile = new File(getApplicationContext().getCacheDir(), tmpFile); - - try (final FileOutputStream outputStream = new FileOutputStream(outputFile, false)) { - if (selectedFileStream != null) { - StreamUtility.copyStream(selectedFileStream, outputStream); - edtFilePath.setText(selectedFileUri.getPath()); - } else { - Toast.makeText(this, R.string.error_open_file, Toast.LENGTH_SHORT).show(); - } - } catch (final IOException ex) { - Toast.makeText(this, R.string.error_copy_file, Toast.LENGTH_SHORT).show(); - } - } catch (final IOException ex) { - Toast.makeText(this, R.string.error_open_file, Toast.LENGTH_SHORT).show(); - } - } else { - Toast.makeText(this, R.string.error_open_file, Toast.LENGTH_SHORT).show(); - } - } - } - } } diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..74e5b3a --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..7353dbd --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..7353dbd --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png deleted file mode 100644 index 5d30b3b..0000000 Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher.png and /dev/null differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png deleted file mode 100644 index b288363..0000000 Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png and /dev/null differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png deleted file mode 100644 index 043e4ae..0000000 Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher.png and /dev/null differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png deleted file mode 100644 index 6bbac87..0000000 Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png and /dev/null differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png deleted file mode 100644 index 073721c..0000000 Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher.png and /dev/null differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png deleted file mode 100644 index 4350072..0000000 Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png and /dev/null differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png deleted file mode 100644 index 6f0b3dd..0000000 Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and /dev/null differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png deleted file mode 100644 index 6c44272..0000000 Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png and /dev/null differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png deleted file mode 100644 index 537ae8f..0000000 Binary files a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png and /dev/null differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png deleted file mode 100644 index f7cdb7b..0000000 Binary files a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png and /dev/null differ diff --git a/app/src/main/res/values/ic_launcher_background.xml b/app/src/main/res/values/ic_launcher_background.xml new file mode 100644 index 0000000..beab31f --- /dev/null +++ b/app/src/main/res/values/ic_launcher_background.xml @@ -0,0 +1,4 @@ + + + #000000 + \ No newline at end of file diff --git a/build.gradle b/build.gradle index da11dfb..cdf8d5c 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:4.2.2' + classpath 'com.android.tools.build:gradle:7.1.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4410496..105209b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Tue Jul 06 16:47:53 CEST 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME