Added saving the log to file

This commit is contained in:
Ampli-fier
2019-06-20 22:35:27 +02:00
parent 377de120fd
commit f254e1c829
4 changed files with 59 additions and 2 deletions
+6 -2
View File
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/save_log"
android:title="@string/menu_save_log"
android:icon="@drawable/ic_save_white_24dp"
app:showAsAction="always"/>
<item android:title="@string/menu_copy_to_clipboard"
android:id="@+id/copy_log_to_clipboard" />
<item android:title="@string/menu_zoom_in"
+3
View File
@@ -154,6 +154,7 @@
<string name="menu_view_profile">View profile</string>
<string name="menu_zoom_in">Zoom in</string>
<string name="menu_zoom_out">Zoom out</string>
<string name="menu_save_log">Save log</string>
<string name="title_share_location">Share location with all group members</string>
<string name="mute_for_one_hour">Mute for 1 hour</string>
@@ -400,6 +401,8 @@
<string name="pref_in_chat_sounds">In-chat sounds</string>
<string name="pref_message_text_size">Message font size</string>
<string name="pref_view_log">View log</string>
<string name="pref_saved_log">Saved \"DeltaChat.txt\" to Download folder</string>
<string name="pref_save_log_failed">Failed to save the log</string>
<string name="pref_log_header">Log</string>
<string name="pref_other">Other</string>
<string name="pref_backup">Backup</string>
@@ -7,6 +7,7 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;
import org.thoughtcrime.securesms.database.NoExternalStorageException;
import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.Util;
@@ -57,10 +58,22 @@ public class LogViewActivity extends BaseActionBarActivity {
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
Float newSize;
switch (item.getItemId()) {
case android.R.id.home:
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();
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());
Toast.makeText(getApplicationContext(), R.string.done, Toast.LENGTH_SHORT).show();
@@ -39,9 +39,14 @@ import android.widget.EditText;
import com.b44t.messenger.DcContext;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.database.NoExternalStorageException;
import org.thoughtcrime.securesms.util.Scrubber;
import org.thoughtcrime.securesms.util.StorageUtil;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.ref.WeakReference;
@@ -95,6 +100,38 @@ public class LogViewFragment extends Fragment {
public void scrollUpLog() { logPreview.setSelection(0); }
public boolean saveLogFile() throws NoExternalStorageException {
File outputDirectory = null;
try {
outputDirectory = StorageUtil.getDownloadDir();
try {
String logText = logPreview.getText().toString();
if(!logText.trim().equals("")){
File logFile =new File(outputDirectory + "/DeltaChat.txt");
if(!logFile.exists()){
logFile.createNewFile();
}
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) {
e.printStackTrace();
return false;
}
return true;
}
private static String grabLogcat() {
try {
final Process process = Runtime.getRuntime().exec("logcat -v threadtime -d");