@@ -130,8 +130,13 @@ protected void onCreate(final Bundle savedInstanceState) {
130130 } else {
131131 navigationView .setCheckedItem (navigationView .getMenu ().getItem (0 ).getSubMenu ().getItem (flipperPosition ).getItemId ());
132132 }
133+
134+ if (!savedInstanceState .getBoolean ("KEEP_FILE" )) {
135+ deleteTempFile ();
136+ }
133137 } else {
134138 navigationView .setCheckedItem (navigationView .getMenu ().getItem (0 ).getSubMenu ().getItem (0 ).getItemId ());
139+ deleteTempFile ();
135140 }
136141
137142 spnLanguages = findViewById (R .id .SpnLanguages );
@@ -150,8 +155,12 @@ protected void onCreate(final Bundle savedInstanceState) {
150155 loadSettingsContent ();
151156
152157 loadAlertContent ();
158+ }
153159
154- // Cleanup of previous runs, if applicable
160+ /**
161+ * Delete the temporary file to save storage
162+ */
163+ private void deleteTempFile () {
155164 final File f = new File (getApplicationContext ().getCacheDir (), tmpFile );
156165 if (f .exists ()) {
157166 //noinspection ResultOfMethodCallIgnored
@@ -296,9 +305,12 @@ public void onClick(View v) {
296305
297306 btnGenerate .setOnClickListener (new View .OnClickListener () {
298307 @ Override
299- public void onClick (View v ) {
308+ public void onClick (final View v ) {
300309 if (fileLoading ) return ;
301- if (!new File (getApplicationContext ().getCacheDir (), tmpFile ).exists ()) return ;
310+ if (!new File (getBaseContext ().getCacheDir (), tmpFile ).exists ()) {
311+ Toast .makeText (getApplicationContext (), R .string .error_no_file , Toast .LENGTH_LONG ).show ();
312+ return ;
313+ }
302314
303315 mRecyclerViewFile .setAdapter (null );
304316
@@ -593,25 +605,26 @@ private void saveSettings(final String lang, final boolean md5, final boolean sh
593605 }
594606
595607 @ Override
596- public void onSaveInstanceState (Bundle savedInstanceState ) {
608+ public void onSaveInstanceState (final Bundle savedInstanceState ) {
597609 savedInstanceState .putInt ("TAB_NUMBER" , viewFlipper .getDisplayedChild ());
598610 savedInstanceState .putString ("FILE_PATH" , edtFilePath .getText ().toString ());
599611 savedInstanceState .putString ("FILE_COMPARE" , edtFileCompare .getText ().toString ());
600612 savedInstanceState .putParcelableArrayList ("FILE_KEY" , fileDataArrayList );
601613 savedInstanceState .putString ("TEXT_DATA" , edtTextData .getText ().toString ());
602614 savedInstanceState .putString ("TEXT_COMPARE" , edtTextCompare .getText ().toString ());
603615 savedInstanceState .putParcelableArrayList ("TEXT_KEY" , textDataArrayList );
616+ savedInstanceState .putBoolean ("KEEP_FILE" , true );
604617 super .onSaveInstanceState (savedInstanceState );
605618 }
606619
607620 @ Override
608- public void onConfigurationChanged (@ NonNull Configuration newConfig ) {
621+ public void onConfigurationChanged (@ NonNull final Configuration newConfig ) {
609622 super .onConfigurationChanged (newConfig );
610623 LocaleHelper .onAttach (getBaseContext ());
611624 }
612625
613626 @ Override
614- protected void attachBaseContext (Context base ) {
627+ protected void attachBaseContext (final Context base ) {
615628 super .attachBaseContext (LocaleHelper .onAttach (base ));
616629 }
617630
@@ -639,7 +652,7 @@ public void run() {
639652 }
640653
641654 @ Override
642- public boolean onNavigationItemSelected (@ NonNull MenuItem item ) {
655+ public boolean onNavigationItemSelected (@ NonNull final MenuItem item ) {
643656 int page = 0 ;
644657
645658 switch (item .getItemId ()) {
@@ -665,7 +678,7 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
665678 }
666679
667680 @ Override
668- public void hashDataFile (List <HashData > data ) {
681+ public void hashDataFile (final List <HashData > data ) {
669682 fileLoading = false ;
670683 pgbFile .setVisibility (View .GONE );
671684
@@ -696,7 +709,7 @@ protected void onActivityResult(final int requestCode, final int resultCode, @Nu
696709 try (final InputStream selectedFileStream = getContentResolver ().openInputStream (selectedFileUri )) {
697710 final File outputFile = new File (getApplicationContext ().getCacheDir (), tmpFile );
698711
699- try (final FileOutputStream outputStream = new FileOutputStream (outputFile )) {
712+ try (final FileOutputStream outputStream = new FileOutputStream (outputFile , false )) {
700713 if (selectedFileStream != null ) {
701714 StreamUtility .copyStream (selectedFileStream , outputStream );
702715 edtFilePath .setText (selectedFileUri .getPath ());
0 commit comments