mirror of
https://github.com/gsantner/dandelion
synced 2024-11-22 04:12:08 +01:00
Cleaned code, added debug log to DebugFragment of AboutActivity
This commit is contained in:
parent
2a4706654f
commit
02f56f25fb
12 changed files with 163 additions and 16 deletions
|
@ -42,6 +42,11 @@ import com.github.dfa.diaspora_android.R;
|
|||
import com.github.dfa.diaspora_android.data.AppSettings;
|
||||
import com.github.dfa.diaspora_android.ui.HtmlTextView;
|
||||
import com.github.dfa.diaspora_android.util.Helpers;
|
||||
import com.github.dfa.diaspora_android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
@ -184,8 +189,8 @@ public class AboutActivity extends AppCompatActivity {
|
|||
/**
|
||||
* Fragment that shows debug information like app version, pod version...
|
||||
*/
|
||||
public static class DebugFragment extends Fragment {
|
||||
|
||||
public static class DebugFragment extends Fragment implements Observer {
|
||||
private TextView logBox;
|
||||
public DebugFragment() {
|
||||
}
|
||||
|
||||
|
@ -198,6 +203,10 @@ public class AboutActivity extends AppCompatActivity {
|
|||
TextView osVersion = (TextView) rootView.findViewById(R.id.fragment_debug__android_version);
|
||||
TextView deviceName = (TextView) rootView.findViewById(R.id.fragment_debug__device_name);
|
||||
TextView podDomain = (TextView) rootView.findViewById(R.id.fragment_debug__pod_domain);
|
||||
logBox = (TextView) rootView.findViewById(R.id.fragment_debug__log_box);
|
||||
|
||||
Log.addLogObserver(this);
|
||||
update(Log.getInstance(), null);
|
||||
|
||||
if (isAdded()) {
|
||||
try {
|
||||
|
@ -218,6 +227,24 @@ public class AboutActivity extends AppCompatActivity {
|
|||
}
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
Log.removeLogObserver(this);
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Observable observable, Object o) {
|
||||
if(logBox != null) {
|
||||
ArrayList<String> logs = Log.getLogBuffer();
|
||||
String log = "";
|
||||
for(String s : logs) {
|
||||
log = log + s+"\n";
|
||||
}
|
||||
logBox.setText(log);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,7 +51,6 @@ import android.support.v7.app.ActionBarDrawerToggle;
|
|||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.ActionMenuView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
@ -82,6 +81,7 @@ import com.github.dfa.diaspora_android.ui.ContextMenuWebView;
|
|||
import com.github.dfa.diaspora_android.ui.CustomWebViewClient;
|
||||
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
|
||||
import com.github.dfa.diaspora_android.util.Helpers;
|
||||
import com.github.dfa.diaspora_android.util.Log;
|
||||
import com.github.dfa.diaspora_android.util.WebHelper;
|
||||
|
||||
import org.json.JSONException;
|
||||
|
@ -202,7 +202,7 @@ public class MainActivity extends AppCompatActivity
|
|||
boolean newWebView = (webView == null);
|
||||
if(newWebView) {
|
||||
Log.d(App.TAG, "Webview was null. Create new one.");
|
||||
View webviewHolder = getLayoutInflater().inflate(R.layout.webview, null);
|
||||
View webviewHolder = getLayoutInflater().inflate(R.layout.webview, this.contentLayout);
|
||||
webView = (ContextMenuWebView) webviewHolder.findViewById(R.id.webView);
|
||||
((LinearLayout)webView.getParent()).removeView(webView);
|
||||
setupWebView(savedInstanceState);
|
||||
|
@ -353,6 +353,7 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
|
||||
//For Android 4.1/4.2 only. DONT REMOVE
|
||||
@SuppressWarnings("unused")
|
||||
protected void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture)
|
||||
{
|
||||
Log.d(App.TAG, "openFileChooser(ValCallback<Uri>, String, String");
|
||||
|
@ -805,7 +806,7 @@ public class MainActivity extends AppCompatActivity
|
|||
if (WebHelper.isOnline(MainActivity.this)) {
|
||||
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
||||
View layout = getLayoutInflater().inflate(R.layout.dialog_search__people_tags, null);
|
||||
View layout = getLayoutInflater().inflate(R.layout.dialog_search__people_tags, contentLayout);
|
||||
final EditText input = (EditText) layout.findViewById(R.id.dialog_search__input);
|
||||
final DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
|
|
|
@ -26,20 +26,15 @@ import android.os.Bundle;
|
|||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import com.github.dfa.diaspora_android.App;
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
|
||||
import butterknife.OnEditorAction;
|
||||
|
||||
/**
|
||||
* @author vanitas
|
||||
*/
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
package com.github.dfa.diaspora_android.data;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import com.github.dfa.diaspora_android.util.Log;
|
||||
|
||||
import com.github.dfa.diaspora_android.App;
|
||||
import com.github.dfa.diaspora_android.listener.WebUserProfileChangedListener;
|
||||
|
|
|
@ -23,7 +23,7 @@ import android.content.Intent;
|
|||
import android.os.AsyncTask;
|
||||
import android.os.IBinder;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.util.Log;
|
||||
import com.github.dfa.diaspora_android.util.Log;
|
||||
|
||||
import com.github.dfa.diaspora_android.App;
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import android.graphics.Bitmap;
|
|||
import android.graphics.BitmapFactory;
|
||||
import android.os.AsyncTask;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
import com.github.dfa.diaspora_android.util.Log;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.github.dfa.diaspora_android.App;
|
||||
|
|
|
@ -20,7 +20,7 @@ package com.github.dfa.diaspora_android.task;
|
|||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
import com.github.dfa.diaspora_android.util.Log;
|
||||
import android.webkit.CookieManager;
|
||||
|
||||
import com.github.dfa.diaspora_android.App;
|
||||
|
|
|
@ -20,7 +20,7 @@ package com.github.dfa.diaspora_android.task;
|
|||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
import com.github.dfa.diaspora_android.util.Log;
|
||||
import android.webkit.CookieManager;
|
||||
|
||||
import com.github.dfa.diaspora_android.App;
|
||||
|
|
|
@ -24,7 +24,7 @@ import android.content.Intent;
|
|||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
import com.github.dfa.diaspora_android.util.Log;
|
||||
|
||||
import com.github.dfa.diaspora_android.App;
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
package com.github.dfa.diaspora_android.util;
|
||||
|
||||
import com.github.dfa.diaspora_android.App;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
|
||||
/**
|
||||
* Class that saves logs eg. for later debugging.
|
||||
* TODO: Differentiate log types (error/debug/info...)
|
||||
* Created by vanitas on 09.09.16.
|
||||
*/
|
||||
public class Log extends Observable{
|
||||
public static Log instance;
|
||||
private SimpleDateFormat dateFormat;
|
||||
private ArrayList<String> logBuffer;
|
||||
private ArrayList<Observer> observers;
|
||||
|
||||
private Log() {
|
||||
logBuffer = new ArrayList<>();
|
||||
dateFormat = new SimpleDateFormat("HH:mm:ss");
|
||||
observers = new ArrayList<>();
|
||||
}
|
||||
|
||||
public static Log getInstance() {
|
||||
if(instance == null) instance = new Log();
|
||||
return instance;
|
||||
}
|
||||
|
||||
private static String time() {
|
||||
return getInstance().dateFormat.format(new Date())+": ";
|
||||
}
|
||||
|
||||
public static void d(String tag, String msg) {
|
||||
Log l = getInstance();
|
||||
android.util.Log.d(tag, msg);
|
||||
l.logBuffer.add(time()+msg);
|
||||
l.notifyLogBufferChanged();
|
||||
}
|
||||
|
||||
public static void e(String tag, String msg) {
|
||||
Log l = getInstance();
|
||||
android.util.Log.e(tag, msg);
|
||||
l.logBuffer.add(time()+msg);
|
||||
l.notifyLogBufferChanged();
|
||||
}
|
||||
|
||||
public static void i(String tag, String msg) {
|
||||
Log l = getInstance();
|
||||
android.util.Log.i(tag, msg);
|
||||
l.logBuffer.add(time()+msg);
|
||||
l.notifyLogBufferChanged();
|
||||
}
|
||||
|
||||
public static void v(String tag, String msg) {
|
||||
Log l = getInstance();
|
||||
android.util.Log.v(tag, msg);
|
||||
l.logBuffer.add(time()+msg);
|
||||
l.notifyLogBufferChanged();
|
||||
}
|
||||
|
||||
public static void w(String tag, String msg) {
|
||||
Log l = getInstance();
|
||||
android.util.Log.w(tag, msg);
|
||||
l.logBuffer.add(time()+msg);
|
||||
l.notifyLogBufferChanged();
|
||||
}
|
||||
|
||||
public static void wtf(String tag, String msg) {
|
||||
Log l = getInstance();
|
||||
android.util.Log.wtf(tag, msg);
|
||||
l.logBuffer.add(time()+msg);
|
||||
l.notifyLogBufferChanged();
|
||||
}
|
||||
|
||||
public static ArrayList<String> getLogBuffer() {
|
||||
return getInstance().logBuffer;
|
||||
}
|
||||
|
||||
private void notifyLogBufferChanged() {
|
||||
if(observers == null) return;
|
||||
for(Observer o : observers) {
|
||||
if(o != null) {
|
||||
o.update(this, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void addLogObserver(Observer observer) {
|
||||
getInstance().observers.add(observer);
|
||||
}
|
||||
|
||||
public static void removeLogObserver(Observer o) {
|
||||
getInstance().observers.remove(o);
|
||||
}
|
||||
}
|
|
@ -17,6 +17,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/activity_vertical_margin" />
|
||||
|
||||
<!-- APP SECTION -->
|
||||
<TextView
|
||||
android:id="@+id/fragment_debug__section_app"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -34,6 +35,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:id="@+id/fragment_debug__app_version"/>
|
||||
|
||||
<!-- DEVICE SECTION -->
|
||||
<TextView
|
||||
android:id="@+id/fragment_debug__section_device"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -52,6 +54,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:id="@+id/fragment_debug__device_name"/>
|
||||
|
||||
<!-- POD SECTION -->
|
||||
<TextView
|
||||
android:id="@+id/fragment_debug__section_pod"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -64,5 +67,26 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/fragment_debug__pod_domain"/>
|
||||
|
||||
<!-- LOG SECTION -->
|
||||
<TextView
|
||||
android:id="@+id/fragment_debug__section_log"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/fragment_debug__section_log"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
style="@android:style/TextAppearance.DeviceDefault.Large"/>
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<HorizontalScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/fragment_debug__log_box" />
|
||||
</HorizontalScrollView>
|
||||
</ScrollView>
|
||||
</LinearLayout>
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<string name="fragment_debug__section_app">Application</string>
|
||||
<string name="fragment_debug__section_device">Device</string>
|
||||
<string name="fragment_debug__section_pod">Diaspora Pod</string>
|
||||
<string name="fragment_debug__section_log">Debug Log</string>
|
||||
<string name="fragment_debug__app_version">App Version: %1$s</string>
|
||||
<string name="fragment_debug__package_name">Package Name: %1$s</string>
|
||||
<string name="fragment_debug__android_version">Android Version: %1$s</string>
|
||||
|
|
Loading…
Reference in a new issue