package com.example.owncloud.ui.activity;

import android.os.AsyncTask;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import com.example.owncloud.R;
import com.example.owncloud.ui.dialog.LoadingDialog;

import java.lang.ref.WeakReference;

public class LogHistoryActivity extends AppCompatActivity {
    private static final String DIALOG_WAIT_TAG = "DIALOG_WAIT";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.log_send_file);

        TextView logTV = (TextView) findViewById(R.id.logTV);


        new LoadingLogTask(logTV).execute();

    }

    private class LoadingLogTask extends AsyncTask <String, Void, String> {
        private final WeakReference<TextView> textViewReference;

        public LoadingLogTask(TextView logTV) {
            textViewReference = new WeakReference<TextView>(logTV);
        }

        @Override
        protected void onPostExecute(String result) {
            showLoadingDialog();
        }

        @Override
        protected void onPreExecute() {
            dismissLoadingDialog();
        }

        protected String doInBackground(String... args) {
            try {
                Thread.sleep(3000);
            } catch (Exception e) {

            }
            return "";
        }

    }

    public void showLoadingDialog() {
        LoadingDialog dialog = LoadingDialog.newInstance("test");
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        dialog.show(ft, DIALOG_WAIT_TAG);
    }

    public void dismissLoadingDialog() {
        Fragment fragment = getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG);
        if (fragment != null) {
            ((LoadingDialog) fragment).dismiss();
        }
    }
}

@@ -65,16 +65,42 @@
 ncTask;%0A
+import android.os.Bundle;%0A
 import a
@@ -131,16 +131,16 @@
 agment;%0A
-
 import a
@@ -282,34 +282,8 @@
 ty;%0A
-import android.os.Bundle;%0A
 impo
@@ -559,16 +559,187 @@
 WAIT%22;%0A%0A
+    private static final String KEY_LOG_TEXT = %22LOG_TEXT%22;%0A%0A    private static final String TAG = LogHistoryActivity.class.getSimpleName();%0A%0A    private String mLogText;%0A%0A
     @Ove
@@ -970,45 +970,261 @@
     
-new LoadingLogTask(logTV).execute();%0A
+if (savedInstanceState == null) %7B%0A            LoadingLogTask task = new LoadingLogTask(logTV);%0A            task.execute();%0A        %7D else %7B%0A            mLogText = savedInstanceState.getString(KEY_LOG_TEXT);%0A            logTV.setText(mLogText);%0A        %7D
 %0A   
@@ -1580,20 +1580,23 @@
         
-show
+dismiss
 LoadingD
@@ -1677,39 +1677,36 @@
 ) %7B%0A            
-dismiss
+show
 LoadingDialog();

fix loading