@@ -130,8 +130,13 @@ protected void onCreate(final Bundle savedInstanceState) {
130
130
} else {
131
131
navigationView .setCheckedItem (navigationView .getMenu ().getItem (0 ).getSubMenu ().getItem (flipperPosition ).getItemId ());
132
132
}
133
+
134
+ if (!savedInstanceState .getBoolean ("KEEP_FILE" )) {
135
+ deleteTempFile ();
136
+ }
133
137
} else {
134
138
navigationView .setCheckedItem (navigationView .getMenu ().getItem (0 ).getSubMenu ().getItem (0 ).getItemId ());
139
+ deleteTempFile ();
135
140
}
136
141
137
142
spnLanguages = findViewById (R .id .SpnLanguages );
@@ -150,8 +155,12 @@ protected void onCreate(final Bundle savedInstanceState) {
150
155
loadSettingsContent ();
151
156
152
157
loadAlertContent ();
158
+ }
153
159
154
- // Cleanup of previous runs, if applicable
160
+ /**
161
+ * Delete the temporary file to save storage
162
+ */
163
+ private void deleteTempFile () {
155
164
final File f = new File (getApplicationContext ().getCacheDir (), tmpFile );
156
165
if (f .exists ()) {
157
166
//noinspection ResultOfMethodCallIgnored
@@ -296,9 +305,12 @@ public void onClick(View v) {
296
305
297
306
btnGenerate .setOnClickListener (new View .OnClickListener () {
298
307
@ Override
299
- public void onClick (View v ) {
308
+ public void onClick (final View v ) {
300
309
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
+ }
302
314
303
315
mRecyclerViewFile .setAdapter (null );
304
316
@@ -593,25 +605,26 @@ private void saveSettings(final String lang, final boolean md5, final boolean sh
593
605
}
594
606
595
607
@ Override
596
- public void onSaveInstanceState (Bundle savedInstanceState ) {
608
+ public void onSaveInstanceState (final Bundle savedInstanceState ) {
597
609
savedInstanceState .putInt ("TAB_NUMBER" , viewFlipper .getDisplayedChild ());
598
610
savedInstanceState .putString ("FILE_PATH" , edtFilePath .getText ().toString ());
599
611
savedInstanceState .putString ("FILE_COMPARE" , edtFileCompare .getText ().toString ());
600
612
savedInstanceState .putParcelableArrayList ("FILE_KEY" , fileDataArrayList );
601
613
savedInstanceState .putString ("TEXT_DATA" , edtTextData .getText ().toString ());
602
614
savedInstanceState .putString ("TEXT_COMPARE" , edtTextCompare .getText ().toString ());
603
615
savedInstanceState .putParcelableArrayList ("TEXT_KEY" , textDataArrayList );
616
+ savedInstanceState .putBoolean ("KEEP_FILE" , true );
604
617
super .onSaveInstanceState (savedInstanceState );
605
618
}
606
619
607
620
@ Override
608
- public void onConfigurationChanged (@ NonNull Configuration newConfig ) {
621
+ public void onConfigurationChanged (@ NonNull final Configuration newConfig ) {
609
622
super .onConfigurationChanged (newConfig );
610
623
LocaleHelper .onAttach (getBaseContext ());
611
624
}
612
625
613
626
@ Override
614
- protected void attachBaseContext (Context base ) {
627
+ protected void attachBaseContext (final Context base ) {
615
628
super .attachBaseContext (LocaleHelper .onAttach (base ));
616
629
}
617
630
@@ -639,7 +652,7 @@ public void run() {
639
652
}
640
653
641
654
@ Override
642
- public boolean onNavigationItemSelected (@ NonNull MenuItem item ) {
655
+ public boolean onNavigationItemSelected (@ NonNull final MenuItem item ) {
643
656
int page = 0 ;
644
657
645
658
switch (item .getItemId ()) {
@@ -665,7 +678,7 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
665
678
}
666
679
667
680
@ Override
668
- public void hashDataFile (List <HashData > data ) {
681
+ public void hashDataFile (final List <HashData > data ) {
669
682
fileLoading = false ;
670
683
pgbFile .setVisibility (View .GONE );
671
684
@@ -696,7 +709,7 @@ protected void onActivityResult(final int requestCode, final int resultCode, @Nu
696
709
try (final InputStream selectedFileStream = getContentResolver ().openInputStream (selectedFileUri )) {
697
710
final File outputFile = new File (getApplicationContext ().getCacheDir (), tmpFile );
698
711
699
- try (final FileOutputStream outputStream = new FileOutputStream (outputFile )) {
712
+ try (final FileOutputStream outputStream = new FileOutputStream (outputFile , false )) {
700
713
if (selectedFileStream != null ) {
701
714
StreamUtility .copyStream (selectedFileStream , outputStream );
702
715
edtFilePath .setText (selectedFileUri .getPath ());
0 commit comments