Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".gui.MainActivity"
android:label="@string/app_name"
android:exported="true"
android:launchMode="singleInstance"
android:theme="@style/Theme.DeadHash.NoActionBar">
Expand Down
Binary file added app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
*
Expand Down
68 changes: 34 additions & 34 deletions app/src/main/java/com/codedead/deadhash/gui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -106,6 +107,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
private CheckBox ChbCRC32;

private final String tmpFile = "tmpFile";
private ActivityResultLauncher<Intent> activityResultLauncher;

@Override
protected void onCreate(final Bundle savedInstanceState) {
Expand Down Expand Up @@ -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();
}
}
});
}

/**
Expand Down Expand Up @@ -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)));
}
});

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -577,7 +608,6 @@ private void loadSettingsContent() {
lang = "ru";
}


final int checkedRadioButtonId = group.getCheckedRadioButtonId();
int themeIndex = 0;
if (checkedRadioButtonId == R.id.RdbLightTheme) {
Expand Down Expand Up @@ -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();
}
}
}
}
}
15 changes: 15 additions & 0 deletions app/src/main/res/drawable/ic_launcher_foreground.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108"
android:tint="#FFFFFF">
<group android:scaleX="2.8188"
android:scaleY="2.8188"
android:translateX="20.1744"
android:translateY="20.1744">
<path
android:fillColor="@android:color/white"
android:pathData="M12.65,10C11.83,7.67 9.61,6 7,6c-3.31,0 -6,2.69 -6,6s2.69,6 6,6c2.61,0 4.83,-1.67 5.65,-4H17v4h4v-4h2v-4H12.65zM7,14c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2z"/>
</group>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
</adaptive-icon>
5 changes: 5 additions & 0 deletions app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
</adaptive-icon>
Binary file removed app/src/main/res/mipmap-hdpi/ic_launcher.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-hdpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-mdpi/ic_launcher.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-mdpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xhdpi/ic_launcher.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions app/src/main/res/values/ic_launcher_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#000000</color>
</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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