Fix. Avoid load logs again when changing device orientation
authorjabarros <jabarros@solidgear.es>
Fri, 5 Dec 2014 13:33:04 +0000 (14:33 +0100)
committerjabarros <jabarros@solidgear.es>
Fri, 5 Dec 2014 13:33:04 +0000 (14:33 +0100)
src/com/owncloud/android/ui/activity/LogHistoryActivity.java

index 676388d..0186e1e 100644 (file)
@@ -51,12 +51,15 @@ public class LogHistoryActivity extends SherlockFragmentActivity  {
 
     private static final String MAIL_ATTACHMENT_TYPE = "text/plain";
 
 
     private static final String MAIL_ATTACHMENT_TYPE = "text/plain";
 
+    private static final String KEY_LOG_TEXT = "LOG_TEXT";
+
     private static final String TAG = LogHistoryActivity.class.getSimpleName();
 
     private static final String DIALOG_WAIT_TAG = "DIALOG_WAIT";
 
     private String mLogPath = FileStorageUtils.getLogPath();
     private File logDIR = null;
     private static final String TAG = LogHistoryActivity.class.getSimpleName();
 
     private static final String DIALOG_WAIT_TAG = "DIALOG_WAIT";
 
     private String mLogPath = FileStorageUtils.getLogPath();
     private File logDIR = null;
+    private String mLogText;
 
 
     @Override
 
 
     @Override
@@ -70,6 +73,7 @@ public class LogHistoryActivity extends SherlockFragmentActivity  {
         actionBar.setDisplayHomeAsUpEnabled(true);
         Button deleteHistoryButton = (Button) findViewById(R.id.deleteLogHistoryButton);
         Button sendHistoryButton = (Button) findViewById(R.id.sendLogHistoryButton);
         actionBar.setDisplayHomeAsUpEnabled(true);
         Button deleteHistoryButton = (Button) findViewById(R.id.deleteLogHistoryButton);
         Button sendHistoryButton = (Button) findViewById(R.id.sendLogHistoryButton);
+        TextView logTV = (TextView) findViewById(R.id.logTV);
 
         deleteHistoryButton.setOnClickListener(new OnClickListener() {
             
 
         deleteHistoryButton.setOnClickListener(new OnClickListener() {
             
@@ -89,20 +93,22 @@ public class LogHistoryActivity extends SherlockFragmentActivity  {
             }
         });
 
             }
         });
 
-        if (mLogPath != null) {
-            logDIR = new File(mLogPath);
-        }
-
-        if (logDIR != null && logDIR.isDirectory()) {
-            // Show a dialog while log data is being loaded
-            showLoadingDialog();
-
-            TextView logTV = (TextView) findViewById(R.id.logTV);
+        if (savedInstanceState == null) {
+            if (mLogPath != null) {
+                logDIR = new File(mLogPath);
+            }
 
 
-            // Start a new thread that will load all the log data
-            LoadingLogTask task = new LoadingLogTask(logTV);
-            task.execute();
+            if (logDIR != null && logDIR.isDirectory()) {
+                // Show a dialog while log data is being loaded
+                showLoadingDialog();
 
 
+                // Start a new thread that will load all the log data
+                LoadingLogTask task = new LoadingLogTask(logTV);
+                task.execute();
+            }
+        } else {
+            mLogText = savedInstanceState.getString(KEY_LOG_TEXT);
+            logTV.setText(mLogText);
         }
     }
 
         }
     }
 
@@ -183,7 +189,8 @@ public class LogHistoryActivity extends SherlockFragmentActivity  {
             if (textViewReference != null && result != null) {
                 final TextView logTV = textViewReference.get();
                 if (logTV != null) {
             if (textViewReference != null && result != null) {
                 final TextView logTV = textViewReference.get();
                 if (logTV != null) {
-                    logTV.setText(result);
+                    mLogText = result;
+                    logTV.setText(mLogText);
                     dismissLoadingDialog();
                 }
             }
                     dismissLoadingDialog();
                 }
             }
@@ -258,4 +265,12 @@ public class LogHistoryActivity extends SherlockFragmentActivity  {
             loading.dismiss();
         }
     }
             loading.dismiss();
         }
     }
+
+    @Override
+    protected void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+
+        /// global state
+        outState.putString(KEY_LOG_TEXT, mLogText);
+    }
 }
\ No newline at end of file
 }
\ No newline at end of file