mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Code cleanup for saving the Log to file
This commit is contained in:
@@ -64,15 +64,10 @@ public class LogViewActivity extends BaseActionBarActivity {
|
||||
finish();
|
||||
return true;
|
||||
case R.id.save_log:
|
||||
try {
|
||||
if (logViewFragment.saveLogFile())
|
||||
Toast.makeText(getApplicationContext(), R.string.pref_saved_log, Toast.LENGTH_LONG).show();
|
||||
else
|
||||
Toast.makeText(getApplicationContext(), R.string.pref_save_log_failed, Toast.LENGTH_LONG).show();
|
||||
} catch (NoExternalStorageException e) {
|
||||
e.printStackTrace();
|
||||
if (logViewFragment.saveLogFile())
|
||||
Toast.makeText(getApplicationContext(), R.string.pref_saved_log, Toast.LENGTH_LONG).show();
|
||||
else
|
||||
Toast.makeText(getApplicationContext(), R.string.pref_save_log_failed, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
return true;
|
||||
case R.id.copy_log_to_clipboard:
|
||||
Util.writeTextToClipboard(this, logViewFragment.getLogText());
|
||||
|
||||
@@ -102,7 +102,7 @@ public class LogViewFragment extends Fragment {
|
||||
|
||||
public void scrollUpLog() { logPreview.setSelection(0); }
|
||||
|
||||
public boolean saveLogFile() throws NoExternalStorageException {
|
||||
public boolean saveLogFile() {
|
||||
|
||||
File outputDir = null;
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
|
||||
@@ -111,26 +111,18 @@ public class LogViewFragment extends Fragment {
|
||||
|
||||
try {
|
||||
outputDir = StorageUtil.getDownloadDir();
|
||||
try {
|
||||
String logText = logPreview.getText().toString();
|
||||
if(!logText.trim().equals("")){
|
||||
File logFile = new File(outputDir + "/" + logFileName);
|
||||
String logText = logPreview.getText().toString();
|
||||
if(!logText.trim().equals("")){
|
||||
File logFile = new File(outputDir + "/" + logFileName);
|
||||
|
||||
if(!logFile.exists()){
|
||||
logFile.createNewFile();
|
||||
}
|
||||
if(!logFile.exists()) logFile.createNewFile();
|
||||
|
||||
FileWriter logFileWriter = new FileWriter(logFile, false);
|
||||
BufferedWriter logFileBufferWriter = new BufferedWriter(logFileWriter);
|
||||
logFileBufferWriter.write(logText);
|
||||
logFileBufferWriter.close();
|
||||
}
|
||||
FileWriter logFileWriter = new FileWriter(logFile, false);
|
||||
BufferedWriter logFileBufferWriter = new BufferedWriter(logFileWriter);
|
||||
logFileBufferWriter.write(logText);
|
||||
logFileBufferWriter.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
} catch (NoExternalStorageException e) {
|
||||
} catch (IOException | NoExternalStorageException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user